

<?php $__env->startSection('content'); ?>
    <?php
        $client = optional($item->client ?? $item->person);
        $creator = optional($item->creator);
    ?>

    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                معاينة المرتجع رقم <?php echo e($item->id); ?>


                <span style="float:left; display:flex; gap:5px; align-items:center;">
                    <a class="btn btn-primary btn-sm" href="<?php echo e(route('returns.print', $item->id)); ?>" target="_blank">
                        <i class="fa fa-print"></i> طباعة منسقة
                    </a>

                    <?php if($currentUser->can('Edit Returns')): ?>
                        <a title="تعديل" href="<?php echo e(route('returns.edit', $item)); ?>" class="btn btn-warning btn-sm">
                            <i class="fa fa-pencil fa-fw" aria-hidden="true"></i> تعديل
                        </a>
                    <?php endif; ?>

                    <?php if($item->total_due && $currentUser->can('addPayment Returns')): ?>
                        <a title="سند قبض" data-toggle="modal" data-target="#myModal" href="<?php echo e(route('returns.addPayment', $item->id)); ?>" class="btn btn-success btn-sm">
                            <i class="fa fa-money fa-fw" aria-hidden="true"></i> سند قبض
                        </a>
                    <?php endif; ?>
                </span>

                <div style="clear:both;"></div>
            </h1>
        </section>

        <section class="content">
            <div class="nav-tabs-custom">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#tab_1" data-toggle="tab">بيانات المرتجع</a></li>
                    <li><a href="#tab_3" data-toggle="tab">الصور والمرفقات</a></li>
                    <li><a href="#tab_4" data-toggle="tab">التحصيلات</a></li>
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('qtyReview Returns')): ?>
                        <li><a href="#tab_6" data-toggle="tab">إستلام قطع الغيار</a></li>
                    <?php endif; ?>
                </ul>

                <div class="tab-content">
                    <div class="tab-pane active" id="tab_1">
                        <div class="row">
                            <div class="col-xs-12">
                                <div class="box box-primary">
                                    <div class="box-header with-border">
                                        <h3 class="box-title">بيانات المرتجع</h3>
                                    </div>

                                    <div class="box-body box-success">
                                        <table class="table table-bordered table-striped preview-summary-table">
                                            <tr>
                                                <td>العميل</td>
                                                <td><?php echo e($client->name ?? '-'); ?></td>
                                            </tr>
                                            <tr>
                                                <td>تاريخ المرتجع</td>
                                                <td><?php echo e($item->date ?? '-'); ?></td>
                                            </tr>
                                            <tr>
                                                <td>المستخدم</td>
                                                <td><?php echo e($creator->name ?? '-'); ?></td>
                                            </tr>
                                            <tr>
                                                <td>الإجمالي</td>
                                                <td><?php echo e(number_format((float) $item->total, 2)); ?></td>
                                            </tr>
                                        </table>

                                        <hr>

                                        <table class="table table-bordered table-striped preview-items-table">
                                            <thead>
                                                <tr>
                                                    <th style="width:60px;">#</th>
                                                    <th>الصنف</th>
                                                    <th style="width:120px;">السعر</th>
                                                    <th style="width:120px;">الكمية</th>
                                                    <th style="width:140px;">الإجمالي</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php $__currentLoopData = $item->details; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $d): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <tr>
                                                        <td><?php echo e($loop->iteration); ?></td>
                                                        <td><?php echo e($d->name); ?></td>
                                                        <td><?php echo e($d->pivot->price); ?></td>
                                                        <td><?php echo e($d->pivot->qty); ?></td>
                                                        <td><?php echo e($d->pivot->qty * ($d->pivot->price - $d->pivot->discount)); ?></td>
                                                    </tr>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </tbody>
                                            <tfoot>
                                                <tr>
                                                    <th colspan="4" style="text-align:center;">الإجمالي</th>
                                                    <th><?php echo e(number_format((float) $item->total, 2)); ?></th>
                                                </tr>
                                            </tfoot>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="tab-pane" id="tab_3">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="box box-primary">
                                    <div class="box-header with-border">
                                        <h3 class="box-title">الصور والمرفقات</h3>
                                    </div>
                                    <div class="box-body box-success">
                                        <table class="table table-bordered">
                                            <?php $i = 1; ?>

                                            <?php if(isset($item) && optional($item->getFirstMedia('images'))->getUrl()): ?>
                                                <?php $__currentLoopData = $item->getMedia('images'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $image): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <tr>
                                                        <td style="width:60px;"><?php echo e($i); ?></td>
                                                        <td>
                                                            <a target="_blank" href="<?php echo e($image->getUrl()); ?>">
                                                                <img style="width: 200px;" src="<?php echo e($image->getUrl()); ?>" />
                                                            </a>
                                                        </td>
                                                    </tr>
                                                    <?php $i++; ?>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            <?php endif; ?>

                                            <?php if($item->details): ?>
                                                <?php $__currentLoopData = $item->details; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $d): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php $__currentLoopData = $d->getMedia('attachments'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $image): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <?php
                                                            $filepath = $image->getUrl();
                                                            $extension = $image->mime_type;
                                                        ?>
                                                        <tr>
                                                            <td style="width:60px;"><?php echo e($i); ?></td>
                                                            <td>
                                                                <?php if(in_array($extension,['image/jpeg','image/png'])): ?>
                                                                    <a target="_blank" href="<?php echo e($image->getUrl()); ?>">
                                                                        <img style="width: 200px;" src="<?php echo e($filepath); ?>">
                                                                    </a>
                                                                <?php else: ?>
                                                                    <a target="_blank" href="<?php echo e($filepath); ?>" class="btn btn-sm btn-warning">عرض</a>
                                                                <?php endif; ?>
                                                            </td>
                                                        </tr>
                                                        <?php $i++; ?>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            <?php endif; ?>

                                            <?php if(isset($item) && optional($item->getFirstMedia('attachments'))->getUrl()): ?>
                                                <?php $__currentLoopData = $item->getMedia('attachments'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $file): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php
                                                        $filepath = $file->getUrl();
                                                        $extension = $file->mime_type;
                                                    ?>
                                                    <tr>
                                                        <td style="width:60px;"><?php echo e($i); ?></td>
                                                        <td>
                                                            <?php if(in_array($extension,['image/jpeg','image/png'])): ?>
                                                                <a target="_blank" href="<?php echo e($filepath); ?>">
                                                                    <img style="width: 200px;" src="<?php echo e($filepath); ?>">
                                                                </a>
                                                            <?php else: ?>
                                                                <a target="_blank" href="<?php echo e($filepath); ?>" class="btn btn-sm btn-warning">عرض</a>
                                                            <?php endif; ?>
                                                        </td>
                                                    </tr>
                                                    <?php $i++; ?>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            <?php endif; ?>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="tab-pane" id="tab_4">
                        <div class="row">
                            <div class="col-xs-12">
                                <div class="box box-primary">
                                    <div class="box-header with-border">
                                        <h3 class="box-title">التحصيلات</h3>
                                    </div>
                                    <div class="box-body">
                                        <table class="table table-bordered table-striped">
                                            <thead>
                                                <tr>
                                                    <th>#</th>
                                                    <th>البيان</th>
                                                    <th>التاريخ</th>
                                                    <th>الموظف</th>
                                                    <th>المبلغ</th>
                                                    <th>المرفقات</th>
                                                    <th></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php $__currentLoopData = $item->transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $col): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <tr>
                                                        <td><?php echo e($loop->iteration); ?></td>
                                                        <td><?php echo e($col->note); ?></td>
                                                        <td><?php echo e($col->trans_date); ?></td>
                                                        <td><?php echo e(optional($col->creator)->name); ?></td>
                                                        <td><?php echo e(abs($col->value)); ?></td>
                                                        <td>
                                                            <?php
                                                                $image = optional($col->getFirstMedia('images'));
                                                                $filepath = $image->getUrl();
                                                                $extension = $image->mime_type;
                                                            ?>
                                                            <?php if($filepath): ?>
                                                                <?php if(in_array($extension,['image/jpeg','image/png'])): ?>
                                                                    <a target="_blank" href="<?php echo e($image->getUrl()); ?>">
                                                                        <img style="width: 100px;" src="<?php echo e($filepath); ?>">
                                                                    </a>
                                                                <?php else: ?>
                                                                    <a target="_blank" href="<?php echo e($filepath); ?>" class="btn btn-sm btn-warning">عرض</a>
                                                                <?php endif; ?>
                                                            <?php endif; ?>
                                                        </td>
                                                        <td>
                                                            <?php if($currentUser->can('Edit Transactions')): ?>
                                                                <a title="تعديل" href="<?php echo e(route('transactions.edit', $col)); ?>" class="btn btn-primary btn-xs">
                                                                    <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>
                                                                </a>
                                                            <?php endif; ?>
                                                            <?php if($currentUser->can('Delete Transactions')): ?>
                                                                <a title="حذف" class="btn btn-xs btn-danger remove-record" data-url="<?php echo e(route('transactions.destroy', $col)); ?>" data-id="<?php echo e($col->id); ?>">
                                                                    <i class="fa fa-trash"></i>
                                                                </a>
                                                            <?php endif; ?>
                                                            <?php if($currentUser->can('Show Transactions')): ?>
                                                                <a title="طباعة" href="<?php echo e(route('transactions.show', $col)); ?>" class="btn btn-info btn-xs">
                                                                    <i class="fa fa-print" aria-hidden="true"></i>
                                                                </a>
                                                            <?php endif; ?>
                                                        </td>
                                                    </tr>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('qtyReview Returns')): ?>
                        <div class="tab-pane" id="tab_6">
                            <div class="row">
                                <div class="col-xs-12">
                                    <div class="box box-primary">
                                        <div class="box-header with-border">
                                            <h3 class="box-title">إستلام قطع الغيار</h3>
                                        </div>
                                        <div class="box-body">
                                            <form method="post" action="<?php echo e(route('returns.qtyReview')); ?>">
                                                <?php echo csrf_field(); ?>
                                                <input type="hidden" name="branche_id" value="<?php echo e($item->branche_id); ?>">
                                                <table class="table table-bordered table-striped">
                                                    <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>الكود</th>
                                                            <th>الصنف</th>
                                                            <th>الكمية</th>
                                                            <th>الحالة</th>
                                                            <th>ملحوظة</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php $__currentLoopData = $item->details; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $d): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <tr>
                                                                <td><?php echo e($loop->iteration); ?></td>
                                                                <td><?php echo e($d->code); ?></td>
                                                                <td><?php echo e($d->name); ?></td>
                                                                <td><?php echo e($d->pivot->qty); ?></td>
                                                                <td>
                                                                    <input type="hidden" name="prod[<?php echo e($loop->iteration); ?>][detail_id]" value="<?php echo e($d->pivot->id); ?>">
                                                                    <input type="hidden" name="prod[<?php echo e($loop->iteration); ?>][product_id]" value="<?php echo e($d->id); ?>">
                                                                    <input type="hidden" name="prod[<?php echo e($loop->iteration); ?>][qty]" value="<?php echo e($d->pivot->qty); ?>">
                                                                    <select class="form-control" name="prod[<?php echo e($loop->iteration); ?>][item_status]">
                                                                        <option <?php echo e($d->pivot->item_status == 'قيد المراجعة' ? 'selected' : ''); ?> value="قيد المراجعة">قيد المراجعة</option>
                                                                        <option <?php echo e($d->pivot->item_status == 'تم الاستلام' ? 'selected' : ''); ?> value="تم الاستلام">تم الاستلام</option>
                                                                        <option <?php echo e($d->pivot->item_status == 'مرفوض' ? 'selected' : ''); ?> value="مرفوض">مرفوض</option>
                                                                    </select>
                                                                </td>
                                                                <td>
                                                                    <input type="text" class="form-control" name="prod[<?php echo e($loop->iteration); ?>][item_note]" value="<?php echo e($d->pivot->item_note); ?>">
                                                                </td>
                                                            </tr>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </tbody>
                                                </table>
                                                <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> حفظ</button>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </section>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('css'); ?>
<style>
    .preview-summary-table td,
    .preview-items-table td,
    .preview-items-table th {
        text-align: center !important;
        vertical-align: middle !important;
    }

    .preview-items-table tfoot th {
        background: #f5f5f5;
        font-weight: bold;
    }
</style>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.front', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/mwarsha2023/public_html/test4.mwarsha.com/resources/views/returns/show.blade.php ENDPATH**/ ?>