<?php $__env->startSection("styles"); ?>

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

<?php $__env->startPush("js"); ?>

    <script>
        var $main_tab_content = $("#tab-content-stocks-management");

        var showPreviewValidateImportData = function(warehouse_id){
            let data = {
                'warehouse_id' : warehouse_id,
                'operation' : "show-dt-validate-preview",
            };
            
            
        };

        var showModalNouveauTransfertStock = function(warehouse_id){
            let data = {
                'warehouse_id' : warehouse_id,
                'operation' : "show-modal-nouveau-transfert-stock",
            };
            
            
        };

        var showModalNouvelleDemandeStock = function(sender_id,sender_type){
            let data = {
                'sender_id' : sender_id,
                'sender_type' : sender_type,
            };
            
            
        };

            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("st-request-create")): ?>
            var showModalNewAdvancedDemandeStock = function(){
                
                
            };
            <?php endif; ?>

        var showModalEditLotsDemand = function(id_demand,id_table_demande ){
                let data = {
                    'id_demand' : id_demand,
                    'id_table_demande' : id_table_demande,
                };
                
                
            };


        var openOrClosePVs = function () {
            let $toogles = $('input[name=switch-pvs][type=checkbox]');
            let val = [];
            $.each($toogles,function() {
                let $this = $(this);
                val.push({
                    'state' : $this.prop('checked'),
                    'id_pv' : $this.attr('data-id-pv'),
                });
            });

            let url = 'admin/login';
            let param = {body: {datas : val}, method:'post',};

            swal.fire({
                title: '<?php echo e(__("Clôture de points de ventes")); ?>',
                text : "<?php echo e(__("Confirmer les modifications?")); ?>",
                icon: 'question',
                showCancelButton : true,
                showConfirmButton: true,
                reverseButtons : true,
                cancelButtonText : '<?php echo e(__("Non")); ?>',
                confirmButtonText : '<?php echo e(__("Oui")); ?>',
            })
                .then((result) => {
                    if (result.isConfirmed) {
                        request(url,param)
                            .then(reponse => {
                                let success = reponse.is_success;
                                toast({title:reponse.message,icon : (success) ? "success" : "error"});
                                if(success){
                                    hideModal();
                                }
                            });
                    }
                });
        };

        var receiveTransferts = function(id_table){
            let data = [];

            $("table#"+id_table+' tbody tr.selected')
                .each(function (index) {
                    let $input = $(this).find("td input[type='number']");
                    let $select = $(this).find("td select");
                    let values = {
                        'id_transfert': $input.attr('data-id-transfert'),
                        "received_qty": $input.val(),
                        "id_type_ajustement": $select.val(),
                    };
                    data.push(values);
                });

            let count = data.length;

            if(count > 0){
                swal.fire({
                    title: "<?php echo e(__('Stocks en Transit')); ?>",
                    text: "<?php echo e(__("Recevoir ces stocks ?")); ?>",
                    icon: 'question',
                    showCancelButton : true,
                    reverseButtons : true,
                    confirmButtonText: '<?php echo e(__("Oui")); ?>',
                    cancelButtonText: '<?php echo e(__("Non")); ?>',
                })
                    .then((result) => {
                        if (result.isConfirmed) {
                            let param = {
                                body: { datas : data,},
                                method:'post',
                            };
                            let url = "";

                            request(url,param)
                                .then(result => {
                                    // if(!result.is_success){}
                                    $("#"+id_table).DataTable().draw();
                                    let type = (result.is_success) ? "success" : 'error';
                                    toast(type,{'title' : "<?php echo e(__('Transit')); ?>","msg" : result.message});
                                });
                        }
                    });
            }
            else{
                toast("error",{'title':"<?php echo e(__('Transit')); ?>","msg":"<?php echo e(__("Veuillez cochez au moins 01 ligne dans le tableau.")); ?>"});
            }
        };

        var getSelectedDatasInTableDemande = function(id_table){
            let data = [];
            let table = $("#"+id_table).DataTable();
            $("#"+id_table+" tbody tr.selected").each(function (index,tr) {
                let rowData = table.row(tr).data();
                data.push(rowData.id);
            });
            return data;
        };

        var changeStatutDemand = function($btn){
            let id_table = $btn.attr('data-id-table');
            let datas = getSelectedDatasInTableDemande(id_table);
            let url = $btn.attr("data-url");

            if (datas.length > 0){
                swal.fire({
                    icon: 'question',
                    title: "<?php echo e(__('Demands')); ?>",
                    text: "<?php echo e(__("Put")); ?> "+datas.length+" <?php echo e(__('row(s)')); ?> "+$btn.attr("data-libelle-statut")+" ?",
                    showCancelButton: true,
                    confirmButtonText: '<?php echo e(__("Yes")); ?>',
                    cancelButtonText: '<?php echo e(__("No")); ?>',
                })
                    .then((result) => {
                        if (result.isConfirmed) {
                            let param = { body: {ids : datas}, method:'post',};
                            request(url,param)
                                .then(result => {
                                    refresh_datatable(id_table);
                                    toast({icon : result.type, title :result.title,text : result.message});
                                });
                        }
                    });
            }else{
                toast({icon:"error", title :'<?php echo e(__("Veuillez cochez au moins 01 ligne dans le tableau.")); ?>'});
            }
        };


        var loadEditorUploadStock = function (warehouse_id,formTitle,tableId,config) {
            uploadStockEditor.field("warehouse_id").s.opts.def = warehouse_id ;

            uploadStockEditor.create({
                title: formTitle,
                message: `<div class="fs-13 font-weight-bold text-center m-b-20">
                            <div>Upload your stocks files</div>
                             <div>
                                 <a href="<?php echo e(url('backend/uploads/stock-imports-model.xlsx')); ?>"
                                     target="_blank"
                                     class="kt-font-info fs-10 text-underline text-blue">
                                     Click here to get a file model
                                 </a>
                             </div>
                         </div>`,
                buttons: {
                    className: "btn-success",
                    text: "<?php echo e(__("Import")); ?> <i class='fa fa-upload' />",
                    action: function () {
                        this.submit(
                            function (response) {
                                const that = this;
                                $(".DTE_Form_Error").hide();
                                if (('fieldErrors' in response) && !$.isEmptyObject(response.fieldErrors)){
                                    response.fieldErrors.forEach(error => {
                                       that.field(error.name).error(error.status)
                                    });
                                    return ;
                                }

                                const success = response.success ?? false;
                                if(success) {
                                    refresh_datatable(tableId);
                                    dispatchBrowserEvent("stocks:importations.preview.loaded",{warehouse_id})
                                }
                                toast({title : response.message , icon : success ? "success" : 'error' })
                            },
                            (response) =>{
                                $(".DTE_Form_Error").show().html(response.message)
                            },
                            false,
                            true //  close modal
                        );
                    },

                }
            });
        };

        var loadEditorCreateLot = function (warehouse_id,formTitle,tableId,config) {
            createLotEditor.field("warehouse_id").s.opts.def = warehouse_id ;
            createLotEditor.create({
                title: formTitle,
                buttons: {
                    className: config.className,
                    text: config.attr.icon+config.attr.title,
                    action: function () {
                        this.submit(
                            function (response) {
                                if(typeof response === 'object'){
                                    if (('fieldErrors' in response) && $.isEmptyObject(response.fieldErrors)){
                                        if (response.success){
                                            toast({title: response.message,});
                                            refresh_datatable(tableId);
                                            loadEditorCreateLot(warehouse_id,formTitle,tableId,config);
                                            return ;
                                        }
                                    }
                                    if (('message' in response) && !response.success){
                                        toast({icon : "error",'title':response.message});
                                    }
                                }
                            },
                            false,
                            false,
                            false //  close modal
                        );
                    },

                }
            });
        };

        var loadEditorCreateAdjustment = function (stock,tableId) {
             createAdjustmentEditor.field("stock_id").s.opts.def = stock.id ;
             createAdjustmentEditor.field("info").s.opts.def = stock.info ;
             createAdjustmentEditor.s.table = "#"+tableId;
             createAdjustmentEditor.create({
                title : "<?php echo e(strtoupper(__("Adjustment"))); ?> : "+stock.lot_id,
                buttons: {
                    className: "btn-success",
                    text: "<?php echo e(__("Adjust")); ?> <i class='fa fa-save' />",
                    action: function () {
                        this.submit(
                            function (response) {
                                if(typeof response === 'object'){
                                    if (('fieldErrors' in response) && $.isEmptyObject(response.fieldErrors)){
                                        if (response.success){
                                            toast({icon : "success",title: response.message});
                                            refresh_datatable(tableId);
                                            //loadEditorCreateAdjustment(stock,tableId);
                                            return ;
                                        }
                                    }
                                    if (('message' in response) && !response.success){
                                        toast({icon : "error",'title':response.message});
                                    }
                                }
                            },
                            false,
                            false,
                            true //  close modal
                        );
                    },

                }
            });
        };

        var getEditorTransferdQtyDemand = function(id_table){
            return DataTableEditor( {
                ajax: {url : "admin/login", type : "post",},
                idSrc:  'id',
                table: "#"+id_table,
                fields: [
                    {
                        label : "<?php echo e(__('Tranfered Qty')); ?>",
                        name : "transfered_qty",
                        data : "transfered_qty",
                        attr : { type : "number", },
                    },
                ]
            } );
        };

        var getEditorReceivedQtyDemand = function(id_table){
            return  DataTableEditor( {
                ajax: {url : "admin/login", type : "post",},
                idSrc:  'id',
                table: "#"+id_table,
                fields: [
                    {
                        label : "<?php echo e(__('Received Qty')); ?>",
                        name : "received_qty",
                        data : "received_qty",
                        attr : { type : "number", }
                    },
                    {
                        label : "<?php echo e(__('Message')); ?>",
                        name : "message_tmp",
                        type :'textarea',
                        data : "message_tmp",
                        attr : {rows : "5", cols : "4",}
                    },
                    {
                        label: "<?php echo e(__('Type')); ?>",
                        name: "id_type_ajustement",
                        type: "select",
                        data : "id_type_ajustement",
                        attr : {
                            "data-plugin-multiselects" : "",
                            "data-plugin-optionss" : '{ "enableCaseInsensitiveFiltering": true}',
                        },
                        options : [],
                    },
                ]
            } );
        };

        let $body_container = $("#body-container");
        let $tabs_content_menus = $body_container.find('#tab-content-menus-entrepots');
        let $menus = $body_container.find('.nav a[data-toggle="tab"]');

        var uploadStockEditor =  DataTableEditor( {
            ajax: {url : "<?php echo e(route('admin.stocks.importations.create')); ?>", type : "post",},
            idSrc:  'id',
            // table: "#"+tableId,
            fields: [
                {
                    label: "<?php echo e(__('Warehouse Id')); ?>",
                    name: "warehouse_id" ,
                    data: "warehouse_id" ,
                    type : "hidden",
                },
                {
                    label: "<?php echo e(__('File')); ?> : ",
                    name: "file" ,
                    type: "upload",
                    display: (id)=> {
                        // return `<img src="${this.file('files',id).web_path}"/>`
                        // return `<img src="${that.editor.file('file',id).web_path}" alt="Preview" style="max-width: 200px; max-height: 200px;">`
                        return `<small class="fs-10 text-primary"> ${id}</small>`
                    },
                    noImageText: 'No File',
                    clearText: 'Remove',
                    fieldInfo: "<?php echo e(__("Excel File(.xlsx, .xls)")); ?>",
                    dragDropText :"Drag and drop your file here.",
                    fileReadText : "Downloading ...",
                    uploadText : "Choose a file",
                    attr : { accept : '.xlsx,.xlx'}
                },
                {
                    label: "<?php echo e(__('My File has headers')); ?> ? ",
                    name: "file_has_headers" ,
                    def:  1,
                    type: "radio",
                    options : [
                        {label : "<?php echo e(yesNo(1)); ?>" , value : 1},
                        {label : "<?php echo e(yesNo(0)); ?>", value : 0},
                    ],
                },
            ]
        } );

        var createLotEditor =  DataTableEditor( {
            ajax: {url : "<?php echo e(route('admin.stocks.create')); ?>", type : "post",},
            idSrc:  'id',
            // table: "#"+tableId,
            fields: [
                {
                    label: "<?php echo e(__('Warehouse Id')); ?>",
                    name: "warehouse_id" ,
                    data: "warehouse_id" ,
                    // def : id_entrepot,
                    type : "hidden",
                },
                {
                    label: "<?php echo e(__('Lot id')); ?>",
                    name: "lot_id" ,
                },
                {
                    label: "<?php echo e(__('Expired At')); ?>",
                    name: "expired_at" ,
                    def : "<?php echo e(date("d-m-Y")); ?>",
                    type : 'datetime',
                    attr: {
                        "readonly" : true,
                        //type : "text",
                        "data-plugin-datepickers" : "",
                        "data-plugin-options" : '{ format:"dd-mm-yyyy"}',
                    }
                },
                {
                    label: "<?php echo e(__('Quantity')); ?>",
                    name: "qty" ,
                    attr: {type : "number",}
                },
                {
                    label : "<?php echo e(__('Product')); ?>",
                    name : "product_id",
                    type :'select',
                    attr : {
                        "data-plugin-multiselect" : "",
                    },
                    options : <?php echo json_encode($products, 15, 512) ?>,
                },
            ]
        } );

        var updateRowStockEditor =  DataTableEditor( {
            ajax: {url : "admin/login", type : "post",},
            idSrc:  'id',
            //table: "#"+tableId,
            fields: [
                {
                    label: "<?php echo e(__('Lot id')); ?>",
                    name: "lot_id" ,
                    data : "lot_id",
                },
                {
                    label: "<?php echo e(__('Expired At')); ?>",
                    name: "expired_at" ,
                    data: "expired_at" ,
                    attr: {
                        "readonly" : true,
                        "data-plugin-datepicker" : "",
                        "data-plugin-options" : '{ format:"dd-mm-yyyy"}',
                    }
                },
                {
                    label : "<?php echo e(__('Product')); ?>",
                    name : "product_id",
                    data : "product_id",
                    type :'select',
                    attr : {
                        "data-plugin-multiselect" : "",
                    },
                    options : <?php echo json_encode($products, 15, 512) ?>,
                },
            ]
        } );

        var createAdjustmentEditor = DataTableEditor( {
            ajax : {
                // "contentType": "application/json, charset=utf-8",
                url : "<?php echo e(route('admin.stocks.adjustments.create')); ?>",
                type : "post",
            },
            idSrc:  'id',
            fields: [
                {
                    label: "<?php echo e(__('Infos')); ?>", name: "info" ,
                    attr: {"readonly" : true, "disabled" : true, class : "bg-success text-white"}
                },
                {label: "<?php echo e(__('Id Stock')); ?>", name: "stock_id" , type : "hidden",},
                { label: "<?php echo e(__('Ajusted Qty')); ?>", name: "qty_adjusted" , attr: {type : "number",}},
                {
                    label : "<?php echo e(__('Operation')); ?>", name : "operation_code", type :'select',
                    attr : {
                        "data-plugin-multiselect" : '',
                        "data-plugin-options" : '{"enableCaseInsensitiveFiltering":false}',
                    },
                    options : <?php echo json_encode($adjustmentsOperations, 15, 512) ?>,
                },
                {
                    label : "<?php echo e(__('Reason')); ?>", name : "reason_code", type :'select',
                    attr : {
                        "data-plugin-multiselect" : '',
                        "data-plugin-options" : '{"enableCaseInsensitiveFiltering":false}',
                    },
                    options : <?php echo json_encode($adjustmentsReasons, 15, 512) ?>,
                },
                {
                    label: "<?php echo e(__('Comment')); ?>", name: "comment" , type :'textarea',
                    attr: { rows : 4, cols : 6,}
                },

            ]
        } );

        var $card = $("#card-stock-management");
        var $warehouse = $card.find();

        var showTableByTabIndex = function(tab_index = 1){
             //console.clear();
            const $tab = $card.find('a[data-toggle="tab"][data-tab-index='+tab_index+']');
            const tableId = $tab.attr("data-id-table");
            let has_checkbox = $tab.attr("data-has-checkbox");
            const table_html = $('#'+tableId);
            const $parentActiveTab = $("ul#tab-stocks-management a.active");
            const $parentActiveTabContent = $($parentActiveTab.attr("href"))
            const $warehouse = $parentActiveTabContent.find("select.warehouse-filter");
            let datatable;
            let url = $tab.attr('data-route');
            let cols = [];
            let options = {
                lengthChange: true,
                processing: true,
                serverSide: true,
                dom : "Bfrtilp",
                // ajax : {
                //     url : url,
                //     type : "get",
                //     data : function (d) {
                //           d.warehouse_id = $warehouse.val();
                //     }
                // }
            };
            console.log("active-tab-index = "+tab_index );
            if($warehouse.length){
                url += "?warehouse_id="+$warehouse.val()
            }
            let buttons = [
                { extend: "reload" },
                { extend: "export", },
            ];


            let table_filter_dates = [
                4, //ajustements
                5, //demandes
                51, //demandes-reçues
                511, //demandes-reçues-pv
                512, //demandes-reçues-magasin
                52, //demandes-reçues-magasin
                521, //demandes-reçues-magasin
                522, //demandes-reçues-magasin

                6, //transits
                61, //transits-pv
                611, //transits-pv-reçues
                612, //transits-pv-envoyées
                62, //transits-magasin
                621, //transits-magasin-reçues
                622, //transits-magasin-envoyées
            ];

           // console.log("table-id = "+tableId)

            if($.inArray(tab_index,[111,112,211,212]) !== -1){ // par Lots
                if($.inArray(tab_index,[111,211]) !== -1){
                    url += "&available_only=true";
                    //options.ajax.data['available_only'] = true;
                }else{
                    url += "&available_only=false";
                }
                cols = [
                    {data: 'lot_id', name: 'lot_id' ,searchable: true,
                        className: "<?php echo e(auth(activeGuard())->user()->can('st-stock-update')
                                   ? "text-success cursor-pointer text-success"
                                   :''); ?> left",
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("st-stock-update")): ?>
                        render: editIcon
                        <?php endif; ?>
                    },
                    {data: 'product_id', name: 'product_id' ,searchable: true, className : 'left',},
                    {data: 'product.name', name: 'name_product' ,searchable: true},
                    {
                        data: 'qty', name: 'qty',
                        searchable: true ,
                        className: "<?php echo e(auth(activeGuard())->user()->can('st-adjustment-create')
                                   ? "text-success cursor-pointer editable qty-editable text-success"
                                   :''); ?> right",
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("st-adjustment-create")): ?>
                        render: editIcon
                        <?php endif; ?>
                    },
                    
                    
                    
                    
                    
                    

                    
                    
                    

                    
                    {data: 'product.category.name', name: 'category' ,searchable: false},
                    {data: 'expired_at', name: 'expired_at',searchable: true,
                        className: "<?php echo e(auth(activeGuard())->user()->can('st-stock-update')
                                   ? "text-success cursor-pointer text-success"
                                   :''); ?> left",
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("st-stock-update")): ?>
                        render: editIcon
                        <?php endif; ?>
                    },

                  //  {data: 'action', name: 'action', searchable: false,},

                ];

                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("st-stock-create")): ?>
                    globalBtnCreate.action = function(e, dt, button, config){
                                                    let formTitle = " <?php echo e(strtoupper(__("New Lot"))); ?> >>>"+ $warehouse.find("option:selected").text();
                                                    loadEditorCreateLot($warehouse.val(),formTitle,tableId,config);
                                                };
                //ajoute le btn à la positon 0
                buttons.unshift(globalBtnCreate);
                <?php endif; ?>
            }
            else if($.inArray(tab_index,[12,22,]) !== -1){ // grouper par id_produit
                cols = [
                    {data: 'product_id', name: 'product_id' ,searchable: true,className: "left"},
                    {data: 'name', name: 'name' ,searchable: true,className: "left"},
                    {data: 'qty', name: 'qty',searchable: false ,className: "right"},
                    {data: 'lots_count', name: 'lots_count',searchable: false ,className: "right"},
                    {data: 'category', name: 'category' ,searchable: false,className: "left"},
                ]
            }
            else if($.inArray(tab_index,[13,23]) !== -1){ // importations
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("st-importations-create")): ?>
                    globalBtnCreate.text = `<i class="fa fa-upload"></i>`;
                    globalBtnCreate.action = function(e, dt, button, config){
                    let formTitle = " <?php echo e(strtoupper(__("Importation"))); ?> >>"+ $warehouse.find("option:selected").text();
                    loadEditorUploadStock($warehouse.val(),formTitle,tableId,config);
                };
                 buttons.push({
                         className: "btn-warning",
                         attr : {
                             title: '<?php echo e(__("Preview imported data")); ?>',
                             icon: '<i class="fa fa-eye"></i> ',
                             "data-toggle":"tooltip",
                             "data-original-title" : '<?php echo e(__("Preview imported data")); ?>',
                         },
                         text: function (dt,button,config) {
                             let label = config.attr.title;
                             return config.attr.icon;
                         },
                         // columns: 'th:nth-child(n+2)',
                         action:  () => {
                             return dispatchBrowserEvent(
                                         "stocks:importations.preview.loaded",
                                         {
                                             warehouse : {
                                                 id : $warehouse.val() ,
                                                 name : $warehouse.find("option:selected").text()
                                             }
                                         }
                                     )
                         }
                     },
                 )
                //ajoute le btn à la positon 0
                buttons.unshift(globalBtnCreate);
                <?php endif; ?>

                    cols = [
                    {data: 'lot_id', name: 'lot_id' ,searchable: true,className: "left"},
                    {data: 'product_id', name: 'product_id' ,searchable: true},
                    {data: 'product_name', name: 'name_product' ,searchable: true},
                    {data: 'real_qty', name: 'stock_reel',searchable: false ,className: "right"},
                    {data: 'theoretical_qty', name: 'theoretical_qty',searchable: false ,className: "right"},
                    {data: 'gap', name: 'gap',searchable: false ,className: "right"},
                    {data: 'product_category', name: 'product_category' ,searchable: false},
                    {data: 'created_by', name: 'created_by',searchable: false},
                    {data: 'expired_at', name: 'expired_at',searchable: false},
                    {data: 'created_at', name: 'created_at',searchable: false},
                ];
            }
            else if($.inArray(tab_index,[14,24]) !== -1){ // ajustements
                cols = [
                    {data: 'stock.lot_id', name: 'lot_id' ,searchable: true,className: "left"},
                    {data: 'product', name: 'product' ,searchable: false},
                    {data: 'qty_before', name: 'qty_before',searchable: true ,className: "right"},
                    {data: 'qty_adjusted', name: 'qty_adjusted',searchable: true ,className: "right"},
                    {data: 'qty_after', name: 'qty_after',searchable: true ,className: "right"},
                    {data: 'reason', name: 'reason',searchable: false ,className: "left"},
                    {data: 'operation', name: 'operation',searchable: false ,className: "left"},
                    {data: 'comment', name: 'comment',searchable: false ,className: "left"},
                    {data: 'created_by', name: 'created_by',searchable: false},
                    {data: 'created_at', name: 'created_at',searchable: false},
                ];
            }

            //[Demandes] PV->Reçues ou Magasin->Reçues
            else if($.inArray(tab_index,[511,521]) !== -1){
                cols = [
                    {data: 'checkbox', name: 'checkbox_all' ,searchable: false,ordering:false,exportable:false,className: "center select-checkbox"},
                    {data: 'lot_id', name: 'lot_id' ,searchable: true,className: "left"},
                    {data: 'expired_at', name: 'expired_at',className: "left",searchable: true,exportable:false},
                    {data: 'product', name: 'product' ,searchable: true,className: "left"},
                    {data: 'requested_qty', name: 'requested_qty',searchable: true ,className: "right"},
                    {data: 'transfered_qty', name: 'transfered_qty',searchable: true ,
                        className: "<?php echo e(auth(activeGuard())->user()->can('st-request-update')
                                   ? "text-success cursor-pointer text-success"
                                   :''); ?> right",
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("st-request-update")): ?>
                        render : editIcon,
                        <?php endif; ?>
                    },
                    {data: 'at', name: 'at',className: "left",searchable: true,exportable:false},
                ];
            }

            //[Demandes] PV->Envoyées ou Magasin->Envoyées
            else if($.inArray(tab_index,[512,522]) !== -1){
                cols = [
                    {data: 'product_id', name: 'product_id' ,searchable: true},
                    {data: 'product.name', name: 'name_product' ,searchable: false},
                    {data: 'requested_qty', name: 'qte',searchable: false ,className: "right"},
                    {data: 'user', name: 'created_by',searchable: false},
                    {data: 'created_at', name: 'created_at',searchable: false},
                ];
            }

            //[Transits] PV->Envoyées ou Magasin->Envoyées
            else if($.inArray(tab_index,[612,622]) !== -1){
                cols = [
                    {data: 'checkbox', name: 'checkbox_all' ,searchable: false,ordering:false,exportable:false,className: " select-checkbox"},
                    {data: 'product_id', name: 'product_id' ,searchable: true},
                    {data: 'product.name', name: 'name_product' ,searchable: false},
                    {data: 'requested_qty', name: 'requested_qty',searchable: false ,className: "right"},
                    {data: 'transfered_qty', name: 'transfered_qty',searchable: false ,className: "right"},
                    {data: 'edit_received_qty', name: 'received_qty',searchable: false ,className: "right"},
                    {data: 'edit_message_tmp', name: 'message',searchable: false ,className: "left",},
                    {data: 'edit_type', name: 'type',searchable: false ,className: "left",},
                    {data: 'statut', name: 'statut',searchable: false},
                ];
            }

            //[Transits] PV->Reçues ou Magasin->Reçues
            else if($.inArray(tab_index,[611,621]) !== -1){
                cols = [
                    {data: 'lot_id', name: 'lot_id' ,searchable: true,className: "left"},
                    {data: 'expired_at', name: 'expired_at',className: "left",searchable: true,exportable:false},
                    {data: 'product', name: 'product' ,searchable: true,className: "left"},
                    {data: 'requested_qty', name: 'requested_qty',searchable: true ,className: "right"},
                    {data: 'transfered_qty', name: 'transfered_qty',searchable: true ,className: "right",},
                    {data: 'received_qty', name: 'received_qty',searchable: true ,className: "right"},
                    {data: 'statut', name: 'statut',searchable: false ,className: "left"},
                ];
            }

            if (has_checkbox){
                options.columnDefs = [ {
                    orderable: false,
                    className: 'select-checkbox',
                    targets:   0,
                    content : "",
                } ];

                options.select = {
                    style :    'multi',
                    selector : 'td.select-checkbox',
                };
            }
            options.ajax = url;

            if ($.fn.dataTable.isDataTable('#'+tableId)){
                let table = table_html.DataTable();
                datatable = table.ajax.url(url).load();
                //datatable = table.draw();
            }
            else{
                append_dt_footer(tableId);
                options.columns = cols; // add columns
                options.buttons = buttons; // add buttons
                datatable = table_html.DataTable(options); // generate datatable
            }

            dispatchBrowserEvent("stocks:dataTable.opened",{
                table_id : tableId,
                warehouse_id : $warehouse.val(),
                url ,
                has_checkbox
            })
            return datatable;
        };
        var active_tab_index = 111;
        $(function () {
            showTableByTabIndex(active_tab_index);

            $card.find('select').on('change',function (e) {
                showTableByTabIndex(active_tab_index);
            });

           // $menus.eq(0).tab("show"); // affiche le premier menus
            $card.find('.nav a[data-toggle="tab"]').on('shown.bs.tab', function(e){
                var $active_tab = $(e.target); // active tab
                 active_tab_index = parseInt($active_tab.attr("data-tab-index"));
               // console.clear();
                //if(active_tab_index > 0){
                    showTableByTabIndex(active_tab_index)
                //}
            });

            // $("button.btn-demande-change-statut").on('click',function (e) {
            //     changeStatutDemand($(this));
            // })
        });
    </script>
    <script>

        $(function () {
            const $first_table = $card.find("div.tab-pane.active.show")
                                          .eq(0)
                                          .find('div.tab-pane.active.show')
                                          .eq(0).find('div.tab-pane.active.show')
                                          .eq(0)
                                          .find("table")
                                          .eq(0)

            if ($first_table){
               // refresh_datatable($first_table.attr('id'));
            }

        });
    </script>
<?php $__env->stopPush(); ?>

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

<div class="card shadow mb-4" id="card-stock-management">
    <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
        <h6 class="m-0 font-weight-bold text-success"><?php echo e($title); ?></h6>
        <div class="dropdown no-arrow">
            <a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink"
               data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400"></i>
            </a>















        </div>
    </div>
    <ul class="nav nav-tabs" id="tab-stocks-management" role="tablist">
        <?php $__currentLoopData = $tabs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $options): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <li class="nav-item">
                <a data-toggle="tab" role="tab"
                   class="nav-link <?php echo e(($loop->first) ?"border-left-0 active show":""); ?>"
                   id="<?php echo e($options['id']); ?>"
                   href="#<?php echo e($options['href']); ?>"
                   aria-controls="<?php echo e($options['id']); ?>"
                   aria-selected="<?php echo e(($loop->first) ?"true":"false"); ?>">
                    <span class="<?php echo e($options['icon']); ?>"></span>
                    <?php echo e(__($options['title'])); ?>

                </a>
            </li>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </ul>

    <div class="tab-content" id="tab-content-stocks-management">
        <?php $__currentLoopData = $tabs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $options): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div role="tabpanel"
                 class="tab-pane fade <?php echo e(($loop->first) ?"active show":""); ?>"
                 id="<?php echo e($options['href']); ?>"
                 aria-labelledby="<?php echo e($options['id']); ?>">
                <?php if ($__env->exists(($options['content']['file']), ['options' => $options])) echo $__env->make(($options['content']['file']), ['options' => $options], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/lekruu/public_html/resources/views/backend/stocks/management/index.blade.php ENDPATH**/ ?>