load->helper("accounts"); checkLogin(); } public function _remap($alias = "", $params = array()) { $data['dataValue'] = $this->session; // echo "
"; print_r($_GET['accategory_id']);die();

        $data['pageTitle'] = "Account Head";
        switch ($alias) {
            case 'navigate':
                $data['pageTitle'] = "Ledger";
                $AccountGroups = $this->db->where("status", 1)->get("tbl_acgroups")->result();
                foreach ($AccountGroups as $AccountGroup) {
                    // $AccountGroup->AccountCategories = $this->db->where("status", 1)->where("acgroup_id", $AccountGroup->acgroup_id)->get("tbl_accategories")->result();
                                    $AccountGroup->AccountCategories = $this->db->where("status", 1)->where("accategory_id ", ($_GET['accategory_id'] ?? ""))->get("tbl_accategories")->result();

                }
                $data['AccountGroups'] = $AccountGroups;
                // echo "
"; print_r($data['AccountGroups']);die();

                loadView("accounts/ledger/navigate", $data);
                break;
            case 'getledgersummary':
                $account_id = $this->uri->segment(3);
                $data['pageTitle'] = "Ledger";
                $Transactions = $this->db->where("status", 1)->where("account_id", $account_id)->get("tbl_voucherdetails")->result();
                $Account = $this->db->where("status", 1)->where("account_id", $account_id)->get("tbl_accounts")->row();
                foreach ($Transactions as $T) {
                    //$T->AccountCategory=$this->db->where("status",1)->where("accategory_id",$AccountGroup->acgroup_id)->get("tbl_accategories")->result();
                    $T->Voucher = $this->db->where("status", 1)->where("voucher_id", $T->voucher_id)->get("tbl_vouchers")->row();
                }
                $data['Transactions'] = $Transactions;
                $data['Account'] = $Account;
                $data['account_id'] = $account_id;
                $this->load->view("accounts/ledgersummary", $data);
                break;
            case 'partyledger':
                // $data['fiscalStart'] = NepaliDate($this->session->userdata['FiscalYear']->fiscalyear_from);
                // $data['fiscalEnd'] = NepaliDate($this->session->userdata['FiscalYear']->fiscalyear_to);
                // $_GET['show_ledger'];
                
                if (!isset($_GET['from_date'])) {
                    $data['from_date'] = null;
                }
                if (!isset($_GET['to_date'])) {
                    $data['to_date'] = null;
                }
                if (isset($_GET)) {
                    $data = $_GET;
                }
                $data['pageTitle'] = "View Party Ledger";
                $data['fiscalStart'] =  NepaliToEnglishDate($data['fromDate'] ?? $this->session->userdata['FiscalYear']->fiscalyear_from);
                $data['fiscalEnd'] = NepaliToEnglishDate($data['toDate'] ?? $this->session->userdata['FiscalYear']->fiscalyear_to);
                  

                if (isset($_GET['show_ledger'])) {
                    $fromDate_Nepali=$data['from_date'];
                    $toDate_Nepali =$data['to_date'];
                    $data['fromDate'] = NepaliToEnglishDate($fromDate_Nepali);
                    $data['toDate'] = NepaliToEnglishDate($toDate_Nepali);
                    $data['fromDate_Nepali'] = $fromDate_Nepali;
                    $data['toDate_Nepali'] = $toDate_Nepali;
                    $data['account_id'] = $_GET['account_id'];
                }
                loadView("accounts/ledger/partywise", $data);
                break;
            case 'print': 
                $account_id = $this->uri->segment(4);
                $fromDate=(isset($_GET['from_date'])?$_GET['from_date']:NepaliDate(($this->session->userdata('FiscalYear'))->fiscalyear_from));
                $toDate=(isset($_GET['to_date'])?$_GET['to_date']:NepaliDate(($this->session->userdata('FiscalYear'))->fiscalyear_to));
                $LedgerPDF=$this->myaccounts->ledgerPDF($account_id,NepaliToEnglishDate($fromDate), NepaliToEnglishDate($toDate));
                $data['PDFFile']=site_url("pdf/ledgers/".$LedgerPDF);
                if(isset($_GET['modal']))
                $this->load->view("accounts/pdfviewer",$data);
                else
                loadView("accounts/pdfviewer",$data);
                break;                           
            case 'getaccountbalance':
                $account_id = $this->uri->segment(4);
                $AccountDetails=$this->myaccounts->getAccountDetails($account_id);
                $AccountDetails->BalanceRaw=$AccountDetails->Balance;
                $AccountDetails->Balance=myCurrency($AccountDetails->Balance);
                echo json_encode($AccountDetails);
                break;
            case 'day_book':
                $data['pageTitle'] = "Day Book";               
                loadView("accounts/daybook", $data);
                break;
            case 'bank_book':
                if (!isset($_POST['fromDate'])) {
                    $data['fromDate'] = null;
                }
                if (!isset($_POST['toDate'])) {
                    $data['toDate'] = null;
                }
                if (isset($_POST)) {
                    $data = $_POST;
                }
                $data['fiscalStart'] =  NepaliToEnglishDate($data['fromDate'] ?? $this->session->userdata['FiscalYear']->fiscalyear_from);
                $data['fiscalEnd'] = NepaliToEnglishDate($data['toDate'] ?? $this->session->userdata['FiscalYear']->fiscalyear_to);
               
                // $data['fiscalStart'] = NepaliDate($this->session->userdata['FiscalYear']->fiscalyear_from);
                // $data['fiscalEnd'] = NepaliDate($this->session->userdata['FiscalYear']->fiscalyear_to);
                $data['pageTitle'] = "Bank Book";               
                loadView("accounts/ledger_bankbook", $data);
                break;
            case 'cash_book':

                if (!isset($_POST['fromDate'])) {
                    $data['fromDate'] = null;
                }
                if (!isset($_POST['toDate'])) {
                    $data['toDate'] = null;
                }
                if (isset($_POST)) {
                    $data = $_POST;
                }
                $data['fiscalStart'] =  NepaliToEnglishDate($data['fromDate'] ?? $this->session->userdata['FiscalYear']->fiscalyear_from);
                $data['fiscalEnd'] = NepaliToEnglishDate($data['toDate'] ?? $this->session->userdata['FiscalYear']->fiscalyear_to);
               
                // $data['fiscalStart'] = NepaliDate($this->session->userdata['FiscalYear']->fiscalyear_from);
                // $data['fiscalEnd'] = NepaliDate($this->session->userdata['FiscalYear']->fiscalyear_to);
                $data['pageTitle'] = "Cash Book";               
                loadView("accounts/ledger_cashbook", $data);
                break;
            case 'receiveables':
                $data['pageTitle'] = "Accounts Receivables";               
                loadView("accounts/ledger_receiveables", $data);
                break;
            case 'payables':
                $data['pageTitle'] = "Accounts Payables";               
                loadView("accounts/ledger_payables", $data);
                break;
            default:
                $data['pageTitle'] = "Ledger";
                $Accounts = $this->db->where("status", 1)->get("tbl_accounts")->result();
                foreach ($Accounts as $Account) :


                endforeach;
                $AccountGroups = $this->db->where("status", 1)->get("tbl_acgroups")->result();
                $data['Accounts'] = $Accounts;
                $data['AccountGroups'] = $AccountGroups;
                loadView("accounts/ledgerall", $data);
                break;
        }
    }
}