<?php

class Garage extends mainController {

    public function __construct() {
        parent::__construct();
        $this->load->model('Garage');
    }

    public function landing() {
        $vars['error'] = false;
        $vars['pageName'] = 'Garage';
        $vars['title'] = GarageModel::getmsg('garage');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        //        $vars['all_vehicles']           = $this->_registry->vehicle->getAllVehicles_ID();
        //        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage']];

        $vars['menu_blocks'] = array(
            array('msg' => 'vehicles', 'prmsn' => 'VEHICLES', 'icon' => 'fa fa-truck'
                , 'detail' => array(
                    array('msg' => 'vehicle', 'prmsn' => 'ListVehicle', 'lnk' => SITE_LINK . 'Garage/VehicleList', 'icon' => 'fa fa-car')
                    , array('msg' => 'checkup_setting', 'prmsn' => 'checkup_setting', 'lnk' => SITE_LINK . 'Garage/checkupSetting', 'icon' => 'fa fa-wrench')
                    , array('msg' => 'checkup', 'prmsn' => 'vehicle_check_in_out', 'lnk' => SITE_LINK . 'Garage/VehicleCheckup', 'icon' => 'fa fa-wrench')
                    , array('msg' => 'checkup_list', 'prmsn' => 'vehicle_check_in_out_list', 'lnk' => SITE_LINK . 'Garage/VehicleCheckupList', 'icon' => 'fa fa-list')
                    , array('msg' => 'mecanique', 'prmsn' => 'vehicle_mecanique_list', 'lnk' => SITE_LINK . 'Garage/vehicle_mecanique_syndicate', 'icon' => 'fa fa-wrench'),
                    array('msg' => 'syndicate', 'prmsn' => 'vehicle_syndicate_list', 'lnk' => SITE_LINK . 'Garage/vehicle_mecanique_syndicate/syndicate', 'icon' => 'fa fa-wrench')
                    , array('msg' => 'checkup', 'prmsn' => 'vehicle_checkup_list', 'lnk' => SITE_LINK . 'Garage/vehicle_checkup', 'icon' => 'fa fa-wrench')
                    , array('msg' => 'vehicle_maintenance', 'prmsn' => 'vehicle_maintenance_list', 'lnk' => SITE_LINK . 'Garage/vehicle_maintenance', 'icon' => 'fa fa-wrench')
                )
            ),
            array('msg' => 'expenses', 'prmsn' => 'TruckExpenses', 'icon' => 'fa fa-money'
                , 'detail' => array(
                    array('msg' => 'fuel_tracker', 'prmsn' => 'fuel_tracker', 'lnk' => SITE_LINK . 'Garage/FuelList', 'icon' => 'fa fa-battery-full')
                    , array('msg' => 'vehicle_expenses', 'prmsn' => 'add_truck_expense', 'lnk' => SITE_LINK . 'Garage/VehicleExpenses', 'icon' => 'fa fa-usd')
                    , array('msg' => 'vehicle_expense_list', 'prmsn' => 'truck_expense_list', 'lnk' => SITE_LINK . 'Garage/VehicleExpenseList', 'icon' => 'fa fa-list')
                )),
            array('msg' => 'rent', 'prmsn' => 'rent', 'icon' => 'fa fa-gear'
                , 'detail' => array(
                    array('msg' => 'rent_type', 'prmsn' => 'rent_type', 'lnk' => SITE_LINK . 'Garage/rent_type', 'icon' => 'fa fa-list'),
                    array('msg' => 'vehicle_rents', 'prmsn' => 'vehicle_rents', 'lnk' => SITE_LINK . 'Garage/vehicle_rents', 'icon' => 'fa fa-list'),
                    array('msg' => 'multi_rent_payment', 'prmsn' => 'multi_rent_payment', 'lnk' => SITE_LINK . 'Garage/multi_rent_payment', 'icon' => 'fa fa-list')
                )
            ),
        );
        $this->load->view('Garage', $vars);
    }

    public function VehicleList() {

        $vars['pageName'] = 'ListVehicle';
        $vars['title'] = GarageModel::getmsg('vehicle_list');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        preg_match('/\/(\d+)$/', $_SERVER['REQUEST_URI'], $match);
        $vars['IsEdit'] = count($match) > 0 ? true : false;
        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('vehicle_list'), 'VehicleList']];
        $this->load->view('Garage/VehicleList', $vars);
    }

    public function ViewVehicle() {
        $vars['pageName'] = 'ViewVehicle';
        $vars['title'] = GarageModel::getmsg('vehicle_info');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['Vehicle_ID'] = (int) $url[count($url) - 1];
        $vars['IsEdit'] = (int) $url[count($url) - 1] ? true : false;
        $vars['VehicleInfo'] = $this->_registry->vehicle->getVehicleInfo($vars['Vehicle_ID']);
        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('vehicle_list'), 'VehicleList'], [GarageModel::getmsg('vehicle_info'), 'ViewVehicle/' . $vars['Vehicle_ID']]];
        $this->load->view('Garage/ViewVehicle', $vars);
    }

    public function vehicle_checkup() {
        $vars['pageName'] = 'vehicle_checkup_list';
        $vars['title'] = GarageModel::getmsg('checkup');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('checkup_list'), 'vehicle_checkup']];
        $this->load->view('Garage/vehicle_checkup', $vars);
    }

    public function vehicle_mecanique_syndicate() {
        preg_match("/\/syndicate\b/i", $_SERVER['REQUEST_URI'], $match_sales);
        $vars['is_syndicate'] = count($match_sales) > 0 ? true : false;
        $vars['is_modal_shown'] = !empty($_GET['modal']) ? 1 : 0;
        $vars['vehicle_id'] = !empty($_GET['vehicle_id']) ? $_GET['vehicle_id'] : '';
        $vars['vehicle_name'] = !empty($_GET['vehicle_name']) ? $_GET['vehicle_name'] : '';
        $vars['pageName'] = $vars['is_syndicate'] ? 'vehicle_syndicate_list' : 'vehicle_mecanique_list';
        $vars['title'] = GarageModel::getmsg($vars['is_syndicate'] ? 'syndicate' : 'mecanique');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg($vars['is_syndicate'] ? 'syndicate_list' : 'mecanique_list' ), 'vehicle_mecanique' . ($vars['is_syndicate'] ? '/syndicate' : '')]];
        $this->load->view('Garage/vehicle_mecanique', $vars);
    }

    public function vehicle_maintenance() {
        $vars['pageName'] = 'vehicle_maintenance_list';
        $vars['title'] = GarageModel::getmsg('vehicle_maintenance');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('vehicle_maintenance'), 'vehicle_maintenance']];
        $this->load->view('Garage/vehicle_maintenance', $vars);
    }

    public function VehicleExpenseList() {
        $vars['pageName'] = 'truck_expense_list';
        $vars['title'] = GarageModel::getmsg('vehicle_expense_list');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('vehicle_expense_list'), 'VehicleExpenseList']];
        $this->load->view('Garage/VehicleExpenseList', $vars);
    }

    public function VehicleExpenses() {
        $vars['pageName'] = 'add_truck_expense';
        $vars['title'] = GarageModel::getmsg('vehicle_expenses');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        $vars['all_vehicles'] = $this->_registry->vehicle->getAvailableVehicles();
        $vars['today'] = Date::getToday();
        $url = explode('/', $_SERVER['REQUEST_URI']);

        preg_match("/\/act/", $_SERVER['REQUEST_URI'], $match_a);
        $vars['IsEdit'] = is_numeric($url[count($url) - 1]) ? true : false;
        $vars['is_actual'] = count($match_a) > 0 ? true : false;
        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
        $DefaultCurSymbol = CurrencyFactory::getDefaultCurrencySymbol();
        $DefaultCurName = $this->_registry->Currency->getCurrencyNameByID($vars['DefaultCurrencyID']);
        $vars['currency_symbol'] = $DefaultCurName . ' -  ' . $DefaultCurSymbol;

        $vars['id'] = $vars['IsEdit'] ? $url[count($url) - 1] : 0;
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['edit_data'] = $vars['IsEdit'] ? $this->_registry->vehicle->getVehicleExpenseByID($vars['id']) : array();
        $vars['check_lock'] = $vars['IsEdit'] ? CommonFunctions::check_lock_data(['type' => 'vehicle_expense', 'start_date' => $vars['edit_data']['Main']['Truck_Expense_Date'], 'is_actual' => ($vars['is_actual'] ? 1 : 0)]) : '';

        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('vehicle_expenses'), 'VehicleExpenses']];
        $this->load->view('Garage/VehicleExpenses', $vars);
    }

    public function FuelList() {
        $vars['pageName'] = 'fuel_tracker';
        $vars['title'] = GarageModel::getmsg('fuel_consumption_list');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        $vars['today'] = Date::gettoday();
        $vars['year'] = date("Y", strtotime($vars['today'])); // get the year from today
        $vars['month'] = date("m", strtotime($vars['today'])); // get the month from today
        //        die($month);
        //        $vars['monthName']                  = date("F", mktime(0, 0, 0, $month, 10));// get Month Name
        //        $vars['fuelList'] = $this->_registry->vehicle->viewFuelConsumbtionPerMonth($month,$vars['year']);
        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('fuel_consumption_list'), 'FuelList']];
        $this->load->view('Garage/FuelList', $vars);
    }

    public function checkupSetting() {
        $vars['pageName'] = 'checkup_setting';
        $vars['title'] = GarageModel::getmsg('checkup_setting');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        $vars['today'] = Date::getToday();
        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('checkup_setting'), 'checkupSetting']];
        $this->load->view('Garage/checkup_setting', $vars);
    }

    public function VehicleCheckup() {
        $vars['pageName'] = 'vehicle_check_in_out';
        $vars['title'] = GarageModel::getmsg('checkup');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        $vars['today'] = Date::getToday();
        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('checkup'), 'VehicleCheckup']];
        $this->load->view('Garage/VehicleCheckup', $vars);
    }

    public function VehicleCheckupList() {
        $vars['pageName'] = 'vehicle_check_in_out_list';
        $vars['title'] = GarageModel::getmsg('checkup_list');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        $vars['all_vehicles'] = $this->_registry->vehicle->getAllVehicles();
        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('checkup_list'), 'VehicleCheckupList']];
        $this->load->view('Garage/VehicleCheckupList', $vars);
    }

    public function rent_type() {
        $vars['pageName'] = 'rent_type';
        $vars['title'] = GarageModel::getmsg('rent_type');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('rent_type'), 'rent_type']];
        $this->load->view('Garage/rent-type', $vars);
    }

    public function vehicle_rents() {
        $vars['pageName'] = 'vehicle_rents';
        $vars['title'] = GarageModel::getmsg('vehicle_rents');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        $vars['vehicle_rent_account_id'] = smc_session()['account_setting']['vehicle_rent_account_id'];
        $vars['vehicle_rent_account'] = CommonFunctions::CommonView('tbl_chart_of_accounts', ['Account_ID'], [$vars['vehicle_rent_account_id']])[0];
        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('vehicle_rents'), 'vehicle_rents']];
        $this->load->view('Garage/vehicle_rents', $vars);
    }

    public function multi_rent_payment() {
        $vars['pageName'] = 'multi_rent_payment';
        $vars['title'] = GarageModel::getmsg('multi_rent_payment');
        $vars['system_name'] = GarageModel::getmsg('garage_sys');
        $vars['payment_type'] = $this->_registry->payment->viewPaymentTypes();

        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('multi_rent_payment'), 'multi_rent_payment']];
        $this->load->view('Garage/multi_rent_payment', $vars);
    }

    //    public function VehicleMaintenance() {
    //        $vars['pageName'] = 'VehicleMaintenance';
    //        $vars['title'] = GarageModel::getmsg('vehicle_maintenance');
    //        $vars['system_name'] = GarageModel::getmsg('garage_sys');
    //        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('vehicle_maintenance'), 'VehicleMaintenance']];
    //        $this->load->view('Garage/VehicleMaintenance', $vars);
    //    }
    //    public function VehicleDriverList() {
    //        $vars['pageName'] = 'ViewVehicle';
    //
    //        $vars['title'] = GarageModel::getmsg('vehicle_driver_list');
    //        $vars['system_name'] = GarageModel::getmsg('garage_sys');
    //        $url = $_SERVER['REQUEST_URI'];
    //        $vars['num'] = intval(substr($url, strrpos($url, '/') + 1));
    //        $vars['vehicleDriverlist_ID'] = $this->_registry->vehicle->getVehicleDriver_ID($vars['num']);
    //        $vars['all_vehicles'] = $this->_registry->vehicle->getVehicles();
    //        $vars['all_usageTypes'] = $this->_registry->vehicle->getUsageType();
    //        $vars['all_drivers'] = $this->_registry->vehicle->getDriver();
    //        $vars['all_salesman'] = $this->_registry->vehicle->getSalesMan();
    //        $vars['all_shifts'] = $this->_registry->employee->viewShifts();
    //        $vars['all_zones'] = $this->_registry->vehicle->getVehicleZones();
    //        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('vehicle_driver_list'), 'VehicleDriverList']];
    //        $this->load->view('Garage/VehicleDriverList', $vars);
    //    }
    //    public function DailyCheckupList() {
    //        $vars['pageName'] = 'ViewVehicle';
    //
    //        $vars['title'] = GarageModel::getmsg('daily_checkup_list');
    //        $vars['system_name'] = GarageModel::getmsg('garage_sys');
    //        $vars['today'] = Date::gettoday();
    //        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('daily_checkup_list'), 'DailyCheckupList']];
    //        $this->load->view('Garage/DailyCheckupList', $vars);
    //    }
    //    public function VehicleSchedule() {
    //        $vars['pageName'] = 'VehicleSchedule';
    //        $vars['title'] = GarageModel::getmsg('truck_availability');
    //        $vars['system_name'] = GarageModel::getmsg('garage_sys');
    //        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('truck_availability'), 'VehicleSchedule']];
    //        $this->load->view('Garage/VehicleSchedule', $vars);
    //    }
    //    public function GarageDashboard() {
    //        $vars['pageName'] = 'GarageDashboard';
    //        $vars['title'] = GarageModel::getmsg('dashboard');
    //        $vars['system_name'] = GarageModel::getmsg('garage_sys');
    //        $vars['availableTrucks'] = $this->_registry->vehicle->getCountAvailableTrucks();
    //        $vars['maintainTrucks'] = $this->_registry->vehicle->getCountTruckToMaintain();
    //        $vars['LoadedTrucks'] = $this->_registry->vehicle->GetCountLoadedTrucks();
    //        $vars['TruckExpense'] = $this->_registry->vehicle->getDailyTruckExpense();
    //        $vars['today'] = Date::getToday();
    //        $vars['per_days'] = GarageModel::getPieforGarage();
    //        $vars['arrName1'] = GarageModel::topSales()[0];
    //        $vars['arrValue1'] = GarageModel::topSales()[1];
    //        $DefaultCurrencyID        = $this->_registry->Currency->getDefaultCurrency();
    //        $vars['DefaultCurrSymbol']        = $this->_registry->Currency->viewCurrencySymbol($DefaultCurrencyID);
    //        $vars['dailyCheckup']      = $this->_registry->vehicle->viewDailyCheckup($vars['today']);
    //        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('dashboard'), 'GarageDashboard']];
    //        $this->load->view('Garage/GarageDashboard', $vars);
    //    }
    //
    //    public function WeighBridgeList() {
    //        $vars['pageName'] = 'WeighBridgeList';
    //        $vars['title'] = GarageModel::getmsg('weighbridge_list');
    //        $vars['system_name'] = GarageModel::getmsg('garage_sys');
    //        $vars['today'] = Date::getToday();
    //        $vars['year'] = date("Y", strtotime($vars['today'])); // get the year from today
    //        $month = date("m", strtotime($vars['today'])); // get the month from today
    //        $vars['monthName'] = date("F", mktime(0, 0, 0, $month, 10));
    //        $vars['breadCrumb'] = [[GarageModel::getmsg('garage'), 'Garage'], [GarageModel::getmsg('weighbridge_list'), 'WeighBridgeList']];
    //        $this->load->view('Garage/WeighBridgeList', $vars);
    //    }
}
