1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
30 # module for Chart of Accounts, Income Statement and Balance Sheet
31 # search and edit transactions posted by the GL, AR and AP
33 #======================================================================
41 # this is for our long dates
42 # $locale->text('January')
43 # $locale->text('February')
44 # $locale->text('March')
45 # $locale->text('April')
46 # $locale->text('May ')
47 # $locale->text('June')
48 # $locale->text('July')
49 # $locale->text('August')
50 # $locale->text('September')
51 # $locale->text('October')
52 # $locale->text('November')
53 # $locale->text('December')
55 # this is for our short month
56 # $locale->text('Jan')
57 # $locale->text('Feb')
58 # $locale->text('Mar')
59 # $locale->text('Apr')
60 # $locale->text('May')
61 # $locale->text('Jun')
62 # $locale->text('Jul')
63 # $locale->text('Aug')
64 # $locale->text('Sep')
65 # $locale->text('Oct')
66 # $locale->text('Nov')
67 # $locale->text('Dec')
69 sub chart_of_accounts {
70 $lxdebug->enter_sub();
72 CA->all_accounts(\%myconfig, \%$form);
74 @column_index = qw(accno description debit credit);
76 $column_header{accno} =
77 qq|<th class=listheading>| . $locale->text('Account') . qq|</th>\n|;
78 $column_header{description} =
79 qq|<th class=listheading>| . $locale->text('Description') . qq|</th>\n|;
80 $column_header{debit} =
81 qq|<th class=listheading>| . $locale->text('Debit') . qq|</th>\n|;
82 $column_header{credit} =
83 qq|<th class=listheading>| . $locale->text('Credit') . qq|</th>\n|;
85 $form->{title} = $locale->text('Chart of Accounts');
87 $colspan = $#column_index + 1;
94 <table border=0 width=100%>
95 <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr>
97 <tr class=listheading>|;
99 map { print $column_header{$_} } @column_index;
105 foreach $ca (@{ $form->{CA} }) {
107 $description = $form->escape($ca->{description});
110 qq|$form->{script}?action=list&accno=$ca->{accno}&login=$form->{login}&password=$form->{password}&description=$description|;
112 if ($ca->{charttype} eq "H") {
113 print qq|<tr class=listheading>|;
114 map { $column_data{$_} = "<th>$ca->{$_}</th>"; } qw(accno description);
118 print qq|<tr class=listrow$i>|;
119 $column_data{accno} = "<td><a href=$href>$ca->{accno}</a></td>";
120 $column_data{description} = "<td>$ca->{description}</td>";
125 $debit = $form->format_amount(\%myconfig, $ca->{debit}, 2, " ");
128 $credit = $form->format_amount(\%myconfig, $ca->{credit}, 2, " ");
130 $column_data{debit} =
134 $column_data{credit} =
139 $totaldebit += $ca->{debit};
140 $totalcredit += $ca->{credit};
142 map { print $column_data{$_} } @column_index;
149 map { $column_data{$_} = "<td> </td>"; }
150 qw(accno description);
152 $column_data{debit} =
153 "<th align=right class=listtotal>"
154 . $form->format_amount(\%myconfig, $totaldebit, 2, 0) . "</th>";
155 $column_data{credit} =
156 "<th align=right class=listtotal>"
157 . $form->format_amount(\%myconfig, $totalcredit, 2, 0) . "</th>";
159 print "<tr class=listtotal>";
161 map { print $column_data{$_} } @column_index;
166 <td colspan=$colspan><hr size=3 noshade></td>
174 $lxdebug->leave_sub();
178 $lxdebug->enter_sub();
180 $form->{title} = $locale->text('List Transactions');
181 $form->{title} .= " - " . $locale->text('Account') . " $form->{accno}";
184 $form->all_departments(\%myconfig);
185 if (@{ $form->{all_departments} }) {
186 $form->{selectdepartment} = "<option>\n";
189 $form->{selectdepartment} .=
190 "<option>$_->{description}--$_->{id}\n"
191 } (@{ $form->{all_departments} });
196 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
197 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
199 | if $form->{selectdepartment};
203 $form->{description} =~ s/\"/"/g;
208 <form method=post action=$form->{script}>
210 <input type=hidden name=accno value=$form->{accno}>
211 <input type=hidden name=description value="$form->{description}">
212 <input type=hidden name=sort value=transdate>
213 <input type=hidden name=eur value=$eur>
214 <input type=hidden name=accounttype value=$form->{accounttype}>
216 <table border=0 width=100%>
217 <tr><th class=listtop>$form->{title}</th></tr>
224 <th align=right>| . $locale->text('From') . qq|</th>
225 <td><input name=fromdate size=11 title="$myconfig{dateformat}"></td>
226 <th align=right>| . $locale->text('To') . qq|</th>
227 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
230 <th align=right>| . $locale->text('Include in Report') . qq|</th>
232 <input name=l_subtotal class=checkbox type=checkbox value=Y> |
233 . $locale->text('Subtotal') . qq|</td>
238 <tr><td><hr size=3 noshade></td></tr>
241 <input type=hidden name=login value=$form->{login}>
242 <input type=hidden name=password value=$form->{password}>
244 <br><input class=submit type=submit name=action value="|
245 . $locale->text('List Transactions') . qq|">
252 $lxdebug->leave_sub();
255 sub list_transactions {
256 $lxdebug->enter_sub();
258 CA->all_transactions(\%myconfig, \%$form);
260 $description = $form->escape($form->{description});
261 $department = $form->escape($form->{department});
262 $projectnumber = $form->escape($form->{projectnumber});
263 $title = $form->escape($form->{title});
267 "$form->{script}?action=list_transactions&accno=$form->{accno}&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&description=$description&accounttype=$form->{accounttype}&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title";
269 $description = $form->escape($form->{description}, 1);
270 $department = $form->escape($form->{department}, 1);
271 $projectnumber = $form->escape($form->{projectnumber}, 1);
272 $title = $form->escape($form->{title}, 1);
276 "$form->{script}?action=list_transactions&accno=$form->{accno}&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&description=$description&accounttype=$form->{accounttype}&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title";
278 # figure out which column comes first
279 $column_header{transdate} =
280 qq|<th><a class=listheading href=$href&sort=transdate>|
281 . $locale->text('Date')
283 $column_header{reference} =
284 qq|<th><a class=listheading href=$href&sort=reference>|
285 . $locale->text('Reference')
287 $column_header{description} =
288 qq|<th><a class=listheading href=$href&sort=description>|
289 . $locale->text('Description')
291 $column_header{debit} = qq|<th>| . $locale->text('Debit') . qq|</th>|;
292 $column_header{credit} = qq|<th>| . $locale->text('Credit') . qq|</th>|;
293 $column_header{balance} = qq|<th>| . $locale->text('Balance') . qq|</th>|;
296 $form->sort_columns(qw(transdate reference description debit credit));
298 if ($form->{accno}) {
299 push @column_index, "balance";
302 $form->{title} = $locale->text('Account') .
303 " $form->{accno} - $form->{description}";
305 if ($form->{department}) {
306 ($department) = split /--/, $form->{department};
307 $options = $locale->text('Department') . " : $department<br>";
309 if ($form->{projectnumber}) {
310 $options .= $locale->text('Project Number');
311 $options .= " : $form->{projectnumber}<br>";
314 if ($form->{fromdate} || $form->{todate}) {
315 if ($form->{fromdate}) {
316 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
318 if ($form->{todate}) {
319 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
322 $form->{period} = "$fromdate - $todate";
325 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
328 $options .= $form->{period};
337 <th class=listtop>$form->{title}</th>
346 <tr class=listheading>
349 map { print "$column_header{$_}\n" } @column_index;
355 # add sort to callback
356 $callback = $form->escape($callback . "&sort=$form->{sort}");
358 if (@{ $form->{CA} }) {
359 $sameitem = $form->{CA}->[0]->{ $form->{sort} };
362 $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
363 if ($form->{accno} && $form->{balance}) {
365 map { $column_data{$_} = "<td> </td>" } @column_index;
367 $column_data{balance} =
369 . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)
377 map { print $column_data{$_} } @column_index;
383 foreach $ca (@{ $form->{CA} }) {
385 if ($form->{l_subtotal} eq 'Y') {
386 if ($sameitem ne $ca->{ $form->{sort} }) {
391 # construct link to source
393 "<a href=$ca->{module}.pl?action=edit&id=$ca->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{reference}</a>";
394 my $debit = ($ca->{debit} != 0) ? $form->format_amount(\%myconfig, $ca->{debit}, 2, " ") : " ";
395 $column_data{debit} =
396 "<td align=right>$debit</td>";
397 my $credit = ($ca->{credit} != 0) ? $form->format_amount(\%myconfig, $ca->{credit}, 2, " ") : " ";
398 $column_data{credit} =
399 "<td align=right>$credit</td>";
401 $form->{balance} += $ca->{amount};
402 $column_data{balance} =
404 . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)
407 $subtotaldebit += $ca->{debit};
408 $subtotalcredit += $ca->{credit};
410 $totaldebit += $ca->{debit};
411 $totalcredit += $ca->{credit};
413 $column_data{transdate} = qq|<td>$ca->{transdate}</td>|;
414 $column_data{reference} = qq|<td>$href</td>|;
415 $column_data{description} = qq|<td>$ca->{description}</td>|;
423 map { print $column_data{$_} } @column_index;
431 if ($form->{l_subtotal} eq 'Y') {
435 map { $column_data{$_} = "<td> </td>" } @column_index;
437 $column_data{debit} =
439 . $form->format_amount(\%myconfig, $totaldebit, 2, " ") . "</th>";
440 $column_data{credit} =
442 . $form->format_amount(\%myconfig, $totalcredit, 2, " ") . "</th>";
443 $column_data{balance} =
445 . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0) . "</th>";
451 map { print $column_data{$_} } @column_index;
459 <td><hr size=3 noshade></td>
467 $lxdebug->leave_sub();
471 $lxdebug->enter_sub();
473 map { $column_data{$_} = "<td> </td>" } @column_index;
475 $column_data{debit} =
477 . $form->format_amount(\%myconfig, $subtotaldebit, 2, " ") . "</th>";
478 $column_data{credit} =
480 . $form->format_amount(\%myconfig, $subtotalcredit, 2, " ") . "</th>";
485 $sameitem = $ca->{ $form->{sort} };
488 <tr class=listsubtotal>
491 map { print "$column_data{$_}\n" } @column_index;
497 $lxdebug->leave_sub();