changes for filter and print

This commit is contained in:
2024-09-29 16:59:27 +05:45
parent 497f567cba
commit 684e01bf48
1335 changed files with 38709 additions and 74987 deletions

View File

@ -76,7 +76,7 @@ class bibaccounts
$group->cr_total += $accountBalances['cr_total'];
$group->regular_balance_dr += $accountBalances['regular_balance_dr'];
$group->regular_balance_cr += $accountBalances['regular_balance_cr'];
$account->balances=$accountBalances;
$account->balances = $accountBalances;
}
if (
$group->dr_total > 0 &&
@ -90,7 +90,67 @@ class bibaccounts
$group->opening_balance = ($group->posting_side == "DR") ? $group->opening_balance_dr - $group->opening_balance_cr : $group->opening_balance_cr - $group->opening_balance_dr;
$group->closing_balance = ($group->posting_side == "DR") ? $group->dr_total - $group->cr_total : $group->cr_total - $group->dr_total;
$group->regular_balance = ($group->posting_side == "DR") ? $group->regular_balance_dr - $group->regular_balance_cr : $group->regular_balance_cr - $group->regular_balance_dr;
$group->accounts = $accounts;
$result[] = $group;
}
// pre($result);die;
return $result;
}
// new function
function getAccountGroupsWithBalancesNew($acgroup_id = null, $fiscalStart = null, $fiscalEnd = null)
{
$CI = &get_instance();
$result = [];
$whereClause = "";
if ($acgroup_id !== null) {
$whereClause = "WHERE acgroup_id = '$acgroup_id' AND status=1 AND created_on >= '$fiscalStart' AND created_on >= '$fiscalEnd' ";
}
$t = "SELECT * FROM `tbl_acgroups` $whereClause";
$accountGroups = $CI->db->query($t)->result();
foreach ($accountGroups as $group) {
$t = "SELECT * FROM tbl_accounts
WHERE (accategory_id IN (SELECT accategory_id FROM tbl_accategories WHERE acgroup_id = '{$group->acgroup_id}')
OR accategory_id IN (SELECT parent_category_id FROM tbl_accategories WHERE accategory_id IN (SELECT accategory_id FROM tbl_accategories WHERE acgroup_id = '{$group->acgroup_id}')))
AND status <> -1";
$accounts = $CI->db->query($t)->result();
$group->dr_total = 0;
$group->cr_total = 0;
$group->regular_balance_dr = 0;
$group->regular_balance_cr = 0;
$group->opening_balance_dr = 0;
$group->opening_balance_cr = 0;
foreach ($accounts as $account) {
$accountBalances = $this->getAccountBalances($account->account_id);
// pre($accountBalances);die;
$group->opening_balance_dr += $accountBalances['opening_balance_dr'];
$group->opening_balance_cr += $accountBalances['opening_balance_cr'];
$group->dr_total += $accountBalances['dr_total'];
$group->cr_total += $accountBalances['cr_total'];
$group->regular_balance_dr += $accountBalances['regular_balance_dr'];
$group->regular_balance_cr += $accountBalances['regular_balance_cr'];
$account->balances = $accountBalances;
}
if (
$group->dr_total > 0 &&
$group->cr_total > 0 &&
$group->regular_balance_dr > 0 &&
$group->regular_balance_cr > 0 &&
$group->opening_balance_dr > 0 &&
$group->opening_balance_cr > 0
) $group->isZero = 1;
else $group->isZero = 0;
$group->opening_balance = ($group->posting_side == "DR") ? $group->opening_balance_dr - $group->opening_balance_cr : $group->opening_balance_cr - $group->opening_balance_dr;
$group->closing_balance = ($group->posting_side == "DR") ? $group->dr_total - $group->cr_total : $group->cr_total - $group->dr_total;
$group->regular_balance = ($group->posting_side == "DR") ? $group->regular_balance_dr - $group->regular_balance_cr : $group->regular_balance_cr - $group->regular_balance_dr;
$group->accounts = $accounts;
$result[] = $group;
}
@ -99,7 +159,9 @@ class bibaccounts
}
function getAccountCategoriesWithBalances($acgroup_id = null, $accategory_id=null)
// new function ends
function getAccountCategoriesWithBalances($acgroup_id = null, $accategory_id = null)
{
$CI = &get_instance();
$result = [];
@ -138,7 +200,7 @@ class bibaccounts
$category->cr_total += $accountBalances['cr_total'];
$category->regular_balance_dr += $accountBalances['regular_balance_dr'];
$category->regular_balance_cr += $accountBalances['regular_balance_cr'];
$account->balances=$accountBalances;
$account->balances = $accountBalances;
}
$category->posting_side = $CI->db->query("SELECT posting_side FROM tbl_acgroups WHERE acgroup_id=(SELECT acgroup_id FROM tbl_accategories WHERE accategory_id='" . $category->accategory_id . "')")->row()->posting_side;
@ -149,8 +211,8 @@ class bibaccounts
$category->accounts = $accounts;
$result[] = $category;
}
// pre($category);
if($accategory_id!=null)return isset($category)?$category:'';
// pre($category);
if ($accategory_id != null) return isset($category) ? $category : '';
return $result;
}
@ -538,7 +600,7 @@ class bibaccounts
$fiscal_year_id = ($fiscal_year_id == "") ? $this->FY : $fiscal_year_id;
$branch_id = ($branch_id == "") ? $this->Branch : $branch_id;
$CI = &get_instance();
$query = $CI->db->query("SELECT SUM(dr) AS dr_total, SUM(cr) AS cr_total FROM tbl_voucherdetails WHERE account_id='$account_id' AND status=1 AND fiscalyear_id='$fiscal_year_id' AND branch_id='$branch_id'");
$query = $CI->db->query("SELECT SUM(dr) AS dr_total, SUM(cr) AS cr_total FROM tbl_voucherdetails WHERE account_id='$account_id' AND status=1 AND fiscalyear_id='$fiscal_year_id' AND branch_id='$branch_id' ");
$result = $query->row();
$drTotal = $result->dr_total;
@ -578,7 +640,51 @@ class bibaccounts
'regular_balance_cr' => $regularBalanceCr,
);
}
function getAccountBalancesNew($account_id, $fiscal_year_id = "", $branch_id = "",$fiscalStart = null, $fiscalEnd = null)
{
$fiscal_year_id = ($fiscal_year_id == "") ? $this->FY : $fiscal_year_id;
$branch_id = ($branch_id == "") ? $this->Branch : $branch_id;
$CI = &get_instance();
$query = $CI->db->query("SELECT SUM(dr) AS dr_total, SUM(cr) AS cr_total FROM tbl_voucherdetails WHERE account_id='$account_id' AND status=1 AND fiscalyear_id='$fiscal_year_id' AND branch_id='$branch_id' AND created_on >= '$fiscalStart' AND created_on >= '$fiscalEnd' ");
$result = $query->row();
echo "<pre>";print_r($result);die();
$drTotal = $result->dr_total;
$crTotal = $result->cr_total;
$posting_side = $CI->db->query("SELECT posting_side FROM tbl_acgroups WHERE acgroup_id=(SELECT acgroup_id FROM tbl_accategories WHERE accategory_id=(SELECT accategory_id FROM tbl_accounts WHERE account_id='$account_id'))")->row()->posting_side;
$drBalance = 0;
$crBalance = 0;
if ($posting_side == "DR") {
$drBalance = $drTotal - $crTotal;
} else {
$crBalance = $crTotal - $drTotal;
}
$openingBalanceQuery = $CI->db->query("SELECT SUM(dr) AS opening_balance_dr, SUM(cr) AS opening_balance_cr FROM tbl_voucherdetails WHERE account_id='$account_id' AND voucher_id=0 AND status=1 AND fiscalyear_id='$fiscal_year_id' AND branch_id='$branch_id'");
$openingBalanceResult = $openingBalanceQuery->row();
$openingBalanceDr = $openingBalanceResult->opening_balance_dr;
$openingBalanceCr = $openingBalanceResult->opening_balance_cr;
$regularBalanceQuery = $CI->db->query("SELECT SUM(dr) AS regular_balance_dr, SUM(cr) AS regular_balance_cr FROM tbl_voucherdetails WHERE account_id='$account_id' AND voucher_id<>0 AND status=1 AND fiscalyear_id='$fiscal_year_id' AND branch_id='$branch_id'");
$regularBalanceResult = $regularBalanceQuery->row();
$regularBalanceDr = $regularBalanceResult->regular_balance_dr;
$regularBalanceCr = $regularBalanceResult->regular_balance_cr;
return array(
'dr_total' => $drTotal,
'cr_total' => $crTotal,
'dr_balance' => $drBalance,
'cr_balance' => $crBalance,
'opening_balance_dr' => $openingBalanceDr,
'opening_balance_cr' => $openingBalanceCr,
'regular_balance_dr' => $regularBalanceDr,
'regular_balance_cr' => $regularBalanceCr,
);
}
//////
@ -608,12 +714,13 @@ class bibaccounts
<?php } ?>
<tbody>
<?php foreach ($accountCategories as $accountCategory) : ?>
<?php //print_r($accountCategory);die; ?>
<?php //print_r($accountCategory);die;
?>
<?php if ($ReportOptions['showZeroBalances'] && $accountCategory->isZero == true) continue; ?>
<tr class="<?php echo ($accountCategory->isParent) ? ' parent-row' : ''; ?>" data-toggle="collapse" data-target="#accategory_<?php echo $accountCategory->accategory_id; ?>">
<td class="group-name">
<?php if($accountCategory->parent_category_id): ?>
<?php echo "&nbsp;&nbsp;". $accountCategory->accategory_name; ?>
<?php if ($accountCategory->parent_category_id): ?>
<?php echo "&nbsp;&nbsp;" . $accountCategory->accategory_name; ?>
<?php else: ?>
<b><?php echo $accountCategory->accategory_name; ?></b>
<?php endif; ?>
@ -817,14 +924,14 @@ class bibaccounts
/*
* Retrieves the account groups and accounts with balances that has cash/bank in debit side
*/
function getIncomeAndExpenditure()
function getIncomeAndExpenditure($fiscalStart,$fiscalEnd)
{
$CI = &get_instance();
#2 >> Bank Accounts
#3 >> Cash Accounts
$Incomes = array();
$Expenses = array();
$t = "select * from tbl_voucherdetails where voucher_id in (select voucher_id from tbl_voucherdetails where voucher_id<>0 and account_id in (select account_id from tbl_accounts where accategory_id=2 or accategory_id=3)) and account_id not in (select account_id from tbl_accounts where accategory_id=2 or accategory_id=3)";
$t = "select * from tbl_voucherdetails where voucher_id in (select voucher_id from tbl_voucherdetails where voucher_id<>0 and account_id in (select account_id from tbl_accounts where accategory_id=2 or accategory_id=3)) AND created_on >= '$fiscalStart' AND created_on >= '$fiscalEnd' and account_id not in (select account_id from tbl_accounts where accategory_id=2 or accategory_id=3)";
$accounts = $CI->db->query($t)->result();
foreach ($accounts as $account) {
$account->details = $CI->db->query("select * from tbl_accounts where account_id=" . $account->account_id)->row();
@ -954,14 +1061,14 @@ class bibaccounts
$sides["Incomes"] = $newArray;
else
$sides["Expenses"] = $newArray;
endforeach;
return $sides;
}
function prepareIncomeExpenses()
function prepareIncomeExpenses($fiscalStart,$fiscalEnd)
{
$cashFlow = $this->getIncomeAndExpenditure();
$cashFlow = $this->getIncomeAndExpenditure($fiscalStart,$fiscalEnd);
$a = 0;
foreach ($cashFlow as $side) :
$Groups = array();
@ -1003,7 +1110,7 @@ class bibaccounts
$sides["Incomes"] = $newArray;
else
$sides["Expenses"] = $newArray;
endforeach;
return $sides;