X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=gl%2Finquiry%2Fprofit_loss.php;h=1543bddc1ba102842f8f071865bf58660b0e72b0;hb=52f4ea3f7360e1284b1cf1cd39b2efda6ff0606f;hp=7254ea4e763fbb41c62d23fb9c1b9e01be2b6908;hpb=44e62c2ee85ee532bed9a8df1da41be9475370a1;p=fa-stable.git
diff --git a/gl/inquiry/profit_loss.php b/gl/inquiry/profit_loss.php
index 7254ea4e..1543bddc 100644
--- a/gl/inquiry/profit_loss.php
+++ b/gl/inquiry/profit_loss.php
@@ -21,11 +21,16 @@ include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/gl/includes/gl_db.inc");
$js = "";
-if ($use_date_picker)
+if (user_use_date_picker())
$js = get_js_date_picker();
page(_($help_context = "Profit & Loss Drilldown"), false, false, "", $js);
+$compare_types = array(
+ _("Accumulated"),
+ _("Period Y-1"),
+ _("Budget")
+);
//----------------------------------------------------------------------------------------------------
// Ajax updates
@@ -39,49 +44,110 @@ if (isset($_GET["TransFromDate"]))
if (isset($_GET["TransToDate"]))
$_POST["TransToDate"] = $_GET["TransToDate"];
if (isset($_GET["Compare"]))
- $_POST["Compare"] = $_GET["Compare"];
+ $_POST["Compare"] = $_GET["Compare"];
+if (isset($_GET["Dimension"]))
+ $_POST["Dimension"] = $_GET["Dimension"];
+if (isset($_GET["Dimension2"]))
+ $_POST["Dimension2"] = $_GET["Dimension2"];
if (isset($_GET["AccGrp"]))
- $_POST["AccGrp"] = $_GET["AccGrp"];
-if (isset($_GET["DrillLevel"]))
- $_POST["DrillLevel"] = $_GET["DrillLevel"];
-else
- $_POST["DrillLevel"] = 1; // Root level
-
+ $_POST["AccGrp"] = $_GET["AccGrp"];
+
//----------------------------------------------------------------------------------------------------
-function is_of_account_type($accttype,$typeslist)
+function display_type ($type, $typename, $from, $to, $begin, $end, $compare, $convert,
+ $dimension=0, $dimension2=0, $drilldown, $path_to_root)
{
- return in_array($accttype, $typeslist);
-}
+ global $levelptr, $k;
+
+ $code_per_balance = 0;
+ $code_acc_balance = 0;
+ $per_balance_total = 0;
+ $acc_balance_total = 0;
+ unset($totals_arr);
+ $totals_arr = array();
+
+ //Get Accounts directly under this group/type
+ $result = get_gl_accounts(null, null, $type);
-function get_child_account_types($acctype)
-{
- global $parentsarr;
- $parentsarr = array();
- $childernsarr = array();
- $list = '';
- array_push($parentsarr, $acctype);
- while (sizeof($parentsarr)>0)
- {
- $parent = array_pop($parentsarr);
- array_push($childernsarr,$parent);
- pushchilds($parent);
+ while ($account=db_fetch($result))
+ {
+ $per_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
+
+ if ($compare == 2)
+ $acc_balance = get_budget_trans_from_to($begin, $end, $account["account_code"], $dimension, $dimension2);
+ else
+ $acc_balance = get_gl_trans_from_to($begin, $end, $account["account_code"], $dimension, $dimension2);
+ if (!$per_balance && !$acc_balance)
+ continue;
+
+ if ($drilldown && $levelptr == 0)
+ {
+ $url = "" . $account['account_code']
+ ." ". $account['account_name'] ."";
+
+ start_row("class='stockmankobg'");
+ label_cell($url);
+ amount_cell($per_balance * $convert);
+ amount_cell($acc_balance * $convert);
+ amount_cell(Achieve($per_balance, $acc_balance));
+ end_row();
+ }
+
+ $code_per_balance += $per_balance;
+ $code_acc_balance += $acc_balance;
}
- $list = substr($list,0,-1);
- return $childernsarr;
-}
-function pushchilds($parent)
-{
- global $parentsarr;
+ $levelptr = 1;
+
+ //Get Account groups/types under this group/type
+ $result = get_account_types(false, false, $type);
+ while ($accounttype=db_fetch($result))
+ {
+ $totals_arr = display_type($accounttype["id"], $accounttype["name"], $from, $to, $begin, $end,
+ $compare, $convert, $dimension, $dimension2, $drilldown, $path_to_root);
+ $per_balance_total += $totals_arr[0];
+ $acc_balance_total += $totals_arr[1];
+ }
- $sql = "SELECT id FROM ".TB_PREF."chart_types WHERE parent=".$parent;
- $result = db_query($sql,"Query failed");
- while ($myrow=db_fetch($result))
+ //Display Type Summary if total is != 0
+ if (($code_per_balance + $per_balance_total + $code_acc_balance + $acc_balance_total) != 0)
{
- array_push($parentsarr, $myrow['id']);
+ if ($drilldown && $type == $_POST["AccGrp"])
+ {
+ start_row("class='inquirybg' style='font-weight:bold'");
+ label_cell(_('Total') . " " . $typename);
+ amount_cell(($code_per_balance + $per_balance_total) * $convert);
+ amount_cell(($code_acc_balance + $acc_balance_total) * $convert);
+ amount_cell(Achieve(($code_per_balance + $per_balance_total), ($code_acc_balance + $acc_balance_total)));
+ end_row();
+ }
+ //START Patch#1 : Display only direct child types
+ $acctype1 = get_account_type($type);
+ $parent1 = $acctype1["parent"];
+ if ($drilldown && $parent1 == $_POST["AccGrp"])
+ //END Patch#2
+ //elseif ($drilldown && $type != $_POST["AccGrp"])
+ {
+ $url = "" . $type . " " . $typename ."";
+
+ alt_table_row_color($k);
+ label_cell($url);
+ amount_cell(($code_per_balance + $per_balance_total) * $convert);
+ amount_cell(($code_acc_balance + $acc_balance_total) * $convert);
+ amount_cell(Achieve(($code_per_balance + $per_balance_total), ($code_acc_balance + $acc_balance_total)));
+ end_row();
+ }
}
-}
+
+ $totals_arr[0] = $code_per_balance + $per_balance_total;
+ $totals_arr[1] = $code_acc_balance + $acc_balance_total;
+ return $totals_arr;
+}
+
function Achieve($d1, $d2)
{
if ($d1 == 0 && $d2 == 0)
@@ -96,18 +162,28 @@ function Achieve($d1, $d2)
function inquiry_controls()
{
- start_table("class='tablestyle_noborder'");
+ global $compare_types;
+
+ $dim = get_company_pref('use_dimension');
+ start_table(TABLESTYLE_NOBORDER);
- date_cells(_("From:"), 'TransFromDate', '', null, -30);
+ $date = today();
+ if (!isset($_POST['TransToDate']))
+ $_POST['TransToDate'] = end_month($date);
+ if (!isset($_POST['TransFromDate']))
+ $_POST['TransFromDate'] = add_days(end_month($date), -user_transaction_days());
+ date_cells(_("From:"), 'TransFromDate');
date_cells(_("To:"), 'TransToDate');
- //Compare Combo
- global $sel;
- $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
- echo "
Comapre To: | \n";
+ echo ""._("Compare to").": | \n";
echo "";
- echo array_selector('Compare', null, $sel);
+ echo array_selector('Compare', null, $compare_types);
echo " | \n";
+
+ if ($dim >= 1)
+ dimensions_list_cells(_("Dimension")." 1:", 'Dimension', null, true, " ", false, 1);
+ if ($dim > 1)
+ dimensions_list_cells(_("Dimension")." 2:", 'Dimension2', null, true, " ", false, 2);
submit_cells('Show',_("Show"),'','', 'default');
end_table();
@@ -117,22 +193,25 @@ function inquiry_controls()
//----------------------------------------------------------------------------------------------------
-function print_profit_and_loss()
+function display_profit_and_loss($compare)
{
- global $comp_path, $path_to_root, $table_style, $sel;
+ global $path_to_root, $compare_types;
- $dim = get_company_pref('use_dimension');
- $dimension = $dimension2 = 0;
+ if (!isset($_POST['Dimension']))
+ $_POST['Dimension'] = 0;
+ if (!isset($_POST['Dimension2']))
+ $_POST['Dimension2'] = 0;
+ $dimension = $_POST['Dimension'];
+ $dimension2 = $_POST['Dimension2'];
$from = $_POST['TransFromDate'];
$to = $_POST['TransToDate'];
- $compare = $_POST['Compare'];
- $drilllevel = $_POST["DrillLevel"];
- $nextDrillLevel = $drilllevel + 1;
-
- $dec = 0;
- $pdec = user_percent_dec();
-
+
+ if (isset($_POST["AccGrp"]) && (strlen($_POST['AccGrp']) > 0))
+ $drilldown = 1; // Deeper Level
+ else
+ $drilldown = 0; // Root level
+
if ($compare == 0 || $compare == 2)
{
$end = $to;
@@ -148,238 +227,102 @@ function print_profit_and_loss()
$begin = add_months($from, -12);
$end = add_months($to, -12);
}
-
- $classname = '';
-
- $typeper = array(0,0,0,0,0,0,0,0,0,0);
- $typeacc = array(0,0,0,0,0,0,0,0,0,0);
- $typename = array('','','','','','','','','','');
- $acctype = array('','','','','','','','','','');
- $closing = array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1);
- $level = 0;
-
- $classper = 0.0;
- $classacc = 0.0;
- $salesper = 0.0;
- $salesacc = 0.0;
- $last = -1;
-
- $closeclass = false;
- $convert = 1;
- $ctype = 0;
-
- //For drill down, prepare the list of sub account types
- if (isset($_POST['AccGrp']) && (strlen($_POST['AccGrp']) > 0) )
- $sub_types_arr = get_child_account_types($_POST['AccGrp']);
-
- $accounts = get_gl_accounts_all(0);
div_start('pl_tbl');
- start_table("width=50% $table_style");
+ start_table(TABLESTYLE, "width='50%'");
$tableheader = "
-
+
-
";
-
- while ($account=db_fetch($accounts))
+ ";
+
+ if (!$drilldown) //Root Level
{
- if ($account['account_code'] == null && $account['parent'] > 0)
- continue;
-
- //Check for confirming the account type
- if (isset($_POST['AccGrp']) && (strlen($_POST['AccGrp']) > 0) )
- {
- if (!is_of_account_type($account['AccountType'], $sub_types_arr))
- continue;
- }
-
- if ($account['account_code'] != null)
- {
- $per_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
-
- if ($compare == 2)
- $acc_balance = get_budget_trans_from_to($begin, $end, $account["account_code"], $dimension, $dimension2);
- else
- $acc_balance = get_gl_trans_from_to($begin, $end, $account["account_code"], $dimension, $dimension2);
- if (!$per_balance && !$acc_balance)
- continue;
- }
-
- if ($account['AccountClassName'] != $classname)
+ $salesper = 0.0;
+ $salesacc = 0.0;
+
+ //Get classes for PL
+ $classresult = get_account_classes(false, 0);
+ while ($class = db_fetch($classresult))
{
- if ($classname != '')
- {
- $closeclass = true;
- }
- }
-
- if ($account['AccountTypeName'] != $typename[$level] || $closeclass )
- {
- if ($typename[$level] != '')
+ $class_per_total = 0;
+ $class_acc_total = 0;
+ $convert = get_class_type_convert($class["ctype"]);
+
+ //Print Class Name
+ table_section_title($class["class_name"],4);
+ echo $tableheader;
+
+ //Get Account groups/types under this group/type
+ $typeresult = get_account_types(false, $class['cid'], -1);
+ $k = 0; // row color
+ while ($accounttype=db_fetch($typeresult))
{
- for ( ; $level >= 0, $typename[$level] != ''; $level--)
+ $TypeTotal = display_type($accounttype["id"], $accounttype["name"], $from, $to, $begin, $end, $compare, $convert,
+ $dimension, $dimension2, $drilldown, $path_to_root);
+ $class_per_total += $TypeTotal[0];
+ $class_acc_total += $TypeTotal[1];
+
+ if ($TypeTotal[0] != 0 || $TypeTotal[1] != 0 )
{
- if ($account['parent'] == $closing[$level] || $account['parent'] < $last || $account['parent'] <= 0 || $closeclass)
- {
- // Display Groups only of Specific Drill Level
- if ($level == $drilllevel && ($typeper[$level] != 0 || $typeacc[$level] != 0 ))
- {
- $url = "" . $typename[$level] ."";
-
- alt_table_row_color($k);
- label_cell($url);
- amount_cell($typeper[$level] * $convert);
- amount_cell($typeacc[$level] * $convert);
- amount_cell(Achieve($typeper[$level], $typeacc[$level]));
- end_row();
- }
+ $url = "" . $accounttype['id'] . " " . $accounttype['name'] ."";
- $typeper[$level] = $typeacc[$level] = 0.0;
- }
- else
- break;
- }
- if ($closeclass)
- {
- start_row("class='inquirybg' style='font-weight:bold'");
- label_cell(_('Total') . " " . $classname);
- amount_cell($classper * $convert);
- amount_cell($classacc * $convert);
- amount_cell(Achieve($classper, $classacc));
- end_row();
-
- $salesper += $classper;
- $salesacc += $classacc;
- $classper = $classacc = 0.0;
-
- $closeclass = false;
+ alt_table_row_color($k);
+ label_cell($url);
+ amount_cell($TypeTotal[0] * $convert);
+ amount_cell($TypeTotal[1] * $convert);
+ amount_cell(Achieve($TypeTotal[0], $TypeTotal[1]));
+ end_row();
}
}
- if ($account['AccountClassName'] != $classname)
- {
- if (isset($_POST['AccGrp']) && (strlen($_POST['AccGrp']) > 0))
- table_section_title($account['AccountTypeName'],4);
- else
- table_section_title($account['AccountClassName'],4);
-
- echo $tableheader;
- }
- $level++;
- if ($account['parent'] != $last)
- $last = $account['parent'];
- $typename[$level] = $account['AccountTypeName'];
- $acctype[$level] = $account['AccountType'];
- $closing[$level] = $account['parent'];
- }
- $classname = $account['AccountClassName'];
- $ctype = $account['ClassType'];
- $convert = get_class_type_convert($ctype);
-
- if ($account['account_code'] != null)
- {
- //$per_balance *= -1;
- //$acc_balance *= -1;
-
- for ($i = 0; $i <= $level; $i++)
- {
- $typeper[$i] += $per_balance;
- $typeacc[$i] += $acc_balance;
- }
- $classper += $per_balance;
- $classacc += $acc_balance;
- //Show accounts details only for drill down and direct child of Account Group
- if ( isset($_POST['AccGrp']) && ($account['AccountType'] == $_POST['AccGrp']))
- {
- $url = "" . $account['account_code']
- ." ". $account['account_name'] ."";
-
- start_row("class='stockmankobg'");
- label_cell($url);
- amount_cell($per_balance * $convert);
- amount_cell($acc_balance * $convert);
- amount_cell(Achieve($per_balance, $acc_balance));
- end_row();
- }
+ //Print Class Summary
+
+ start_row("class='inquirybg' style='font-weight:bold'");
+ label_cell(_('Total') . " " . $class["class_name"]);
+ amount_cell($class_per_total * $convert);
+ amount_cell($class_acc_total * $convert);
+ amount_cell(Achieve($class_per_total, $class_acc_total));
+ end_row();
+
+ $salesper += $class_per_total;
+ $salesacc += $class_acc_total;
}
+
+ start_row("class='inquirybg' style='font-weight:bold'");
+ label_cell(_('Calculated Return'));
+ amount_cell($salesper *-1);
+ amount_cell($salesacc * -1);
+ amount_cell(achieve($salesper, $salesacc));
+ end_row();
+
}
- if ($account['AccountClassName'] != $classname)
+ else
{
- if ($classname != '')
- {
- $closeclass = true;
- }
+ //Level Pointer : Global variable defined in order to control display of root
+ global $levelptr;
+ $levelptr = 0;
+
+ $accounttype = get_account_type($_POST["AccGrp"]);
+ $classid = $accounttype["class_id"];
+ $class = get_account_class($classid);
+ $convert = get_class_type_convert($class["ctype"]);
+
+ //Print Class Name
+ table_section_title($_POST["AccGrp"] . " " . get_account_type_name($_POST["AccGrp"]),4);
+ echo $tableheader;
+
+ $classtotal = display_type($accounttype["id"], $accounttype["name"], $from, $to, $begin, $end, $compare, $convert,
+ $dimension, $dimension2, $drilldown, $path_to_root);
+
}
- if ($account['AccountTypeName'] != $typename[$level])
- {
- if ($typename[$level] != '')
- {
- for ( ; $level >= 0, $typename[$level] != ''; $level--)
- {
- if ($account['parent'] == $closing[$level] || $account['parent'] < $last || $account['parent'] <= 0 || $closeclass)
- {
-
- //Inside drill down, Show summary of the specific account group
- if (isset($_POST['AccGrp']) && (strlen($_POST['AccGrp']) > 0) && ($acctype[$level] == $_POST['AccGrp']))
- {
- start_row("class='inquirybg' style='font-weight:bold'");
- label_cell(_('Total') . " " .$typename[$level]);
- amount_cell($typeper[$level] * $convert);
- amount_cell($typeacc[$level] * $convert);
- amount_cell(Achieve($typeper[$level], $typeacc[$level]));
- end_row();
- }
- // Display Groups only of Specific Drill Level
- elseif ($level == $drilllevel && ($typeper[$level] != 0 || $typeacc[$level] != 0 ))
- {
- $url = "" . $typename[$level] ."";
-
- alt_table_row_color($k);
- label_cell($url);
- amount_cell($typeper[$level] * $convert);
- amount_cell($typeacc[$level] * $convert);
- amount_cell(Achieve($typeper[$level], $typeacc[$level]));
- end_row();
- }
-
- $typeper[$level] = $typeacc[$level] = 0.0;
- }
- else
- break;
- }
+
- if (($closeclass) && !(isset($_POST['AccGrp']) && (strlen($_POST['AccGrp']) > 0)) )
- {
- $calculateper = $salesper + $classper;
- $calculateacc = $salesacc + $classacc;
-
- start_row("class='inquirybg' style='font-weight:bold'");
- label_cell(_('Total') . " " . $classname);
- amount_cell($classper * $convert);
- amount_cell($classacc * $convert);
- amount_cell(Achieve($classper, $classacc));
- end_row();
-
- start_row("class='inquirybg' style='font-weight:bold'");
- label_cell(_('Calculated Return'));
- amount_cell($calculateper *-1);
- amount_cell($calculateacc * -1);
- amount_cell(Achieve($calculateper, $calculateacc));
- end_row();
-
- }
- }
- }
end_table(1); // outer table
div_end();
}
@@ -390,11 +333,9 @@ start_form();
inquiry_controls();
-print_profit_and_loss();
+display_profit_and_loss(get_post('Compare'));
end_form();
end_page();
-?>
-