<?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\Shifts;
use App\Models\ShiftCashFlow;

$user_details=User::withTrashed()->where('id', $shift->user_id)->first();
$other_details=CustomerDetails::withTrashed()->where('user_id', $shift->user_id)->first();

$cashier_role=User::withTrashed()->where('id', $shift->user_id)->value('user_role');
if($cashier_role == 1){
    $cashier_name=AdminDetails::withTrashed()->where('user_id', $shift->user_id)->value('name');
}
if($cashier_role == 3){
    $cashier_name=ManagerDetails::withTrashed()->where('user_id', $shift->user_id)->value('name');
}
if($cashier_role == 4){
    $cashier_name=CashierDetails::withTrashed()->where('user_id', $shift->user_id)->value('name');
}

$starting_balance = Shifts::where('id',$shift->id)->value('starting_balance');
$cash_flaws = ShiftCashFlow::where('shfit_id', $shift->id)->get();
$expense = 0;
$revenue = 0;
$sales_total = 0;
$cash_payments = 0;
$card_payments = 0;
$online_payments = 0;
$credit_payments = 0;
foreach($cash_flaws as $cash_flaw){
if($cash_flaw->type == "in" && $cash_flaw->is_sales == "0"){
    $revenue = $revenue+$cash_flaw->amount;
}
if($cash_flaw->type == "out"){
    $expense = $expense+$cash_flaw->amount;
}

if($cash_flaw->is_sales == "1"){
    $sales_total = $sales_total+$cash_flaw->amount;
}
if($cash_flaw->paid_type == "cash"){
    $cash_payments = $cash_payments+$cash_flaw->amount;
}
if($cash_flaw->paid_type == "card"){
    $card_payments = $card_payments+$cash_flaw->amount;
}
if($cash_flaw->paid_type == "online"){
    $online_payments = $online_payments+$cash_flaw->amount;
}
if($cash_flaw->paid_type == "credit"){
    $credit_payments = $credit_payments+$cash_flaw->amount;
}
}

// $balance = ($starting_balance+$revenue+$sales_total) - $expense;

$balance = ($starting_balance+$cash_payments+$revenue) - $expense;

?>
<html lang="en">

<style type="text/css">
body {
    margin: 0px;
    padding: 15px;
    width: 88mm;
}

div, p {
    margin: 0;
    padding: 0;
}

</style>

<body>
<div style="text-align: center;
    font-size: 18px;
    font-weight: 500;
    padding-top: 5px;
    padding-bottom: 5px;
    border-top: 1px dashed;
    border-bottom: 1px dashed;">
SHIFT REPORT
</div>

<table style="width:100%;margin-top:15px;">
     <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Shift ID : </p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;">SHFT-000<?php echo e($shift->id); ?></p>
        </td>
    </tr>
    <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Cashier :</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;"><?php echo e($cashier_name); ?></p>
        </td>
    </tr>
    <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Shift In Time :</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;"><?php echo e($shift->created_at->format('Y/m/d \T\i\m\e:H:i:s')); ?></p>
        </td>
    </tr>
    <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Shift Out Time :</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;"><?php echo e($shift->updated_at->format('Y/m/d \T\i\m\e:H:i:s')); ?></p>
        </td>
    </tr>
</table>

<table style="width:100%;margin-top:15px;">
     <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Opening Cash :</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;">LKR <?php echo e(number_format($shift->starting_balance)); ?></p>
        </td>
    </tr>
   
</table>

<table style="width:100%;margin-top:15px;">
     <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Total Sales :</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;">LKR <?php echo e(number_format($sales_total)); ?></p>
        </td>
    </tr>
   
</table>

<table style="width:100%;margin-top:15px;">
     <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Cash Payments :</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;">LKR <?php echo e(number_format($cash_payments)); ?></p>
        </td>
    </tr>
    <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Card Payments :</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;">LKR <?php echo e(number_format($card_payments)); ?></p>
        </td>
    </tr>
    <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Online Payments :</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;">LKR <?php echo e(number_format($online_payments)); ?></p>
        </td>
    </tr>
     <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Credit  :</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;">LKR <?php echo e(number_format($credit_payments)); ?></p>
        </td>
    </tr>
</table>
<table style="width:100%;margin-top:15px;">
     <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Expenses :</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;">LKR <?php echo e(number_format($expense)); ?></p>
        </td>
    </tr>
    <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Other Incomes :</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;">LKR <?php echo e(number_format($revenue)); ?></p>
        </td>
    </tr>

</table>

<table style="width:100%;margin-top:15px;">
     <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Expected Cash :</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;">LKR <?php echo e(number_format($balance)); ?></p>
        </td>
    </tr>
    <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Closing Cash :</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;">LKR <?php echo e(number_format($shift->cashier_entered_value)); ?></p>
        </td>
    </tr>
    <tr>
        <td style="width:40%; text-align:left;">
        <p style="margin:0;">Cash Difference:</p>
        </td>
        <td style="width:60%; text-align:left;">
        <p style="margin:0;">
            LKR <?php echo e(number_format(abs($shift->difference))); ?>

            <?php if($shift->difference < 0): ?>
                (Short)
            <?php elseif($shift->difference > 0): ?>
                (Excess)
            <?php endif; ?>
        </p>
        </td>
    </tr>
</table>
<p style="margin:0;;margin-top:15px;">Remarks :</p>
<div style="text-align: left;
    font-size: 18px;
    font-weight: 500;
    padding-top: 5px;
    padding-bottom: 5px;
    border-top: 1px dashed;
    border-bottom: 1px dashed;;margin-top:15px;">
<p style="margin:0;">Receiver Signature :</p>
<p style="margin:0;">Approved By :</p>
</div>
</body>
<?php if(!request()->has('view')): ?>
<script>
    window.onload = function() {
        window.print();
    }
</script>
<?php endif; ?>
<?php /**PATH /home/u446954234/domains/orionerp.xyz/public_html/demo/resources/views/shift_bill.blade.php ENDPATH**/ ?>