
<?php $__env->startSection('content'); ?>
    <?php Fun::lang()?>
    <div class="page">
        <div class=container-fluid>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12">
                        <div class="title-add">
                            <div class="pull-left">
                                <h3><?php echo e(__('administrator.warehouse')); ?></h3>
                            </div>
                            <div class="pull-right">
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Warehouse Create')): ?>
                                    <a onclick="getHtmlForm('<?php echo e(route('warehouse.create')); ?>','<?php echo e(__('administrator.create')); ?> <?php echo e(__('administrator.warehouse')); ?>','500px')" class=" button_info">
                                        <span class="fa fa-plus"></span> <?php echo e(__('administrator.new_warehouse')); ?>

                                    </a>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="wrapper-table">
                <table id="datatable" width="100%" class="table table-striped table-hover ">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th><?php echo e(__('administrator.branch')); ?></th>
                        <th><?php echo e(__('administrator.warehouse_name')); ?></th>
                        <th><?php echo e(__('administrator.warehouse_type')); ?></th>
                        <th><?php echo e(__('administrator.tailor')); ?></th>
                        <th><?php echo e(__('administrator.description')); ?></th>
                        <th><?php echo e(__('administrator.action')); ?></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $__currentLoopData = $data; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php
                            $br = findBranch($value->branch_id);
                            $bg = '';
                            if($value->warehouse_type=='item'){
                                $bg = 'bg-success';
                            }elseif($value->warehouse_type=='material'){
                                $bg = 'bg-warning';
                            }elseif($value->warehouse_type=='fabric'){
                                $bg = 'bg-info';
                            }elseif($value->warehouse_type=='cut_piece'){
                                $bg = '';
                            }else{
                                 $bg = 'bg-danger';
                            }
                            $tailor = findTailor($value->tailor_id);
                            $check_wh = \App\Model\stock_inventory\StockModel::where('warehouse_id',$value->id)->first();
                        ?>
                        <tr>
                            <td class="<?php echo e($bg); ?>"><?php echo e($key+1); ?></td>
                            <td class="<?php echo e($bg); ?>"><?php echo e($br?$br->name:''); ?></td>
                            <td class="<?php echo e($bg); ?>"><span class="wh_name"><?php echo e($value->warehouse_name); ?></span></td>
                            <td class="<?php echo e($bg); ?>"><?php echo e($value->warehouse_type?getWarehouseType($value->warehouse_type):''); ?></td>
                            <td class="<?php echo e($bg); ?>"><?php echo e($tailor?$tailor->name:''); ?></td>
                            <td class="<?php echo e($bg); ?>"><?php echo e($value->description); ?></td>
                            <td style="width: 200px;" class="<?php echo e($bg); ?>">
                                <?php
                                    $user_role = Auth::user()->branch_id;
                                    $user_role = findBranch($user_role);
                                 ?>
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Warehouse Edit')): ?>
                                    <a data-href="<?php echo e(route('warehouse.edit',$value->id)); ?>"
                                       class="button_warning btn-edit"><?php echo e(__('administrator.edit')); ?></a>
                                <?php endif; ?>
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Warehouse Set-main')): ?>
                                        <?php if($user_role->main===1 || 1): ?>

                                        <?php if($value->warehouse_type !== 'tailor' && $value->warehouse_type !== 'cut_piece'): ?>
                                        <a herf="#"
                                           class="
                                <?php if($value->main==1): ?>
                                               button_primary
                                        <?php else: ?>
                                               button_info
                                        <?php endif; ?>"
                                           <?php if($value->main==0): ?>
                                           onclick="set_main('<?php echo e($value->id); ?>')"
                                            <?php endif; ?> >
                                            <?php if($value->main==1): ?>
                                                <?php echo e(__('administrator.main')); ?>

                                            <?php else: ?>
                                                <?php echo e(__('administrator.set')); ?>

                                            <?php endif; ?>
                                        </a>
                                    <?php endif; ?>
                                    <?php endif; ?>
                                <?php endif; ?>
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Delete Warehouse')): ?>
                                    <?php if(!$check_wh): ?>
                                        <a class="button_danger btn_delete"
                                           data-href="<?php echo e(route('warehouse.delete')); ?>?id=<?php echo e($value->id); ?>"><?php echo e(__('administrator.delete')); ?></a>
                                    <?php endif; ?>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

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

    <script type="text/javascript">
        let table_ =  $('#datatable');
        table_.DataTable({
            "lengthMenu": [20, 30, 50,100]
        });
        table_.on('click', '.btn_delete', function () {
            let text = $(this).closest('tr').find('.wh_name').text();
            let url = $(this).data('href');
            $.confirm({
                theme: 'modern',
                title: '<?php echo e(__('administrator.are_you_sure')); ?>',
                content: 'Warehouse Name :' + text,
                buttons: {
                    delete: {
                        btnClass: 'button_danger',
                        text: '<?php echo e(__('administrator.delete')); ?>',
                        action: function () {
                            $.ajax({
                                method: 'get',
                                url: url,
                                success: function (res) {
                                    if (res) {
                                        window.location.reload();
                                    }
                                },
                                error: function (xhr) {
                                    alertErrorFormController(xhr);
                                }
                            });
                        }
                    },
                    cancel: {
                        btnClass: 'button_warning',
                        text: '<?php echo e(__('administrator.cancel')); ?>',
                        action: function () {

                        }
                    },
                }
            });
        });
        table_.on('click', '.btn-edit', function () {
            let url = $(this).data('href');
            getHtmlForm(url, '<?php echo e(__('administrator.edit')); ?> <?php echo e(__('administrator.warehouse')); ?>', '500px')
        });
        function set_main(id) {
            if ($.confirm({
                title: '<strong style="color:darkcyan;"><?php echo e(__('administrator.change_status')); ?></strong>',
                content: "<b>Want to Change Main Warehouse ? "
                    + " </b>Then Click OK",

                buttons: {
                    '<?php echo e(__('administrator.cancel')); ?>': {
                        btnClass: 'btn-red',
                        action: function () {
                        }

                    },
                    '<?php echo e(__('administrator.ok')); ?>': {
                        btnClass: 'btn-blue',
                        action: function () {
                            $.ajax({
                                type: "GET",
                                dataType: "json",
                                url: '<?php echo e(route("warehouse_changeStatus")); ?>',
                                data: {'id': id},
                                success: function (data) {
                                    location.reload();
                                }
                            });
                        }
                    }
                }
            }))

                return false;
        }
    </script>
<?php $__env->stopSection(); ?>




<?php echo $__env->make(branchMenu(), \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/nsowos/public_html/shr-brand/resources/views/administrator/setup/warehouse/index.blade.php ENDPATH**/ ?>