<?php

class Inventory extends mainController {

    public function __construct() {
        parent::__construct();
        $this->year_id = Session::getCurrentYearID();
        $this->load->model('inventory');
        $this->controller_permission = Session::getPermissionsObject();

    }

    public function landing() {
        self::Inventory();
    }

    public function Inventory() {
        $cond ='';
        $cond2 ='';
        $user_id =smc_session()['user_details']['User_ID'];
        if (smc_session()['user_details']['limit_customer_invoice'] == 1) {
            $cond = ' and Logged_ID = '.$user_id.'';
        }

        if($this->controller_permission->hasPermission('Branches')){
            $cond .=  '';

        }else{
            $cond .= ' and branch_id ="' . (smc_session()['user_accounts']['branch_id']) . '"'  ;
            $cond2 .=' and branch_id ="' . (smc_session()['user_accounts']['branch_id']) . '"'  ;

        }
        
        $vars['pageName'] = 'Inventory';
        $vars['title'] = inventoryModel::getmsg('inventory');
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        $vars['count_customer'] = $this->_registry->customer->get_customer_count(); //$this->_registry->Count->countRows('tbl_customers');
        $vars['count_rows_inv'] = $this->_registry->Count->countRows('tbl_invoices', 'where is_actual = 0 and current_year_id = "' . $this->year_id . '" '.$cond.' ');
        $vars['count_rows_pur_order'] = $this->_registry->Count->countRows('tbl_purchase_order', 'where is_actual = 0 and is_sales= 0 and is_quotation= 0 and is_converted= 0  and  current_year_id = "' . $this->year_id . '" '.$cond2.' ');
        $vars['count_rows_sales_quo'] = $this->_registry->Count->countRows('tbl_purchase_order', 'where is_actual = 0 and is_sales= 1 and is_quotation= 1 and is_converted= 0  and  current_year_id = "' . $this->year_id . '" '.$cond.' ');
        $vars['count_rows_pur_quo'] = $this->_registry->Count->countRows('tbl_purchase_order', 'where is_actual = 0 and is_sales= 0 and is_quotation= 1 and is_converted= 0  and  current_year_id = "' . $this->year_id . '" '.$cond2.' ');
        $vars['count_rows_pur_return'] = $this->_registry->Count->countRows('tbl_accounting_return_invoices', 'where Is_Actual = 0 and Is_Customer_Invoice= 0 and disable_qty=0 and  current_year_id = "' . $this->year_id . '"  '.$cond2.'');
        $vars['count_rows_sales_return'] = $this->_registry->Count->countRows('tbl_accounting_return_invoices', 'where Is_Actual = 0 and Is_Customer_Invoice= 1 and disable_qty = 0 and  current_year_id = "' . $this->year_id . '" '.$cond.'  ');
        $vars['count_rows_pur'] = $this->_registry->Count->countRows('tbl_inventory_purchases', 'where is_actual = 0 and disable_qty=0 and current_year_id = "' . $this->year_id . '" '.$cond2.' ');
        $vars['count_rows_pur_noqty'] = $this->_registry->Count->countRows('tbl_inventory_purchases', 'where is_actual = 0 and disable_qty=1 and current_year_id = "' . $this->year_id . '" '.$cond2.' ');
        
        $vars['count_rows_sales_pur'] = $this->_registry->Count->countRows('tbl_sales_purchase', ' where is_return = 0');// no bramch
        $vars['count_rows_sales_pur_return'] = $this->_registry->Count->countRows('tbl_sales_purchase', ' where is_return = 1');// no bramch
        
        $vars['count_rows_product'] = $this->_registry->Count->countRows('tbl_stock_products', 'where Status_ID = 1 '.$cond2.'  ');
        $vars['count_rows_sup'] = $this->_registry->Count->countRows('tbl_stock_suppliers', 'where 1 = 1 '.$cond2.'  ');
        
        $vars['pricing_classes'] = $this->_registry->Product->getPricesClasses();
        $vars['all_country'] = $this->_registry->countries->viewCountries();
        $vars['count_sales_order'] = $this->_registry->purchase->get_pending_order_count();
        

        $vars['count_rows_pur_order_act'] = $this->_registry->Count->countRows('tbl_purchase_order', 'where is_actual = 1 and is_sales= 0 and is_quotation= 0 and is_converted= 0  and  current_year_id = "' . $this->year_id . '"  '.$cond2.' ');
        $vars['count_sales_order_act'] = $this->_registry->Count->countRows('tbl_purchase_order', 'where is_actual = 1 and is_sales= 1 and is_quotation= 0 and is_converted= 0  and  current_year_id = "' . $this->year_id . '"  '.$cond2.'');
       
       
        $vars['count_rows_pur_return_act'] = $this->_registry->Count->countRows('tbl_accounting_return_invoices', 'where Is_Actual = 1 and Is_Customer_Invoice= 0 and  current_year_id = "' . $this->year_id . '" '.$cond2.' ');
        $vars['count_rows_sales_return_act'] = $this->_registry->Count->countRows('tbl_accounting_return_invoices', 'where Is_Actual = 1 and Is_Customer_Invoice= 1 and  current_year_id = "' . $this->year_id . '" '.$cond2.' ');


        $vars['count_rows_inv_act'] = $this->_registry->Count->countRows('tbl_invoices', 'where is_actual = 1 and current_year_id = "' . $this->year_id . '" '.$cond2.' ');
        $vars['count_rows_pur_act'] = $this->_registry->Count->countRows('tbl_inventory_purchases', 'where is_actual = 1 and disable_qty=0 and current_year_id = "' . $this->year_id . '" '.$cond2.' ');

        $vars['count_rows_pur_return_no_qty'] = $this->_registry->Count->countRows('tbl_accounting_return_invoices', 'where Is_Actual = 0 and Is_Customer_Invoice= 0 and disable_qty=1 and  current_year_id = "' . $this->year_id . '" '.$cond2.' ');
        $vars['count_rows_sales_return_no_qty'] = $this->_registry->Count->countRows('tbl_accounting_return_invoices', 'where Is_Actual = 0 and Is_Customer_Invoice= 1 and disable_qty=1 and  current_year_id = "' . $this->year_id . '" '.$cond2.' ');


        $vars['count_rows_delivery_note'] = $this->_registry->Count->countRows('tbl_inventory_delivery_report', 'where current_year_id = "' . smc_session()['current_year_id'] . '" '.$cond2.'');

        //        $this->_registry->Product->insert_table_floors();
        //        $data = $this->_registry->sales->salesConsilidateByUser(0,"2017-11-15","2017-11-15");
        //        $data = $this->_registry->sales->dailyActivityByUser(0,"2017-11-15","2017-11-15");
        //        $data = $this->_registry->sales->detailInvDistByCustomer(0,"2017-11-15","2017-11-15");
        //        $data = $this->_registry->sales->setData(array("customers"=>[0,1],"from_date"=>"2017-11-15","to_date"=>"2017-11-15"))->invoiceDistByCustomer();
        //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory']];
        //        $smart_diner_block = array();
        //        $invoice_main_block = array();
        //        $act_invoice_main_block = array();
        //        $invoice_types = $this->_registry->invoice->getInvoiceTypes();
        $record_types = $this->_registry->invoice->get_record_types();
        $invoice_types = !empty($record_types['inv']) ? $record_types['inv'] : array();
        $purchase_types = !empty($record_types['pur']) ? $record_types['pur'] : array();
        $purchase_noqty_types = !empty($record_types['pnq']) ? $record_types['pnq'] : array();
        $sales_order_types = !empty($record_types['oin']) ? $record_types['oin'] : array();
        //        echo"<pre>";die(print_r($sales_order_types));
        $purchase_order_types = !empty($record_types['pin']) ? $record_types['pin'] : array();
        $purchase_delivery_types = !empty($record_types['dls']) ? $record_types['dls'] : array();
        $sales_delivery_types = !empty($record_types['dlc']) ? $record_types['dlc'] : array();

        $inv_block = array(
            array('msg' => 'sales_invoice_list', 'prmsn' => 'salesInvoiceList', 'lnk' => SITE_LINK . 'Inventory/InvoiceList', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_inv'])
        );

        if (empty($invoice_types)) {
            array_unshift($inv_block, array('msg' => 'new_sales_invoice', 'prmsn' => 'newSalesInvoice', 'lnk' => SITE_LINK . 'Inventory/addpurchase/sales', 'icon' => 'fa fa-plus-circle'));
        } else {
            foreach ($invoice_types as $invoice_type) {
                array_unshift($inv_block, array('msg' => $invoice_type['invoice_type_name'], 'prmsn' => 'newSalesInvoice', 'lnk' => SITE_LINK . 'Inventory/addpurchase/sales/type' . $invoice_type['invoice_type_id'], 'icon' => 'fa fa-plus-circle'));
            }
        }
        $inv_del_block = array(
            array('msg' => 'invoice_delivery_note_list', 'prmsn' => 'DeliveryNoteList', 'lnk' => SITE_LINK . 'Inventory/InvoiceDeliveryNoteList', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_delivery_note'])
            , array('msg' => 'due_date_invoice_list', 'prmsn' => 'DueDateInvoiceList', 'lnk' => SITE_LINK . 'Inventory/DueDateInvoiceList', 'icon' => 'fa fa-list')
            , array('msg' => 'data_collector', 'prmsn' => 'data_collector_invoice', 'lnk' => SITE_LINK . 'Inventory/invoiceFiles', 'icon' => 'fa fa-list')
            , array('msg' => 'posponted_list', 'prmsn' => 'inventory_postponed_list', 'lnk' => SITE_LINK . 'Inventory/postponed_list', 'icon' => 'fa fa-list')
            , array('msg' => 'postponed_report', 'prmsn' => 'inventory_postponed_report', 'lnk' => SITE_LINK . 'Inventory/postponed_report', 'icon' => 'fa fa-list')
            , array('msg' => 'add_consumption', 'prmsn' => 'add_consumption', 'lnk' => SITE_LINK . 'Inventory/consumption', 'icon' => 'fa fa-list')
            , array('msg' => 'consumption_list', 'prmsn' => 'consumption_list', 'lnk' => SITE_LINK . 'Inventory/consumption_list', 'icon' => 'fa fa-list')
        );
        if (empty($sales_delivery_types)) {
            array_unshift($inv_del_block, array('msg' => 'invoice_delivery_note', 'prmsn' => 'DeliveryNote', 'lnk' => SITE_LINK . 'Inventory/DeliveryNote', 'icon' => 'fa fa-pencil'));
        } else {
            foreach ($sales_delivery_types as $invoice_type) {
                array_unshift($inv_del_block, array('msg' => $invoice_type['invoice_type_name'], 'prmsn' => 'DeliveryNote', 'lnk' => SITE_LINK . 'Inventory/DeliveryNote/type' . $invoice_type['invoice_type_id'], 'icon' => 'fa fa-plus-circle'));
            }
        }
        $invoice_main_block = array_merge($inv_block, $inv_del_block);


        $act_invoice_block = array(
            array('msg' => 'act_sales_invoice_list', 'prmsn' => 'ActualSalesList', 'lnk' => SITE_LINK . 'Inventory/InvoiceList/act', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_inv_act'])
        );

        if (empty($invoice_types)) {
            array_unshift($act_invoice_block, array('msg' => 'act_sales_invoice', 'prmsn' => 'ActualInvoice', 'lnk' => SITE_LINK . 'Inventory/addpurchase/sales/act', 'icon' => 'fa fa-plus'));
        } else {
            foreach ($invoice_types as $invoice_type) {
                array_unshift($act_invoice_block, array('msg' => $invoice_type['invoice_type_name_actual'], 'prmsn' => 'ActualInvoice', 'lnk' => SITE_LINK . 'Inventory/addpurchase/sales/act/type' . $invoice_type['invoice_type_id'], 'icon' => 'fa fa-plus-circle'));
            }
        }

        $act_purchase_block = array(
            array('msg' => 'act_purchase_invoice_list', 'prmsn' => 'ActualPurchaseList', 'lnk' => SITE_LINK . 'Inventory/InvoiceList/vendor/act', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_pur_act'])
            , array('msg' => 'actual_posponted_list', 'prmsn' => 'actual_inventory_postponed_list', 'lnk' => SITE_LINK . 'Inventory/postponed_list/act', 'icon' => 'fa fa-list')
            , array('msg' => 'actual_posponted_report', 'prmsn' => 'actual_inventory_postponed_report', 'lnk' => SITE_LINK . 'Inventory/postponed_report/act', 'icon' => 'fa fa-list')
        );

        if (empty($purchase_types)) {
            array_unshift($act_purchase_block, array('msg' => 'act_purchase_invoice', 'prmsn' => 'ActualPurchase', 'lnk' => SITE_LINK . 'Inventory/addpurchase/act', 'icon' => 'fa fa-plus'));
        } else {
            foreach ($purchase_types as $purchase_type) {
                array_unshift($act_purchase_block, array('msg' => $purchase_type['invoice_type_name_actual'], 'prmsn' => 'ActualPurchase', 'lnk' => SITE_LINK . 'Inventory/addpurchase/act/type' . $purchase_type['invoice_type_id'], 'icon' => 'fa fa-plus-circle'));
            }
        }
        $inv_pur_act_main_block = array_merge($act_invoice_block, $act_purchase_block);

        $pur_block = array(
            array('msg' => 'purchase_invoice_list', 'prmsn' => 'purchase_list', 'lnk' => SITE_LINK . 'Inventory/InvoiceList/vendor', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_pur'])
            , array('msg' => 'add_sales_purchase', 'prmsn' => 'add_sales_purchase', 'lnk' => SITE_LINK . 'Inventory/salesPurchase', 'icon' => 'fa fa-plus-circle')
            , array('msg' => 'sales_purchase_list', 'prmsn' => 'sales_purchase_list', 'lnk' => SITE_LINK . 'Inventory/sales_purchase_list', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_sales_pur'])
            , array('msg' => 'add_sales_purchase_return', 'prmsn' => 'add_sales_purchase_return', 'lnk' => SITE_LINK . 'Inventory/salesPurchase/return', 'icon' => 'fa fa-user-md')
            , array('msg' => 'sales_purchase_return_list', 'prmsn' => 'sales_purchase_return_list', 'lnk' => SITE_LINK . 'Inventory/sales_purchase_list/return', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_sales_pur_return'])
        );
        if (empty($purchase_types)) {
            array_unshift($pur_block, array('msg' => 'new_purchase_invoice', 'prmsn' => 'addpurchase', 'lnk' => SITE_LINK . 'Inventory/addpurchase', 'icon' => 'fa fa-user-md'));
        } else {
            foreach ($purchase_types as $pur_type) {
                array_unshift($pur_block, array('msg' => $pur_type['invoice_type_name'], 'prmsn' => 'addpurchase', 'lnk' => SITE_LINK . 'Inventory/addpurchase/type' . $pur_type['invoice_type_id'], 'icon' => 'fa fa-plus-circle'));
            }
        }
        $pur_del_block = array(
            array('msg' => 'purchase_delivery_note_list', 'prmsn' => 'DeliveryPurchaseNoteList', 'lnk' => SITE_LINK . 'Inventory/PurchaseDeliveryNoteList/vendor', 'icon' => 'fa fa-list')
            , array('msg' => 'due_date_purchase_list', 'prmsn' => 'DueDatePurchaseList', 'lnk' => SITE_LINK . 'Inventory/DueDateInvoiceList/vendor', 'icon' => 'fa fa-list')
        );
        if (empty($purchase_delivery_types)) {
            array_unshift($pur_del_block, array('msg' => 'purchase_delivery_note', 'prmsn' => 'DeliveryNote/vendor', 'lnk' => SITE_LINK . 'Inventory/DeliveryNote/vendor', 'icon' => 'fa fa-user-md'));
        } else {
            foreach ($purchase_delivery_types as $type) {
                array_unshift($pur_del_block, array('msg' => $type['invoice_type_name'], 'prmsn' => 'DeliveryNote/vendor', 'lnk' => SITE_LINK . 'Inventory/DeliveryNote/vendor/type' . $type['invoice_type_id'], 'icon' => 'fa fa-plus-circle'));
            }
        }
        $purchase_main_block = array_merge($pur_block, $pur_del_block);


        $purchase_noqty_off_block = array(
            array('msg' => 'purchase_no_qty_list', 'prmsn' => 'purchase_no_qty_list', 'lnk' => SITE_LINK . 'Inventory/InvoiceList/vendor/noqty', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_pur_noqty'])
        );
        if (empty($purchase_noqty_types)) {
            array_unshift($purchase_noqty_off_block, array('msg' => 'add_purchase_no_qty', 'prmsn' => 'add_purchase_no_qty', 'lnk' => SITE_LINK . 'Inventory/addpurchase/noqty', 'icon' => 'fa fa-plus-circle'));
        } else {
            foreach ($purchase_noqty_types as $pur_type) {
                array_unshift($purchase_noqty_off_block, array('msg' => $pur_type['invoice_type_name'], 'prmsn' => 'add_purchase_no_qty', 'lnk' => SITE_LINK . 'Inventory/addpurchase/noqty/type' . $pur_type['invoice_type_id'], 'icon' => 'fa fa-plus-circle'));
            }
        }
        $purchase_noqty_act_block = array(
            array('msg' => 'act_purchase_no_qty_list', 'prmsn' => 'act_purchase_no_qty_list', 'lnk' => SITE_LINK . 'Inventory/InvoiceList/vendor/noqty/act', 'icon' => 'fa fa-list')
        );
        if (empty($purchase_noqty_types)) {
            array_unshift($purchase_noqty_act_block, array('msg' => 'add_act_purchase_no_qty', 'prmsn' => 'add_act_purchase_no_qty', 'lnk' => SITE_LINK . 'Inventory/addpurchase/noqty/act', 'icon' => 'fa fa-plus-circle'));
        } else {
            foreach ($purchase_noqty_types as $pur_type) {
                array_unshift($purchase_noqty_act_block, array('msg' => $pur_type['invoice_type_name_actual'], 'prmsn' => 'add_act_purchase_no_qty', 'lnk' => SITE_LINK . 'Inventory/addpurchase/noqty/act/type' . $pur_type['invoice_type_id'], 'icon' => 'fa fa-plus-circle'));
            }
        }
        $purchase_noqty_main_block = array_merge($purchase_noqty_off_block, $purchase_noqty_act_block);

        //
        $sales_order_off = array(
            array('msg' => 'sales_order_list', 'prmsn' => 'SalesOrderList', 'lnk' => SITE_LINK . 'Inventory/quotationOrderList/order/sales', 'icon' => 'fa fa-list', 'badge' => $vars['count_sales_order']['official'])
            , array('msg' => 'order_postponed_list', 'prmsn' => 'order_postponed_list', 'lnk' => SITE_LINK . 'Inventory/postponed_list/order', 'icon' => 'fa fa-list')
            , array('msg' => 'order_postponed_report', 'prmsn' => 'order_postponed_report', 'lnk' => SITE_LINK . 'Inventory/postponed_report/order', 'icon' => 'fa fa-list')
        );

        if (empty($sales_order_types)) {
            array_unshift($sales_order_off, array('msg' => 'sales_orders', 'prmsn' => 'salesOrder', 'lnk' => SITE_LINK . 'Inventory/quotationOrder/order/sales', 'icon' => 'fa fa-plus')
            );
        } else {
            foreach ($sales_order_types as $type) {
                array_unshift($sales_order_off, array('msg' => $type['invoice_type_name'], 'prmsn' => 'salesOrder', 'lnk' => SITE_LINK . 'Inventory/quotationOrder/order/sales/type' . $type['invoice_type_id'], 'icon' => 'fa fa-plus-circle'));
            }
        }
        $purchase_order_off = array(
            array('msg' => 'purchase_order_list', 'prmsn' => 'purchaseOrderList', 'lnk' => SITE_LINK . 'Inventory/quotationOrderList/order', 'icon' => 'fa fa-list','badge' => $vars['count_rows_pur_order'])
        );

        if (empty($purchase_order_types)) {
            array_unshift($purchase_order_off, array('msg' => 'purchase_orders', 'prmsn' => 'purchaseOrder', 'lnk' => SITE_LINK . 'Inventory/quotationOrder/order', 'icon' => 'fa fa-plus'));
        } else {
            foreach ($purchase_order_types as $type) {
                array_unshift($purchase_order_off, array('msg' => $type['invoice_type_name'], 'prmsn' => 'purchaseOrder', 'lnk' => SITE_LINK . 'Inventory/quotationOrder/order/type' . $type['invoice_type_id'], 'icon' => 'fa fa-plus-circle'));
            }
        }
        $order_main_block = array_merge($sales_order_off, $purchase_order_off);

        $sales_order_act = array(
            array('msg' => 'actual_sales_order_list', 'prmsn' => 'actual_sales_order_list', 'lnk' => SITE_LINK . 'Inventory/quotationOrderList/order/sales/act', 'icon' => 'fa fa-list', 'badge' => $vars['count_sales_order']['actual'])
            , array('msg' => 'act_order_postponed_list', 'prmsn' => 'act_order_postponed_list', 'lnk' => SITE_LINK . 'Inventory/postponed_list/order/act', 'icon' => 'fa fa-list')
            , array('msg' => 'act_order_postponed_report', 'prmsn' => 'act_order_postponed_report', 'lnk' => SITE_LINK . 'Inventory/postponed_report/order/act', 'icon' => 'fa fa-list')
        );
        if (empty($sales_order_types)) {
            array_unshift($sales_order_act, array('msg' => 'actual_sales_order', 'prmsn' => 'actual_sales_order', 'lnk' => SITE_LINK . 'Inventory/quotationOrder/order/sales/act', 'icon' => 'fa fa-plus'));
        } else {
            foreach ($sales_order_types as $type) {
                array_unshift($sales_order_act, array('msg' => $type['invoice_type_name'], 'prmsn' => 'actual_sales_order', 'lnk' => SITE_LINK . 'Inventory/quotationOrder/order/sales/act/type' . $type['invoice_type_id'], 'icon' => 'fa fa-plus-circle'));
            }
        }
        $purchase_order_act = array(
            array('msg' => 'actual_purchase_order_list', 'prmsn' => 'actual_purchase_order_list', 'lnk' => SITE_LINK . 'Inventory/quotationOrderList/order/act', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_pur_order_act'])
        );
        if (empty($purchase_order_types)) {
            array_unshift($purchase_order_act, array('msg' => 'actual_purchase_order', 'prmsn' => 'actual_purchase_order', 'lnk' => SITE_LINK . 'Inventory/quotationOrder/order/act', 'icon' => 'fa fa-plus'));
        } else {
            foreach ($purchase_order_types as $type) {
                array_unshift($purchase_order_act, array('msg' => $type['invoice_type_name'], 'prmsn' => 'actual_purchase_order', 'lnk' => SITE_LINK . 'Inventory/quotationOrder/order/act/type' . $type['invoice_type_id'], 'icon' => 'fa fa-plus-circle'));
            }
        }
        $act_order_main_block = array_merge($sales_order_act, $purchase_order_act);

        $smart_diner_block = array();

        $product_block = array(
            array('msg' => 'product_list', 'prmsn' => 'listproduct', 'lnk' => SITE_LINK . 'Inventory/listproduct', 'icon' => 'fa fa-product-hunt', 'badge' => $vars['count_rows_product']),
            array('msg' => 'product_specification_options', 'prmsn' => 'product_specification_options', 'lnk' => SITE_LINK . 'Inventory/product_specification_options', 'icon' => 'fa fa-product-hunt'),
            array('msg' => 'import_recipe', 'prmsn' => 'import_recipe', 'mdl' => '#import_recipe_modal', 'icon' => 'fa fa-product-hunt'),
            array('msg' => 'product_recipe', 'prmsn' => 'product_recipe', 'lnk' => SITE_LINK . 'Inventory/product_recipe', 'icon' => 'fa fa-list'),
            array('msg' => 'template_stock', 'prmsn' => 'TemplateStock', 'lnk' => SITE_LINK . 'Inventory/TemplateStock', 'icon' => 'fa fa-text-height'),
            array('msg' => 'current_stock', 'prmsn' => 'currentStock', 'lnk' => SITE_LINK . 'Inventory/stock_value_report', 'icon' => 'fa fa-archive'),
            array('msg' => 'reorder_stock', 'prmsn' => 'reorderStock', 'lnk' => SITE_LINK . 'Inventory/reorderStock', 'icon' => 'fa fa-retweet'),
            array('msg' => 'add_multi_product', 'prmsn' => 'add_multi_product', 'icon' => 'fa fa-list', 'mdl' => '#add_multi_product_modal'),
            array('msg' => 'edit_multi_product', 'prmsn' => 'edit_multi_product', 'lnk' => SITE_LINK . 'Inventory/edit_multi_product', 'icon' => 'fa fa-list'),
            array('msg' => 'uom_conversion', 'prmsn' => 'uomConversion', 'lnk' => SITE_LINK . 'Inventory/uomConversion', 'icon' => 'fa fa-asterisk'),
            array('msg' => 'product_reservation_duration', 'prmsn' => 'product_reservation_duration', 'lnk' => SITE_LINK . 'Inventory/product_reservation_duration', 'icon' => 'fa fa-calendar'),
            array('msg' => 'customer_product_codes', 'prmsn' => 'customer_product_codes', 'lnk' => SITE_LINK . 'Inventory/customer_supplier_codes/cust', 'icon' => 'fa fa-calendar'),
            array('msg' => 'supplier_product_codes', 'prmsn' => 'supplier_product_codes', 'lnk' => SITE_LINK . 'Inventory/customer_supplier_codes', 'icon' => 'fa fa-calendar'),
            array('msg' => 'products_customers', 'prmsn' => 'products_customers', 'lnk' => SITE_LINK . 'Inventory/products_customers', 'icon' => 'fa fa-calendar'),
            array('msg' => 'lebanon_vat_amount', 'prmsn' => 'lebanon_vat_amount', 'mdl' => '#edit-lebanon-vate-modal', 'icon' => 'fa fa-asterisk'),

        );
        if (smc_session()['default_setting']['activate_skip'] == 1)
            $product_block[] = array('msg' => 'skip_keys', 'prmsn' => 'skipkeys', 'lnk' => SITE_LINK . 'Inventory/skipkeys', 'icon' => 'fa fa-asterisk');
        $product_block[] = array('msg' => 'print_barcodes', 'prmsn' => 'print_barcode', 'lnk' => SITE_LINK . 'Inventory/printBarCode', 'icon' => 'fa fa-print');

        $product_block = array_merge($product_block, array(
            array('msg' => 'product_sections', 'prmsn' => 'product_sections', 'lnk' => SITE_LINK . 'Inventory/product_sections', 'icon' => 'fa fa-asterisk'),
        ));
        if (smc_session()['default_setting']['activate_smart_diner'] == 1) {
            $smart_diner_block = array(
                array('msg' => 'floor_table_setting', 'prmsn' => 'floor_table_setting', 'lnk' => SITE_LINK . 'Inventory/floor_setting', 'icon' => 'fa fa-gear')
                , array('msg' => 'service', 'prmsn' => 'invoice_service', 'mdl' => '#edit-service-modal', 'icon' => 'fa fa-asterisk')
                , array('msg' => 'void_reason_list', 'prmsn' => 'void_reason', 'lnk' => SITE_LINK . 'Inventory/reason_list', 'icon' => 'fa fa-list')
                , array('msg' => 'void_report', 'prmsn' => 'void_report', 'lnk' => SITE_LINK . 'Inventory/void_report', 'icon' => 'fa fa-list'),
                array('msg' => 'kitchen_note', 'prmsn' => 'kitchen_note', 'lnk' => SITE_LINK . 'Inventory/kitchen_note_list', 'icon' => 'fa fa-list'),
                array('msg' => 'product_note', 'prmsn' => 'product_note', 'lnk' => SITE_LINK . 'Inventory/product_note_list', 'icon' => 'fa fa-list')
            );
            if (smc_session()['default_setting']['is_add_ons_active'] == 1) {
                $smart_diner_block[] = array('msg' => 'add_ons', 'prmsn' => 'add_ons', 'lnk' => SITE_LINK . 'Inventory/AddOns', 'icon' => 'fa fa-asterisk');
                $smart_diner_block[] = array('msg' => 'add_ons_details', 'prmsn' => 'add_ons_details', 'lnk' => SITE_LINK . 'Inventory/AddOnsDetailsList', 'icon' => 'fa fa-asterisk');
            }
        }
        $inventory_setting_block = array(
            array('msg' => 'general_setting', 'prmsn' => 'GeneralSetting', 'lnk' => SITE_LINK . 'Inventory/GeneralSetting', 'icon' => 'fa fa-asterisk'),
            array('msg' => 'end_of_shift', 'prmsn' => 'manager_end_of_shift', 'mdl' => '#end_of_shift_modal', 'icon' => 'fa fa-asterisk'),
            array('msg' => 'scale_list', 'prmsn' => 'scale', 'lnk' => SITE_LINK . 'Inventory/scaleList', 'icon' => 'fa fa-asterisk'),
            array('msg' => 'scale_keys', 'prmsn' => 'scaleKeys', 'lnk' => SITE_LINK . 'Inventory/scaleKeys', 'icon' => 'fa fa-asterisk'),
            array('msg' => 'Printers', 'prmsn' => 'printers', 'lnk' => SITE_LINK . 'Inventory/printers', 'icon' => 'fa fa-list'),
            array('msg' => 'family', 'prmsn' => 'family', 'lnk' => SITE_LINK . 'Inventory/family', 'icon' => 'fa fa-list'),
            array('msg' => 'pos_categories', 'prmsn' => 'viewCategories', 'lnk' => SITE_LINK . 'Inventory/POSCat', 'icon' => 'fa fa-list'),
            array('msg' => 'viewBrand', 'prmsn' => 'view_brand', 'lnk' => SITE_LINK . 'Inventory/viewBrand', 'icon' => 'fa fa-list'),
            array('msg' => 'view_delivery_fees', 'prmsn' => 'view_delivery_fees', 'lnk' => SITE_LINK . 'Inventory/viewDeliveryFees', 'icon' => 'fa fa-list'),
            array('msg' => 'salesman_depot_list', 'prmsn' => 'salesman_depot_list', 'lnk' => SITE_LINK . 'Inventory/salesman_depot_list', 'icon' => 'fa fa-list'),
            array('msg' => 'add_discount_report_settings', 'prmsn' => 'add_discount_report_settings', 'lnk' => SITE_LINK . 'Inventory/add_discount_report_settings', 'icon' => 'fa fa-list'),
            array('msg' => 'pur_cat', 'prmsn' => 'purchase_cat_list', 'lnk' => SITE_LINK . 'Inventory/purchase_cat_list', 'icon' => 'fa fa-list'),
            array('msg' => 'invoice_types', 'prmsn' => 'invoice_types', 'lnk' => SITE_LINK . 'Inventory/invoice_types', 'icon' => 'fa fa-list'),
            array('msg' => 'driver_list', 'prmsn' => 'driver_list', 'lnk' => SITE_LINK . 'Inventory/driver_list', 'icon' => 'fa fa-list'),
            array('msg' => 'display', 'prmsn' => 'display', 'lnk' => SITE_LINK . 'Inventory/display', 'icon' => 'fa fa-list'),
            array('msg' => 'service', 'prmsn' => 'invoice_service', 'mdl' => '#edit-service-modal', 'icon' => 'fa fa-asterisk'),
            array('msg' => 'product_rate', 'prmsn' => 'product_rate', 'mdl' => '#edit-product-rate-modal', 'icon' => 'fa fa-asterisk'),
            array('msg' => 'rate_type_one', 'prmsn' => 'rate_type_one', 'mdl' => '#edit-product-rate-type-one-modal', 'icon' => 'fa fa-asterisk'),
            array('msg' => 'rate_type_two', 'prmsn' => 'rate_type_two', 'mdl' => '#edit-product-rate-type-two-modal', 'icon' => 'fa fa-asterisk'),
        );
        if (smc_session()['default_setting']['is_tag_active'] == 1)
            $inventory_setting_block[] = array('msg' => 'general_criteria', 'prmsn' => 'general_criteria', 'lnk' => SITE_LINK . 'Inventory/general_criteria', 'icon' => 'fa fa-asterisk');

        if (smc_session()['default_setting']['sync_type'] == 0) {
            $inventory_setting_block[] = array('msg' => 'reorder_invoices', 'prmsn' => 'reorder_invoices', 'lnk' => SITE_LINK . 'Inventory/reorder_invoice', 'icon' => 'fa fa-asterisk');
            $inventory_setting_block[] = array('msg' => 'reorder_actual_invoices', 'prmsn' => 'reorder_act_invoices', 'lnk' => SITE_LINK . 'Inventory/reorder_invoice/act', 'icon' => 'fa fa-asterisk');
        }
        $inventory_setting_block[] = array('msg' => 'sync_website', 'prmsn' => 'sync_website', 'lnk' => SITE_LINK . 'Inventory/sync_website', 'icon' => 'fa fa-asterisk');

        //
        $vars['menu_blocks'] = array(
            array('msg' => 'job_order', 'prmsn' => 'job_order', 'icon' => 'fa fa-gear'
                , 'detail' => array(
                    array('msg' => 'job_order_options', 'prmsn' => 'job_order_options', 'lnk' => SITE_LINK . 'Inventory/job_order_options', 'icon' => 'fa fa-list'),
                    array('msg' => 'job_order_stages', 'prmsn' => 'job_order_stages', 'lnk' => SITE_LINK . 'Inventory/job_order_stages', 'icon' => 'fa fa-list'),
                    array('msg' => 'job_order_blocks', 'prmsn' => 'job_order_blocks', 'lnk' => SITE_LINK . 'Inventory/job_order_blocks', 'icon' => 'fa fa-list'),
                    array('msg' => 'new_job_order', 'prmsn' => 'new_job_order', 'lnk' => SITE_LINK . 'Inventory/job_order', 'icon' => 'fa fa-plus'),
                    array('msg' => 'job_order_list', 'prmsn' => 'job_order_list', 'lnk' => SITE_LINK . 'Inventory/job_order_list', 'icon' => 'fa fa-list')
                )
            ), array('msg' => 'station_setting', 'prmsn' => 'station_setting', 'icon' => 'fa fa-gear'
                , 'detail' => array(
                    array('msg' => 'bone_type', 'prmsn' => 'bone_type', 'lnk' => SITE_LINK . 'Inventory/bone_type', 'icon' => 'fa fa-list'),
                    array('msg' => 'pump', 'prmsn' => 'station_pump', 'lnk' => SITE_LINK . 'Inventory/station_pump', 'icon' => 'fa fa-list'),
                    array('msg' => 'station_purchase', 'prmsn' => 'station_purchase', 'lnk' => SITE_LINK . 'Inventory/station_purchase', 'icon' => 'fa fa-plus'),
                    array('msg' => 'station_purchase_list', 'prmsn' => 'station_purchase_list', 'lnk' => SITE_LINK . 'Inventory/station_purchase_list', 'icon' => 'fa fa-list'),
                    array('msg' => 'station_invoice', 'prmsn' => 'station_invoice', 'lnk' => SITE_LINK . 'Inventory/station_invoice', 'icon' => 'fa fa-plus'),
                    array('msg' => 'station_invoice_list', 'prmsn' => 'station_invoice_list', 'lnk' => SITE_LINK . 'Inventory/station_invoice_list', 'icon' => 'fa fa-list'),
                    array('msg' => 'customer_coupons', 'prmsn' => 'customer_coupons', 'lnk' => SITE_LINK . 'Inventory/customer_coupons', 'icon' => 'fa fa-plus'),
                    array('msg' => 'customer_coupons_list', 'prmsn' => 'customer_coupons_list', 'lnk' => SITE_LINK . 'Inventory/customer_coupons_list', 'icon' => 'fa fa-list'),
                    array('msg' => 'coupon_type_balance', 'prmsn' => 'coupon_type_balance', 'lnk' => SITE_LINK . 'Inventory/coupon_type_balance', 'icon' => 'fa fa-list'),
                    array('msg' => 'customer_coupon_per_date', 'prmsn' => 'customer_coupon_per_date', 'lnk' => SITE_LINK . 'Inventory/customer_coupon_per_date', 'icon' => 'fa fa-list')
                )
            ),
            array('msg' => 'inventory_setting', 'prmsn' => 'inventory_setting', 'icon' => 'fa fa-gear'
                , 'detail' => $inventory_setting_block
            ),
            array('msg' => 'products', 'prmsn' => 'product_setting', 'icon' => 'fa fa-archive'
                , 'detail' => $product_block),
            array('msg' => 'pricing', 'prmsn' => 'pricing', 'icon' => 'fa fa-money'
                , 'detail' => array(
                    array('msg' => 'pricing_class', 'prmsn' => 'pricing_class', 'lnk' => SITE_LINK . 'Inventory/pricing_classes', 'icon' => 'fa fa-asterisk'),
                    array('msg' => 'pricing_list', 'prmsn' => 'PricingList', 'lnk' => SITE_LINK . 'Inventory/PricingList', 'icon' => 'fa fa-asterisk'),
                    array('msg' => 'supplier_pricing_class', 'prmsn' => 'supplier_pricing_class', 'lnk' => SITE_LINK . 'Inventory/pricing_classes/supp', 'icon' => 'fa fa-asterisk'),
                    array('msg' => 'supplier_pricing_list', 'prmsn' => 'SupplierPricingList', 'lnk' => SITE_LINK . 'Inventory/PricingList/supp', 'icon' => 'fa fa-asterisk'),
                    array('msg' => 'supplier_pricing_discounts', 'prmsn' => 'supplier_pricing_discounts', 'lnk' => SITE_LINK . 'Inventory/PricingList/supp/disc', 'icon' => 'fa fa-asterisk'),
                    array('msg' => 'customer_pricing_discounts', 'prmsn' => 'customer_pricing_discounts', 'lnk' => SITE_LINK . 'Inventory/PricingList/disc', 'icon' => 'fa fa-asterisk'),
                    array('msg' => 'supplier_pricing_discounts_amount', 'prmsn' => 'supplier_pricing_discounts_amount', 'lnk' => SITE_LINK . 'Inventory/PricingList/supp/amt', 'icon' => 'fa fa-asterisk'),
                    array('msg' => 'customer_pricing_discounts_amount', 'prmsn' => 'customer_pricing_discounts_amount', 'lnk' => SITE_LINK . 'Inventory/PricingList/amt', 'icon' => 'fa fa-asterisk'),
                )
            ),
            array('msg' => 'purchase_invoice', 'prmsn' => 'Purchase Invoice', 'icon' => 'fa fa-shopping-cart'
                , 'detail' => $purchase_main_block
            ),
            array('msg' => 'purchase_no_qty', 'prmsn' => 'purchase_no_qty', 'icon' => 'fa fa-shopping-cart'
                , 'detail' => $purchase_noqty_main_block
            ),
            array('msg' => 'sales_invoice', 'prmsn' => 'Sales Invoice', 'icon' => 'fa fa-file'
                , 'detail' => $invoice_main_block
            ),
            array('msg' => 'return', 'prmsn' => 'Return', 'icon' => 'fa fa-minus-circle'
                , 'detail' => array(
                    array('msg' => 'return_from_customer', 'prmsn' => 'ReturnCustomer', 'lnk' => SITE_LINK . 'Inventory/ReturnNoInvoice/sales', 'icon' => 'fa fa-arrow-right')
                    , array('msg' => 'return_customer_list', 'prmsn' => 'ReturnCustomerList', 'lnk' => SITE_LINK . 'Inventory/ReturnCustomerList', 'icon' => 'fa fa-eye', 'badge' => $vars['count_rows_sales_return'])
                    , array('msg' => 'return_to_vendor', 'prmsn' => 'ReturnVendor', 'lnk' => SITE_LINK . 'Inventory/ReturnNoInvoice', 'icon' => 'fa fa-arrow-left')
                    , array('msg' => 'return_vendor_list', 'prmsn' => 'ReturnVendorList', 'lnk' => SITE_LINK . 'Inventory/ReturnCustomerList/vendor', 'icon' => 'fa fa-eye', 'badge' => $vars['count_rows_pur_return'])
                )
            ),
            array('msg' => 'return_noqty', 'prmsn' => 'return_noqty', 'icon' => 'fa fa-minus-circle'
                , 'detail' => array(
                    array('msg' => 'return_customer_noqty', 'prmsn' => 'return_customer_noqty', 'lnk' => SITE_LINK . 'Inventory/ReturnNoInvoice/sales/noqty', 'icon' => 'fa fa-arrow-right')
                    , array('msg' => 'return_customer_noqty_list', 'prmsn' => 'return_customer_noqty_list', 'lnk' => SITE_LINK . 'Inventory/ReturnCustomerList/noqty', 'icon' => 'fa fa-eye', 'badge' => $vars['count_rows_sales_return_no_qty'])
                    , array('msg' => 'return_supplier_noqty', 'prmsn' => 'return_supplier_noqty', 'lnk' => SITE_LINK . 'Inventory/ReturnNoInvoice/noqty', 'icon' => 'fa fa-arrow-left')
                    , array('msg' => 'return_supplier_noqty_list', 'prmsn' => 'return_supplier_noqty_list', 'lnk' => SITE_LINK . 'Inventory/ReturnCustomerList/vendor/noqty', 'icon' => 'fa fa-eye', 'badge' => $vars['count_rows_pur_return_no_qty'])
                )
            ),
            array('msg' => 'exchange', 'prmsn' => 'exchange', 'icon' => 'fa fa-minus-circle'
                , 'detail' => array(
                    array('msg' => 'exchange', 'prmsn' => 'exchange', 'lnk' => SITE_LINK . 'Inventory/ReturnNoInvoice/sales/exchange', 'icon' => 'fa fa-plus')
                    , array('msg' => 'exchange_list', 'prmsn' => 'exchange_list', 'lnk' => SITE_LINK . 'Inventory/exchange_list', 'icon' => 'fa fa-list')
                )
            ),
            array('msg' => 'shipping_management', 'prmsn' => 'shipping_management', 'icon' => 'fa fa-minus-circle'
                , 'detail' => array(
                    array('msg' => 'shipping_companies', 'prmsn' => 'shipping_companies', 'lnk' => SITE_LINK . 'Inventory/shipping_companies', 'icon' => 'fa fa-list'),
                    array('msg' => 'shipping_list', 'prmsn' => 'shipping_list', 'lnk' => SITE_LINK . 'Inventory/shipping_list', 'icon' => 'fa fa-list'),
                )
            ),
            array('msg' => 'subscriptions', 'prmsn' => 'subscriptions', 'icon' => 'fa fa-minus-circle'
                , 'detail' => array(
                    array('msg' => 'subscription_block', 'prmsn' => 'subscription_block', 'lnk' => SITE_LINK . 'Inventory/subscription_block', 'icon' => 'fa fa-list'),
                    array('msg' => 'subscription_category', 'prmsn' => 'subscription_category', 'lnk' => SITE_LINK . 'Inventory/subscription_category', 'icon' => 'fa fa-list'),
                    array('msg' => 'subscription_setting', 'prmsn' => 'subscription_setting', 'lnk' => SITE_LINK . 'Inventory/subscription_setting', 'icon' => 'fa fa-list'),
                    array('msg' => 'edit_subscription_setting_prices', 'prmsn' => 'edit_subscription_setting_prices', 'lnk' => SITE_LINK . 'Inventory/edit_subscription_setting_prices', 'icon' => 'fa fa-pencil'),
                    array('msg' => 'customer_subscriptions', 'prmsn' => 'customer_subscriptions', 'lnk' => SITE_LINK . 'Inventory/customer_subscriptions', 'icon' => 'fa fa-list'),
                    array('msg' => 'customer_subscriptions_open_balance', 'prmsn' => 'customer_subscriptions_open_balance', 'lnk' => SITE_LINK . 'Inventory/customer_subscriptions_open_balance', 'icon' => 'fa fa-list'),
                    array('msg' => 'customer_subscriptions_close_balance', 'prmsn' => 'customer_subscriptions_close_balance', 'lnk' => SITE_LINK . 'Inventory/customer_subscriptions_close_balance', 'icon' => 'fa fa-list'),
                    array('msg' => 'subscription_fees', 'prmsn' => 'subscription_fees', 'lnk' => SITE_LINK . 'Inventory/subscription_fees', 'icon' => 'fa fa-money'),
                    array('msg' => 'subscription_fees_list', 'prmsn' => 'subscription_fees_list', 'lnk' => SITE_LINK . 'Inventory/subscription_fees_list', 'icon' => 'fa fa-money'),
                    array('msg' => 'category_fees_list', 'prmsn' => 'category_fees_list', 'lnk' => SITE_LINK . 'Inventory/category_fees_list', 'icon' => 'fa fa-money'),
                    array('msg' => 'subscription_block_report', 'prmsn' => 'subscription_block_report', 'lnk' => SITE_LINK . 'Inventory/subscription_block_report', 'icon' => 'fa fa-money'),
                )
            ),
            //            array('msg' => 'production_template', 'prmsn' => 'production', 'icon' => 'fa fa-users'
            //                , 'detail' => array(
            //                    array('msg' => 'production_template', 'prmsn' => 'production_template', 'lnk' => SITE_LINK . 'Inventory/production_template', 'icon' => 'fa fa-pencil')
            //                    , array('msg' => 'production_process', 'prmsn' => 'production_process', 'lnk' => SITE_LINK . 'Inventory/production_process', 'icon' => 'fa fa-pencil')
            //                    , array('msg' => 'production_process_touch', 'prmsn' => 'production_process', 'lnk' => SITE_LINK . 'Inventory/production_process_touch', 'icon' => 'fa fa-pencil')
            //                )
            //            ),
            array('msg' => 'customer_vendor', 'prmsn' => 'Customers', 'icon' => 'fa fa-user'
                , 'detail' => array(
                    array('msg' => 'customer', 'prmsn' => 'viewCustomer', 'lnk' => SITE_LINK . 'Inventory/CustomerList', 'icon' => 'fa fa-list', 'badge' => $vars['count_customer'])
                    , array('msg' => 'vendor', 'prmsn' => 'VendorList', 'lnk' => SITE_LINK . 'Inventory/ViewVendorList', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_sup'])
                    , array('msg' => 'customer_limit_balance', 'prmsn' => 'CustomerLimitBalance', 'lnk' => SITE_LINK . 'Inventory/CustomerLimitBalance', 'icon' => 'fa fa-list')
                    //                    , array('msg' => 'user_customer_list', 'prmsn' => 'UserCustomersList', 'lnk' => SITE_LINK . 'Inventory/UserCustomersList', 'icon' => 'fa fa-list')
                    , array('msg' => 'get_data_server', 'prmsn' => 'get_manual_data_from_server', 'lnk' => SITE_LINK . 'Inventory/get_data_server', 'icon' => 'fa fa-list')
                    , array('msg' => 'online_ledger', 'prmsn' => 'online_ledger', 'lnk' => SITE_LINK . 'Inventory/online_ledger', 'icon' => 'fa fa-list')
                    , array('msg' => 'online_road_customer_ledger', 'prmsn' => 'online_road_customer_ledger', 'lnk' => SITE_LINK . 'Inventory/online_road_customer_ledger', 'icon' => 'fa fa-list')
                    , array('msg' => 'view_customer_visits', 'prmsn' => 'view_customer_visits', 'lnk' => SITE_LINK . 'Inventory/view_customer_visits', 'icon' => 'fa fa-list')
                    , array('msg' => 'customer_supplier_contacts', 'prmsn' => 'customer_supplier_contacts', 'lnk' => SITE_LINK . 'Inventory/customer_supplier_contacts', 'icon' => 'fa fa-list')
                    , array('msg' => 'salesman_customers_list', 'prmsn' => 'salesman_customers_list', 'lnk' => SITE_LINK . 'Inventory/salesman_customers_list', 'icon' => 'fa fa-list'),
                    array('msg' => 'cust_group_list', 'prmsn' => 'cust_group', 'lnk' => SITE_LINK . 'Inventory/group_list/cust', 'icon' => 'fa fa-list'),
                    array('msg' => 'supp_group_list', 'prmsn' => 'supp_group', 'lnk' => SITE_LINK . 'Inventory/group_list/supp', 'icon' => 'fa fa-list'),
                    array('msg' => 'cust_class_list', 'prmsn' => 'cust_class', 'lnk' => SITE_LINK . 'Inventory/class_list/cust', 'icon' => 'fa fa-list'),
                    array('msg' => 'supp_class_list', 'prmsn' => 'supp_class', 'lnk' => SITE_LINK . 'Inventory/class_list/supp', 'icon' => 'fa fa-list'),
                    array('msg' => 'import_customers', 'prmsn' => 'import_customers', 'mdl' => '#import_cust_modal', 'icon' => 'fa fa-delicious'),
                    array('msg' => 'import_supplier', 'prmsn' => 'import_supplier', 'mdl' => '#import_supp_modal', 'icon' => 'fa fa-delicious'),
                    array('msg' => 'customers_certificate', 'prmsn' => 'customers_certificate', 'lnk' => SITE_LINK . 'Inventory/customers_certificate', 'icon' => 'fa fa-user-plus'),
                    array('msg' => 'customers_contra', 'prmsn' => 'customers_contra', 'lnk' => SITE_LINK . 'Inventory/customers_contra', 'icon' => 'fa fa-user-plus'),
                    array('msg' => 'collected_points_for_customer', 'prmsn' => 'collected_points_for_customer', 'lnk' => SITE_LINK . 'Inventory/collected_points_for_customer', 'icon' => 'fa fa-user-plus'),
                    array('msg' => 'description_for_points', 'prmsn' => 'description_for_points', 'lnk' => SITE_LINK . 'Inventory/description_for_points', 'icon' => 'fa fa-user-plus'),

                )
            ),
            array('msg' => 'report', 'prmsn' => 'ReportInventory', 'icon' => 'fa fa-line-chart'
                , 'detail' => array(
                    array('msg' => 'item_profit', 'prmsn' => 'ItemProfit', 'lnk' => SITE_LINK . 'Inventory/ItemProfit', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'movement_per_item', 'prmsn' => 'movement_per_item', 'lnk' => SITE_LINK . 'Inventory/movement_per_item', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'unmoved_items', 'prmsn' => 'UnmovedItems', 'lnk' => SITE_LINK . 'Inventory/UnmovedItems', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'invoice_per_time', 'prmsn' => 'invoice_report', 'lnk' => SITE_LINK . 'Inventory/InvoiceReportPerTime', 'icon' => 'fa fa-list')
                    , array('msg' => 'sold_per_brand', 'prmsn' => 'total_sold_items_by_brand', 'lnk' => SITE_LINK . 'Inventory/TotalItems/brand', 'icon' => 'fa fa-bar-chart'),
                    array('msg' => 'sold_per_category', 'prmsn' => 'total_sold_items_by_category', 'lnk' => SITE_LINK . 'Inventory/TotalItems', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'sold_per_date', 'prmsn' => 'total_sold_items', 'lnk' => SITE_LINK . 'Inventory/TotalItemsPerDate', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'total_sales_return_items', 'prmsn' => 'total_sales_return_items', 'lnk' => SITE_LINK . 'Inventory/TotalReturnItemsPerDate', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'detailed_sold_per_date', 'prmsn' => 'detailed_sold_items', 'lnk' => SITE_LINK . 'Inventory/DetailedInvoiceProductReport', 'icon' => 'fa fa-dollar'),
                    array('msg' => 'invoice_detailed_vehicle_driver', 'prmsn' => 'invoice_detailed_vehicle_driver', 'lnk' => SITE_LINK . 'Inventory/invoices_details_vehicle_driver', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'detailed_returned_items', 'prmsn' => 'detailed_returned_items', 'lnk' => SITE_LINK . 'Inventory/DetailedReturnedProductReport/1', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'user_invoices', 'prmsn' => 'user_invoices', 'lnk' => SITE_LINK . 'Inventory/UserInvoices', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'end_shift_report', 'prmsn' => 'end_of_shift_report', 'lnk' => SITE_LINK . 'Inventory/end_of_shift_report', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'end_of_day', 'prmsn' => 'manager_end_of_day', 'mdl' => '#confirm_end_of_day', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'cash_drawer_log', 'prmsn' => 'cash_drawer_log', 'lnk' => SITE_LINK . 'Inventory/cash_drawer_log', 'icon' => 'fa fa-list')
                    , array('msg' => 'detailed_purchase_items_report', 'prmsn' => 'detailed_purchase_items_report', 'lnk' => SITE_LINK . 'Inventory/DetailedPurchaseItemsReport', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'expiry_date_report', 'prmsn' => 'expiry_date_report', 'lnk' => SITE_LINK . 'Inventory/ExpiryDate/ex', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'product_lot_report', 'prmsn' => 'product_lot_report', 'lnk' => SITE_LINK . 'Inventory/ExpiryDate/lot', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'product_serial_report', 'prmsn' => 'product_serial_report', 'lnk' => SITE_LINK . 'Inventory/ExpiryDate/serial', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'total_sales_ordered_items', 'prmsn' => 'total_sales_ordered_items', 'lnk' => SITE_LINK . 'Inventory/total_ordered_items/sales', 'icon' => 'fa fa-list')
                    , array('msg' => 'total_purchase_ordered_items', 'prmsn' => 'total_purchase_ordered_items', 'lnk' => SITE_LINK . 'Inventory/total_ordered_items', 'icon' => 'fa fa-list')
                    , array('msg' => 'detailed_sales_order_per_date', 'prmsn' => 'detailed_sales_order_items', 'lnk' => SITE_LINK . 'Inventory/DetailedOrderProductReport/sales', 'icon' => 'fa fa-list')
                    , array('msg' => 'detailed_purchase_order_per_date', 'prmsn' => 'detailed_purchase_order_items', 'lnk' => SITE_LINK . 'Inventory/DetailedOrderProductReport', 'icon' => 'fa fa-list')
                    , array('msg' => 'invoice_discount_list', 'prmsn' => 'invoice_discount_list', 'lnk' => SITE_LINK . 'Inventory/invoice_discount_list', 'icon' => 'fa fa-list')
                    , array('msg' => 'return_damaged_items', 'prmsn' => 'return_damaged_items', 'lnk' => SITE_LINK . 'Inventory/return_damaged_items', 'icon' => 'fa fa-list')
                    , array('msg' => 'sales_per_category', 'prmsn' => 'sales_per_category', 'lnk' => SITE_LINK . 'Inventory/category_trial_balance/sales', 'icon' => 'fa fa-list')
                    , array('msg' => 'purchase_per_category', 'prmsn' => 'purchase_per_category', 'lnk' => SITE_LINK . 'Inventory/category_trial_balance', 'icon' => 'fa fa-list')
                    , array('msg' => 'sales_per_category_disc', 'prmsn' => 'sales_per_category_disc', 'lnk' => SITE_LINK . 'Inventory/category_trial_balance/sales/disc', 'icon' => 'fa fa-list')
                    , array('msg' => 'purchase_per_category_disc', 'prmsn' => 'purchase_per_category_disc', 'lnk' => SITE_LINK . 'Inventory/category_trial_balance/disc', 'icon' => 'fa fa-list')
                    , array('msg' => 'periodic_sales_mov', 'prmsn' => 'periodic_sales_mov', 'lnk' => SITE_LINK . 'Inventory/periodic_sales_purchase_mov/sales', 'icon' => 'fa fa-list')
                    , array('msg' => 'periodic_purchase_mov', 'prmsn' => 'periodic_purchase_mov', 'lnk' => SITE_LINK . 'Inventory/periodic_sales_purchase_mov', 'icon' => 'fa fa-list')
                    , array('msg' => 'item_movement', 'prmsn' => 'item_movement', 'lnk' => SITE_LINK . 'Inventory/item_movement', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'customer_daily_report', 'prmsn' => 'customer_daily_report', 'lnk' => SITE_LINK . 'Inventory/customer_daily_report', 'icon' => 'fa fa-user')
                    , array('msg' => 'customer_sold_items_report', 'prmsn' => 'customer_sold_items_report', 'lnk' => SITE_LINK . 'Inventory/customer_sold_items_report', 'icon' => 'fa fa-user')
                    , array('msg' => 'monthly_sales_report', 'prmsn' => 'monthly_sales_report', 'lnk' => SITE_LINK . 'Inventory/monthly_sales_report', 'icon' => 'fa fa-user')
                    , array('msg' => 'forecast_report', 'prmsn' => 'forecast_report', 'lnk' => SITE_LINK . 'Inventory/forecast_report', 'icon' => 'fa fa-list')
                    , array('msg' => 'daily_sales', 'prmsn' => 'daily_sales', 'lnk' => SITE_LINK . 'Inventory/daily_sales', 'icon' => 'fa fa-list')
                )
            ),
            array('msg' => 'actual_reports', 'prmsn' => 'actual_report_inventory', 'icon' => 'fa fa-line-chart'
                , 'detail' => array(
                    array('msg' => 'act_item_profit', 'prmsn' => 'actual_item_profit', 'lnk' => SITE_LINK . 'Inventory/ItemProfit/act', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'act_movement_per_item', 'prmsn' => 'actual_movement_per_item', 'lnk' => SITE_LINK . 'Inventory/movement_per_item/act', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'act_unmoved_items', 'prmsn' => 'ActualUnmovedItems', 'lnk' => SITE_LINK . 'Inventory/UnmovedItems/act', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'act_invoice_per_time', 'prmsn' => 'act_invoice_report', 'lnk' => SITE_LINK . 'Inventory/InvoiceReportPerTime/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_sold_per_brand', 'prmsn' => 'act_total_sold_items_by_brand', 'lnk' => SITE_LINK . 'Inventory/TotalItems/brand/act', 'icon' => 'fa fa-bar-chart'),
                    array('msg' => 'act_sold_per_category', 'prmsn' => 'act_total_sold_items_by_category', 'lnk' => SITE_LINK . 'Inventory/TotalItems/act', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'act_sold_per_date', 'prmsn' => 'act_total_sold_items', 'lnk' => SITE_LINK . 'Inventory/TotalItemsPerDate/act', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'act_total_sales_return_items', 'prmsn' => 'act_total_sales_return_items', 'lnk' => SITE_LINK . 'Inventory/TotalReturnItemsPerDate/act', 'icon' => 'fa fa-bar-chart'),
                    array('msg' => 'invoice_detailed_vehicle_driver_actual', 'prmsn' => 'invoice_detailed_vehicle_driver_actual', 'lnk' => SITE_LINK . 'Inventory/invoices_details_vehicle_driver/act', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'act_detailed_sold_per_date', 'prmsn' => 'act_detailed_sold_items', 'lnk' => SITE_LINK . 'Inventory/DetailedInvoiceProductReport/act', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'act_detailed_returned_items', 'prmsn' => 'act_detailed_returned_items', 'lnk' => SITE_LINK . 'Inventory/DetailedReturnedProductReport/act/1', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'act_user_invoices', 'prmsn' => 'act_user_invoices', 'lnk' => SITE_LINK . 'Inventory/UserInvoices/act', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'act_detailed_purchase_items_report', 'prmsn' => 'act_detailed_purchase_items_report', 'lnk' => SITE_LINK . 'Inventory/DetailedPurchaseItemsReport/act', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'act_total_sales_ordered_items', 'prmsn' => 'act_total_sales_ordered_items', 'lnk' => SITE_LINK . 'Inventory/total_ordered_items/sales/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_total_purchase_ordered_items', 'prmsn' => 'act_total_purchase_ordered_items', 'lnk' => SITE_LINK . 'Inventory/total_ordered_items/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_detailed_sales_order_per_date', 'prmsn' => 'act_detailed_sales_order_items', 'lnk' => SITE_LINK . 'Inventory/DetailedOrderProductReport/sales/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_detailed_purchase_order_per_date', 'prmsn' => 'act_detailed_purchase_order_items', 'lnk' => SITE_LINK . 'Inventory/DetailedOrderProductReport/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'actual_invoice_discount_list', 'prmsn' => 'actual_invoice_discount_list', 'lnk' => SITE_LINK . 'Inventory/invoice_discount_list/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_return_damaged_items', 'prmsn' => 'actual_return_damaged_items', 'lnk' => SITE_LINK . 'Inventory/return_damaged_items/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_sales_per_category', 'prmsn' => 'act_sales_per_category', 'lnk' => SITE_LINK . 'Inventory/category_trial_balance/sales/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_purchase_per_category', 'prmsn' => 'act_purchase_per_category', 'lnk' => SITE_LINK . 'Inventory/category_trial_balance/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_sales_per_category_disc', 'prmsn' => 'act_sales_per_category_disc', 'lnk' => SITE_LINK . 'Inventory/category_trial_balance/sales/act/disc', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_purchase_per_category_disc', 'prmsn' => 'act_purchase_per_category_disc', 'lnk' => SITE_LINK . 'Inventory/category_trial_balance/act/disc', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_periodic_sales_mov', 'prmsn' => 'act_periodic_sales_mov', 'lnk' => SITE_LINK . 'Inventory/periodic_sales_purchase_mov/sales/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_periodic_purchase_mov', 'prmsn' => 'act_periodic_purchase_mov', 'lnk' => SITE_LINK . 'Inventory/periodic_sales_purchase_mov/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_customer_daily_report', 'prmsn' => 'act_customer_daily_report', 'lnk' => SITE_LINK . 'Inventory/customer_daily_report/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_customer_sold_items_report', 'prmsn' => 'act_customer_sold_items_report', 'lnk' => SITE_LINK . 'Inventory/customer_sold_items_report/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_monthly_sales_report', 'prmsn' => 'act_monthly_sales_report', 'lnk' => SITE_LINK . 'Inventory/monthly_sales_report/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'actual_forecast_report', 'prmsn' => 'actual_forecast_report', 'lnk' => SITE_LINK . 'Inventory/forecast_report/act', 'icon' => 'fa fa-list')

                //                    array('msg' => 'expiry_date_report', 'prmsn' => 'expiry_date_report', 'lnk' => SITE_LINK . 'Inventory/ExpiryDate', 'icon' => 'fa fa-dollar')
                )
            ),
            array('msg' => 'sales_reports', 'prmsn' => 'salesReports', 'icon' => 'fa fa-line-chart'
                , 'detail' => array(
                    array('msg' => 'sales_consolidate', 'prmsn' => 'salesConsolidateByUser', 'lnk' => SITE_LINK . 'Inventory/salesConsolidateByUser', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'daily_activity_user', 'prmsn' => 'dailyActivityByUser', 'lnk' => SITE_LINK . 'Inventory/dailyActivityByUser', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'customer_inv_dist', 'prmsn' => 'invoiceDistByCustomer', 'lnk' => SITE_LINK . 'Inventory/invoiceDistByCustomer', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'movement_control', 'prmsn' => 'movement_control', 'lnk' => SITE_LINK . 'Inventory/movement_control', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'salesman_commission', 'prmsn' => 'inventory_sales_commission', 'lnk' => SITE_LINK . 'Inventory/sales_commission', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'monthly_sales_graph', 'prmsn' => 'monthly_sales_graph', 'lnk' => SITE_LINK . 'Inventory/monthly_sales_graph', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'monthly_year_sales_graph', 'prmsn' => 'monthly_year_sales_graph', 'lnk' => SITE_LINK . 'Inventory/monthly_year_sales_graph', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'monthly_year_sales_list', 'prmsn' => 'monthly_year_sales_list', 'lnk' => SITE_LINK . 'Inventory/monthly_year_sales_list', 'icon' => 'fa fa-list')
                    , array('msg' => 'monthly_year_products_sales_list', 'prmsn' => 'monthly_year_products_sales_list', 'lnk' => SITE_LINK . 'Inventory/monthly_year_products_sales_list', 'icon' => 'fa fa-list')
                )
            ),
            array('msg' => 'act_sales_reports', 'prmsn' => 'sales_reports_actual', 'icon' => 'fa fa-line-chart'
                , 'detail' => array(
                    array('msg' => 'act_sales_consolidate', 'prmsn' => 'sales_consolidate_by_user_actual', 'lnk' => SITE_LINK . 'Inventory/salesConsolidateByUser/act', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'act_daily_activity_user', 'prmsn' => 'daily_activity_by_user_actual', 'lnk' => SITE_LINK . 'Inventory/dailyActivityByUser/act', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'act_customer_inv_dist', 'prmsn' => 'invoice_dist_by_customer_actual', 'lnk' => SITE_LINK . 'Inventory/invoiceDistByCustomer/act', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'act_movement_control', 'prmsn' => 'movement_control_actual', 'lnk' => SITE_LINK . 'Inventory/movement_control/act', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'act_salesman_commission', 'prmsn' => 'inventory_sales_commission_actual', 'lnk' => SITE_LINK . 'Inventory/sales_commission/act', 'icon' => 'fa fa-dollar')
                    , array('msg' => 'act_monthly_year_sales_graph', 'prmsn' => 'monthly_year_sales_graph_actual', 'lnk' => SITE_LINK . 'Inventory/monthly_year_sales_graph/act', 'icon' => 'fa fa-bar-chart')
                    , array('msg' => 'act_monthly_year_sales_list', 'prmsn' => 'monthly_year_sales_list_actual', 'lnk' => SITE_LINK . 'Inventory/monthly_year_sales_list/act', 'icon' => 'fa fa-list')
                    , array('msg' => 'act_monthly_year_products_sales_list', 'prmsn' => 'monthly_year_products_sales_list_actual', 'lnk' => SITE_LINK . 'Inventory/monthly_year_products_sales_list/act', 'icon' => 'fa fa-list')
                )
            ),
            array('msg' => 'act_invoicing', 'prmsn' => 'ActualInvoicing', 'icon' => 'fa fa-users'
                , 'detail' => $inv_pur_act_main_block
            ),
            array('msg' => 'actual_return', 'prmsn' => 'actual_return', 'icon' => 'fa fa-minus-circle'
                , 'detail' => array(
                    array('msg' => 'actual_return_customer', 'prmsn' => 'actual_return_customer', 'lnk' => SITE_LINK . 'Inventory/ReturnNoInvoice/sales/act', 'icon' => 'fa fa-arrow-right')
                    , array('msg' => 'actual_return_customer_list', 'prmsn' => 'actual_return_customer_list', 'lnk' => SITE_LINK . 'Inventory/ReturnCustomerList/act', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_sales_return_act'])
                    , array('msg' => 'actual_return_vendor', 'prmsn' => 'actual_return_vendor', 'lnk' => SITE_LINK . 'Inventory/ReturnNoInvoice/act', 'icon' => 'fa fa-arrow-left')
                    , array('msg' => 'actual_return_vendor_list', 'prmsn' => 'actual_return_vendor_list', 'lnk' => SITE_LINK . 'Inventory/ReturnCustomerList/vendor/act', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_pur_return_act'])
                )
            ),
            array('msg' => 'quotation', 'prmsn' => 'quotation', 'icon' => 'fa fa-file'
                , 'detail' => array(
                    array('msg' => 'sales_quotation', 'prmsn' => 'sales_quotation', 'lnk' => SITE_LINK . 'Inventory/quotationOrder/quotation/sales', 'icon' => 'fa fa-plus')
                    , array('msg' => 'sales_quotation_list', 'prmsn' => 'sales_quotation_list', 'lnk' => SITE_LINK . 'Inventory/quotationOrderList/quotation/sales', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_sales_quo'])
                    , array('msg' => 'purchase_quotation', 'prmsn' => 'purchase_quotation', 'lnk' => SITE_LINK . 'Inventory/quotationOrder/quotation', 'icon' => 'fa fa-plus')
                    , array('msg' => 'purchase_quotation_list', 'prmsn' => 'purchase_quotation_list', 'lnk' => SITE_LINK . 'Inventory/quotationOrderList/quotation', 'icon' => 'fa fa-list', 'badge' => $vars['count_rows_pur_quo'])
                )
            ),
            array('msg' => 'orders', 'prmsn' => 'Order', 'icon' => 'fa fa-file'
                , 'detail' => $order_main_block
            ),
            array('msg' => 'actual_orders', 'prmsn' => 'actual_order', 'icon' => 'fa fa-file'
                , 'detail' => $act_order_main_block
            ),
            array('msg' => 'smart_diner', 'prmsn' => 'smart_diner', 'icon' => 'fa fa-file'
                , 'detail' => $smart_diner_block),
        );
        $vars['check_uom'] = $this->_registry->Product->check_if_default_uom();
        
        $vars['empty_collected_points'] = $this->_registry->Product->empty_collected_points();
        $this->load->view('Inventory', $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));
        $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;
        $vars['drivers_item_list'] = CommonBusiness::getDrivers();


        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) - 1]) : is_numeric(explode("?", $url[count($url) - 1])[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) - 1] : 0;
        } else {
            $vars['id'] = $vars['IsEdit'] || $vars['is_copy'] || $vars['is_return'] ? explode("?", $url[count($url) - 1])[0] : 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;

        //                echo $vars['delivery_id'];
        //                die();
        $vars['collector_data'] = $vars['is_data_collector'] ? $this->_registry->invoice->invoiceFileData($vars['file_id']) : array();
        //        $vars['collector_data'] = $this->_registry->invoice->getInvoiceByID(2);
        $vars['edit_arr'] = ($vars['IsEdit'] || $vars['is_copy']) ? ($vars['IsSales'] ? $this->_registry->invoice->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['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'] ? $this->_registry->invoice->checkInvoicesPayments($vars['id'], ($vars['IsSales'] ? 1 : 0)) : array();

        $vars['pending_invoices'] = $this->_registry->invoice->getPendingInvoices();
        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['today'] = Date::getToday();
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['currency_list'] = $this->_registry->Currency->getAllCurrencies();

        $vars['DefaultCurrencyID'] = smc_session()['local_currency'];
        //$vars['DefaultCurrencyID'] = $vars['IsSales'] ? smc_session()['pricing_class_currency'] : $this->_registry->Currency->getDefaultCurrency();
        $currency_data = $this->_registry->Currency->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'] = $this->_registry->organization->getOrganizationDetails();
        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();
        $vars['all_uom'] = $this->_registry->Product->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('inventory'), 'Inventory']];
        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' : 'edit_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('Inventory/addpurchase', $vars);
    }

    public function salesPurchase() {
        //        $vars['pageName'] = 'add_sales_purchase';

        $vars['system_name'] = inventoryModel::getmsg('sales_prurchase');
        preg_match("/\/return\b/i", $_SERVER['REQUEST_URI'], $match);
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['is_return'] = count($match) > 0 ? true : false;
        $vars['title'] = inventoryModel::getmsg($vars['is_return'] ? 'add_sales_purchase_return' : 'add_sales_purchase');
        $vars['IsEdit'] = is_numeric($url[count($url) - 1]) ? true : false;
        $vars['id'] = $vars['IsEdit'] ? $url[count($url) - 1] : 0;
        $vars['edit_arr'] = $vars['IsEdit'] ? (!$vars['is_return'] ? $this->_registry->salesPurchase->getSalesPurchaseByID($vars['id']) : $this->_registry->salesPurchase->getSalesPurchaseReturnByID($vars['id'])) : '';
//                             echo"<pre>";die(print_r($vars['edit_arr']));
        $vars['check_lock'] = $vars['IsEdit'] ? CommonFunctions::check_lock_data(['type' => 'invoice', 'start_date' => $vars['edit_arr']['Main']['Date'], 'is_actual' => 0]) : '';

        preg_match("/\/noqty\b/i", $_SERVER['REQUEST_URI'], $match_del);
        $vars['is_noqty'] = count($match_del) > 0 ? true : false;

        $vars['related_payments'] = $this->_registry->invoice->checkInvoicesPayments($vars['id'], 1);
        $vars['pending_invoices'] = $this->_registry->invoice->getPendingInvoices();
        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['today'] = Date::getToday();
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['DefaultCurrencyID'] = smc_session()['pricing_class_currency'];
        $currency_data = $this->_registry->Currency->getCurrencyByID($vars['DefaultCurrencyID']);

        $vars['currency_round'] = ($vars['IsEdit'] && !empty($vars['edit_arr']['Main']['currency_round'])) ? $vars['edit_arr']['Main']['currency_round'] : $currency_data[2];

        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();
        $vars['all_uom'] = $this->_registry->Product->getUOM();

        $vars['pageName'] = $vars['is_return'] ? ($vars['IsEdit'] ? 'edit_sales_purchase_return' : 'add_sales_purchase_return') : ($vars['IsEdit'] ? 'edit_sales_purchase' : 'add_sales_purchase');

        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_return'] ? 'sales_purchase_return_list' : 'sales_purchase_list'), 'sales_purchase_list' . ($vars['is_return'] ? '/return' : '')], [inventoryModel::getmsg($vars['is_return'] ? 'add_sales_purchase_return' : 'add_sales_purchase'), 'salesPurchase' . ($vars['is_return'] ? '/return' : '') . ($vars['IsEdit'] ? '/' . $vars['id'] : '')]];
        $this->load->view('Inventory/salesPurchase', $vars);
    }

    public function listproduct() {
        //                $delete = $this->_registry->common_scripts->correct_trans_types_current();
        //                echo"<pre>";die(print_r($delete));
        $vars['pageName'] = 'listproduct';
        $vars['title'] = inventoryModel::getmsg('product_list');
        $vars['system_name'] = inventoryModel::getmsg('product_sys');
        $vars['productlist'] = $this->_registry->Product->getProducts();
        $vars['all_categories'] = $this->_registry->Product->getCat();
        $vars['all_uom'] = $this->_registry->Product->getAllUOM();
        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
        $vars['orgname'] = $this->_registry->organization->getOrganizationDetails();
        $vars['printers'] = $this->_registry->Product->getAllPrinters();
        $vars['branches'] = CommonBusiness::getAllBranch();
        $vars['pricing_classes'] = $this->_registry->Product->getPricesClasses();
        $vars['max_code'] = $this->_registry->Product->getMaxProductCode();
        $vars['add_ons'] = CommonFunctions::CommonView('tbl_add_ons');
        $vars['check_uom'] = $this->_registry->Product->check_if_default_uom();
        $vars['is_new'] = !empty($_GET['is_new']) ? 1 : 0;
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('product_list'), 'listproduct']];
        $this->load->view('Inventory/listproduct', $vars);
    }

    public function ViewProduct() {
        $vars['pageName'] = 'ViewProduct';
        $vars['title'] = inventoryModel::getmsg('product_info');
        $vars['system_name'] = inventoryModel::getmsg('product_sys');
        //        preg_match('/\/(\d+)$/', $_SERVER['REQUEST_URI'], $match);
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['Product_ID'] = (int) $url[count($url) - 1];
        $vars['Product_Info'] = $this->_registry->Product->getProductInfo($vars['Product_ID']);
        $vars['class_price'] = $this->_registry->Product->getPricingClasses($vars['Product_ID']);
        $vars['uom_conversion'] = $this->_registry->Product->getUOMPricesByProduct($vars['Product_ID']);
        $vars['pricing_classes'] = $this->_registry->Product->getPricesClasses();
        $vars['all_uom'] = $this->_registry->Product->getAllUOM();
        $vars['ProductLocation'] = $this->_registry->depot->getProductLocationInfo(null, $vars['Product_ID']);
        //$vars['ProductInfo'] = $this->_registry->Product->getProductInfo($vars['Product_ID']);
        $data = ['Product_ID' => $vars['Product_ID']];
        $vars['product_criteria'] = $this->_registry->restaurantPos->setData($data)->getProductCriteria();
        //  echo"<pre>";
        //    die(print_r($vars['ProductInfo']));
        
        $vars['printers'] = $this->_registry->Product->getAllPrinters();
        $vars['branches'] = CommonBusiness::getAllBranch();
        
        $vars['products_links'] = $this->_registry->Product->getProductLinks($vars['Product_ID']);
        $vars['prod_options'] = $this->_registry->Product->get_prod_options($vars['Product_ID']);
        //echo"<pre>";
        //die(print_r($vars['products_links']));
        $vars['maintenance_arr'] = $this->_registry->Product->get_product_maintenance($vars['Product_ID']);
        $vars['all_categories'] = $this->_registry->Product->getCat();
        $vars['all_currencies'] = $this->_registry->Currency->getAllCurrencies();
        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
        $vars['currencyList'] = $this->_registry->Currency->GetLIListCurrency();
        $vars['add_ons'] = CommonFunctions::CommonView('tbl_add_ons');
        $vars['product_add_ons'] = CommonFunctions::CommonView('product_add_ons', ['product_id'], [$vars['Product_ID']]);
        if (file_exists(upload_path . 'products_photos/' . $vars['Product_ID'] . '.jpg'))
            $vars['filename1'] = upload_url . 'products_photos/' . $vars['Product_ID'] . '.jpg';
        else
            $vars['filename1'] = SITE_LINK . 'img/profiles/product.png';
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('product_list'), 'listproduct'], [inventoryModel::getmsg('product_info'), 'ViewProduct/' . $vars['Product_ID']]];
        $this->load->view('Inventory/ViewProduct', $vars);
    }

    public function InvoiceList() {
        //        echo"<pre>";die(print_r($_SERVER));
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        preg_match("/\/vendor\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['IsVendor'] = count($match) > 0 ? true : false;

        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        preg_match("/\/noqty\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_noqty'] = count($match_act) > 0 ? true : false;

        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? ($vars['IsVendor'] ? ($vars['is_noqty'] ? 'act_purchase_no_qty_list' : 'act_purchase_list') : 'act_invoice_list') : ($vars['IsVendor'] ? ($vars['is_noqty'] ? 'purchase_no_qty_list' : 'purchase_list') : 'invoice_list'));

        $vars['pageName'] = $vars['is_actual'] ? ($vars['IsVendor'] ? ($vars['is_noqty'] ? 'act_purchase_no_qty_list' : 'ActualPurchaseList') : 'ActualSalesList') : ($vars['IsVendor'] ? ($vars['is_noqty'] ? 'purchase_no_qty_list' : 'purchase_list') : 'salesInvoiceList');
        $records = $this->_registry->invoice->get_record_types();
        $vars['inv_pur_types'] = !$vars['IsVendor'] ? (!empty($records['inv']) ? $records['inv'] : array()) : (!empty($records['pur']) ? $records['pur'] : array());
        //       echo"<pre>";die(print_r($vars['inv_pur_types']));
        $vars['del_types'] = !$vars['IsVendor'] ? (!empty($records['dlc']) ? $records['dlc'] : array()) : (!empty($records['dls']) ? $records['dls'] : array());
        $vars['order_types'] = !$vars['IsVendor'] ? (!empty($records['ois']) ? $records['ois'] : array()) : (!empty($records['opr']) ? $records['opr'] : array());
        $vars['noqty_types'] = !$vars['IsVendor'] ? array() : (!empty($records['pnq']) ? $records['pnq'] : array());

        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'],
            [inventoryModel::getmsg($vars['IsVendor'] ? 'vendors' : 'customers'), ($vars['IsVendor'] ? 'ViewVendorList/vendor' : 'CustomerList')],
            [inventoryModel::getmsg($vars['IsVendor'] ? ($vars['is_actual'] ? 'act_purchase_list' : 'purchase_list') : ($vars['is_actual'] ? 'act_invoice_list' : 'invoice_list')), 'InvoiceList' . ($vars['IsVendor'] ? '/vendor' : '') . ( $vars['is_actual'] ? '/act' : '') . ( $vars['is_noqty'] ? '/noqty' : '')]];
        $this->load->view('Inventory/InvoiceList', $vars);
    }

    public function VendorList() {
        $vars['title'] = inventoryModel::getmsg('vendor_sys');
        $vars['system_name'] = inventoryModel::getmsg('vendor_sys');
        preg_match("/\/vendor\b/i", $_SERVER['REQUEST_URI'], $match);
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['IsVendor'] = count($match) > 0 ? true : false;
        $vars['ID'] = $url[count($url) - 1];
        $vars['pageName'] = $vars['IsVendor'] ? 'VendorList' : 'CustomerList';
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'],
            [inventoryModel::getmsg($vars['IsVendor'] ? 'vendors' : 'customers'), ($vars['IsVendor'] ? 'ViewVendorList' : 'CustomerList')],
            [inventoryModel::getmsg($vars['IsVendor'] ? 'purchase_list' : 'invoice_list'), 'VendorList' . ($vars['IsVendor'] ? '/vendor' : '') . "/{$vars['ID']}"]];
        $this->load->view('Inventory/VendorList', $vars);
    }

    public function CustomerList() {
        $vars['pageName'] = 'viewCustomer';
        $vars['title'] = inventoryModel::getmsg('inventory');
        $vars['system_name'] = inventoryModel::getmsg('customer_sys');
        $vars['default_currency'] = smc_session()['default_currency'];
        $vars['permissions'] = $this->controller_permission;
        $vars['is_new'] = isset($_GET['new']) ? 1 : 0;
        $vars['shipping_companies'] = $this->_registry->organization->getshippingCompanies();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('customers'), 'CustomerList']];
        // die(print_r($vars));
        $this->load->view('Inventory/CustomerList', $vars);
    }

    public function einv_generate_tlv_qr_code($array_tag=array()){
        $index=1;
        $tlv_string='';
        foreach($array_tag as $tag_val){
            $tlv_string.=pack("H*", sprintf("%02X",(string) "$index")).
                         pack("H*", sprintf("%02X",strlen((string) "$tag_val"))).
                         (string) "$tag_val";
            $index++;                              
        }      
        return base64_encode($tlv_string);
    }

    public function ViewInvoice() {
        $vars['title'] = inventoryModel::getmsg('inventory_sys');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        preg_match("/\/vendor\b/i", $_SERVER['REQUEST_URI'], $match);
        $getID = explode('/', $_SERVER['REQUEST_URI']);
        $url = explode('/', $_GET['url']);

        $vars['IsVendor'] = count($match) > 0 ? true : false;

        $Invoice_ID = $url[count($url) - 2];
        //        if($vars['IsVendor'])
        //            die('heree');
        //                die($Invoice_ID.'===');
        $data = !$vars['IsVendor'] ? $this->_registry->invoice->getInvoiceToPrint($Invoice_ID) : $this->_registry->purchase->getPurchaseToPrint($Invoice_ID);
        $hide_qr='';

        try {
            if (!$vars['IsVendor']) {
                $payment = $this->_registry->invoice->getInvoiceByID($Invoice_ID);
                 if(!empty($payment['Payment']))
                {
                    if(!empty($payment['Payment']['Credit_Card']))
                    foreach ($payment['Payment']['Credit_Card'] as $key => $value) {
                        $data['main']['Credit_Card_' . $key] = $value;
                    }
                    if(!empty($payment['Payment']['Cash']))
                    foreach ($payment['Payment']['Cash'] as $key => $value) {
                        $data['main']['Cash_' . $key] = $value;
                    }
                    if(!empty($payment['Payment']['others']))
                    foreach ($payment['Payment']['others'] as $key => $value) {
                        $data['main']['others_' . $key] = $value;
                    }
                    if(!empty($payment['Payment']['Cheque']))
                    foreach ($payment['Payment']['Cheque'] as $key => $value) {
                        $data['main']['Cheque_' . $key] = $value;
                    }
                }

            }
        } catch (Exception $e) {
            $x = 'Message: ' . $e->getMessage();
        }

        $paid='Un Paid';
        if($data['main']['Invoice_Paid_Amount'] > 0)
            $paid='Paid';
            $data['main']['paid']=$paid;
        $data['main']['print_date'] =date("Y-m-d h:i:sa");
        $data['main']['hide_qr']=$hide_qr;
       
        $template_id = !empty($_GET['template_id']) ? $_GET['template_id'] : '';
        // $template_id = 69;
        $getOrganizationDetails= $this->_registry->organization->getOrganizationDetails()[0];
        $data['main']= array_merge($data['main'],$getOrganizationDetails);
        
        if(strlen($data['main']['Organization_Commercial_Registry']) <= 0)
            $data['main']['hidden_org__Organization_Commercial_Registry'] = 'hidden';

        if(strlen($data['main']['Organization_vat_num']) <= 3)
            $data['main']['hidden_Organization_vat_num'] = 'hidden';

        if(strlen($data['main']['Organization_Phone']) <= 3)
            $data['main']['hidden_org__Organization_Phone'] = 'hidden';

 
 
        if(strlen($data['main']['organiaztion_name_en']) <= 3)
            $data['main']['hidden_organiaztion_name_en'] = 'hidden';
        
        
        if(strlen($data['main']['org_cr_en']) <= 3)
            $data['main']['hidden_org_cr_en'] = 'hidden';

        if(strlen($data['main']['org_vat_en']) <= 3)
            $data['main']['hidden_org_vat_en'] = 'hidden';

        if(strlen($data['main']['org_phone_en']) <= 3)
            $data['main']['hidden_org_phone_en'] = 'hidden';

        if(strlen($data['main']['organiaztion_name_en']) <= 0)
            $data['main']['hidden_organiaztion_name_en'] = 'hidden';

        if(smc_session()['default_setting']['enable_sales_invoice_qr_code'] == 1 && !$vars['IsVendor']){
            $data_tlv= $this->einv_generate_tlv_qr_code(array($data['main']['organiaztion_name_en'],$data['main']['org_vat_en'],str_replace(' ','T',$data['main']['date_created']),str_replace(',','',$data['main']['Invoice_Net_Total']),$data['main']['vat1_total']));
            $data['main']['qrcode'] = SITE_LINK . 'common_controller/GenerateQRCode?code=' . $data_tlv;
        }
        
        $data['main']['others_class'] = 'hidden';
        if($data['main']['others_Transaction_Amount'] > 0){
            $data['main']['others_class'] = '';
        }
        $data['main']['cash_class'] = 'hidden';
        if($data['main']['Cash_Transaction_Amount'] > 0){
            $data['main']['cash_class'] = '';
        }

        $data['main']['cheque_class'] = 'hidden';
        if($data['main']['Cheque_Transaction_Amount'] > 0){
            $data['main']['cheque_class'] = '';
        }
        $data['main']['credit_card_class'] = 'hidden';
        if($data['main']['Credit_Card_Transaction_Amount'] > 0){
            $data['main']['credit_card_class'] = '';
        }


        $total_payment_method = floatval($data['main']['others_Transaction_Amount'])+floatval($data['main']['Cash_Transaction_Amount'])+floatval($data['main']['Cheque_Transaction_Amount'])+floatval($data['main']['Credit_Card_Transaction_Amount']);
        $data['main']['invoice_pending_class'] =  'hidden';
        if($total_payment_method == 0 || $total_payment_method == '' ){
            $data['main']['invoice_pending_class'] = '';
        }



        $data['main']['lebanon_vat'] = $data['main']['Invoice_VAT'];
        $data['main']['hide_lebanon_vat'] = 'hidden';
        $data['main']['hide_usd_vat'] = 'hidden';
        if($data['main']['Currency_Code'] == 'USD' ){
            $data['main']['lebanon_vat'] = CommonFunctions::formatNumber( ((float)$data['main']['Invoice_VAT']) * smc_session()['default_setting']['lebanon_vat_amount']);
            $data['main']['hide_usd_vat'] = '';

        }else{
            $data['main']['hide_lebanon_vat'] = '';
        }
        $exchange_rate_first_sec_arr = CurrencyFactory::returnExchangeRate(smc_session()['local_currency'],smc_session()['second_currency']['id']);
        $exchange_rate_first_sec = $exchange_rate_first_sec_arr[1] == '*' ? $exchange_rate_first_sec_arr[0] : (1 / $exchange_rate_first_sec_arr[0]);

        $exchange_rate_sec_first_arr = CurrencyFactory::returnExchangeRate(smc_session()['second_currency']['id'],smc_session()['local_currency']);
        $exchange_rate_sec_first = $exchange_rate_sec_first_arr[1] == '*' ? $exchange_rate_sec_first_arr[0] : (1 / $exchange_rate_sec_first_arr[0]);
        $data['main']['local_currency_rate'] = $exchange_rate_first_sec;
        $data['main']['second_currency_rate'] = $exchange_rate_sec_first;
        if($data['main']['Currency_Code'] == smc_session()['local_currency_code']){
            $data['main']['total_second_currency_grand'] = CommonFunctions::formatNumber($data['main']['grand_total_no_format'] * $data['main']['local_currency_rate']).' ' .smc_session()['second_currency']['symbol'];
        }else{
            $data['main']['total_second_currency_grand'] = CommonFunctions::formatNumber($data['main']['grand_total_no_format'] * $data['main']['second_currency_rate']).' ' .smc_session()['default_currency']['Currency_Symbol']; ;

        }
        $data['main']['lebanon_vat_rate'] = smc_session()['default_setting']['lebanon_vat_amount'];

 
        if(strlen($data['main']['CR']) <= 0)
            $data['main']['hidden_CR'] = 'hidden';
        if(strlen($data['main']['customer_vat']) <= 0)
            $data['main']['hidden_customer_vat'] = 'hidden'; 
        if(strlen($data['main']['customer_address']) <= 0)
            $data['main']['hidden_customer_address'] = 'hidden';
        if(strlen($data['main']['Mobile']) <= 0)
            $data['main']['hidden_Mobile'] = 'hidden';
        if(strlen($data['main']['Phone']) <= 0)
            $data['main']['hidden_Phone'] = 'hidden';

            // echo "<pre>";  die(print_r($data));

        if (!empty($data)) {
            if (!$vars['IsVendor']) {
                $vars['pageName'] = $data['main']['is_actual'] ? 'ViewSalesInvoiceActual' : 'ViewSalesInvoice';
                

                $template_key = $data['main']['is_actual'] ? ['act_invoice', 'invoice'] : ['invoice'];
                
                if (!empty($template_id))
                    $template_key['id'] = $template_id;
                if (empty($data['Details']) && !empty($data['main']['reason_id'])) {
                    $template_row['html'] = 'you can not view this invoice! 
                                <br>
                                This invoice is voided.';
                } else {
                    $template_row = Forms::build_print_template($template_key, $data['main'], array('inv_detail' => $data['Details'], 'inv_detail_linked' => $data['DetailsLinked']));
                }
                 
            } else {
                //            $data = $this->_registry->purchase->getPurchaseToPrint($Invoice_ID);
                $vars['pageName'] = $data['main']['is_actual'] ? 'ViewPurchaseInvoiceActual' : 'ViewPurchaseInvoice';
                $template_key = $data['main']['is_actual'] ? ['act_purchase', 'purchase'] : 'purchase';
                if (!empty($template_id))
                    $template_key['id'] = $template_id;
                $template_row = Forms::build_print_template($template_key, $data['main'], array('inv_detail' => $data['Details']));
            }
         } else
            $template_row['html'] = 'you can not view this invoice! 
        <br>
        This invoice is not available.';
        echo $template_row['html'];
        echo '<script src="' . SITE_LINK . '/Theme/plugins/jquery/jquery-2.1.1.js" type="text/javascript"></script>';
        //        $this->load->view_html($template_row['html'], $vars);
        exit;
    }


    public function view_station_purchase() {
        $vars['title'] = inventoryModel::getmsg('inventory_sys');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $url = explode('/', $_GET['url']);

        $Invoice_ID = $url[count($url) - 1];
        $data = $this->_registry->purchase->getPurchaseToPrint($Invoice_ID);
            //    echo '<pre>'; print_r($data);
        $vars['pageName'] = 'view_station_purchase';
        $template_key = 'station_purchase';
        $template_row = Forms::build_print_template($template_key, $data['main'], array('inv_detail' => $data['Details']));

        echo $template_row['html'];
        echo '<script src="' . SITE_LINK . '/Theme/plugins/jquery/jquery-2.1.1.js" type="text/javascript"></script>';
        //        $this->load->view_html($template_row['html'], $vars);
        exit;
    }

    public function view_customer_coupon() {
        $vars['title'] = inventoryModel::getmsg('inventory_sys');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $url = explode('/', $_GET['url']);
        $Invoice_ID = $url[count($url) - 1];
        $data = $this->_registry->station->getCustomerCouponData($Invoice_ID);
        $vars['pageName'] = 'view_customer_coupon';
        $template_key = 'customer_coupon';
        $template_row = Forms::build_print_template($template_key, $data['main'], array('coupons' => $data['details']['coupons'],
                    'products' => $data['details']['products']));

        echo $template_row['html'];
        echo '<script src="' . SITE_LINK . '/Theme/plugins/jquery/jquery-2.1.1.js" type="text/javascript"></script>';
        //        $this->load->view_html($template_row['html'], $vars);
        exit;
    }

    public function ReportProduct() {
        $vars['pageName'] = 'ReportProduct';
        $vars['title'] = inventoryModel::getmsg('product_report');
        $vars['system_name'] = inventoryModel::getmsg('product_sys');
        $url = explode('/', $_GET['url']);
        $vars['Product_ID'] = $url[count($url) - 1];
        $today = Date::getToday();
        $vars['year'] = date("Y", strtotime($today)); // get the year from today
        $month = date("m", strtotime($today)); // get the month from today
        $vars['monthName'] = date("F", mktime(0, 0, 0, $month, 10)); // transform the month number to month name
        $DefaultCurrencyID = $this->_registry->Currency->getDefaultCurrency();
        $vars['CurrencySymbol'] = $this->_registry->Currency->viewCurrencySymbol($DefaultCurrencyID);
        // show all details about product BY ID 
        $vars['Prodcut_Details'] = $this->_registry->Product->getProductInfo($vars['Product_ID']);

        // show AvailableQuantity By Product_ID
        $vars['AvailableQuantity'] = $this->_registry->Product->viewAvailableQuantity($vars['Product_ID']);

        // show BestCutomer Name By Product_ID
        $vars['BestCustomer'] = $this->_registry->Product->viewBestCustomer($vars['Product_ID']);

        // argument Product_ID , and Display value with Currency
        $vars['AveragePrice'] = $this->_registry->Product->viewProductAveragePrice($vars['Product_ID']);

        //        $vars['AveragePriceOfProduct'] = $this->_registry->Product->viewStockByAveragePriceOfProduct();
        $vars['SoldQuantity'] = $this->_registry->Product->viewSoldQuantityByDate($vars['Product_ID']);

        $vars['SoldQuantityPermonth'] = $this->_registry->Product->viewSoldQuantityByDate($vars['Product_ID'], $vars['year'], $month);

        $vars['ReturnQuantity'] = $this->_registry->Product->viewReturnQuantityByDate($vars['Product_ID']);

        $vars['arr'] = InventoryModel::ReturnSoldQuantity()[0];

        $vars['arrYear'] = InventoryModel::ReturnSoldQuantity()[1];

        $vars['arrCustomerPerYear'] = InventoryModel::ReturnSoldQuantity()[2];
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('product_list'), 'listproduct'], [inventoryModel::getmsg('product_info'), 'ViewProduct/' . ($vars['Product_ID'])], [inventoryModel::getmsg('product_report'), 'ReportProduct/' . ($vars['Product_ID'])]];
        $this->load->view('Inventory/ReportProduct', $vars);
    }

    public function Stock() {
        $vars['pageName'] = 'currentStock';
        $vars['title'] = inventoryModel::getmsg('current_stock');
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        $vars['all_Method_Type'] = $this->_registry->Product->getPricingMethod();
        $vars['Method_Type_Name'] = $this->_registry->Product->getNamePricingMethod();
        $vars['viewStockValue'] = $this->_registry->Product->viewStockValue();
        $vars['currency_symbol'] = CurrencyFactory::getLocalCurrencySymbol();
        $vars['CanChooseMethodPrice'] = $this->_registry->Count->countRows("tbl_stock_default_pricing_method");
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('current_stock'), 'Stock']];
        $this->load->view('Inventory/Stock', $vars);
    }

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

    public function ReturnCustomerList() {

        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        preg_match("/\/vendor/", $_SERVER['REQUEST_URI'], $match);
        $vars['IsVendor'] = count($match) > 0 ? 1 : 0;
        preg_match("/\/act/", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        preg_match("/\/noqty/", $_SERVER['REQUEST_URI'], $match);
        $vars['is_noqty'] = count($match) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] == 1 ? ($vars['IsVendor'] ? 'actual_return_vendor_list' : 'actual_return_customer_list') : ($vars['IsVendor'] ? ($vars['is_noqty'] ? 'return_supplier_noqty_list' : 'ReturnVendorList') : ($vars['is_noqty'] ? 'return_customer_noqty_list' : 'ReturnCustomerList'));

        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? ($vars['IsVendor'] ? 'actual_return_vendor_list' : 'actual_return_customer_list') : ($vars['IsVendor'] ? 'return_vendor_list' : 'return_customer_list'));
        $vars['today'] = Date::getToday();
        $vars['year'] = date("Y", strtotime($vars['today'])); // get the year from today
        $records = $this->_registry->invoice->get_record_types();
        $vars['inv_pur_types'] = !$vars['IsVendor'] ? (!empty($records['inv']) ? $records['inv'] : array()) : (!empty($records['pur']) ? $records['pur'] : array());
        //       echo"<pre>";die(print_r($vars['inv_pur_types']));
        $vars['del_types'] = !$vars['IsVendor'] ? (!empty($records['dlc']) ? $records['dlc'] : array()) : (!empty($records['dls']) ? $records['dls'] : array());
        $vars['order_types'] = !$vars['IsVendor'] ? (!empty($records['ois']) ? $records['ois'] : array()) : (!empty($records['opr']) ? $records['opr'] : array());
        $vars['noqty_types'] = !$vars['IsVendor'] ? array() : (!empty($records['pnq']) ? $records['pnq'] : array());

        $month = date("m", strtotime($vars['today'])); // get the month from today
        $vars['monthName'] = date("F", mktime(0, 0, 0, $month, 10)); // transform the month number to month name
        $vars['pageName'] = $vars['is_actual'] ? ($vars['IsVendor'] ? 'actual_return_vendor_list' : 'actual_return_customer_list') : ($vars['IsVendor'] ? ($vars['is_noqty'] ? 'return_supplier_noqty_list' : 'ReturnVendorList') : ($vars['is_noqty'] ? 'return_customer_noqty_list' : 'ReturnCustomerList'));
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'ReturnCustomerList' . ($vars['IsVendor'] ? '/vendor' : '') . ($vars['is_actual'] ? "/act" : '') . ($vars['is_noqty'] ? "/noqty" : '')]];
        $this->load->view('Inventory/ReturnCustomerList', $vars);
    }

    public function DeliveryNote() {
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        preg_match("/\/order/", $_SERVER['REQUEST_URI'], $match_order);
        $vars['is_order'] = count($match_order) > 0 ? 1 : 0;
        preg_match("/\/pur/", $_SERVER['REQUEST_URI'], $match_order);
        $vars['is_purchase'] = count($match_order) > 0 ? 1 : 0;
        //        preg_match("/\/vendor$/", $_SERVER['REQUEST_URI'], $match);
        $url = explode('/', $_SERVER['REQUEST_URI']);
        //        $vars['IsVendor'] = strtolower($url[count($url) - 1]) == "vendor";
        preg_match("/\/act/", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        preg_match("/\/vendor/", $_SERVER['REQUEST_URI'], $match);
        $vars['IsSales'] = count($match) > 0 ? 0 : 1;
        //        echo $vars['IsSales'].'==';die();
        $vars['IsEdit'] = !$vars['is_order'] && !$vars['is_purchase'] ? (is_numeric($url[count($url) - 1]) ? true : false) : false;
        $vars['id'] = ($vars['IsEdit'] || $vars['is_order'] || $vars['is_purchase']) ? $url[count($url) - 1] : 0;
//        $vars['check_invoice'] = $vars['IsEdit'] ? $this->_registry->delivery->check_delivery_invoice($vars['id'], $vars['IsSales']) : false;
        $vars['check_pur_converted'] = $vars['is_purchase'] ? $this->_registry->delivery->check_purchase_converted($vars['id']) : 0;
        $vars['check_pur_is_from_delivery'] = $vars['is_purchase'] ? $this->_registry->delivery->check_purchase_is_from_delivery($vars['id']) : 0;
        $vars['delivery_converted_nb'] = $this->_registry->delivery->check_delivery_converted($vars['id'], $vars['IsSales']);

//        echo $vars['delivery_converted_nb'].'===='; die();
        $vars['edit_arr'] = $vars['IsEdit'] ? $this->_registry->delivery->get_delivery_note_by_id($vars['id']) : ($vars['is_order'] ? $this->_registry->delivery->get_order_for_delivery_note($vars['id']) : ($vars['is_purchase'] ? $this->_registry->purchase->get_purchase_to_deliver($vars['id']) : array()));
//                        echo "<pre>";die(print_r($vars['edit_arr']));

        $vars['check_lock'] = $vars['IsEdit'] ? CommonFunctions::check_lock_data(['type' => 'delivery', 'start_date' => $vars['edit_arr']['Main']['Date'], 'is_actual' => $vars['is_actual']]) : '';

        $vars['currency_list'] = $this->_registry->Currency->getAllCurrencies();
        $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['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];
        $vars['title'] = !empty($vars['current_invoice_type']) ? $vars['invoice_type_details']['invoice_type_name'] : inventoryModel::getmsg(!$vars['IsSales'] ? 'purchase_delivery_note' : 'invoice_delivery_note');
        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();

        $vars['today'] = Date::getToday();
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['DefaultCurrencyID'] = $vars['IsSales'] ? smc_session()['pricing_class_currency'] : $this->_registry->Currency->getDefaultCurrency();

        $vars['all_uom'] = $this->_registry->Product->getUOM();
        $vars['pageName'] = !$vars['IsSales'] ? 'DeliveryPurchaseNoteList' : 'DeliveryNoteList';
        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'],
            [$vars['title'], 'DeliveryNote' . (!$vars['IsSales'] ? '/vendor' : '')]];
        $this->load->view('Inventory/DeliveryNote', $vars);
    }

    public function ViewReturnDebit() {
        $vars['title'] = inventoryModel::getmsg('return_list');
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        preg_match("/\/vendor\b/i", $_SERVER['REQUEST_URI'], $match);
        $url = explode('/', $_SERVER['REQUEST_URI']);
        //        $vars['IsVendor'] = strtolower($url[count($url) - 3]) == "vendor";
        $vars['IsVendor'] = !empty($match) ? true : false;
        $Invoice_ID = $url[count($url) - 1];
        $vars['ReturnItem'] = $this->_registry->return->getReturnByID($Invoice_ID);
                // echo "<pre>";die(print_r($vars));

        $vars['CurrName'] = $this->_registry->Currency->getCurrencyNameByID($vars['ReturnItem']['Main']['Currency_ID']);
        $vars['pageName'] = $vars['ReturnItem']['Main']['Is_Actual'] == 1 ? ($vars['IsVendor'] ? 'ViewReturnDebitActual' : 'ViewReturnCreditActual') : ($vars['IsVendor'] ? 'ViewReturnDebit' : 'ViewReturnCredit');
        $template_id = !empty($_GET['template_id']) ? $_GET['template_id'] : '';
        if (!empty($vars['ReturnItem']['Main']["Return_ID"])) {
            $template_key = ['return_invoice'];
            $Supp_ID = $vars['ReturnItem']['Main']['Person_ID'];
            $vars['From_Details'] = $vars['IsVendor'] ? $this->_registry->vendor->ViewAllDetails($Supp_ID) : $this->_registry->customer->ViewAllCustomerDetails($Supp_ID);
            $vars['ReturnItem']['Main']['vat_percent'] = smc_session()['vat_percent'];
            $vars['ReturnItem']['Main']['Country_Name'] = $vars['From_Details'][0]['Country_Name'];
            $vars['ReturnItem']['Main']['return_title'] = 'Return ' . ($vars['IsVendor'] ? 'Purchase' : 'Invoice');
            $vars['ReturnItem']['Main']['is_purchase'] = ($vars['IsVendor'] ? 'Purchase' : 'hidden');
            $vars['ReturnItem']['Main']['is_sales'] = ($vars['IsVendor'] ? 'hidden' : 'Invoice');
            $vars['ReturnItem']['Main']['cust_supp_mobile'] = $vars['From_Details'][0][$vars['IsVendor'] ? "Supplier_Mobile" : "Customer_Mobile"];
            $vars['ReturnItem']['Main']['Name'] = $vars['From_Details'][0]["Name"];
            $vars['ReturnItem']['Main']['cust_supp_name'] = $vars['From_Details'][0][$vars['IsVendor'] ? "Supplier_Name" : "Customer_Name"];
            $vars['ReturnItem']['Main']['cust_supp_address'] = $vars['From_Details'][0][$vars['IsVendor'] ? "Supplier_Address" : "Customer_Address"];
            $vars['ReturnItem']['Main']['CR'] = $vars['From_Details'][0]["CR"];
            $vars['ReturnItem']['Main']['customer_vat'] = $vars['From_Details'][0]["customer_vat"];
            $vars['ReturnItem']['Main']['Account_Code'] = $vars['From_Details'][0]["Account_Code"];
            if(smc_session()['default_setting']['enable_sales_invoice_qr_code'] == 1 ){
                $getOrganizationDetails= $this->_registry->organization->getOrganizationDetails()[0];
                $data_tlv= $this->einv_generate_tlv_qr_code(array($getOrganizationDetails['organiaztion_name_en'],$getOrganizationDetails['org_vat_en'],str_replace(' ','T',$vars['ReturnItem']['Main']['date_created']),str_replace(',','',$vars['ReturnItem']['Main']['net']),$vars['ReturnItem']['Main']['Invoice_VAT']));
                $vars['ReturnItem']['Main']['qrcode'] = SITE_LINK . 'common_controller/GenerateQRCode?code=' . $data_tlv;
            }

            if (!empty($template_id))
                $template_key['id'] = $template_id;
            $template_row = Forms::build_print_template($template_key, $vars['ReturnItem']['Main'], array('return_detail' => $vars['ReturnItem']['Details']));
        } else
            $template_row['html'] = 'you can not view this return! <br>This return is not available.';
        echo $template_row['html'];
        //        $this->load->view_html($template_row['html'], $vars);
        echo '<script src="' . SITE_LINK . '/Theme/plugins/jquery/jquery-2.1.1.js" type="text/javascript"></script>';
        exit;
        //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], count($match) > 0 ? [inventoryModel::getmsg('return_list'), 'ReturnCustomerList/vendor'] : [inventoryModel::getmsg('return_list'), 'ReturnCustomerList'], count($match) > 0 ? [inventoryModel::getmsg('view_return'), 'ViewReturnDebit/vendor/' . $url[count($url) - 2] . '/' . $url[count($url) - 1]] : [inventoryModel::getmsg('view_return'), 'ViewReturnDebit/' . $url[count($url) - 2] . '/' . $url[count($url) - 1]]];
        //        $this->load->view('Inventory/ViewReturnDebit', $vars);
    }

    public function POSCat() {
        $vars['pageName'] = 'viewCategories';
        $vars['title'] = inventoryModel::getmsg('pos_categories');
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        preg_match('/\/(\d+)$/', $_SERVER["REQUEST_URI"], $matches);
        preg_match("/\/letters\b/i", $_SERVER['REQUEST_URI'], $letters);
        preg_match("/\/Newest\b/i", $_SERVER['REQUEST_URI'], $Newest);
        $check = '';
        $sort_by = 'c.order_id asc';
        if(!empty($letters)){
            $check = 'letters';
            $sort_by = 'c.Cat_Name asc';
        }elseif(!empty($Newest)){
                        $check = 'Newest';

            $sort_by = 'c.Cat_ID DESC';
        }
        $vars['sort_by_check'] = $check;
        $vars['matches'] = $matches;
        $vars['list'] = count($matches) == 0 ? $this->_registry->Product->getProductsCat('',null,$sort_by) : $this->_registry->Product->getProductsCat($matches[1],null,$sort_by);
        //echo "<pre>";die(print_r($vars));
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('pos_categories'), 'POSCat' . (count($matches) == 0 ? '' : "/{$matches[1]}")]];
        $this->load->view('Inventory/POSCat', $vars);
    }

    //    public function salesOrder() {
    //        $vars['pageName'] = 'salesOrder';
    //        $vars['title'] = inventoryModel::getmsg('inventory');
    //        $vars['system_name'] = inventoryModel::getmsg('sales_order');
    //        $vars['max_order_id'] = $this->_registry->LoadingOrder->getMaxOrder();
    //        $vars['all_zones'] = $this->_registry->vehicle->getVehicleZones();
    //        $vars['productList'] = $this->_registry->Product->selectProducts();
    //        $vars['today'] = Date::getToday();
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('sales_order'), 'salesOrder']];
    //        $this->load->view('Inventory/salesOrder', $vars);
    //    }
    //    public function EditOrder() {
    //        $vars['pageName'] = 'EditSalesOrder';
    //        $vars['title'] = inventoryModel::getmsg('inventory');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        preg_match('/\/(\d+)$/', $_SERVER['REQUEST_URI'], $match);
    //        $url = explode("/", $_GET['url']);
    //        $vars['Sales_ID'] = $url[count($url) - 1];
    //        $vars['today'] = Date::getToday();
    //        $vars['all_zones'] = $this->_registry->vehicle->getVehicleZones();
    //        $vars['Edit_Sales'] = $this->_registry->LoadingOrder->EditSalesOrder($vars['Sales_ID']);
    //        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
    //        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('sales_order'), 'SalesOrderList'], [inventoryModel::getmsg('edit_order'), 'EditOrder/' . $match[1]]];
    //        $this->load->view('Inventory/EditOrder', $vars);
    //    }
    //    public function SalesOrderList() {
    //        $vars['pageName'] = 'SalesOrderList';
    //        $vars['title'] = inventoryModel::getmsg('sales_order_list');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        $vars['today'] = Date::getToday();
    //        $url = explode('/', $_SERVER['REQUEST_URI']);
    //        $vars['Load_ID'] = $url[count($url) - 1];
    //        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
    //        $vars['currencyList'] = $this->_registry->Currency->GetLIListCurrency();
    //        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
    //        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('sales_order_list'), 'SalesOrderList']];
    //        $this->load->view('Inventory/SalesOrderList', $vars);
    //    }
    //    public function ViewSalesOrder($id) {
    //
    //        $vars['pageName'] = 'SalesOrderList';
    //        $vars['title'] = inventoryModel::getmsg('sales_order_details');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('sales_order_list'), 'SalesOrderList'],[inventoryModel::getmsg('sales_order_details'), 'ViewSalesOrder/'.$id]];
    //        $this->load->view('Inventory/ViewSalesOrder', $vars);
    //    }
    //    public function LoadingOrderList() {
    //        $vars['pageName'] = 'LoadingOrderList';
    //        $vars['title'] = inventoryModel::getmsg('loading_order_list');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        $loading_order = new LoadingOrder;
    //        $vars['today'] = Date::getToday();
    //        $vars['LoadingList'] = $this->_registry->LoadingOrder->viewLoadingOrder($vars['today']);
    //        $vars['Statuses'] = [$this->_registry->expenses->getStatusName(18) . "#label-important", $this->_registry->expenses->getStatusName(17) . "#label-warning", $this->_registry->expenses->getStatusName(23) . "#label-info", $this->_registry->expenses->getStatusName(24) . "#label-master"];
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('loading_order_list'), 'LoadingOrderList']];
    //        $this->load->view('Inventory/LoadingOrderList', $vars);
    //    }
    //    public function ViewLoadingOrder() {
    //        $vars['pageName'] = 'viewLoadingOrder';
    //        $vars['title'] = inventoryModel::getmsg('inventory');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        preg_match('/\/(\d+)$/', $_SERVER['REQUEST_URI'], $match);
    //        $organization = new Organization;
    //        $LoadOrder = new LoadingOrder;
    //        $url = explode('/', $_SERVER['REQUEST_URI']);
    //        $vars['Load_ID'] = $url[count($url) - 1];
    //        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
    //        $vars['Load_details'] = $this->_registry->LoadingOrder->viewLoadingInfoByID($vars['Load_ID']);
    //        $vars['loadedButton'] = false;
    //        if (($vars['Load_details'][0]['Is_Load'] == 2 || $vars['Load_details'][0]['Is_Load'] == 3)) {
    //            $vars['Total_Quantity_details'] = $this->_registry->LoadingOrder->viewLoadedQuantityToReturn($vars['Load_ID']);
    //            $vars['loadedButton'] = true;
    //        }
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('loading_order_list'), 'LoadingOrderList'], [inventoryModel::getmsg('view_order'), 'ViewLoadingOrder/' . $match[1]]];
    //        $this->load->view('Inventory/ViewLoadingOrder', $vars);
    //    }
    //    public function addLoadingOrder() {
    //        $vars['pageName'] = 'addLoadingOrder';
    //        $vars['title'] = inventoryModel::getmsg('inventory');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        $vars['max_order_id'] = $this->_registry->LoadingOrder->getMaxLoadingOrder();
    //        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
    //        $vars['classes'] = $this->_registry->Product->getClasses();
    //        $vars['all_vehicles'] = $this->_registry->vehicle->getAvailableVehiclesForSelect();
    //        $vars['today'] = Date::getToday();
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('new_loading_order'), 'addLoadingOrder']];
    //        $this->load->view('Inventory/addLoadingOrder', $vars);
    //    }
    //    public function ReturnDamagedLoad() {
    //        $vars['pageName'] = 'returnDamagedLoad';
    //        $vars['title'] = inventoryModel::getmsg('loading_order_return');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        preg_match('/\/(\d+)$/', $_SERVER['REQUEST_URI'], $match);
    //        $url = explode('/', $_SERVER['REQUEST_URI']);
    //        $vars['Load_ID'] = $url[count($url) - 1];
    //        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
    //        $vars['Load_details'] = $this->_registry->LoadingOrder->viewLoadedDetailsToReturn($vars['Load_ID']);
    //        $vars['Total_Quantity_details'] = $this->_registry->LoadingOrder->viewLoadedQuantityToReturn($vars['Load_ID']);
    //        $vars['Return_details'] = $this->_registry->LoadingOrder->viewLoadReturn($vars['Load_ID']);
    //        $vars['EditMode'] = true;
    //        if ($vars['Load_details'][0]['Is_Load'] == 3) {
    //            $vars['EditMode'] = false;
    //        }
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('loading_order_list'), 'LoadingOrderList'], [inventoryModel::getmsg('loading_order_return'), 'ReturnDamagedLoad/' . $match[1]]];
    //        $this->load->view('Inventory/ReturnDamagedLoad', $vars);
    //    }
    //    public function PaymentofLoadingOrder() {
    //        $vars['pageName'] = 'PaymentofLoadingOrder';
    //        $vars['title'] = inventoryModel::getmsg('payment_of_loading_order');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        preg_match('/\/(\d+)$/', $_SERVER['REQUEST_URI'], $match);
    //        $url = explode('/', $_SERVER['REQUEST_URI']);
    //        $vars['today'] = Date::getToday();
    //        $vars['Load_ID'] = $url[count($url) - 1];
    //        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
    //        $vars['currencyList'] = $this->_registry->Currency->GetLIListCurrency();
    //        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();
    //        $vars['CurrencySymbol'] = $this->_registry->Currency->viewCurrencySymbol($vars['DefaultCurrencyID']);
    //        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
    //        $vars['Load_details'] = $this->_registry->LoadingOrder->viewLoadedDetailsToReturn($vars['Load_ID']);
    //        $vars['ListProducts'] = $this->_registry->LoadingOrder->calculateLoadingOrderAfterReturn($vars['Load_ID']);
    //        $vars['all_accounts'] = $this->_registry->vehicle->viewExpenseAccounts();
    //        $vars['payment_Types'] = $this->_registry->payment->viewPaymentLoadingTypes();
    //        $vars['loadOrderValue'] = $this->_registry->LoadingOrder->viewLoadOrderValue($vars['Load_ID']);
    //        //        $vars['Cashes'] = $this->_registry->invoice->returnPaymentTypes('Cash');
    //        //        $vars['Checks'] = $this->_registry->invoice->returnPaymentTypes('Cheque');
    //        $vars['paidClosedInvoice'] = false;
    //        if ($vars['paidClosedInvoice'] [0]['Is_Load'] == 3) {
    //            $vars['paidClosedInvoice'] = true;
    //        }
    //        $vars['LoadPayment'] = $this->_registry->LoadingOrder->viewLoadingOrderPayments($vars['Load_ID']);
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('loading_order_list'), 'LoadingOrderList'], [inventoryModel::getmsg('inventory'), 'PaymentofLoadingOrder/' . $match[1]]];
    //        $this->load->view('Inventory/PaymentofLoadingOrder', $vars);
    //    }
    //    public function adjustStock() {
    //        $vars['pageName'] = 'adjustStock';
    //        $vars['title'] = inventoryModel::getmsg('Adjust_Stock');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('Adjust_Stock'), 'adjustStock']];
    //        $this->load->view('Inventory/adjustStock', $vars);
    //    }

    public function movement_per_item() {
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        preg_match("/\/act/", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'actual_movement_per_item' : 'movement_per_item';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_movement_per_item' : 'movement_per_item');
        $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
        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10));
        $vars['all_products'] = $this->_registry->Product->selectProducts();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_movement_per_item' : 'movement_per_item'), 'movement_per_item' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/ItemMovement', $vars);
    }

    //    public function ItemCostChange() {
    //        $vars['pageName'] = 'ItemCostChange';
    //        $vars['title'] = inventoryModel::getmsg('item_cost_change');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        $today = Date::gettoday();
    //        $vars['year'] = date("Y", strtotime($today)); // get the year from today
    //        $month = date("m", strtotime($today)); // get the month from today
    //        $vars['monthName'] = date("F", mktime(0, 0, 0, $month, 10));
    //        $vars['all_products'] = $this->_registry->Product->selectProducts();
    //        $firstItemID = $vars['all_products'][0]['Product_ID'];
    //        $vars['productList'] = $this->_registry->Product->IfCostChanged($today, $today, $firstItemID);
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('item_cost_change'), 'ItemCostChange']];
    //        $this->load->view('Inventory/ItemCostChange', $vars);
    //    }

    public function UnmovedItems() {


        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        preg_match("/\/act/", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['today'] = Date::gettoday();
        $vars['pageName'] = $vars['is_actual'] ? 'ActualUnmovedItems' : 'UnmovedItems';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_unmoved_items' : 'unmoved_items');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_unmoved_items' : 'unmoved_items'), 'UnmovedItems' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/UnmovedItems', $vars);
    }

    public function viewVendorList() {
        $vars['pageName'] = 'VendorList';
        $vars['title'] = inventoryModel::getmsg('vendors');
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        $vars['default_currency'] = smc_session()['default_currency'];
        $vars['is_modal_shown'] = !empty($_GET['modal']) ? 1 : 0;
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('vendors'), 'ViewVendorList']];
        $this->load->view('Inventory/ViewVendorList', $vars);
    }

    public function viewVendorDetails() {
        $vars['pageName'] = 'ViewVendor';
        $vars['title'] = inventoryModel::getmsg('vendor_details');
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        //        preg_match('/\/(\d+)$/', $_SERVER['REQUEST_URI'], $match);
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $VendorID = $url[count($url) - 1];
        $vars['Results_Details'] = $this->_registry->vendor->ViewAllDetails($VendorID);
        $vars['default_currency'] = smc_session()['default_currency'];
        $vars['supplier_contacts'] = CommonFunctions::CommonView('tbl_customer_supplier_contacts', ['main_id', 'type_id'], [$VendorID, '2']);

        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('vendors'), 'ViewVendorList'], [inventoryModel::getmsg('vendor_details'), 'viewVendorDetails/' . $VendorID]];
        $this->load->view('Inventory/viewVendorDetails', $vars);
    }

    public function viewCustomerDetails() {
        $vars['pageName'] = 'viewCustomer';
        $vars['title'] = inventoryModel::getmsg('customer_details');
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['Customer_ID'] = $url[count($url) - 1];
        $vars['Results_Details'] = $this->_registry->customer->ViewAllCustomerDetails($vars['Customer_ID']);
        $vars['default_currency'] = smc_session()['default_currency'];
        $vars['is_new'] = !empty($_GET['new']) ? 1 : 0;
        $vars['shipping_companies'] = $this->_registry->organization->getshippingCompanies();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('customers'), 'CustomerList'], [inventoryModel::getmsg('customer_details'), 'viewCustomerDetails/' . $vars['Customer_ID']]];
        $this->load->view('Inventory/viewCustomerDetails', $vars);
    }

    public function PurchaseDeliveryNoteList() {
        $vars['pageName'] = 'DeliveryPurchaseNoteList';
        $vars['title'] = inventoryModel::getmsg('purchase_delivery_note_list');
        preg_match("/\/vendor\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['IsVendor'] = count($match) > 0 ? true : false;
        $vars['system_name'] = inventoryModel::getmsg('inventory_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
        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10));
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'],
            [inventoryModel::getmsg($vars['IsVendor'] ? 'purchase_delivery_note_list' : 'invoice_delivery_note_list'), 'PurchaseDeliveryNoteList' . ($vars['IsVendor'] ? '/vendor' : '')]];
        $this->load->view('Inventory/PurchaseDeliveryNoteList', $vars);
    }

    public function InvoiceDeliveryNoteList() {
        $vars['pageName'] = 'DeliveryNoteList';
        $vars['title'] = inventoryModel::getmsg('invoice_delivery_note_list');
        $vars['system_name'] = inventoryModel::getmsg('inventory_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
        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10));
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('invoice_delivery_note_list'), 'InvoiceDeliveryNoteList']];
        $this->load->view('Inventory/InvoiceDeliveryNoteList', $vars);
    }

    public function PricingList() {
        preg_match("/\/supp/", $_SERVER['REQUEST_URI'], $match2);
        $vars['is_supp'] = count($match2) > 0 ? 1 : 0;
        preg_match("/\/disc/", $_SERVER['REQUEST_URI'], $match_disc);
        $vars['is_disc'] = count($match_disc) > 0 ? 1 : 0;
        preg_match("/\/amt/", $_SERVER['REQUEST_URI'], $match_disc);
        $vars['is_amt'] = count($match_disc) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_supp'] ? ($vars['is_disc'] ? 'supplier_pricing_discounts' : ($vars['is_amt'] ? 'supplier_pricing_discounts_amount' : 'SupplierPricingList')) : ($vars['is_disc'] ? 'customer_pricing_discounts' : ($vars['is_amt'] ? 'customer_pricing_discounts_amount' : 'PricingList'));
        $vars['title'] = inventoryModel::getmsg($vars['is_supp'] ? ($vars['is_disc'] ? 'supplier_pricing_discounts' : ($vars['is_amt'] ? 'supplier_pricing_discounts_amount' : 'supplier_pricing_list')) : ($vars['is_disc'] ? 'customer_pricing_discounts' : ($vars['is_amt'] ? 'customer_pricing_discounts_amount' : 'pricing_list')));
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        //        $vars['classes'] = $this->_registry->Product->getClasses();
        //        $vars['today'] = Date::gettoday();
        //        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
        //        $vars['products'] = $this->_registry->Product->getItemsToAdjustPrice();
        //        $vars['currencyList'] = $this->_registry->Currency->GetLIListCurrency();
        $vars['purchase_id'] = !empty($_GET['id']) ? $_GET['id'] : 0;

        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'PricingList' . ($vars['is_supp'] ? '/supp' : '') . ($vars['is_disc'] ? '/disc' : ($vars['is_amt'] ? '/amt' : ''))]];
        $this->load->view('Inventory/PricingList', $vars);
    }

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

    //    public function ActualSalesInvoice() {
    //        
    //        $vars['title'] = inventoryModel::getmsg('inventory');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        preg_match("/\/sales$/", $_SERVER['REQUEST_URI'], $match);
    //        $url = explode('/', $_SERVER['REQUEST_URI']);
    //        $vars['IsSales'] = strtolower($url[count($url) - 1]) == "sales" ? true : false;
    //        $vars['pageName'] = 'ActualInvoice';
    //        $all_depots = $this->_registry->depot->getDepots();
    //        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
    //        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
    //        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
    //        $vars['all_depots'] = $this->_registry->depot->getDepots();
    //        $vars['all_categories'] = $this->_registry->material->getMaterialCategory();
    //        $vars['Cashes'] = $this->_registry->payment->getPaymentTypesByType('cash');
    //        $vars['Checks'] = $this->_registry->payment->getPaymentTypesByType('cheque');
    //        $vars['CreditCards'] = $this->_registry->payment->getPaymentTypesByType('credit_card');
    //        $vars['purAcc'] = $this->_registry->purchase->getPurchaseAccounts();
    //        $vars['salesAcc'] = $this->_registry->invoice->getSalesAccounts();
    //        $vars['currencyList'] = $this->_registry->Currency->GetLIListCurrency();
    //        $vars['all_uom'] = $this->_registry->material->getMaterialUOM();
    //        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], count($match) > 0 ? [inventoryModel::getmsg('act_invoice'), 'ActualSalesInvoice/sales'] : [inventoryModel::getmsg('act_invoice'), 'ActualSalesInvoice']];
    //        $this->load->view('Inventory/ActualSalesInvoice', $vars);
    //    }
    //    public function ActualNewInvoice() {
    //        $vars['pageName'] = 'ActualInvoice';
    //        $vars['title'] = inventoryModel::getmsg('act_invoice');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        preg_match("/\/sales\b/i", $_SERVER['REQUEST_URI'], $match);
    //        $url = explode('/', $_SERVER['REQUEST_URI']);
    //        $vars['IsSales'] = count($match) > 0 ? true : false;
    //        $vars['IsEdit'] = is_numeric($url[count($url) - 1]) ? true : false;
    //        $vars['id'] = $vars['IsEdit'] ? $url[count($url) - 1] : 0;
    //        $vars['edit_arr'] = $vars['IsEdit'] ? ($vars['IsSales'] ? $this->_registry->invoice->getInvoiceByID($vars['id']) : $this->_registry->purchase->getPurchaseByID($vars['id'])) : '';
    //        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
    //        $vars['all_depots'] = $this->_registry->depot->getDepots();
    //        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
    //        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
    //        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
    //        $vars['all_categories'] = $this->_registry->material->getMaterialCategory();
    //        //        $vars['InvoiceNumber'] = $vars['IsSales'] ? $this->_registry->invoice->getMaxInvoice(1) : $this->_registry->purchase->getMaxPurchase(1);
    //        $vars['Cashes'] = $this->_registry->payment->getPaymentTypesByType('cash');
    //        $vars['Checks'] = $this->_registry->payment->getPaymentTypesByType('cheque');
    //        $vars['CreditCards'] = $this->_registry->payment->getPaymentTypesByType('credit_card');
    //        $vars['currencyList'] = $this->_registry->Currency->GetLIListCurrency();
    //        $vars['all_uom'] = $this->_registry->material->getMaterialUOM();
    //        //        $vars['suppliers'] = $this->_registry->vendor->viewSuppliersForAutoComplete();
    //        //        $vars['purAcc'] = $this->_registry->purchase->getPurchaseAccounts();
    //        //        $vars['salesAcc'] = $this->_registry->invoice->getSalesAccounts();
    //        //        $vars['customers'] = $this->_registry->customer->view();
    //        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], count($match) > 0 ? [inventoryModel::getmsg('act_invoice'), 'ActualNewInvoice/sales'] : [inventoryModel::getmsg('act_invoice'), 'ActualNewInvoice']];
    //        $this->load->view('Inventory/ActualNewInvoice', $vars);
    //    }

    public function ViewDeliveryNote() {
        $vars['title'] = inventoryModel::getmsg('delivery_note');
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');

        preg_match("/\/vendor\b/i", $_SERVER['REQUEST_URI'], $match_vendor);
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['IsVendor'] = count($match_vendor) > 0 ? true : false;
        $IDs = explode('/', $_GET['url']);
        $DefaultCurrencyID = $this->_registry->Currency->getDefaultCurrency();
        $CurrSymbole = $this->_registry->Currency->viewCurrencySymbol($DefaultCurrencyID);
        $vars['CurrName'] = $this->_registry->Currency->getCurrencyNameByID($DefaultCurrencyID);
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['Invoice_ID'] = $url[count($url) - 2];
        $Supp_ID = $url[count($url) - 1];
        $vars['total'] = $vars['IsVendor'] ? $this->_registry->purchase->getPurchaseDeliveryNoteListDetails($vars['Invoice_ID']) : $this->_registry->invoice->getInvoiceDeliveryNoteListDetails($vars['Invoice_ID']);
        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
        $vars['From_Details'] = $vars['IsVendor'] ? $this->_registry->vendor->ViewAllDetails($Supp_ID) : $vars['org_details'];
        $vars['To_Details'] = $vars['IsVendor'] ? $vars['org_details'] : $this->_registry->customer->ViewAllCustomerDetails($Supp_ID);
        $vars['pageName'] = $vars['IsVendor'] ? 'ViewPurchaseDeliveryNote' : 'DeliveryNoteList';
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['IsVendor'] ? 'purchase_delivery_note_list' : 'invoice_delivery_note_list'), $vars['IsVendor'] ? 'PurchaseDeliveryNoteList/vendor' : 'InvoiceDeliveryNoteList']];
        $this->load->view('Inventory/ViewDeliveryNote', $vars);
    }

    //
    //    public function LoadOrderWithoutSalesOrder() {
    //        $vars['pageName'] = 'salesOrder';
    //        $vars['title'] = inventoryModel::getmsg('loading_order');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        $vars['all_vehicles'] = $this->_registry->vehicle->getAvailableVehiclesForSelect();
    //        $vars['productList'] = $this->_registry->Product->selectProducts();
    //        $vars['today'] = Date::getToday();
    //        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
    //        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
    //        $vars['classes'] = $this->_registry->Product->getClasses();
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('loading_order'), 'LoadOrderWithoutSalesOrder']];
    //        $this->load->view('Inventory/LoadOrderWithoutSalesOrder', $vars);
    //    }
    //
    //    public function InventoryDashboard() {
    //        $vars['pageName'] = 'InventoryDashboard';
    //        $vars['title'] = inventoryModel::getmsg('dashboard');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        $today = Date::getToday();
    //        $vars['year'] = date("Y", strtotime($today)); // get the year from today
    //        $month = date("m", strtotime($today)); // get the month from today
    //        $vars['monthName'] = date("F", mktime(0, 0, 0, $month, 10));
    //        $duedt = explode("-", $today);
    //        $date = mktime(0, 0, 0, $duedt[1], $duedt[2], $duedt[0]);
    //        $week = (int) date('W', $date);
    //        $vars['InvoiceNb'] = $this->_registry->invoice->getInvoiceNumbers();
    //        $vars['returnNb'] = $this->_registry->invoice->getTotalInvoiceReturn();
    //        $vars['InvoiceDueDateDaily'] = $this->_registry->invoice->getInvoiceByDueDate(null, $today);
    //        $vars['InvoiceDueDateWeek'] = $this->_registry->invoice->getInvoiceByDueDate($week);
    //        $vars['InvoiceDueDateMonth'] = $this->_registry->invoice->getInvoiceByDueDate(null, null, $month, $vars['year']);
    //        $vars['PurchaseDueDateWeek'] = $this->_registry->purchase->getPurchaseByDueDate($week);
    //        $vars['PurchaseDueDateMonth'] = $this->_registry->purchase->getPurchaseByDueDate(null, null, $month, $vars['year']);
    //        $vars['PurchaseNb'] = $this->_registry->purchase->getPurchaseNumbers();
    //        $vars['OrderNb'] = $this->_registry->LoadingOrder->getSalesOrderNumber();
    //        $DefaultCurrencyID = $this->_registry->Currency->getDefaultCurrency();
    //        $vars['DefaultCurrSymbol'] = $this->_registry->Currency->viewCurrencySymbol($DefaultCurrencyID);
    //        //        $vars['arrName'] = InventoryModel::ProductSummaryByCat()[0];
    //        $vars['arrVal'] = InventoryModel::DailyProductSummary()[1];
    //        $vars['arrName1'] = InventoryModel::inventoryDashboard()[0];
    //        $vars['arrValue1'] = InventoryModel::inventoryDashboard()[1];
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('dashboard'), 'InventoryDashboard']];
    //        $this->load->view('Inventory/InventoryDashboard', $vars);
    //    }

    public function GeneralSetting() {
        $vars['pageName'] = 'GeneralSetting';
        $vars['title'] = inventoryModel::getmsg('general_setting');
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        $vars['id'] = isset($_GET['ID']) ? $_GET['ID'] : 0;
        $vars['allSetting'] = $this->_registry->Product->getAllSettings();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('general_setting'), 'GeneralSetting']];
        $this->load->view('Inventory/GeneralSetting', $vars);
    }

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

    public function HistoryReportForItem() {
        $vars['pageName'] = 'HistoryReportForItem';
        $vars['title'] = inventoryModel::getmsg('history_report_item');
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        $vars['product'] = $this->_registry->Product->mainItemsHistory();
        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
        $vars['CurrencyDefaultName'] = $this->_registry->Currency->getCurrencyNameByID($vars['DefaultCurrencyID']);
        $vars['CurrencyDefaultSymbol'] = $this->_registry->Currency->viewCurrencySymbol($vars['DefaultCurrencyID']);
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('history_report_item'), 'HistoryReportForItem']];
        $this->load->view('Inventory/HistoryReportForItem', $vars);
    }

    public function HistoryReportForItemsDetails() {
        $vars['pageName'] = 'HistoryReportForItemDetails';
        $vars['title'] = inventoryModel::getmsg('history_report_item_details');
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        $vars['url'] = explode('/', $_SERVER['REQUEST_URI']);
        $vars['ID'] = $vars['url'][count($vars['url']) - 1];
        $vars['product'] = $this->_registry->Product->itemsHistoryDetails($vars['ID']);
        $vars['product_purchased_details'] = $this->_registry->Product->getInvoicePurchasedByItem($vars['ID']);
        $vars['product_sales_details'] = $this->_registry->Product->getSalesInvoicePurchasedByItem($vars['ID']);
        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
        $vars['CurrencyDefaultName'] = $this->_registry->Currency->getCurrencyNameByID($vars['DefaultCurrencyID']);
        $vars['CurrencyDefaultSymbol'] = $this->_registry->Currency->viewCurrencySymbol($vars['DefaultCurrencyID']);
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('history_report_item'), 'HistoryReportForItem'], [inventoryModel::getmsg('history_report_item_details'), 'HistoryReportForItemsDetails/' . $vars['ID']]];
        $this->load->view('Inventory/HistoryReportForItemsDetails', $vars);
    }

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

    //    public function mergeCategoriesItems() {
    //        $vars['pageName'] = 'TemplateStock';
    //        $vars['title'] = inventoryModel::getmsg('merge_items_categories');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory');
    //        $vars['productTypes'] = $this->_registry->Product->getItemsTypes();
    //        $vars['all_categories'] = $this->_registry->Product->getItemsCategoryByType(0);
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('merge_items_categories'), 'mergeCategoriesItems']];
    //        $this->load->view('Inventory/mergeCategoriesItems', $vars);
    //    }
    //    public function addServicesInvoice() {
    //        $vars['pageName'] = 'newServicesInvoice';
    //        $vars['title'] = inventoryModel::getmsg('new_service_invoice');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory');
    //        preg_match("/\/act$/", $_SERVER['REQUEST_URI'], $match);
    //        $url = explode('/', $_SERVER['REQUEST_URI']);
    //        $vars['IsActual'] = strtolower($url[count($url) - 1]) == "act" ? "1" : "0";
    //        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
    //        $vars['CurrSymbole'] = $this->_registry->Currency->viewCurrencySymbol($vars['DefaultCurrencyID']);
    //        $vars['salesAcc'] = $this->_registry->invoice->getSalesAccounts();
    //        $vars['customers'] = $this->_registry->customer->view();
    //        $vars['today'] = Date::getToday();
    //        $vars['InvoiceNumber'] = CommonFunctions::getLastID('tbl_inventory_services_invoices', 'Invoice_ID');
    //        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
    //        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
    //        $vars['currencyList'] = $this->_registry->Currency->GetLIListCurrency();
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('new_service_invoice'), 'addServicesInvoice']];
    //        $this->load->view('Inventory/addServicesInvoice', $vars);
    //    }
    //
    //    public function ServicesInvoiceList() {
    //        $vars['pageName'] = 'ServicesInvoiceList';
    //        $vars['title'] = inventoryModel::getmsg('service_invoice_list');
    //        preg_match("/\/act$/", $_SERVER['REQUEST_URI'], $match);
    //        $url = explode('/', $_SERVER['REQUEST_URI']);
    //        $vars['IsActual'] = strtolower($url[count($url) - 1]) == "act" ? "1" : "0";
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        $vars['today'] = Date::gettoday();
    //        $vars['year'] = date("Y", strtotime($vars['today']));
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('service_invoice_list'), 'ServicesInvoiceList']];
    //        $this->load->view('Inventory/ServicesInvoiceList', $vars);
    //    }
    //    public function ViewServicesInvoice() {
    //        $vars['pageName'] = 'ViewServicesInvoice';
    //        $vars['title'] = inventoryModel::getmsg('view_service_invoice');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
    //        $url = explode('/', $_SERVER['REQUEST_URI']);
    //        $Inv_ID = $url[count($url) - 1];
    //        $vars['ListDetails'] = $this->_registry->invoice->viewServicesDetails($Inv_ID);
    //        $vars['From_Details'] = $this->_registry->organization->getOrganizationDetails();
    //        $vars['To_Details'] = $this->_registry->customer->ViewAllCustomerDetails($vars['ListDetails'][0]['Customer_ID']);
    //        $vars['CurrName'] = $this->_registry->Currency->getCurrencyNameByID($vars['ListDetails'][0]['Currency_ID']);
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('service_invoice_list'), 'ServicesInvoiceList']];
    //        $this->load->view('Inventory/ViewServicesInvoice', $vars);
    //    }

    public function DueDateInvoiceList() {
        $vars['title'] = inventoryModel::getmsg('invoice_duedate_list');
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['IsVendor'] = strtolower($url[count($url) - 1]) == "vendor";
        $vars['today'] = Date::gettoday();
        $vars['pageName'] = $vars['IsVendor'] ? 'DueDatePurchaseList' : 'DueDateInvoiceList';
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['IsVendor'] ? 'purchase_duedate_list' : 'invoice_duedate_list'), 'DueDateInvoiceList' . ($vars['IsVendor'] ? '/vendor' : '')]];
        $this->load->view('Inventory/DueDateInvoiceList', $vars);
    }

    public function CustomerLimitBalance() {
        $vars['pageName'] = 'CustomerLimitBalance';
        $vars['title'] = inventoryModel::getmsg('customer_limit_balance');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['all_currencies'] = $this->_registry->Currency->getAllCurrencies();
        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
        $vars['CurrSymbole'] = $this->_registry->Currency->viewCurrencySymbol($vars['DefaultCurrencyID']);
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('customer_limit_balance'), 'CustomerLimitBalance']];
        $this->load->view('Inventory/CustomerLimitBalance', $vars);
    }

    public function quotationOrder() {
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        preg_match("/\/sales\b/i", $_SERVER['REQUEST_URI'], $match_sales);
        preg_match("/\/order\b/i", $_SERVER['REQUEST_URI'], $match_order);
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['IsSales'] = count($match_sales) > 0 ? true : false;
        $vars['IsQuotation'] = count($match_order) > 0 ? false : true;
        preg_match("/\/qto\b/i", $_SERVER['REQUEST_URI'], $match_qto);
        $vars['is_qto'] = count($match_qto) > 0 ? true : false; //when converting quotation to order
        $vars['pageName'] = $vars['IsQuotation'] ? ($vars['IsSales'] ? 'sales_quotation' : 'purchase_quotation') : ($vars['is_actual'] ? ($vars['IsSales'] ? 'actual_sales_order' : 'actual_purchase_order') : ($vars['IsSales'] ? 'salesOrder' : 'purchaseOrder')); // to be edited
        // echo "<pre>";die(print_r($vars));
        preg_match("/\/rev\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_revision'] = count($match_act) > 0 ? true : false;

        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['IsEdit'] = (is_numeric($url[count($url) - 1]) && !$vars['is_qto'] && !$vars['is_revision'] ) ? true : false;
        $vars['id'] = ($vars['IsEdit'] || $vars['is_qto'] || $vars['is_revision']) ? $url[count($url) - 1] : 0;
        if (!$vars['IsEdit']) {
//            $vars['unique_id'] = 'order' . uniqid();
//            smc_session()['duplicate_check'][$vars['unique_id']] = true;
            $vars['unique_id'] = token_unique::generate_token('order');
        }
        $vars['edit_arr'] = ($vars['IsEdit'] || $vars['is_qto']) ? $this->_registry->purchase->getPurchaseOrderByID($vars['id']) : ($vars['is_revision'] ? $this->_registry->purchase->get_quotation_revision($vars['id']) : array());
        $vars['check_lock'] = $vars['IsEdit'] ? CommonFunctions::check_lock_data(['type' => 'order', 'start_date' => $vars['edit_arr']['Main']['Date'], 'is_actual' => ($vars['is_actual']?1:0)]) : '';

        $vars['drivers_item_list'] = CommonBusiness::getDrivers();
        $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['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 $vars['current_invoice_type'].'====';die();
        //                echo "<pre>";die(print_r($vars['invoice_type_details']));
        $vars['title'] = !empty($vars['current_invoice_type']) ? $vars['invoice_type_details'][$vars['is_actual'] == 1 ? 'invoice_type_name_actual' : 'invoice_type_name'] : inventoryModel::getmsg(( $vars['IsQuotation'] ? ($vars['IsSales'] ? 'sales_quotation' : 'purchase_quotation') : ($vars['is_actual'] ? ($vars['IsSales'] ? 'actual_sales_order' : 'actual_purchase_order') : ($vars['IsSales'] ? 'sales_order' : 'purchase_orders')))); // to be edited
        //        echo $vars['is_data_collector'] ? 'here' : 'not';
        //        die();
        //        $vars['collector_data'] = $this->_registry->invoice->getInvoiceByID(2);
        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['today'] = Date::getToday();
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['DefaultCurrencyID'] = $vars['IsSales'] ? smc_session()['pricing_class_currency'] : $this->_registry->Currency->getDefaultCurrency();
        $currency_data = $this->_registry->Currency->getCurrencyByID($vars['DefaultCurrencyID']);
        //        $vars['DefaultCurrencyID'] = smc_session()['local_currency'];
        $vars['currency_round'] = (($vars['IsEdit'] || $vars['is_qto']) && isset($vars['edit_arr']['Main']['currency_round'])) ? $vars['edit_arr']['Main']['currency_round'] : $currency_data[2];
        //        $vars['currency_round'] = $vars['IsEdit'] ? $vars['edit_arr']['Main']['currency_round'] : smc_session()['local_currency_round'];
        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
        //                        echo"<pre>";
        //                        die(print_r($vars['edit_arr']));
        //        $vars['InvoiceNumber'] = $vars['IsSales'] ? $this->_registry->invoice->getMaxInvoice() : $this->_registry->purchase->getMaxPurchase();
        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();
        $vars['all_uom'] = $this->_registry->Product->getUOM();
        $vars['templates'] = CommonFunctions::CommonView('tbl_print_template', ['template_key'], [$vars['IsQuotation'] ? 'quotation' : 'order']);



        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [
                $vars['title'],
                'quotationOrder' . ($vars['IsQuotation'] ? '/quotation' : '/order') . ($vars['IsSales'] ? '/sales' : '') . ($vars['is_actual'] ? '/act' : '') . (empty($vars['current_invoice_type']) ? '' : ('/type' . $vars['current_invoice_type'])) . ($vars['IsEdit'] ? '/' . $vars['id'] : '')]]; // to be  edited

        $this->load->view('Inventory/quotationOrder', $vars);
    }

    public function quotationOrderList() {
        preg_match("/\/sales\b/i", $_SERVER['REQUEST_URI'], $match_sales);
        preg_match("/\/quotation\b/i", $_SERVER['REQUEST_URI'], $match_order);
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['IsSales'] = count($match_sales) > 0 ? true : false;
        $vars['IsQuotation'] = count($match_order) > 0 ? true : false;

        $vars['pageName'] = $vars['IsQuotation'] ? ($vars['IsSales'] ? 'sales_quotation_list' : 'purchase_quotation_list') : ($vars['is_actual'] ? ($vars['IsSales'] ? 'actual_sales_order_list' : 'actual_purchase_order_list') : ($vars['IsSales'] ? 'SalesOrderList' : 'purchaseOrderList'));
        $vars['title'] = inventoryModel::getmsg($vars['IsQuotation'] ? ($vars['IsSales'] ? 'sales_quotation_list' : 'purchase_quotation_list') : ( $vars['is_actual'] ? ($vars['IsSales'] ? 'actual_sales_order_list' : 'actual_purchase_order_list') : ($vars['IsSales'] ? 'sales_order_list' : 'purchase_order_list')));


        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $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));
        $records = $this->_registry->invoice->get_record_types();
        $vars['inv_pur_types'] = $vars['IsSales'] ? (!empty($records['inv']) ? $records['inv'] : array()) : (!empty($records['pur']) ? $records['pur'] : array());
        $vars['del_types'] = $vars['IsSales'] ? (!empty($records['dlc']) ? $records['dlc'] : array()) : (!empty($records['dls']) ? $records['dls'] : array());
        $vars['order_types'] = $vars['IsSales'] ? (!empty($records['ois']) ? $records['ois'] : array()) : (!empty($records['opr']) ? $records['opr'] : array());
        $vars['noqty_types'] = $vars['IsSales'] ? array() : (!empty($records['pnq']) ? $records['pnq'] : array());

        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [
                inventoryModel::getmsg($vars['IsQuotation'] ? ($vars['IsSales'] ? 'sales_quotation_list' : 'purchase_quotation_list') : ($vars['is_actual'] ? ($vars['IsSales'] ? 'actual_sales_order_list' : 'actual_purchase_order_list') : ($vars['IsSales'] ? 'sales_order_list' : 'purchase_order_list'))),
                'quotationOrderList' . ($vars['IsQuotation'] ? '/quotation' : '/order') . ($vars['IsSales'] ? '/sales' : '') . ($vars['is_actual'] ? '/act' : '')]];

        $this->load->view('Inventory/quotationOrderList', $vars);
    }

    public function viewQuotationOrder() {
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        preg_match("/\/quotation\b/i", $_SERVER['REQUEST_URI'], $match_sales);
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['IsQuotation'] = count($match_sales) > 0 ? true : false;
        $url = explode('/', $_GET['url']);
        $id = $url[count($url) - 1];
        $vars['list'] = $this->_registry->invoice->getQuotationToPrint($id);

        //$vars['title'] = inventoryModel::getmsg($vars['IsQuotation'] ? ($vars['list']['Main']['is_sales'] == 1 ? 'sales_quotation_details' : 'purchase_quotation_details') : ($vars['is_actual'] ? ($vars['list']['Main']['is_sales'] == 1 ? 'actual_sales_order_details' : 'actual_purchase_order_details') : ($vars['list']['Main']['is_sales'] == 1 ? 'sales_order_details' : 'purchase_order_details')));
        $vars['pageName'] = $vars['IsQuotation'] ? ($vars['list']['Main']['is_sales'] == 1 ? 'view_sales_quotation_details' : 'view_purchase_quotation_details') : ($vars['is_actual'] == 1 ? ($vars['list']['Main']['is_sales'] == 1 ? 'actual_sales_order_details' : 'actual_purchase_order_details') : ($vars['list']['Main']['is_sales'] == 1 ? 'view_sales_order_details' : 'view_purchase_order_details'));
        //$vars['IsPurchase'] = $vars['list']['Main']['is_sales'] == 1 ? 0 : 1;
        // $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'],
        //  [inventoryModel::getmsg($vars['IsQuotation'] ? ($vars['list']['Main']['is_sales'] == 1 ? 'sales_quotation_list' : 'purchase_quotation_list') : ($vars['is_actual'] == 1 ? ($vars['list']['Main']['is_sales'] == 1 ? 'actual_sales_order_list' : 'actual_purchase_order_list') : ($vars['list']['Main']['is_sales'] == 1 ? 'sales_order_list' : 'purchase_order_list'))),
        //       'quotationOrderList' . ($vars['IsQuotation'] ? '/quotation' : '/order') . (($vars['list']['Main']['is_sales'] == 1 ? '/sales' : '') . ($vars['is_actual'] == 1 ? '/act' : ''))],
        //    [inventoryModel::getmsg($vars['IsQuotation'] ? 'view_quotation' : 'view_order'), 'viewQuotationOrder/' . ($vars['IsQuotation'] ? 'quotation/' : 'order/') . ($vars['is_actual'] == 1 ? 'act/' : '') . $id]];     
        $template_id = !empty($_GET['template_id']) ? $_GET['template_id'] : '';
        //echo "<pre>"; die(print_r($vars));
        $template_key = $vars['IsQuotation'] ? ($vars['list']['Main']['is_sales'] == 1 ? ($vars['is_actual'] ? ['act_sales_quotation', 'quotation'] : ['sales_quotation', 'quotation']) : ($vars['is_actual'] ? ['act_purchase_quotation', 'purchase_quotation', 'quotation'] : ['purchase_quotation', 'quotation'])) : ($vars['list']['Main']['is_sales'] == 1 ? ($vars['is_actual'] ? ['act_sales_order', 'sales_order', 'order'] : ['sales_order', 'order']) : ($vars['is_actual'] ? ['act_purchase_order', 'purchase_order', 'order'] : ['purchase_order', 'order']));
        if (!empty($template_id))
            $template_key['id'] = $template_id;
        $template_row = Forms::build_print_template($template_key, $vars['list']['Main'], array('inv_detail' => $vars['list']['Details']));
        echo $template_row['html'];
        echo '<script src="' . SITE_LINK . '/Theme/plugins/jquery/jquery-2.1.1.js" type="text/javascript"></script>';
        //$this->load->view_html($template_row['html'], $vars);
        exit;
    }

    //    public function purchaseOrderToInvoice() {
    //        $vars['pageName'] = 'addpurchase';
    //        $vars['title'] = inventoryModel::getmsg('invoice');
    //        $vars['system_name'] = inventoryModel::getmsg('inventory');
    //        $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['suppliers'] = $this->_registry->vendor->viewSuppliersForAutoComplete();
    //        $vars['purAcc'] = $this->_registry->purchase->getPurchaseAccounts();
    //        $vars['all_depots'] = $this->_registry->depot->getDepots();
    //        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
    //        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
    //        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
    //        $vars['all_categories'] = $this->_registry->material->getMaterialCategory();
    //        $vars['InvoiceNumber'] = $this->_registry->purchase->getMaxPurchase();
    //        $vars['Cashes'] = $this->_registry->payment->getPaymentTypesByType('cash');
    //        $vars['Checks'] = $this->_registry->payment->getPaymentTypesByType('cheque');
    //        $vars['CreditCards'] = $this->_registry->payment->getPaymentTypesByType('credit_card');
    //        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();
    //        $url = explode('/', $_SERVER['REQUEST_URI']);
    //        $ID = $url[count($url) - 1];
    //        $vars['order_details'] = $this->_registry->purchase->getPurchaseOrderDetails($ID);
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('invoice'), 'purchaseOrderToInvoice']];
    //        $this->load->view('Inventory/purchaseOrderToInvoice', $vars);
    //    }

    public function uomConversion() {
        $vars['pageName'] = 'uomConversion';
        $vars['title'] = inventoryModel::getmsg('uom_conversion');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['all_uom'] = $this->_registry->material->getMaterialUOM();
        $vars['all_products'] = $this->_registry->Product->selectProducts();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('uom_conversion'), 'uomConversion']];
        $this->load->view('Inventory/uomConversion', $vars);
    }

    public function InvoiceReportPerTime() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'act_invoice_report' : 'invoice_report';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_invoice_per_time' : 'invoice_per_time');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $today = Date::gettoday();
        $vars['year'] = date("Y", strtotime($today)); // get the year from today
        $vars['month'] = date("m", strtotime($today)); // get the month from today
        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10)); // get Month Name
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_invoice_per_time' : 'invoice_per_time'), 'InvoiceReportPerTime' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/InvoiceReportPerTime', $vars);
    }

    public function TotalItemsPerDate() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'act_total_sold_items' : 'total_sold_items';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_sold_per_date' : 'sold_per_date');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['today'] = Date::gettoday();
        $vars['users'] = CommonFunctions::CommonView('tbl_common_users');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_sold_per_date' : 'sold_per_date'), 'TotalItemsPerDate' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/TotalItemsPerDate', $vars);
    }

    public function DetailedInvoiceProductReport() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'act_detailed_sold_items' : 'detailed_sold_items';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_detailed_sold_per_date' : 'detailed_sold_per_date');
        $vars['system_name'] = inventoryModel::getmsg('invoice_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
        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10)); // get Month Name
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_detailed_sold_per_date' : 'detailed_sold_per_date'), 'DetailedInvoiceProductReport' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/DetailedInvoiceProductReport', $vars);
    }

    public function invoices_details_vehicle_driver() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'invoice_detailed_vehicle_driver_actual' : 'invoice_detailed_vehicle_driver';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'invoice_detailed_vehicle_driver_actual' : 'invoice_detailed_vehicle_driver');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $today = Date::gettoday();
        $vars['year'] = date("Y", strtotime($today)); // get the year from today
        $vars['month'] = date("m", strtotime($today)); // get the month from today
        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10)); // get Month Name
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'actual_invoice_details' : 'invoice_details'), 'invoices_details_vehicle_driver' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/invoices_details_vehicle_driver', $vars);
    }

    public function DetailedReturnedProductReport() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'act_detailed_returned_items' : 'detailed_returned_items';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_detailed_returned_items' : 'detailed_returned_items');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['return_type'] = $url[count($url) - 1];
        $today = Date::gettoday();
        $vars['year'] = date("Y", strtotime($today)); // get the year from today
        $vars['month'] = date("m", strtotime($today)); // get the month from today
        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10)); // get Month Name
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_detailed_returned_items' : 'detailed_returned_items'), 'DetailedReturnedProductReport' . ($vars['is_actual'] ? '/act/1' : '/1')]];
        $this->load->view('Inventory/DetailedReturnedProductReport', $vars);
    }

    public function printBarCode() {
        $vars['pageName'] = 'print_barcode';
        $vars['title'] = inventoryModel::getmsg('print_barcodes');
        $vars['system_name'] = inventoryModel::getmsg('general_setting');
        //        $url = explode('/', $_SERVER['REQUEST_URI']);
        if (!empty($_POST['pr']))
            $_GET['product_id'] = explode('&', $_POST['pr'])[0];
        elseif (!empty($_GET['pr']))
            $_GET['product_id'] = explode('&', $_GET['pr'])[0];
        //        echo $_GET['product_id'][0];die();
        $vars['all_uom'] = $this->_registry->material->getMaterialUOM();
        $vars['printer_size'] = $this->_registry->Product->getPaperSize();
        $vars['selected_product'] = empty($_GET['product_id']) ? '' : $this->_registry->Product->setData($_GET)->getProductsForAutoComplete('', 0);
        //        echo"<pre>";
        //        die(print_r($_GET));
        $vars['current_price_class_name'] = !empty(smc_session()['default_setting']['default_barcode_class_id']) ? CommonFunctions::SpecificAttribute('pricing_class_list', 'class_id', smc_session()['default_setting']['default_barcode_class_id'], 'class_name') : '';
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('print_barcodes'), 'printBarCode']];
        $this->load->view('Inventory/printBarCode', $vars);
    }

    public function ItemProfit() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'actual_item_profit' : 'ItemProfit';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_item_profit' : 'item_profit');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $today = Date::gettoday();
        $vars['year'] = date("Y", strtotime($today)); // get the year from today
        $vars['month'] = date("m", strtotime($today)); // get the month from today
        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10)); // get Month Name
        //        $vars['profit'] = $this->_registry->invoice->getTotalItemProfit($today);
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_item_profit' : 'item_profit'), 'ItemProfit' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/ItemProfit', $vars);
    }

    public function ReturnNoInvoice() {

        $vars['system_name'] = inventoryModel::getmsg('purchase_sys');
        preg_match("/\/sales\b/i", $_SERVER['REQUEST_URI'], $match);
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['IsSales'] = count($match) > 0 ? true : false;

        preg_match("/\/act/", $_SERVER['REQUEST_URI'], $match_act);
        preg_match("/\/exchange/", $_SERVER['REQUEST_URI'], $match_exchange);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['is_exchange'] = count($match_exchange) > 0 ? 1 : 0;

        preg_match("/\/noqty/", $_SERVER['REQUEST_URI'], $match);
        $vars['is_noqty'] = count($match) > 0 ? 1 : 0;

        $vars['IsEdit'] = (empty($_GET['is_pop']) ? is_numeric($url[count($url) - 1]) : is_numeric(explode("?", $url[count($url) - 1])[0])) ? true : false;
        $vars['id'] = $vars['IsEdit'] ? $url[count($url) - 1] : 0;
        if (empty($_GET['is_pop'])) {
            $vars['id'] = $vars['IsEdit'] ? $url[count($url) - 1] : 0;
        } else {
            $vars['id'] = $vars['IsEdit'] ? explode("?", $url[count($url) - 1])[0] : 0;
        }
        if (!$vars['IsEdit']) {
//            $vars['unique_id'] = 'ret' . uniqid();
//            smc_session()['duplicate_check'][$vars['unique_id']] = true;
            $vars['unique_id'] = token_unique::generate_token('ret');
        }


        $vars['pageName'] = $vars['is_exchange'] ? ($vars['IsEdit'] ? 'edit_exchange' : 'add_exchange') :
                ($vars['IsSales'] ? ($vars['is_actual'] ? 'actual_return_customer' : ($vars['is_noqty'] ? 'return_customer_noqty' : 'ReturnCustomer') ) :
                        ($vars['is_actual'] ? 'actual_return_vendor' : ($vars['is_noqty'] ? 'return_supplier_noqty' : 'ReturnVendor')));
        $vars['title'] = inventoryModel::getmsg($vars['is_exchange'] ? ($vars['IsEdit'] ? 'edit_exchange' : 'add_exchange') : ($vars['IsSales'] ? ($vars['is_actual'] ? 'actual_return_customer' : ($vars['is_noqty'] ? 'return_customer_noqty' : 'return_from_customer') ) : ($vars['is_actual'] ? 'actual_return_vendor' : ($vars['is_noqty'] ? 'return_supplier_noqty' : 'return_to_vendor'))));
        $vars['edit_arr'] = $vars['IsEdit'] ? ($vars['is_exchange'] ? $this->_registry->invoicepos->retreive_exchange_by_id($vars['id']) : $this->_registry->return->getReturnByID($vars['id'], $vars['IsSales'])) : '';
        $vars['check_lock'] = $vars['IsEdit'] ? CommonFunctions::check_lock_data(['type' => ($vars['is_exchange'] ? 'exchange' : 'return'), 'start_date' => $vars['edit_arr']['Main']['Date'], 'is_actual' => $vars['is_actual']]) : '';

//                                echo"<pre>";
//                                die(print_r($vars['edit_arr']));
        $vars['is_main_transfer'] = $vars['IsEdit'] ? ($vars['IsSales'] ? $vars['edit_arr']['Main']['is_main_transfer'] : 0) : 0;
        $vars['pending_invoices'] = $this->_registry->invoice->getPendingInvoices();
        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['today'] = Date::getToday();
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['DefaultCurrencyID'] = $vars['IsSales'] ? smc_session()['pricing_class_currency'] : $this->_registry->Currency->getDefaultCurrency();
        //        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
        //        $vars['InvoiceNumber'] = $vars['IsSales'] ? $this->_registry->invoice->getMaxInvoice() : $this->_registry->purchase->getMaxPurchase();
        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();
        $vars['templates'] = CommonFunctions::CommonView('tbl_print_template', ['template_key'], ['return_invoice']);


        $vars['all_uom'] = $this->_registry->Product->getUOM();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'],
            [inventoryModel::getmsg($vars['is_exchange'] ? 'exchange_list' : ($vars['IsSales'] ? ($vars['is_actual'] ? 'actual_return_customer_list' : ($vars['is_noqty'] ? 'return_customer_noqty_list' : 'return_customer_list')) : ($vars['is_actual'] ? 'actual_return_vendor_list' : ($vars['is_noqty'] ? 'return_supplier_noqty_list' : 'return_vendor_list')))), $vars['is_exchange'] ? 'exchange_list' : ('ReturnCustomerList' . ($vars['IsSales'] ? '' : '/vendor') . ($vars['is_actual'] ? '/act' : '') . ($vars['is_noqty'] ? '/noqty' : ''))],
            [$vars['title'], $vars['is_exchange'] ? ('ReturnNoInvoice/sales/exchange' . ($vars['IsEdit'] ? "/{$vars['id']}" : '')) : ('ReturnNoInvoice' . ($vars['IsSales'] ? '/sales' : '') . ($vars['is_actual'] ? '/act' : '') . ($vars['is_noqty'] ? '/noqty' : '') . ($vars['IsEdit'] ? "/{$vars['id']}" : ""))]];
        //$vars['breadCrumb'] 	= [['Inventory','Inventory'],['PURCHASE INVOICE',''],['New Purchase','addpurchase']];
        $this->load->view('Inventory/ReturnNoInvoice', $vars);
    }

    public function scaleList() {
        $vars['pageName'] = 'scale';
        $vars['title'] = inventoryModel::getmsg('scale');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['scale_types'] = CommonFunctions::get_scale_types();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('scale'), 'scaleList']];
        $this->load->view('Inventory/scaleList', $vars);
    }

    public function scaleKeys() {
        $vars['pageName'] = 'scaleKeys';
        $vars['title'] = inventoryModel::getmsg('scale');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['keys'] = $this->_registry->Product->getKeysProducts(1);
        $vars['scales'] = CommonFunctions::CommonView('tbl_scale');
        //        die(print_r($vars['scales']));
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('scale'), 'scaleKeys']];
        $this->load->view('Inventory/scaleKeys', $vars);
    }

    public function skipKeys() {
        $vars['pageName'] = 'skipkeys';
        $vars['title'] = inventoryModel::getmsg('skip_keys');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['keys'] = $this->_registry->Product->getKeysProducts(1);
        $vars['scales'] = CommonFunctions::CommonView('tbl_scale');
        $vars['categories'] = CommonFunctions::CommonView('tbl_product_cat');
        //        die(print_r($vars['scales']));
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('skip_keys'), 'skipKeys']];
        $this->load->view('Inventory/skipKeys', $vars);
    }

    public function pos_view_invoice() {
        //$vars['pageName'] = 'scaleKeys';
        $vars['title'] = inventoryModel::getmsg('admin');
        $vars['system_name'] = inventoryModel::getmsg('admin');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];
        
        preg_match("/\/table/", $_SERVER['REQUEST_URI'], $is_order_table);
        $vars['is_order_table'] = count($is_order_table) > 0 ? '' : 'hidden';

        
        $data_arr = $this->_registry->invoice->getInvoiceToPrint($vars['id']);
        //echo"<pre>";print_r($data_arr);die;
        $hide_qr='';
        $getOrganizationDetails= $this->_registry->organization->getOrganizationDetails()[0];
            if(strlen($getOrganizationDetails['Organization_vat_num']) < 3)
                $data_arr['main']['hidden_Organization_vat_num'] = 'hidden';

        $data_arr['main']= array_merge($data_arr['main'],$getOrganizationDetails);
        if(smc_session()['default_setting']['enable_sales_invoice_qr_code'] == 1){
        // $qr_string ='%0A Seller Name: '.$data_arr['main']['Organization_Name'].'%0A Vat Number: '.$data_arr['main']['Organization_vat_num'].'%0A Invoice  '.$data_arr['main']['invoice_prefix'].$data_arr['main']['Invoice_ID'].'%0A Invoice Date: '.$data_arr['main']['date_time'].'%0A Total VAT: '.$data_arr['main']['vat1_total'].' '.$data_arr['main']['Currency_Symbol'].'%0A Invoice Total: '.$data_arr['main']['Invoice_Net_Total'].' '.$data_arr['main']['Currency_Symbol']; 
        $data_tlv= $this->einv_generate_tlv_qr_code(array($data_arr['main']['organiaztion_name_en'],$data_arr['main']['org_vat_en'],str_replace(' ','T',$data_arr['main']['date_created']),str_replace(',','',$data_arr['main']['Invoice_Net_Total']),$data_arr['main']['vat1_total']));

        $data_arr['main']['qrcode'] = SITE_LINK . 'common_controller/GenerateQRCode?code=' . $data_tlv;
        }else{
            $hide_qr='hidden';
        }
        if($data_arr['main']['Invoice_Paid_Amount'] == 0){
            $data_arr['main']['returned_cash'] = 0;
        }

        $data_arr['main']['lebanon_vat'] = $data_arr['main']['Invoice_VAT'];
        $data_arr['main']['hide_lebanon_vat'] = 'hidden';
        $data_arr['main']['hide_usd_vat'] = 'hidden';
        if($data_arr['main']['Currency_Code'] == 'USD' ){
            $data_arr['main']['lebanon_vat'] = CommonFunctions::formatNumber( ((float)$data_arr['main']['Invoice_VAT']) * smc_session()['default_setting']['lebanon_vat_amount']);
            $data_arr['main']['hide_usd_vat'] = '';
        }else{
            $data_arr['main']['hide_lebanon_vat'] = '';
        }
        $data_arr['main']['lebanon_vat_rate'] = smc_session()['default_setting']['lebanon_vat_amount'];
        $exchange_rate_first_sec_arr = CurrencyFactory::returnExchangeRate(smc_session()['local_currency'],smc_session()['second_currency']['id']);
        $exchange_rate_first_sec = $exchange_rate_first_sec_arr[1] == '*' ? $exchange_rate_first_sec_arr[0] : (1 / $exchange_rate_first_sec_arr[0]);

        $exchange_rate_sec_first_arr = CurrencyFactory::returnExchangeRate(smc_session()['second_currency']['id'],smc_session()['local_currency']);
        $exchange_rate_sec_first = $exchange_rate_sec_first_arr[1] == '*' ? $exchange_rate_sec_first_arr[0] : (1 / $exchange_rate_sec_first_arr[0]);
        $data_arr['main']['local_currency_rate'] = $exchange_rate_first_sec;
        $data_arr['main']['second_currency_rate'] = $exchange_rate_sec_first;

        $data_arr['main']['lebanon_vat_rate'] = smc_session()['default_setting']['lebanon_vat_amount'];

        if($data_arr['main']['Currency_Code'] == smc_session()['local_currency_code']){
            $data_arr['main']['total_second_currency_grand'] = CommonFunctions::formatNumber($data_arr['main']['grand_total_no_format'] * $data_arr['main']['local_currency_rate']).' ' .smc_session()['second_currency']['symbol'];
        }else{
            $data_arr['main']['total_second_currency_grand'] = CommonFunctions::formatNumber($data_arr['main']['grand_total_no_format'] * $data_arr['main']['second_currency_rate']).' ' .smc_session()['default_currency']['Currency_Symbol']; ;

        }

          //echo"<pre>";print_r($data_arr);die;//returned_cash

        
        $data_arr['main']['is_order_table'] = $vars['is_order_table'];
        
        $data_arr['main']['print_date'] =date("Y-m-d h:i:sa");
        $data_arr['main']['hide_qr']=$hide_qr;
        $data_arr['main']['type_preview'] = !empty($_GET['type_preview']) ? '' : 'window.print()';
        $data_arr['main']['smc__print_time'] = date('Y-m-d H:i:s');
        $data_arr['main']['smc__print_username'] = empty(smc_session()['user_logged_username']) ? '' : smc_session()['user_logged_username'];
        $data_arr['main']['smc__print_userfullname'] = empty(smc_session()['user_logged_full_name']) ? '' : smc_session()['user_logged_full_name'];
        $data_arr['main']['smc__theme_path'] = THEME_PATH;
        $data_arr['main']['smc__upload_path'] = str_replace(dirBase, '', upload_path);
        $data_arr['main']['smc__upload_url'] = upload_url;
        $data_arr['main']['smc__site_link'] = SITE_LINK;
        $data_arr['main']['smc__logo_url'] = SITE_LINK . 'img/logo_white.png';
        $data_arr['main']['smc__system_vat_percent'] = smc_session()['vat_percent'];
        $data_arr['main']['smc__local_currency_symbol'] = smc_session()['local_currency_symbol'];

        $data_arr['main']['rate_second_currency2'] = CurrencyFactory::getLastExRate(smc_session()['second_currency']['id']);
        $data_arr['main']['rate_second_currency'] = CurrencyFactory::getSecondCurrencyLastExRate(smc_session()['local_currency']);
        //echo"<pre>";print_r($data_arr);die;//returned_cash

        if($data_arr['main']['cash_amount'] == 0)
            $data_arr['main']['returned_cash']  = 0;

        if (empty($_GET['is_posponed']))
            $print_template = $data_arr['main']['is_actual'] ? ['act_pos_invoice', 'pos_invoice'] : 'pos_invoice';
        else
            $print_template = $data_arr['main']['is_actual'] ? ['act_postponed_invoice', 'postponed_invoice', 'act_pos_invoice', 'pos_invoice'] : ['postponed_invoice', 'pos_invoice'];

        //$print_template = empty($_GET['is_posponed']) ? 'pos_invoice' : ['postponed_invoice', 'pos_invoice'];
        $template_row = Forms::build_print_template($print_template, $data_arr['main'], array('inv_detail' => $data_arr['Details'], 'inv_detail_linked' => $data_arr['DetailsLinked']
                    , 'disc' => $data_arr['disc_items'], 'disc_linked' => $data_arr['disc_items_linked']
                    , 'no_disc' => $data_arr['no_disc_items'], 'no_disc_linked' => $data_arr['no_disc_items_linked']));
        //$this->load->view_html($html, $vars);
        // echo "<pre>"; die(print_r($data_arr));
        if (smc_session()['default_setting']['sumatra_print'] == 1 && !empty($data_arr['main']['type_preview'])) {
            $print_w_h = Forms::get_print_width_height('pos');
            $filename = Forms::html2pdf($template_row['html'], $print_w_h);
            Forms::real_print(null, $filename, ['repeat' => $template_row['copies']]);
        } else {
            echo $template_row['html'];
        }
        exit;
        //$vars['data'] = $this->_registry->invoicepos->getPOSInvoices($vars['id']);
        //$vars['breadCrumb'] = [[inventoryModel::getmsg('admin'), 'Adminstration'], [inventoryModel::getmsg('floor_setting'), 'pos_view_invoice']];
        //$this->load->view('POS/pos_view_invoice', $vars, true);
    }
        public function print_paid_amount() {
        $vars['pageName'] = 'print_paid_amount';
        $vars['title'] = inventoryModel::getmsg('inventory_sys');
        $getID = explode('/', $_SERVER['REQUEST_URI']);
        $url = explode('/', $_GET['url']);

        $Invoice_ID = $url[count($url) - 1];
        $data = $this->_registry->invoice->getInvoiceToPrint($Invoice_ID);
        //echo "<pre>";die(print_r($data));
        $template_key = 'paid_amount';
        $template_row = Forms::build_print_template($template_key, $data['main'], array('inv_detail' => $data['Details']));
        echo $template_row['html'];
        echo '<script src="' . SITE_LINK . '/Theme/plugins/jquery/jquery-2.1.1.js" type="text/javascript"></script>';
        //        $this->load->view_html($template_row['html'], $vars);
        exit;
    }

    public function view_user_invoices() {
        //        $vars['pageName'] = 'scaleKeys';
        //        $vars['title'] = inventoryModel::getmsg('admin');
        //        $vars['system_name'] = inventoryModel::getmsg('admin');
        $current_user = '';
        $current_class = '';
        $current_class_id = $_POST['class_id'];
        if (!empty($_POST['user']))
            $current_user = CommonFunctions::SpecificAttribute('tbl_common_users', ['User_ID'], [$_POST['user']], 'User_Name');
        if (!empty($_POST['class_id']))
            $current_class = CommonFunctions::SpecificAttribute('tbl_pricing_class', ['Class_ID'], [$_POST['class_id']], 'Class_Name');
        $from_to_date = explode(" - ", $_POST['From_To_Date']);
        $_POST['From_Date'] = $from_to_date[0];
        $_POST['To_Date'] = $from_to_date[1];

        $vars['data_filter'] = ['from_date' => $_POST['From_Date'], 'to_date' => $_POST['To_Date'],
            'class' => $current_class, 'user' => $current_user];
        $vars['data'] = $this->_registry->invoice->setData($_POST)->getUserInvoices();
        $vars['totals'] = $this->_registry->invoice->totalUserInvoices($_POST['From_Date'], $_POST['To_Date'], $_POST['user'], $_POST['salesman'], 0);
        $this->load->view('Inventory/view_user_invoices', $vars, true);
    }

    public function view_total_sold_items() {
        $current_user = $customer_name = '';
        //        echo"<pre>";print_r($_POST);
        $from_to_date = explode(" - ", $_POST['From_To_Date']);
        $From_To_Date_invoice = explode(" - ", $_POST['From_To_Date_invoice']);
        $_POST['From_Date'] = !empty($_POST['From_To_Date']) ? $from_to_date[0] : '';
        $_POST['To_Date'] = !empty($_POST['From_To_Date']) ? $from_to_date[1] : '';
        $_POST['From_Date_invoice'] = $From_To_Date_invoice[0];
        $_POST['To_Date_invoice'] = $From_To_Date_invoice[1];
        $_POST['return'] = !empty($_POST['with_return']) ? 1 : 0;
        $_POST['users'] = !empty($_POST['users']) ? $_POST['users'] : '';
        $_POST['customer_id'] = is_numeric($_POST['customer_id']) ? $_POST['customer_id'] : '';
        $_POST['branch_id'] = is_numeric($_POST['branch_id']) ? $_POST['branch_id'] : '';

        if (!empty($_POST['customer_id'])) {
            $customer_name = $_POST['customer_name'];
        }
        if (!empty($_POST['users'])) {
            $current_user = $this->_registry->user->setData($_POST)->getUserNames();
        }
        $vars['data'] = $this->_registry->invoice->setData($_POST)->getTotalSoldItems();

        //        echo"<pre>";        print_r($vars['data']);exit;
        $vars['totals'] = $this->_registry->invoice->get_total_sold_items_totals($_POST['return'], $_POST['From_Date'], $_POST['To_Date'], $_POST['users'], 0, $_POST['customer_id'], $_POST['is_day'], $_POST['From_Date_invoice'], $_POST['To_Date_invoice'], $_POST['branch_id'], $_POST['category_filter'], $_POST['sales_man_id']);
        $vars['data_filter'] = ['fromToDate' => $_POST['From_To_Date'], 'fromToDateinvoice' => $_POST['From_To_Date_invoice'],
            'users' => $current_user, 'return' => $_POST['return'], 'customer_name' => $customer_name, 'is_day' => $_POST['is_day']];
        //  echo"<pre>";        print_r($vars['data_filter']);exit;
        $this->load->view('Inventory/view_total_sold_items', $vars, true);
    }

    public function pos_view_payment() {
        $vars['title'] = inventoryModel::getmsg('admin');
        $vars['system_name'] = inventoryModel::getmsg('admin');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];
        $vars['data'] = $this->_registry->payment->getPaymentToPrint($vars['id']);
        //        echo"<pre>";
        //         die(print_r($vars['data']));
        if ($vars['data']['IsReceipt'] == 1)
            $temp_name = $vars['data']['Status_ID'] ? ['act_pos_receipt', 'pos_receipt', 'act_pos_payment', 'pos_payment'] : ['pos_receipt', 'pos_payment'];
        else
            $temp_name = $vars['data']['Status_ID'] ? ['act_pos_payment', 'pos_payment', 'act_pos_receipt', 'pos_receipt'] : ['pos_payment', 'pos_receipt'];

        $template_row = Forms::build_print_template($temp_name, $vars['data']);
        //        $this->load->view_html($html, $vars);
        if (smc_session()['default_setting']['sumatra_print'] == 1) {
            $print_w_h = Forms::get_print_width_height('pos');
            $filename = Forms::html2pdf($template_row['html'], $print_w_h);
            Forms::real_print(null, $filename, ['repeat' => $template_row['copies']]);
        } else
            echo $template_row['html'];
        exit;
        //                die(print_r($vars['data']));
        //        $paymentdetails = $this->_registry->payment->view(0, $maxpayment);
        //        $vars['breadCrumb'] = [[inventoryModel::getmsg('admin'), 'Adminstration'], [inventoryModel::getmsg('floor_setting'), 'pos_view_invoice']];
        //        $this->load->view('POS/pos_view_payment', $vars, true);
    }

    public function pos_view_expense() {
        $vars['title'] = inventoryModel::getmsg('admin');
        $vars['system_name'] = inventoryModel::getmsg('admin');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];
        $vars['data'] = $this->_registry->expenses->getExpenseToPrint($vars['id']);
        //        echo "<pre>";print_r($vars['data']);exit;
        $vars['data']['main']['paid_amount'] = $vars['data']['details'][0]['paid_amount'];
        $vars['data']['main']['Account_Code'] = $vars['data']['details'][0]['Account_Code'];
        $vars['data']['main']['Account_Name'] = $vars['data']['details'][0]['Account_Name'];
        $temp_name = $vars['data']['main']['Is_Hidden'] ? ['act_pos_expense', 'pos_expense'] : 'pos_expense';

        $template_row = Forms::build_print_template($temp_name, $vars['data']['main']);
        if (smc_session()['default_setting']['sumatra_print'] == 1) {
            $print_w_h = Forms::get_print_width_height('pos');
            $filename = Forms::html2pdf($template_row['html'], $print_w_h);
            Forms::real_print(null, $filename, ['repeat' => $template_row['copies']]);
        } else
            echo $template_row['html'];
        exit;
        //                die(print_r($vars['data']));
        //        $paymentdetails = $this->_registry->payment->view(0, $maxpayment);
        //        $vars['breadCrumb'] = [[inventoryModel::getmsg('admin'), 'Adminstration'], [inventoryModel::getmsg('floor_setting'), 'pos_view_invoice']];
        //        $this->load->view('POS/pos_view_payment', $vars, true);
    }

    public function pos_view_deposit() {
        $vars['title'] = inventoryModel::getmsg('admin');
        $vars['system_name'] = inventoryModel::getmsg('admin');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];
        $data = CommonFunctions::CommonView('tbl_accounting_bank_deposit_withdrawal', ['Deposit_WithDrawal_ID'], [$vars['id']])[0];
        $data['deposite_account_name'] = CommonFunctions::SpecificAttribute('tbl_chart_of_accounts', ['Account_ID'], [$data['To_Account_ID']], 'Account_Name');
        $symbol = CurrencyFactory::getCurrencySymbol($data['Currency_From']);
        $arr = ["title" => CommonLanguage::getMessage('deposit'),
            "deposite_account" => $data['deposite_account_name'],
            "deposite_amount" => $data['Deposit_WithDrawal_Amount'], "Currency_Symbol" => $symbol];
        $temp_name = $data['Is_Hidden'] ? ['act_pos_deposite', 'pos_deposite'] : 'pos_deposite';

        $template_row = Forms::build_print_template($temp_name, $arr);
        //        $this->load->view_html($html, $vars);
        if (smc_session()['default_setting']['sumatra_print'] == 1) {
            $print_w_h = Forms::get_print_width_height('pos');
            $filename = Forms::html2pdf($template_row['html'], $print_w_h);
            Forms::real_print(null, $filename, ['repeat' => $template_row['copies']]);
        } else
            echo $template_row['html'];
        exit;
        //        $this->load->view('POS/pos_view_deposit', $vars, true);
    }

    public function pos_view_withdrawal() {
        $vars['title'] = inventoryModel::getmsg('admin');
        $vars['system_name'] = inventoryModel::getmsg('admin');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];
        $data = CommonFunctions::CommonView('tbl_accounting_bank_deposit_withdrawal', ['Deposit_WithDrawal_ID'], [$vars['id']])[0];
        $data['withdrawal_account_name'] = CommonFunctions::SpecificAttribute('tbl_chart_of_accounts', ['Account_ID'], [$data['From_Account_ID']], 'Account_Name');
        $symbol = CurrencyFactory::getCurrencySymbol($data['Currency_From']);
        $arr = ["title" => CommonLanguage::getMessage('withdrawal'), "withdrawal_account" => $data['withdrawal_account_name'], "withdrawal_amount" => $data['Deposit_WithDrawal_Amount'], "Currency_Symbol" => $symbol];
        $temp_name = $data['Is_Hidden'] ? ['act_pos_withdrawal', 'pos_withdrawal'] : 'pos_withdrawal';

        $template_row = Forms::build_print_template($temp_name, $arr);
        //        $this->load->view_html($html, $vars);
        if (smc_session()['default_setting']['sumatra_print'] == 1) {
            $print_w_h = Forms::get_print_width_height('pos');
            $filename = Forms::html2pdf($template_row['html'], $print_w_h);
            Forms::real_print(null, $filename, ['repeat' => $template_row['copies']]);
        } else
            echo $template_row['html'];
        exit;
        //        $this->load->view('POS/pos_view_withdrawal', $vars, true);
    }

    public function pos_view_return() {
        $vars['title'] = inventoryModel::getmsg('admin');
        $vars['system_name'] = inventoryModel::getmsg('admin');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];
        $vars['ReturnItem'] = $this->_registry->return->getReturnByID($vars['id']);
        

        $Supp_ID = $vars['data']['Main']['Person_ID'];
        $vars['From_Details'] = $this->_registry->customer->ViewAllCustomerDetails($Supp_ID);
        $vars['CurrName'] = $this->_registry->Currency->getCurrencyNameByID($vars['ReturnItem']['Main']['Currency_ID']);
        $vars['pageName'] = $vars['ReturnItem']['Main']['Is_Actual'] == 1 ? ($vars['IsVendor'] ? 'ViewReturnDebitActual' : 'ViewReturnCreditActual') : ($vars['IsVendor'] ? 'ViewReturnDebit' : 'ViewReturnCredit');
        $template_id = !empty($_GET['template_id']) ? $_GET['template_id'] : '';
            $Supp_ID = $vars['ReturnItem']['Main']['Person_ID'];
            $vars['From_Details'] = $vars['IsVendor'] ? $this->_registry->vendor->ViewAllDetails($Supp_ID) : $this->_registry->customer->ViewAllCustomerDetails($Supp_ID);
            $vars['ReturnItem']['Main']['vat_percent'] = smc_session()['vat_percent'];
            $vars['ReturnItem']['Main']['Country_Name'] = $vars['From_Details'][0]['Country_Name'];
            $vars['ReturnItem']['Main']['return_title'] = 'Return ' . ($vars['IsVendor'] ? 'Purchase' : 'Invoice');
            $vars['ReturnItem']['Main']['is_purchase'] = ($vars['IsVendor'] ? 'Purchase' : 'hidden');
            $vars['ReturnItem']['Main']['is_sales'] = ($vars['IsVendor'] ? 'hidden' : 'Invoice');
            $vars['ReturnItem']['Main']['cust_supp_mobile'] = $vars['From_Details'][0][$vars['IsVendor'] ? "Supplier_Mobile" : "Customer_Mobile"];
            $vars['ReturnItem']['Main']['Name'] = $vars['From_Details'][0]["Name"];
            $vars['ReturnItem']['Main']['cust_supp_name'] = $vars['From_Details'][0][$vars['IsVendor'] ? "Supplier_Name" : "Customer_Name"];
            $vars['ReturnItem']['Main']['cust_supp_address'] = $vars['From_Details'][0][$vars['IsVendor'] ? "Supplier_Address" : "Customer_Address"];
            $vars['ReturnItem']['Main']['CR'] = $vars['From_Details'][0]["CR"];
            $vars['ReturnItem']['Main']['customer_vat'] = $vars['From_Details'][0]["customer_vat"];
            $vars['ReturnItem']['Main']['Account_Code'] = $vars['From_Details'][0]["Account_Code"];
            if(smc_session()['default_setting']['enable_sales_invoice_qr_code'] == 1 ){
                        $getOrganizationDetails= $this->_registry->organization->getOrganizationDetails()[0];
 
                 $data_tlv= $this->einv_generate_tlv_qr_code(array($getOrganizationDetails['organiaztion_name_en'],$getOrganizationDetails['org_vat_en'],str_replace(' ','T',$vars['ReturnItem']['Main']['date_created']),str_replace(',','',$vars['ReturnItem']['Main']['net']),$vars['ReturnItem']['Main']['Invoice_VAT']));
                $vars['ReturnItem']['Main']['qrcode'] = SITE_LINK . 'common_controller/GenerateQRCode?code=' . $data_tlv;
            }

                //echo "<pre>"; die(print_r($vars));

                //$this->load->view('POS/pos_view_return', $vars, true);
        $temp_name = $vars['data']['main_invoice']['Is_Actual'] ? ['act_pos_return', 'pos_return'] : 'pos_return';

        $template_row = Forms::build_print_template($temp_name, $vars['ReturnItem']['Main'], array('return_detail' => $vars['ReturnItem']['Details']));
        if (smc_session()['default_setting']['sumatra_print'] == 1) {
            $print_w_h = Forms::get_print_width_height('pos');
            $filename = Forms::html2pdf($template_row['html'], $print_w_h);
            Forms::real_print(null, $filename, ['repeat' => $template_row['copies']]);
        } else
            echo $template_row['html'];
        exit;
    }

    public function UserInvoices() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'act_user_invoices' : 'user_invoices';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_user_invoices' : 'user_invoices');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['users'] = CommonFunctions::CommonView('tbl_common_users');
        $vars['shipping_company'] = CommonFunctions::CommonView('tbl_shipping_company');
        $vars['shipping_status'] = CommonFunctions::CommonView('tbl_shipping_status');
        $vars['current_today'] = date("Y-m-d h:i:s a");
        $vars['local_currency_symbol'] = CurrencyFactory::getLocalCurrencySymbol();
        //        $vars['totals'] = $this->_registry->invoice->totalUserInvoices(smc_session()['user_details']['User_ID'],)
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_user_invoices' : 'user_invoices'), 'UserInvoices' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/UserInvoices', $vars);
    }

    public function UserCustomersList() {
        $vars['pageName'] = 'UserCustomersList';
        $vars['title'] = inventoryModel::getmsg('inventory');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['users'] = CommonFunctions::CommonView('tbl_common_users');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('user_customer_list'), 'UserCustomersList']];
        $this->load->view('Inventory/UserCustomersList', $vars);
    }

    public function salesConsolidateByUser() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'sales_consolidate_by_user_actual' : 'salesConsolidateByUser';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_sales_consolidate' : 'sales_consolidate');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['users'] = CommonFunctions::CommonView('tbl_common_users');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_sales_consolidate' : 'sales_consolidate'), 'salesConsolidateByUser' . ($vars['is_actual'] ? '/act' : '')]];
        $vars['today'] = Date::getToday();
        $this->load->view('Inventory/salesConsolidateByUser', $vars);
    }

    public function dailyActivityByUser() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'daily_activity_by_user_actual' : 'dailyActivityByUser';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_daily_activity_user' : 'daily_activity_user');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['users'] = CommonFunctions::CommonView('tbl_common_users');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_daily_activity_user' : 'daily_activity_user'), 'dailyActivityByUser' . ($vars['is_actual'] ? '/act' : '')]];
        $vars['today'] = Date::getToday();
        $this->load->view('Inventory/dailyActivityByUser', $vars);
    }

    public function invoiceDistByCustomer() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'invoice_dist_by_customer_actual' : 'invoiceDistByCustomer';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_customer_inv_dist' : 'customer_inv_dist');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_customer_inv_dist' : 'customer_inv_dist'), 'invoiceDistByCustomer' . ($vars['is_actual'] ? '/act' : '')]];
        $vars['today'] = Date::getToday();
        $this->load->view('Inventory/invoiceDistByCustomer', $vars);
    }

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

    public function sales_purchase_list() {
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        preg_match("/\/return\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['is_return'] = count($match) > 0 ? true : false;
        $vars['pageName'] = $vars['is_return'] ? 'sales_purchase_return_list' : 'sales_purchase_list';
        $vars['title'] = inventoryModel::getmsg($vars['is_return'] ? 'sales_purchase_return_list' : 'sales_purchase_list');
        $today = Date::gettoday();
        $vars['year'] = date("Y", strtotime($today)); // get the year from today
        $vars['month'] = date("m", strtotime($today)); // get the month from today
        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10)); // get Month Name
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_return'] ? 'sales_purchase_return_list' : 'sales_purchase_list'), 'sales_purchase_list' . ($vars['is_return'] ? '/return' : '')]];
        $this->load->view('Inventory/sales_purchase_list', $vars);
    }

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

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

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

    public function pos_view_end_shift() {
        $vars['pageName'] = 'print_end_shift';
        $vars['title'] = inventoryModel::getmsg('admin');
        $vars['system_name'] = inventoryModel::getmsg('admin');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];
        $shift_row = $this->_registry->invoicepos->get_end_of_shift_by_id($vars['id']);
        //
        $vars['is_actual'] = empty($_GET['is_actual']) ? 0 : $_GET['is_actual'];
        $vars['current_date_from'] = $shift_row['open_time'];
        $vars['current_date_to'] = $shift_row['close_time'];
        $vars['tmp_currency_id'] = $shift_row['Currency_ID'];
        //
        $vars['type_preview'] = 'window.print()';
        $users = [['User_ID' => $shift_row['user_id'], 'User_Name' => '', 'cash_account_id' => $shift_row['account_id']]];
        $vars['tmp_users_arr'] = $users;
        //
        $template_row = $this->end_of_shift_day_fill_template($vars, false);
        //
        //        if (smc_session()['default_setting']['sumatra_print'] == 1) {
        //            $print_w_h = Forms::get_print_width_height('pos');
        //            $filename = Forms::html2pdf($template_row['html'], $print_w_h);
        //            Forms::real_print(null, $filename, ['repeat' => $template_row['copies']]);
        //        } else
        echo $template_row['html'];
        exit;
        //        $this->load->view('POS/pos_view_end_shift', $vars, true);
    }

    public function pos_view_end_day() {
        $vars['pageName'] = 'print_end_shift';
        $vars['title'] = inventoryModel::getmsg('admin');
        $vars['system_name'] = inventoryModel::getmsg('admin');
        //
        if (isset($_GET['end_of_day_range'])) {
            $vars['current_date'] = explode(" - ", $_GET['end_of_day_range']);
            if (!empty($_GET['is_date_checked'])) {
                $vars['current_date_from'] = $vars['current_date'][0];
                $vars['current_date_to'] = $vars['current_date'][1];
            } else {
                $vars['current_date_from'] = $this->_registry->invoicepos->get_open_shift_time(null, 1);
                $vars['current_date_to'] = date('Y-m-d H:i:s');
            }
            $vars['tmp_currency_id'] = null;
            $vars['is_actual'] = $_GET['is_actual'];
        } elseif (isset($_GET['shift_id'])) {
            $data = $this->_registry->invoicepos->get_end_of_shift_by_id($_GET['shift_id']);
            $vars['current_date_from'] = $data['open_time'];
            $vars['current_date_to'] = $data['close_time'];
            $vars['tmp_currency_id'] = null;
            $vars['is_actual'] = $data['is_actual'];
            $_GET['branch_id'] = !empty($data['app_branch_id']) ? $data['app_branch_id'] : $data['branch_id'];
        }
        //echo "<pre>";die(print_r($vars));
        $vars['per_day_print'] = isset($_GET['per_day_print']) ? $_GET['per_day_print'] : 0;
        $vars['type_preview'] = !empty($_GET['type_preview']) && $_GET['type_preview'] == 1 ? '' : 'window.print()';
        //
        $users = array();
        $ttl_usrs = ['User_ID' => 0, 'User_Name' => 'Total Users', 'cash_account_id' => null];
        if (isset($_GET['with_user']) && $_GET['with_user'] == 0)
            $users = [$ttl_usrs];
        else {
            $users = User::get_users_with_acc();
            $users[] = $ttl_usrs;
        }
        $vars['tmp_users_arr'] = $users;
        //

        $template_row = $this->end_of_shift_day_fill_template($vars, true);

        if (smc_session()['default_setting']['activate_end_of_day_sumatra'] == 1 && $_GET['type_preview'] == 2) {
            $print_w_h = Forms::get_print_width_height('pos');
            $filename = Forms::html2pdf($template_row['html'], $print_w_h);
            Forms::real_print(null, $filename, ['repeat' => $template_row['copies']]);
        } else
            echo $template_row['html'];
        exit;
        //$this->load->view('POS/pos_view_end_shift', $vars, true);
    }
    public function end_of_shift_day_fill_template($vars, $is_end_day) {
        if ($is_end_day)
            $vars['template_title'] = !empty($_GET['template_title']) ? $_GET['template_title'] : '';
        else
            $vars['template_title'] = CommonLanguage::getMessage('end_shift_report');
        $vars['end_of_shif_class'] = ($is_end_day ? 'hidden' : '');
        $vars['end_of_day_class'] = ($is_end_day ? '' : 'hidden');
        $vars['category_data'] = $vars['total_sold_items_data'] = $vars['total_credit'] = array();
        //
        $date_arrays = array(array('current_date_from' => $vars['current_date_from'], 'current_date_to' => $vars['current_date_to']));
        if (!empty($vars['per_day_print'])) {
            $start_date_time = explode(" ", $vars['current_date_from']);
            $end_date_time = explode(" ", $vars['current_date_to']);
            $period = new DatePeriod(new DateTime($start_date_time[0]), new DateInterval('P1D'), new DateTime($end_date_time[0] . ' +1 day'));
            $tmp_period_arr = array();
            foreach ($period as $value)
                $tmp_period_arr [] = $value->format('Y-m-d');
            if (count($tmp_period_arr) > 1) {
                $date_arrays = array();
                foreach ($tmp_period_arr as $key => $tmp_date) {
                    if (!isset($tmp_period_arr[$key + 1]))
                        break;
                    $date_arrays[] = ['current_date_from' => $tmp_date . ' ' . $start_date_time[1],
                        'current_date_to' => $tmp_period_arr[$key + 1] . ' ' . $end_date_time[1]];
                }
            }
        }
        //
        if ($is_end_day)
            $print_template = $vars['is_actual'] ? ['act_end_of_day', 'end_of_day'] : 'end_of_day';
        else
            $print_template = $vars['is_actual'] ? ['act_end_of_shift', 'end_of_shift', 'act_end_of_day', 'end_of_day'] : ['end_of_shift', 'end_of_day'];
        $_GET['branch_id'] = empty($_GET['branch_id']) ? NULL : $_GET['branch_id'];
        //$print_template = array('end_of_shift', 'end_of_day');
        //
        $dates_data = array();
        foreach ($date_arrays as $date_row) {
            $users_data = array();
            $crnt_vars = $vars;
            $crnt_vars['current_date_from'] = $date_row['current_date_from'];
            $crnt_vars['current_date_to'] = $date_row['current_date_to'];
            //
            foreach ($vars['tmp_users_arr'] as $user) {
                $current_data = $this->_registry->invoicepos->setData($_GET)->get_end_of_shift_balances($date_row['current_date_from'], $date_row['current_date_to'], $vars['tmp_currency_id'], $user['User_ID'], $user['cash_account_id'], $vars['is_actual']);
                $users_data[$user['User_ID']]['user_name'] = empty($user['User_Name']) ? $current_data['username'] : $user['User_Name'];
                //
                foreach ($current_data as $indx => $val) {
                    if (!is_array($val))
                        $users_data[$user['User_ID']][$indx] = $val;
                    else {
                        if ($indx == 'total_count' || $indx == 'total_amounts') {
                            $prfx = ($indx == 'total_amounts' ? 'amounts__' : 'count__');
                            foreach ($val as $indx2 => $val2) {
                                if (is_numeric($val2))
                                    $val2 = CommonFunctions::formatNumber($val2);
                                $users_data[$user['User_ID']][$prfx . $indx2] = $val2;
                                $users_data[$user['User_ID']][$prfx . $indx2 . '_class'] = ($val2 == 0 ? 'hidden' : '');
                            }
                        } elseif ($indx == 'totals') {
                            foreach ($val as $indx2 => $val2) {
                                if (is_array($val2)) {
                                    $users_data[$user['User_ID']]['totals__' . $indx2 . '_amount'] = CommonFunctions::formatNumber($val2['amount']);
                                    $users_data[$user['User_ID']]['totals__' . $indx2 . '_amount_class'] = ($val2['amount'] == 0 ? 'hidden' : '');
                                    $users_data[$user['User_ID']]['totals__' . $indx2 . '_local_amount'] = CommonFunctions::formatNumber($val2['local_amount']);
                                    



                                    $users_data[$user['User_ID']]['totals__' . $indx2 . '_local_currency'] = CommonFunctions::formatNumber($val2['local_currency_amount']).' '.smc_session()['local_currency_symbol'];
                                    $users_data[$user['User_ID']]['totals__' . $indx2 . '_second_currency'] = CommonFunctions::formatNumber($val2['second_currency_amount']).' '. smc_session()['second_currency']['symbol'] ;
                                    $users_data[$user['User_ID']]['totals__' . $indx2 . '_cash_local_currency_amount'] = CommonFunctions::formatNumber($val2['cash_local_currency_amount']).' '.smc_session()['local_currency_symbol'];
                                    $users_data[$user['User_ID']]['totals__' . $indx2 . '_cash_second_currency_amount'] = CommonFunctions::formatNumber($val2['cash_second_currency_amount']).' '. smc_session()['second_currency']['symbol'] ;
                                    if ($indx2 == 'net_invoices') {
                                        $users_data[$user['User_ID']]['totals__' . $indx2 . '_total_check']  = CommonFunctions::formatNumber($this->_registry->invoicepos->setData($_GET)->getTotalCreditCashbyUser($date_row['current_date_from'], $date_row['current_date_to'],$user['User_ID'],'check')).' '.smc_session()['local_currency_symbol'];
                                        $users_data[$user['User_ID']]['totals__' . $indx2 . '_total_credit']  = CommonFunctions::formatNumber($this->_registry->invoicepos->setData($_GET)->getTotalCreditCashbyUser($date_row['current_date_from'], $date_row['current_date_to'],$user['User_ID'],'credit')).' '.smc_session()['local_currency_symbol'];
                                        $users_data[$user['User_ID']]['totals__' . $indx2 . '_total_other']  = CommonFunctions::formatNumber($this->_registry->invoicepos->setData($_GET)->getTotalCreditCashbyUser($date_row['current_date_from'], $date_row['current_date_to'],$user['User_ID'],'other')).' '.smc_session()['local_currency_symbol'];
                                        $users_data[$user['User_ID']]['totals__' . $indx2 . '_total_cash']  = CommonFunctions::formatNumber($this->_registry->invoicepos->setData($_GET)->getTotalCreditCashbyUser($date_row['current_date_from'], $date_row['current_date_to'],$user['User_ID'],'cash')).' '.smc_session()['local_currency_symbol'];

                                        $users_data[$user['User_ID']]['totals__' . $indx2 . '_from_invoice'] = $val2['from_invoice'];
                                        $users_data[$user['User_ID']]['totals__' . $indx2 . '_to_invoice'] = $val2['to_invoice'];
                                    
                                        $users_data[$user['User_ID']]['totals__' . $indx2 . '_unpaid_invoice'] = $this->_registry->invoice->setData(['From_Date' => $date_row['current_date_from'], 'To_Date' => $date_row['current_date_to'], 'unpaid_inv' => 1, 'branch_id' => $_GET['branch_id'], 'user' => $user['User_ID']])->getUserInvoicesTotal()['current_total'];
                                    }
                                }
                            }
                        }
                    }
                }
                $users_data[$user['User_ID']]['local_amount_col_class'] = smc_session()['local_currency'] != $current_data['currency_id'] ? '' : 'hidden';
                $users_data[$user['User_ID']]['deposite_col_span'] = smc_session()['local_currency'] != $current_data['currency_id'] ? 3 : 2;
                $users_data[$user['User_ID']]['user_name_class'] = ($current_data['is_user_with_data'] ? '' : 'hidden');
                 
            }
            // echo"<pre>";die(print_r($users_data)) ;
            $crnt_vars['with_invoice_view'] = 'hidden';
            $crnt_vars['data_inv'] = array();
            if (!empty($_GET['with_inv'])) {
                $crnt_vars['data_inv'] = $this->_registry->invoice->setData(['From_Date' => $date_row['current_date_from'], 'To_Date' => $date_row['current_date_to'], 'branch_id' => $_GET['branch_id']])->getUserInvoices();
                $crnt_vars['with_invoice_view'] = '';
            }
            $crnt_vars['with_unpaid_invoices_view'] = 'hidden';
            $crnt_vars['data_unpaid_inv'] = array();
            if (!empty($_GET['with_unpaid_invoices'])) {
                $crnt_vars['data_unpaid_inv'] = $this->_registry->invoice->setData(['From_Date' => $date_row['current_date_from'], 'To_Date' => $date_row['current_date_to'], 'unpaid_inv' => 1, 'branch_id' => $_GET['branch_id']])->getUserInvoices();
                $crnt_vars['with_unpaid_invoices_view'] = '';
            }
            $crnt_vars['category_view'] = 'hidden';
            $crnt_vars['category_data'] = array();
            if (!empty($_GET['with_category'])) {
                $crnt_vars['category_data'] = $this->_registry->invoicepos->setData($_GET)->getCategoryTotals($date_row['current_date_from'], $date_row['current_date_to'], $_GET['empty_category']);
                $crnt_vars['category_view'] = '';
            }
            $crnt_vars['with_sold_items_view'] = 'hidden';
            if (!empty($_GET['with_sold_items'])) {
                $crnt_vars['total_sold_items_data'] = $this->_registry->invoicepos->setData($_GET)->getTotalSoldItems($date_row['current_date_from'], $date_row['current_date_to'], true);
                $crnt_vars['sold_item_total_quantity'] = $crnt_vars['total_sold_items_data']['total_quantity'];
                $crnt_vars['sold_item_sub_total'] = $crnt_vars['total_sold_items_data']['sub_total'];
                $crnt_vars['sold_item_vat_total'] = $crnt_vars['total_sold_items_data']['vat_total'];
                $crnt_vars['sold_item_vat1_total'] = $crnt_vars['total_sold_items_data']['vat1_total'];
                $crnt_vars['sold_item_vat2_total'] = $crnt_vars['total_sold_items_data']['vat2_total'];
                $crnt_vars['sold_item_total'] = $crnt_vars['total_sold_items_data']['total'];
                $crnt_vars['with_sold_items_view'] = '';
            }
            $crnt_vars['with_void_items_view'] = 'hidden';
            if (!empty($_GET['with_void_items'])) {
                $crnt_vars['void_items_data'] = $this->_registry->invoicepos->setData($_GET)->getTotalVoidItems($date_row['current_date_from'], $date_row['current_date_to']);
                if (count($crnt_vars['void_items_data']) != 0)
                    $crnt_vars['with_void_items_view'] = '';
            }
            $crnt_vars['with_discounted_items_view'] = 'hidden';
            if (!empty($_GET['with_discounted_items'])) {
                $crnt_vars['discounted_items_data'] = $this->_registry->invoicepos->setData($_GET)->getTotalDiscountedItems($date_row['current_date_from'], $date_row['current_date_to']);
                if (count($crnt_vars['discounted_items_data']) != 0)
                    $crnt_vars['with_discounted_items_view'] = '';
            }
            //$crnt_vars['not_with_user_and_credit_view'] = (!empty($_GET['with_user']) || empty($crnt_vars['total_credit'])) ? 'hidden' : '';
            $crnt_vars['with_total_credits_view'] = 'hidden';
            if (!empty($_GET['with_total_credits'])) {
                $crnt_vars['total_credit'] = $this->_registry->invoicepos->setData($_GET)->getTotalCreditCash($date_row['current_date_from'], $date_row['current_date_to']);
                if (!empty($crnt_vars['total_credit'])) {
                    $crnt_vars['credit_total_credit'] = !empty($crnt_vars['total_credit']['total_credit']) ? CommonFunctions::formatNumber($crnt_vars['total_credit']['total_credit']) : 0;
                    $crnt_vars['credit_total_cash'] = !empty($crnt_vars['total_credit']['total_cash']) ? CommonFunctions::formatNumber($crnt_vars['total_credit']['total_cash']) : 0;
                    $crnt_vars['with_total_credits_view'] = '';
                }
            }
            $crnt_vars['with_inv_or_with_users_view'] = (empty($_GET['with_inv']) && empty($_GET['with_user'])) ? 'hidden' : '';
            $crnt_vars['totals'] = $this->_registry->invoice->setData(['branch_id' => $_GET['branch_id']])->totalUserInvoices($date_row['current_date_from'], $date_row['current_date_to']);
            $crnt_vars['totals_total'] = CommonFunctions::formatNumber($crnt_vars['totals']['total']);
            $crnt_vars['totals_total_cash'] = CommonFunctions::formatNumber($crnt_vars['totals']['total_cash']);
            $crnt_vars['totals_total_debit'] = CommonFunctions::formatNumber($crnt_vars['totals']['total'] - $crnt_vars['totals']['total_cash']);
            $crnt_vars['totals_discount'] = CommonFunctions::formatNumber($crnt_vars['totals']['discount']);
           //echo"<pre>";die(print_r($crnt_vars)) ;
            
            $crnt_vars = array_merge($crnt_vars, array('data_inv' => $crnt_vars['data_inv'], 'data_unpaid_inv' => $crnt_vars['data_unpaid_inv'],
                'category_data' => $crnt_vars['category_data'],
                'sold_items_data' => (empty($crnt_vars['total_sold_items_data']['items']) ? array() : $crnt_vars['total_sold_items_data']['items']),
                'users_data' => $users_data));
            $dates_data[] = $crnt_vars;
        }
        if (empty($vars['per_day_print'])) {
            $tmp_data = $dates_data[0];
            $tmp_data['smc__start_data_per_days'] = '';
            $tmp_data['smc__end_data_per_days'] = '';
            $template_row = Forms::build_print_template($print_template, $tmp_data, array(), true);
        } else  //here we send $vars as main for variables that outside loop like 'type_preview'
            $template_row = Forms::build_print_template($print_template, $vars, array('data_per_days' => $dates_data), true);
        //        $template_row = Forms::build_print_template($print_template, $vars, array(
        //                    'data_inv' => (empty($vars['data_inv']) ? array() : $vars['data_inv']),
        //                    'category_data' => (empty($vars['category_data']) ? array() : $vars['category_data']),
        //                    'sold_items_data' => (empty($vars['total_sold_items_data']['items']) ? array() : $vars['total_sold_items_data']['items']),
        //                    'users_data' => $users_data
        //                        ));
        //
        return $template_row;
    }

    public function end_of_shift_report() {
        $vars['pageName'] = 'end_of_shift_report';
        $vars['title'] = inventoryModel::getmsg('end_shift_report');
        $vars['system_name'] = inventoryModel::getmsg('end_shift_report');
        $vars['users'] = CommonFunctions::CommonView('tbl_common_users');
        $vars['current_today'] = date("Y-m-d h:i:s a");
        //$vars['totals'] = $this->_registry->invoice->totalUserInvoices(smc_session()['user_details']['User_ID'],)
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('end_shift_report'), 'end_of_shift_report']];
        $this->load->view('Inventory/end_of_shift_report', $vars);
    }

    public function TotalReturnItemsPerDate() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'act_total_sales_return_items' : 'total_sales_return_items';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_total_sales_return_items' : 'total_sales_return_items');
        $vars['system_name'] = inventoryModel::getmsg('invoice_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
        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10)); // get Month Name
        $vars['from_day'] = smc_session()['start_date']; //$vars['year'] . '-01-01';
        $vars['users'] = CommonFunctions::CommonView('tbl_common_users');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_total_sales_return_items' : 'total_sales_return_items'), 'TotalReturnItemsPerDate' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/TotalReturnItemsPerDate', $vars);
    }

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

    public function table_setting($id) {
        $vars['pageName'] = 'tables';
        $vars['title'] = inventoryModel::getmsg('tables');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['floor_id'] = $id;
        $vars['floor_name'] = CommonFunctions::SpecificAttribute('tbl_floor', 'floor_id', $id, 'floor_name');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('floor_setting'), 'floor_setting'], [$vars['floor_name'], 'table_setting/' . $id]];
        $this->load->view('Inventory/table_setting', $vars);
    }

    public function reason_list() {
        $vars['pageName'] = 'void_reason';
        $vars['title'] = inventoryModel::getmsg('void_reason');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('void_reason_list'), 'reason_list']];
        $this->load->view('Inventory/void-reason-list', $vars);
    }

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

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

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

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

    public function AddOns() {
        $vars['pageName'] = 'add_ons';
        $vars['title'] = inventoryModel::getmsg('add_ons');
        $vars['system_name'] = inventoryModel::getmsg('inventory_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('add_ons'), 'AddOns']];
        $this->load->view('Inventory/add-ons-list', $vars);
    }

    public function AddOnsDetailsList() {
        $vars['pageName'] = 'add_ons_details';
        $vars['title'] = inventoryModel::getmsg('add_ons_details');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['add_ons'] = CommonFunctions::CommonView('tbl_add_ons');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('add_ons_details'), 'AddOnsDetailsList']];
        $this->load->view('Inventory/add-ons-details-list', $vars);
    }

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

    public function stock_value_report() {
        $vars['pageName'] = 'currentStock';
        $vars['title'] = inventoryModel::getmsg('stock_value');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('stock_value'), 'stock_value_report']];
        $vars['methods'] = CommonFunctions::CommonView('tbl_stock_pricing_methods');
        $vars['classes'] = CommonFunctions::CommonView('tbl_pricing_class c join tbl_common_currency cu on cu.Currency_ID = c.Currency_ID');
        $vars['today'] = Date::getToday();
        $this->load->view('Inventory/stock_value_report', $vars);
    }

    public function pos_customer_invoices() {
        $vars['title'] = inventoryModel::getmsg('admin');
        $vars['system_name'] = inventoryModel::getmsg('admin');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];
        $data_arr = $this->_registry->invoicepos->get_customer_invoices($_GET['id'], $_GET['from_date'], $_GET['to_date'], 1, $_GET['pos_customer']);
        $details_arr = $data_arr['details'];
        unset($data_arr['details']);
        $template_row = Forms::build_print_template('pos_customer_invoices', $data_arr, array('inv_detail' => $details_arr));
        //        $this->load->view_html($html, $vars);
        if (smc_session()['default_setting']['sumatra_print'] == 1) {
            $print_w_h = Forms::get_print_width_height('pos');
            $filename = Forms::html2pdf($template_row['html'], $print_w_h);
            Forms::real_print(null, $filename, ['repeat' => $template_row['copies']]);
        } else {
            echo $template_row['html'];
        }
        //        
        //        $html = Forms::build_print_template('pos_customer_invoices', $data_arr, array('inv_detail' => $details_arr));
        //   
        //        if (smc_session()['default_setting']['sumatra_print'] == 1) {
        //            $filename = Forms::html2pdf($html, array('width' => 8, 'height' => 22));
        //            $this->_registry->invoicepos->real_print(null, $filename);
        //        } else {
        //            echo $html;
        //        }
        exit;
    }

    public function pos_customer_ledger() {
        $vars['title'] = inventoryModel::getmsg('admin');
        $vars['system_name'] = inventoryModel::getmsg('admin');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];
        $data_arr = $this->_registry->invoicepos->customer_ledger($_GET['id'], $_GET['from_date'], $_GET['to_date'], 1);
        $details_arr = $data_arr['details'];
        unset($data_arr['details']);
        // echo "<pre>";die(print_r($data_arr));
        $template_row = Forms::build_print_template('pos_customer_ledger', $data_arr, array('inv_detail' => $details_arr));
        //        $this->load->view_html($html, $vars);
        if (smc_session()['default_setting']['sumatra_print'] == 1) {
            $print_w_h = Forms::get_print_width_height('pos');
            $filename = Forms::html2pdf($template_row['html'], $print_w_h);
            Forms::real_print(null, $filename, ['repeat' => $template_row['copies']]);
        } else {
            echo $template_row['html'];
        }
        //        $template_row = Forms::build_print_template('pos_customer_ledger', $data_arr, array('inv_detail' => $details_arr));
        //   
        //        if (smc_session()['default_setting']['sumatra_print'] == 1) {
        //            $filename = Forms::html2pdf($template_row['html'], array('width' => 8, 'height' => 22));
        //            $this->_registry->invoicepos->real_print(null, $filename);
        //        } else {
        //            echo $template_row['html'];
        //        }
        exit;
    }

    public function pos_view_order() {
        $vars['title'] = inventoryModel::getmsg('admin');
        $vars['system_name'] = inventoryModel::getmsg('admin');
        preg_match("/\/order\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $is_order = count($match_act) > 0 ? 1 : 0;
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];
        if ($is_order == 1) {
            $data_arr = $this->_registry->purchase->getPurchaseOrderByID($vars['id']);
            $data_arr['main'] = $data_arr['Main'];
            $data_arr['main']['customer_data_hide'] = $data_arr['Main']['Person_ID'] == 0 ? 'hidden' : '';
            $data_arr['main']['printed_before_class'] = $data_arr['main']['persons_count_class'] = $data_arr['main']['table_class'] = $data_arr['main']['delivery_class'] = 'hidden';
            $data_arr['main']['note_class'] = !empty($data_arr['main']['Invoice_Description']) ? '' : 'hidden';
            $data_arr['main']['order_time'] = $data_arr['main']['date_time'];
            $data_arr['main']['Bon_Number'] = $data_arr['main']['Order_ID_Auto'];
        } else {
            $data_arr = $this->_registry->invoice->getInvoiceToPrint($vars['id']);
        }
        $data_arr['main']['pos_order_main'] = '';
        $data_arr['main']['pos_deleted_added_main'] = 'hidden';
        //        echo"<pre>";
        //        die(print_r($data_arr));
        $template_key = $data_arr['main']['is_actual'] ? ['act_pos_order', 'pos_order'] : 'pos_order';

        $template_row = Forms::build_print_template($template_key, $data_arr['main'], array('inv_detail' => $data_arr['Details'], 'inv_detail_linked' => $data_arr['Details']));
        //        $this->load->view_html($html, $vars);
        if (smc_session()['default_setting']['sumatra_print'] == 1) {
            $print_w_h = Forms::get_print_width_height('pos');
            $filename = Forms::html2pdf($template_row['html'], $print_w_h);
            Forms::real_print(null, $filename, ['repeat' => $template_row['copies']]);
        } else {
            echo $template_row['html'];
        }
        //        $html = Forms::build_print_template('pos_order', $data_arr['main'], array('inv_detail' => $data_arr['Details'], 'inv_detail' => $data_arr['Details']));
        //        //        $this->load->view_html($html, $vars);
        //        echo $html;
        exit;
        //        $vars['data'] = $this->_registry->invoicepos->getPOSInvoices($vars['id']);
        //        $vars['breadCrumb'] = [[inventoryModel::getmsg('admin'), 'Adminstration'], [inventoryModel::getmsg('floor_setting'), 'pos_view_invoice']];
        //        $this->load->view('POS/pos_view_invoice', $vars, true);
    }

    public function movement_control() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['pageName'] = $vars['is_actual'] ? 'movement_control_actual' : 'movement_control';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_movement_control' : 'movement_control');
        $today = Date::gettoday();
        $vars['year'] = date("Y", strtotime($today)); // get the year from today
        $vars['month'] = date("m", strtotime($today)); // get the month from today
        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10)); // get Month Name
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_movement_control' : 'movement_control'), 'movement_control' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/movement_control', $vars);
    }

    public function view_customer_visits() {
        $vars['title'] = inventoryModel::getmsg('view_customer_visits');
        $vars['system_name'] = inventoryModel::getmsg('');
        $vars['pageName'] = 'view_customer_visits';
        //        $today = Date::gettoday();

        $vars['today'] = Date::gettoday();
        $vars['users'] = CommonFunctions::CommonView('tbl_common_users');
        //        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('view_customer_visits'), 'view_customer_visits']];
        $this->load->view('Inventory/view_customer_visits', $vars);
    }

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

    public function reorder_invoice() {
        $vars['system_name'] = inventoryModel::getmsg('reorder_invoices');
        preg_match("/\/act/", $_SERVER['REQUEST_URI'], $match2);
        $vars['is_actual'] = count($match2) > 0 ? "1" : "0";
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'reorder_actual_invoices' : 'reorder_invoices');
        $vars['pageName'] = $vars['is_actual'] ? 'reorder_act_invoices' : 'reorder_invoices';
        $vars['breadCrumb'] = [[ACCModel::getmsg('inventory'), 'Inventory'], [ACCModel::getmsg($vars['is_actual'] ? 'reorder_actual_invoices' : 'reorder_invoices'), $vars['is_actual'] ? 'reorder_invoice/act' : 'reorder_invoice']];
        $this->load->view('Inventory/reorder_invoice', $vars);
    }

    public function pricing_classes() {
        preg_match("/\/supp/", $_SERVER['REQUEST_URI'], $match2);
        $vars['is_supp'] = count($match2) > 0 ? 1 : 0;
        $vars['title'] = inventoryModel::getmsg($vars['is_supp'] ? 'supplier_pricing_class' : 'pricing_class');
        $vars['system_name'] = inventoryModel::getmsg($vars['is_supp'] ? 'supplier_pricing_class' : 'pricing_class');
        $vars['pageName'] = $vars['is_supp'] ? 'supplier_pricing_class' : 'pricing_class';
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['methods'] = CommonFunctions::CommonView('tbl_stock_pricing_methods');
        $vars['classes'] = CommonFunctions::CommonView('tbl_pricing_class c join tbl_common_currency cu on cu.Currency_ID = c.Currency_ID');

        $vars['breadCrumb'] = [[ACCModel::getmsg('inventory'), 'Inventory'], [ACCModel::getmsg($vars['is_supp'] ? 'supplier_pricing_class' : 'pricing_class'), 'pricing_classes' . ($vars['is_supp'] ? '/supp' : '')]];
        $this->load->view('Inventory/pricing_classes', $vars);
    }

    public function viewBrand() {
        $vars['title'] = inventoryModel::getmsg('brand_list');
        $vars['system_name'] = inventoryModel::getmsg('brand_list');
        $vars['pageName'] = 'view_brand';
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['breadCrumb'] = [[ACCModel::getmsg('inventory'), 'Inventory'], [ACCModel::getmsg('brand_list'), 'viewBrand']];
        $this->load->view('Inventory/viewBrand', $vars);
    }

    public function viewDeliveryFees() {
        $vars['title'] = inventoryModel::getmsg('view_delivery_fees');
        $vars['system_name'] = inventoryModel::getmsg('view_delivery_fees');
        $vars['pageName'] = 'view_delivery_fees';
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['breadCrumb'] = [[ACCModel::getmsg('inventory'), 'Inventory'], [ACCModel::getmsg('view_delivery_fees'), 'viewDeliveryFees']];
        $this->load->view('Inventory/viewDeliveryFees', $vars);
    }

    public function TotalItems() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        preg_match("/\/brand\b/i", $_SERVER['REQUEST_URI'], $match_sales);
        $vars['is_brand'] = count($match_sales) > 0 ? true : false;
        $vars['pageName'] = $vars['is_actual'] ? ($vars['is_brand'] ? 'act_total_sold_items_by_brand' : 'act_total_sold_items_by_category') : ($vars['is_brand'] ? 'total_sold_items_by_brand' : 'total_sold_items_by_category');
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? ($vars['is_brand'] ? 'act_sold_per_brand' : 'act_sold_per_category') : ($vars['is_brand'] ? 'sold_per_brand' : 'sold_per_category'));
        $vars['system_name'] = inventoryModel::getmsg('invoice_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
        //        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10)); // get Month Name
        //        $vars['from_day'] = smc_session()['start_date'];//$vars['year'] . '-01-01';
        $vars['users'] = CommonFunctions::CommonView('tbl_common_users');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'TotalItems' . ($vars['is_brand'] ? '/brand' : '') . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/TotalItems', $vars);
    }

    public function view_total_sold_items_brand() {
        $current_user = '';
        $from_to_date = explode(" - ", $_POST['From_To_Date']);
        $_POST['From_Date'] = $from_to_date[0];
        $_POST['To_Date'] = $from_to_date[1];
        $_POST['return'] = !empty($_POST['with_return']) ? 1 : 0;
        $_POST['users'] = !empty($_POST['users']) ? $_POST['users'] : '';
        $_POST['brand_id'] = !empty($_POST['brand_id']) ? $_POST['brand_id'] : '';
        if (!empty($_POST['users'])) {
            $current_user = $this->_registry->user->setData($_POST)->getUserNames();
        }

        $vars['data'] = $this->_registry->invoice->setData($_POST)->getTotalSoldBrandItems();
        $quantity_total = $this->_registry->invoice->get_total_sold_brand_items_totals($_POST['return'], $_POST['From_Date'], $_POST['To_Date'], $_POST['users'], 0, $_POST['brand_id']);
        $vars['total_quantity'] = $quantity_total[0];
        $vars['totals'] = $quantity_total[1];
        $vars['data_filter'] = ['fromToDate' => $_POST['From_To_Date'],
            'users' => $current_user, 'return' => $_POST['return']];

        $this->load->view('Inventory/view_total_sold_items_brand', $vars, true);
    }

    public function DetailedPurchaseItemsReport() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'act_detailed_purchase_items_report' : 'detailed_purchase_items_report';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_detailed_purchase_items_report' : 'detailed_purchase_items_report');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');

        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_detailed_purchase_items_report' : 'detailed_purchase_items_report'), 'DetailedPurchaseItemsReport' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/DetailedPurchaseItemsReport', $vars);
    }

    public function product_sections() {

        $vars['pageName'] = 'product_sections';
        $vars['title'] = inventoryModel::getmsg('product_sections');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');

        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('product_sections'), 'product_sections']];
        $this->load->view('Inventory/product_sections', $vars);
    }

    public function printers() {

        $vars['pageName'] = 'printers';
        $vars['title'] = inventoryModel::getmsg('Printers');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');

        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('Printers'), 'printers']];
        $this->load->view('Inventory/printers', $vars);
    }

    public function family() {

        $vars['pageName'] = 'family';
        $vars['title'] = inventoryModel::getmsg('family');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');

        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('family'), 'family']];
        $this->load->view('Inventory/family', $vars);
    }

    public function ExpiryDate() {

        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        preg_match("/\/ex\b/i", $_SERVER['REQUEST_URI'], $match_ex);
        preg_match("/\/lot\b/i", $_SERVER['REQUEST_URI'], $match_lot);
        preg_match("/\/serial\b/i", $_SERVER['REQUEST_URI'], $match_serial);
        $vars['type'] = count($match_ex) > 0 ? 1 : (count($match_lot) > 0 ? 2 : 3);
        $vars['pageName'] = 'expiry_date_report';
        $vars['title'] = inventoryModel::getmsg($vars['type'] == 1 ? 'expiry_date_report' : ($vars['type'] == 2 ? 'product_lot_report' : 'product_serial_report'));
        //        $data = $this->_registry->Product->get_product_expiries(68);
        //        echo"<pre>";
        //        die(print_r($data));
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'ExpiryDate']];
        $this->load->view('Inventory/expiry_date_report', $vars);
    }

    public function product_recipe() {
        $vars['pageName'] = 'product_recipe';
        $vars['title'] = inventoryModel::getmsg('product_recipe');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        //        $cost = Product::get_main_product_cost(33);
        //        die($cost.'===');
        $vars['max_code'] = $this->_registry->Product->getMaxProductCode();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('product_recipe'), 'product_recipe']];
        $this->load->view('Inventory/product_recipe', $vars);
    }

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

    public function products_customers() {
        $vars['pageName'] = 'products_customers';
        $vars['title'] = inventoryModel::getmsg('products_customers');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $id = is_numeric($url[count($url) - 1]) ? $url[count($url) - 1] : 0;
        if ($id >= 0) {
            $customer = $this->_registry->customer->getCustomerByID($id);
            $vars['CustomerName'] = $customer['Customer_Name'];
            $vars['customerID'] = $customer['ID'];

            $vars['Ismatches'] = $vars['customerID'] >= 0 ? true : false;
        }

        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('products_customers'), 'products_customers']];
        $this->load->view('Inventory/products_customers', $vars);
    }

    public function pos_view_exchange() {
        //        $vars['pageName'] = 'scaleKeys';
        $vars['title'] = inventoryModel::getmsg('admin');
        $vars['system_name'] = inventoryModel::getmsg('admin');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];
        $data_arr = $this->_registry->invoicepos->get_exchange_by_id($vars['id']);
        $user_id = $data_arr['main']['created_logged_id'];
        $user_name = User::get_username_by_id($user_id);
        $data_arr['main']['User_Full_Name'] = $user_name;

        $template_key = $data_arr['main']['is_actual'] ? ['act_pos_exchange', 'pos_exchange'] : 'pos_exchange';

        $template_row = Forms::build_print_template($template_key, $data_arr['main'], array('inv_detail' => $data_arr['inv_detail'], 'ret_detail' => $data_arr['ret_detail']));
        //        $this->load->view_html($html, $vars);
        //echo"<pre>";print_r($data_arr);exit;
        if (smc_session()['default_setting']['sumatra_print'] == 1) {
            $print_w_h = Forms::get_print_width_height('pos');
            $filename = Forms::html2pdf($template_row['html'], $print_w_h);
            Forms::real_print(null, $filename, ['repeat' => $template_row['copies']]);
        } else {
            echo $template_row['html'];
        }
        exit;
        //        $vars['data'] = $this->_registry->invoicepos->getPOSInvoices($vars['id']);
        //        $vars['breadCrumb'] = [[inventoryModel::getmsg('admin'), 'Adminstration'], [inventoryModel::getmsg('floor_setting'), 'pos_view_invoice']];
        //        $this->load->view('POS/pos_view_invoice', $vars, true);
    }

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

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

    public function station_purchase() {
        $vars['pageName'] = 'station_purchase';
        $vars['title'] = inventoryModel::getmsg('station_purchase');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['IsEdit'] = is_numeric($url[count($url) - 1]) ? true : false;
        $vars['id'] = $vars['IsEdit'] ? $url[count($url) - 1] : 0;

        $vars['edit_arr'] = $vars['IsEdit'] ? $this->_registry->purchase->getPurchaseByID($vars['id']) : '';
//        echo"<pre>";die(print_r($vars['edit_arr']));
        $vars['check_lock'] = $vars['IsEdit'] ? CommonFunctions::check_lock_data(['type' => 'station_purchase', 'start_date' => $vars['edit_arr']['Main']['Date'], 'is_actual' => ($vars['is_actual'] ? 1 : 0)]) : '';

        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['today'] = Date::getToday();
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
        $currency_data = $this->_registry->Currency->getCurrencyByID($vars['DefaultCurrencyID']);
        $vars['currency_round'] = ($vars['IsEdit'] && !empty($vars['edit_arr']['Main']['currency_round'])) ? $vars['edit_arr']['Main']['currency_round'] : $currency_data[2];

        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();

        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();
        $vars['all_compts'] = $this->_registry->Product->getCompts();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('station_purchase_list'), 'station_purchase_list'], [inventoryModel::getmsg('station_purchase'), 'station_purchase' . ($vars['IsEdit'] ? "/{$vars['id']}" : "")]];
        $this->load->view('Inventory/station_purchase', $vars);
    }

    public function customer_coupons() {
        $vars['pageName'] = 'customer_coupons';
        $vars['title'] = inventoryModel::getmsg('customer_coupons');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['IsEdit'] = is_numeric($url[count($url) - 1]) ? true : false;
        $vars['id'] = $vars['IsEdit'] ? $url[count($url) - 1] : 0;

        $vars['edit_arr'] = $vars['IsEdit'] ? $this->_registry->station->getCustomerCouponData($vars['id']) : '';
//                     echo"<pre>";die(print_r($vars['edit_arr']));
        $vars['check_lock'] = $vars['IsEdit'] ? CommonFunctions::check_lock_data(['type' => 'customer_coupon', 'start_date' => $vars['edit_arr']['main']['invoice_date'], 'is_actual' => ($vars['is_actual'] ? 1 : 0)]) : '';

        //        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['today'] = Date::getToday();
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
        //        $currency_data = $this->_registry->Currency->getCurrencyByID($vars['DefaultCurrencyID']);
        //        $vars['currency_round'] = $vars['IsEdit'] ? $vars['edit_arr']['main']['currency_round'] : $currency_data[2];
        //        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
        //        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('customer_coupons_list'), 'customer_coupons_list'],
            [inventoryModel::getmsg('customer_coupons'), 'customer_coupons' . ($vars['IsEdit'] ? "/{$vars['id']}" : "")]];
        $this->load->view('Inventory/customer_coupons', $vars);
    }

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

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

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

    public function station_invoice() {
        $vars['pageName'] = 'station_invoice';
        $vars['title'] = inventoryModel::getmsg('station_invoice');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['IsEdit'] = is_numeric($url[count($url) - 1]) ? true : false;
        $vars['id'] = $vars['IsEdit'] ? $url[count($url) - 1] : 0;

        $vars['edit_arr'] = $vars['IsEdit'] ? $this->_registry->station->get_station_invoice($vars['id']) : '';
//                echo"<pre>";die(print_r($vars['edit_arr']));
        $vars['check_lock'] = $vars['IsEdit'] ? CommonFunctions::check_lock_data(['type' => 'station_invoice', 'start_date' => $vars['edit_arr']['main']['invoice_date'], 'is_actual' => ($vars['is_actual'] ? 1 : 0)]) : '';

        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['today'] = Date::getToday();
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
        //        $currency_data = $this->_registry->Currency->getCurrencyByID($vars['DefaultCurrencyID']);
        //        $vars['currency_round'] = $vars['IsEdit'] ? $vars['edit_arr']['Main']['currency_round'] : $currency_data[2];

        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();

        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();
        $vars['all_pumps'] = $this->_registry->station->get_pumps($vars['IsEdit'] ? 0 : 1);
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('station_invoice_list'), 'station_invoice_list'], [inventoryModel::getmsg('station_invoice'), 'station_invoice' . ($vars['IsEdit'] ? "/{$vars['id']}" : "")]];
        $this->load->view('Inventory/station_invoice', $vars);
    }

    public function coupon_type_balance() {
        $vars['pageName'] = 'coupon_type_balance';
        $vars['title'] = inventoryModel::getmsg('coupon_type_balance');
        $vars['system_name'] = inventoryModel::getmsg('coupon_type_balance');
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['today'] = Date::getToday();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('coupon_type_balance'), 'coupon_type_balance']];
        $this->load->view('Inventory/coupon_type_balance', $vars);
    }

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

    public function view_station_invoice() {
        $vars['pageName'] = 'view_station_invoice';
        $vars['title'] = inventoryModel::getmsg('purchase_invoice');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];

        $vars['data'] = $this->_registry->station->get_station_invoice($vars['id']);

        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails()[0];
                               //echo"<pre>";die(print_r($vars['org_details']));

        $vars['all_pumps'] = $this->_registry->station->get_pumps();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('sales_invoice'), 'view_station_invoice/' . $vars['id']]];
        $this->load->view('Inventory/view_station_invoice', $vars);
    }

    public function product_reservation_duration() {
        $vars['pageName'] = 'product_reservation_duration';
        $vars['title'] = inventoryModel::getmsg('product_reservation_duration');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['product_resources'] = $this->_registry->Product->getProductResources();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'],
            [inventoryModel::getmsg('product_reservation_duration'), 'product_reservation_duration']];
        $this->load->view('Inventory/product_reservation_duration', $vars);
    }

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

    public function sales_commission() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['pageName'] = $vars['is_actual'] ? 'inventory_sales_commission_actual' : 'inventory_sales_commission';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_salesman_commission' : 'salesman_commission');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['current_type'] = 'inventory';
        $vars['current_color'] = 'primary';
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_salesman_commission' : 'salesman_commission'), 'sales_commission' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/sales_commission', $vars);
    }

    public function job_order() {
        $vars['pageName'] = 'job_order';
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['is_edit'] = is_numeric($url[count($url) - 1]) ? true : false;
        $vars['id'] = $vars['is_edit'] ? $url[count($url) - 1] : 0;
        $vars['title'] = inventoryModel::getmsg('job_order');
        $vars['job_order_block_options'] = $this->_registry->jobOrder->getJobOrderBlockOptionData();
        $vars['job_order_stages'] = CommonFunctions::CommonView('tbl_job_order_stage', null, null, ' order by sort_nb desc');
        $vars['blocks'] = CommonFunctions::CommonView('tbl_job_order_block', null, null, ' order by sort_nb desc');
        //        $submit = $this->_registry->shipping->update_old_invoices_shipping_data();
        //        echo '<pre>';
        //print_r($submit);
        //        die('ok');
        $vars['edit_arr'] = $vars['is_edit'] ? $this->_registry->jobOrder->getJobOrderData($vars['id']) : array();
//       echo"<pre>";die(print_r($vars['edit_arr']));
        $vars['check_lock'] = $vars['is_edit'] ? CommonFunctions::check_lock_data(['type' => 'job_order', 'start_date' => $vars['edit_arr']['main']['job_order_date'], 'is_actual' => 0]) : '';

        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('job_order_list'), 'job_order_list'], [inventoryModel::getmsg('job_order'), 'job_order']];
        $this->load->view('Inventory/job_order', $vars);
    }

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

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

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

    public function job_order_list() {
        $vars['pageName'] = 'job_order_list';
        $vars['title'] = inventoryModel::getmsg('job_order_list');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['job_order_stages'] = CommonFunctions::CommonView('tbl_job_order_stage', null, null, ' order by sort_nb desc');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('job_order_list'), 'job_order_list']];
        $this->load->view('Inventory/job_order_list', $vars);
    }

    public function sales_to_purchase_order() {
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['pageName'] = 'purchaseOrder'; // to be edited
        $vars['title'] = inventoryModel::getmsg('purchase_orders'); // to be edited
        $url = explode('/', $_SERVER['REQUEST_URI']);
        //        $vars['IsEdit'] = (is_numeric($url[count($url) - 1])) ? true : false;
        $vars['id'] = $url[count($url) - 1];
        $vars['data'] = $this->_registry->purchase->get_purchase_from_sales_order($vars['id']);
        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['today'] = Date::getToday();
        $vars['currency_list'] = $this->_registry->Currency->getAllCurrencies();
        //        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        //        $vars['DefaultCurrencyID'] = $this->_registry->Currency->getDefaultCurrency();
        //        $currency_data = $this->_registry->Currency->getCurrencyByID($vars['DefaultCurrencyID']);
        //        $vars['currency_round'] = (($vars['IsEdit']) && isset($vars['edit_arr']['Main']['currency_round'])) ? $vars['edit_arr']['Main']['currency_round'] : $currency_data[2];
        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
        //                        echo"<pre>";
        //                        die(print_r($vars['data']));
        //        $vars['InvoiceNumber'] = $vars['IsSales'] ? $this->_registry->invoice->getMaxInvoice() : $this->_registry->purchase->getMaxPurchase();
        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();
        $vars['all_uom'] = $this->_registry->Product->getUOM();



        //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [
        //                inventoryModel::getmsg($vars['IsQuotation'] ? ($vars['IsSales'] ? 'sales_quotation' : 'purchase_quotation') : ( $vars['is_actual'] ? ($vars['IsSales'] ? 'actual_sales_order' : 'actual_purchase_order') : ($vars['IsSales'] ? 'sales_order' : 'purchase_orders'))),
        //                'quotationOrder' . ($vars['IsQuotation'] ? '/quotation' : '/order') . ($vars['IsSales'] ? '/sales' : '') . ($vars['is_actual'] ? '/act' : '') . ($vars['IsEdit'] ? '/' . $vars['id'] : '')]]; // to be  edited

        $this->load->view('Inventory/sales_to_purchase_order', $vars);
    }

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

    public function shipping_list() {
        $vars['pageName'] = 'shipping_list';
        $vars['title'] = inventoryModel::getmsg('shipping_list');
        $vars['shipping_status'] = CommonFunctions::CommonView('tbl_shipping_status');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('shipping_list'), 'shipping_list']];
        $this->load->view('Inventory/shipping_list', $vars);
    }

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

    public function customer_subscriptions() {
        $vars['pageName'] = 'customer_subscriptions';
        $vars['title'] = inventoryModel::getmsg('customer_subscriptions');
        $vars['main_block'] = CommonFunctions::CommonView('tbl_subscription_block', ['parent_id'], [0]);
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('customer_subscriptions'), 'customer_subscriptions']];
        $this->load->view('Inventory/customer_subscriptions', $vars);
    }

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

    public function customer_subscriptions_close_balance() {
        $vars['pageName'] = 'customer_subscriptions_close_balance';
        $vars['title'] = inventoryModel::getmsg('customer_subscriptions_close_balance');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['current_type'] = 'close';
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('customer_subscriptions_close_balance'), 'customer_subscriptions_close_balance']];
        $this->load->view('Inventory/customer_subscriptions_open_balance', $vars);
    }

    public function subscription_fees() {
        $vars['pageName'] = 'subscription_fees';
        $vars['title'] = inventoryModel::getmsg('subscription_fees');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['main_block'] = CommonFunctions::CommonView('tbl_subscription_block', ['parent_id'], [0]);
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('subscription_fees'), 'subscription_fees']];
        $this->load->view('Inventory/subscription_fees', $vars);
    }

    //    public function exchange() {
    //        $url = explode('/', $_SERVER['REQUEST_URI']);
    //        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
    //        $vars['is_actual'] = count($match_act) > 0 ? true : false;
    //        $vars['IsEdit'] = is_numeric($url[count($url) - 1]) ? true : false;
    //        $vars['pageName'] = $vars['IsEdit'] ? 'edit_exchange' : 'add_exchange';
    //        $vars['title'] = inventoryModel::getmsg($vars['IsEdit'] ? 'edit_exchange' : 'add_exchange');
    //        $vars['id'] = $vars['IsEdit'] ? $url[count($url) - 1] : 0;
    //        $vars['edit_arr'] = $vars['IsEdit'] ? $this->_registry->invoicepos->retreive_exchange_by_id($vars['id']) : array();
    //        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
    //        $vars['DefaultCurrencyID'] = smc_session()['pricing_class_currency'];
    //        $currency_data = $this->_registry->Currency->getCurrencyByID($vars['DefaultCurrencyID']);
    //        //        $vars['DefaultCurrencyID'] = smc_session()['local_currency'];
    //        $vars['currency_round'] = (($vars['IsEdit']) && isset($vars['edit_arr']['Main']['currency_round'])) ? $vars['edit_arr']['Main']['currency_round'] : $currency_data[2];
    //
    //        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
    //        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
    //        $vars['Extable'] = $this->_registry->Currency->getExchangeRateTable();
    //        $vars['all_uom'] = $this->_registry->Product->getUOM();
    //
    //        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
    //        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['IsEdit'] ? 'edit_exchange' : 'add_exchange'), 'exchange']];
    //        $this->load->view('Inventory/exchange', $vars);
    //    }
    public function exchange_list() {
        $vars['pageName'] = 'exchange_list';
        $vars['title'] = inventoryModel::getmsg('exchange_list');
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('exchange_list'), 'exchange_list']];
        $this->load->view('Inventory/exchange_list', $vars);
    }

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

    public function subscription_fees_list() {
        $vars['pageName'] = 'subscription_fees_list';
        $vars['title'] = inventoryModel::getmsg('subscription_fees_list');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['payment_type'] = $this->_registry->payment->viewPaymentTypes();
        $vars['main_block'] = CommonFunctions::CommonView('tbl_subscription_block', ['parent_id'], [0]);
        //        $this->_registry->subscriptions->setData(array('invoices'=>[['inv_id'=>5091,'discount_amount'=>54975]]))->edit_disc_cust_subscription();
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('subscription_fees_list'), 'subscription_fees_list']];
        $this->load->view('Inventory/subscription_fees_list', $vars);
    }

    public function total_ordered_items() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        preg_match("/\/sales\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_sales'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? ($vars['is_sales'] == 1 ? 'act_total_sales_ordered_items' : 'act_total_purchase_ordered_items') : ($vars['is_sales'] == 1 ? 'total_sales_ordered_items' : 'total_purchase_ordered_items');
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? ($vars['is_sales'] == 1 ? 'act_total_sales_ordered_items' : 'act_total_purchase_ordered_items') : ($vars['is_sales'] == 1 ? 'total_sales_ordered_items' : 'total_purchase_ordered_items'));
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['today'] = Date::gettoday();
        $vars['users'] = CommonFunctions::CommonView('tbl_common_users');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'total_ordered_items' . ($vars['is_actual'] ? '/act' : '') . ($vars['is_sales'] ? '/sales' : '')]];
        $this->load->view('Inventory/total_ordered_items', $vars);
    }

    public function view_subscription_fees() {
        $vars['pageName'] = 'view_station_purchase';
        $main_ids = $_GET['main_ids'];
        $data = $this->_registry->subscriptions->getSubscriptionsToPrint($main_ids);
 
        $template_key = 'subscription_fees';
        $template_row = Forms::build_print_template($template_key, array(), array('inv_detail' => $data), true);
        //
        echo $template_row['html'];
        echo '<script src="' . SITE_LINK . '/Theme/plugins/jquery/jquery-2.1.1.js" type="text/javascript"></script>';
        //        $this->load->view_html($template_row['html'], $vars);
        exit;
    }

    public function invoice_discount_list() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['pageName'] = $vars['is_actual'] ? 'actual_invoice_discount_list' : 'invoice_discount_list';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'actual_invoice_discount_list' : 'invoice_discount_list');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'actual_invoice_discount_list' : 'invoice_discount_list'), 'invoice_discount_list' . ($vars['is_actual'] ? '/act' : '')]];

        $this->load->view('Inventory/invoice_discount_list', $vars);
    }

    public function return_damaged_items() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['pageName'] = $vars['is_actual'] ? 'actual_return_damaged_items' : 'return_damaged_items';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_return_damaged_items' : 'return_damaged_items');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['is_actual'] ? 'act_return_damaged_items' : 'return_damaged_items'), 'return_damaged_items' . ($vars['is_actual'] ? '/act' : '')]];

        $this->load->view('Inventory/return_damaged_items', $vars);
    }

    public function view_shipment() {
        $url = explode('/', $_GET['url']);
        $Invoice_ID = $url[count($url) - 1];
        $data = $this->_registry->invoice->getInvoiceToPrint($Invoice_ID);
        $shippment = CommonFunctions::CommonView('tbl_invoice_shipping', ['Invoice_ID_Auto'], [$Invoice_ID])[0];
        $shippment_address = CommonFunctions::CommonView('tbl_customer_shipping_address', ['shipping_address_id'], [$data['main']['address_id']])[0];
        $data['main']['shipping_number'] = $shippment['api_shipping_id'];

        $data['main']['shipping_number_qrcode'] = SITE_LINK . 'common_controller/GenerateQRCode?code=' . $data['main']['shipping_number'];
        $data['main']['shipping_number_barcode'] = SITE_LINK . 'common_controller/GenerateBarCodeImage?code=' . $data['main']['shipping_number'];
        $data['main']['shipping_number_barcode39'] = SITE_LINK . 'common_controller/GenerateTypeBarCodeImage?type=C39&code=' . $data['main']['shipping_number'];

        $data['main']['street'] = $shippment_address['shipping_street'];
        $data['main']['building'] = $shippment_address['shipping_building'];
        $data['main']['address'] = $shippment_address['shipping_address'];
        $data['main']['shipping_account'] = '131625';
        if (!empty($shippment['from_address_id'])) {
            $data['main']['from_address'] = 'Lebanon - Beirut';
            if ($shippment['from_address_id'] == 1) {
                $data['main']['from_name'] = 'Megara';
                $data['main']['from_mobile'] = '71144627';
            } else if ($shippment['from_address_id'] == 2) {
                $data['main']['from_name'] = 'Jouri';
                $data['main']['from_mobile'] = '76055537';
            } else if ($shippment['from_address_id'] == 3) {
                $data['main']['from_name'] = 'K boutique';
                $data['main']['from_mobile'] = '76885332';
            } else {
                $data['main']['from_name'] = 'Lamritta';
                $data['main']['from_mobile'] = '70689703';
            }
        } else {
            $data['main']['from_name'] = '';
            $data['main']['from_address'] = '';
            $data['main']['from_mobile'] = '';
        }
        //                echo"<pre>";print_r($data);exit;
        $template_id = !empty($_GET['template_id']) ? $_GET['template_id'] : '';
        if (!empty($data)) {
            $vars['pageName'] = 'view_shipment';
            $template_key = 'view_shipment';
            if (!empty($template_id))
                $template_key['id'] = $template_id;
            $template_row = Forms::build_print_template($template_key, $data['main'], array());
        } else
            $template_row['html'] = 'you can not edit this invoice! 
        <br>
        This invoice is not available.';
        echo $template_row['html'];
        echo '<script src="' . SITE_LINK . '/Theme/plugins/jquery/jquery-2.1.1.js" type="text/javascript"></script>';
        //        $this->load->view_html($template_row['html'], $vars);
        exit;
    }

    public function postponed_list() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        preg_match("/\/order\b/i", $_SERVER['REQUEST_URI'], $match_type);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['is_order'] = count($match_type) > 0 ? true : false;
        $vars['pageName'] = $vars['is_order'] ? ($vars['is_actual'] ? 'act_order_postponed_list' : 'order_postponed_list') : ($vars['is_actual'] ? 'actual_inventory_postponed_list' : 'inventory_postponed_list');
        $vars['title'] = inventoryModel::getmsg($vars['is_order'] ? ($vars['is_actual'] ? 'act_order_postponed_list' : 'order_postponed_list') : ($vars['is_actual'] ? 'actual_posponted_list' : 'posponted_list'));
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'postponed_list' . ($vars['is_order'] ? '/order' : '') . ($vars['is_actual'] ? '/act' : '')]];

        $this->load->view('Inventory/postponed_list', $vars);
    }

    public function postponed_report() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        preg_match("/\/order\b/i", $_SERVER['REQUEST_URI'], $match_type);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;
        $vars['is_order'] = count($match_type) > 0 ? true : false;
        $vars['pageName'] = $vars['is_order'] ? ($vars['is_actual'] ? 'act_order_postponed_report' : 'order_postponed_report') : ($vars['is_actual'] ? 'actual_inventory_postponed_report' : 'inventory_postponed_report');
        $vars['title'] = inventoryModel::getmsg($vars['is_order'] ? ($vars['is_actual'] ? 'act_order_postponed_report' : 'order_postponed_report') : ($vars['is_actual'] ? 'actual_posponted_list' : 'postponed_report'));
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'postponed_report' . ($vars['is_order'] ? '/order' : '') . ($vars['is_actual'] ? '/act' : '')]];

        $this->load->view('Inventory/postponed_report', $vars);
    }

    public function DetailedOrderProductReport() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        preg_match("/\/sales\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_sales'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? ($vars['is_sales'] == 1 ? 'act_detailed_sales_order_items' : 'act_detailed_purchase_order_items') : ($vars['is_sales'] == 1 ? 'detailed_sales_order_items' : 'detailed_purchase_order_items');
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? ($vars['is_sales'] == 1 ? 'act_detailed_sales_order_per_date' : 'act_detailed_purchase_order_per_date') : ($vars['is_sales'] == 1 ? 'detailed_sales_order_per_date' : 'detailed_purchase_order_per_date'));
        $vars['system_name'] = inventoryModel::getmsg('invoice_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
        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10)); // get Month Name
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'DetailedOrderProductReport' . ($vars['is_actual'] ? '/act' : '') . ($vars['is_sales'] == 1 ? '/sales' : '')]];
        $this->load->view('Inventory/DetailedOrderProductReport', $vars);
    }

    public function category_trial_balance() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        preg_match("/\/sales\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_sales'] = count($match_act) > 0 ? 1 : 0;
        preg_match("/\/disc\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_disc'] = count($match_act) > 0 ? 1 : 0;
        $vars['permissions'] = $this->controller_permission;

        $vars['pageName'] = $vars['is_disc'] ? ($vars['is_actual'] ? ($vars['is_sales'] == 1 ? 'act_sales_per_category_disc' : 'act_purchase_per_category_disc') : ($vars['is_sales'] == 1 ? 'sales_per_category_disc' : 'purchase_per_category_disc')) : ($vars['is_actual'] ? ($vars['is_sales'] == 1 ? 'act_sales_per_category' : 'act_purchase_per_category') : ($vars['is_sales'] == 1 ? 'sales_per_category' : 'purchase_per_category'));
        $vars['title'] = inventoryModel::getmsg($vars['is_disc'] ? ($vars['is_actual'] ? ($vars['is_sales'] == 1 ? 'act_sales_per_category_disc' : 'act_purchase_per_category_disc') : ($vars['is_sales'] == 1 ? 'sales_per_category_disc' : 'purchase_per_category_disc')) : ($vars['is_actual'] ? ($vars['is_sales'] == 1 ? 'act_sales_per_category' : 'act_purchase_per_category') : ($vars['is_sales'] == 1 ? 'sales_per_category' : 'purchase_per_category')));
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'category_trial_balance' . ($vars['is_sales'] == 1 ? '/sales' : '') . ($vars['is_actual'] ? '/act' : '') . ($vars['is_disc'] ? '/disc' : '')]];
        //        $this->_registry->Product->category_trial_balance();
        $this->load->view('Inventory/category_trial_balance', $vars);
    }

    public function view_category_trial_balance() {
        $current_user = $customer_name = '';
//                echo"<pre>";print_r($_POST);
        $from_to_date = explode(" - ", $_POST['From_To_Date']);
        $_POST['From_Date'] = !empty($_POST['From_To_Date']) ? $from_to_date[0] : '';
        $_POST['To_Date'] = !empty($_POST['From_To_Date']) ? $from_to_date[1] : '';
        $_POST['customer_id'] = is_numeric($_POST['customer_id']) ? $_POST['customer_id'] : '';
        $_POST['branch_id'] = !empty($_POST['branch_id']) ? $_POST['branch_id'] : '';
        $_POST['sales_man_id'] = !empty($_POST['sales_man_id']) ? $_POST['sales_man_id'] : '';
        $_POST['type'] = !empty($_POST['type']) ? $_POST['type'] : '';
        $_POST['group_id'] = !empty($_POST['group_id']) ? $_POST['group_id'] : '';
        $vars['data_filter'] = ['From_Date' => $_POST['From_Date'], 'To_Date' => $_POST['To_Date'],
            'type' => $_POST['type']];


        $vars['data'] = $this->_registry->Product->setData($_POST)->cat_trial_blanc_with_disc_report_p_day();

//          echo"<pre>";        print_r($vars['data_filter']);exit;
        $this->load->view('Inventory/view_category_trial_balance', $vars, true);
    }

    public function periodic_sales_purchase_mov() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        preg_match("/\/sales\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_sales'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? ($vars['is_sales'] == 1 ? 'act_periodic_sales_mov' : 'act_periodic_purchase_mov') : ($vars['is_sales'] == 1 ? 'periodic_sales_mov' : 'periodic_purchase_mov');
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? ($vars['is_sales'] == 1 ? 'act_periodic_sales_mov' : 'act_periodic_purchase_mov') : ($vars['is_sales'] == 1 ? 'periodic_sales_mov' : 'periodic_purchase_mov'));
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'periodic_sales_purchase_mov' . ($vars['is_sales'] == 1 ? '/sales' : '') . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/periodic_sales_purchase_mov', $vars);
    }

    public function customer_supplier_codes() {
        preg_match("/\/cust\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['is_cust'] = count($match) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_cust'] == 1 ? 'customer_product_codes' : 'supplier_product_codes';
        $vars['title'] = CommonLanguage::getMessage($vars['is_cust'] == 1 ? 'customer_product_codes' : 'supplier_product_codes');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], ('customer_supplier_codes' . ($vars['is_cust'] == 1 ? '/cust' : ''))]];
        $this->load->view('Inventory/customer_supplier_codes', $vars);
    }

    public function salesman_customers_list() {
        $vars['pageName'] = 'salesman_customers_list';
        $vars['title'] = inventoryModel::getmsg('salesman_customers_list');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['users'] = CommonFunctions::CommonView('tbl_common_users', ['is_app'], [1]);
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('salesman_customers_list'), 'salesman_customers_list']];
        $this->load->view('Inventory/salesman_customers_list', $vars);
    }
    #yousif 
    


    public function salesman_depot_list() {
        $vars['pageName'] = 'salesman_depot_list';
        $vars['title'] = inventoryModel::getmsg('salesman_depot_list');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        //        $vars['users'] = CommonFunctions::CommonView('tbl_common_users');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('salesman_depot_list'), 'salesman_depot_list']];
        $this->load->view('Inventory/salesman_depot_list', $vars);
    }

    public function group_list() {
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['group_type'] = $url[count($url) - 1];
        //       echo $vars['group_type'].'==';
        //       die('ok');
        $vars['pageName'] = $vars['group_type'] . '_group';
        $vars['title'] = inventoryModel::getmsg($vars['group_type'] . '_group_list');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['group_type'] . '_group_list'), 'group_list/' . $vars['group_type']]];
        $this->load->view('Inventory/group_list', $vars);
    }

    public function class_list() {
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['class_type'] = $url[count($url) - 1];
        $vars['pageName'] = $vars['class_type'] . '_class';
        $vars['title'] = inventoryModel::getmsg($vars['class_type'] . '_class_list');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg($vars['class_type'] . '_class_list'), 'class_list/' . $vars['class_type']]];
        $this->load->view('Inventory/class_list', $vars);
    }

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

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

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

    public function item_movement() {
        $vars['pageName'] = 'item_movement';
        $vars['title'] = inventoryModel::getmsg('item_movement');
        $vars['system_name'] = inventoryModel::getmsg('item_movement');
        $vars['get_paramters'] = $_GET;
        $vars['origin'] = 'inventory';
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('item_movement'), 'item_movement']];

        $this->load->view('Stock/stock_transactions', $vars);
    }

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

    public function customer_daily_report() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? 'act_customer_daily_report' : 'customer_daily_report';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_customer_daily_report' : 'customer_daily_report');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'customer_daily_report' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/customer_daily_report', $vars);
    }

    public function consumption() {

        $vars['system_name'] = inventoryModel::getmsg('inventory');

        $url = explode('/', $_SERVER['REQUEST_URI']);
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? true : false;

        $vars['IsEdit'] = is_numeric($url[count($url) - 1]) ? true : false;
        $vars['id'] = $vars['IsEdit'] ? $url[count($url) - 1] : 0;

        if (!$vars['IsEdit']) {
//            $vars['unique_id'] = 'cons' . uniqid();
//            smc_session()['duplicate_check'][$vars['unique_id']] = true;
            $vars['unique_id'] = token_unique::generate_token('cons');
        }
        $vars['edit_arr'] = $vars['IsEdit'] ? $this->_registry->invoice->getConsumptionByID($vars['id']) : '';
        $vars['check_lock'] = $vars['IsEdit'] ? CommonFunctions::check_lock_data(['type' => 'consumption', 'start_date' => $vars['edit_arr']['Main']['Date'], 'is_actual' => ($vars['is_actual'] ? 1 : 0)]) : '';

        $vars['pageName'] = $vars['id'] == 0 ? 'add_consumption' : 'edit_consumption';
        $vars['title'] = inventoryModel::getmsg($vars['id'] == 0 ? 'add_consumption' : 'edit_consumption');
//                echo '<pre>';
//                print_r( $vars['edit_arr']);
//                die('ok');

        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['today'] = Date::getToday();

        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
        $vars['all_uom'] = $this->_registry->Product->getUOM();


        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('consumption_list'), 'consumption_list']];
        if ($vars['id'] == 0) {
            $vars['breadCrumb'][] = [inventoryModel::getmsg('add_consumption'), 'consumption'];
        }
        $this->load->view('Inventory/consumption', $vars);
    }

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

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

    public function subscription_block() {
        $vars['pageName'] = 'subscription_block';
        $vars['title'] = inventoryModel::getmsg('subscription_block');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('subscription_block'), 'subscription_block']];

        $this->load->view('Inventory/subscription_block', $vars);
    }

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

    public function category_fees_list() {
        $vars['pageName'] = 'category_fees_list';
        $vars['title'] = inventoryModel::getmsg('category_fees_list');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['main_block'] = CommonFunctions::CommonView('tbl_subscription_block', ['parent_id'], [0]);
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('category_fees_list'), 'category_fees_list']];
        $vars['header_arr'] = $this->_registry->subscriptions->get_category_fees_header();
        $this->load->view('Inventory/category_fees_list', $vars);
    }

    public function subscription_block_report() {
        $vars['pageName'] = 'subscription_block_report';
        $vars['title'] = inventoryModel::getmsg('subscription_block_report');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['main_block'] = CommonFunctions::CommonView('tbl_subscription_block', ['parent_id'], [0]);
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('subscription_block_report'), 'subscription_block_report']];
        $this->load->view('Inventory/subscription_block_report', $vars);
    }

    public function customer_sold_items_report() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] == 0 ? 'customer_sold_items_report' : 'act_customer_sold_items_report';
        $vars['title'] = CommonLanguage::getMessage($vars['is_actual'] == 0 ? 'customer_sold_items_report' : 'act_customer_sold_items_report');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'customer_sold_items_report' . ($vars['is_actual'] ? '/act' : '')]];
        //                $this->_registry->invoice->customer_sold_items_report();
        //        $vars['header_arr'] = $this->_registry->invoice->get_cust_sold_header(10);
        $this->load->view('Inventory/customer_sold_items_report', $vars);
    }

    public function monthly_sales_report() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] == 0 ? 'monthly_sales_report' : 'act_monthly_sales_report';
        $vars['title'] = CommonLanguage::getMessage($vars['is_actual'] == 0 ? 'monthly_sales_report' : 'act_monthly_sales_report');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'monthly_sales_report' . ($vars['is_actual'] ? '/act' : '')]];
        $today = date('Y-m-d');
        $vars['year'] = date("Y", strtotime($today)); // get the year from today
        $vars['month'] = date("m", strtotime($today)); // get the month from today
        //        $vars['monthName'] = date("F", mktime(0, 0, 0, $month, 10)); // transform the month number to month name
        //          $this->_registry->invoice->customer_sold_items_report();
        //        $vars['header_arr'] = $this->_registry->invoice->get_cust_sold_header();
        $this->load->view('Inventory/monthly_sales_report', $vars);
    }

    public function monthly_sales_graph() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] == 0 ? 'monthly_sales_graph' : 'act_monthly_sales_graph';
        $vars['title'] = CommonLanguage::getMessage($vars['is_actual'] == 0 ? 'monthly_sales_graph' : 'act_monthly_sales_graph');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'monthly_sales_graph' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/monthly_sales_graph', $vars);
    }

    public function monthly_year_sales_graph() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] == 0 ? 'monthly_year_sales_graph' : 'act_monthly_year_sales_graph';
        $vars['title'] = CommonLanguage::getMessage($vars['is_actual'] == 0 ? 'monthly_year_sales_graph' : 'act_monthly_year_sales_graph');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'monthly_year_sales_graph' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/monthly_year_sales_graph', $vars);
    }

    public function monthly_year_sales_list() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] == 0 ? 'monthly_year_sales_list' : 'monthly_year_sales_list_actual';
        $vars['title'] = CommonLanguage::getMessage($vars['is_actual'] == 0 ? 'monthly_year_sales_list' : 'act_monthly_year_sales_list');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'monthly_year_sales_list' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/monthly_year_sales_list', $vars);
    }

    public function monthly_year_products_sales_list() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] == 0 ? 'monthly_year_products_sales_list' : 'monthly_year_products_sales_list_actual';
        $vars['title'] = CommonLanguage::getMessage($vars['is_actual'] == 0 ? 'monthly_year_products_sales_list' : 'act_monthly_year_products_sales_list');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'monthly_year_products_sales_list' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Inventory/monthly_year_products_sales_list', $vars);
    }

    public function forecast_report() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] == 0 ? 'forecast_report' : 'actual_forecast_report';
        $vars['title'] = CommonLanguage::getMessage($vars['is_actual'] == 0 ? 'forecast_report' : 'actual_forecast_report');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [$vars['title'], 'forecast_report' . ($vars['is_actual'] ? '/act' : '')]];
        $today = date('Y-m-d');
        $vars['year'] = date("Y", strtotime($today)); // get the year from today
        $vars['month'] = date("m", strtotime($today)); // get the month from today
        $this->_registry->invoice->forcast_sales_report('2020-02', '2020-03', 17);
        $this->load->view('Inventory/forecast_report', $vars);
    }
    
    public function customers_certificate() {
        $vars['pageName'] = 'customers_certificate';
        $vars['title'] = inventoryModel::getmsg('customers_certificate');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('customers_certificate') ]];
        $this->load->view('Inventory/customers_certificate', $vars);
    }
    
    public function customers_contra() {
        $vars['pageName'] = 'customers_contra';
        $vars['title'] = inventoryModel::getmsg('customers_contra');
        $vars['system_name'] = inventoryModel::getmsg('inventory');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('customers_contra') ]];
        $this->load->view('Inventory/customers_contra', $vars);
    }

    public function daily_sales() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match_act);
        $vars['is_actual'] = count($match_act) > 0 ? 1 : 0;
        $vars['pageName'] =   'daily_sales';
        $vars['title'] = inventoryModel::getmsg( 'daily_sales');
        $vars['system_name'] = inventoryModel::getmsg('invoice_sys');
        $today = Date::gettoday();
        $vars['year'] = date("Y", strtotime($today)); // get the year from today
        $vars['month'] = date("m", strtotime($today)); // get the month from today
        $vars['monthName'] = date("F", mktime(0, 0, 0, $vars['month'], 10)); // get Month Name
        $vars['breadCrumb'] = [[inventoryModel::getmsg('inventory'), 'Inventory'], [inventoryModel::getmsg('daily_sales'), 'daily_sales' ]];
        $this->load->view('Inventory/daily_sales', $vars);
    }

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

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

}
