
<?php $__env->startSection('content'); ?>
    <?php
    $total_due_riel = 0;
    $total_due_usd = 0;
    $total_mat_riel = 0;
    $total_mat_usd = 0;
    $total_return = 0;
    $production = $payment->production;
    $pcurr = findCurrency($production->currency_id);
    $total_item = $production->total_item;

    ?>
    <?php echo Form::open(['route' => ['add-payment-production',$payment->id],'files'=>true,'class'=>'jform']); ?>

    <table>
        <tr>
            <td><?php echo e(__('administrator.tailor')); ?></td>
            <td> : <?php echo e($payment->tailor->name??''); ?></td>
        </tr>
        <tr>
            <td><?php echo e(__('administrator.invoice_number')); ?></td>
            <td> : <?php echo e($production->invoice_number??''); ?></td>
        </tr>
    </table>
    <hr>
    <h3><?php echo e(__('administrator.tailor_due')); ?></h3>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>#</th>
            <th><?php echo e(__('administrator.date')); ?></th>
            <th><?php echo e(__('administrator.amount')); ?></th>
            <th><?php echo e(__('administrator.note')); ?></th>
        </tr>
        </thead>
        <tbody>
        <?php $__currentLoopData = $tailor_due; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php
            $curr = findCurrency($row->currency_id);
            if($row->currency_id===1){
                $total_due_riel += $row->paid_amount;
            }else{
                $total_due_usd += $row->paid_amount;
            }
            ?>
            <tr>
                <td><?php echo e($key+1); ?></td>
                <td><?php echo e(date('d-m-Y',strtotime($row->payment_date))); ?></td>
                <td><?php echo e(($curr->symbol??'').$row->paid_amount); ?></td>
                <td><?php echo e($row->note); ?></td>
            </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </tbody>
        <tfoot>
        <tr>
            <th colspan="2" class="text-right"><?php echo e(__('administrator.total')); ?></th>
            <th>
                <?php echo e($total_due_riel?('៛'.$total_due_riel):''); ?>

                <?php echo $total_due_riel&&$total_due_usd?'<br>':''; ?>

                <?php echo e($total_due_riel?('$'.$total_due_usd):''); ?>

            </th>
            <th></th>
        </tr>
        </tfoot>
    </table>
    <hr>
    <h3><?php echo e(__('administrator.material')); ?></h3>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>#</th>
            <th><?php echo e(__('administrator.date')); ?></th>
            <th><?php echo e(__('administrator.invoice_number')); ?></th>
            <th><?php echo e(__('administrator.material')); ?></th>
            <th><?php echo e(__('administrator.amount')); ?></th>
        </tr>
        </thead>
        <tbody>
        <?php $__currentLoopData = $material_due; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php
            $curr = findCurrency($row->currency_id);
            if($row->currency_id===1){
                $total_mat_riel += $row->account_receivable;
            }else{
                $total_mat_usd += $row->account_receivable;
            }
            $inv_cur = findCurrency($row->currency_id);
            $html = '';
            foreach ($row->detail as $kmat=>$mat){
                $unit = findUnit($mat->unit_id);
                $html.= ($kmat+1).'. '.$mat->product->product_name.' ('.$mat->qty.($unit->unit??'').' * '.$inv_cur->symbol.$mat->price.' = '.$inv_cur->symbol.($mat->qty*$mat->price).' )<br>';
            }
            ?>
            <tr>
                <td><?php echo e($key+1); ?></td>
                <td><?php echo e(date('d-m-Y',strtotime($row->date))); ?></td>
                <td><?php echo e($row->invoice_number); ?></td>
                <td><?php echo $html; ?></td>
                <td><?php echo e(($curr->symbol??'').$row->account_receivable); ?></td>
            </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </tbody>
        <tfoot>
        <tr>
            <th colspan="4" class="text-right"><?php echo e(__('administrator.total')); ?></th>
            <th>
                <?php echo e($total_mat_riel?('៛'.$total_mat_riel):''); ?>

                <?php echo $total_mat_riel&&$total_mat_usd?'<br>':''; ?>

                <?php echo e($total_mat_usd?('$'.$total_mat_usd):''); ?>

            </th>
        </tr>
        </tfoot>
    </table>
    <hr>
    <h3><?php echo e(__('administrator.return_item')); ?></h3>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>#</th>
            <th><?php echo e(__('administrator.date')); ?></th>
            <th><?php echo e(__('administrator.invoice_number')); ?></th>
            <th><?php echo e(__('administrator.qty')); ?></th>
        </tr>
        </thead>
        <tbody>
        <?php $__currentLoopData = $return_qty; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php
            $qty = \App\Model\production\ProductionDoneDetailModel::where('production_done_id', $row->id)->sum('qty');
            $total_return += $qty;
            ?>
            <tr>
                <td><?php echo e($key+1); ?></td>
                <td><?php echo e(date('d-m-Y',strtotime($row->date))); ?></td>
                <td><?php echo e($row->invoice_number); ?></td>
                <td><?php echo e($qty); ?></td>
            </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </tbody>
        <tfoot>
        <tr>
            <th colspan="3" class="text-right"><?php echo e(__('administrator.total_qty')); ?></th>
            <th> : <?php echo e($total_return); ?></th>
        </tr>
        <tr>
            <th colspan="3" class="text-right"><?php echo e(__('administrator.sewing_price')); ?></th>
            <th> : <?php echo e($pcurr->symbol??''); ?><?php echo e($production->sewing_price); ?></th>
        </tr>
        <tr>
            <th colspan="3" class="text-right"><?php echo e(__('administrator.total_amount')); ?></th>
            <?php
            $return_amount = $total_return*$production->sewing_price;
            ?>
            <th> :  <?php echo e($pcurr->symbol??''); ?><?php echo e($return_amount); ?></th>
        </tr>
        </tfoot>
    </table>
    <hr>
    <h3>ខោបាត់</h3>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th></th>
            <th><?php echo e(__('administrator.total_qty')); ?></th>
            <th><?php echo e(__('administrator.return_qty')); ?></th>
            <th><?php echo e(__('administrator.qty')); ?></th>
            <th><?php echo e(__('administrator.price')); ?> <?php echo e($pcurr->symbol??''); ?></th>
            <th><?php echo e(__('administrator.total')); ?> <?php echo e($pcurr->symbol??''); ?></th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>បាត់ខោ</td>
            <td><?php echo Form::text('total_item_qty',$total_item, ['placeholder'=>__('administrator.qty'),'class' => 'form-control number-only','readonly']); ?></td>
            <td><?php echo Form::text('total_return_qty',$total_return, ['placeholder'=>__('administrator.qty'),'class' => 'form-control number-only','readonly']); ?></td>
            <td><?php echo Form::text('lost_qty',$total_item-$total_return, ['placeholder'=>__('administrator.qty'),'class' => 'form-control number-only']); ?></td>
            <td><?php echo Form::text('lost_price',null, ['placeholder'=>__('administrator.price'),'class' => 'form-control number-only']); ?></td>
            <td><?php echo Form::text('total_lost',null, ['placeholder'=>__('administrator.total'),'class' => 'form-control number-only','readonly']); ?></td>
        </tr>
        </tbody>
    </table>
    <hr>
    <h3><?php echo e(__('administrator.grand_total')); ?></h3>
    <br>
    <table class="">
        <tr>
            <td><?php echo e(__('administrator.total')); ?> <?php echo e(__('administrator.return')); ?> (<?php echo e($pcurr->symbol??''); ?>) </td>
            <td> <?php echo Form::text('return_amount',$return_amount, ['class' => 'form-control number-only','readonly']); ?></td>
        </tr>
        <tr>
            <td><?php echo e(__('administrator.total')); ?> <?php echo e(__('administrator.tailor_due')); ?> (៛)</td>
            <td> <?php echo Form::text('tailor_due_riel',$total_due_riel, ['class' => 'form-control number-only','readonly']); ?></td>
        </tr>
        <tr>
            <td><?php echo e(__('administrator.total')); ?> <?php echo e(__('administrator.tailor_due')); ?> ($)</td>
            <td> <?php echo Form::text('tailor_due_usd',$total_due_usd, ['class' => 'form-control number-only','readonly']); ?></td>
        </tr>
        <tr>
            <td><?php echo e(__('administrator.total')); ?> <?php echo e(__('administrator.material_price')); ?> (៛)</td>
            <td> <?php echo Form::text('material_due_riel',$total_mat_riel, ['class' => 'form-control number-only','readonly']); ?></td>
        </tr>
        <tr>
            <td><?php echo e(__('administrator.total')); ?> <?php echo e(__('administrator.material_price')); ?> ($)&nbsp;&nbsp;</td>
            <td> <?php echo Form::text('material_due_usd',$total_mat_usd, ['class' => 'form-control number-only','readonly']); ?></td>
        </tr>
        <tr>
            <td>បាត់ខោ (<?php echo e($pcurr->symbol??''); ?>) </td>
            <td> <?php echo Form::text('total_lost',0, ['class' => 'form-control number-only','readonly']); ?></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td><?php echo e(__('administrator.remain_amount')); ?> (៛)</td>
            <td> <?php echo Form::text('remain_amount_riel',0, ['class' => 'form-control number-only','readonly']); ?></td>
        </tr>
        <tr>
            <td><?php echo e(__('administrator.remain_amount')); ?> ($)</td>
            <td> <?php echo Form::text('remain_amount_usd',0, ['class' => 'form-control number-only','readonly']); ?></td>
        </tr>
        <tr>
            <td><?php echo e(__('administrator.currency')); ?></td>
            <td> <?php echo Form::select('currency_id',getCurrency(),null, ['class' => 'form-control select2','placeholder'=>__('administrator.please_select')]); ?></td>
        </tr>
    </table>
    <input type="submit" class="hidden">
    <?php echo Form::close(); ?>

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

<?php $__env->startSection('jq'); ?>
    <script>
        $(document).ready(function () {
            gen_total();
            $('table').on('keyup','input[name=lost_qty],input[name=lost_price]',function () {
               gen_total();
           });
        });
        function gen_total() {
            let qty = $('input[name=lost_qty]').val();
            let price = $('input[name=lost_price]').val();
            price = price?parseFloat(price):0;
            qty = qty?parseFloat(qty):0;
            let total = price*qty;
            $('input[name=total_lost]').val(total.toFixed(2));

            let return_amount = parseFloat('<?php echo e($return_amount); ?>');
            let total_due_riel = parseFloat('<?php echo e($total_due_riel); ?>');
            let total_due_usd = parseFloat('<?php echo e($total_due_usd); ?>');
            let total_mat_riel = parseFloat('<?php echo e($total_mat_riel); ?>');
            let total_mat_usd = parseFloat('<?php echo e($total_mat_usd); ?>');
            let cur_id = parseFloat('<?php echo e($pcurr->id); ?>');
            let rate = parseFloat(<?php echo e(getRate()); ?>);
            let total_riel = total_due_riel+total_mat_riel;
            let total_usd = total_mat_usd+total_due_usd;
            if(cur_id===1){
                total /= rate;
                return_amount /=rate;
            }
            let remain_usd = return_amount-(total_usd+total+(total_riel/rate));
            $('input[name=remain_amount_riel]').val((remain_usd*rate).toFixed(2));
            $('input[name=remain_amount_usd]').val(remain_usd.toFixed(2));
        }
    </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/payment/production/add-payment.blade.php ENDPATH**/ ?>