<?php $__env->startSection('content'); ?>
    <?php
    $packer = \App\Model\setup\PackerModel::find($packing->packer_id);
    $payment = \App\Model\payment\PaymentModel::where(['invoice_id' => $packing->id, 'type' => 'packing'])->first();
    $cur = findCurrency($payment->currency_id)->symbol ?? '';
    $remain = $payment->payment_amount - $payment->paid_amount;
    ?>
    <?php echo Form::open(array('route' => ['production-packing-add-payment',$packing->id],'method'=>'POST','class'=>'jform','enctype'=>'multipart/form-data')); ?>

    <div style="overflow:hidden;padding:15px;">
        <div class="row text-center">
            <h4>
                <b><?php echo app('translator')->getFromJson('administrator.add_payment'); ?></b>
            </h4>
            <br>
            <br>
        </div>
        <div class="form-group row">
            <label class="col-sm-4 col-form-label text-right required"><?php echo e(__('administrator.date')); ?></label>
            <div class="col-sm-6">
                <?php echo Form::text('date',date('d-m-Y'), ['class' => 'form-control date_picker']); ?>

            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-4 col-form-label text-right "><?php echo e(__('administrator.invoice')); ?></label>
            <div class="col-sm-6">
                <input type="text" class="form-control" name="invoice" value="<?php echo e($packing->invoice_number); ?>" readonly>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-4 col-form-label text-right"><?php echo e(__('administrator.packer')); ?></label>
            <div class="col-sm-6">
                <?php echo Form::text('packer',$packer->name??'' , ['class' => 'form-control','readonly']); ?>

            </div>
        </div>
        <div class="form-group row">
            <table class="table">
                <thead>
                <tr>
                    <th>#</th>
                    <th><?php echo app('translator')->getFromJson('administrator.barcode'); ?></th>
                    <th><?php echo app('translator')->getFromJson('administrator.item'); ?></th>
                    <th><?php echo app('translator')->getFromJson('administrator.size'); ?></th>
                    <th><?php echo app('translator')->getFromJson('administrator.color'); ?></th>
                    <th><?php echo app('translator')->getFromJson('administrator.total_qty'); ?></th>
                    <th><?php echo app('translator')->getFromJson('administrator.price'); ?></th>
                    <th><?php echo app('translator')->getFromJson('administrator.total'); ?></th>
                </tr>
                </thead>
                <tbody>
                <?php
                $packing_done = \App\Model\production\packing\ProductionPackingDoneModel::where('packing_id', $packing->id)->pluck('id');
                $packing_done_detail = \App\Model\production\packing\ProductionPackingDoneDetailModel::whereIn('packing_done_id', $packing_done)
                    ->selectRaw('SUM(qty) as total_qty,barcode')
                    ->groupBy('barcode')
                    ->get();
                $grand_total = 0;
                $total_qty = 0;
                ?>
                <?php $__currentLoopData = $packing_done_detail; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                    $product_unit = findProductUnitByCode($row->barcode, 'product');
                    $product = getProductById($product_unit->product_id);
                    $size = findSize($product_unit->size_code);
                    $color = findColor($product_unit->color_code);
                    $unit = findUnit($product_unit->unit_id)->unit ?? '';
                    $total = $packer->fee * $row->total_qty;
                    $grand_total+=$total;
                    $total_qty+=$row->total_qty;
                    ?>
                    <tr>
                        <td><?php echo e($key+1); ?></td>
                        <td><?php echo e($row->barcode); ?></td>
                        <td><?php echo e($product->product_name??''); ?></td>
                        <td><?php echo e($size->size??''); ?></td>
                        <td><?php echo e($color->name??''); ?></td>
                        <td><?php echo e("$row->total_qty $unit"); ?></td>
                        <td><?php echo e(number_format($packer->fee,2)." $cur"); ?></td>
                        <td><?php echo e(number_format($total,2)." $cur"); ?></td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="5" class="text-right">
                        <?php echo app('translator')->getFromJson('administrator.total'); ?>
                    </td>
                    <td><?php echo e($total_qty); ?> ឯកតា</td>
                    <td></td>
                    <td>
                        <?php echo e(number_format($grand_total,2)." $cur"); ?>

                    </td>
                </tr>
                </tfoot>
            </table>
        </div>
        <div class="form-group row">
            <label class="col-sm-4 col-form-label text-right"><?php echo e(__('administrator.amount')); ?></label>
            <div class="col-sm-6">
                <?php echo Form::text('payment_amount',number_format($payment->payment_amount,2)." $cur", ['class' => 'form-control','readonly']); ?>

            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-4 col-form-label text-right"><?php echo e(__('administrator.paid')); ?></label>
            <div class="col-sm-6">
                <?php echo Form::text('paid_amount',number_format($payment->paid_amount,2)." $cur" , ['class' => 'form-control','readonly']); ?>

            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-4 col-form-label text-right"><?php echo e(__('administrator.amount')); ?></label>
            <div class="col-sm-6">
                <?php echo Form::text('remain',number_format($remain,2)." $cur" , ['class' => 'form-control','readonly']); ?>

            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-4 col-form-label text-right required"><?php echo e(__('administrator.payment_method')); ?></label>
            <div class="col-sm-6">
                <?php echo Form::select('payment_method', getPaymentMethod() , null , ['placeholder'=>__('administrator.please_select'),'class' => 'form-control select2']); ?>

            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-4 col-form-label text-right required"><?php echo e(__('administrator.pay')); ?> ( <?php echo e($cur); ?> )</label>
            <div class="col-sm-6">
                <?php echo Form::text('paid',null , ['class' => 'form-control number-only txt_paid']); ?>

            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-4 col-form-label text-right "><?php echo e(__('administrator.note')); ?></label>
            <div class="col-sm-6">
                <?php echo Form::textarea('note',null, ['class' => 'form-control no-resize','rows'=>'5','maxlength'=>'150']); ?>

            </div>
        </div>
    </div>
    <?php echo Form::submit('text', ['class' => 'submit_ display-none' ]); ?>

    <?php echo Form::close(); ?>

    <script>
        $(document).ready(function () {
            set_date_picker();
            $('.txt_paid').on('keyup',function () {
                let remain = parseFloat('<?php echo e($remain); ?>')
                let paid = $(this).val()
                paid = paid?parseFloat(paid):0
                if(paid>remain){
                    $(this).val(remain)
                }
            })
        })
    </script>

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


<?php echo $__env->make('layouts.jform', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/nsowos/public_html/shr-brand/resources/views/administrator/production-packing/add-payment.blade.php ENDPATH**/ ?>