

<?php $__env->startSection('content'); ?>
<style>
    /* Main Styles */
    .account-statement {
        margin: 2rem;
        font-family: 'Tajawal', Tahoma, Geneva, Verdana, sans-serif;
    }
    
    /* Header Cards */
    .header-card {
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        border-radius: 8px;
        overflow: hidden;
        margin-bottom: 1.5rem;
        
        
        
    }
    
    .header-card .card-header {
        background-color: #2C4E71;
        padding: 5px;
        
        
    }
    
    .header-card .card-title {
        text-align: center;
        font-weight: 300;
        color: #FFF;
        margin: 0;
        font-size: 1.1rem;
        font-size:15px;
        
    }
    
    .header-card .card-body {
        padding: 5px;
        display: flex;
        align-items: center;
        background-color: #f8f9fa;
        font-size:14px;
    }
    
    /* Main Table */
    .statement-table {
        width: 100%;
        border-collapse: collapse;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    }
    
    .statement-table thead th {
        background-color: #2C4E71;
        color: white;
        padding: 2px;
        text-align: center;
        vertical-align: middle;
        border: 1px solid  #0a3f63;
        font-size:12px
    }
    
    .statement-table tbody td {
        padding: 2px;
        text-align: center;
        border: 1px solid #dee2e6;
        font-size:12px
    }
    
    .statement-table tbody tr {
        background-color: #f8f9fa;
        transition: background-color 0.2s;
    }
    
    .statement-table tbody tr:hover {
        background-color: #e9ecef;
    }
    
    /* Special Cells */
    .final-state-cell {
        font-weight: 700 !important;
        background-color: #e2e6ea !important;
    }
    
    .rejected-item {
        color: #dc3545;
        text-decoration: line-through;
    }
    
    .summary-row {
        background-color: #2C4E71 !important;
        color: white !important;
    }
 
    
    .summary-row th {
        font-weight: 700;
        padding: 3px;
        font-size:12px;
        text-align:center;
    }
    
    /* Responsive Adjustments */
    @media (max-width: 768px) {
        .header-card .card-body {
            flex-direction: column;
            text-align: center;
        }
        
        .statement-table {
            display: block;
            overflow-x: auto;
        }
    }

     @media  print{
    @page{ size: A4 landscape; margin: 12mm; }
    body{background:#fff}
    .toolbar{display:none !important}
    .page{box-shadow:none; border-radius:0; margin:0}
    thead{display: table-header-group;}
    tfoot{display: table-footer-group;}
    /* تحسين الألوان في الطباعة */
    *{-webkit-print-color-adjust: exact; print-color-adjust: exact;}
  }
  
</style>

<div class="account-statement">
    <!-- Header Section -->
    <div class="row">
        <!-- Logo Column -->
        <div class="col-md-3 mb-3">
            <a href="<?php echo e(url('#')); ?>" class="brand-link d-block text-center">
                <img src='<?php echo e(asset("theme/dist/img/splash.png")); ?>' style="height: 74px;" alt="Company Logo">
            </a>
        </div>

        <!-- Period Card -->
        <div class="col-md-4 mb-3">
            <div class="header-card">
                <div class="card-header">
                    <h3 class="card-title">الفترة</h3>
                </div>
                <div class="card-body">
                    <span class="period-date"><?php echo e($to); ?></span>
                    <span class="px-2 font-weight-bold">الي</span>
                    <span class="period-date"><?php echo e($from); ?></span>
                    <span class="px-2 font-weight-bold">بدأ من</span>
                </div>
            </div>
        </div>

        <!-- Client Account Card -->
        <div class="col-md-5 mb-3">
            <div class="header-card">
                <div class="card-header">
                    <h3 class="card-title">كشف حساب عميل</h3>
                </div>
                <div class="card-body">
                    <span class="creation-date"><?php echo e(date('Y-m-d')); ?></span>
                    <span class="px-2">تاريخ الأنشاء</span>
                    <span class="client-name font-weight-bold"><?php echo e($client->name); ?></span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Account Statement Table -->
    <div class="card shadow-sm">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="statement-table">
                    <thead>
                        <tr>
                            <th style="width: 100px">الحالة النهائية</th>
                            <th style="width: 100px">الرصيد النهائي</th>
                            <th style="width: 100px">الرصيد السابق</th>
                            <th>مدفوعات</th>
                            <th>خصم مرتجعات</th>
                            <th>خصم نقدي</th>
                            <th>المبلغ</th>
                            <th>السعر</th>
                            <th>الكمية</th>
                            <th>رقم العملية</th>
                            <th>نوع العملية</th>
                            <th>التاريخ</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                            $total_amount = 0;
                            $total_price = 0;
                            $total_payments = 0;
                         ?>

                        <?php foreach($client_sheets as $client_sheet_item): ?>
                            <!-- Invoice Items -->
                            <?php foreach($client_sheet_item->items as $key => $item): ?>
                                <?php 
                                    $total_amount += $item->item_amount;
                                    $total_price += ($item->item_price * $item->item_amount);
                                 ?>
                                <tr>
                                    <?php if(count($client_sheet_item->payment_methods) == 0 && count($client_sheet_item->items)-1 == $key): ?>
                                        <td class="final-state-cell"><?php echo e($client_sheet_item->final_state); ?></td>
                                        <td class="final-state-cell"><?php echo e($client_sheet_item->current); ?></td>
                                        <td class="final-state-cell"><?php echo e($client_sheet_item->previos); ?></td>
                                    <?php else: ?>
                                        <td>-</td>
                                        <td>-</td>
                                        <td>-</td>
                                    <?php endif; ?>

                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td><?php echo e(number_format($item->item_price * $item->item_amount, 2)); ?></td>
                                    <td><?php echo e(number_format($item->item_price, 2)); ?></td>
                                    <td><?php echo e($item->item_amount); ?></td>
                                    <td><?php echo e($item->invoice_id); ?></td>
                                    <td>فاتورة - <?php echo e($item->sell_store->store->sell_name); ?></td>
                                    <td><?php echo e($item->created_at->format('d/m/Y')); ?></td>
                                </tr>
                            <?php endforeach; ?>

                            <!-- Payment Methods -->
                            <?php foreach($client_sheet_item->payment_methods as $key => $payment): ?>
                                <?php 
                                    if (!($payment->cheque_id && $payment->cheque->status == "Rejected")) {
                                        $total_payments += $payment->pay;
                                    }
                                 ?>
                                <tr>
                                    <?php if(count($client_sheet_item->payment_methods)-1 === $key): ?>
                                        <td class="final-state-cell"><?php echo e($client_sheet_item->final_state); ?></td>
                                        <td class="final-state-cell"><?php echo e($client_sheet_item->current); ?></td>
                                        <td class="final-state-cell"><?php echo e($client_sheet_item->previos); ?></td>
                                    <?php else: ?>
                                        <td>-</td>
                                        <td>-</td>
                                        <td>-</td>
                                    <?php endif; ?>

                                    <td <?php if($payment->cheque_id && $payment->cheque->status == "Rejected"): ?> class="rejected-item" <?php endif; ?>>
                                        <?php echo e(number_format($payment->pay, 2)); ?>

                                    </td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td><?php echo e($payment->receipt_id); ?></td>
                                    <td <?php if($payment->cheque_id && $payment->cheque->status == "Rejected"): ?> class="rejected-item" <?php endif; ?>>
                                        سند قبض ف - <?php echo e($payment->payment_method ? $payment->payment_method->name : ""); ?>

                                    </td>
                                    <td><?php echo e($payment->created_at->format('d/m/Y')); ?></td>
                                </tr>
                            <?php endforeach; ?>

                            <!-- Receipts -->
                            <?php foreach($client_sheet_item->receipts as $key => $receipt): ?>
                                <?php 
                                    if (!($receipt->cheque_id && $receipt->cheque->status == "Rejected")) {
                                        $total_payments += $receipt->pay;
                                    }
                                 ?>
                                <tr>
                                    <td class="final-state-cell"><?php echo e($client_sheet_item->final_state); ?></td>
                                    <td class="final-state-cell"><?php echo e($client_sheet_item->current); ?></td>
                                    <td class="final-state-cell"><?php echo e($client_sheet_item->previos); ?></td>
                                    
                                    <td <?php if($receipt->cheque_id && $receipt->cheque->status == "Rejected"): ?> class="rejected-item" <?php endif; ?>>
                                        <?php echo e(number_format($receipt->pay, 2)); ?>

                                    </td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td><?php echo e($receipt->id); ?></td>
                                    <td <?php if($receipt->cheque_id && $receipt->cheque->status == "Rejected"): ?> class="rejected-item" <?php endif; ?>>
                                        سند قبض - <?php echo e($receipt->safe_account_id ? $receipt->safe_account->payment_method->name : ""); ?>

                                    </td>
                                    <td><?php echo e($receipt->created_at->format('d/m/Y')); ?></td>
                                </tr>
                            <?php endforeach; ?>

                            <!-- Review Items -->
                            <?php foreach($client_sheet_item->review_items as $key => $item): ?>
                                <tr>
                                    <?php if(count($client_sheet_item->review_items)-1 == $key): ?>
                                        <td class="final-state-cell"><?php echo e($client_sheet_item->final_state); ?></td>
                                        <td class="final-state-cell"><?php echo e($client_sheet_item->current); ?></td>
                                        <td class="final-state-cell"><?php echo e($client_sheet_item->previos); ?></td>
                                    <?php else: ?>
                                        <td>-</td>
                                        <td>-</td>
                                        <td>-</td>
                                    <?php endif; ?>

                                    <td>-</td>
                                    
                                    <?php if(count($client_sheet_item->review_items)-1 == $key): ?>
                                        <td><?php echo e(number_format($item->review->total_price, 2)); ?></td>
                                    <?php else: ?>
                                        <td>-</td>
                                    <?php endif; ?>

                                    <td>-</td>
                                    <td><?php echo e(number_format($item->price * $item->quantity, 2)); ?></td>
                                    <td><?php echo e(number_format($item->price, 2)); ?></td>
                                    <td><?php echo e($item->quantity); ?></td>
                                    <td><?php echo e($item->invoiceitem->invoice_id); ?></td>
                                    <td style="color: #dc3545;">
                                        مرتجع - <?php echo e($item->invoiceitem->sell_store->store->sell_name); ?>

                                    </td>
                                    <td><?php echo e($item->created_at->format('d/m/Y')); ?></td>
                                </tr>
                            <?php endforeach; ?>
                            
                            <!-- discount -->
                            <?php foreach($client_sheet_item->discounts as $key => $dis): ?>
                                 
                                <tr>
                                    <td class="final-state-cell"><?php echo e($client_sheet_item->final_state); ?></td>
                                    <td class="final-state-cell"><?php echo e($client_sheet_item->current); ?></td>
                                    <td class="final-state-cell"><?php echo e($client_sheet_item->previos); ?></td>
                                    
                                    <td>-</td>
                                    <td>-</td>

                                    <td> <?php echo e($dis->value); ?></td>
                                    
                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td><?php echo e($dis->id); ?></td>
                                    <td >
                                        خصم نقدي  
                                    
                                    </td>
                                    <td><?php echo e($dis->created_at->format('d/m/Y')); ?></td>
                                </tr>
                            <?php endforeach; ?>


                        <?php endforeach; ?>

                        <!-- Summary Row -->
                        <?php 
                            $final_state = $client_sheets ? $client_sheets[count($client_sheets)-1]->final_state : "";
                            $final_current = $client_sheets ? $client_sheets[count($client_sheets)-1]->current : "";
                         ?>
                        <tr class="summary-row">
                            <th><?php echo e($final_state); ?></th>
                            <th><?php echo e($final_current); ?></th>
                            <th></th>
                            <th><?php echo e(number_format($total_payments, 2)); ?></th>
                            <th></th>
                            <th></th>
                            <th><?php echo e(number_format($total_price, 2)); ?></th>
                            <th></th>
                            <th><?php echo e($total_amount); ?></th>
                            <th colspan="3"></th>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.masterHome2', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>