<?php Fun::lang() ?>
<style>
    .fee_footer td {
        padding: 5px;
    }

    .fee_footer {
        margin-right: 10px;
    }
</style>
<div class="page1 print_cutting">
    <div class="container-fluid">
        <div class="col-md-12">
            <h4 style="float: left; color: #2979bc"><?php echo e(__('administrator.cutting')); ?></h4>
        </div>
        <div class="col-sm-12 col-sm-12 col-xs-12">
            <table class="table add-fabric-table">
                <tr>
                    <td><?php echo e(__('administrator.date')); ?></td>
                    <td><?php echo e(date('d-m-Y',strtotime($cutting->date))); ?></td>
                    <td rowspan="3" style="font-size: 26px"><?php echo e(__('administrator.invoice_number')); ?></td>
                    <td rowspan="3"><?php echo e($cutting->invoice_number); ?></td>
                    <td><?php echo e(__('administrator.total_template')); ?></td>
                    <?php
                    $total_template = 0;
                    $total_qty = 0;
                    $sum_cutpiece = 0;
                    $total_fabric = 0;
                    $sum_totalyard = 0;
                    $key = 1;
                    foreach ($detail as $row) {
                        if ($row->type == 'cut_piece') {
                            $total_template += $row->size_qty;
                        }
                    }
                    ?>
                    <td><?php echo e($total_template); ?></td>
                </tr>
                <tr>
                    <td><?php echo e(__('administrator.qty_per_clothes')); ?></td>
                    <td><span class="qty_per_clothes"></span></td>
                </tr>
                <tr>
                    <td><?php echo e(__('administrator.warehouse')); ?></td>
                    <td><?php echo e(findWarehouse($cutting->from_warehouse)->warehouse_name); ?></td>
                </tr>

            </table>
        </div>
        <div class="col-sm-6 col-sm-12 col-xs-12">
            <div style=" margin-top: 4px">
                <table class="table add-fabric-table">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th><?php echo e(__('administrator.fabric')); ?></th>
                        <th><?php echo e(__('administrator.color')); ?></th>
                        <th><?php echo e(__('administrator.code')); ?></th>
                        <th><?php echo e(__('administrator.qty')); ?></th>
                        <th><?php echo e(__('administrator.yard')); ?></th>
                        <th><?php echo e(__('administrator.total')); ?></th>
                    </tr>
                    </thead>
                    <tbody class="fabric-tbody">
                    <?php $__currentLoopData = $fabric_detail; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $fabric): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php
                        $product = getProductById($fabric->fabric_id);

                        $total_yard = $fabric->qty * $fabric->qty_per_unit;
                        $total_fabric += $fabric->qty;
                        $sum_totalyard += $total_yard;

                        $color = findColor($product->color_code)->name??'';

                        ?>
                        <tr>
                            <td><?php echo e($key++); ?></td>
                            <td><?php echo e($product->product_name ?? ''); ?></td>
                            <td><?php echo e($fabric->barcode); ?></td>
                            <td><?php echo e($color); ?></td>
                            <td><?php echo e($fabric->qty); ?></td>
                            <td><?php echo e($fabric->qty_per_unit); ?></td>
                            <td><?php echo e($total_yard); ?></td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $total_row = 10;
                        $total_data = count($fabric_detail);
                        $left_row = $total_row - $total_data;
                    ?>
                    <?php if($total_row>$total_data): ?>
                        <?php for($i=0;$i<$left_row; $i++): ?>
                            <tr>
                                <td><?php echo e($key++); ?></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>
                        <?php endfor; ?>
                    <?php endif; ?>
                    <tr>
                        <td colspan="5"></td>
                        <td rowspan="3"><?php echo e(__('administrator.total_piece')); ?> : <br><br> <?php echo e($total_fabric); ?> ដើម</td>
                        <td rowspan="3"><?php echo e(__('administrator.total_yard')); ?> : <br><br> <?php echo e($sum_totalyard); ?> យ៉ាត
                            <input type="hidden" class="total_yard" value="<?php echo e($sum_totalyard); ?>">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="col-sm-6 col-sm-12 col-xs-12">
            <div style=" margin-top: 4px">
                <table class="table add-fabric-table">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th><?php echo e(__('administrator.product')); ?></th>
                        <th><?php echo e(__('administrator.barcode')); ?></th>
                        <th><?php echo e(__('administrator.size')); ?></th>
                        <th><?php echo e(__('administrator.color')); ?></th>
                        <th><?php echo e(__('administrator.qty')); ?></th>
                    </tr>
                    </thead>
                    <tbody class="fabric-tbody">
                    <?php $__currentLoopData = $detail; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $production_cutting): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php
                            $total_qty= $production_cutting->qty * $production_cutting->size_qty;
                            $sum_cutpiece +=$total_qty;
                            $size = findSize($production_cutting->size_code)->size??'';
                            $color = findColor($production_cutting->color_code)->name??'';
                            $product = \App\Model\product\ProductUnitModel::join('nso007_products','nso007_products.id','nso007_product_unit.product_id')
                            ->where('nso007_product_unit.barcode',$production_cutting->barcode)
                            ->where('nso007_products.type','product')
                            ->select('product_name')
                            ->first();
                        ?>
                        <tr>
                            <td><?php echo e($key+=1); ?></td>
                            <td><?php echo e($product->product_name??'------'); ?></td>
                            <td><?php echo e($production_cutting->barcode); ?></td>
                            <td><?php echo e($size); ?></td>
                            <td><?php echo e($color); ?></td>
                            <td><?php echo e($production_cutting->qty); ?></td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $total_row = 11;
                        $total_data = count($detail);
                        $left_row = $total_row-$total_data;
                    ?>
                    <?php if($total_row>$total_data): ?>
                        <?php for($i=0;$i <$left_row; $i++): ?>
                            <tr>
                                <td><?php echo e($key+=1); ?></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>
                        <?php endfor; ?>
                    <?php endif; ?>
                    <tr>
                        <td colspan="5" class="text-right"><?php echo e(__('administrator.total')); ?> </td>
                        <td ><?php echo e($sum_cutpiece); ?><input type="hidden" class="total_sum_cutpiece" value="<?php echo e($sum_cutpiece); ?>"></td>
                    </tr>
                    </tbody>
                </table>
                <?php if($cutting->cost_per_piece): ?>
                    <table class="fee_footer pull-right">
                        <tr>
                            <td class="text-right"><?php echo e(__('administrator.tailor_fee')); ?></td>
                            <td> :</td>
                            <td class="text-left">฿<?php echo e($cutting->cost_per_piece); ?> / <?php echo e(__('administrator.piece')); ?></td>
                        </tr>
                        <tr>
                            <td class="text-right"><?php echo e(__('administrator.total_tailor_fee')); ?></td>
                            <td> :</td>
                            <td class="text-left">฿<?php echo e($sum_cutpiece*$cutting->cost_per_piece); ?></td>
                        </tr>
                    </table>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        let total_sum_cutpiece = $('.total_sum_cutpiece').val();
        let total_yard = $('.total_yard').val();
        let total = parseFloat(total_yard) / parseFloat(total_sum_cutpiece);
        $('.qty_per_clothes').text(total.toFixed(2));
    });
</script>
<?php /**PATH /home/nsowos/public_html/shr-brand/resources/views/administrator/production-cutting/show.blade.php ENDPATH**/ ?>