<?php

class Ticketing extends mainController {

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

    public function landing() {
        $vars['pageName'] = 'ticketing';
        $vars['title'] = ACCModel::getmsg('ticketing');
        $vars['menu_blocks'] = array(
            array('msg' => 'ticketing_setting', 'prmsn' => 'ticketing_setting', 'icon' => 'fa fa-cog'
                  , 'detail' => array(
                      array('msg' => 'ticketing_type_list', 'prmsn' => 'ticketing_type', 'lnk' => SITE_LINK . 'Ticketing/ticketing_type_list', 'icon' => 'fa fa-list'),
                      array('msg' => 'ticketing_station_list', 'prmsn' => 'station', 'lnk' => SITE_LINK . 'Ticketing/ticketing_station_list', 'icon' => 'fa fa-list'),
                      array('msg' => 'ticketing_list', 'prmsn' => 'ticketing_list', 'lnk' => SITE_LINK . 'Ticketing/ticketing_list', 'icon' => 'fa fa-list'),
                      array('msg' => 'ticketing_calendar', 'prmsn' => 'ticketing_calendar', 'lnk' => SITE_LINK . 'Ticketing/ticketing_calendar', 'icon' => 'fa fa-calendar'),
                  )
                  ),
                  array('msg' => 'maintenance', 'prmsn' => 'Maintenance', 'icon' => 'fa fa-cog'
                  , 'detail' => array(
                    array('msg' => 'maintenance_type_list', 'prmsn' => 'maintenance_type_list', 'lnk' => SITE_LINK . 'Ticketing/maintenance_type_list', 'icon' => 'fa fa-list'),
                    //   array('msg' => 'maintenance_supporter', 'prmsn' => 'maintenance_supporter', 'lnk' => SITE_LINK . 'Ticketing/maintenance_supporter', 'icon' => 'fa fa-list'),
                    array('msg' => 'maintenance_list', 'prmsn' => 'maintenance_list', 'lnk' => SITE_LINK . 'Ticketing/maintenance_list', 'icon' => 'fa fa-list'),
                  )
                 ),
                 array('msg' => 'General Appointment', 'prmsn' => 'General_Appointment', 'icon' => 'fa fa-cog'
                 , 'detail' => array(
                     array('msg' => 'event_list', 'prmsn' => 'event_list', 'lnk' => SITE_LINK . 'Ticketing/event_list', 'icon' => 'fa fa-list'),
                     array('msg' => 'appointment_list', 'prmsn' => 'appointment_list', 'lnk' => SITE_LINK . 'Ticketing/appointment_list', 'icon' => 'fa fa-list'),
                 )
                )
        );
        $this->load->view('Ticketing', $vars);
    }
    public function ticketing_type_list() {
        $vars['pageName'] = 'ticketing_type';
        $vars['title'] = TicketingModel::getmsg('ticketing_type_list');
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('ticketing_type_list'), 'ticketing_type_list']];
        $this->load->view('ticketing/ticketing_type_list', $vars);
    }
    public function maintenance_type_list() {
        $vars['pageName'] = 'maintenance_type_list';
        $vars['title'] = TicketingModel::getmsg('maintenance_type_list');
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('maintenance_type_list'), 'maintenance_type_list']];
        $this->load->view('ticketing/maintenance_type_list', $vars);
    }
    public function maintenance_supporter() {
        $vars['pageName'] = 'maintenance_supporter';
        $vars['title'] = TicketingModel::getmsg('maintenance_supporter');
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('maintenance_supporter'), 'maintenance_supporter']];
        $this->load->view('ticketing/maintenance_supporter', $vars);
    }

    public function ticketing_station_list() {
        $vars['pageName'] = 'station';
        $vars['title'] = TicketingModel::getmsg('ticketing_station_list');
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('ticketing_station_list'), 'ticketing_station_list']];
        $this->load->view('ticketing/ticketing_station_list', $vars);
    }
    public function ticketing_list() {
        $vars['pageName'] = 'ticketing_list';
        $vars['title'] = TicketingModel::getmsg('ticketing_list');
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('ticketing_list'), 'ticketing_list']];
        $this->load->view('ticketing/ticketing_list', $vars);
    }
    public function maintenance_list() {
        $vars['pageName'] = 'maintenance_list';
        $vars['title'] = TicketingModel::getmsg('maintenance_list');
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('maintenance_list'), 'maintenance_list']];
        $this->load->view('ticketing/maintenance_list', $vars);
    }
    public function event_list() {
        $vars['pageName'] = 'event_list';
        $vars['title'] = TicketingModel::getmsg('event_list');
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('event_list'), 'event_list']];
        $this->load->view('ticketing/event_list', $vars);
    }
    public function appointment_list() {
        $vars['pageName'] = 'appointment_list';
        $vars['title'] = TicketingModel::getmsg('appointment_list');
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('appointment_list'), 'appointment_list']];
        $this->load->view('ticketing/appointment_list', $vars);
    }

    public function view_ticketing_replies() {
        $vars['pageName'] = 'view_ticketing_replies';
        $vars['title'] = TicketingModel::getmsg('view_ticketing_replies');
        if(!empty($_GET['id']) && is_numeric($_GET['id'])){
            $vars['data'] = $this->_registry->ticketing_class->get_ticketing_replies($_GET['id']);
        }
        //        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('view_ticketing_reply'), 'view_ticketing_reply']];
        $this->load->view('ticketing/view_ticketing_replies', $vars);
    }
    public function ticketing() {
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['ticketing_id'] = is_numeric($url[count($url) - 1]) ? $url[count($url) - 1] : 0;
        $vars['edit_arr'] = $vars['ticketing_id']== 0 ? array() : $this->_registry->ticketing_class->get_ticketing_data($vars['ticketing_id']);
        $vars['ticketing_status'] = CommonFunctions::CommonView('tbl_ticketing_status');
        $vars['default_currency_id'] = $this->_registry->currency->getDefaultCurrency();
        $default_currency = $this->_registry->currency->getCurrencyByID($vars['default_currency_id']);
        $vars['default_currency_name'] = !empty($default_currency) ? ($default_currency[1].' '.$default_currency[0]) : '';
        if ($vars['ticketing_id'] == 0) {
//            $vars['unique_id'] = 'inv' . uniqid();
//            smc_session()['duplicate_check'][$vars['unique_id']] = true;
            $vars['unique_id'] = token_unique::generate_token('ticket');
            
        }
        //        echo '<pre>';
        //        print_r($vars['default_currency']);
        $vars['pageName'] = $vars['ticketing_id'] == 0 ? 'add_ticketing' : 'edit_ticketing';
        $vars['title'] = TicketingModel::getmsg($vars['ticketing_id'] == 0 ? 'add_ticketing' : 'edit_ticketing');
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('ticketing_list'), 'ticketing_list'], [$vars['title'], 'ticketing'.($vars['ticketing_id'] != 0  ? "/{$vars['ticketing_id']}" : "")]];
        $this->load->view('ticketing/ticketing', $vars);
    }
    public function add_maintenance() {
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['ticketing_id'] = is_numeric($url[count($url) - 1]) ? $url[count($url) - 1] : 0;
        $vars['edit_arr'] = $vars['ticketing_id']== 0 ? array() : $this->_registry->ticketing_class->get_maintenance_data($vars['ticketing_id']);
        $vars['ticketing_status'] = CommonFunctions::CommonView('tbl_ticketing_status');
        $vars['default_currency_id'] = $this->_registry->currency->getDefaultCurrency();
        $default_currency = $this->_registry->currency->getCurrencyByID($vars['default_currency_id']);
        $vars['default_currency_name'] = !empty($default_currency) ? ($default_currency[1].' '.$default_currency[0]) : '';
        if ($vars['ticketing_id'] == 0) {
//            $vars['unique_id'] = 'inv' . uniqid();
//            smc_session()['duplicate_check'][$vars['unique_id']] = true;
            $vars['unique_id'] = token_unique::generate_token('ticket');
            
        }
        //        echo '<pre>';
        //        print_r($vars['default_currency']);
        $vars['pageName'] = $vars['ticketing_id'] == 0 ? 'add_maintenance' : 'edit_maintenance';
        $vars['title'] = TicketingModel::getmsg($vars['ticketing_id'] == 0 ? 'add_maintenance' : 'edit_maintenance');
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('maintenance_list'), 'maintenance_list'], [$vars['title'], 'add_maintenance'.($vars['ticketing_id'] != 0  ? "/{$vars['ticketing_id']}" : "")]];
        $this->load->view('ticketing/add_maintenance', $vars);
    }
    public function add_event() {
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['ticketing_id'] = is_numeric($url[count($url) - 1]) ? $url[count($url) - 1] : 0;
        $vars['edit_arr'] = $vars['ticketing_id']== 0 ? array() : $this->_registry->ticketing_class->get_event_data($vars['ticketing_id']);
         if ($vars['ticketing_id'] == 0) {
//            $vars['unique_id'] = 'inv' . uniqid();
//            smc_session()['duplicate_check'][$vars['unique_id']] = true;
            $vars['unique_id'] = token_unique::generate_token('ticket');
            
        }
        //        echo '<pre>';
        //        print_r($vars['default_currency']);
        $vars['pageName'] = $vars['ticketing_id'] == 0 ? 'add_event' : 'edit_event';
        $vars['title'] = TicketingModel::getmsg($vars['ticketing_id'] == 0 ? 'add_event' : 'event');
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('event_list'), 'event_list'], [$vars['title'], 'add_event'.($vars['ticketing_id'] != 0  ? "/{$vars['ticketing_id']}" : "")]];
        $this->load->view('ticketing/add_event', $vars);
    }
    public function add_appointment() {
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['appointment_id'] = is_numeric($url[count($url) - 1]) ? $url[count($url) - 1] : 0;
        $vars['edit_arr'] = $vars['appointment_id']== 0 ? array() : $this->_registry->ticketing_class->get_appointment_data($vars['appointment_id']);
         if ($vars['appointment_id'] == 0) {
//            $vars['unique_id'] = 'inv' . uniqid();
//            smc_session()['duplicate_check'][$vars['unique_id']] = true;
            $vars['unique_id'] = token_unique::generate_token('ticket');
            
        }
             //       echo '<pre>';die( print_r($vars));
        //        print_r($vars['default_currency']);
        $vars['pageName'] = $vars['appointment_id'] == 0 ? 'add_appointment' : 'edit_appointment';
        $vars['title'] = TicketingModel::getmsg($vars['appointment_id'] == 0 ? 'add_appointment' : 'appointment');
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('appointment_list'), 'appointment_list'], [$vars['title'], 'add_appointment'.($vars['appointment_id'] != 0  ? "/{$vars['appointment_id']}" : "")]];
        $this->load->view('ticketing/add_appointment', $vars);
    }

    public function View_maintenance() {
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['ticketing_id'] = is_numeric($url[count($url) - 1]) ? $url[count($url) - 1] : 0;
        $vars['edit_arr'] = $vars['ticketing_id']== 0 ? array() : $this->_registry->ticketing_class->get_maintenance_data($vars['ticketing_id']);
        $vars['serial'] = $this->_registry->ticketing_class->get_maintenance_by_serial_number( $vars['edit_arr']['main']['serial_number']);
        $vars['customer'] =Customer::getCustomerByID($vars['edit_arr']['customer_id']);
        $vars['pageName'] = 'view_maintenance';
        $vars['title'] = 'View Maintenance';
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('maintenance_list'), 'maintenance_list'], [$vars['title'], 'View Maintenance'.($vars['ticketing_id'] != 0  ? "/{$vars['ticketing_id']}" : "")]];
        $this->load->view('ticketing/view_maintenance', $vars);
    }
    public function ticketing_calendar() {
        $vars['pageName'] = 'ticketing_calendar';
        $vars['title'] = TicketingModel::getmsg('ticketing_calendar');
        $vars['breadCrumb'] = [[TicketingModel::getmsg('ticketing'), 'Ticketing'], [TicketingModel::getmsg('ticketing_calendar'), 'ticketing_calendar']];
        $this->load->view('ticketing/ticketing_calendar', $vars);
    }
    public function addpurchase() {
        //bakhour
        // $data = $this->_registry->station->MergeCustomerCoupon();
        $vars['system_name'] = inventoryModel::getmsg('purchase_sys');
        preg_match("/\/sales\b/i", $_SERVER['REQUEST_URI'], $match_sales);
        preg_match("/\/order\b/i", $_SERVER['REQUEST_URI'], $match_order);
        $url = explode('/', $_SERVER['REQUEST_URI']);
                // echo"<pre>";die(print_r($url[count($url) - 1]));
        $vars['IsSales'] = count($match_sales) > 0 ? true : false;
        $vars['IsOrder'] = count($match_order) > 0 ? true : false;
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        preg_match("/\/delivery\b/i", $_SERVER['REQUEST_URI'], $match_del);
        $vars['is_delivery'] = count($match_del) > 0 ? true : false;
        preg_match("/\/note\b/i", $_SERVER['REQUEST_URI'], $match_del);
        $vars['is_note'] = count($match_del) > 0 ? true : false;
        preg_match("/\/copy\b/i", $_SERVER['REQUEST_URI'], $match_del);
        $vars['is_copy'] = count($match_del) > 0 ? true : false;
        preg_match("/\/return\b/i", $_SERVER['REQUEST_URI'], $match_del);
        $vars['is_return'] = count($match_del) > 0 ? true : false;
        preg_match("/\/noqty\b/i", $_SERVER['REQUEST_URI'], $match_del);
        $vars['is_noqty'] = !$vars['IsSales'] && count($match_del) > 0 ? true : false;


        preg_match("/\/collector\b/i", $_SERVER['REQUEST_URI'], $match_c);
        $vars['is_data_collector'] = count($match_c) > 0 ? true : false;
        $vars['IsEdit'] = (empty($_GET['is_pop']) ? is_numeric($url[count($url) - 2]) : is_numeric(explode("?", $url[count($url) - 2])[0])) && !$vars['is_data_collector'] && !$vars['IsOrder'] && !$vars['is_delivery'] && !$vars['is_copy'] && !$vars['is_return'] && !$vars['is_note'] ? true : false;

        if (!$vars['IsEdit']) {
            $vars['unique_id'] = token_unique::generate_token('inv');
//            $vars['unique_id'] = 'inv' . uniqid();
//            smc_session()['duplicate_check'][$vars['unique_id']] = true;
        }

        //        echo $vars['IsEdit'] ? 'herree' : 'theree';die();
        if ($vars['is_actual'])
            $vars['pageName'] = $vars['IsSales'] ? ($vars['IsEdit'] ? 'editInvoiceActual' : 'ActualInvoice') : ($vars['IsEdit'] ? ($vars['is_noqty'] ? 'editPurchaseActual_noqty' : 'editPurchaseActual') : ($vars['is_noqty'] ? 'add_act_purchase_no_qty' : 'ActualPurchase'));
        else
            $vars['pageName'] = $vars['IsSales'] ? ($vars['IsEdit'] ? 'editInvoice' : 'newSalesInvoice') : ($vars['IsEdit'] ? ($vars['is_noqty'] ? 'editPurchase_noqty' : 'editPurchase') : ($vars['is_noqty'] ? 'add_purchase_no_qty' : 'addpurchase'));

        if (empty($_GET['is_pop'])) {
            $vars['id'] = $vars['IsEdit'] || $vars['is_copy'] || $vars['is_return'] ? $url[count($url) - 2] : 0;
        } else {
            $vars['id'] = $vars['IsEdit'] ? explode("?", $url[count($url) - 2]) : 0;
            //            echo $vars['id'].'==';
        }

        $vars['file_id'] = $vars['is_data_collector'] ? $url[count($url) - 1] : 0;
        $vars['order_id'] = $vars['IsOrder'] ? $url[count($url) - 1] : 0;
        $vars['delivery_order_id'] = $vars['is_delivery'] ? $url[count($url) - 1] : 0;
        $vars['delivery_id'] = $vars['is_note'] ? $url[count($url) - 1] : 0;

        $vars['maintenance_id'] =substr( $url[count($url) - 1] ,1) ;
        if(!is_numeric($vars['maintenance_id']) || !$vars['IsSales']){
            $vars['maintenance_id'] = null;
        }
        $vars['maintenance_data'] =  $this->_registry->ticketing_class->get_maintenance_data($vars['maintenance_id']);
        if(empty($vars['maintenance_data']['main']))
            $vars['maintenance_id'] = null;



        
        //                echo $vars['delivery_id'];
        //                die();
        $invoice_class = new Invoice();
        $WarehouseDepot_class = new WarehouseDepot();
        $Currency_class = new Currency();
        $Organization_class = new Organization();
        $Product_class = new Product();
        
        $vars['collector_data'] = $vars['is_data_collector'] ? $invoice_class->invoiceFileData($vars['file_id']) : array();
        $vars['edit_arr'] = ($vars['IsEdit'] || $vars['is_copy']) ? ($vars['IsSales'] ? $invoice_class->getInvoiceByID($vars['id']) : $this->_registry->purchase->getPurchaseByID($vars['id'])) : ($vars['IsOrder'] ? $this->_registry->purchase->getPurchaseOrderByID($vars['order_id']) : '');
        $vars['edit_arr'] = $vars['is_delivery'] ? $this->_registry->delivery->get_order_delivered_data($vars['delivery_order_id']) : $vars['edit_arr'];
        $vars['edit_arr'] = $vars['is_note'] ? $this->_registry->delivery->get_delivery_to_invoice($vars['delivery_id']) : $vars['edit_arr'];
        $vars['edit_arr'] = $vars['is_return'] ? $this->_registry->return->get_return_to_invoice($vars['id']) : $vars['edit_arr'];
        $vars['check_lock'] = $vars['IsEdit'] ? CommonFunctions::check_lock_data(['type' => 'invoice', 'start_date' => $vars['edit_arr']['Main']['Date'], 'is_actual' => ($vars['is_actual'] ? 1 : 0)]) : '';
//        echo $vars['check_lock'].'===';die();
// echo"<pre>";die(print_r( $vars));

//                                                                       echo"<pre>";die(print_r($vars['edit_arr']));
        $vars['is_main_transfer'] = $vars['IsEdit'] ? (($vars['IsSales'] && !empty($vars['edit_arr']['Main']['is_main_transfer'])) ? $vars['edit_arr']['Main']['is_main_transfer'] : 0) : 0;
        //below we add condition for invoice app id if filled to check that sync. activated and server since in branch or where no sync. maybe it is filled from app. distribution
        $vars['is_branch_transfer'] = $vars['IsEdit'] ? (($vars['IsSales'] && (!empty($vars['edit_arr']['Main']['is_branch_transfer']) || (!empty($vars['edit_arr']['Main']['invoice_app_id'] && smc_session()['default_setting']['sync_type'] == 1)))) ? 1 : 0) : 0;
        $vars['related_payments'] = $vars['IsEdit'] ? $invoice_class->checkInvoicesPayments($vars['id'], ($vars['IsSales'] ? 1 : 0)) : array();


        $vars['pending_invoices'] = $invoice_class->getPendingInvoices();
        $vars['all_depots'] = $WarehouseDepot_class->getDepots();
        $vars['today'] = Date::getToday();
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['currency_list'] = $Currency_class->getAllCurrencies();

        $vars['DefaultCurrencyID'] = $vars['IsSales'] ? smc_session()['pricing_class_currency'] : $Currency_class->getDefaultCurrency();
        $currency_data = $Currency_class->getCurrencyByID($vars['DefaultCurrencyID']);
        //        $vars['DefaultCurrencyID'] = smc_session()['local_currency'];
        $vars['currency_round'] = (($vars['IsEdit'] || $vars['IsOrder'] || $vars['is_copy']) && isset($vars['edit_arr']['Main']['currency_round'])) ? $vars['edit_arr']['Main']['currency_round'] : $currency_data[2];

        $vars['org_details'] =  $Organization_class->getOrganizationDetails();
        $vars['org_address'] =  $Organization_class->getOrganizationPhysicalAddress();
        $vars['Extable'] = $Currency_class->getExchangeRateTable();
        $vars['all_uom'] = $Product_class->getUOM();
        $vars['templates'] = CommonFunctions::CommonView('tbl_print_template', ['template_key'], ['invoice']);
        $vars['current_invoice_type'] = NULL;
        $vars['invoice_type_details'] = array();
        //        if ($vars['IsSales']) {
        preg_match("/\/type\s*(\d+)\b/i", $_SERVER['REQUEST_URI'], $match_invoice_type);
        if (($vars['IsEdit'] || $vars['is_copy'])) {
            $vars['current_invoice_type'] = empty($vars['edit_arr']['Main']['invoice_type_id']) ? NULL : $vars['edit_arr']['Main']['invoice_type_id'];
        } else {
            $vars['current_invoice_type'] = empty($match_invoice_type) ? NULL : $match_invoice_type[1];
        }
        if (!empty($_GET['invoice_type']))
            $vars['current_invoice_type'] = $_GET['invoice_type'];
        if (!empty($vars['current_invoice_type']))
            $vars['invoice_type_details'] = CommonFunctions::CommonView('invoice_type_list', ['invoice_type_id'], [$vars['current_invoice_type']])[0];
        //        }
        //                echo "<pre>";die(print_r($vars['invoice_type_details']));
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? ($vars['IsSales'] ? (empty($vars['current_invoice_type']) ? 'act_sales_invoice' : $vars['invoice_type_details']['invoice_type_name_actual']) : 'act_purchase_invoice') : ($vars['IsSales'] ? (empty($vars['current_invoice_type']) ? 'sales_invoice' : $vars['invoice_type_details']['invoice_type_name']) : 'purchase_invoice'));

        //        $this->_registry->Product->build_products_with_prices(['is_sales'=>1]);
        //        die();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('ticketing'), 'Ticketing']];
        if (!$vars['is_copy'] && !$vars['is_return'] && !$vars['IsOrder']) {
            $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? ($vars['IsSales'] ? ($vars['IsEdit'] ? 'edit_act_sales_invoice' : (empty($vars['current_invoice_type']) ? 'act_sales_invoice' : $vars['invoice_type_details']['invoice_type_name_actual'])) : ($vars['IsEdit'] ? ($vars['is_noqty'] ? 'edit_act_pur_no_qty' : 'edit_act_purchase_invoice') : ($vars['is_noqty'] ? 'act_pur_no_qty' : 'act_purchase_invoice'))) : ($vars['IsSales'] ? ($vars['IsEdit'] ? 'edit_sales_invoice' : (empty($vars['current_invoice_type']) ? 'sales_invoice' : $vars['invoice_type_details']['invoice_type_name'])) : ( $vars['IsEdit'] ? ($vars['is_noqty'] ? 'edit_pur_no_qty' : 'edit_purchase_invoice') : ($vars['is_noqty'] ? 'purchase_no_qty' : 'purchase_invoice'))));
            $vars['breadCrumb'][] = [$vars['title'],
                'addpurchase' . ($vars['IsSales'] ? ($vars['is_data_collector'] ? "/sales/collector/{$vars['file_id']}" : ($vars['IsOrder'] ? "/order/sales" . ($vars['is_actual'] ? '/act' : '') . "/{$vars['order_id']}" : '/sales')) : '') . (($vars['is_actual'] && !$vars['IsOrder']) ? '/act' : '') . (!empty($vars['current_invoice_type']) ? (($vars['IsEdit'] || $vars['is_copy'] || $vars['is_return']) ? '' : ('/type' . $vars['current_invoice_type'])) : '') . (($vars['IsEdit'] || $vars['is_copy'] || $vars['is_return']) ? "/{$vars['id']}" : '')];
        }
        if ($vars['IsEdit'] || $vars['is_copy'] || $vars['is_return']) {
            $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? ($vars['IsSales'] ? (empty($vars['current_invoice_type']) ? 'new_act_sales_invoice' : $vars['invoice_type_details']['invoice_type_name_actual']) : ($vars['is_noqty'] ? 'act_pur_no_qty' : 'new_act_purchase_invoice')) : ($vars['IsSales'] ? (empty($vars['current_invoice_type']) ? 'new_sales_invoice' : $vars['invoice_type_details']['invoice_type_name']) : ($vars['is_noqty'] ? 'purchase_no_qty' : 'new_purchase_invoice')));
            $vars['breadCrumb'][] = [$vars['title'],
                'addpurchase' . ($vars['IsSales'] ? ($vars['is_data_collector'] ? "/sales/collector/{$vars['file_id']}" : ($vars['IsOrder'] ? "/order/sales" . ($vars['is_actual'] ? '/act' : '') . "/{$vars['order_id']}" : '/sales') . (empty($vars['current_invoice_type']) ? '' : ('/type' . $vars['current_invoice_type']))) : '') . (($vars['is_actual'] && !$vars['IsOrder']) ? '/act' : '')];
        }
        $vars['cash_customer_arr'] = Customer::get_cash_customer_acc();

        //        $salesman_id = (($vars['IsEdit'] || $vars['IsOrder'] || $vars['is_delivery'] || $vars['is_copy'] || $vars['is_return']) && !empty($vars['edit_arr']['Main']['Sales_ID'])) ? $vars['edit_arr']['Main']['Sales_ID'] : (!empty($vars['edit_arr']['Person']['selected_emp']) && !empty($vars['edit_arr']['Person']['emp_id']) ? $vars['edit_arr']['Person']['emp_id'] : '');
        //        $vars['salesman_depot'] = $this->_registry->salesman->get_salesman_depot($salesman_id);
        $this->load->view('ticketing/addpurchase', $vars);
    }


}
