load->helper("accounts"); $this->load->library("myaccounts"); checkLogin(); } public function _remap($alias = "", $params = array()) { $data['dataValue'] = $this->session; $data['pageTitle'] = "Accounting Vouchers"; switch ($alias) { case 'print': $voucher_id = $this->uri->segment(4); $VoucherPDF = $this->myaccounts->voucherPDF($voucher_id); $data['PDFFile'] = site_url("pdf/vouchers/" . $VoucherPDF); if (isset($_GET['modal'])) $this->load->view("accounts/pdfviewer", $data); else loadView("accounts/pdfviewer", $data); break; case 'listvouchers': $data['pageTitle'] = "Vouchers"; $data['fiscalStart'] = NepaliDate($this->session->userdata['FiscalYear']->fiscalyear_from); $data['fiscalEnd'] = NepaliDate($this->session->userdata['FiscalYear']->fiscalyear_to); $fromDate_bs = isset($_GET['from_date']) ? $_GET['from_date'] : firstDayOfNepaliMonth(); $todate_bs = isset($_GET['to_date']) ? $_GET['to_date'] : NepaliDate(Today()); $fromDate_ad = NepaliToEnglishDate($fromDate_bs); $toDate_ad = NepaliToEnglishDate($todate_bs); $data['fromDate_bs'] = $fromDate_bs; $data['toDate_bs'] = $todate_bs; $data['fromDate_ad'] = $fromDate_ad; $data['toDate_ad'] = $toDate_ad; $data['VoucherTypes']=$this->myaccounts->getVoucherTypes(); loadView("accounts/vouchers/listvouchers", $data); break; case 'addvoucher': $data['pageTitle'] = "Journal Voucher"; if (isset($_POST['submit']) && !isVoucherExists($_POST['voucher_no'])) { $TableData = array( 'voucher_no' => filter_var($_POST['voucher_no']), 'voucher_ref' => "JV" . filter_var($_POST['voucher_no']), // If the voucher is raised against other transactions 'voucher_date' => NepaliToEnglishDate(filter_var($_POST['voucher_date'])), 'voucher_state' => 'Entered', // Different stages of voucher Entered/Reversed/Cancel/Deleted/Locked/Draft etc. 'voucher_type' => 'Journal', //Different types of Vouchers like Cash/Bank/Payment/Receipt/advance etc. 'fiscalyear_id' => $this->session->userdata("FiscalYearID"), 'branch_id' => $this->session->userdata("BranchID"), 'created_by' => $this->session->userdata("loggedUser"), 'created_on' => date('Y-m-d H:i:s'), 'remarks' => filter_var($_POST['remarks']), 'status' => 1 ); $this->db->insert('tbl_vouchers', $TableData); $voucher_id = $this->db->insert_id(); $account_ids = $_POST['account_ids']; $narrations = $_POST['narration']; $debits = $_POST['debit']; $credits = $_POST['credit']; $entry_no = 0; for ($entry_no = 0; $entry_no < sizeof($account_ids); $entry_no++) { $TableData = array(); $TableData = array( 'voucher_id' => $voucher_id, 'entry_no' => $entry_no, 'transaction_date' => NepaliToEnglishDate(filter_var($_POST['voucher_date'])), 'account_id' => $account_ids[$entry_no], 'narration' => $narrations[$entry_no], 'dr' => $debits[$entry_no], 'cr' => $credits[$entry_no], // 'cheque' => filter_var($_POST['cheque']), // 'cheque_details' => filter_var($_POST['cheque_details']), 'currency' => 'NPR', // 'exrate' => filter_var($_POST['exrate']), // 'fcdr' => filter_var($_POST['fcdr']), // 'fccr' => filter_var($_POST['fccr']), 'branch_id' => $this->session->userdata("BranchID"), 'fiscalyear_id' => $this->session->userdata("FiscalYearID"), 'created_on' => date('Y-m-d H:i:s'), 'created_by' => $this->session->userdata("loggedUser"), // 'remarks' => filter_var($_POST['remarks']), 'status' => 1 ); $this->db->insert('tbl_voucherdetails', $TableData); } redirect("accounts/vouchers/print/" . $voucher_id); break; } loadView("accounts/vouchers/addvoucher", $data); break; case 'voucherdetails': $voucher_id = $this->uri->segment(4); $Voucher = $this->db->where("voucher_id", $voucher_id)->get("tbl_vouchers")->row(); $Voucher->Details = $this->db->where("voucher_id", $voucher_id)->get("tbl_voucherdetails")->result(); $data['Voucher'] = $Voucher; $this->load->view("accounts/vouchers/voucherdetails", $data); break; case 'show_voucher': $data['pageTitle'] = "Voucher Entries"; $voucher_id = $this->uri->segment(4); $Voucher = $this->db->where("voucher_id", $voucher_id)->get("tbl_vouchers")->row(); if($Voucher) { $Voucher->Details = $this->db->where("voucher_id", $voucher_id)->get("tbl_voucherdetails")->result(); $data['Voucher'] = $Voucher; $data['voucher_id'] = $voucher_id; loadview("accounts/vouchers/show_voucher", $data); } break; case 'reversal': $voucher_id = $this->uri->segment(4); if (isVoucherReverseable($voucher_id)) : $VoucherDetails = $this->db->where("voucher_id", $voucher_id)->get("tbl_voucherdetails")->result(); $entry_no = 0; foreach ($VoucherDetails as $VoucherDetail) : $TableData = array( 'voucher_id' => $voucher_id, 'entry_no' => $entry_no, 'transaction_date' => $VoucherDetail->transaction_date, 'account_id' => $VoucherDetail->account_id, 'narration' => "Reversal of Voucher #" . getFieldfromValue("tbl_vouchers", "voucher_no", "voucher_id", $VoucherDetail->voucher_id), 'dr' => $VoucherDetail->cr, 'cr' => $VoucherDetail->dr, // 'cheque' => filter_var($_POST['cheque']), // 'cheque_details' => filter_var($_POST['cheque_details']), 'currency' => 'NPR', // 'exrate' => filter_var($_POST['exrate']), // 'fcdr' => filter_var($_POST['fcdr']), // 'fccr' => filter_var($_POST['fccr']), 'branch_id' => $this->session->userdata("BranchID"), 'fiscalyear_id' => $this->session->userdata("FiscalYearID"), 'created_on' => date('Y-m-d H:i:s'), 'created_by' => $this->session->userdata("loggedUser"), // 'remarks' => filter_var($_POST['remarks']), 'status' => 1 ); $this->db->insert('tbl_voucherdetails', $TableData); $entry_no++; endforeach; $this->db->where("voucher_id", $voucher_id)->set("voucher_state", 'Reversed')->update("tbl_vouchers"); endif; redirect("accounts/vouchers/listvouchers"); break; case 'saveaccount': if (isset($_POST['submit'])) { if (!$this->checkifAccountExists($_POST['account_name'])) { $TableData = array( 'accategory_id' => filter_var($_POST['accategory_id']), // 'account_code' => generateAccountCode(filter_var($_POST['account_code'])), 'account_name' => filter_var($_POST['account_name']), // 'account_type' => filter_var($_POST['account_type']), // 'account_plcategory' => filter_var($_POST['account_plcategory']), // 'account_currency' => filter_var($_POST['account_currency']), // 'account_partyname' => filter_var($_POST['account_partyname']), // 'account_partyaddress' => filter_var($_POST['account_partyaddress']), // 'account_partypan' => filter_var($_POST['account_partypan']), // 'account_partycontact' => filter_var($_POST['account_partycontact']), // 'account_partyemail' => filter_var($_POST['account_partyemail']), // 'account_partycontactperson' => filter_var($_POST['account_partycontactperson']), // 'account_partycontactpersoncontact' => filter_var($_POST['account_partycontactpersoncontact']), 'created_on' => date('Y-m-d H:i:s'), 'created_by' => 'admin', 'remarks' => filter_var($_POST['remarks']), 'status' => 1, ); $this->db->insert('tbl_accounts', $TableData); $account_id = $this->db->insert_id(); $voucherData = array( "voucher_id" => 0, "transaction_date" => date("Y-m-d"), "account_id" => $account_id, "Dr" => 0, "Cr" => 0, "fiscalyear_id" => $this->session->userdata['FiscalYearID'], "created_on" => date('Y-m-d H:i:s'), "branch_id" => $this->session->userdata("BranchID"), "created_by" => $this->session->userdata("loggedUser"), "remarks" => "Opening Balance Entry", "status" => 1 ); if ($_POST['opening_balance_drcr'] == "DR") $voucherData['Dr'] = $_POST['opening_balance']; if ($_POST['opening_balance_drcr'] == "CR") $voucherData['Cr'] = $_POST['opening_balance']; $this->db->insert('tbl_voucherdetails', $voucherData); redirect("accounts/accountheads/list"); } else { echo "Account Head Name Already Exists"; die; } } loadView("accounts/accountheads/add", $data); break; default: if ($VoucherType = $this->myaccounts->getVoucherType($alias)) { $this->processVoucher($VoucherType); break; } loadView("accounts/vouchers/listvouchers", $data); } } private function processVoucher($VoucherType) { $data['pageTitle'] = $VoucherType->voucher_name; $data['VoucherType'] = $VoucherType; $data['fiscalStart'] = NepaliDate($this->session->userdata['FiscalYear']->fiscalyear_from); $data['fiscalEnd'] = NepaliDate($this->session->userdata['FiscalYear']->fiscalyear_to); $command = $this->uri->segment(4); switch ($command) { case 'create': $voucher_no = generateVoucherNo($VoucherType->vouchertype_id); if (isset($_POST['submit'])) { $TableData = array( 'voucher_no' => $voucher_no, 'voucher_ref' => $VoucherType->vouchertype_id, 'voucher_date' => NepaliToEnglishDate(filter_var($_POST['voucher_date'])), 'voucher_state' => 'Entered', // Different stages of voucher Entered/Reversed/Cancel/Deleted/Locked/Draft etc. 'voucher_type' => $VoucherType->vouchertype_id, //Different types of Vouchers like Cash/Bank/Payment/Receipt/advance etc. 'fiscalyear_id' => $this->session->userdata("FiscalYearID"), 'branch_id' => $this->session->userdata("BranchID"), 'created_by' => $this->session->userdata("loggedUser"), 'created_on' => date('Y-m-d H:i:s'), // 'remarks' => filter_var($_POST['remarks']), 'status' => 1 ); $this->db->insert('tbl_vouchers', $TableData); $voucher_id = $this->db->insert_id(); $account_ids = $_POST['account_ids']; $narration = $_POST['narration']; $debits = $_POST['debit']; $credits = $_POST['credit']; $entry_no = 0; $entryTotal = 0; for ($entry_no = 0; $entry_no < sizeof($account_ids); $entry_no++) { $TableData = array(); $entryTotal += $debits[$entry_no]; $TableData = array( 'voucher_id' => $voucher_id, 'entry_no' => $entry_no, 'transaction_date' => NepaliToEnglishDate(filter_var($_POST['voucher_date'])), 'account_id' => $account_ids[$entry_no], 'narration' => $narration, 'dr' => $debits[$entry_no], 'cr' => $credits[$entry_no], // 'cheque' => isset($_POST['cheque_number']) ? $_POST['cheque_number'][$entry_no] : "", // 'cheque_details' => isset($_POST['cheque_details']) ? $_POST['cheque_details'][$entry_no] : "", 'currency' => 'NPR', // 'exrate' => filter_var($_POST['exrate']), // 'fcdr' => filter_var($_POST['fcdr']), // 'fccr' => filter_var($_POST['fccr']), 'branch_id' => $this->session->userdata("BranchID"), 'fiscalyear_id' => $this->session->userdata("FiscalYearID"), 'created_on' => date('Y-m-d H:i:s'), 'created_by' => $this->session->userdata("loggedUser"), // 'remarks' => filter_var($_POST['remarks']), 'status' => 1 ); //pre($TableData);die; $this->db->insert('tbl_voucherdetails', $TableData); } $entry_no++; // echo json_encode(['status' => 'success']); loadview("accounts/vouchers/create", $data); break; } loadview("accounts/vouchers/create", $data); // loadview("accounts/vouchers/$VoucherType->voucher_alias/create", $data); break; default: // $dirname = getcwd() . "/application/views/accounts/vouchers/$VoucherType->voucher_alias"; // $filename = $dirname . "/create.php"; // //echo getcwd() . "\n";die; // if (!file_exists($filename)) { // mkdir($dirname, 0777); // $this->createView($filename); // $filename = $dirname . "/list.php"; // $this->createListView($filename); // } $data['Vouchers'] = $this->db->where("status", 1)->where("voucher_type", $VoucherType->vouchertype_id)->get("tbl_vouchers")->result(); // echo '
' . $VoucherType->vouchertype_id; // print_r($VoucherType); // die(); // loadview("accounts/vouchers/$VoucherType->voucher_alias/list", $data); redirect("accounts/vouchers/listvouchers?vouchertypes=".$VoucherType->vouchertype_id); } } private function createView($filename) { $CreateFileContent = "\n"; file_put_contents($filename, $CreateFileContent); } private function createListView($filename) { $ListFileContent = "\n\n\n\n\n
\n\n\n\n\n\n\n\nCreate
\n voucher_options==\"\"): ?> voucher_options; ?>\n"; file_put_contents($filename, $ListFileContent); } function checkifAccountExists($account_name) { return ($this->db->query("select * from tbl_accounts where UPPER(account_name)='" . strtoupper($account_name) . "'")->num_rows() > 0) ? true : false; } }\n\n\n\n\n
\n\n\n\n\n\n\n\n
ID# Voucher No Voucher Date Voucher Type Voucher State Action voucher_id; ?>\" class=\"voucher_state==\"Reversed\")?\"table-danger\":\"\"; ?>\">\n voucher_id; ?> voucher_no; ?> voucher_date; ?> voucher_type; ?> voucher_state; ?> \n );\" class=\"btn btn-success btn-xs\" title=\"View Details\">\n\n \n\n