var grabPartTemp = true; var supplierInvTemp = true;
var completeClosedTemp = true; var documentTemp = true; var workorderTemp = true;
var locationTemp = true;

var vehicleTemp = true;  
var inspectionTemp = true;  
// var scheduleTemp = true;   
var checklistTemp = true; 
var workShopIVCTemp = true; 
var driverTemp = true; 
var inspReminderTemp = true; 

// var WODTemp = true; var FDTemp = true; var inspeTemp = true;
// var logbookTemp = true;
// var tyreTemp = true; var fuelTemp = true; var reportTemp = true;
// var dailyTemp = true; var remainderTemp = true; var woRequestTemp = true;
// var toolsTemp = true; var poTemp = true; //var soTemp = true;
// var mainDashboard = true;var incidentTemp = true;


// var navigationItem23 = new sap.tnt.NavigationListItem({ key: 'p023',enabled:false,expanded: false,text: oBundle.getText('Two_Wheeler'),icon: 'sap-icon://sales-order-item',
// items: [
//             new sap.tnt.NavigationListItem({key: 'p0231',text: oBundle.getText('Maintenance')}),
//             new sap.tnt.NavigationListItem({key: 'p0232',text: oBundle.getText('Vehicles')}),
//             new sap.tnt.NavigationListItem({key: 'p0233',text: oBundle.getText('Team_Management')})
//     ]
// });

var navigationGrab0 = new sap.tnt.NavigationListItem({key:'four_wheeler_dashboard',expanded: true,text: oBundle.getText('Dashboard'),icon: 'sap-icon://grid'});
var navigationGrab1 = new sap.tnt.NavigationListItem({key: 'inspection_report',text: oBundle.getText('Inspection_Report'), icon: 'sap-icon://inspection',
    select:function(){
        if(inspectionTemp){
            funGetInspection();
            inspectionTemp = false;
        }
    }
});
var navigationGrab2 = new sap.tnt.NavigationListItem({key: 'grab_checkpoint',text: oBundle.getText('Inspection_Form'), icon:'sap-icon://form',
    select:function(){
        if(checklistTemp){
            funGetChecklist();
            checklistTemp = false;
        }
    }
});
var navigationGrab3 = new sap.tnt.NavigationListItem({key: 'grab_workorder',text: oBundle.getText('Workorder'), icon: 'sap-icon://wrench'
    ,select: function () {
        if(workorderTemp){
            
            getVerificationWorkorder();
            var currentWorkorderTab = oAppWorkOrderPageLayout.getSelectedSection();
            if(nullCheckAll(currentWorkorderTab)){
                oAppWorkOrderPageLayout.setSelectedSection(currentWorkorderTab);
            }else{
                oAppWorkOrderPageLayout.setSelectedSection("GWO11");
            }
            workorderTemp = false;
        }
      },
});
var navigationGrab4 = new sap.tnt.NavigationListItem({key: 'grab_service_schedule',text: oBundle.getText('Service_Schedule'),icon:'sap-icon://appointment'});
var navigationGrab5 = new sap.tnt.NavigationListItem({key: 'grab_vehicle',text: oBundle.getText('Vehicles'), icon: 'sap-icon://inventory',
    select:function(){
        if(vehicleTemp){
            get4WVehicle();
            vehicleTemp = false;
        }
    }
});
var navigationGrab6 = new sap.tnt.NavigationListItem({key: 'grab_team_management',text: oBundle.getText('Team_Management'), icon: 'sap-icon://employee',
    select: function(){
        if(locationTemp){
            getAllLocationData();
            locationTemp = false;
        }
    }
})
var navigationGrab7 = new sap.tnt.NavigationListItem({key: 'grab_workshop',text: oBundle.getText('Workshop'), icon:'sap-icon://retail-store'})
var navigationGrab8 = new sap.tnt.NavigationListItem({key: 'grab_supplier',text: oBundle.getText('Supplier'), icon: 'sap-icon://supplier'})
var navigationGrab9 = new sap.tnt.NavigationListItem({key: 'grab_part_master',text: oBundle.getText('Part_Master'), icon:'sap-icon://wrench',
    select:function(event){
        
        if(vehicleTemp){
            get4WVehicle();
            vehicleTemp = false;
        };
        if(grabPartTemp){
            get4WPartMaster();
            grabPartTemp = false;
        };
        let oxmaint_role = sessionStorage.getItem('oxmaint_role');
        if(oxmaint_role == 'Workshop'){
            partFilterWOrkshopData.setVisible(false);
        }else{
            partFilterWOrkshopData.setVisible(true);
        }
    }
});
var navigationGrab10 = new sap.tnt.NavigationListItem({key: 'grab_invoice',text: oBundle.getText('Invoice'),icon:'sap-icon://monitor-payments',
    select:function(){
        if(workShopIVCTemp){
            // fetchInvoiceComparision();
            getemailsforworkshop();
            workShopIVCTemp = false;
        }
    }
})
// var navigationGrab11 = new sap.tnt.NavigationListItem({key: 'grab_document',text: oBundle.getText('Documents')})
var navigationGrab12 = new sap.tnt.NavigationListItem({key: 'grab_approval_master',text: oBundle.getText('Approval'),icon:'sap-icon://approvals'})
var navigationGrab13 =  new sap.tnt.NavigationListItem({key: 'grab_supplier_invoice',text: oBundle.getText('Supplier_Invoice'), icon:'sap-icon://monitor-payments',
    select:function(){
        if(supplierInvTemp){
            get4WSuppOpenInvoice();
            getSupplierClosedWorkorder();
            fetchSupplierInvoice();
            // get4WCompletedSuppInvoice();
            supplierInvTemp = false;
        }
    }
});
var navigationGrab14 = new sap.tnt.NavigationListItem({key: 'grab_report',text: oBundle.getText('Report'), icon:'sap-icon://manager-insight'});
var navigationGrab15 = new sap.tnt.NavigationListItem({visible:true,key: 'grab_driver',text: oBundle.getText('Driver'), icon:"sap-icon://end-user-experience-monitoring",
    select:function(){
        if(driverTemp){
            getDriverData();
        }
    }
});
var navigationGrab16 = new sap.tnt.NavigationListItem({key: 'grab_vehicle_documents',text: oBundle.getText('Vehicle_Insurance_Documents'),icon :'sap-icon://insurance-car'
    ,select:function(){
        loadVehicleDocAndDash();
    }
});
var navigationGrab17 = new sap.tnt.NavigationListItem({key: 'grab_vehicle_renewable_doc',text: oBundle.getText('Vehicle_Renewable_Documents'),icon :'sap-icon://insurance-car',
    select:function(){
        loadVehicleDocAndDash();
    }
});
var navigationGrab18 = new sap.tnt.NavigationListItem({key: 'grab_veh_ins_dash',text: oBundle.getText('Vehicle_Insurance_Dashboard'),icon :'sap-icon://documents',
    select:function(){
        loadVehicleDocAndDash();
    }
});
var navigationGrab19 = new sap.tnt.NavigationListItem({key: 'grab_veh_ren_dash',text: oBundle.getText('Vehicle_Renewable_Dashboard'),icon :'sap-icon://documents',
    select:function(){
        loadVehicleDocAndDash();
    }
});

var navigationGrabItem20 = new sap.tnt.NavigationListItem({visible:true, key: 'all_documents',expanded: false,text: oBundle.getText('Documents'),icon: 'sap-icon://documents',
items: [
    navigationGrab16,navigationGrab17,navigationGrab18,navigationGrab19
    ],select:function(){
        loadVehicleDocAndDash();
    }
});

// var navigationGrabItem21 = new sap.tnt.NavigationListItem({key: 'grab_holiday_calendar',text: oBundle.getText('Holiday_Calendar'),icon :'sap-icon://add-calendar',
//     select:function(){
//         if(locationTemp){
//             getAllLocationData();
//             locationTemp = false;
//         }
//     }
// });


var navigationGrabItem22 = new sap.tnt.NavigationListItem({key: 'grab_location_holiday',text: oBundle.getText('Location_&_Holiday'),icon :'sap-icon://time-account',
    select:function(){
        if(locationTemp){
            getAllLocationData();
            locationTemp = false;
        };
    }
});
var navigationGrab23 = new sap.tnt.NavigationListItem({visible:true,key: 'grab_inspection_reminder',text: oBundle.getText('Inspection_Reminder'),icon :'sap-icon://time-off',
    select:function(){
        if(inspReminderTemp){
            getInspectionReminder();
            inspReminderTemp = false;
        }
    }
});
var navigationGrab24 = new sap.tnt.NavigationListItem({visible:false,key: 'grab_dash1',text: oBundle.getText('Dashboard1'),icon :'sap-icon://time-off'});







function loadVehicleDocAndDash(){
    if(documentTemp){
        initVehicleDocuments();
        initRenewableDocuments();
        loadVehicleInsurenceDashboard();
        loadVehicleRenewableDashboard();
        documentTemp = false;
    }
}

// var navigationItem24 = new sap.tnt.NavigationListItem({ key: 'p024',expanded: true,text: oBundle.getText('Four_Wheeler'),icon: 'sap-icon://taxi',
//     items: [
//             new sap.tnt.NavigationListItem({key:'four_wheeler_dashboard',expanded: true,text: oBundle.getText('Dashboard'),icon: 'sap-icon://grid'}),   // Dashboard  0
//             new sap.tnt.NavigationListItem({key: 'inspection_report',text: oBundle.getText('Inspection_Report')}), // Inspection 1
//             new sap.tnt.NavigationListItem({key: 'grab_checkpoint',text: oBundle.getText('Inspection_Form')}),  // Inspection Form 2
//             new sap.tnt.NavigationListItem({key: 'grab_workorder',text: oBundle.getText('Workorder')}),  // Workorder  3
//             new sap.tnt.NavigationListItem({key: 'grab_service_schedule',text: oBundle.getText('Service_Schedule')}), // Service schedule 4
//             new sap.tnt.NavigationListItem({key: 'grab_vehicle',text: oBundle.getText('Vehicles')}), // 4W Vehicle 5
//             new sap.tnt.NavigationListItem({key: 'grab_team_management',text: oBundle.getText('Team_Management')}),   // Team Management  6
//             new sap.tnt.NavigationListItem({key: 'grab_workshop',text: oBundle.getText('Workshop')}),          // Workshop    7
//             new sap.tnt.NavigationListItem({key: 'grab_supplier',text: oBundle.getText('Supplier')}),          // Supplier   8
//             new sap.tnt.NavigationListItem({key: 'grab_part_master',text: oBundle.getText('Part_Master'),
//                 select:function(event){
//                     get4WPartMaster();
//                     if(grabPartTemp){
//                         grabPartTemp = false;
//                     }
//                 }
//             }),       // Part Inventory   9
//             // new sap.tnt.NavigationListItem({key: 'grab_branche',text: oBundle.getText('Branches')}),  
//             new sap.tnt.NavigationListItem({key: 'grab_invoice',text: oBundle.getText('Invoice')}),           // Invoice   10
//             new sap.tnt.NavigationListItem({key: 'grab_document',text: oBundle.getText('Documents')}),          // Documents 11
//             new sap.tnt.NavigationListItem({key: 'grab_approval_master',text: oBundle.getText('Approval')}),          // Approval  12
//             new sap.tnt.NavigationListItem({key: 'grab_supplier_invoice',text: oBundle.getText('Supplier_Invoice'),
//                 select:function(){
//                     get4WSuppOpenInvoice();
//                     getSupplierClosedWorkorder();
//                     fetchSupplierInvoice();
//                     get4WCompletedSuppInvoice();
//                     if(supplierInvTemp){
//                         supplierInvTemp = false;
//                     }
//                 }
//             }),  //Supplier Invoice   13
//             new sap.tnt.NavigationListItem({key: 'grab_report',text: oBundle.getText('Report')}),  //report   14
//             new sap.tnt.NavigationListItem({key: 'grab_driver',text: oBundle.getText('Driver')}),  //driver   15
//             // new sap.tnt.NavigationListItem({key: 'grab_invoice_comparison',text: oBundle.getText('Invoice Comparison')}),  //Invoice Comparison   14
//         ]
//     // ]
//     });


var hvi_default_type = sessionStorage.getItem('oxmaint_default_type');
if(nullCheckAll(hvi_default_type)){

    var hvi_default = hvi_default_type.split(",");
}

var hvi_account_access_value = sessionStorage.getItem('oxmaint_account_access');
if(nullCheckAll(hvi_account_access_value)){
    var hvi_account_access = hvi_account_access_value.split(",");

    // let oxmaint_role = sessionStorage.getItem('oxmaint_role');
    // if(oxmaint_role != 'Administrator'){
    //     navigationGrabItem22.setVisible(false);
    // }
    if(hvi_login_type=="2"){
        teamAccess();
    }
}else{
    if(hvi_login_type=="2"){
        teamAccess();
    }
}

function teamAccess(){

    if(nullCheckAll(hvi_user_access)){

        //Team Management
        if(hvi_user_access.indexOf('view_user_account')==-1 && hvi_user_access.indexOf('create_user_account')==-1 &&hvi_user_access.indexOf('modify_user_account')==-1 ){
            // navigationItem24.getItems()[6].setVisible(false);
            navigationGrab6.setVisible(false);
        };
        if( hvi_user_access.indexOf('create_user_account')==-1  ){
            if (sap.ui.getCore().byId("createTeamID")) {
                sap.ui.getCore().byId("createTeamID").setVisible(false);
            }
        };
        //Approval Master
        if(hvi_user_access.indexOf('view_approval_level')==-1 && hvi_user_access.indexOf('modify_approval_level')==-1 ){
            // navigationItem24.getItems()[12].setVisible(false);
            navigationGrab12.setVisible(false);
        };

        //Workshop && workshop master
        if(hvi_user_access.indexOf('view_workshop')==-1 && hvi_user_access.indexOf('create_workshop')==-1 && 
            hvi_user_access.indexOf('modify_workshop')==-1 && hvi_user_access.indexOf('delete_workshop')==-1 &&
            hvi_user_access.indexOf('view_workshop_group')==-1 && hvi_user_access.indexOf('create_workshop_group')==-1 && 
            hvi_user_access.indexOf('modify_workshop_group')==-1 && hvi_user_access.indexOf('delete_workshop_group')==-1){
            // navigationItem24.getItems()[7].setVisible(false);
            navigationGrab7.setVisible(false);
        };
        //Workshop
        if(hvi_user_access.indexOf('view_workshop')==-1 && hvi_user_access.indexOf('create_workshop')==-1 && 
            hvi_user_access.indexOf('modify_workshop')==-1 && hvi_user_access.indexOf('delete_workshop')==-1 ){
                if (sap.ui.getCore().byId("GW1")) {
                    sap.ui.getCore().byId("GW1").setVisible(false);
                }
        };
        //Create Workshop Button
        if( hvi_user_access.indexOf('create_workshop')==-1  ){
            if (sap.ui.getCore().byId("grabWorkshopBtnID")) {
                sap.ui.getCore().byId("grabWorkshopBtnID").setVisible(false);
            }
        };
        
        //Workshop Group Master
        if(hvi_user_access.indexOf('view_workshop_group')==-1 && hvi_user_access.indexOf('create_workshop_group')==-1 && 
            hvi_user_access.indexOf('modify_workshop_group')==-1 && hvi_user_access.indexOf('delete_workshop_group')==-1){
                if (sap.ui.getCore().byId("GW2")) {
                    sap.ui.getCore().byId("GW2").setVisible(false);
                }
        };
        //Create Workshop Master Button 
        if( hvi_user_access.indexOf('create_workshop_group')==-1  ){
            if (sap.ui.getCore().byId("grabWorkshopMasterBtnID")) {
                sap.ui.getCore().byId("grabWorkshopMasterBtnID").setVisible(false);
            }
        };



        //Supplier
        if(hvi_user_access.indexOf('view_supplier')==-1 && hvi_user_access.indexOf('create_supplier')==-1 && hvi_user_access.indexOf('modify_supplier')==-1 && hvi_user_access.indexOf('delete_supplier')==-1){
            // navigationItem24.getItems()[8].setVisible(false);
            navigationGrab8.setVisible(false);
        };
        //Create aSupplier Button
        if( hvi_user_access.indexOf('create_supplier')==-1  ){
            if (sap.ui.getCore().byId("createSupplierBtnID")) {
                sap.ui.getCore().byId("createSupplierBtnID").setVisible(false);
            }
        };

        
        //Schedule
        if(hvi_user_access.indexOf('view_schedule')==-1 && hvi_user_access.indexOf('create_schedule')==-1 && hvi_user_access.indexOf('modify_schedule')==-1 && hvi_user_access.indexOf('delete_schedule')==-1){
            // navigationItem24.getItems()[4].setVisible(false);
            navigationGrab4.setVisible(false);
            if (sap.ui.getCore().getElementById("grab_dash_scheduler")) {
                sap.ui.getCore().getElementById("grab_dash_scheduler").setVisible(false);
            }
            
        };
        if( hvi_user_access.indexOf('create_schedule')==-1  ){
            if (sap.ui.getCore().byId("createScheduleID")) {
                sap.ui.getCore().byId("createScheduleID").setVisible(false);
            }
        };


        if(hvi_user_access.indexOf('view_assign_vehicle')==-1 && hvi_user_access.indexOf('assign_vehicle')==-1 && hvi_user_access.indexOf('modify_assign_vehicle')==-1){
            // navigationItem24.getItems()[5].setVisible(false);
            navigationGrab5.setVisible(false);
        }
        if(hvi_user_access.indexOf('view_inspection_form')==-1 && hvi_user_access.indexOf('delete_inspection_form')==-1 && hvi_user_access.indexOf('modify_inspection_form')==-1 && hvi_user_access.indexOf('create_inspection_form')==-1){
            // navigationItem24.getItems()[2].setVisible(false);
            navigationGrab2.setVisible(false);
        }
        if(hvi_user_access.indexOf('view_inspection_transaction')==-1 && hvi_user_access.indexOf('create_inspection_transaction')==-1 && hvi_user_access.indexOf('archive_inspection_transaction')==-1 ){
            // navigationItem24.getItems()[1].setVisible(false);
            navigationGrab1.setVisible(false);
            if (sap.ui.getCore().getElementById("grab_dash_inspection")) {
                sap.ui.getCore().getElementById("grab_dash_inspection").setVisible(false);
            }
        }

        //Parts Data
        if(hvi_user_access.indexOf('view_master_data_part_and_labour')==-1 && hvi_user_access.indexOf('create_master_data_part_and_labour')==-1 && hvi_user_access.indexOf('modify_master_data_part_and_labour')==-1 && hvi_user_access.indexOf('delete_master_data_part_and_labour')==-1){
            // navigationItem24.getItems()[9].setVisible(false);
            navigationGrab9.setVisible(false);
        };
        if( hvi_user_access.indexOf('create_master_data_part_and_labour')==-1  ){
            if (sap.ui.getCore().byId("createPartsID")) {
                sap.ui.getCore().byId("createPartsID").setVisible(false);
            }
        };



        if(hvi_user_access.indexOf('view_work_order')==-1 && hvi_user_access.indexOf('create_work_order')==-1 && hvi_user_access.indexOf('modify_work_order')==-1 && hvi_user_access.indexOf('cancel_work_order')==-1 && hvi_user_access.indexOf('archive_work_order')==-1 ){
            // navigationItem24.getItems()[3].setVisible(false);
            navigationGrab3.setVisible(false);
            if (sap.ui.getCore().getElementById("grab_dash_workorder")) {
                sap.ui.getCore().getElementById("grab_dash_workorder").setVisible(false);
            }
            
        };
        if( hvi_user_access.indexOf('create_work_order')==-1  ){
            if (sap.ui.getCore().byId("createWorkorderID")) {
                sap.ui.getCore().byId("createWorkorderID").setVisible(false);
            }
            if (sap.ui.getCore().byId("createWorkorderID2")) {
                sap.ui.getCore().byId("createWorkorderID2").setVisible(false);
            }
        };
        

        //Invoice
        if(hvi_user_access.indexOf('invoice_comparision_dashboard')==-1){
            // navigationItem24.getItems()[10].setVisible(false);
            navigationGrab10.setVisible(false);
        }

        //Create Invoice
        if(hvi_user_access.indexOf('create_invoice_work_order')==-1){ 
            if (sap.ui.getCore().byId("createIdInvoiceBtn")) {
                sap.ui.getCore().byId("createIdInvoiceBtn").setVisible(false);
            }
        };
        //Modify Invoice
        if(hvi_user_access.indexOf('open_invoice_work_order')==-1){ 
            if (sap.ui.getCore().byId("GWO9")) {
                sap.ui.getCore().byId("GWO9").setVisible(false);
            }
        }

        // if(hvi_user_access.indexOf('view_document')==-1){
        //     // navigationItem24.getItems()[11].setVisible(false);
        //     navigationGrab11.setVisible(false);
        // }
        if(hvi_user_access.indexOf('supplier_invoice')==-1){
            // navigationItem24.getItems()[13].setVisible(false);
            navigationGrab13.setVisible(false);
        }
        
        if(hvi_user_access.indexOf('download_report')==-1){
            // navigationItem24.getItems()[14].setVisible(false);
            navigationGrab14.setVisible(false);
        }
        if(hvi_user_access.indexOf('driver')==-1){
            // navigationItem24.getItems()[15].setVisible(false);
            navigationGrab15.setVisible(false);
        }
        if(hvi_user_access.indexOf('location')==-1){
            if (sap.ui.getCore().byId("SLM0")) {sap.ui.getCore().byId("SLM0").setVisible(false);}
        }
        if(hvi_user_access.indexOf('holiday')==-1){ 
            if (sap.ui.getCore().byId("SLM1")) { sap.ui.getCore().byId("SLM1").setVisible(false); }
        }
        
        if(hvi_user_access.indexOf('location')==-1 && hvi_user_access.indexOf('holiday')==-1){
            if (sap.ui.getCore().byId("SLM0")) { sap.ui.getCore().byId("SLM0").setVisible(false); }
            if (sap.ui.getCore().byId("SLM1")) { sap.ui.getCore().byId("SLM1").setVisible(false); }
            navigationGrabItem22.setVisible(false);
        }

        if(hvi_user_access.indexOf('view_schedule')==-1 && hvi_user_access.indexOf('create_schedule')==-1 && 
            hvi_user_access.indexOf('modify_schedule')==-1 && hvi_user_access.indexOf('delete_schedule')==-1 &&
            hvi_user_access.indexOf('view_work_order')==-1 && hvi_user_access.indexOf('create_work_order')==-1 &&
            hvi_user_access.indexOf('modify_work_order')==-1 && hvi_user_access.indexOf('cancel_work_order')==-1 && 
            hvi_user_access.indexOf('archive_work_order')==-1 && hvi_user_access.indexOf('view_inspection_transaction')==-1 && 
            hvi_user_access.indexOf('create_inspection_transaction')==-1 && hvi_user_access.indexOf('archive_inspection_transaction')==-1 
        ){
            SegmentedGrabGroup.setVisible(false);
        }
    
        if(hvi_user_access.indexOf('inspection_reminder')==-1){
            navigationGrab23.setVisible(false);
        }
        
        if(hvi_user_access.indexOf('documents')==-1){
            navigationGrabItem20.setVisible(false);
        }

        
        
    }else{
        navigationGrab0.setVisible(false);
        navigationGrab1.setVisible(false);
        navigationGrab2.setVisible(false);
        navigationGrab3.setVisible(false);
        navigationGrab4.setVisible(false);
        navigationGrab5.setVisible(false);
        navigationGrab6.setVisible(false);
        navigationGrab7.setVisible(false);
        navigationGrab8.setVisible(false);
        navigationGrab9.setVisible(false);
        navigationGrab10.setVisible(false);
        // navigationGrab11.setVisible(false);
        navigationGrab12.setVisible(false);
        navigationGrab13.setVisible(false);
        navigationGrab14.setVisible(false);
        navigationGrab15.setVisible(false);
        navigationGrab16.setVisible(false);
        navigationGrab17.setVisible(false);
        navigationGrab18.setVisible(false);
        navigationGrab19.setVisible(false);
        navigationGrab20.setVisible(false);
        navigationGrab21.setVisible(false);
        navigationGrab22.setVisible(false);
        navigationGrab23.setVisible(false);
    }
}


var carProToggle = true;
var documentToggle = true;

var sideNavigation = new sap.tnt.SideNavigation({ expanded: false,
    // fixedItem:new sap.tnt.NavigationList({ items: [navigationItem10,navigationItem14, navigationItem15, navigationItem16] }),
    // fixedItem:new sap.tnt.NavigationList({ items: [ navigationItem10] }),
    item: new sap.tnt.NavigationList({
        items: [ 
            // navigationItem24
            navigationGrab0,
            navigationGrab1,
            navigationGrab2,
            navigationGrab3,
            navigationGrab4,
            navigationGrab5,
            navigationGrab6,
            navigationGrab7,
            navigationGrab8,
            navigationGrab9,
            navigationGrab10,
            // navigationGrab11,
            navigationGrab12,
            navigationGrab13,
            navigationGrab14,
            navigationGrabItem20,
            navigationGrab15,
            navigationGrabItem22,
            navigationGrab23,
            navigationGrab24
            // navigationGrab16,
            // navigationGrab17,
            // navigationGrab18,
            // navigationGrab19
        ]
    }),
    itemSelect: function (event) {
   
    var sKey = event.getParameter('item').getKey();
    
    if (documentToggle && sKey == "all_documents") {
        event.getParameter('item').setExpanded(true);
        documentToggle = false;
    } else if (sKey == "all_documents") {
        event.getParameter('item').setExpanded(false);
        documentToggle = true;
    }

    navContainer.to(sKey, "show");
    
}
});



var navContainer = new sap.m.NavContainer({
    pages: [
        
        
        //Grab New Pages
        new sap.m.ScrollContainer('four_wheeler_dashboard',{ vertical: true,height: "100%",width: "100%",
            horizontal: false,content: [oLayoutBlockGrabDashboard]}),                                         //dashboard
        new sap.m.ScrollContainer('grab_workorder',{content: [oAppWorkOrder]}),                               //workorder history 

        new sap.m.ScrollContainer('inspection_report',{content: [oAppInspection]}),                           //inspection history
        new sap.m.ScrollContainer('grab_checkpoint',{content: [oLayoutCheckList]}),                           //form
        
        new sap.m.ScrollContainer('grab_vehicle',{content: [VehiclePage4W]}),                                 //4w Vehicle
        new sap.m.ScrollContainer('grab_team_management',{content: [teamPage4W]}),                            //4w Team Management
        new sap.m.ScrollContainer('grab_workshop',{content: [workshopPage4W]}),                               //4W Workshop
        new sap.m.ScrollContainer('grab_supplier',{content: [supplierPage4W]}),                               //4w Supplier
        // new sap.m.ScrollContainer('grab_branche',{content: [branchesPage4W]}),                                //4w Branches
        new sap.m.ScrollContainer('grab_invoice',{content: [oAppInvoicePageLayout]}),                         //4w Invoice
        new sap.m.ScrollContainer('grab_part_master',{content: [partMasterPage4W]}),                          //4w Parts Master
        new sap.m.ScrollContainer('grab_approval_master',{content: [approvalPage4W]}),                        //4w Approval
        new sap.m.ScrollContainer('grab_supplier_invoice',{content: [oAppSupplierInvoicePage]}),              //4w Supplier Invoice
        // new sap.m.ScrollContainer('grab_invoice_comparison',{content: [oAppInvoiceComparisonPage]}),       //4w Invoice Comparision
        // new sap.m.ScrollContainer('grab_document',{content: [teamDocPage]}),                                  //Team DOc
        new sap.m.ScrollContainer('grab_service_schedule',{content: [oLayoutScheduleMain]}),                  //4w Supplier Invoice
        new sap.m.ScrollContainer('grab_report',{content: [grabReportForm1]}),                                //4w Report
        new sap.m.ScrollContainer('grab_driver',{content: [driverPage4W]}),                                   //4w Driver
        new sap.m.ScrollContainer('grab_vehicle_documents',{content: [vehicleDocumentsPage]}),                //4w Vehicle Documents
        new sap.m.ScrollContainer('grab_vehicle_renewable_doc',{content: [vehicleRenewableDocPage]}),         //4w Vehicle Renewable Documents
        new sap.m.ScrollContainer('grab_veh_ins_dash',{content: [vehicleInsurenceDashboardPage]}),            //4w Vehicle Insurence Dashboard
        new sap.m.ScrollContainer('grab_veh_ren_dash',{content: [vehicleRenewableDashboardPage]}),            //4w Vehicle Renewable Documents
        // new sap.m.ScrollContainer('grab_holiday_calendar',{content: [holidayCalendarPage4W]}),                //4w Holiday Calendar
        new sap.m.ScrollContainer('grab_location_holiday',{content: [locationHolidayPage4W]}),                                      //4w Slot
        new sap.m.ScrollContainer('grab_inspection_reminder',{content: [inspReminderPage4W]}),                                      //4w Slot
        new sap.m.ScrollContainer('grab_dash1',{content: [dash1Page4W]}),                                      //4w Slot
       
       
        // new sap.m.ScrollContainer('p0232',{content: [VehiclePage2W]}), 
        // new sap.m.ScrollContainer('p0241',{content: [maintenancePage4W]}),    //4w Maintenance


        
              

    ]
}).addStyleClass("page");


var userDetailQuickView = new sap.m.QuickViewPage({
    header: oBundle.getText("User_Info"),
    title: emailUser,
    description: "",
    icon: "sap-icon://employee"
});
if (hvi_userid != null) {
    var descriptionText = oBundle.getText("User") + " : " + hvi_userid + "\n" +
                        //  oBundle.getText("Role") + " : " + hvi_team_role + "\n" +
                          oBundle.getText("Login_Type") + " : " + portal_type_flag;

    userDetailQuickView.setDescription(descriptionText);
}



var userView = new sap.m.QuickView({
    placement: sap.m.PlacementType.Auto,
    pages: [userDetailQuickView]
}).addStyleClass('loginBtnCss');
var logout = new sap.m.Button({
    type: sap.m.ButtonType.Default,
    icon: sap.ui.core.IconPool.getIconURI("log"),
    press: function () {
        sap.m.MessageBox.show(oBundle.getText("Do_you_want_to_logout"),
            sap.m.MessageBox.Icon.ERROR,
            oBundle.getText("Alert"),
            [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO].map(action => oBundle.getText(action)),
            function (bConfirmed) {
                if (bConfirmed == "YES") {
                    allClearAndLogOut();
                }
            })
    },
    tooltip: oBundle.getText("Log_out")
}).addStyleClass('loginBtnCss');
var refreshBtn = new sap.m.Button({
    type: sap.m.ButtonType.Default,
    icon: sap.ui.core.IconPool.getIconURI("synchronize"),
    layoutData: new sap.m.OverflowToolbarLayoutData({priority: "High"}),
    press: function () {refresh();},
    tooltip: oBundle.getText("Refresh")
}).addStyleClass('loginBtnCss');
var fullScreen = new sap.m.Button({
    type: sap.m.ButtonType.Default,
    icon: sap.ui.core.IconPool.getIconURI("full-screen"),
    layoutData: new sap.m.OverflowToolbarLayoutData({priority: "Low"}),
    press: function () {
        GoInFullscreen();
    }
}).addStyleClass('loginBtnCss');

var userImg = new sap.m.Button({
    type: sap.m.ButtonType.Default,
    icon: sap.ui.core.IconPool.getIconURI("employee"),
    layoutData: new sap.m.OverflowToolbarLayoutData({priority: "Low"}),
    press: function () {userView.openBy(this);},
    tooltip: oBundle.getText("User_Info")
}).addStyleClass('loginBtnCss');
    
 var appName = new sap.m.Title({ text: `PRIME - ${portal_type_flag}`,
                level:"H1",layoutData: new sap.m.OverflowToolbarLayoutData({priority: "Low"})}).addStyleClass('blackFont');


var toolHeader = new sap.tnt.ToolHeader({
    content: [
        new sap.m.Button({
            icon: 'sap-icon://menu2',
            type: sap.m.ButtonType.Transparent,
            press: function () {
                var sideExpanded = toolPage.getSideExpanded();
                toolPage.setSideExpanded(!sideExpanded);
            },
            layoutData: new sap.m.OverflowToolbarLayoutData({priority: "NeverOverflow"})
        }).addStyleClass('loginBtnCss'),
        // customizationBtn,
        // new sap.m.Label({ text: oBundle.getText("Sites")+" :", design: sap.m.LabelDesign.Bold }).addStyleClass('whiteText'),
        // multiLocationDB,
        new sap.m.ToolbarSpacer({width: '40%'}),
        new sap.m.Image({ src: "Images/logo.png", width: "40px", height: "40px",
        layoutData: new sap.m.OverflowToolbarLayoutData({priority: "NeverOverflow"})}), 
        appName,
        new sap.tnt.ToolHeaderUtilitySeparator({ }), new sap.m.ToolbarSpacer(),
        // languageDB,
        // messageButton,
        userImg,refreshBtn,logout,fullScreen
    ]
});


var toolPage = new sap.tnt.ToolPage({
    header: toolHeader,
    sideContent: sideNavigation,
    mainContents: [navContainer]
});

jQuery.sap.initMobile();

function sizeChanged(mParams) {
    switch(mParams.name) {
        case "Phone":
            toolPage.setSideExpanded(false);
            appName.setText(`PRIME - ${portal_type_flag}`);
            break;
        case "Tablet":
            toolPage.setSideExpanded(false);
            appName.setText(`PRIME - ${portal_type_flag}`);
            break;
        case "Desktop":
           toolPage.setSideExpanded(true);
           appName.setText(`PRIME - ${portal_type_flag}`);
    }
}

sap.ui.Device.media.attachHandler(sizeChanged, null, sap.ui.Device.media.RANGESETS.SAP_STANDARD);
sizeChanged(sap.ui.Device.media.getCurrentRange(sap.ui.Device.media.RANGESETS.SAP_STANDARD));


var portalPage = new sap.m.Page({
    showHeader: false,
    content: [toolPage]
});
var app = new sap.m.App({initialPage:portalPage});
app.addPage(portalPage).placeAt("body");

function refresh() {
    
    var selectedSideKey = sideNavigation.getSelectedKey();
    console.log(selectedSideKey)
    
    if(selectedSideKey == 'inspection_report'){
        funGetInspection();
    }else if(selectedSideKey == 'grab_checkpoint'){
        funGetChecklist();
    }else if(selectedSideKey == 'grab_workorder'){
        let currentSectionId = oAppWorkOrderPageLayout.getSelectedSection();
        if(currentSectionId=="GWO1"){  // Pending
            getPendingWorkorder();
        }else if(currentSectionId=="GWO2"){  //Open
            getOpenWorkorder();
        }else if(currentSectionId=="GWO3"){  //Completed
            getCompletedWorkorder();
        }else if(currentSectionId=="GWO4"){  //Closed
            getClosedWorkorder();
        }else if(currentSectionId=="GWO5"){  //GRN
            getGrnWorkorder();
        }else if(currentSectionId=="GWO6"){  //Reject
            getRejectWorkorder();
        }else if(currentSectionId=="GWO7"){  //Cancelled
            getCancelledWorkorder();
        }else if(currentSectionId=="GWO8"){  //Archive
            funGetArchiveWO();
        }else if(currentSectionId=="GWO9"){  //Open Invoice
            get4WOpenInvoice();
        }else if(currentSectionId=="GW10"){  //All Workorder
            getAllWorkorderDetails();
        }else if(currentSectionId == "GWO11"){ // Need Verification
            getVerificationWorkorder();
        };

    }else if(selectedSideKey == 'grab_service_schedule'){
        getScheduleDetails();
    }else if(selectedSideKey == 'grab_vehicle'){
        get4WVehicle();
    }else if(selectedSideKey == 'grab_team_management'){
        get4WTeam();
    }else if(selectedSideKey == 'grab_workshop'){
        let currentSectionId = workshopMain.getSelectedSection();
        if(currentSectionId=="GW1"){  //Workshop
            getWorkshop();
        }else if(currentSectionId=="GW2"){  //Workshop Master
            getWorkshopMaster();
        }
    }else if(selectedSideKey == 'grab_supplier'){
        get4WSupplier();
    }else if(selectedSideKey == 'grab_part_master'){
        get4WPartMaster();
    }else if(selectedSideKey == 'grab_invoice'){
        let currentSectionId = oAppInvoicePageLayout.getSelectedSection();
        if(currentSectionId == "INV2"){
            // getemailsforworkshop();
            refreshCurrentWorkshopInvoiceData();
            // fetchInvoiceComparision();
        }else if(currentSectionId == "INV3"){
            // get4WCompletedInvoice();
            oTable4WAllInvoiceGRN.setBusy(true);
            getGrnWorkorder();
        }

    }else if(selectedSideKey == 'grab_approval_master'){
        get4WApproval();
    }else if(selectedSideKey == 'grab_supplier_invoice'){
        let currentSectionId = oAppSupplierInvoicePage.getSelectedSection();
        if(currentSectionId == "SUPP1"){
            get4WSuppOpenInvoice();
            getSupplierClosedWorkorder();
        }else if(currentSectionId == "SUPP2"){
            fetchSupplierInvoice();
        }else if(currentSectionId == "SUPP3"){
            // get4WCompletedSuppInvoice();
        }
       
    }else if(selectedSideKey == 'four_wheeler_dashboard' || selectedSideKey == undefined || selectedSideKey == 'p024'){
        onload(1);
    }else if(selectedSideKey == 'grab_vehicle_documents'){
        // loadVehicleDocuments();
        loadVehicleInsuranceDocuments();
    }else if(selectedSideKey == 'grab_vehicle_renewable_doc'){
        // loadRenewableDocuments();
        loadRenewableDocuments();
    }else if(selectedSideKey == 'grab_veh_ins_dash'){
        // loadVehicleInsurenceDashboard();
        loadInsuranceData();
    }else if(selectedSideKey == 'grab_veh_ren_dash'){
        // loadVehicleRenewableDocuments();
        loadDashboardData();
    }else if(selectedSideKey == 'grab_location_holiday'){
        let currentSectionId = slotMainLayout.getSelectedSection();
        if(currentSectionId=="SLM0"){
            getAllLocationData();
        }else if(currentSectionId=="SLM1"){

        };

    }else if (selectedSideKey == 'grab_inspection_reminder'){
        getInspectionReminder();
    // }else if (selectedSideKey == 'grab_dash1'){
    //     reportWorkorderStatus()
    }else if (selectedSideKey == 'grab_driver'){
        getDriverData();
    }
        
   
}

async function onload(src) {
    if(!(src == 1)){
        jQuery("body").toggleClass("sapUiSizeCompact");
    };

    
    // $.ajax({
    //     url: getWorkshopMaster(),
    // }).done(function(){
    //     $.ajax({
    //         url: get4WVehicle(),
    //     }).done(function(){
    //         onload1();
    //     });
    // });

    try {
        await getWorkshopMasterLoad();
        // get4WVehicle();
        onload1();
    } catch (error) {
        console.error("Error during loading:", error);
    }


}

function onload1() {

    const dateValue1 = new Date();
    const formattedDate1 = dateValue1.toISOString().split('T')[0] +  " 00:00:00.0000000 +00:00"; 


    const dateValue2 = new Date();
    dateValue2.setDate(dateValue2.getDate() + 1);
    const formattedDate2 = dateValue2.toISOString().split('T')[0] +  " 00:00:00.0000000 +00:00";

    dashboardWorkorderInspectionCount(formattedDate1, formattedDate2)
    get4WApproval();
   
    
   /* 
    if(hvi_user_access.indexOf('create_work_order')!=-1 || 
        hvi_user_access.indexOf('modify_work_order')!=-1 ||
        hvi_user_access.indexOf('cancel_work_order')!=-1 || 
        hvi_user_access.indexOf('view_work_order')!=-1 ||
        hvi_user_access.indexOf('archive_work_order')!=-1){
            getAllWorkorderDetails();
            if(hvi_user_access.indexOf('create_work_order')!=-1 || 
                hvi_user_access.indexOf('modify_work_order')!=-1 ){
                    get4WTeam();
                    get4WPartMaster();
                    getWorkshop();
                }
        

    };

    if(hvi_user_access.indexOf('create_user_account')!=-1 || 
        hvi_user_access.indexOf('modify_user_account')!=-1 ||
        hvi_user_access.indexOf('deactive_user_account')!=-1 || 
        hvi_user_access.indexOf('view_user_account')!=-1 ){
            getWorkshop();
            get4WSupplier();
    }
    */

    //Inspection Data
    // if(
    //     hvi_user_access.indexOf('create_inspection_transaction')!=-1 || hvi_user_access.indexOf('view_inspection_transaction')!=-1 ||
    //     hvi_user_access.indexOf('archive_inspection_transaction')!=-1
    // ){
    //     funGetInspection();
    // };


    //Inspection Form data
    // if(
    //     hvi_user_access.indexOf('view_inspection_form')!=-1 || hvi_user_access.indexOf('create_inspection_form')!=-1 ||
    //     hvi_user_access.indexOf('modify_inspection_form')!=-1 || hvi_user_access.indexOf('delete_inspection_form')!=-1 ||
    //     hvi_user_access.indexOf('create_inspection_transaction')!=-1 
    // ){
    //     funGetChecklist();
    // };



    //Schedules Data
    if(
        hvi_user_access.indexOf('create_schedule')!=-1 || hvi_user_access.indexOf('modify_schedule')!=-1 ||
        hvi_user_access.indexOf('delete_schedule')!=-1 
    ){
        getScheduleDetails();
    };
    
    //Workorder Data
    if(
        hvi_user_access.indexOf('create_work_order')!=-1 || hvi_user_access.indexOf('modify_work_order')!=-1 ||
        hvi_user_access.indexOf('cancel_work_order')!=-1 || hvi_user_access.indexOf('archive_work_order')!=-1 ||
        hvi_user_access.indexOf('view_work_order')!=-1 
    ){
        // getAllWorkorderDetails();
    };

    
    //Team Management
    if(
        hvi_user_access.indexOf('create_user_account')!=-1 || hvi_user_access.indexOf('modify_user_account')!=-1 ||
        hvi_user_access.indexOf('deactive_user_account')!=-1 || hvi_user_access.indexOf('view_user_account')!=-1 ||
        hvi_user_access.indexOf('create_work_order')!=-1 || hvi_user_access.indexOf('modify_work_order')!=-1
    ){
        get4WTeam();
    };

    // //Part Master
    // if(
    //     hvi_user_access.indexOf('create_master_data_part_and_labour')!=-1 || hvi_user_access.indexOf('modify_master_data_part_and_labour')!=-1 ||
    //     hvi_user_access.indexOf('delete_master_data_part_and_labour')!=-1 || hvi_user_access.indexOf('view_master_data_part_and_labour')!=-1 ||
    //     hvi_user_access.indexOf('create_work_order')!=-1 || hvi_user_access.indexOf('modify_work_order')!=-1
    // ){
    //     // get4WPartMaster();
    // };

    //Supplier data
    if(
        hvi_user_access.indexOf('view_supplier')!=-1 || hvi_user_access.indexOf('create_supplier')!=-1 ||
        hvi_user_access.indexOf('modify_supplier')!=-1 || hvi_user_access.indexOf('delete_supplier')!=-1 ||
        hvi_user_access.indexOf('create_master_data_part_and_labour')!=-1 || hvi_user_access.indexOf('modify_master_data_part_and_labour')!=-1 ||
        hvi_user_access.indexOf('create_user_account')!=-1 || hvi_user_access.indexOf('modify_user_account')!=-1 ||
        hvi_user_access.indexOf('create_work_order')!=-1 || hvi_user_access.indexOf('modify_work_order')!=-1
    ){
        get4WSupplier();
    };

    //Workshop Data
    if(
        hvi_user_access.indexOf('modify_invoice_work_order')!=-1 || hvi_user_access.indexOf('invoice_comparision_dashboard')!=-1 ||
        hvi_user_access.indexOf('view_workshop')!=-1 || hvi_user_access.indexOf('create_workshop')!=-1 ||
        hvi_user_access.indexOf('modify_workshop')!=-1 || hvi_user_access.indexOf('delete_workshop')!=-1 ||
        hvi_user_access.indexOf('create_work_order')!=-1 || hvi_user_access.indexOf('modify_work_order')!=-1 ||
        hvi_user_access.indexOf('create_user_account')!=-1 || hvi_user_access.indexOf('modify_user_account')!=-1 
    ){
        getWorkshop();
    };


    //Create Invoice
    if(
        hvi_user_access.indexOf('modify_invoice_work_order')!=-1 || hvi_user_access.indexOf('create_invoice_work_order')!=-1 || 
        hvi_user_access.indexOf('open_invoice_work_order')!=-1 
    ){
        // get4WOpenInvoice();
    };
    
    // Invoice Comparision Dashboard
    // if(
    //     hvi_user_access.indexOf('invoice_comparision_dashboard')!=-1  
    // ){
    //     fetchInvoiceComparision();
    // };
    
    // Supplier Comparision Dashboard
    // if(
    //     hvi_user_access.indexOf('supplier_invoice')!=-1  
    // ){
    //     get4WSuppOpenInvoice();
    //     getSupplierClosedWorkorder();
    //     fetchSupplierInvoice();
    //     get4WCompletedSuppInvoice();
    // };



    // funGetInspection();
    // getScheduleDetails();
    // funGetChecklist();
    // getPendingWorkorder();
    // get4WPartMaster();
    // get4WSupplier();
    // getWorkshop();

    
    // get4WOpenInvoice();
    // fetchInvoiceComparision()

    // get4WSuppOpenInvoice();
    // getSupplierClosedWorkorder();
    // fetchSupplierInvoice();
    // get4WCompletedSuppInvoice();


    // initVehicleDocuments();
    // initVehicleRenewableDashboard();
    // initVehicleInsurenceDashboard();
    // initRenewableDocuments();

}

// window.setInterval(function () {

//     // getSubscription();
//     // checkLoginBlock();
//     if(hvi_login_type=="2"){
//         // checkLoginBlockTeam();
//     }
// }, 5000000);

// function getSubscription() {

//     var emailUser = sessionStorage.getItem('oxmaint_email');
//     subsTable.where({ id: emailUser }).read().done(function (results) {
    
//         if (results.length > 0) {
//             subscriptionID = results[0]['subs_id'];
//             var oStatus = results[0]['status'];
//             var oCount = results[0]['unit_count'];
//             var oPlan_name = results[0]['plan_name'];
//             sessionStorage.setItem('oxmaint_status', oStatus);
//             sessionStorage.setItem('oxmaint_count', oCount);
//             sessionStorage.setItem('oxmaint_plan', oPlan_name);
//             sessionStorage.setItem('oxmaint_plan_id', results[0]['plan_id']);
//             sessionStorage.setItem('oxmaint_account_access', results[0]['access']);
//             sessionStorage.setItem('stripe_customer_id', results[0]['customer_id']);

//             // console.log(oStatus)
//             // console.log(subscriptionID)
//             if(oStatus=="Active"){
//                 oBannerNewUser2.setVisible(false);
//                 sessionStorage.setItem('subscription_type',true);
//                 if(subscriptionID!=null && subscriptionID!="" && subscriptionID.includes("sub_") ){
//                     btnInvoice.setVisible(true);
//                     btnUpgrade.setVisible(true);
//                     if(hvi_login_type=="1"){
//                         btnCanelSubs.setVisible(true);
//                     }
//                 }
//             }else if(oStatus=="Inactive" || oStatus=="Cancelled"){
//                 oBannerNewUser2.setVisible(true);
//                 sessionStorage.setItem('subscription_type',false);
//                 btnCanelSubs.setVisible(false);
//                 if(subscriptionID!=null && subscriptionID!="" && subscriptionID.includes("sub_") ){
//                     btnInvoice.setVisible(true);
//                     btnRewnew.setVisible(true);
//                 }
                
//             }


//             // oAppSubscriptionLayout.setVisible(false);
//             accountList2.setVisible(true);

//             var oData = [];
//             oData.push({ item: oBundle.getText("Plan_Name"), value: results[0]['plan_name'] });
//             oData.push({ item: oBundle.getText("Number of User"), value: results[0]['unit_count'] });
//             oData.push({ item: oBundle.getText("Monthly_Billing_Amount"), value: results[0]['paid_amount'] });
//             oData.push({ item: oBundle.getText("Subscription_Status"), value: results[0]['status'] }); 
//             oData.push({ item: oBundle.getText("Subscription_Date"), value: timeConverter(results[0]['start_date'])});
//             oData.push({ item: oBundle.getText("Next_Billing_Date"), value: timeConverter(results[0]['next_date'])});

//             var oModel = new sap.ui.model.json.JSONModel();
//             oModel.setData({ modelData: oData });
//             accountList2.setModel(oModel);

//             var oItem = new sap.m.StandardListItem({ title: "{item}",info: "{value}"});
//             accountList2.bindAggregation("items", "/modelData", oItem);

//         }else{
//             sessionStorage.setItem('subscription_type',false);
//             sessionStorage.setItem('oxmaint_status', "New");
//             sessionStorage.setItem('oxmaint_count', 50);
//             sessionStorage.setItem('oxmaint_plan', "Trial");

//             // oAppSubscriptionLayout.setVisible(true);
//             accountList2.setVisible(false);
//         }
//     });
// }

/*
function subscriptionDialog(){

    	var mList = new sap.m.List({
            showUnread: true,
            backgroundDesign: sap.m.BackgroundDesign.Transparent,
        }).addStyleClass("homelist");
    
        var oData = [];
        oData.push({ item: oBundle.getText("Unlimited_Inspections"), value: "" });
        oData.push({ item: oBundle.getText("Unlimited_Work_Order"), value: "" });
        oData.push({ item: oBundle.getText("Purchase_Order"), value: "" });
        oData.push({ item: oBundle.getText("Tyre_Inventory"), value: "" });
        oData.push({ item: oBundle.getText("Operator_Daily_Reporting"), value: "" });
        oData.push({ item: oBundle.getText("Preventive_Maintenance_Schedule"), value: "" });
        oData.push({ item: oBundle.getText("Defect_and_Issue_Email_Notification"), value: "" });
        oData.push({ item: oBundle.getText("Work_Order_Approval_Workflow"), value: "" });
        oData.push({ item: oBundle.getText("App_and_Inspection_Forms_Customization"), value: "" });
        oData.push({ item: oBundle.getText("Incident_Reporting"), value: "" });
        oData.push({ item: oBundle.getText("Fuel_Tracking"), value: "" });
        oData.push({ item: oBundle.getText("Team_Management_and_Collaboration"), value: "" });
        

        var oModel = new sap.ui.model.json.JSONModel();
        oModel.setData({ modelData: oData });
        mList.setModel(oModel);
       
        var oItem = new sap.m.StandardListItem({title: "{item}",info: "{value}"});
        mList.bindAggregation("items", "/modelData", oItem);
    
    
        var oLayout =  new sap.ui.layout.BlockLayout({
            background: sap.ui.layout.BlockBackgroundType.Dashboard,
            content: [
                new sap.ui.layout.BlockLayoutRow({
                    content: [
                        new sap.ui.layout.BlockLayoutCell({
                            titleAlignment:"Center",
                            title: oBundle.getText("Start_14_days_Premium_trial"),
                            content: mList
                        }),
                    ]
                })
            ]
        }).addStyleClass('homeLayout');
    
    
    var oDialog = new sap.m.Dialog({
        contentWidth:"400px",
        title: oBundle.getText("Subscription_Alert"),
        content: [oLayout],
        buttons: [
                    new sap.m.Button({
                        text: oBundle.getText("Upgrade_Now"),
                        icon: "sap-icon://lead",
                        press: function () {
                            //sendMailClickEvent("Upgrade now","portal - Subscription dialog ");
                            //window.open("https://oxmaint.com/pricing.html", "_blank");

                            buyPlan();
                        }
                    }),
                    new sap.m.Button({
                        text: oBundle.getText("Skip"),
                        icon: "sap-icon://decline",
                        press: function () {
                            sendMailClickEvent("Skip","portal - Subscription dialog");
                            oDialog.close();
                        }
                    })
                ]
    }).open();
    
}

function sendMailClickEvent(button,screen) {

    $.ajax({
        type: "POST",
        url: "https://oxmaint.com/notification/check_click_event.php",
        data: {
            "master_email": emailUser,
            "button": button,
            "screen": screen
        },
        success: function (data) { }
    });

}

function checkLoginBlock() {

    var emailUser = sessionStorage.getItem('oxmaint_email');
    loginTable.select("id", "pin", "blocked","checklist").where({ id: emailUser }).read().done(function (results) {

        if (results.length > 0) {
            var blocked = results[0]['blocked'];

            if (blocked == "Yes") {
            allClearAndLogOut();
            }

            if(results[0]['checklist']!=null){
                if(results[0]['checklist']=="2019"){
                    checklistIDArray = ["2019"];
                }else{
                    checklistIDArray = results[0]['checklist'].split("^");
                }
            }
            // getDefaultCheckList();
        }
    });
}


var multiLocationJSONArray = [];

function funGetLocationMulti() {

    multiLocationDB.setBusy(true);
    HVI_Location.where({ master_email: emailUser }).take(150).read().done(function (results) {

        if(hvi_login_type=="2"){
            multiLocationJSONArray = results;
            checkLoginBlockTeam();
        }else{
            results.splice(0, 0, {location_id: "Default-001", location_name: oBundle.getText("All")});

            var oModelDashboard = new sap.ui.model.json.JSONModel();
            oModelDashboard.setData({ modelData: results });
            multiLocationDB.setModel(oModelDashboard);
    
            var oItemTemplate2 = new sap.ui.core.ListItem();
            oItemTemplate2.bindProperty("key", "location_id");
            oItemTemplate2.bindProperty("text", "location_name");
            multiLocationDB.bindItems("/modelData", oItemTemplate2); 
        
            multiLocationDB.setSelectedKey(hvi_location_id);
            multiLocationDB.setBusy(false);

        }

    });
}


function checkLoginBlockTeam() {
    var emailUser = sessionStorage.getItem('oxmaint_email');
    var teamId = sessionStorage.getItem('oxmaint_userid');

    HVI_AccessControl.where({ master_email:emailUser,emailid: teamId}).read().done(function (results) {
        if (results.length > 0) {

            var user_block = results[0]['user_block'];
            var user_access = results[0]['user_access'];
            var employee_name = results[0]['name'];
            var assign_vehicle = results[0]['assign_vehicle'];
            var notification_email = results[0]['notification_email'];
            hvi_team_role = results[0]['role'];
            
            sessionStorage.setItem('oxmaint_employee_name', employee_name);
            sessionStorage.setItem('oxmaint_user_access', user_access);
            // sessionStorage.setItem('oxmaint_assign_vehicle', assign_vehicle);
            sessionStorage.setItem('oxmaint_notification_email', notification_email);

            sessionStorage.setItem('oxmaint_approver', results[0]['approver']);
            sessionStorage.setItem('oxmaint_write_access', results[0]['read_write_access']);

            if(hvi_team_role == "4"){ // for sub admin
                
                multiLocationJSONArray.splice(0, 0, {location_id: "Default-001", location_name: oBundle.getText("All")});

                var oModelDashboard = new sap.ui.model.json.JSONModel();
                oModelDashboard.setData({ modelData: multiLocationJSONArray });
                multiLocationDB.setModel(oModelDashboard);
                multiLocationDB.setSelectedKey(hvi_location_id);
        
            }else{
                
                multiLocationJSONArray.splice(0, 0, {location_id: "Default-001", location_name: oBundle.getText("All")});

                var oModelDashboard = new sap.ui.model.json.JSONModel();
                oModelDashboard.setData({ modelData: multiLocationJSONArray });
                multiLocationDB.setModel(oModelDashboard);
                multiLocationDB.setSelectedKey(hvi_location_id);
                
                if(results[0]['location_id']!=null && results[0]['location_id']!=''){
                    hvi_location_id = results[0]['location_id'];
                }
            }
            

            var oItemTemplate2 = new sap.ui.core.ListItem();
            oItemTemplate2.bindProperty("key", "location_id");
            oItemTemplate2.bindProperty("text", "location_name");
            multiLocationDB.bindItems("/modelData", oItemTemplate2); 
            multiLocationDB.setBusy(false);
            

            if (user_block == "Yes") {
                allClearAndLogOut();
            } 

        }else{
            allClearAndLogOut();
        }
    });
 }

 */



 function allClearAndLogOut(){
    
        sessionStorage.removeItem("oxmaint_remember");
        sessionStorage.removeItem("oxmaint_count");
        sessionStorage.removeItem("oxmaint_status");
        sessionStorage.removeItem("oxmaint_plan");
        sessionStorage.removeItem('oxmaint_email');
        sessionStorage.removeItem('oxmaint_userid');
        sessionStorage.removeItem('oxmaint_user_access');
        sessionStorage.removeItem('oxmaint_assign_vehicle');
        sessionStorage.setItem('oxmaint_login_type', "1");
        sessionStorage.removeItem('oxmaint_approval_level');
        sessionStorage.removeItem('oxmaint_supplier_id');
        sessionStorage.removeItem('oxmaint_account_access');
        sessionStorage.removeItem('stripe_customer_id');
        sessionStorage.removeItem('oxmaint_location_id');
        sessionStorage.removeItem('oxmaint_admin_name');
        sessionStorage.removeItem('oxmaint_approver');

        sessionStorage.removeItem("report_prefix");
        sessionStorage.removeItem("report_start_no");

        sessionStorage.removeItem("wo_prefix");
        sessionStorage.removeItem("wo_start_no");
        sessionStorage.removeItem("sc_prefix");
        sessionStorage.removeItem("sc_start_no");

        sessionStorage.removeItem("po_prefix");
        sessionStorage.removeItem("po_start_no");

        sessionStorage.removeItem("oxmaint_company_name");

        window.open("login.html", "_self");
}


function GoInFullscreen() {
    
     if ((document.fullScreenElement && document.fullScreenElement !== null) ||
        (!document.mozFullScreen && !document.webkitIsFullScreen)) {
         if (document.documentElement.requestFullScreen) {
             document.documentElement.requestFullScreen();
         } else if (document.documentElement.mozRequestFullScreen) {
             document.documentElement.mozRequestFullScreen();
         } else if (document.documentElement.webkitRequestFullScreen) {
             document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
         }
         fullScreen.setIcon(sap.ui.core.IconPool.getIconURI("exit-full-screen"));
         toolPage.setSideExpanded(true);
     } else {
         toolPage.setSideExpanded(true);
         fullScreen.setIcon(sap.ui.core.IconPool.getIconURI("full-screen"));
         if (document.cancelFullScreen) {
             document.cancelFullScreen();
         } else if (document.mozCancelFullScreen) {
             document.mozCancelFullScreen();
         } else if (document.webkitCancelFullScreen) {
             document.webkitCancelFullScreen();
         }
    }
}



// //Land to particular page
// if(hvi_user_access.indexOf('view_inspection_transaction')!=-1 || hvi_user_access.indexOf('create_inspection_transaction')!=-1 || hvi_user_access.indexOf('closed_inspection_transaction')!=-1 || hvi_user_access.indexOf('View_inspection_transaction')!=-1){
//     navContainer.to("inspection_report");
// }else if(hvi_user_access.indexOf('view_workshop')!=-1 || hvi_user_access.indexOf('create_workshop')!=-1 || hvi_user_access.indexOf('modify_workshop')!=-1 || hvi_user_access.indexOf('delete_workshop')!=-1){
//     navContainer.to("grab_workshop");
// }else if(hvi_user_access.indexOf('view_user_account')!=-1 || hvi_user_access.indexOf('create_user_account')!=-1 ||hvi_user_access.indexOf('modify_user_account')!=-1 ){
//     navContainer.to("grab_team_management");
// }else if(hvi_user_access.indexOf('view_approval_level')!=-1 || hvi_user_access.indexOf('modify_approval_level')!=-1 ){
//     navContainer.to("grab_approval_master");
// }else if(hvi_user_access.indexOf('view_supplier')!=-1 || hvi_user_access.indexOf('create_supplier')!=-1 || hvi_user_access.indexOf('modify_supplier')!=-1 || hvi_user_access.indexOf('delete_supplier')!=-1){
//     navContainer.to("grab_supplier");
// }else if(hvi_user_access.indexOf('view_schedule')!=-1 || hvi_user_access.indexOf('create_schedule')!=-1 || hvi_user_access.indexOf('modify_schedule')!=-1 || hvi_user_access.indexOf('delete_schedule')!=-1){
//     navContainer.to("grab_service_schedule");
// }else if(hvi_user_access.indexOf('view_assign_vehicle')!=-1 || hvi_user_access.indexOf('assign_vehicle')!=-1 || hvi_user_access.indexOf('modify_assign_vehicle')!=-1){
//     navContainer.to("grab_vehicle");
// }else if(hvi_user_access.indexOf('view_inspection_form')!=-1 || hvi_user_access.indexOf('delete_inspection_form')!=-1 || hvi_user_access.indexOf('modify_inspection_form')!=-1 || hvi_user_access.indexOf('create_inspection_form')!=-1){
//     navContainer.to("grab_checkpoint");
// }else if(hvi_user_access.indexOf('view_master_data_part_and_labour')!=-1 || hvi_user_access.indexOf('create_master_data_part_and_labour')!=-1 || hvi_user_access.indexOf('modify_master_data_part_and_labour')!=-1 || hvi_user_access.indexOf('delete_master_data_part_and_labour')!=-1){
//     navContainer.to("grab_part_master");
// }else if(hvi_user_access.indexOf('view_work_order')!=-1 || hvi_user_access.indexOf('create_work_order')!=-1 || hvi_user_access.indexOf('modify_work_order')!=-1 || hvi_user_access.indexOf('cancel_work_order')!=-1 ){
//     navContainer.to("grab_workorder");
// }else if(hvi_user_access.indexOf('create_invoice_work_order')!=-1 || hvi_user_access.indexOf('modify_invoice_work_order')!=-1){
//     navContainer.to("grab_invoice");
// }else if(hvi_user_access.indexOf('view_document')!=-1){
//     navContainer.to("grab_document");
// }else if(hvi_user_access.indexOf('supplier_invoice')!=-1){
//     navContainer.to("grab_supplier_invoice");
// }