
<?php $__env->startSection('title'); ?> Supplier Profile | POS Electronics <?php $__env->stopSection(); ?>
<?php $__env->startSection('supplier-profile'); ?> active <?php $__env->stopSection(); ?>
<?php $__env->startSection('styles'); ?>
<?php $__env->stopSection(); ?>


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

<div class="container-fluid p-0">
    <div class=" d-flex align-items-center justify-content-between my-3">
        <div class="align-items-center">
            <h3 class="mb-0 pb-0">Supplier</h3>
        </div>
    </div>

    <div class="row">

        <?php echo $__env->make('admin.productManage.supplier.profile.partials.sidebar', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

        <div class="col-md-9 mb-2">
            <div class="h-100 border-0">

                <div class="table_data rounded p-0">
                    <div class="card shadow">
                        <div class="card border-0">
                            <div class="row card-header aggregate-section-div">
                                <div class="">
                                    <div class=" d-flex justify-content-between align-items-center border-0">
                                        <div class="d-flex align-items-center">
                                            <h3 class="m-0">Invoice</h3>
                                        </div>
                                        <div class="d-none d-sm-block">
                                        </div>
                                    </div>

                                    <?php if(Auth::user()->can('purchase-create')): ?>
                                    <div class="mt-2 btn btn-success d-block rounded-0 d-sm-none">
                                    </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <div id="card_body_1" class="card-body">
                                <div class="">
                                    <div class="row">
                                        <div class="table-container table-responsive">
                                            <table id="" class="table table-bordered min-w-1150">
                                                <thead class="text-uppercase">
                                                    <tr class="me-3">
                                                        <th class="text-center" scope="col"><span>Invoice</span></th>
                                                        <th class="text-center" scope="col"><span>QTY</span></th>
                                                        <th class="text-center" scope="col"><span>Net</span></th>
                                                        <th class="text-center" scope="col"><span>Paid</span></th>
                                                        <th class="text-center" scope="col"><span>Due</span></th>
                                                        <th class="text-center" scope="col"><span>Status</span></th>
                                                        <th class="text-center" scope="col"><span>Date</span></th>
                                                    </tr>
                                                </thead>
                                                <tbody class="text-center">

                                                    <?php $__currentLoopData = $purchaseData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php if(isset($item) && $item != null): ?>
                                                    <tr class="">
                                                        <td class="custom-w-250">
                                                            <div class="row_title">
                                                                <b>#<?php echo e($item->purchase_id); ?></b>
                                                            </div>
                                                            <div class="row-actions mt-2">
                                                                <?php if(Auth::user()->can('purchase-edit')): ?>
                                                                <span><button
                                                                        class="edit_class_modal border-0 fw-bolder bg-transparent text-success"
                                                                        onclick="invoicePurchaseProductList(<?php echo e($item->id); ?>)">
                                                                        Invoice
                                                                        Details </button></span>
                                                                <span> | <a
                                                                        class="edit_class_modal border-0 fw-bolder bg-transparent text-primary"
                                                                        href="<?php echo e(route('purchase-invoice', $item->id)); ?>">
                                                                        Invoice View
                                                                    </a></span>
                                                                <?php endif; ?>
                                                            </div>
                                                        </td>

                                                        <td>
                                                            <span
                                                                class="fw-bolder text-secondary"><?php echo e($item->purchasePaymentData->total_product); ?></span>
                                                        </td>
                                                        <td>
                                                            <span class="fw-bolder text-success"><?php echo e($item->purchasePaymentData->net_amount); ?>tk</span>
                                                        </td>
                                                        <td>
                                                            <span class="fw-bolder text-success"><?php echo e($item->purchasePaymentData->paid_amount); ?>tk</span>
                                                        </td>
                                                        <td>
                                                            <span class="fw-bolder text-danger"><?php echo e($item->purchasePaymentData->due_amount); ?>tk</span>
                                                        </td>
                                                        <td>
                                                            <?php if($item->is_bill_pay == true): ?>
                                                            <span class="badge custom-bg-green">Paid Up</span>
                                                            <?php else: ?>
                                                            <span class="badge bg-warning">Unpaid</span>
                                                            <?php endif; ?>
                                                        </td>
                                                        <td>
                                                            <b><?php echo e(Carbon\Carbon::parse($item->billing_date)->format('d-m-Y')); ?></b>
                                                        </td>

                                                    </tr>

                                                    
                                                    <div class="modal fade" id="invoicePurchaseProductList<?php echo e($item->id); ?>"
                                                        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">Invoice Purchase List
                                                                    </h1>
                                                                    <button type="button" class="btn-close"
                                                                        data-bs-dismiss="modal"
                                                                        aria-label="Close"></button>
                                                                </div>
                                                                <div class="modal-body p-0"
                                                                    id="updatePurchaseProductDetails<?php echo e($item->id); ?>">

                                                                </div>
                                                                <div class="modal-footer">
                                                                    <button type="button" class="btn btn-danger"
                                                                        data-bs-dismiss="modal">Close</button>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>

                                                    <?php endif; ?>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


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

                                        <?php if(isset($purchaseCount) && $purchaseCount >= 10): ?>
                                        <div class="clearfix d-flex">
                                            <div class="float-left">
                                                <p class="text-muted">
                                                    <?php echo e(__('Showing')); ?>

                                                    <span
                                                        class="font-weight-bold"><?php echo e($purchaseData->firstItem()); ?></span>
                                                    <?php echo e(__('to')); ?>

                                                    <span class="font-weight-bold"><?php echo e($purchaseData->lastItem()); ?></span>
                                                    <?php echo e(__('of')); ?>

                                                    <span class="font-weight-bold"><?php echo e($purchaseData->total()); ?></span>
                                                    <?php echo e(__('results')); ?>

                                                </p>
                                            </div>

                                            <div class="float-right custom-table-pagination">
                                                <?php echo $purchaseData->links('pagination::bootstrap-4'); ?>

                                            </div>
                                        </div>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="table_data rounded mt-4 p-0">
                    <div class="card shadow">
                        <div class="card border-0">
                            <div class="row card-header aggregate-section-div">
                                <div class="">
                                    <div class=" d-flex justify-content-between align-items-center border-0">
                                        <div class="d-flex align-items-center">
                                            <h3 class="m-0">Due Payment</h3>
                                        </div>
                                        <div class="d-none d-sm-block">
                                            <?php if(Auth::user()->can('purchase-create')): ?>

                                            <?php endif; ?>
                                        </div>
                                    </div>

                                    <?php if(Auth::user()->can('purchase-create')): ?>
                                    <div class="mt-2 btn btn-success d-block rounded-0 d-sm-none">

                                    </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <div id="card_body_1" class="card-body">
                                <div class="">
                                    <div class="row">
                                        <div class="table-container table-responsive">
                                            <table id="" class="table table-bordered min-w-1150">
                                                <thead class="text-uppercase">
                                                    <tr class="me-3">
                                                        <th class="text-center" scope="col"><span>Invoice</span></th>
                                                        <th class="text-center" scope="col"><span>Paid Amount</span></th>
                                                        <th class="text-center" scope="col"><span>Payment Method</span></th>
                                                        <th class="text-center" scope="col"><span>Date</span></th>
                                                    </tr>
                                                </thead>
                                                <tbody class="text-center">

                                                    <?php $__currentLoopData = $supplierInvoiceData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php if(isset($item) && $item != null): ?>
                                                    <tr class="">
                                                        <td class="custom-w-250">
                                                            <div class="row_title">
                                                                <b>#<?php echo e($item->supplier_invoice); ?></b>
                                                            </div>
                                                            <div class="row-actions mt-2">
                                                                <?php if(Auth::user()->can('purchase-edit')): ?>
                                                                <span><a class="edit_class_modal border-0 fw-bolder bg-transparent text-primary "
                                                                        href="<?php echo e(route('supplier-due-payment-invoice', $item->supplier_invoice)); ?>">
                                                                        Invoice View
                                                                    </a></span>
                                                                <?php endif; ?>
                                                            </div>
                                                        </td>

                                                        <td>
                                                            <span
                                                                class="fw-bolder text-success"><?php echo e($item->total_paid_amount); ?>tk</span>
                                                        </td>
                                                        <td>
                                                            <span
                                                                class="fw-bolder text-info"><?php echo e($item->payment_method); ?></span>
                                                        </td>
                                                        <td>
                                                            <b><?php echo e(Carbon\Carbon::parse($item->payment_date)->format('d-m-Y')); ?></b>
                                                        </td>

                                                    </tr>

                                                    <?php endif; ?>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


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

                                        <?php if(isset($supplierInvoiceCount) && $supplierInvoiceCount >= 10): ?>
                                        <div class="clearfix d-flex">
                                            <div class="float-left">
                                                <p class="text-muted">
                                                    <?php echo e(__('Showing')); ?>

                                                    <span
                                                        class="font-weight-bold"><?php echo e($supplierInvoiceData->firstItem()); ?></span>
                                                    <?php echo e(__('to')); ?>

                                                    <span
                                                        class="font-weight-bold"><?php echo e($supplierInvoiceData->lastItem()); ?></span>
                                                    <?php echo e(__('of')); ?>

                                                    <span
                                                        class="font-weight-bold"><?php echo e($supplierInvoiceData->total()); ?></span>
                                                    <?php echo e(__('results')); ?>

                                                </p>
                                            </div>

                                            <div class="float-right custom-table-pagination">
                                                <?php echo $supplierInvoiceData->links('pagination::bootstrap-4'); ?>

                                            </div>
                                        </div>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>

        </div>
    </div>

    
    <div class="modal fade" id="supplierDuePayment" tabindex="-1" 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">Supplier Due Payment</h1>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <form action="<?php echo e(route('due-purchase-payment-supplier-wise')); ?>" method="post"
                    enctype="multipart/form-data" onsubmit="return checkValidate()">
                    <?php echo csrf_field(); ?>

                    <input type="hidden" name="supplier_id" value="<?php echo e($singleSupplierData->id); ?>">
                    <input type="hidden" name="total_product" value="<?php echo e($subTotalProductQty); ?>">
                    <input type="hidden" name="total_amount" value="<?php echo e($grandTotalProductPrice); ?>">
                    <input type="hidden" name="total_due_amount" id="totalDueAmount" value="<?php echo e($totalDuePrice); ?>">
                    <input type="hidden" name="total_paid_amount" id="totalPaidAmount" value="<?php echo e($totalPaidPrice); ?>">
                    <input type="hidden" name="total_change_amount" id="totalChangeAmount" 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:</strong></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr>
                                                    <td class="text-no-wrap custom-payment-table-items"><strong>Total
                                                            Due Amount(TK):</strong>
                                                    </td>
                                                    <td
                                                        class="text-no-wrap custom-payment-table-items px-3 text-center">
                                                        <span class="text-primary"><b><?php echo e($totalDuePrice); ?></b></span>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="text-no-wrap custom-payment-table-items"><strong>Current
                                                            Paid Amount(TK):</strong>
                                                    </td>
                                                    <td
                                                        class="text-no-wrap custom-payment-table-items px-3 text-center">
                                                        <span class="text-success">
                                                            <b id="currentPaidAmountText">0</b>
                                                        </span>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="text-no-wrap custom-payment-table-items"><strong>Current
                                                            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($totalDuePrice); ?></b>
                                                        </span>
                                                    </td>
                                                </tr>
                                            </tbody>

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

                        <div class="row px-4 mb-4">
                            <div class="col-md-6 mb-2">
                                <div class="form-group custom-select2-form">
                                    <label for="payment_type" class="custom-payment-form-label"> Paymnet Type <span
                                            class=" text-danger">*</span>
                                    </label>
                                    <select name="payment_type" id="payment_type" class="form-select select2" 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>

                                <?php $__errorArgs = ['payment_type'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                <span class=text-danger><?php echo e($message); ?></span>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                            <div class="col-md-6 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="duePaymentAmount"
                                    placeholder="Enter Payment Amount" name="paid_amount" step="0.01" value="0"
                                    onblur="updateDuePayAmount()" 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" <?php echo e($totalDuePrice > 0 ? '' : 'disabled'); ?>

                            >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: $('#supplierDuePayment')
        });
    });

    //To show update modal...
    function invoicePurchaseProductList(id) {
        var url = "<?php echo e(route('get-purchase-product-details-with-id')); ?>";
        if (id != '') {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $.ajax({
                type: 'post',
                url: url,
                data: {
                    purchase_id: id,
                },
                success: function (data) {
                    if(data.error){
                        toastr.error(data.error);
                    }else{
                        $("#invoicePurchaseProductList"+id).modal('show');
                        $("#updatePurchaseProductDetails"+id).html(data);
                    }
                }
            });
        }
    }

    //To calculate payment amount...
    function updateDuePayAmount() {
        let totalProductPrice = parseFloat(<?php echo e($grandTotalProductPrice); ?>);
        let paymentAmount = parseFloat($("#duePaymentAmount").val());
        let totalPaidAmount = parseFloat($("#totalPaidAmount").val());
        let totalDueAmount = parseFloat($("#totalDueAmount").val());
        

        if(paymentAmount < 0){ 
            toastr.error('Sorry, Negative number not applicable.!'); 
            $("#duePaymentAmount").val(0);
            event.preventDefault();
        }else{
            if (paymentAmount > 0) {
                let grandTotalPaidAmount = totalPaidAmount+paymentAmount;
                let finalAmount = totalDueAmount-paymentAmount;
                $("#currentPaidAmountText").text(paymentAmount);
                if(finalAmount >= 0){
                    if(finalAmount == 0){
                        $("#finalDueAmountText").text('0');
                    }else{
                        $("#finalDueAmountText").text(finalAmount);
                    }
                }else{
                    let changeAmount = Math.abs(finalAmount);
                    $("#finalDueAmountText").text('0');
                }
            }else{
                toastr.error('Sorry, You can not submit with payment amount 0.!');
                event.preventDefault();
            }
        }
    }

    //To show due pay modal...
    function profileDuePay(id) {
        if (id != '') {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $.ajax({
                type: 'post',
                url: url,
                data: {
                    purchase_id: id,
                },
                success: function (data) {
                    if(data.error){
                        toastr.error(data.error);
                    }else{
                        $("#profileDuePayModal"+id).modal('show');
                        $("#updateBillingPaymentDetails"+id).html(data);
                    }
                }
            });
        }
    }

    //To calculate payment amount...
    function updatePayAmountForProfileDue(id) {
        let totalProductPrice = parseFloat($("#totalAmount"+id).val());
        let totalDuePrice = parseFloat($("#dueAmount"+id).val());
        let paymentAmount = parseFloat($("#paymentAmount"+id).val());

        //To check negative number...
        if(paymentAmount < 0){
            toastr.error('Sorry, Negative number not applicable.!');
            $("#paymentAmount"+id).val(0)
        }else{
            if (paymentAmount >= 0) {
                let finalAmount = (totalDuePrice - paymentAmount);
                if(finalAmount >= 0){
                    if(finalAmount == 0){
                        $("#finalDueAmountText"+id).text('0');
                    }else{
                        $("#finalDueAmountText"+id).text(finalAmount);
                    }
                    $("#finalChangeAmountText"+id).text('0');
                    $("#changeAmount"+id).val(0);
                }else{
                    let changeAmount = Math.abs(finalAmount);
                    $("#finalChangeAmountText"+id).text(changeAmount);
                    $("#finalDueAmountText"+id).text('0');
                    $("#changeAmount"+id).val(changeAmount);
                }
            }
        }
    }

    //To check...
    function checkValidate() {
        var paymentAmount = $("#duePaymentAmount").val();
        
        if (paymentAmount <= 0) { 
            event.preventDefault();
            toastr.error('Sorry, You can not submit with paid amount 0 .!');
        }

        return true;
    }

    //To show update modal...
    function updateSupplier(id) {
        $("#updateSupplier"+id).modal('show');
    }
</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/supplier/profile/index.blade.php ENDPATH**/ ?>