<?php

class Stock extends mainController {

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

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

    public function Stock() {
        $vars['pageName'] = 'Stock';
        $vars['title'] = StockModel::getmsg('stock');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        //        $vars['breadCrumb'] = [[StockModel::getmsg('dashboard'), 'Stock/StockDashboard'], [StockModel::getmsg('stock'), 'Stock']];
        //        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock']];
        //
        $vars['menu_blocks'] = array(
            array('msg' => 'Warehouses', 'prmsn' => 'Warehouses', 'icon' => 'fa fa-home'
                , 'detail' => array(
                    array('msg' => 'Import_Data', 'prmsn' => 'import_stock', 'mdl' => '#UploadExcelFile', 'icon' => 'fa fa-delicious')
                    , array('msg' => 'Warehouses', 'prmsn' => 'ListDepot', 'lnk' => SITE_LINK . 'Stock/ListDepot', 'icon' => 'fa fa-delicious')
                    , array('msg' => 'Product_Location', 'prmsn' => 'MaterialLocation', 'lnk' => SITE_LINK . 'Stock/ProductLocationList', 'icon' => 'fa fa-compass'),
                    array('msg' => 'multi_product_location', 'prmsn' => 'multi_product_location', 'lnk' => SITE_LINK . 'Stock/multi_product_location', 'icon' => 'fa fa-compass')
                    , array('msg' => 'Depot_Content', 'prmsn' => 'DepotContent', 'lnk' => SITE_LINK . 'Stock/DepotContent', 'icon' => 'fa fa-archive')
                    , array('msg' => 'data_collector_adjust', 'prmsn' => 'data_collector_adjust', 'lnk' => SITE_LINK . 'Stock/adjustmentFiles', 'icon' => 'fa fa-archive')
                    , array('msg' => 'assign_product_quantity', 'prmsn' => 'assign_product_quantity', 'lnk' => SITE_LINK . 'Stock/add_assign', 'icon' => 'fa fa-archive')
                    , array('msg' => 'assign_product_quantity_list', 'prmsn' => 'assign_product_quantity_list', 'lnk' => SITE_LINK . 'Stock/assign_list', 'icon' => 'fa fa-archive')
                    , array('msg' => 'act_assign_product_quantity', 'prmsn' => 'act_assign_product_quantity', 'lnk' => SITE_LINK . 'Stock/add_assign/act', 'icon' => 'fa fa-archive')
                    , array('msg' => 'act_assign_product_quantity_list', 'prmsn' => 'act_assign_product_quantity_list', 'lnk' => SITE_LINK . 'Stock/assign_list/act', 'icon' => 'fa fa-archive')
                    , array('msg' => 'adjust_product_quantity', 'prmsn' => 'adjust_product_quantity', 'lnk' => SITE_LINK . 'Stock/add_assign/adj', 'icon' => 'fa fa-archive')
                    , array('msg' => 'adjust_product_quantity_list', 'prmsn' => 'adjust_product_quantity_list', 'lnk' => SITE_LINK . 'Stock/assign_list/adj', 'icon' => 'fa fa-archive')
                    , array('msg' => 'act_adjust_product_quantity', 'prmsn' => 'act_adjust_product_quantity', 'lnk' => SITE_LINK . 'Stock/add_assign/act/adj', 'icon' => 'fa fa-archive')
                    , array('msg' => 'act_adjust_product_quantity_list', 'prmsn' => 'act_adjust_product_quantity_list', 'lnk' => SITE_LINK . 'Stock/assign_list/act/adj', 'icon' => 'fa fa-archive')
                    , array('msg' => 'stock_acc_adjust', 'prmsn' => 'stock_acc_adjust', 'lnk' => SITE_LINK . 'Stock/add_assign/acc', 'icon' => 'fa fa-archive')
                    , array('msg' => 'stock_acc_adjust_list', 'prmsn' => 'stock_acc_adjust_list', 'lnk' => SITE_LINK . 'Stock/stock_acc_adjust_list', 'icon' => 'fa fa-archive')
                    , array('msg' => 'act_stock_acc_adjust', 'prmsn' => 'act_stock_acc_adjust', 'lnk' => SITE_LINK . 'Stock/add_assign/acc/act', 'icon' => 'fa fa-archive')
                    , array('msg' => 'act_stock_acc_adjust_list', 'prmsn' => 'act_stock_acc_adjust_list', 'lnk' => SITE_LINK . 'Stock/stock_acc_adjust_list/act', 'icon' => 'fa fa-archive')
                )
            )
            , array('msg' => 'Transfers', 'prmsn' => 'StockTransfer', 'icon' => 'fa fa-share'
                , 'detail' => array(
                    array('msg' => 'Request_Order', 'prmsn' => 'RequestOrder', 'lnk' => SITE_LINK . 'Stock/RequestOrder', 'icon' => 'fa fa-plus')
                    , array('msg' => 'Transfer_Goods', 'prmsn' => 'TransferGoods', 'lnk' => SITE_LINK . 'Stock/RequestOrder/transfer', 'icon' => 'fa fa-plus')
                    , array('msg' => 'Request_List', 'prmsn' => 'RequestList', 'lnk' => SITE_LINK . 'Stock/RequestList', 'icon' => 'fa fa-th-list')
                    , array('msg' => 'Transfer_List', 'prmsn' => 'TransferList', 'lnk' => SITE_LINK . 'Stock/RequestList/transfer', 'icon' => 'fa fa-list-ul')
                    , array('msg' => 'request_details_report', 'prmsn' => 'request_details_report', 'lnk' => SITE_LINK . 'Stock/details_report/request', 'icon' => 'fa fa-list-ul')
                    , array('msg' => 'transfer_details_report', 'prmsn' => 'transfer_details_report', 'lnk' => SITE_LINK . 'Stock/details_report/transfer', 'icon' => 'fa fa-list-ul')
                )
            )
            , array('msg' => 'stock_damage', 'prmsn' => 'stock_damage', 'icon' => 'fa fa-stack-overflow'
                , 'detail' => array(
                    array('msg' => 'add_stock_damage', 'prmsn' => 'add_stock_damage', 'lnk' => SITE_LINK . 'Stock/add_damage', 'icon' => 'fa fa-stack-overflow')
                    , array('msg' => 'stock_damage_list', 'prmsn' => 'stock_damage_list', 'lnk' => SITE_LINK . 'Stock/damage_list', 'icon' => 'fa fa-stack-overflow')
                    , array('msg' => 'multi_product_damaged', 'prmsn' => 'multi_product_damaged', 'lnk' => SITE_LINK . 'Stock/multi_product_damaged', 'icon' => 'fa fa-stack-overflow')
                )
            )
            , array('msg' => 'report', 'prmsn' => 'StockReports', 'icon' => 'fa fa-share'
                , 'detail' => array(
                    array('msg' => 'Stock_Card', 'prmsn' => 'StockCard', 'lnk' => SITE_LINK . 'Stock/StockCard', 'icon' => 'fa fa-stack-overflow')
                    , array('msg' => 'consumed_item', 'prmsn' => 'consumed_item', 'lnk' => SITE_LINK . 'Stock/getConsumedProduct', 'icon' => 'fa fa-stack-overflow')
                    , array('msg' => 'damaged_items', 'prmsn' => 'DamagedItems', 'lnk' => SITE_LINK . 'Stock/DamagedItems', 'icon' => 'fa fa-stack-overflow')
                    //                    , array('msg' => 'multi_product_damaged', 'prmsn' => 'multi_product_damaged', 'lnk' => SITE_LINK . 'Stock/multi_product_damaged', 'icon' => 'fa fa-stack-overflow')
                    , array('msg' => 'stock_adjustments', 'prmsn' => 'stock_adjustments', 'lnk' => SITE_LINK . 'Stock/stock_adjustments', 'icon' => 'fa fa-stack-overflow')
                    , array('msg' => 'stock_transactions', 'prmsn' => 'stock_transactions', 'lnk' => SITE_LINK . 'Stock/stock_transactions', 'icon' => 'fa fa-stack-overflow')
                    , array('msg' => 'backdated_stock', 'prmsn' => 'backdated_stock', 'lnk' => SITE_LINK . 'Stock/backdated_stock', 'icon' => 'fa fa-stack-overflow')
                    , array('msg' => 'transfered_delivered_items', 'prmsn' => 'transfered_delivered_items', 'lnk' => SITE_LINK . 'Stock/transfered_delivered_items', 'icon' => 'fa fa-stack-overflow')
                )
            )
        );
        //
        $this->load->view('Stock', $vars);
    }

    public function ListDepot() {
        $vars['pageName'] = 'ListDepot';
        $vars['title'] = StockModel::getmsg('Depot_List');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg('Depot_List'), 'ListDepot']];
        $this->load->view('Stock/ListDepot', $vars);
    }

    public function details_report() {
        preg_match("/\/request\b/i", $_SERVER['REQUEST_URI'], $match_request);
        $vars['is_request'] = count($match_request) > 0 ? true : false;
        $vars['pageName'] = $vars['is_request'] ? 'request_details_report' : 'transfer_details_report';
        $vars['title'] = StockModel::getmsg($vars['is_request'] ? 'request_details_report' : 'transfer_details_report');
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg($vars['is_request'] ? 'request_details_report' : 'transfer_details_report'), 'details_report/' . ($vars['is_request'] ? 'request' : 'transfer')]];
        $this->load->view('Stock/details_report', $vars);
    }

    public function ViewDepot() {

        $vars['pageName'] = 'ViewDepot';
        $vars['title'] = StockModel::getmsg('depot_info');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        preg_match('/\/(\d+)$/', $_SERVER['REQUEST_URI'], $match);
        $vars['Depot_ID'] = count($match) > 0 ? $match[1] : 0;
        $vars['IsEdit'] = count($match) > 0 ? true : false;
        //        $vars['DepotInfo'] = $this->_registry->depot->getDepotInfo($vars['Depot_ID']);
        $vars['DepotProfile'] = $this->_registry->depot->getDepotProfile($match[1]);
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg('Depot_List'), 'ListDepot'], [StockModel::getmsg('depot_info'), 'ViewDepot/' . $match[1]]];
        $this->load->view('Stock/ViewDepot', $vars);
    }

    public function ProductLocationList() {

        $vars['pageName'] = 'MaterialLocation';
        $vars['title'] = StockModel::getmsg('Product_Location_list');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        //        $vars['all_products']    = $this->_registry->product->getMainProducts();
        //        $vars['all_depots']      = $this->_registry->depot->getDepots();
        $vars['all_uom'] = $this->_registry->material->getMaterialUOM();
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg('Product_Location_list'), 'ProductLocationList']];
        $this->load->view('Stock/ProductLocationList', $vars);
    }

    public function multi_product_location() {
        $vars['pageName'] = 'multi_product_location';
        $vars['title'] = StockModel::getmsg('multi_product_location');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg('multi_product_location'), 'multi_product_location']];
        $this->load->view('Stock/multi_product_location', $vars);
    }

    public function TransferGoods() {

        $vars['pageName'] = 'TransferGoods';

        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $vars['today'] = Date::getToday();
        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['Request_ID'] = $url[count($url) - 1];
        $vars['request_details'] = $this->_registry->depot->viewRequestDetails($vars['Request_ID']);
        $vars['Request'] = $this->_registry->depot->viewRequestList($vars['Request_ID']);
        //        echo"<pre>";die(print_r($vars['Request']));
        $vars['title'] = StockModel::getmsg($vars['Request'][0]['Status_ID'] != 3 ? 'Request_Order' : 'Transfer_Goods');
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg('Transfer_Goods'), 'TransferGoods/' . $vars['Request_ID']]];
        $this->load->view('Stock/TransferGoods', $vars);
    }

    public function view_transfer_details() {
        $vars['pageName'] = 'TransferGoods';
        $vars['title'] = StockModel::getmsg('Transfer_Goods');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $url = explode('/', $_SERVER['REQUEST_URI']);

        $request_id = $url[count($url) - 1];
        $request_details = $this->_registry->depot->viewRequestDetails($request_id);
        $Request = $this->_registry->depot->viewRequestList($request_id)[0];
        //echo '<pre>';
        //    print_r($Request);
        //        print_r($request_details);
        // die('ok');

        if ($Request['Status_ID'] == 3) {
            $temp_from = $Request['Req_To'];
            $Request['Req_To'] = $Request['Req_From'];
            $Request['Req_From'] = $temp_from;
        }
        $template_key = 'transfer_request';
        $template_row = Forms::build_print_template($template_key, $Request, array('transfer_details' => $request_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 TransferList() {

        $vars['pageName'] = 'TransferList';
        $vars['title'] = StockModel::getmsg('Transfer_List');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg('Transfer_List'), 'TransferList']];
        $this->load->view('Stock/TransferList', $vars);
    }

    public function RequestList() {


        $vars['today'] = Date::getToday();
        preg_match("/\/transfer\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['is_transfer'] = count($match) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_transfer'] ? 'TransferList' : 'RequestList';
        $vars['title'] = StockModel::getmsg($vars['is_transfer'] ? 'Transfer_List' : 'Request_List');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [$vars['title'], 'RequestList' . ($vars['is_transfer'] ? '/transfer' : '')]];
        $this->load->view('Stock/RequestList', $vars);
    }

    public function RequestOrder() {

        $vars['title'] = StockModel::getmsg('Request_Order');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        preg_match("/\/collector\b/i", $_SERVER['REQUEST_URI'], $match_c);
        $vars['is_data_collector'] = count($match_c) > 0 ? true : false;
        preg_match("/\/convert\b/i", $_SERVER['REQUEST_URI'], $match_convert);
        $vars['is_convert'] = count($match_convert) > 0 ? true : false;
        preg_match("/\/invoice\b/i", $_SERVER['REQUEST_URI'], $match_convert);
        $vars['is_invoice'] = count($match_convert) > 0 ? true : false;
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['IsEdit'] = is_numeric($url[count($url) - 1]) && !$vars['is_data_collector'] && !$vars['is_invoice'] ? true : false;
        if (!$vars['IsEdit']) {
            //            $vars['unique_id'] = 'req' . uniqid();
            //            smc_session()['duplicate_check'][$vars['unique_id']] = true;
            $vars['unique_id'] = token_unique::generate_token('req');
        }
        $vars['id'] = $vars['IsEdit'] || $vars['is_invoice'] ? $url[count($url) - 1] : 0;
        preg_match("/\/transfer\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['is_confirmed'] = count($match) > 0 ? true : false;

        $vars['pageName'] = $vars['is_confirmed'] ? 'TransferGoods' : 'RequestOrder';
        $vars['edit_arr'] = $vars['IsEdit'] ? $this->_registry->depot->getRequestorderByID($vars['id']) : ($vars['is_invoice'] ? $this->_registry->invoice->get_inv_to_transfer($vars['id']) : '');
        $vars['file_id'] = $vars['is_data_collector'] ? $url[count($url) - 1] : 0;
        $vars['collector_data'] = $vars['is_data_collector'] ? $this->_registry->invoice->invoiceFileData($vars['file_id']) : array();
//                echo"<pre>";print_r($vars['edit_arr']);die();
        $vars['is_actual'] = 0;
        $vars['check_lock'] = $vars['IsEdit'] ? CommonFunctions::check_lock_data(['type' => 'request', 'start_date' => $vars['edit_arr']['main']['Request_Date'], 'is_actual' => ($vars['is_actual'] ? 1 : 0)]) : '';

        $vars['is_main_transfer'] = ($vars['IsEdit'] && $vars['is_confirmed']) ? $vars['edit_arr']['main']['is_main_transfer'] : 0;
        $vars['today'] = Date::getToday();
        $vars['All_Depots_Not_PIC'] = $this->_registry->depot->getAllDepot();
        $vars['from_depot'] = $this->_registry->depot->getAllDepot(empty(smc_session()['user_accounts']['branch_id']) ? smc_session()['default_branch_id'] : smc_session()['user_accounts']['branch_id']);
        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
        $vars['org_address'] = $this->_registry->organization->getOrganizationPhysicalAddress();
        $vars['all_uom'] = $this->_registry->product->getUOM();
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg($vars['is_confirmed'] ? 'Transfer_List' : 'Request_List'), 'RequestList'], [StockModel::getmsg($vars['is_confirmed'] ? 'Transfer_Goods' : 'Request_Order'), 'RequestOrder' . ($vars['is_confirmed'] ? '/transfer' : '') . ( $vars['IsEdit'] ? '/' . $vars['id'] : '')]];
        $this->load->view('Stock/RequestOrder', $vars);
    }

    public function LoadingList() {

        $vars['pageName'] = 'ListDepot';

        $vars['title'] = StockModel::getmsg('Loaded_Depot');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $vars['today'] = Date::gettoday();
        $vars['loadingListToday'] = $this->_registry->LoadingOrder->viewTotalLoadByDate($vars['today'], null, 1);
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg('Loaded_Depot'), 'LoadingList']];
        $this->load->view('Stock/LoadingList', $vars);
    }

    public function DepotContent() {

        $vars['pageName'] = 'DepotContent';

        $vars['title'] = StockModel::getmsg('Depot_Content');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['today'] = Date::gettoday();
        $vars['all_uom'] = $this->_registry->material->getMaterialUOM();
        preg_match("/\/collector\b/i", $_SERVER['REQUEST_URI'], $match_c);
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['file_id'] = is_numeric($url[count($url) - 1]) ? ($url[count($url) - 1]) : 0;
        $vars['is_data_collector'] = count($match_c) > 0 ? 1 : 0;
        if ($vars['is_data_collector'] == 1 && !empty($vars['file_id']))
            $vars['adjustment_data'] = $this->_registry->depot->adjustmentFileData($vars['file_id']);
        $vars['is_depot_content'] = 1;
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg('Depot_Content'), 'DepotContent']];
        $this->load->view('Stock/DepotContent', $vars);
    }

    public function ViewTransfer() {

        $vars['pageName'] = 'ViewTransfer';
        $vars['title'] = StockModel::getmsg('Transfer_List');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $vars['org_details'] = $this->_registry->organization->getOrganizationDetails();
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['Request_ID'] = $url[count($url) - 1];
        $vars['request_details'] = $this->_registry->depot->viewRequestDetails($vars['Request_ID']);
        $vars['Request'] = $this->_registry->depot->viewRequestList($vars['Request_ID']);
        $vars['Depots_Info_To'] = $this->_registry->depot->getDepotInfo($vars['Request'][0]['Request_From']);
        $vars['Depots_Info_From'] = $this->_registry->depot->getDepotInfo($vars['Request'][0]['Request_To']);
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg('Transfer_List'), 'TransferList']];
        $this->load->view('Stock/ViewTransfer', $vars);
    }

    //    public function ItemsAgingReport() {
    //
    //        $vars['pageName'] = 'ItemsAgingReport';
    //        $vars['title'] = StockModel::getmsg('items_aging_report');
    //        $vars['system_name'] = StockModel::getmsg('stock_sys');
    //        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg('items_aging_report'), 'ItemsAgingReport']];
    //        $vars['result'] = $this->_registry->depot->agingReportItems();
    //        $vars['defCurrencySymbol'] = $this->_registry->symbol->getLocalCurrencySymbol();
    //        $this->load->view('Stock/ItemsAgingReport', $vars);
    //    }

    public function StockCard() {

        $vars['pageName'] = 'StockCard';
        $vars['title'] = StockModel::getmsg('Stock_Card');
        $vars['system_name'] = StockModel::getmsg('stock_sys');

        $vars['Trans_Type'] = $this->_registry->depot->getTransactionsProductType();
        $vars['today'] = $this->_registry->todate->getToday();
        $vars['year'] = date("Y", strtotime($vars['today'])); // get the year from today
        $vars['start_date'] = smc_session()['start_date'];
        $vars['Currency_Symbol'] = $this->_registry->symbol->getLocalCurrencySymbol();
        $vars['Currency_Default'] = $this->_registry->symbol->getDefaultCurrency();
        $vars['currency'] = $this->_registry->currency->GetLIListCurrency();
        $vars['All_Depot'] = $this->_registry->depot->getAllDepot();

        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg('Stock_Card'), 'StockCard']];

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

    public function DamagedItems() {

        $vars['pageName'] = 'DamagedItems';
        $vars['title'] = StockModel::getmsg('damaged_items');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $vars['today'] = Date::getToday();
        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['is_depot_content'] = 0;
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg('damaged_items'), 'DamagedItems']];
        $this->load->view('Stock/DamagedItems', $vars);
    }

    public function adjustmentFiles() {

        $vars['pageName'] = 'data_collector_adjust';
        $vars['title'] = inventoryModel::getmsg('data_collector_adjust');
        $vars['system_name'] = inventoryModel::getmsg('stock_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('stock'), 'Stock'], [inventoryModel::getmsg('data_collector_adjust'), 'adjustmentFiles']];


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

    public function appAdjustment() {

        $vars['pageName'] = 'data_collector_adjust';
        $vars['title'] = StockModel::getmsg('data_collector_adjust');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['file_id'] = strtolower($url[count($url) - 1]);
        //        $vars['adjustment_data'] = $this->_registry->depot->adjustmentFileData($vars['file_id']);
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [StockModel::getmsg('data_collector_adjust'), 'appAdjustment']];
        $this->load->view('Stock/appAdjustment', $vars);
    }

    public function getConsumedProduct() {
        $vars['pageName'] = 'consumed_item';
        $vars['title'] = inventoryModel::getmsg('getConsumedProduct');
        $vars['system_name'] = inventoryModel::getmsg('stock_sys');
        //        $vars['item_consumed'] = $this->_registry->depot->getConsumedProduct();
        $vars['today'] = Date::getToday();
        $vars['year'] = date("Y", strtotime($vars['today']));
        $vars['month'] = date("m", strtotime($vars['today']));
        $vars['breadCrumb'] = [[inventoryModel::getmsg('stock'), 'Stock'], [inventoryModel::getmsg('getConsumedProduct'), 'getConsumedProduct']];
        $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');

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

    public function stock_adjustments() {
        $vars['pageName'] = 'stock_adjustments';
        $vars['title'] = inventoryModel::getmsg('stock_adjustments');
        $vars['system_name'] = inventoryModel::getmsg('stock_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('stock'), 'Stock'], [inventoryModel::getmsg('stock_adjustments'), 'stock_adjustments']];

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

    public function stock_transactions() {
        $vars['pageName'] = 'stock_transactions';
        $vars['title'] = inventoryModel::getmsg('stock_transactions');
        $vars['system_name'] = inventoryModel::getmsg('stock_sys');
        $vars['get_paramters'] = $_GET;
        $vars['origin'] = 'stock';
        $vars['breadCrumb'] = [[inventoryModel::getmsg('stock'), 'Stock'], [inventoryModel::getmsg('stock_transactions'), 'stock_transactions']];

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

    public function backdated_stock() {
        $vars['pageName'] = 'backdated_stock';
        $vars['title'] = inventoryModel::getmsg('backdated_stock');
        $vars['system_name'] = inventoryModel::getmsg('stock_sys');
        $vars['get_paramters'] = $_GET;
        $vars['breadCrumb'] = [[inventoryModel::getmsg('stock'), 'Stock'], [inventoryModel::getmsg('backdated_stock'), 'backdated_stock']];

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

    public function multi_product_damaged() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['is_actual'] = count($match) > 0 ? true : false;
        $vars['pageName'] = $vars['is_actual'] ? 'act_multi_product_damaged' : 'multi_product_damaged';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'act_multi_product_damaged' : 'multi_product_damaged');
        $vars['system_name'] = inventoryModel::getmsg('stock_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('stock'), 'Stock'], [$vars['title'], 'multi_product_damaged' . ($vars['is_actual'] ? '/act' : '')]];

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

    public function add_damage() {

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

        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['IsEdit'] = is_numeric($url[count($url) - 1]) ? 1 : 0;
        if (!$vars['IsEdit']) {
            $vars['unique_id'] = token_unique::generate_token('damage');
        }
        $vars['id'] = $vars['IsEdit'] ? $url[count($url) - 1] : 0;
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['is_actual'] = count($match) > 0 ? true : false;

        $vars['pageName'] = $vars['is_actual'] ? 'add_act_stock_damage' : 'add_stock_damage';
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? 'add_act_stock_damage' : 'add_stock_damage');
        $vars['edit_arr'] = $vars['IsEdit'] ? $this->_registry->depot->get_damage_by_id($vars['id']) : array();
        //        echo"<pre>";die(print_r($vars['edit_arr']));
        $vars['check_lock'] = $vars['IsEdit'] ? CommonFunctions::check_lock_data(['type' => 'damage', 'start_date' => $vars['edit_arr']['main']['damage_date'], 'is_actual' => ($vars['is_actual'] ? 1 : 0)]) : '';

        $vars['breadCrumb'] = [[inventoryModel::getmsg('stock'), 'Stock'], [$vars['title'], 'add_damage' . ($vars['is_actual'] ? '/act' : '')]];
        $vars['all_uom'] = $this->_registry->product->getUOM();

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

    public function damage_list() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['is_actual'] = count($match) > 0 ? true : false;
        $vars['pageName'] = $vars['is_actual'] ? 'act_stock_damage_list' : 'stock_damage_list';
        $vars['title'] = StockModel::getmsg($vars['is_actual'] ? 'act_stock_damage_list' : 'stock_damage_list');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $vars['today'] = Date::getToday();
        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [$vars['title'], 'damage_list' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Stock/damage_list', $vars);
    }

    public function add_assign() {

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

        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['IsEdit'] = is_numeric($url[count($url) - 1]) ? 1 : 0;

        if (!$vars['IsEdit']) {
            $vars['unique_id'] = token_unique::generate_token('assign');
        }
        $vars['id'] = $vars['IsEdit'] ? $url[count($url) - 1] : 0;
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['is_actual'] = count($match) > 0 ? true : false;
        preg_match("/\/acc\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['is_acc'] = count($match) > 0 ? true : false;
        preg_match("/\/adj\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['is_adjust'] = count($match) > 0 ? 1 : 0;

        $vars['pageName'] = $vars['is_actual'] ? ($vars['is_adjust'] ? 'act_adjust_product_quantity' : ($vars['is_acc'] ? 'act_stock_acc_adjust' : 'act_assign_product_quantity')) : ($vars['is_adjust'] ? 'adjust_product_quantity' : ($vars['is_acc'] ? 'stock_acc_adjust' : 'assign_product_quantity'));
        $vars['title'] = inventoryModel::getmsg($vars['is_actual'] ? ($vars['is_adjust'] ? 'act_adjust_product_quantity' : ($vars['is_acc'] ? 'act_stock_acc_adjust' : 'act_assign_product_quantity')) : ($vars['is_adjust'] ? 'adjust_product_quantity' : ($vars['is_acc'] ? 'stock_acc_adjust' : 'assign_product_quantity')));
        $vars['edit_arr'] = $vars['IsEdit'] ? ($vars['is_acc'] ? $this->_registry->depot->get_stock_acc_adjust_by_id($vars['id']) : $this->_registry->depot->get_assign_by_id($vars['id'])) : array();
//                echo"<pre>";die(print_r($vars['edit_arr']));
        $vars['check_lock'] = $vars['IsEdit'] ? CommonFunctions::check_lock_data(['type' => 'assign', 'start_date' => $vars['edit_arr']['main'][$vars['is_acc'] ? 'adjust_date' : 'assign_date'], 'is_actual' => ($vars['is_actual'] ? 1 : 0)]) : '';

        $vars['breadCrumb'] = [[inventoryModel::getmsg('stock'), 'Stock'], [$vars['title'], 'add_assign' . ($vars['is_actual'] ? '/act' : '') . ($vars['is_adjust'] ? '/adj' : '') . ($vars['is_acc'] ? '/acc' : '')]];
        $vars['all_uom'] = $this->_registry->product->getUOM();
        $vars['CurList'] = CurrencyFactory::GetLIListCurrency();
        $vars['DefaultCurrencyID'] = $this->_registry->currency->getDefaultCurrency();
        $vars['currency_data'] = $this->_registry->currency->getCurrencyByID($vars['DefaultCurrencyID']);
        $vars['Extable'] = $this->_registry->currency->getExchangeRateTable();


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

    public function assign_list() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['is_actual'] = count($match) > 0 ? true : false;
        preg_match("/\/adj\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['is_adjust'] = count($match) > 0 ? 1 : 0;
        $vars['pageName'] = $vars['is_actual'] ? ($vars['is_adjust'] ? 'act_adjust_product_quantity_list' : 'act_assign_product_quantity_list') : ($vars['is_adjust'] ? 'adjust_product_quantity_list' : 'assign_product_quantity_list');
        $vars['title'] = StockModel::getmsg($vars['is_actual'] ? ($vars['is_adjust'] ? 'act_adjust_product_quantity_list' : 'act_assign_product_quantity_list') : ($vars['is_adjust'] ? 'adjust_product_quantity_list' : 'assign_product_quantity_list'));
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $vars['today'] = Date::getToday();
        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [$vars['title'], 'assign_list' . ($vars['is_actual'] ? '/act' : '') . ($vars['is_adjust'] ? '/adj' : '')]];
        $this->load->view('Stock/assign_list', $vars);
    }

    public function confirm_delivered_items() {
        $vars['pageName'] = 'confirm_delivered_items';
        $vars['title'] = StockModel::getmsg('confirm_delivered_items');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $vars['today'] = Date::getToday();
        $vars['all_depots'] = $this->_registry->depot->getDepots();
        $vars['all_uom'] = $this->_registry->product->getUOM();

        $url = explode('/', $_SERVER['REQUEST_URI']);
        $vars['id'] = $url[count($url) - 1];
        $vars['edit_arr'] = $this->_registry->depot->getRequestorderByID($vars['id']);
//        echo"<pre>";die(print_r($vars['edit_arr']));
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [$vars['title'], 'confirm_delivered_items']];
        $this->load->view('Stock/confirm_delivered_items', $vars);
    }

    public function transfered_delivered_items() {
        $vars['pageName'] = 'transfered_delivered_items';
        $vars['title'] = inventoryModel::getmsg('transfered_delivered_items');
        $vars['system_name'] = inventoryModel::getmsg('stock_sys');
        $vars['breadCrumb'] = [[inventoryModel::getmsg('stock'), 'Stock'], [$vars['title'], 'transfered_delivered_items']];

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

    public function stock_acc_adjust_list() {
        preg_match("/\/act\b/i", $_SERVER['REQUEST_URI'], $match);
        $vars['is_actual'] = count($match) > 0 ? true : false;

        $vars['pageName'] = $vars['is_actual'] ? 'act_stock_acc_adjust_list' : 'stock_acc_adjust_list';
        $vars['title'] = StockModel::getmsg($vars['is_actual'] ? 'act_stock_acc_adjust_list' : 'stock_acc_adjust_list');
        $vars['system_name'] = StockModel::getmsg('stock_sys');
        $vars['today'] = Date::getToday();
        $vars['breadCrumb'] = [[StockModel::getmsg('stock'), 'Stock'], [$vars['title'], 'stock_acc_adjust_list' . ($vars['is_actual'] ? '/act' : '')]];
        $this->load->view('Stock/stock_acc_adjust_list', $vars);
    }

    public function view_damage() {
        $vars['title'] = ACCModel::getmsg('stock_sys');
        $vars['system_name'] = ACCModel::getmsg('damage');
        $url = explode('/', $_GET['url']);
        $id = $url[count($url) - 1];
        $data = $this->_registry->depot->get_damage_by_id($id);
        $vars['pageName'] = $data['main']['is_actual'] == 1 ? 'view_act_stock_damage' : 'view_stock_damage';
        $template_row = Forms::build_print_template('damage', $data['main'], array('details' => $data['details']));
        $this->load->view_html($template_row['html'], $vars);
        exit;
    }
    public function View_adjust() {
        $vars['title'] = ACCModel::getmsg('adjust');
        $vars['system_name'] = ACCModel::getmsg('adjust');
        $url = explode('/', $_GET['url']);
        $id = $url[count($url) - 1];
        $data = $this->_registry->depot->get_assign_by_id($id);
        // echo "<pre>";print_r($data);die();
        $vars['pageName'] =   'view_adjust_product_quantity';
        $template_row = Forms::build_print_template('adjust', $data['main'], array('details' => $data['details']));
        $this->load->view_html($template_row['html'], $vars);
        exit;
    }

}
