

<?php $__env->startSection('content'); ?>

<?php if(session('success')): ?>
    <div class="alert alert-success mt-3">
        <?php echo e(session('success')); ?>

    </div>
<?php endif; ?>

<?php if(session('error')): ?>
    <div class="alert alert-danger mt-3">
        <?php echo e(session('error')); ?>

    </div>
<?php endif; ?>

<div class="container py-4" dir="rtl">
    <div class="card shadow">
        <!-- رأس البطاقة -->
        <div class="card-header  text-white text-right" style="background-color:#2C4E71" id="ppdiscount">
            <div class="d-flex justify-content-between align-items-center">
                <h4 class="mb-0">تفاصيل مراجعة الخصم #<?php echo e($discount->id); ?></h4>
                 
            </div>
            <div class="mt-2 text-right">
                <span id="ppdiscount" class="badge badge-<?php echo e($discount->status == 'Approved' ? 'success' : ($discount->status == 'Rejected' ? 'danger' : 'warning')); ?>">
                    <?php if($discount->status == 'Approved'): ?> معتمد <?php elseif($discount->status == 'Rejected'): ?> مرفوض <?php else: ?> قيد المراجعة <?php endif; ?>
                </span>
                <span class="ml-2">العميل: <?php echo e($discount->client->name); ?></span>
                <span class="ml-2">التاريخ: <?php echo e($discount->created_at->format('Y-m-d')); ?></span>
                <span class="ml-2">الإجمالي: <?php echo e(number_format($discount->value, 2)); ?> ج.م</span>
            </div>
        </div>

        <!-- محتوى البطاقة -->
        <div class="card-body">
            <!-- جدول الأصناف -->
            <div class="table-responsive mb-4">
                <table class="table table-bordered table-hover text-right">
                    <thead class="thead-light">
                        <tr>
                            <th width="30%">العميل</th>
                            <th width="15%">التاريخ</th>
                            <th width="15%">الإجمالي</th>
                            <th > السبب</th>
                        </tr>
                    </thead>
                    <tbody>
                         <tr>
                            <td><?php echo e($discount->client->name); ?></td>
                            <td> <?php echo e($discount->created_at->format('Y-m-d')); ?> </td>
                            <td><?php echo e(number_format($discount->value, 2)); ?> ج.م</td>
                            <td><?php echo e($discount->reason); ?></td>
                        </tr>
                    </tbody>
                    <tfoot>
                         
                    </tfoot>
                </table>
            </div>

            <!-- ملاحظات المراجعة -->
           

            <!-- حالة التسوية (إذا كانت مكتملة) -->
            <?php if($discount->status == 'Approved'): ?>
            <div class="alert alert-success text-right" id="ppdiscount">
                <h5><i class="fas fa-check-circle ml-2"></i> تمت التسوية</h5>
                <ul class="mb-0" style="list-style-position: inside;">
                    <li><strong>طريقة التسوية:</strong> 
                    
                    <?php echo e($discount->setlement_method == 1 ? 'خصم مباشر من حساب العميل' : ''); ?>  
                    <?php echo e($discount->setlement_method == 2 ? '  رد منفصل' : ''); ?>

                    <?php echo e($discount->setlement_method == 2 ? "رقم سند الصرف $discount->payment_voucher_id " : ''); ?>             
                   </li>
                    <li><strong>المبلغ:</strong> <?php echo e(number_format($discount->value, 2)); ?> ج.م</li>
                    <li><strong>تاريخ التنفيذ:</strong> <?php echo e($discount->updated_at->format('Y-m-d H:i')); ?></li>
                    
                </ul>
            </div>
            <?php endif; ?>

            <!-- نموذج التسوية (إذا كانت قيد الانتظار) -->
            <?php if($discount->status == 'Waiting'): ?>
            <div class="p-3 border rounded bg-light text-right">
                <h5 class="mb-3 text-right">إجراء التسوية المالية</h5>
                
                <form  role="form" method="POST" action="<?php echo e(url('/discount/save_status')); ?>">
                    <?php echo e(csrf_field()); ?>

                <input type="hidden" class="form-control" id="client_id" name="client_id" value="<?php echo e($discount->client_id); ?>" required>
                <input type="hidden" class="form-control" id="discount_id" name="discount_id" value="<?php echo e($discount->id); ?>" required>
                <input type="hidden" class="form-control" id="value" name="value" value="<?php echo e($discount->value); ?>" required>

                


                 <div class="form-group row">
                        <label class="col-md-3 col-form-label text-right">الحالة:</label>
                        <div class="col-md-9">
                            <select name="status" class="form-control select2 text-right" required>
                                <option value="">-- اختر الحالة --</option>
                                <option value="Approved">موافقة</option>
                                <option value="Rejected"> رفض </option>
                            </select>
                        </div>
                    </div>

                    
                <div class="form-group row">
                        <label class="col-md-3 col-form-label text-right">طريقة التسوية:</label>
                        <div class="col-md-9">
                            <select onchange="check_function(this)" id="setlement_method" name="setlement_method" class="form-control select2 text-right" required>
                                <option value="">-- اختر طريقة التسوية --</option>
                                <option value="1">خصم مباشر من حساب العميل</option>
                                <option value="2">رد منفصل</option>
                            </select>
                        </div>
                    </div>
                    

                    <div  id="div_hidden"  style="display: none">
                     <div class="form-group row"  >
                        <label class="col-md-3 col-form-label text-right">رقم سند الصرف:</label>
                        <div class="col-md-9">
                            <div class="form-group">
                                   <input type="number" id="payment_voucher_id" name="payment_voucher_id" min="0" step="0.01" class="form-control">
                            </div>

                        </div>
                    </div> 
                </div>



                    
                    <div class="form-group row mb-0">
                        <div class="col-md-9 offset-md-3">
                            <button type="submit" class="btn btn-primary float-left">
                                <i class="fas fa-check-circle ml-2"></i> تنفيذ التسوية
                            </button>
                        </div>
                    </div>
                </form>

                    </div>
            <?php endif; ?>
        </div>
    </div>
</div>




<script>
function check_function (sel){


let setlement_method = sel.value;


let div_hidden = document.getElementById('div_hidden');

console.log(div_hidden);

if( setlement_method == "2"){
  div_hidden.style.display = "block";
}else {
  div_hidden.style.display = "none";
}

}
</script>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('styles'); ?>
<style>
    /* تخصيصات RTL */
    body {
        text-align: right;
        direction: rtl;
    }
    .table {
        direction: rtl;
    }
    .badge-success { background-color: #28a745; }
    .badge-warning { background-color: #ffc107; color: #212529; }
    .badge-danger { background-color: #dc3545; }
    .text-success { color: #28a745 !important; }
    .text-danger { color: #dc3545 !important; }
    .table-hover tbody tr:hover { background-color: rgba(0, 123, 255, 0.1); }
    
    /* تعديلات Bootstrap RTL */
    .input-group-prepend {
        margin-left: -1px;
        margin-right: 0;
    }
    .form-control, .form-select {
        text-align: right;
    }
    .select2-container--default .select2-selection--single .select2-selection__rendered {
        text-align: right;
    }
    .float-left {
        float: right !important;
    }
    .text-right {
        text-align: right !important;
    }
    .ml-2 {
        margin-right: 0.5rem !important;
        margin-left: 0 !important;
    }
    .hidden { display:none; }
</style>





<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.masterHome2', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>