Image(site_url("images/logo.png"), 8, 10, 40); $this->SetFont('Helvetica', 'B', 12); $this->Cell(0, 10, $this->HeaderText, 0, 1, 'C'); $this->SetFont('Helvetica', 'B', 10); $this->Cell(0, 10, $this->SubHeaderText, 0, 1, 'C'); $this->SetFont('Helvetica', '', 8); $this->Cell(0, 10, "Printed On: " . Today() . " / " . NepaliDate(Today()), 0, 0, 'R'); if (isset($this->HeaderColumns)) { $this->Ln(); $this->SetFillColor(232, 232, 232); $this->SetFont('Helvetica', 'B', 10); //$pdf->SetXY(10, 40); foreach ($this->HeaderColumns as $column) { $this->Cell($column['width'], 10, strtoupper($column['name']), 1, 0, 'L', 1); } $this->Ln(); } // Line break // $this->Ln(20); } function Footer() { // Page footer //$this->SetY(-70); $this->ln(20); $this->SetFont('Helvetica', 'I', 8); $this->Cell(25, 1, $this->printedBy, 0, 1, 'C'); $this->Cell(25, 1, '_________________', 0, 0, 'C'); $this->setX(95); $this->Cell(25, 1, '_________________', 0, 0, 'C'); $this->setX(170); $this->Cell(25, 1, '_________________', 0, 1, 'C'); $this->Cell(25, 10, 'Printed By', 0, 0, 'C'); $this->setX(95); $this->Cell(25, 10, 'Checked By', 0, 0, 'C'); $this->setX(170); $this->Cell(25, 10, 'Approved By', 0, 1, 'C'); $this->SetFont('Helvetica', 'I', 8); $this->SetTextColor(128); $this->Cell(0, 10, 'Page ' . $this->PageNo(), 0, 0, 'C'); } } class myaccounts { public function __construct() { // die; $this->initDatabase(); } function voucherPDF($voucher_id) { $CI = &get_instance(); $CI->load->library("numbertoword"); $q = "select *,(select voucher_no from tbl_vouchers where tbl_vouchers.voucher_id=tbl_voucherdetails.voucher_id) as voucher_no, (select account_name from tbl_accounts where tbl_accounts.account_id=tbl_voucherdetails.account_id) as account_name from tbl_voucherdetails where voucher_id='$voucher_id'"; $VoucherDetails = $CI->db->query($q)->result(); $i = 0; $crTotal = 0; $drTotal = 0; $fields = array(); // print_r($VoucherDetails);die; foreach ($VoucherDetails as $VoucherDetail) : $i++; $fields['account_name_' . $i] = $VoucherDetail->account_name; $fields['narration_' . $i] = $VoucherDetail->narration; $fields['debit_amount_' . $i] = ($VoucherDetail->dr == 0) ? "" : N2($VoucherDetail->dr); $fields['credit_amount_' . $i] = ($VoucherDetail->cr == 0) ? "" : N2($VoucherDetail->cr); $crTotal += $VoucherDetail->cr; $drTotal += $VoucherDetail->dr; endforeach; $fields['voucher_no'] = $VoucherDetails[0]->voucher_no; $fields['transaction_date_ad'] = $VoucherDetails[0]->transaction_date; $fields['transaction_date_bs'] = NepaliDate($VoucherDetails[0]->transaction_date); $fields['prepared_by'] = $VoucherDetails[0]->created_by; $fields['voucher_no'] = $VoucherDetails[0]->voucher_no; $fields['debit_total'] = N2($drTotal); $fields['credit_total'] = N2($crTotal); if ($CI->session->userdata("language") == "np") $fields['amount_in_words'] = trim($CI->numbertoword->nepali_word($crTotal)); else $fields['amount_in_words'] = trim($CI->numbertoword->english_word($crTotal)); // $fields['narration_' . $i] = $VoucherDetail->narration; $file = APPPATH . "/../pdf/e_voucher1.pdf"; $pdf = new FPDM($file); //pre($pdf->getContent($file,"PDF")); $pdf->Load($fields, true); $pdf->Merge(); //$pdf->Flatten(); $OutputFileLocation = APPPATH . "/../pdf/vouchers/"; $OutputFile = "Voucher_" . $VoucherDetails[0]->voucher_no . ".pdf"; $pdf->Output("F", $OutputFileLocation . $OutputFile); return $OutputFile; } function getVoucherTypes() { $CI = &get_instance(); $VoucherType = $CI->db->query("select * from tbl_vouchertypes where status=1 order by voucher_name asc"); return ($VoucherType->num_rows() > 0) ? $VoucherType->result() : false; } function getVoucherType($vouchertype_alias) { $CI = &get_instance(); if (ctype_digit($vouchertype_alias)) { $t = "select * from tbl_vouchertypes where vouchertype_id='$vouchertype_alias'"; $VoucherType = $CI->db->query($t); // echo $t; } else { $t = "select * from tbl_vouchertypes where voucher_alias='$vouchertype_alias'"; $VoucherType = $CI->db->query($t); // echo $t; } return ($VoucherType->num_rows() > 0) ? $VoucherType->row() : false; } function getAccountDetails($account_id) { $CI = &get_instance(); $Account = $CI->db->query("select * from tbl_accounts where account_id='$account_id'")->row(); $Account->Balance = $this->getBalance($account_id); return $Account; } function getBalance($account_id) { $drTotal = getDrTotal($account_id); $crTotal = getCrTotal($account_id); return $drTotal - $crTotal; } function getOldBalance($account_id, $tillDate) { if ($tillDate == "") $tillDate = NepalitoEnglishDate(FYStart()); $t = "select sum(dr) as debitBalance, sum(cr) as creditBalance from tbl_voucherdetails where account_id='$account_id' and transaction_date< '$tillDate'"; $CI = &get_instance(); $Query = $CI->db->query($t); $Result = $Query->row(); $oldBalance = new stdClass; $oldBalance->debitBalance = $Result->debitBalance; $oldBalance->creditBalance = $Result->creditBalance; $oldBalance->balance = ($oldBalance->debitBalance - $oldBalance->creditBalance); return $oldBalance; } function getDrTotal($account_id) { $ci = &get_instance(); return $ci->db->where("status", 1)->where("account_id", $account_id)->select_sum('dr')->get("tbl_voucherdetails")->row()->dr; } function getCrTotal($account_id) { $ci = &get_instance(); return $ci->db->where("status", 1)->where("account_id", $account_id)->select_sum('cr')->get("tbl_voucherdetails")->row()->cr; } function getAllAccountsTable($accategory_id = "", $full = "") { $CI = &get_instance(); if ($accategory_id != "") { $CI->db->where("status", 1)->where("accategory_id", $accategory_id); } if (isset($_GET['accategory_id'])) { $CI->db->where("status", 1)->where("accategory_id", $_GET['accategory_id']); } else { $CI->db->where("status", 1); } $CI->db->order_by("account_name ASC"); $Accounts = $CI->db->get("tbl_accounts")->result(); foreach ($Accounts as $Account) { $Account->Group = $CI->db->query("select * from tbl_acgroups where acgroup_id=(select acgroup_id from tbl_accategories where accategory_id = $Account->accategory_id)")->row(); $Account->Category = $CI->db->query("select * from tbl_accategories where accategory_id = $Account->accategory_id")->row(); } //$q=$CI->db->get_compiled_select(); //print($q); ?>
showAccountsCategoriesCombo("accategory_id", "", "accategory_id"); ?>
"; $html .= ""; $html .= "AccountAccount GroupDrCrBalanceAction"; $html .= ""; $sn = 0; $BalanceTotal = 0; foreach ($Accounts as $Account) : $sn++; $balance = getBalance($Account->account_id); $BalanceTotal += $balance; // pre($Account); $html .= "" . $Account->account_name . "" . $Account->Category->accategory_name . "" . (($balance >= 0) ? myCurrency($balance) : "") . "" . (($balance < 0) ? myCurrency(abs($balance)) : "") . "". myCurrency($balance) .""; endforeach; $html .= ""; // if ($full == "") { $html .= "Total" . (($BalanceTotal > 0) ? myCurrency(abs($BalanceTotal )) : "") . "" . (($BalanceTotal < 0) ? myCurrency(abs($BalanceTotal )) : "") . "" . myCurrency($BalanceTotal) . ""; // } $html .= "\n"; $html .= "
Ledger Details
Ledger Details Goes Here
"; $html .= ''; echo $html; } function getAccountsTableByCategory($accategory_id) { $CI = &get_instance(); $Accounts = $CI->db->where("accategory_id", $accategory_id)->where("status", 1)->order_by("account_name ASC")->get("tbl_accounts")->result(); $html = "
Accounts Under " . getFieldfromValue("tbl_accategories", "accategory_name", "accategory_id", $accategory_id) . "
"; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $sn = 0; foreach ($Accounts as $Account) : $sn++; $html .= ""; endforeach; $html .= "
SnAccountDr/CrAction
" . $sn . "" . $Account->account_name . "" . myCurrency(getBalance($Account->account_id)) . "
"; echo $html; } //ACCOUNT HEADS function getCrAccountOpeningBalance($account_id) { $CI = &get_instance(); $CI->db->select('*'); $CI->db->from('tbl_voucherdetails'); $CI->db->where('account_id', $account_id); $CI->db->where('voucher_id', 0); $query = $CI->db->get(); if ($query->num_rows() > 0) { $result = $query->row(); $balance = $result->cr; return $balance; } else { return 0; } } function getDrAccountOpeningBalance($account_id) { $CI = &get_instance(); $CI->db->select('*'); $CI->db->from('tbl_voucherdetails'); $CI->db->where('account_id', $account_id); $CI->db->where('voucher_id', 0); $query = $CI->db->get(); if ($query->num_rows() > 0) { $result = $query->row(); $balance = $result->dr; return $balance; } else { return 0; } } function getAccountBalanceByAccountCategory($accategory_id) { $CI = &get_instance(); $t = "select * from tbl_voucherdetails where status=1 and account_id in (select account_id from tbl_accounts where accategory_id ='$accategory_id') or account_id in (select account_id from tbl_accounts where accategory_id in (select accategory_id from tbl_accategories where tbl_accategories.parent_category_id = '$accategory_id')) "; $Vouchers = $CI->db->query($t)->result(); $DrBalance = 0; $CrBalance = 0; foreach ($Vouchers as $Voucher) { //pre($Voucher);die; $DrBalance += $Voucher->dr; $CrBalance += $Voucher->cr; } return ($DrBalance) - ($CrBalance); } function getAccountBalanceByAccountCategoryBothSide($accategory_id) { $CI = &get_instance(); $t = "select * from tbl_voucherdetails where account_id in (select account_id from tbl_accounts where accategory_id ='$accategory_id')"; $Vouchers = $CI->db->query($t)->result(); $DrBalance = 0; $CrBalance = 0; foreach ($Vouchers as $Voucher) { $DrBalance += $Voucher->dr; $CrBalance += $Voucher->cr; } return ["DrBalance" => $DrBalance, "CrBalance" => $CrBalance]; } function getAccountBalance($account_id) { $CI = &get_instance(); $t = "select * from tbl_voucherdetails where account_id ='$account_id'"; //in (select account_id from tbl_accounts where accategory_id ='$accategory_id')"; $Vouchers = $CI->db->query($t)->result(); $DrBalance = 0; $CrBalance = 0; foreach ($Vouchers as $Voucher) { $DrBalance += $Voucher->dr; $CrBalance += $Voucher->cr; } return ($DrBalance) - ($CrBalance); } function getAccountBalanceBothSide($account_id) { $CI = &get_instance(); $t = "select * from tbl_voucherdetails where account_id ='$account_id'"; //in (select account_id from tbl_accounts where accategory_id ='$accategory_id')"; $Vouchers = $CI->db->query($t)->result(); $DrBalance = 0; $CrBalance = 0; foreach ($Vouchers as $Voucher) { $DrBalance += $Voucher->dr; $CrBalance += $Voucher->cr; } return ["DrBalance" => $DrBalance, "CrBalance" => $CrBalance]; } function getAccountGroups() { $CI = &get_instance(); $t = "select * from tbl_acgroups where status=1"; $AccountGroups = $CI->db->query($t)->result(); foreach ($AccountGroups as $AccountGroup) : $AccountGroup->dr = 0; $AccountGroup->cr = 0; // $TotalBalance = $this->getTotalBalanceByAccountGroup($AccountGroup->acgroup_id); $ACBalances = array(); $TotalBalance = $this->getAccountBalanceR("Types", $AccountGroup->acgroup_id, $ACBalances); if ($AccountGroup->posting_side == "DR") { $AccountGroup->dr = ($TotalBalance); } else { $AccountGroup->cr = ($TotalBalance); } endforeach; $dr = 0; $cr = 0; return $AccountGroups; } public function getParentAccountCategories($acgroup_id = 0) { if (isset($_GET['group'])) { $acgroup_id = ($_GET['group']) ? $_GET['group'] : $acgroup_id; } $ci = &get_instance(); if ($acgroup_id == 0) $t = "select * from tbl_accategories as b where status=1 and parent_category_id=0"; else $t = "select * from tbl_accategories as b where status=1 and parent_category_id=0 and acgroup_id='$acgroup_id'"; $AccountCategories = $ci->db->query($t)->result(); foreach ($AccountCategories as $AccountCategory) : $AccountCategory->dr = 0; $AccountCategory->cr = 0; $AccountCategory->AccountGroup = $ci->db->query("select * from tbl_acgroups where acgroup_id = '$AccountCategory->acgroup_id'")->row(); if ($AccountCategory->parent_category_id <> 0) { $AccountCategory->Parent = $ci->db->query("select * from tbl_accategories where accategory_id = '$AccountCategory->parent_category_id'")->row(); } // $AccountCategory->Balance = $this->getAccountBalanceByAccountCategory($AccountCategory->accategory_id); $AccountCategory->Balance = $this->getAccountBalanceR("Category", $AccountCategory->accategory_id); $AccountCategory->posting_side = getFieldfromValue("tbl_acgroups", "posting_side", "acgroup_id", $AccountCategory->acgroup_id); if ($AccountCategory->posting_side == "DR") $AccountCategory->dr = $AccountCategory->Balance; else $AccountCategory->cr = $AccountCategory->Balance; endforeach; return $AccountCategories; } public function getChildAccountCategories($accategory_id = 0) { if (isset($_GET['category'])) { $accategory_id = ($_GET['category']) ? $_GET['category'] : $accategory_id; } $ci = &get_instance(); if ($accategory_id == 0) $t = "select * from tbl_accategories as b where status=1 and parent_category_id<>0"; else $t = "select * from tbl_accategories as b where status=1 and parent_category_id='$accategory_id'"; $AccountCategories = $ci->db->query($t)->result(); foreach ($AccountCategories as $AccountCategory) : $AccountCategory->dr = 0; $AccountCategory->cr = 0; if ($AccountCategory->parent_category_id <> 0) { $AccountCategory->Parent = $ci->db->query("select * from tbl_accategories where accategory_id = '$AccountCategory->parent_category_id'")->row(); } // $AccountCategory->Balance = $this->getAccountBalanceByAccountCategory($AccountCategory->accategory_id); $AccountCategory->Balance = $this->getAccountBalanceR("Group", $AccountCategory->accategory_id); $AccountCategory->posting_side = getFieldfromValue("tbl_acgroups", "posting_side", "acgroup_id", $AccountCategory->acgroup_id); if ($AccountCategory->posting_side == "DR") $AccountCategory->dr = $AccountCategory->Balance; else $AccountCategory->cr = $AccountCategory->Balance; endforeach; return $AccountCategories; } function getTotalBalanceByAccountGroup($acgroup_id) { $CI = &get_instance(); $t = "select * from tbl_voucherdetails where account_id in (select account_id from tbl_accounts where accategory_id in (select accategory_id from tbl_accategories where acgroup_id='$acgroup_id'))"; $Vouchers = $CI->db->query($t)->result(); $DrBalance = 0; $CrBalance = 0; foreach ($Vouchers as $Voucher) { //pre($Voucher);die; $DrBalance += $Voucher->dr; $CrBalance += $Voucher->cr; } return ($DrBalance) - ($CrBalance); } function getParentAccountCategoriesByGroup($acgroup_id, $both = false) { $CI = &get_instance(); $AccountCategories = $CI->db ->where("acgroup_id", $acgroup_id) ->where("status", 1) ->where("parent_category_id", 0) ->order_by("accategory_name ASC")->get("tbl_accategories")->result(); foreach ($AccountCategories as $AccountCategory) { $AccountCategory->dr = 0; $AccountCategory->cr = 0; if ($both) { $TotalBalance = $this->getAccountBalanceByAccountCategoryBothSide($AccountCategory->accategory_id); $AccountCategory->dr = $TotalBalance['DrBalance']; $AccountCategory->cr = $TotalBalance['CrBalance']; } else { $AccountCategory->posting_side = getFieldfromValue("tbl_acgroups", "posting_side", "acgroup_id", $AccountCategory->acgroup_id); $TotalBalance = $this->getAccountBalanceByAccountCategory($AccountCategory->accategory_id); if ($AccountCategory->posting_side == "DR") { $AccountCategory->dr = abs($TotalBalance); } else { $AccountCategory->cr = abs($TotalBalance); } } } return $AccountCategories; } function getChildAccountCategoriesByGroupAndParentCategory($acgroup_id, $accategory_id, $both = false) { $CI = &get_instance(); $AccountCategories = $CI->db ->where("acgroup_id", $acgroup_id) ->where("parent_category_id", $accategory_id) ->where("status", 1) ->order_by("accategory_name ASC")->get("tbl_accategories")->result(); foreach ($AccountCategories as $AccountCategory) { $AccountCategory->dr = 0; $AccountCategory->cr = 0; if ($both) { $TotalBalance = $this->getAccountBalanceByAccountCategoryBothSide($AccountCategory->accategory_id); $AccountCategory->dr = $TotalBalance['DrBalance']; $AccountCategory->cr = $TotalBalance['CrBalance']; } else { $TotalBalance = $this->getAccountBalanceByAccountCategory($AccountCategory->accategory_id); $AccountCategory->posting_side = getFieldfromValue("tbl_acgroups", "posting_side", "acgroup_id", $AccountCategory->acgroup_id); if ($AccountCategory->posting_side == "DR") { $AccountCategory->dr = abs($TotalBalance); } else { $AccountCategory->cr = abs($TotalBalance); } } } return $AccountCategories; } function getAccountsByCategory($accategory_id, $getOldBalance = false) { $CI = &get_instance(); $AccountHeads = $CI->db ->where("accategory_id", $accategory_id) ->where("status", 1) ->order_by("account_name ASC")->get("tbl_accounts")->result(); foreach ($AccountHeads as $AccountHead) { $AccountHead = $this->CompileAccount($AccountHead, $getOldBalance); } return $AccountHeads; } function getAccountHeads($getOldBalance = false) { $CI = &get_instance(); $AccountHeads = $CI->db->query("select * from tbl_accounts where status=1 order by accategory_id asc,account_name asc ")->result(); foreach ($AccountHeads as $AccountHead) { $AccountHead = $this->CompileAccount($AccountHead, $getOldBalance); } return $AccountHeads; } function CompileAccount($AccountHead, $getOldBalance = false) { $CI = &get_instance(); $AccountHead->Group = $CI->db->query("select * from tbl_accategories where accategory_id='$AccountHead->accategory_id'")->row(); if ($AccountHead->Group) { if ($AccountHead->Group->parent_category_id != 0) $AccountHead->Category = $CI->db->query("select * from tbl_accategories where accategory_id='" . $AccountHead->Group->parent_category_id . "'")->row(); else $AccountHead->Category = $CI->db->query("select * from tbl_accategories where accategory_id='" . $AccountHead->Group->accategory_id . "'")->row(); $AccountHead->Type = $CI->db->query("select * from tbl_acgroups where acgroup_id='" . $AccountHead->Group->acgroup_id . "'")->row(); } if ($getOldBalance) { $AccountHead->dr_opening_balance = $this->getDrAccountOpeningBalance($AccountHead->account_id); $AccountHead->cr_opening_balance = $this->getCrAccountOpeningBalance($AccountHead->account_id); } $TotalBalances = array(); $TotalBalance = $this->getAccountBalanceR("Account", $AccountHead->account_id, $TotalBalances); $AccountHead->cr = $TotalBalances["DrBalance"]; $AccountHead->dr = $TotalBalances["CrBalance"]; return $AccountHead; } function listAccountHeads() { ?> getAccountHeads(true); ?>
Opening Balance
Group); ?> dr_opening_balance); echo ($TableRow->dr_opening_balance > 0) ? myCurrency($TableRow->dr_opening_balance) : ""; ?> cr_opening_balance); echo ($TableRow->cr_opening_balance > 0) ? myCurrency($TableRow->cr_opening_balance) : ""; ?> " class="btn btn-info btn-xs">
getOldBalance($account_id, $fromDate); $fromDate = ($fromDate == "") ? NepaliToEnglishDate(firstDayOfNepaliMonth()) : $fromDate; $toDate = ($toDate == "") ? Today() : $toDate; $ci = &get_instance(); $q = "select *,(select bs_date from tbl_nepengcalendar where ad_date=tbl_voucherdetails.transaction_date) as transaction_date_bs from tbl_voucherdetails where status=1 and account_id='$account_id' and transaction_date>='$fromDate' and transaction_date<='$toDate'"; // echo $q; $Transactions = $ci->db->query($q)->result(); // $Transactions = $ci->db->where("transaction_date>='$fromDate'")->where("transaction_date<='$toDate'")->where("status", 1)->where("account_id", $account_id)->get("tbl_voucherdetails")->result(); $Account = $ci->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 = $ci->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; $data['oldBalance'] = $oldBalance; return $data; } function showLedger($account_id, $fromDate = "", $toDate = "", $fiscalStart = "", $fiscalEnd = "" ) { $oldBalance = $this->getOldBalance($account_id, FYStart()); $fromDate = ($fromDate == "") ? NepaliToEnglishDate(FYStart()) : $fromDate; $toDate = ($toDate == "") ? Today() : $toDate; $ci = &get_instance(); $Transactions = $ci->db->where("transaction_date between '$fromDate' AND '$toDate'")->where("status", 1)->where("account_id", $account_id)->get("tbl_voucherdetails")->result(); $Account = $ci->db->where("status", 1)->where("account_id", $account_id)->get("tbl_accounts")->row(); foreach ($Transactions as $T) { $T->Voucher = $ci->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; ?>
Leger for Account : account_name; ?> account_id . "/?" . $_SERVER['QUERY_STRING']); ?>" class="btn btn-success btn-sm float-right">Print

session->userdata("CompanyName"); ?>

Ledger Details for account_name; ?>
dr; $balance -= $TableRow->cr; ?>
transaction_date)); ?> voucher_id != 0) : $Tr = $ci->myaccounts->getVoucherTransactions($TableRow->Voucher->voucher_id); foreach ($Tr as $T) : if ($T->account_id != $account_id) { echo $T->account_name; break; } endforeach; // pre($Tr); else : echo "Opening Balance"; endif; ?> voucher_id); ?> dr); $drTotal += $TableRow->dr; ?> cr); $crTotal += $TableRow->cr; ?>
 
Total
load->library("numbertoword"); $ledgerData = $this->getLedgerData($account_id, $fromDate, $toDate); $file = APPPATH . "/../pdf/e_ledger1.pdf"; $pdf = new FPDM($file); $i = 0; $crTotal = 0; $drTotal = 0; $fields = array(); $lineBalance = 0; // pre($ledgerData); //die; $fields['account_name'] = $ledgerData['Account']->account_name; $fields['from_date_ad'] = NepaliToEnglishDate($fromDate); $fields['to_date_ad'] = NepaliToEnglishDate($toDate); $fields['from_date_bs'] = $fromDate; $fields['to_date_bs'] = $toDate; $printedDate = NepaliDate(Today()) . "(AD: " . Today() . ")"; foreach ($ledgerData['Transactions'] as $VoucherDetail) : $i++; $fields['date' . $i] = $VoucherDetail->transaction_date . chr(13) . NepaliDate($VoucherDetail->transaction_date); $fields['voucher_no' . $i] = isset($VoucherDetail->Voucher->voucher_no) ? $VoucherDetail->Voucher->voucher_no : "B/F"; $fields['narration' . $i] = $VoucherDetail->narration; $fields['debit' . $i] = ($VoucherDetail->dr == 0) ? "" : N2($VoucherDetail->dr); $fields['credit' . $i] = ($VoucherDetail->dr == 0) ? N2($VoucherDetail->cr) : ""; $drTotal += $VoucherDetail->dr; $crTotal += $VoucherDetail->cr; $lineBalance += $VoucherDetail->dr - $VoucherDetail->cr; $fields['balance' . $i] = N2($lineBalance); $fields['debit_total'] = $drTotal; $fields['credit_total'] = $crTotal; $fields['balance_total'] = $crTotal - $drTotal; $fields['printed_by'] = $CI->session->userdata("loggedUser"); $fields['printed_on'] = $printedDate; $pdf->Load($fields, true); if ($i > 20) { //$pdf->AddPage(); $i = 0; } endforeach; //$pdf->Load($fields, true); $pdf->Merge(); //$pdf->Flatten(); $OutputFileLocation = APPPATH . "/../pdf/ledgers/"; $OutputFile = "Ledger_" . $ledgerData['Account']->account_id . ".pdf"; $pdf->Output("F", $OutputFileLocation . $OutputFile); return $OutputFile; } function ledgerPDF($account_id, $fromDate, $toDate) { $CI = &get_instance(); $CI->load->library("numbertoword"); $ledgerData = $this->getLedgerData($account_id, $fromDate, $toDate); if ($_SERVER['HTTP_HOST'] == 'localhost') $file = "ledger_$account_id.wpdf"; else $file = "ledger_$account_id.pdf"; $pdf = new MyPDF(); $pdf->HeaderText = "Account Ledger for " . $ledgerData['Account']->account_name; $pdf->SubHeaderText = "Period of $fromDate to $toDate"; $pdf->printedBy = $CI->session->userdata('loggedUser'); $i = 0; $crTotal = 0; $drTotal = 0; $fields = array(); $lineBalance = 0; // pre($ledgerData); //die; $columns = array( array("name" => "Date", "width" => 20, "align" => "C"), array("name" => "VN", "width" => 10, "align" => "L"), array("name" => "Narration", "width" => 80, "align" => "L"), array("name" => "Debit", "width" => 25, "align" => "L"), array("name" => "Credit", "width" => 25, "align" => "L"), array("name" => "Balance", "width" => 25, "align" => "L") ); $pdf->HeaderColumns = $columns; $pdf->SetAutoPageBreak(true, 50); $pdf->AddPage("P", "A4"); $pdf->SetFont('Helvetica', '', 8); $y = 50; $rowHeight = 8; foreach ($ledgerData['Transactions'] as $VoucherDetail) : $pdf->cell($columns[0]['width'], $rowHeight, $VoucherDetail->transaction_date, 1, 0, "C"); $pdf->cell($columns[1]['width'], $rowHeight, isset($VoucherDetail->Voucher->voucher_no) ? $VoucherDetail->Voucher->voucher_no : "B/F", 1, 0, "C"); $pdf->cell($columns[2]['width'], $rowHeight, character_limiter($VoucherDetail->narration, 35, " ..."), 1, 0, "J"); $pdf->cell($columns[3]['width'], $rowHeight, ($VoucherDetail->dr == 0) ? "" : N2($VoucherDetail->dr), 1, 0, "R"); $pdf->cell($columns[4]['width'], $rowHeight, ($VoucherDetail->dr == 0) ? N2($VoucherDetail->cr) : "", 1, 0, "R"); $drTotal += $VoucherDetail->dr; $crTotal += $VoucherDetail->cr; $lineBalance += $VoucherDetail->dr - $VoucherDetail->cr; $pdf->cell($columns[5]['width'], $rowHeight, N2($lineBalance), 1, 0, "R"); $pdf->Ln(); // $x = 10; // $pdf->SetXY($x, $y); // $pdf->Cell($columns[0]['width'], $rowHeight, $VoucherDetail->transaction_date, 1, "C"); // $pdf->SetXY($x += $columns[0]['width'], $y); // $pdf->MultiCell($columns[1]['width'], $rowHeight, isset($VoucherDetail->Voucher->voucher_no) ? $VoucherDetail->Voucher->voucher_no : "B/F", 1, "C"); // $pdf->SetXY($x += $columns[1]['width'], $y); // $pdf->MultiCell($columns[2]['width'], $rowHeight, $VoucherDetail->narration, 1, "J", false, 1); // $pdf->SetXY($x += $columns[2]['width'], $y); // $pdf->MultiCell($columns[3]['width'], $rowHeight, ($VoucherDetail->dr == 0) ? "" : N2($VoucherDetail->dr), 1,"R"); // $pdf->SetXY($x += $columns[3]['width'], $y); // $pdf->MultiCell($columns[4]['width'], $rowHeight, ($VoucherDetail->dr == 0) ? N2($VoucherDetail->cr) : "", 1,"R"); // $drTotal += $VoucherDetail->dr; // $crTotal += $VoucherDetail->cr; // $lineBalance += $VoucherDetail->dr - $VoucherDetail->cr; // $pdf->SetXY($x += $columns[4]['width'],$y); // $pdf->MultiCell($columns[5]['width'], $rowHeight, N2($lineBalance), 1,"R"); // $pdf->Ln(); // $y += $rowHeight; // if($y>280)$pdf->AddPage(); endforeach; $pdf->Output(APPPATH . "/../pdf/ledgers/" . $file, "F"); return $file; // $printedDate = NepaliDate(Today()) . "(AD: " . Today() . ")"; // foreach ($ledgerData['Transactions'] as $VoucherDetail) : // $i++; // $fields['date' . $i] = $VoucherDetail->transaction_date . chr(13) . NepaliDate($VoucherDetail->transaction_date); // $fields['voucher_no' . $i] = isset($VoucherDetail->Voucher->voucher_no) ? $VoucherDetail->Voucher->voucher_no : "B/F"; // $fields['narration' . $i] = $VoucherDetail->narration; // $fields['debit' . $i] = ($VoucherDetail->dr == 0) ? "" : N2($VoucherDetail->dr); // $fields['credit' . $i] = ($VoucherDetail->dr == 0) ? N2($VoucherDetail->cr) : ""; // $drTotal += $VoucherDetail->dr; // $crTotal += $VoucherDetail->cr; // $lineBalance += $VoucherDetail->dr - $VoucherDetail->cr; // $fields['balance' . $i] = N2($lineBalance); // $fields['debit_total'] = $drTotal; // $fields['credit_total'] = $crTotal; // $fields['balance_total'] = $crTotal - $drTotal; // $fields['printed_by'] = $CI->session->userdata("loggedUser"); // $fields['printed_on'] = $printedDate; // $pdf->Load($fields, true); // if ($i > 20) { // //$pdf->AddPage(); // $i = 0; // } // endforeach; // //$pdf->Load($fields, true); // $pdf->Merge(); // //$pdf->Flatten(); // $OutputFileLocation = APPPATH . "/../pdf/ledgers/"; // $OutputFile = "Ledger_" . $ledgerData['Account']->account_id . ".pdf"; // $pdf->Output("F", $OutputFileLocation . $OutputFile); // return $OutputFile; } function listVouchers($fromDate = "", $toDate = "", $account_id = "", $vouchertype_id = "", $showAccounts = false, $showVoucherTypes = false, $fiscalStart = "", $fiscalEnd = "") { // echo $toDate; $ci = &get_instance(); $fromDate = ($fromDate == "") ? NepaliToEnglishDate(firstDayOfNepaliMonth()) : $fromDate; $toDate = ($toDate == "") ? Today() : $toDate; $q = "select *, (select narration from tbl_voucherdetails where tbl_voucherdetails.voucher_id=tbl_vouchers.voucher_id limit 1) as narration from tbl_vouchers where status=1 and voucher_date>='$fromDate' and voucher_date<='$toDate'"; if ($account_id != "") $q .= " and voucher_id in (select voucher_id from tbl_voucherdetails where account_id='$account_id')"; if ($vouchertype_id != "") $q .= " and voucher_type ='$vouchertype_id'"; $q .= " order by voucher_date desc"; // echo $q; $Vouchers = $ci->db->query($q)->result(); $TableData = $Vouchers; if ($showAccounts) : foreach ($TableData as $Row) { $q = "select * from tbl_voucherdetails where voucher_id='" . $Row->voucher_id . "'"; $Row->Transactions = $ci->db->query($q)->result(); $Row->VoucherType = $this->getVoucherType($Row->voucher_type); } endif; ?> ">
Action
voucher_no; ?> voucher_date); ?> Transactions as $Transaction) : ?>
cr) ? "      " : "") . $this->getAccountDetails($Transaction->account_id)->account_name; ?>
narration): ?> (narration; ?>)
VoucherType->voucher_name; ?> Transactions as $Transaction) : $drTotal += $Transaction->dr; ?> dr); ?> Transactions as $Transaction) : $crTotal += $Transaction->cr; ?> cr); ?> session->userdata());die; ?> session->userdata('LoggedUser') != 'admin'): ?>
Total
db->where("status", 1)->where("vouchertype_id", $vouchertype_id); return $ci->db->get("tbl_vouchertypes")->row(); } function deleteVoucher($voucher_id) { $ci = &get_instance(); $ci->db->where("status", 1)->where("voucher_id", $voucher_id)->delete("tbl_vouchers"); $ci->db->where("status", 1)->where("voucher_id", $voucher_id)->delete("tbl_voucherdetails"); } function showVoucher($voucher_id) { $ci = &get_instance(); $Voucher = $ci->db->where("status", 1)->where("voucher_id", $voucher_id)->get("tbl_vouchers")->row(); $Voucher->Details = $ci->db->where("status", 1)->where("voucher_id", $voucher_id)->get("tbl_voucherdetails")->result(); $Voucher->Type = $ci->db->where("status", 1)->where("vouchertype_id", $Voucher->voucher_type)->get("tbl_vouchertypes")->row(); ?>
Type->voucher_type; ?> Voucher No. voucher_no; ?> Print

session->userdata("CompanyName"); ?>

Type->voucher_type; ?> Voucher
Details; ?>
transaction_date); ?> account_id); ?> dr); $drTotal += $TableRow->dr; ?> cr); $crTotal += $TableRow->cr; ?>
 
Total
Narration: narration; ?>
created_by; ?>
______________
______________
Entered By
Checked By
Approved By
db->query($t)->row(); return $Transaction->amount; } private function getVoucherTransactions($voucher_id) { $ci = &get_instance(); $t = "select *,(select account_name from tbl_accounts where tbl_accounts.account_id=tbl_voucherdetails.account_id) as account_name from tbl_voucherdetails where voucher_id='$voucher_id'"; $Transactions = $ci->db->query($t)->result(); return $Transactions; } public function getAccountCategories() { $ci = &get_instance(); $t = "select * from tbl_accategories as b where status=1"; $AccountCategories = $ci->db->query($t)->result(); foreach ($AccountCategories as $AccountCategory) : $AccountCategory->AccountGroup = $ci->db->query("select * from tbl_acgroups where acgroup_id = '$AccountCategory->acgroup_id'")->row(); if ($AccountCategory->parent_category_id <> 0) { $AccountCategory->Parent = $ci->db->query("select * from tbl_accategories where accategory_id = '$AccountCategory->parent_category_id'")->row(); } endforeach; return $AccountCategories; } //NEW METHODS function getAccountBalanceR($BalanceBy, $ReferenceValue, &$ACBalances = array()) { $ci = &get_instance(); if ($BalanceBy == "Account") { $account_id = $ReferenceValue; $t = "SELECT * FROM tbl_voucherdetails WHERE account_id = '$account_id' AND status <> -1"; // echo $t;die; $Vouchers = $ci->db->query($t)->result(); $DrBalance = 0; $CrBalance = 0; foreach ($Vouchers as $Voucher) { $DrBalance += $Voucher->dr; $CrBalance += $Voucher->cr; } $ACBalances['DrBalance'] = $DrBalance; $ACBalances['CrBalance'] = $CrBalance; $ACBalances['Balance'] = $DrBalance - $CrBalance; return $ACBalances['Balance']; } if ($BalanceBy == "Group") { $accategory_id = $ReferenceValue; $t = "SELECT * FROM tbl_accounts WHERE accategory_id = '$accategory_id'"; $Accounts = $ci->db->query($t)->result(); $groupBalance = 0; foreach ($Accounts as $Account) { $groupBalance += $this->getAccountBalanceR("Account", $Account->account_id, $ACBalances); } return $groupBalance; } if ($BalanceBy == "Category") { $accategory_id = $ReferenceValue; $t = "SELECT * FROM tbl_accategories WHERE parent_category_id = '$accategory_id'"; $Categories = $ci->db->query($t)->result(); $categoryBalance = 0; foreach ($Categories as $Category) { $categoryBalance += $this->getAccountBalanceR("Account", $Category->accategory_id, $ACBalances); } return $categoryBalance; } if ($BalanceBy == "Types") { $acgroup_id = $ReferenceValue; $t = "SELECT * FROM tbl_accategories WHERE acgroup_id = '$acgroup_id'"; $Categories = $ci->db->query($t)->result(); $typesBalance = 0; foreach ($Categories as $Category) { $typesBalance += $this->getAccountBalanceR("Group", $Category->accategory_id, $ACBalances); } return $typesBalance; } return 0; } function backupDatabase() { $ci = &get_instance(); $ci->load->database(); $dumpFilePath = __DIR__ . '/../../backup/' . $ci->db->database . '-backup-' . date('y-m-d-h-i-s') . '.sql'; $Filename = $ci->db->database . '-backup-' . date('y-m-d-h-i-s') . '.sql'; $command = "mysqldump -u " . $ci->db->username . " -p" . $ci->db->password . " -h " . $ci->db->hostname . " " . $ci->db->database . " > $dumpFilePath"; $output = shell_exec($command); if ($output === null) { // echo "Database dump successful. File saved at: $Filename"; mail("prajwalbro@gmail.com", "Account Database Backup", "Database dump successful. File saved at: $Filename"); } else { echo "Error: Database dump failed. Please check your configuration and try again."; } } function initDatabase() { $ci = &get_instance(); $ci->load->database(); $ci->load->dbforge(); if (!$ci->db->table_exists('tbl_vouchertypes')) { return; // Table doesn't exist, no need to proceed } $fields = $ci->db->list_fields('tbl_vouchertypes'); // Check if 'default_credits' column exists if (!in_array('default_credits', $fields)) { $ci->dbforge->add_column('tbl_vouchertypes', array('default_credits' => array('type' => 'VARCHAR', 'constraint' => 255))); } // Check if 'default_debits' column exists if (!in_array('default_debits', $fields)) { $ci->dbforge->add_column('tbl_vouchertypes', array('default_debits' => array('type' => 'VARCHAR', 'constraint' => 255))); } } function hasTransaction($type, $id) { switch ($type) { case 'fiscalyear': $ci = &get_instance(); $transactions = $ci->db->where("fiscalyear_id", $id)->get("tbl_voucherdetails"); // pre($transactions);die; if ($transactions->num_rows() > 0) { return true; } else { return false; } break; case 'branch': $ci = &get_instance(); $transactions = $ci->db->where("branch_id", $id)->get("tbl_voucherdetails"); // pre($transactions);die; if ($transactions->num_rows() > 0) { return true; } else { return false; } break; case 'accategory': $ci = &get_instance(); $t = "select * from tbl_voucherdetails where account_id in (select account_id from tbl_accounts where accategory_id=$id) or account_id in (select account_id from tbl_accounts where accategory_id in (select accategory_id from tbl_accategories where parent_category_id=$id))"; $transactions = $ci->db->query($t); // pre($transactions);die; if ($transactions->num_rows() > 0) { return true; } else { return false; } break; case 'account': $ci = &get_instance(); $t = "select * from tbl_voucherdetails where voucher_id<>0 and account_id =$id"; $transactions = $ci->db->query($t); // pre($transactions);die; if ($transactions->num_rows() > 0) { return true; } else { return false; } break; case 'units': $ci = &get_instance(); $t = "select * from tbl_items where units_id=$id"; $transactions = $ci->db->query($t); // pre($transactions);die; if ($transactions->num_rows() > 0) { return true; } else { return false; } break; case 'itemcategory': $ci = &get_instance(); $t = "select * from tbl_items where itemcategories_id=$id"; $transactions = $ci->db->query($t); // pre($transactions);die; if ($transactions->num_rows() > 0) { return true; } else { return false; } break; case 'items': $ci = &get_instance(); $t = "select * from tbl_items where item_id in (select items_id from tbl_salesdetails where items_id=$id) or item_id in (select item_id from tbl_purchasedetails where items_id=$id)"; // echo $t;die; $transactions = $ci->db->query($t); // pre($transactions);die; if ($transactions->num_rows() > 0) { return true; } else { return false; } break; default: return false; } } }