<!DOCTYPE html>
<?php
use App\Models\OrderProducts;
use App\Models\User;
use App\Models\CustomerDetails;
use App\Models\Products;
use App\Models\AdminDetails;
use App\Models\ManagerDetails;
use App\Models\CashierDetails;
use App\Models\Settings;

$setting = Settings::first();
$products=OrderProducts::withTrashed()->where('order_id', $order->id)->get();
$user_details=User::withTrashed()->where('id', $order->customer)->first();
$other_details=CustomerDetails::withTrashed()->where('user_id', $order->customer)->first();

$cashier_role=User::withTrashed()->where('id', $order->sales_person)->value('user_role');
if($cashier_role == 1){
    $cashier_name=AdminDetails::withTrashed()->where('user_id', $order->sales_person)->value('name');
}
if($cashier_role == 3){
    $cashier_name=ManagerDetails::withTrashed()->where('user_id', $order->sales_person)->value('name');
}
if($cashier_role == 4){
    $cashier_name=CashierDetails::withTrashed()->where('user_id', $order->sales_person)->value('name');
}
?>
<html lang="en">
<style type="text/css">
@page {
    margin: 10px;
    padding: 0;
}

</style>
<div style="text-align:center;">
<?php if($setting && $setting->logo != null){ 
?> 
    
<!-- <img src="<?php echo e(asset('db_files/other/'.$setting->logo.'')); ?>" style="width:150px;">  -->
<img src="<?php echo e(base_path('/public/db_files/other/'.$setting->logo.'')); ?>" style="width:150px;"> 
<?php } ?>
    <p><?php echo e($setting->company_name); ?><br><?php echo e($setting->address); ?><br><?php echo e($setting->phone_number); ?><br><?php echo e($setting->email); ?></p>
</div>

<div style="text-align:left;">
    <p><b>Receipt No: </b><?php echo e($order->sales_order_number); ?></p>
    <p style="margin:0;">Date: <?php echo e($order->created_at->format('Y/m/d \T\i\m\e:H:i:s')); ?></p>
    <p style="margin:0;">Cashier: <?php echo e($cashier_name); ?></p>
    <p style="margin:0;">Customer: <?php echo e($other_details->customer_name ?? 'Cash'); ?></p>
    <!-- <p style="margin:0;">Mobile No: <?php echo e($other_details->phone ?? '-'); ?></p> -->
</div>

<table style="width:100%;border-top:1px solid;margin-top:15px;">
    <?php foreach($products as $product){ 
        $product_name = Products::withTrashed()->where('id', $product->product)->value('product_name');
    ?>
    <tr>
        <td style="width:70%; text-align:left;">
        <p style="margin:0;"><?php echo e($product_name); ?><br><?php echo e($product->quantity); ?>x Rs. <?php echo e(number_format($product->price, 2)); ?></p>
        </td>
        <td style="width:30%; text-align:right;">
        <p style="margin:0;">Rs.<?php echo e(number_format($product->price * $product->quantity, 2)); ?></p>
        </td>
    </tr>
    <?php  } ?>
</table>

<table style="width:100%;border-top:1px solid;margin-top:15px;">
    <tr>
        <td style="width:70%; text-align:left;">Sub Total :</td>
        <td style="width:30%; text-align:right;">Rs.<?php echo e(number_format($order->sub_total, 2)); ?></td>
    </tr>
    <tr>
        <td style="width:70%; text-align:left;">Items Count : <?php echo e(count($products)); ?></td>
        <td style="width:30%; text-align:right;"></td>
    </tr>
    <tr>
        <td style="width:70%; text-align:left;">Discount (<?php echo e($order->discount); ?>%)</td>
        <td style="width:30%; text-align:right;">
            Rs.<?php echo e(number_format(($order->sub_total/100)*$order->discount, 2)); ?>

        </td>
    </tr>
</table>

<table style="width:100%;">
    <tr>
        <td style="width:70%; text-align:left;"><h4 style="margin:0;">TOTAL :</h4></td>
        <td style="width:30%; text-align:right;;border-bottom:1px solid;">
            <h4 style="margin:0;">Rs.<?php echo e(number_format($order->total, 2)); ?></h4>
        </td>
    </tr>
</table>
<?php 
$generator = new \Picqer\Barcode\BarcodeGeneratorPNG();
$barcode_data = '<img src="data:image/png;base64,' . base64_encode($generator->getBarcode($order->sales_order_number, $generator::TYPE_CODE_128, 1, 30)) . '" />';

 ?>
 <div style="text-align:center;margin-top:20px;margin-bottom:0px;">
 <?php echo $barcode_data ?>
 <!-- <p style="margin-top:0px;margin-bottom:0px;"><?php echo e($order->sales_order_number); ?></p> -->
 </div>
<p style="text-align:center;margin-top:15px;">Thank You !</p>
<!-- <p style="text-align:center;margin-top:20px;">Thank You ! Mr/Ms <?php echo e($other_details->customer_name ?? ''); ?></p> -->
<?php /**PATH D:\Part Time Work\erp-demo-site\Modules/Admin\resources/views/pdf/invoice.blade.php ENDPATH**/ ?>