<?php

class Maintenance extends mainController {

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

    public function landing() {
        $vars['pageName'] = 'production';
        $vars['title'] = CommonLanguage::getMessage('production');
        $vars['system_name'] = CommonLanguage::getMessage('production');
        $vars['menu_blocks'] = array(
            array('msg' => 'checklist', 'prmsn' => 'checklist_setting', 'icon' => 'fa fa-gear'
                , 'detail' => array(
                    array('msg' => 'checklist', 'prmsn' => 'checklist', 'lnk' => SITE_LINK . 'Maintenance/checklist', 'icon' => 'fa fa-list'),
                    array('msg' => 'schedule_checklist', 'prmsn' => 'schedule_checklist', 'lnk' => SITE_LINK . 'Maintenance/schedule_checklist', 'icon' => 'fa fa-list'),
                    array('msg' => 'answers_checklist_schedule', 'prmsn' => 'answers_checklist_schedule', 'lnk' => SITE_LINK . 'Maintenance/answers_checklist_schedule', 'icon' => 'fa fa-list'),
                    array('msg' => 'history_scheduled_checklist', 'prmsn' => 'history_scheduled_checklist', 'lnk' => SITE_LINK . 'Maintenance/history_scheduled_checklist', 'icon' => 'fa fa-list'),
                    array('msg' => 'missed_schedule_checklist', 'prmsn' => 'missed_schedule_checklist', 'lnk' => SITE_LINK . 'Maintenance/missed_schedule_checklist', 'icon' => 'fa fa-list')
                )
            ),
            array('msg' => 'production_setting', 'prmsn' => 'production_settings', 'icon' => 'fa fa-gear'
                , 'detail' => array(
                    array('msg' => 'production_emp_type', 'prmsn' => 'production_emp_type', 'lnk' => SITE_LINK . 'Maintenance/production_employee_type', 'icon' => 'fa fa-list')
                    , array('msg' => 'simple_production_template', 'prmsn' => 'production_template', 'lnk' => SITE_LINK . 'Maintenance/production_template', 'icon' => 'fa fa-pencil')
                    , array('msg' => 'adv_production_template', 'prmsn' => 'adv_production_template', 'lnk' => SITE_LINK . 'Maintenance/production_template/adv', 'icon' => 'fa fa-pencil')
                    , array('msg' => 'machines_parts', 'prmsn' => 'machines_parts', 'lnk' => SITE_LINK . 'Maintenance/machines_parts', 'icon' => 'fa fa-cogs'),
                    array('msg' => 'line', 'prmsn' => 'line', 'lnk' => SITE_LINK . 'Maintenance/line', 'icon' => 'fa fa-cogs'),
                    array('msg' => 'machine_properties_values', 'prmsn' => 'machine_properties_values', 'lnk' => SITE_LINK . 'Maintenance/machine_properties_values', 'icon' => 'fa fa-list'),
                ),
            ),
            array('msg' => 'machine_expenses', 'prmsn' => 'production_expenses', 'icon' => 'fa fa-chart'
                , 'detail' => array(
                    array('msg' => 'machine_expenses', 'prmsn' => 'machine_expenses', 'lnk' => SITE_LINK . 'Maintenance/machine_expenses', 'icon' => 'fa fa-money'),
                    array('msg' => 'total_machine_expenses', 'prmsn' => 'total_machine_expenses', 'lnk' => SITE_LINK . 'Maintenance/total_machine_expenses', 'icon' => 'fa fa-list'),
                    array('msg' => 'detail_machine_expenses', 'prmsn' => 'detail_machine_expenses', 'lnk' => SITE_LINK . 'Maintenance/detail_machine_expenses', 'icon' => 'fa fa-list')
                )
            ),
            array('msg' => 'production_process_management', 'prmsn' => 'production_process_mgt', 'icon' => 'fa fa-chart'
                , 'detail' => array(
                    array('msg' => 'production_process', 'prmsn' => 'production_process', 'lnk' => SITE_LINK . 'Maintenance/production_process', 'icon' => 'fa fa-pencil')
                    , array('msg' => 'production_process_touch', 'prmsn' => 'production_process_touch', 'lnk' => SITE_LINK . 'Maintenance/production_process_touch', 'icon' => 'fa fa-pencil')
                    , array('msg' => 'production_report', 'prmsn' => 'production_report', 'lnk' => SITE_LINK . 'Maintenance/production_report', 'icon' => 'fa fa-pencil')
                    , array('msg' => 'effective_production_report', 'prmsn' => 'effective_production_report', 'lnk' => SITE_LINK . 'Maintenance/production_process_template_report', 'icon' => 'fa fa-pencil')
                    , array('msg' => 'production_barcode', 'prmsn' => 'production_barcode', 'lnk' => SITE_LINK . 'Maintenance/production_barcode', 'icon' => 'fa fa-pencil')
                    , array('msg' => 'production_color', 'prmsn' => 'production_color', 'lnk' => SITE_LINK . 'Maintenance/production_color', 'icon' => 'fa fa-pencil')

                    )
            )
        );
        $this->load->view('Maintenance', $vars);
    }

    public function checklist() {
        $vars['pageName'] = 'checklist';
        $vars['title'] = CommonLanguage::getMessage('checklist');
        $vars['system_name'] = CommonLanguage::getMessage('maintenance');
        $vars['breadCrumb'] = [[settingModel::getmsg('production'), 'Maintenance'], [settingModel::getmsg('checklist'), 'checklist']];
        $this->load->view('Maintenance/checklist', $vars);
    }

    public function machine_properties_values() {
        $vars['pageName'] = 'machine_properties_values';
        $vars['title'] = CommonLanguage::getMessage('machine_properties_values');
        $vars['system_name'] = CommonLanguage::getMessage('maintenance');
        $vars['breadCrumb'] = [[settingModel::getmsg('production'), 'Maintenance'], [settingModel::getmsg('machine_properties_values'), 'machine_properties_values']];
        $this->load->view('Maintenance/machine_properties_values', $vars);
    }

    public function schedule_checklist() {
        $vars['pageName'] = 'schedule_checklist';
        $vars['title'] = CommonLanguage::getMessage('schedule_checklist');
        $vars['system_name'] = CommonLanguage::getMessage('maintenance');
        $vars['breadCrumb'] = [[settingModel::getmsg('production'), 'Maintenance'], [settingModel::getmsg('schedule_checklist'), 'schedule_checklist']];
        $this->load->view('Maintenance/schedule_checklist', $vars);
    }

    public function answers_checklist_schedule() {
        $vars['pageName'] = 'answers_checklist_schedule';
        $vars['title'] = CommonLanguage::getMessage('answers_checklist_schedule');
        $vars['system_name'] = CommonLanguage::getMessage('maintenance');
        $vars['breadCrumb'] = [[settingModel::getmsg('production'), 'Maintenance'], [settingModel::getmsg('answers_checklist_schedule'), 'answers_checklist_schedule']];
        $this->load->view('Maintenance/answers_checklist_schedule', $vars);
    }

    public function history_scheduled_checklist() {
        $vars['pageName'] = 'history_scheduled_checklist';
        $vars['title'] = CommonLanguage::getMessage('history_scheduled_checklist');
        $vars['system_name'] = CommonLanguage::getMessage('maintenance');
        $vars['breadCrumb'] = [[settingModel::getmsg('production'), 'Maintenance'], [settingModel::getmsg('history_scheduled_checklist'), 'history_scheduled_checklist']];
        $this->load->view('Maintenance/history_scheduled_checklist', $vars);
    }

    public function missed_schedule_checklist() {
        $vars['pageName'] = 'missed_schedule_checklist';
        $vars['title'] = CommonLanguage::getMessage('missed_schedule_checklist');
        $vars['system_name'] = CommonLanguage::getMessage('maintenance');
        $vars['breadCrumb'] = [[settingModel::getmsg('production'), 'Maintenance'], [settingModel::getmsg('missed_schedule_checklist'), 'missed_schedule_checklist']];
        $this->load->view('Maintenance/missed_schedule_checklist', $vars);
    }

    public function machine_expenses() {
        $vars['pageName'] = 'machine_expenses';
        $vars['title'] = CommonLanguage::getMessage('machine_expenses');
        $vars['system_name'] = CommonLanguage::getMessage('maintenance');
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['breadCrumb'] = [[settingModel::getmsg('production'), 'Maintenance'], [settingModel::getmsg('machine_expenses'), 'machine_expenses']];
        $this->load->view('Maintenance/machine_expenses', $vars);
    }

    public function total_machine_expenses() {
        $vars['pageName'] = 'total_machine_expenses';
        $vars['title'] = CommonLanguage::getMessage('total_machine_expenses');
        $vars['system_name'] = CommonLanguage::getMessage('maintenance');
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        //        $data = $this->_registry->product->total_product_expenses_report('2018-01-01', '2018-08-30');
        //        echo "<pre>";die(print_r($data));
        $vars['breadCrumb'] = [[settingModel::getmsg('production'), 'Maintenance'], [settingModel::getmsg('total_machine_expenses'), 'total_machine_expenses']];
        $this->load->view('Maintenance/total_machine_expenses', $vars);
    }

    public function detail_machine_expenses() {
        $vars['pageName'] = 'detail_machine_expenses';
        $vars['title'] = CommonLanguage::getMessage('detail_machine_expenses');
        $vars['system_name'] = CommonLanguage::getMessage('maintenance');
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        //        $data = $this->_registry->product->detail_product_expenses_report('2018-01-01', '2018-08-30');
        //        echo "<pre>";die(print_r($data));
        $vars['breadCrumb'] = [[settingModel::getmsg('production'), 'Maintenance'], [settingModel::getmsg('detail_machine_expenses'), 'detail_machine_expenses']];
        $this->load->view('Maintenance/detail_machine_expenses', $vars);
    }

    public function line() {
        $vars['pageName'] = 'line';
        $vars['title'] = inventoryModel::getmsg('line');
        $vars['system_name'] = inventoryModel::getmsg('maintenance');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('production'), 'Maintenance'], [inventoryModel::getmsg('line'), 'line']];
        $this->load->view('Maintenance/line', $vars);
    }

    public function line_machines() {
        $vars['pageName'] = 'line_machines';
        $vars['title'] = inventoryModel::getmsg('line_machines');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];
        $vars['product_machines'] = $this->_registry->checklist->getMachineLines($vars['id']);
        ;
        //        $vars['product_machines']= CommonFunctions::CommonView('tbl_line_machine',['line_id'],[$vars['id']]);
        $vars['system_name'] = inventoryModel::getmsg('production');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('production'), 'Maintenance'], [inventoryModel::getmsg('line_machines'), 'line_machines']];
        $this->load->view('Maintenance/line_machines', $vars);
    }

    public function production_template() {
        preg_match("/\/adv\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_adv'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_adv'] == 1 ? 'adv_production_template' : 'production_template';
        $vars['title'] = inventoryModel::getmsg($vars['is_adv'] == 1 ? 'adv_production_template' : 'simple_production_template');
        $vars['system_name'] = inventoryModel::getmsg('production');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('production'), 'Maintenance'], [$vars['title'], 'production_template' . ($vars['is_adv'] == 1 ? '/adv' : '')]];
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $this->load->view('Maintenance/production_template', $vars);
    }

    public function production_employee_type() {
        $vars['pageName'] = 'production_emp_type';
        $vars['title'] = inventoryModel::getmsg('production_emp_type');
        $vars['system_name'] = inventoryModel::getmsg('production');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('production'), 'Maintenance'], [inventoryModel::getmsg('production_emp_type'), 'production_employee_type']];
        $this->load->view('Maintenance/production_employee_type', $vars);
    }

    public function production_process() {
        $vars['pageName'] = 'production_process';
        $vars['title'] = inventoryModel::getmsg('production');
        $vars['system_name'] = inventoryModel::getmsg('production');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('production'), 'Maintenance'], [inventoryModel::getmsg('production_process'), 'production_process']];
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['color'] = $this->_registry->product->get_all_production_color();
        $vars['today'] = Date::getToday();
        $this->load->view('Maintenance/production_process', $vars);
    }

    public function production_process_touch() {
        $vars['pageName'] = 'production_process_touch';
        $vars['title'] = inventoryModel::getmsg('production');
        $vars['system_name'] = inventoryModel::getmsg('production');
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['templates_cat'] = CommonFunctions::CommonView('tbl_production_category');

        $vars['templates'] = $this->_registry->production->get_production_templates(0);
//        echo'<pre>';
//        die(print_r($vars['templates']));
        $this->load->view('Maintenance/production_process_touch', $vars);
    }
    public function production_barcode() {
        $vars['pageName'] = 'production_barcode';
        $vars['title'] = inventoryModel::getmsg('production');
        $vars['system_name'] = inventoryModel::getmsg('production');
         
          //        echo"<pre>";
        //        die(print_r($_GET));
         $vars['breadCrumb'] = [[inventoryModel::getmsg('production'), 'Maintenance'], [inventoryModel::getmsg('production_barcode'), 'production_barcode']];
        $this->load->view('Maintenance/production_barcode', $vars);
    }
    public function production_color() {
        $vars['pageName'] = 'production_color';
        $vars['title'] = inventoryModel::getmsg('production_color');
        $vars['system_name'] = inventoryModel::getmsg('production_color');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('production'), 'Maintenance'], [inventoryModel::getmsg('production_color'), 'production_color']];
        $this->load->view('Maintenance/production_color', $vars);
    }

    public function production_report() {
        $vars['pageName'] = 'production_report';
        $vars['title'] = inventoryModel::getmsg('production_report');
        $vars['system_name'] = inventoryModel::getmsg('production');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('production_report'), 'production_report']];
        $this->load->view('Maintenance/production_report', $vars);
    }

    public function machines_parts() {
        $vars['pageName'] = 'machines_parts';
        $vars['title'] = inventoryModel::getmsg('machines_parts');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['max_code'] = $this->_registry->product->getMaxProductCode();
        $vars['check_uom'] = $this->_registry->product->check_if_default_uom();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('production'), 'Maintenance'], [inventoryModel::getmsg('machines_parts'), 'machines_parts']];
        $this->load->view('Maintenance/machines_parts', $vars);
    }

    public function production_process_template_report() {
        $vars['pageName'] = 'effective_production_report';
        $vars['title'] = inventoryModel::getmsg('effective_production_report');
        $vars['system_name'] = inventoryModel::getmsg('production');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('production'), 'Maintenance'], [inventoryModel::getmsg('effective_production_report'), 'production_process_template_report']];
        $this->load->view('Maintenance/production_process_template_report', $vars);
    }

}
