X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=reporting%2Frep705.php;h=607b446c1da5ddc916cc8cbaece65e3e10655c70;hb=d1b959c4b73664327c2e17d5bb3fb515aabfa449;hp=8516da4f1ec4e6458dc95357bc0d905077dd4150;hpb=fc72e71a81a7d2c9d68eabbb1200d4c0cbf17f6e;p=fa-stable.git diff --git a/reporting/rep705.php b/reporting/rep705.php index 8516da4f..607b446c 100644 --- a/reporting/rep705.php +++ b/reporting/rep705.php @@ -9,7 +9,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ -$page_security = 2; +$page_security = 'SA_GLANALYTIC'; // ---------------------------------------------------------------- // $ Revision: 2.0 $ // Creator: Joe Hunt @@ -29,10 +29,10 @@ print_annual_expense_breakdown(); //---------------------------------------------------------------------------------------------------- -function getPeriods($year, $account, $dimension, $dimension2) +function getPeriods($row, $account, $dimension, $dimension2) { - $yr = $year; - $mo = 12; + $yr = $row['yr']; + $mo = $row['mo']; $date13 = date('Y-m-d',mktime(0,0,0,$mo+1,1,$yr)); $date12 = date('Y-m-d',mktime(0,0,0,$mo,1,$yr)); $date11 = date('Y-m-d',mktime(0,0,0,$mo-1,1,$yr)); @@ -47,24 +47,24 @@ function getPeriods($year, $account, $dimension, $dimension2) $date02 = date('Y-m-d',mktime(0,0,0,$mo-10,1,$yr)); $date01 = date('Y-m-d',mktime(0,0,0,$mo-11,1,$yr)); - $sql = "SELECT SUM(CASE WHEN tran_date >= '$date01' AND tran_date < '$date02' THEN -amount / 1000 ELSE 0 END) AS per01, - SUM(CASE WHEN tran_date >= '$date02' AND tran_date < '$date03' THEN -amount / 1000 ELSE 0 END) AS per02, - SUM(CASE WHEN tran_date >= '$date03' AND tran_date < '$date04' THEN -amount / 1000 ELSE 0 END) AS per03, - SUM(CASE WHEN tran_date >= '$date04' AND tran_date < '$date05' THEN -amount / 1000 ELSE 0 END) AS per04, - SUM(CASE WHEN tran_date >= '$date05' AND tran_date < '$date06' THEN -amount / 1000 ELSE 0 END) AS per05, - SUM(CASE WHEN tran_date >= '$date06' AND tran_date < '$date07' THEN -amount / 1000 ELSE 0 END) AS per06, - SUM(CASE WHEN tran_date >= '$date07' AND tran_date < '$date08' THEN -amount / 1000 ELSE 0 END) AS per07, - SUM(CASE WHEN tran_date >= '$date08' AND tran_date < '$date09' THEN -amount / 1000 ELSE 0 END) AS per08, - SUM(CASE WHEN tran_date >= '$date09' AND tran_date < '$date10' THEN -amount / 1000 ELSE 0 END) AS per09, - SUM(CASE WHEN tran_date >= '$date10' AND tran_date < '$date11' THEN -amount / 1000 ELSE 0 END) AS per10, - SUM(CASE WHEN tran_date >= '$date11' AND tran_date < '$date12' THEN -amount / 1000 ELSE 0 END) AS per11, - SUM(CASE WHEN tran_date >= '$date12' AND tran_date < '$date13' THEN -amount / 1000 ELSE 0 END) AS per12 + $sql = "SELECT SUM(CASE WHEN tran_date >= '$date01' AND tran_date < '$date02' THEN amount / 1000 ELSE 0 END) AS per01, + SUM(CASE WHEN tran_date >= '$date02' AND tran_date < '$date03' THEN amount / 1000 ELSE 0 END) AS per02, + SUM(CASE WHEN tran_date >= '$date03' AND tran_date < '$date04' THEN amount / 1000 ELSE 0 END) AS per03, + SUM(CASE WHEN tran_date >= '$date04' AND tran_date < '$date05' THEN amount / 1000 ELSE 0 END) AS per04, + SUM(CASE WHEN tran_date >= '$date05' AND tran_date < '$date06' THEN amount / 1000 ELSE 0 END) AS per05, + SUM(CASE WHEN tran_date >= '$date06' AND tran_date < '$date07' THEN amount / 1000 ELSE 0 END) AS per06, + SUM(CASE WHEN tran_date >= '$date07' AND tran_date < '$date08' THEN amount / 1000 ELSE 0 END) AS per07, + SUM(CASE WHEN tran_date >= '$date08' AND tran_date < '$date09' THEN amount / 1000 ELSE 0 END) AS per08, + SUM(CASE WHEN tran_date >= '$date09' AND tran_date < '$date10' THEN amount / 1000 ELSE 0 END) AS per09, + SUM(CASE WHEN tran_date >= '$date10' AND tran_date < '$date11' THEN amount / 1000 ELSE 0 END) AS per10, + SUM(CASE WHEN tran_date >= '$date11' AND tran_date < '$date12' THEN amount / 1000 ELSE 0 END) AS per11, + SUM(CASE WHEN tran_date >= '$date12' AND tran_date < '$date13' THEN amount / 1000 ELSE 0 END) AS per12 FROM ".TB_PREF."gl_trans WHERE account='$account'"; - if ($dimension > 0) - $sql .= " AND dimension_id = $dimension"; - if ($dimension2 > 0) - $sql .= " AND dimension2_id = $dimension2"; + if ($dimension != 0) + $sql .= " AND dimension_id = ".($dimension<0?0:db_escape($dimension)); + if ($dimension2 != 0) + $sql .= " AND dimension2_id = ".($dimension2<0?0:db_escape($dimension2)); $result = db_query($sql, "Transactions for account $account could not be calculated"); @@ -115,8 +115,13 @@ function print_annual_expense_breakdown() //$yr = date('Y'); //$mo = date('m'): // from now - $yr = $year; - $mo = 12; + $sql = "SELECT begin, end, YEAR(end) AS yr, MONTH(end) AS mo FROM ".TB_PREF."fiscal_year WHERE id=".db_escape($year); + $result = db_query($sql, "could not get fiscal year"); + $row = db_fetch($result); + + $year = sql2date($row['begin'])." - ".sql2date($row['end']); + $yr = $row['yr']; + $mo = $row['mo']; $da = 1; if ($date_system == 1) list($yr, $mo, $da) = jalali_to_gregorian($yr, $mo, $da); @@ -198,13 +203,26 @@ function print_annual_expense_breakdown() $level = 0; $last = -1; - $types = get_account_types_all(0); + $closeclass = false; + $convert = 1; + $ctype = 0; - while ($type = db_fetch($types)) + $accounts = get_gl_accounts_all(0); + + while ($account=db_fetch($accounts)) { - if (!num_accounts_in_type($type['AccountType'], $type['parent'])) + if ($account['account_code'] == null && $account['parent'] > 0) continue; - if ($type['AccountClassName'] != $classname) + + if ($account['account_code'] != null) + { + $bal = getPeriods($row, $account["account_code"], $dimension, $dimension2); + if (!$bal['per01'] && !$bal['per02'] && !$bal['per03'] && !$bal['per04'] && + !$bal['per05'] && !$bal['per06'] && !$bal['per07'] && !$bal['per08'] && + !$bal['per09'] && !$bal['per10'] && !$bal['per11'] && !$bal['per12']) + continue; + } + if ($account['AccountClassName'] != $classname) { if ($classname != '') { @@ -212,13 +230,13 @@ function print_annual_expense_breakdown() } } - if ($type['AccountTypeName'] != $typename[$level]) + if ($account['AccountTypeName'] != $typename[$level]) { if ($typename[$level] != '') { for ( ; $level >= 0, $typename[$level] != ''; $level--) { - if ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0) + if ($account['parent'] == $closing[$level] || $account['parent'] < $last || $account['parent'] <= 0 || $closeclass) { $rep->row += 6; $rep->Line($rep->row); @@ -226,7 +244,7 @@ function print_annual_expense_breakdown() $rep->TextCol(0, 2, _('Total') . " " . $typename[$level]); for ($i = 1; $i <= 12; $i++) { - $rep->AmountCol($i + 1, $i + 2, $total[$level][$i], $dec); + $rep->AmountCol($i + 1, $i + 2, $total[$level][$i] * $convert, $dec); $total[$level][$i] = 0.0; } } @@ -243,7 +261,7 @@ function print_annual_expense_breakdown() $rep->TextCol(0, 2, _('Total') . " " . $classname); for ($i = 1; $i <= 12; $i++) { - $rep->AmountCol($i + 1, $i + 2, $total2[$i], $dec); + $rep->AmountCol($i + 1, $i + 2, $total2[$i] * $convert, $dec); $sales[$i] += $total2[$i]; } $rep->Font(); @@ -252,34 +270,30 @@ function print_annual_expense_breakdown() $closeclass = false; } } - if ($type['AccountClassName'] != $classname) + if ($account['AccountClassName'] != $classname) { $rep->Font('bold'); - $rep->TextCol(0, 5, $type['AccountClassName']); + $rep->TextCol(0, 5, $account['AccountClassName']); $rep->Font(); $rep->NewLine(); } $level++; - if ($type['parent'] != $last) - $last = $type['parent']; - $typename[$level] = $type['AccountTypeName']; - $closing[$level] = $type['parent']; + if ($account['parent'] != $last) + $last = $account['parent']; + $typename[$level] = $account['AccountTypeName']; + $closing[$level] = $account['parent']; $rep->row -= 4; - $rep->TextCol(0, 5, $type['AccountTypeName']); + $rep->TextCol(0, 5, $account['AccountTypeName']); $rep->row -= 4; $rep->Line($rep->row); $rep->NewLine(); } - $classname = $type['AccountClassName']; + $classname = $account['AccountClassName']; + $ctype = $account['ClassType']; + $convert = get_class_type_convert($ctype); - $accounts = get_gl_accounts_in_type($type['AccountType']); - while ($account=db_fetch($accounts)) + if ($account['account_code'] != null) { - $bal = getPeriods($year, $account["account_code"], $dimension, $dimension2); - if (!$bal['per01'] && !$bal['per02'] && !$bal['per03'] && !$bal['per04'] && - !$bal['per05'] && !$bal['per06'] && !$bal['per07'] && !$bal['per08'] && - !$bal['per09'] && !$bal['per10'] && !$bal['per11'] && !$bal['per12']) - continue; $balance = array(1 => $bal['per01'], $bal['per02'], $bal['per03'], $bal['per04'], $bal['per05'], $bal['per06'], $bal['per07'], $bal['per08'], $bal['per09'], $bal['per10'], $bal['per11'], $bal['per12']); @@ -288,7 +302,7 @@ function print_annual_expense_breakdown() for ($i = 1; $i <= 12; $i++) { - $rep->AmountCol($i + 1, $i + 2, $balance[$i], $dec); + $rep->AmountCol($i + 1, $i + 2, $balance[$i] * $convert, $dec); $total2[$i] += $balance[$i]; } for ($j = 0; $j <= $level; $j++) @@ -305,20 +319,20 @@ function print_annual_expense_breakdown() } } } - if ($type['AccountClassName'] != $classname) + if ($account['AccountClassName'] != $classname) { if ($classname != '') { $closeclass = true; } } - if ($type['AccountTypeName'] != $typename[$level]) + if ($account['AccountTypeName'] != $typename[$level]) { if ($typename[$level] != '') { for ( ; $level >= 0, $typename[$level] != ''; $level--) { - if ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0) + if ($account['parent'] == $closing[$level] || $account['parent'] < $last || $account['parent'] <= 0 || $closeclass) { $rep->row += 6; $rep->Line($rep->row); @@ -326,7 +340,7 @@ function print_annual_expense_breakdown() $rep->TextCol(0, 2, _('Total') . " " . $typename[$level]); for ($i = 1; $i <= 12; $i++) { - $rep->AmountCol($i + 1, $i + 2, $total[$level][$i], $dec); + $rep->AmountCol($i + 1, $i + 2, $total[$level][$i] * $convert, $dec); $total[$level][$i] = 0.0; } } @@ -344,14 +358,14 @@ function print_annual_expense_breakdown() $rep->TextCol(0, 2, _('Total') . " " . $classname); for ($i = 1; $i <= 12; $i++) { - $rep->AmountCol($i + 1, $i + 2, $total2[$i], $dec); + $rep->AmountCol($i + 1, $i + 2, $total2[$i] * $convert, $dec); $calc[$i] = $sales[$i] + $total2[$i]; } $rep->NewLine(2); $rep->TextCol(0, 2, _('Calculated Return')); for ($i = 1; $i <= 12; $i++) - $rep->AmountCol($i + 1, $i + 2, $calc[$i], $dec); + $rep->AmountCol($i + 1, $i + 2, $calc[$i] * -1, $dec); // always convert $rep->Font(); $rep->NewLine();