<?php
$br = getBranch();

$customer = $master->customer;
?>
<div class="print_this_form">
    <div class="text-center " style="margin-bottom: 30px;margin-top: 20px"><h3><?php echo e(__('administrator.invoice')); ?></h3></div>
    <table width="100%" style="margin-bottom: 20px">
        <tr style="text-align: left;">
            <td style="width: 65%;vertical-align: top!important;">
                <div><?php echo e(__('administrator.invoice')); ?>: <?php echo e($master->invoice_number); ?></div>
                <div style="margin-top: 5px"><?php echo e(__('administrator.customer')); ?>: <?php echo e($customer->name??''); ?></div>
            </td>
            <td>
                <table>
                    <tr class="font_12">
                        <td><?php echo e(__('administrator.date')); ?> </td>
                        <td style="white-space: nowrap">:
                            <b><?php echo e(date('d-m-Y H:i',strtotime($master->sale_date))); ?> <?php echo e($master->daily_order_number?'('.$master->daily_order_number.')':''); ?></b>
                        </td>
                    </tr>
                    <?php if( $customer->phone??''): ?>
                        <tr class="font_12">
                            <td style="padding-top: 5px"><?php echo e(__('administrator.tel')); ?></td>
                            <td style="padding-top: 5px"> : <?php echo e($customer->phone); ?></td>
                        </tr>
                    <?php endif; ?>
                    <?php if($master->reference_file): ?>
                        <tr class="font_12 no-print">
                            <td><?php echo e(__('administrator.reference_file')); ?></td>
                            <td> :
                                <button class="button_info show_reference_file" data-image="<?php echo e($master->reference_file); ?>"><?php echo e(__('administrator.show')); ?></button>
                            </td>
                        </tr>
                    <?php endif; ?>
                </table>
            </td>
        </tr>
    </table>
    <?php
        $hide=0;
            foreach($detail as $key => $row){
                if($row->dis){
                        $hide ++;
                }
            }
    ?>
    <table class="table table-bordered" width="100%">
        <thead>
        <tr>
            <th>#</th>
            <th><?php echo e(__('administrator.products')); ?></th>
            <th><?php echo e(__('administrator.qty')); ?></th>
            <th><?php echo e(__('administrator.price')); ?></th>
            <?php if($hide): ?>
                <th><?php echo e(__('administrator.discount')); ?>(%)</th>
            <?php endif; ?>
            <th><?php echo e(__('administrator.total')); ?></th>
        </tr>
        </thead>
        <tbody>
        <?php
        $subtotal = 0;
        $key = 0;
        $total_qty = 0;
        $currency = findCurrency($master->currency_id)->symbol;
        $detail = $master->detail;
        $grand_total = 0;
        ?>
        <?php if($detail): ?>
            <?php $__currentLoopData = $detail; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php
                $punit = findProductUnitByCode($row->barcode, 'product');
                $product = getProductById($row->product_id);
                $unit = (findUnit($punit->unit_id ?? ''));
                $total_qty += $row->qty;
                $size = findSize($row->size_code);
                $color = findColor($row->color_code);
                $size = $size ? $size->size : '';
                $color = $color ? $color->name : '';
                $grand_total+=$row->total_amount-$row->dis;
                ?>
                <tr role="row">
                    <td><?php echo e($key+=1); ?></td>
                    <td><?php echo e($product->product_name); ?> (<?php echo e($size.','.$color); ?>)</td>
                    <td><?php echo e($row->qty.' '.($unit->name??'')); ?> <?php echo e($row->return_qty?(' ('.__('administrator.return').':'.$row->return_qty.')'):''); ?></td>

                    <td><?php echo e($currency.number_format($row->sale_price ,2)); ?></td>
                    <?php if($hide): ?>
                        <td><?php echo e($currency.number_format($row->dis)); ?></td>
                    <?php endif; ?>
                    <td><?php echo e($currency.number_format($row->total_amount-$row->dis,2)); ?></td>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

            <?php
                $total_row = 10;
                $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>
                        <?php if($hide): ?>
                            <td></td>
                        <?php endif; ?>
                    </tr>
                <?php endfor; ?>
            <?php endif; ?>
        <?php endif; ?>
        <?php
            $col = 3;
            if($hide){
            $col++;
            }
            //$master->grand_total = $grand_total;
            $owed = $master->grand_total-$master->paid_amount;

            if($master->currency_id===1){
                $cur_sc = findCurrency(2)->symbol??'';
                $grand_total_sc = $master->grand_total/$master->rate;
                $delivery_fee_sc = $master->delivery_fee/$master->rate;
                $more_fee_sc = $master->more_fee/$master->rate;
                $paid_amount_sc = $master->paid_amount/$master->rate;
                $owed_sc = $owed/$master->rate;
            }else{
                $cur_sc = findCurrency(1)->symbol??'';
                $grand_total_sc = $master->grand_total*$master->rate;
                $delivery_fee_sc = $master->delivery_fee*$master->rate;
                $more_fee_sc = $master->more_fee*$master->rate;
                $paid_amount_sc = $master->paid_amount*$master->rate;
                $owed_sc = $owed*$master->rate;
            }
        ?>
        <tr>
            <td colspan="<?php echo e($col); ?>" class="text-right"><?php echo e(__('administrator.total_qty')); ?></td>
            <td colspan="2"><?php echo e($total_qty); ?></td>
        </tr>
        <?php if($master->discount): ?>
            <tr>
                <td colspan="<?php echo e($col); ?>" class="text-right"><?php echo e(__('administrator.discount')); ?></td>
                <td colspan="2"><?php echo e($master->discount); ?></td>
            </tr>
        <?php endif; ?>
        <?php if($master->delivery_fee>0): ?>
            <tr>
                <td colspan="<?php echo e($col); ?>" class="text-right"><?php echo e(__('administrator.delivery_fee')); ?></td>
                <td class="text-left"><?php echo e($currency); ?><?php echo e($master->delivery_fee); ?></td>
                <td class="text-left"><?php echo e("$cur_sc ".number_format($delivery_fee_sc,2)); ?></td>
            </tr>
        <?php endif; ?>
        <?php if($master->more_fee>0): ?>
            <tr>
                <td colspan="<?php echo e($col); ?>" class="text-right"><?php echo e(__('administrator.more_fee')); ?> <?php echo e($master->reason_fee?"( $master->reason_fee )":""); ?></td>
                <td class="text-left"><?php echo e($currency); ?><?php echo e($master->more_fee); ?></td>
                <td class="text-left"><?php echo e("$cur_sc ".number_format($more_fee_sc,2)); ?></td>
            </tr>
        <?php endif; ?>
        <tr>
            <td colspan="<?php echo e($col); ?>" class="text-right"><?php echo e(__('administrator.grand_total')); ?></td>
            <td class="text-left"><?php echo e($currency); ?><?php echo e(number_format(( $master->grand_total),2)); ?></td>
            <td class="text-left"><?php echo e("$cur_sc ".number_format($grand_total_sc,2)); ?></td>
        </tr>
        <?php if($master->paid_amount): ?>
            <tr>
                <td colspan="<?php echo e($col); ?>" class="text-right"><?php echo e(__('administrator.paid')); ?></td>
                <td class="text-left"><?php echo e($currency); ?><?php echo e(number_format(($master->paid_amount),2)); ?></td>
                <td class="text-left"><?php echo e("$cur_sc ".number_format($paid_amount_sc,2)); ?></td>
            </tr>
        <?php endif; ?>
        <?php if($owed): ?>
            <tr>
                <td colspan="<?php echo e($col); ?>" class="text-right"><?php echo e(__('administrator.'.($owed>0?'owed':'change_amount'))); ?></td>
                <td class="text-left"><?php echo e($currency); ?><?php echo e(number_format(abs($owed),2)); ?> </td>
                <td class="text-left"><?php echo e("$cur_sc ".number_format($owed_sc,2)); ?> </td>

            </tr>
        <?php endif; ?>
        </tbody>
    </table>

    <?php if($master->note): ?>
        <div style="margin-top: 30px;text-align: left;">
            <span><b><?php echo e(__('administrator.note')); ?></b> : <?php echo $master->note; ?></span>
        </div>
    <?php endif; ?>
    <div style="margin-top: 20px;text-align: center;">
        <b><?php echo $br->invoice_footer; ?></b>
    </div>
</div>
<?php /**PATH /home/nsowos/public_html/shr-brand/resources/views/pos/invoice/wholesale-invoice.blade.php ENDPATH**/ ?>