
jQuery.sap.require("sap.m.MessageBox");
var HVICore = sap.ui.getCore();
var TableHeader = new sap.m.Label({ wrapping: true, design:sap.m.LabelDesign.Bold});

var busyDialog =  new sap.m.BusyDialog({text: oBundle.getText('Loading')});
var busyDialogGetData = new sap.m.BusyDialog({text: oBundle.getText('getting_data')});
// var busyDialogSchedule = new sap.m.BusyDialog({text: oBundle.getText('Automatic schedule is creating on vehicle')});

var vehicleCount = 0;
var vehicleJSONArray = [];

var availableVehicleJSONArray = [];
var inMaintenanceVehicleJSONArray = [];
var breakdownVehicleJSONArray = [];
var MaintenanceReqVehicleJSONArray = [];

// function funGetVehicle() {

//    availableVehicleJSONArray = [];
//    inMaintenanceVehicleJSONArray = [];
//    breakdownVehicleJSONArray = [];
//    MaintenanceReqVehicleJSONArray = [];
//    oTableVehicle.setBusy(true);
   
//    funGetAssignedVehicle();

//    HVI_VehiclesInv.where(queryUserEmail(1)).includeTotalCount().take(2000).orderByDescending("createdAt").read().done(function (result) {
       
//        var results=funFilterJsonByVehicle(result);
//        vehicleCount = results.length;

//     //    if(results.length <= 0){
//     //         busyDialog.close();
//     //         oTableVehicle.setBusy(false);
//     //         console.log("close kr diya")
//     //     }
    
//        var oModel = new sap.ui.model.json.JSONModel();
//        oModel.setData({ modelData: results });

//        oTableVehicle.setModel(oModel);
//        oModel.setSizeLimit(results.length);
//        oTableVehicle.bindItems({ path: "/modelData", template: vehicleTemplate });
//        oTableVehicle.setBusy(false);

//        oTablePickVehicle.setModel(oModel);
//        oTablePickVehicle.bindItems({ path: "/modelData", template: PickVehicleTemplate });

//        oTFWOV1.setModel(oModel);
//        oTFWOV1.bindAggregation("suggestionItems", "/modelData", new sap.ui.core.ListItem({
//            key: "{vehicle_serial}", text: "{vehicle_serial}"
//        }));

//        busyDialog.close();

//        vehicleArray = new Array();

//        var AvailableCount = 0;
//        var MaintenanceCount = 0;
//        var breakdownCount = 0;
//        var MaintenanceReqCount = 0;

//        var oDataTopRunning = [];
//        var oDataVehicle = [];

//        for (var i = 0; i < vehicleCount; i++) {
//            var vehicle = results[i]['vehicle_serial'];
//            vehicleArray.push(vehicle);

//            var vehicle_number = results[i]['vehicle_serial'];
//            var vehicle_meter = results[i]['odometer'];

//            if (oDataVehicle.indexOf(vehicle_number) > -1) {
//                var objValue = oDataTopRunning[oDataVehicle.indexOf(vehicle_number)].meter;
//                oDataTopRunning[oDataVehicle.indexOf(vehicle_number)].meter = parseFloat(objValue) + parseFloat(vehicle_meter);
//            } else {
//                oDataVehicle.push(vehicle_number);
//                oDataTopRunning.push({ vehicle: vehicle_number, meter: parseFloat(vehicle_meter) });
//            }

//            if (results[i]['status'] == oBundle.getText("Available") || results[i]['status']=="1" || results[i]['status']=="6") {
//                AvailableCount = AvailableCount + 1;
//                availableVehicleJSONArray.push(results[i]);
//            }else if (results[i]['status'] == oBundle.getText("Breakdown") || results[i]['status']=="4") {
//                breakdownCount = breakdownCount + 1;
//                breakdownVehicleJSONArray.push(results[i]);
//            }else if (results[i]['status'] == oBundle.getText("In_Maintenance") || results[i]['status']=="2") {
//                MaintenanceCount = MaintenanceCount + 1;
//                inMaintenanceVehicleJSONArray.push(results[i]);
//            }else if (results[i]['status'] == oBundle.getText("Maintenance_Required") || results[i]['status']=="3") {
//                MaintenanceReqCount = MaintenanceReqCount + 1;
//                MaintenanceReqVehicleJSONArray.push(results[i]);
//            }
//        }

//        list1.setInfo(vehicleCount);
//        list2.setInfo(AvailableCount);
//        list3.setInfo(MaintenanceCount);
//        listV3.setInfo(breakdownCount);
//        listV4.setInfo(MaintenanceReqCount);

//        var oDataVehicleStatusCountChart = [];

//        oDataVehicleStatusCountChart.push({ item: oBundle.getText("Active"), count: AvailableCount });
//        oDataVehicleStatusCountChart.push({ item: oBundle.getText("Maintenance"), count: MaintenanceCount + MaintenanceReqCount});
//        oDataVehicleStatusCountChart.push({ item: oBundle.getText("Breakdown"), count: breakdownCount });

//        var oModelVehicleStatusCountChart = new sap.ui.model.json.JSONModel();
//        oModelVehicleStatusCountChart.setData({ modelData: oDataVehicleStatusCountChart });
//        oPieChartVehicleStatusCount.setModel(oModelVehicleStatusCountChart);

//        oDataTopRunning.sort(function (a, b) {
//            return b.meter - a.meter;
//        });

//        var oModelTopRunningChart = new sap.ui.model.json.JSONModel();
//        oModelTopRunningChart.setData({ modelData: oDataTopRunning });
//        oChartTopRunningVehicle.setModel(oModelTopRunningChart);
//        oChartTopRunningVehicle.setBusy(false);

//    });
// }

// function funGetAssignedVehicle() {

//    HVI_VehiclesInv.where({ user_email: emailUser }).includeTotalCount().take(2000).orderByDescending("createdAt").read().done(function (result) {
      
//        var results=funFilterJsonByVehicle(result);
//        vehicleJSONArray = results;

//    });
// }
/*
 function funGetAssignedVehicle() {

    HVI_VehiclesInv.where({ user_email: emailUser }).includeTotalCount().take(2000).orderByDescending("createdAt").read().done(function (result) {
       
        var results=funFilterJsonByVehicle(result);
        vehicleJSONArray = results;

    });
 }*/

function textFieldValidation(textField,value){
    
    if (value.trim() == "") {                            
       textField.setValueState("Error");
       textField.setValueStateText("Required");          
       return true;
   }else{
       textField.setValueState("None");         
       return false;
   }
}

var standartBusyDialog = new sap.m.BusyDialog({
    title: oBundle.getText('Uploading'),
    text: '',
    showCancelButton: false,
    close: function (oEvent) {
}});
