4 // ----------------------------------------------------------------
8 // Title: Annual expense breakdown
9 // ----------------------------------------------------------------
12 include_once($path_to_root . "includes/session.inc");
13 include_once($path_to_root . "includes/date_functions.inc");
14 include_once($path_to_root . "includes/data_checks.inc");
15 include_once($path_to_root . "gl/includes/gl_db.inc");
17 //----------------------------------------------------------------------------------------------------
19 // trial_inquiry_controls();
20 print_annual_expense_breakdown();
22 //----------------------------------------------------------------------------------------------------
24 function getPeriods($year, $account, $dimension, $dimension2)
31 $date13 = date('Y-m-d',mktime(0,0,0,$mo+1,1,$yr));
32 $date12 = date('Y-m-d',mktime(0,0,0,$mo,1,$yr));
33 $date11 = date('Y-m-d',mktime(0,0,0,$mo-1,1,$yr));
34 $date10 = date('Y-m-d',mktime(0,0,0,$mo-2,1,$yr));
35 $date09 = date('Y-m-d',mktime(0,0,0,$mo-3,1,$yr));
36 $date08 = date('Y-m-d',mktime(0,0,0,$mo-4,1,$yr));
37 $date07 = date('Y-m-d',mktime(0,0,0,$mo-5,1,$yr));
38 $date06 = date('Y-m-d',mktime(0,0,0,$mo-6,1,$yr));
39 $date05 = date('Y-m-d',mktime(0,0,0,$mo-7,1,$yr));
40 $date04 = date('Y-m-d',mktime(0,0,0,$mo-8,1,$yr));
41 $date03 = date('Y-m-d',mktime(0,0,0,$mo-9,1,$yr));
42 $date02 = date('Y-m-d',mktime(0,0,0,$mo-10,1,$yr));
43 $date01 = date('Y-m-d',mktime(0,0,0,$mo-11,1,$yr));
45 $sql = "SELECT SUM(CASE WHEN tran_date >= '$date01' AND tran_date < '$date02' THEN -amount / 1000 ELSE 0 END) AS per01,
46 SUM(CASE WHEN tran_date >= '$date02' AND tran_date < '$date03' THEN -amount / 1000 ELSE 0 END) AS per02,
47 SUM(CASE WHEN tran_date >= '$date03' AND tran_date < '$date04' THEN -amount / 1000 ELSE 0 END) AS per03,
48 SUM(CASE WHEN tran_date >= '$date04' AND tran_date < '$date05' THEN -amount / 1000 ELSE 0 END) AS per04,
49 SUM(CASE WHEN tran_date >= '$date05' AND tran_date < '$date06' THEN -amount / 1000 ELSE 0 END) AS per05,
50 SUM(CASE WHEN tran_date >= '$date06' AND tran_date < '$date07' THEN -amount / 1000 ELSE 0 END) AS per06,
51 SUM(CASE WHEN tran_date >= '$date07' AND tran_date < '$date08' THEN -amount / 1000 ELSE 0 END) AS per07,
52 SUM(CASE WHEN tran_date >= '$date08' AND tran_date < '$date09' THEN -amount / 1000 ELSE 0 END) AS per08,
53 SUM(CASE WHEN tran_date >= '$date09' AND tran_date < '$date10' THEN -amount / 1000 ELSE 0 END) AS per09,
54 SUM(CASE WHEN tran_date >= '$date10' AND tran_date < '$date11' THEN -amount / 1000 ELSE 0 END) AS per10,
55 SUM(CASE WHEN tran_date >= '$date11' AND tran_date < '$date12' THEN -amount / 1000 ELSE 0 END) AS per11,
56 SUM(CASE WHEN tran_date >= '$date12' AND tran_date < '$date13' THEN -amount / 1000 ELSE 0 END) AS per12
57 FROM ".TB_PREF."gl_trans
58 WHERE account='$account'";
60 $sql .= " AND dimension_id = $dimension";
62 $sql .= " AND dimension2_id = $dimension2";
64 $result = db_query($sql, "Transactions for account $account could not be calculated");
66 return db_fetch($result);
69 //----------------------------------------------------------------------------------------------------
71 function print_annual_expense_breakdown()
73 global $path_to_root, $date_system;
75 include_once($path_to_root . "reporting/includes/pdf_report.inc");
76 $dim = get_company_pref('use_dimension');
77 $dimension = $dimension2 = 0;
81 $year = $_POST['PARAM_0'];
82 $dimension = $_POST['PARAM_1'];
83 $dimension2 = $_POST['PARAM_2'];
84 $comments = $_POST['PARAM_3'];
88 $year = $_POST['PARAM_0'];
89 $dimension = $_POST['PARAM_1'];
90 $comments = $_POST['PARAM_2'];
94 $year = $_POST['PARAM_0'];
95 $comments = $_POST['PARAM_1'];
98 //$pdec = user_percent_dec();
100 $cols = array(0, 40, 150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510);
101 //------------0--1---2----3----4----5----6----7----8----10---11---12---13---14---15-
109 if ($date_system == 1)
110 list($yr, $mo, $da) = jalali_to_gregorian($yr, $mo, $da);
111 elseif ($date_system == 2)
112 list($yr, $mo, $da) = islamic_to_gregorian($yr, $mo, $da);
113 $per12 = strftime('%b',mktime(0,0,0,$mo,$da,$yr));
114 $per11 = strftime('%b',mktime(0,0,0,$mo-1,$da,$yr));
115 $per10 = strftime('%b',mktime(0,0,0,$mo-2,$da,$yr));
116 $per09 = strftime('%b',mktime(0,0,0,$mo-3,$da,$yr));
117 $per08 = strftime('%b',mktime(0,0,0,$mo-4,$da,$yr));
118 $per07 = strftime('%b',mktime(0,0,0,$mo-5,$da,$yr));
119 $per06 = strftime('%b',mktime(0,0,0,$mo-6,$da,$yr));
120 $per05 = strftime('%b',mktime(0,0,0,$mo-7,$da,$yr));
121 $per04 = strftime('%b',mktime(0,0,0,$mo-8,$da,$yr));
122 $per03 = strftime('%b',mktime(0,0,0,$mo-9,$da,$yr));
123 $per02 = strftime('%b',mktime(0,0,0,$mo-10,$da,$yr));
124 $per01 = strftime('%b',mktime(0,0,0,$mo-11,$da,$yr));
126 $headers = array(_('Account'), _('Account Name'), $per01, $per02, $per03, $per04,
127 $per05, $per06, $per07, $per08, $per09, $per10, $per11, $per12);
129 $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right', 'right',
130 'right', 'right', 'right', 'right', 'right', 'right');
134 $params = array( 0 => $comments,
135 1 => array('text' => _("Year"),
136 'from' => $year, 'to' => ''),
137 2 => array('text' => _("Dimension")." 1",
138 'from' => get_dimension_string($dimension), 'to' => ''),
139 3 => array('text' => _("Dimension")." 2",
140 'from' => get_dimension_string($dimension2), 'to' => ''),
141 4 => array('text' => _('Info'), 'from' => _('Amounts in thousands'),
146 $params = array( 0 => $comments,
147 1 => array('text' => _("Year"),
148 'from' => $year, 'to' => ''),
149 2 => array('text' => _('Dimension'),
150 'from' => get_dimension_string($dimension), 'to' => ''),
151 3 => array('text' => _('Info'), 'from' => _('Amounts in thousands'),
156 $params = array( 0 => $comments,
157 1 => array('text' => _("Year"),
158 'from' => $year, 'to' => ''),
159 2 => array('text' => _('Info'), 'from' => _('Amounts in thousands'),
163 $rep = new FrontReport(_('Annual Expense Breakdown'), "AnnualBreakDown.pdf", user_pagesize());
166 $rep->Info($params, $cols, $headers, $aligns);
171 $total = Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0);
172 $total2 = Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0);
173 $sales = Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0);
174 $calc = Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0);
175 $accounts = get_gl_accounts_all(0);
177 while ($account = db_fetch($accounts))
179 $bal = getPeriods($year, $account["account_code"], $dimension, $dimension2);
180 if (!$bal['per01'] && !$bal['per02'] && !$bal['per03'] && !$bal['per04'] &&
181 !$bal['per05'] && !$bal['per06'] && !$bal['per07'] && !$bal['per08'] &&
182 !$bal['per09'] && !$bal['per10'] && !$bal['per11'] && !$bal['per12'])
184 $balance = array(1 => $bal['per01'], $bal['per02'], $bal['per03'], $bal['per04'],
185 $bal['per05'], $bal['per06'], $bal['per07'], $bal['per08'],
186 $bal['per09'], $bal['per10'], $bal['per11'], $bal['per12']);
187 if ($account['AccountClassName'] != $classname)
189 if ($classname != '')
195 if ($account['AccountTypeName'] != $group)
199 $rep->Line($rep->row + 6);
201 $rep->TextCol(0, 2, _('Total') . " " . $group);
202 for ($i = 1; $i <= 12; $i++)
203 $rep->TextCol($i + 1, $i + 2, number_format2($total[$i], $dec));
204 $total = Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0);
205 $rep->row -= ($rep->lineHeight + 4);
208 $rep->Line($rep->row + 6);
211 $rep->TextCol(0, 2, _('Total') . " " . $classname);
212 for ($i = 1; $i <= 12; $i++)
214 $rep->TextCol($i + 1, $i + 2, number_format2($total2[$i], $dec));
215 $sales[$i] += $total2[$i];
218 $total2 = Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0);
223 if ($account['AccountClassName'] != $classname)
226 $rep->TextCol(0, 5, $account['AccountClassName']);
228 $rep->row -= ($rep->lineHeight + 4);
230 $group = $account['AccountTypeName'];
231 $rep->TextCol(0, 5, $account['AccountTypeName']);
232 $rep->Line($rep->row - 4);
233 $rep->row -= ($rep->lineHeight + 4);
235 $classname = $account['AccountClassName'];
236 $rep->TextCol(0, 1, $account['account_code']);
237 $rep->TextCol(1, 2, $account['account_name']);
238 for ($i = 1; $i <= 12; $i++)
240 $rep->TextCol($i + 1, $i + 2, number_format2($balance[$i], $dec));
241 $total[$i] += $balance[$i];
242 $total2[$i] += $balance[$i];
247 if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight)
249 $rep->Line($rep->row - 2);
253 if ($account['AccountClassName'] != $classname)
255 if ($classname != '')
260 if ($account['AccountTypeName'] != $group)
264 $rep->Line($rep->row + 6);
266 $rep->TextCol(0, 2, _('Total') . " " . $group);
267 for ($i = 1; $i <= 12; $i++)
268 $rep->TextCol($i + 1, $i + 2, number_format2($total[$i], $dec));
269 $rep->row -= ($rep->lineHeight + 4);
272 $rep->Line($rep->row + 6);
276 $rep->TextCol(0, 2, _('Total') . " " . $classname);
277 for ($i = 1; $i <= 12; $i++)
279 $rep->TextCol($i + 1, $i + 2, number_format2($total2[$i], $dec));
280 $calc[$i] = $sales[$i] + $total2[$i];
283 $rep->row -= ($rep->lineHeight + 8);
284 $rep->TextCol(0, 2, _('Calculated Return'));
285 for ($i = 1; $i <= 12; $i++)
286 $rep->TextCol($i + 1, $i + 2, number_format2($calc[$i], $dec));
293 $rep->Line($rep->row);