
<?php $__env->startSection('title'); ?> Invoice | Beauty Parlour <?php $__env->stopSection(); ?>
<?php $__env->startSection('purchase'); ?> active <?php $__env->stopSection(); ?>
<?php $__env->startSection('styles'); ?>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('main_content_section'); ?>

<div class="row min-vh-100">
    <!-- all content will be here. start -->

    <div class="row invoice p-0 m-0">
        <div class="col-md-9 p-0 m-0">
            <div class="shadow rounded m-3">

                <?php
                ///To get logo...
                $softLogo = App\Models\InvoiceLogo::getSoftwareInvoiceLogo();
                ?>
                <div class="d-md-flex justify-content-between custom-billing-invoice-header">
                    <div class="custom-invoice-logo-section">
                        <div class="d-flex align-items-center  custom-billing-invoice-logo">
                            <?php if(isset($softLogo) && $softLogo->logo_image != null): ?>
                            <img src="<?php echo e(asset('backend/uploads/invoiceLogoImg/'.$softLogo->logo_image)); ?>" alt="logo">
                            <?php else: ?>
                            <img src="<?php echo e(asset('backend')); ?>/billing_invoice_logo.png" alt="logo">
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="custom-issue-due-date-section">

                        <div class="d-flex align-items-center gap-2">
                            <div class="d-flex flex-column justify-content-end custom-issue-due-date-text-area gap-2">
                                <p class="">Invoice Date: </p>
                                <p class="">Invoice Generate: </p>
                            </div>

                            <div class="d-flex flex-column gap-2 custom-billing-invoice-header-right">
                                <input type="hidden" name="invoice_id"
                                    class="form-control custom-cursor-pointer custom-readonly-bg-color"
                                    value="#<?php echo e($singlePurchaseData->id); ?>" readonly>
                                <input type="text"
                                    class=" form-control custom-readonly-bg-color flatpickr-basic custom-date-picker"
                                    name="purchase_date" id="purchase_date" placeholder="DD-MM-YYYY"
                                    value="<?php echo e(Carbon\Carbon::parse($singlePurchaseData->purchase_date)->format('d-m-Y')); ?>"
                                    readonly disabled>
                                <input type="text"
                                    class="form-control custom-readonly-bg-color flatpickr-basic custom-date-picker"
                                    value="<?php echo e(Str::title($singlePurchaseData->purchase_by)); ?>" readonly disabled>
                            </div>
                        </div>

                    </div>
                </div>

                <hr>

                <div class="row px-4 mt-3">
                    <div class="col-12">
                        <h5>Purchase Product List</h5>
                        <div class="table-container table-responsive">
                            <table class="table table-bordered py-3">
                                <!-- <hr class="mb-1"> -->
                                <thead>
                                    <tr>
                                        <th scope="col"> Product </th>
                                        <th scope="col" class="text-center"> QTY </th>
                                        <th scope="col" class="text-center"> Unit Price </th>
                                        <th scope="col" class="text-center"> Total Price </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $__currentLoopData = $purchaseBPD; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $singleBPD): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php if(isset($singleBPD) && $singleBPD != null): ?>
                                    <tr>
                                        <td class="text-no-wrap"><?php echo e($singleBPD->productData->product_name); ?></td>
                                        <td class="text-center"><?php echo e($singleBPD->product_qty); ?></td>
                                        <td class="text-center"><?php echo e($singleBPD->single_product_price); ?></td>
                                        <td class="text-center"><?php echo e($singleBPD->total_product_price); ?></td>
                                    </tr>
                                    <?php endif; ?>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>

                            </table>
                        </div>
                    </div>
                </div>

                <hr>

                <div class="custom-invoice-common-padding pb-5 pt-3">
                    <div class="row">
                        <div class="col-md-6">
                            <span class="">

                                <p class="mb-1" id="updateBranchInvoiceTerms">
                                    <?php echo $softLogo != null ? $softLogo->invoice_terms : ''; ?>

                                </p>
                            </span>
                        </div>
                        <div class="col-md-6">
                            <div class="w-100 d-flex gap-2">
                                <div class="text-end w-50 custom-footer-right-text-block">
                                    <p>Product Qty:</p>
                                    <p>Total Amount:</p>
                                </div>
                                <div class="d-flex flex-column gap-2 w-50">
                                    <input type="text" name="sub_total_quantity" id="sub_total_quantity"
                                        class="form-control custom-cursor-pointer custom-readonly-bg-color"
                                        value="<?php echo e($subTotalProductQty > 0 ? $subTotalProductQty : 0); ?>" readonly>
                                    <input type="text" name="grand_total_price" id="grand_total_price"
                                        class="form-control custom-cursor-pointer custom-readonly-bg-color"
                                        value="<?php echo e($subTotalPrice > 0 ? $subTotalPrice : 0); ?>" readonly>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
        <div class="col-md-3 p-0 m-0">
            <div class="row p-3">
                <div class="col-12 mb-4">
                    <div class="">
                        <div class="card card-stats">
                            <div class="card-header custom-payment-section-header">
                                <div class="icon icon-warning d-flex">
                                    <span class="material-symbols-outlined">equalizer</span>
                                    <p class="category custom-card-header-title custom-payment-section-heading-title">
                                        <strong>Invoice Status</strong>
                                    </p>
                                </div>
                            </div>
                            <div class="card-footer p-0 dashboard-card-footer text-center custom-invoice-card-status">
                                <div class="stats">
                                    <div class="row">
                                        <div class="col-12">
                                            <i class="material-symbols-outlined custom-danger-color">error</i><br>
                                            <span class="custom-danger-color">Pending</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-12 mb-4">
                    <div class="">
                        <div class="card card-stats">
                            <div class="card-header custom-payment-section-header">
                                <div class="icon icon-warning d-flex">
                                    <span class="material-symbols-outlined">equalizer</span>
                                    <p class="category custom-card-header-title custom-payment-section-heading-title">
                                        <strong>Invoice Options</strong>
                                    </p>
                                </div>
                            </div>
                            <div class="card-footer p-0 dashboard-card-footer">
                                <div class="stats">
                                    <div class="row">
                                        <button type="button" class="text-white btn">
                                            <div class="col-12 dashboard-card-color text-center py-2"
                                                onclick="addBillPay(<?php echo e($singlePurchaseData->id); ?>)">
                                                <i class="material-symbols-outlined custom-bill-pay-icon">paid</i> Bill
                                                Pay
                                            </div>
                                        </button>

                                        <a class="text-white btn"
                                            href="<?php echo e(route('purchase-edit', $singlePurchaseData->id)); ?>">
                                            <div class="col-12 dashboard-card-info-color text-center py-2">
                                                <i class="material-symbols-outlined custom-bill-pay-icon">edit_note</i>
                                                Modify Invoice
                                            </div>
                                        </a>

                                        <a class="text-white btn"
                                            href="<?php echo e(route('purchase-delete', $singlePurchaseData->id)); ?>">
                                            <div class="col-12 dashboard-card-danger-color text-center py-2">
                                                <i class="material-symbols-outlined custom-bill-pay-icon">cancel</i>
                                                Delete Invoice
                                            </div>
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <!-- all content will be here. end -->


    
    <div class="modal fade" id="billPaymentModal" tabindex="-1" aria-labelledby="oneInputModalLabel" aria-hidden="true"
        data-bs-backdrop='static'>
        <div class="modal-dialog modal-dialog-centered max-width-900px">
            <div class="modal-content">
                <div class="modal-header">
                    <h1 class="modal-title fs-5" id="oneInputModalLabel">Purchase Bill Payment</h1>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                
                <form action="<?php echo e(route('purchase-payment')); ?>" method="post" enctype="multipart/form-data">
                    <?php echo csrf_field(); ?>
                    <input type="hidden" name="purchase_id" value="<?php echo e($singlePurchaseData->id); ?>">
                    <input type="hidden" name="total_product" value="<?php echo e($subTotalProductQty); ?>">
                    <input type="hidden" name="total_amount" value="<?php echo e($subTotalPrice); ?>">
                    <input type="hidden" name="due_amount" id="dueAmount" value="<?php echo e($subTotalPrice); ?>">
                    <input type="hidden" name="change_amount" id="changeAmount" value="0">
                    <div class="modal-body p-0">
                        <div class="row px-4 mt-4 mb-2">
                            <div class="col-12">
                                <div class="table-container table-responsive">
                                    <div class="table_wrap" id="serviceBillPaymentProduct">
                                        <table class="table table-bordered py-3">
                                            <thead>
                                                <tr>
                                                    <th scope="col" class="text-center"><strong>Items:</strong></th>
                                                    <th scope="col" class="text-center"><strong>Price/QTY:</strong>
                                                        <span
                                                            id="paymentFinalProductPrice">(<?php echo e($subTotalPrice); ?>)tk</span>
                                                    </th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr>
                                                    <td class="text-no-wrap custom-payment-table-items"><strong>Total
                                                            Product(QTY):</strong></td>
                                                    <td
                                                        class="text-no-wrap custom-payment-table-items px-3 text-center">
                                                        <span
                                                            class="text-primary"><b><?php echo e($subTotalProductQty); ?></b></span>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="text-no-wrap custom-payment-table-items"><strong>Total
                                                            Amount(TK):</strong></td>
                                                    <td
                                                        class="text-no-wrap custom-payment-table-items px-3 text-center">
                                                        <span class="text-success"><b><?php echo e($subTotalPrice); ?></b></span>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="text-no-wrap custom-payment-table-items"><strong>Special
                                                            Discount(TK):</strong></td>
                                                    <td
                                                        class="text-no-wrap custom-payment-table-items px-3 text-center">
                                                        <span class="text-secondary">
                                                            <b
                                                                id="finalSpecialDiscountAmountText"><?php echo e($specialDiscountPrice); ?></b>
                                                        </span>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="text-no-wrap custom-payment-table-items"><strong>Due
                                                            Amount(TK):</strong></td>
                                                    <td
                                                        class="text-no-wrap custom-payment-table-items px-3 text-center">
                                                        <span class="text-danger">
                                                            <b id="finalDueAmountText"><?php echo e($subTotalPrice); ?></b>
                                                        </span>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="text-no-wrap custom-payment-table-items"><strong>Change
                                                            Amount(TK):</strong></td>
                                                    <td
                                                        class="text-no-wrap custom-payment-table-items px-3 text-center">
                                                        <span class="text-info">
                                                            <b id="finalChangeAmountText">0</b>
                                                        </span>
                                                    </td>
                                                </tr>
                                            </tbody>

                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="row px-4 mb-4">
                            <div class="col-md-4 mb-2">
                                <div>
                                    <div class="form-group custom-select2-form">
                                        <label for="payment_type">Payment Type <span class=" text-danger">*</span>
                                        </label>
                                        <select class="form-select select2" name="payment_type" id="payment_type"
                                            required>
                                            <option value="" selected disabled>Select Payment Type</option>
                                            <option value="hand cash">Hand Cash</option>
                                            <option value="bank">Bank</option>
                                            <option value="rocket">Rocket</option>
                                            <option value="bkash">Bkash</option>
                                            <option value="cash on delivery">Cash On Delivery</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4 mb-2">
                                <label for="special_discount" class="custom-payment-form-label">Special Discount<span
                                        class=" text-danger">*</span></label>
                                <input type="number" class="form-control" id="specialDiscount"
                                    placeholder="Enter Payment Amount" name="special_discount" step="0.01" value="0"
                                    onblur="updateSpecialDiscount()" required />
                            </div>
                            <div class="col-md-4 mb-2">
                                <label for="payment_amount" class="custom-payment-form-label">Paid Amount<span
                                        class=" text-danger">*</span></label>
                                <input type="number" class="form-control" id="paymentAmount"
                                    placeholder="Enter Payment Amount" name="paid_amount" step="0.01" value="0"
                                    onblur="updatePayAmount()" required />
                            </div>
                            <div class="col-12 mb-4">
                                <label for="payment_note" class="custom-payment-form-label">Payment Note</label>
                                <textarea class="form-control form-control-solid" name="payment_note" id="payment_note"
                                    cols="5" rows="3" placeholder="Enter Note (Optional)"></textarea>
                            </div>
                            <!--begin::Col-->
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-success">Submit Payment</button>
                        <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Cancel</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
    $(document).ready(function(){
        $("#payment_type").select2({
            dropdownParent: $('#billPaymentModal')
        });
    });

    //To bill pay of prodcts...
    function addBillPay(billingId) {
        $("#billPaymentModal").modal('show');
    }

    //To calculate special discount payment amount...
    function updateSpecialDiscount() {
        let totalProductPrice = parseFloat(<?php echo e($subTotalPrice); ?>);
        let paymentAmount = parseFloat($("#paymentAmount").val());
        let specialDiscount = parseFloat($("#specialDiscount").val());

        //To check negative number...
        if(specialDiscount < 0){
            toastr.error('Sorry, Negative number not applicable.!'); 
            $("#specialDiscount").val(0);
            $("#finalSpecialDiscountAmountText").text('0');
        }else{
            $("#finalSpecialDiscountAmountText").text(specialDiscount);
            if(paymentAmount < 0){ 
                toastr.error('Sorry, Negative number not applicable.!'); 
                $("#paymentAmount").val(0) 
            }else{
                if (paymentAmount >= 0) {
                    let discountAmount = (totalProductPrice - specialDiscount);
                    let finalAmount = (discountAmount - paymentAmount);
                    if(finalAmount >= 0){
                        if(finalAmount == 0){
                            $("#finalDueAmountText").text('0');
                        }else{
                            $("#finalDueAmountText").text(finalAmount);
                        }
                        $("#finalChangeAmountText").text('0');
                        $("#dueAmount").val(finalAmount);
                        $("#changeAmount").val(0);
                    }else{
                        let changeAmount = Math.abs(finalAmount);
                        $("#finalChangeAmountText").text(changeAmount);
                        $("#finalDueAmountText").text('0');
                        $("#dueAmount").val(0);
                        $("#changeAmount").val(changeAmount);
                    }
                }
            }
        }
    }
    
    //To calculate payment amount...
    function updatePayAmount() {
        let totalProductPrice = parseFloat(<?php echo e($subTotalPrice); ?>);
        let paymentAmount = parseFloat($("#paymentAmount").val());
        let specialDiscount = parseFloat($("#specialDiscount").val());

        //To check negative number...
        if(specialDiscount < 0){
            toastr.error('Sorry, Negative number not applicable.!'); 
            $("#specialDiscount").val(0);
            $("#finalSpecialDiscountAmountText").text('0');
        }else{
            $("#finalSpecialDiscountAmountText").text(specialDiscount);
            if(paymentAmount < 0){ 
                toastr.error('Sorry, Negative number not applicable.!'); 
                $("#paymentAmount").val(0) 
            }else{
                if (paymentAmount >= 0) {
                    let discountAmount = (totalProductPrice - specialDiscount);
                    let finalAmount = (discountAmount - paymentAmount);
                    if(finalAmount >= 0){
                        if(finalAmount == 0){
                            $("#finalDueAmountText").text('0');
                        }else{
                            $("#finalDueAmountText").text(finalAmount);
                        }
                        $("#finalChangeAmountText").text('0');
                        $("#dueAmount").val(finalAmount);
                        $("#changeAmount").val(0);
                    }else{
                        let changeAmount = Math.abs(finalAmount);
                        $("#finalChangeAmountText").text(changeAmount);
                        $("#finalDueAmountText").text('0');
                        $("#dueAmount").val(0);
                        $("#changeAmount").val(changeAmount);
                    }
                }
            }
        }
    }
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\Project\Personal-Project\Office-Project\update\skin-care\resources\views/admin/productManage/purchaseProduct/getPurchaseBillPayProduct.blade.php ENDPATH**/ ?>