1 #=====================================================================
2 # SQL-Ledger Accounting
5 # Author: Dieter Simader
6 # Email: dsimader@sql-ledger.org
7 # Web: http://www.sql-ledger.org
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #======================================================================
24 # module for Chart of Accounts, Income Statement and Balance Sheet
25 # search and edit transactions posted by the GL, AR and AP
27 #======================================================================
35 # this is for our long dates
36 # $locale->text('January')
37 # $locale->text('February')
38 # $locale->text('March')
39 # $locale->text('April')
40 # $locale->text('May ')
41 # $locale->text('June')
42 # $locale->text('July')
43 # $locale->text('August')
44 # $locale->text('September')
45 # $locale->text('October')
46 # $locale->text('November')
47 # $locale->text('December')
49 # this is for our short month
50 # $locale->text('Jan')
51 # $locale->text('Feb')
52 # $locale->text('Mar')
53 # $locale->text('Apr')
54 # $locale->text('May')
55 # $locale->text('Jun')
56 # $locale->text('Jul')
57 # $locale->text('Aug')
58 # $locale->text('Sep')
59 # $locale->text('Oct')
60 # $locale->text('Nov')
61 # $locale->text('Dec')
64 sub chart_of_accounts {
66 CA->all_accounts(\%myconfig, \%$form);
68 @column_index = qw(accno gifi_accno description debit credit);
70 $column_header{accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</th>\n|;
71 $column_header{gifi_accno} = qq|<th class=listheading>|.$locale->text('GIFI').qq|</th>\n|;
72 $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>\n|;
73 $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</th>\n|;
74 $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</th>\n|;
77 $form->{title} = $locale->text('Chart of Accounts');
79 $colspan = $#column_index + 1;
87 <tr><th class=listtop colspan=$colspan>$form->{title}</font></th></tr>
89 <tr class=listheading>|;
91 map { print $column_header{$_} } @column_index;
98 foreach $ca (@{ $form->{CA} }) {
100 $description = $form->escape($ca->{description});
101 $gifi_description = $form->escape($ca->{gifi_description});
103 $href = qq|$form->{script}?path=$form->{path}&action=list&accno=$ca->{accno}&login=$form->{login}&password=$form->{password}&description=$description&gifi_accno=$ca->{gifi_accno}&gifi_description=$gifi_description|;
105 if ($ca->{charttype} eq "H") {
106 print qq|<tr class=listheading>|;
107 map { $column_data{$_} = "<th class=listheading>$ca->{$_}</th>"; } qw(accno description);
108 $column_data{gifi_accno} = "<th class=listheading>$ca->{gifi_accno} </font></th>";
111 print qq|<tr class=listrow$i>|;
112 $column_data{accno} = "<td><a href=$href>$ca->{accno}</a></td>";
113 $column_data{gifi_accno} = "<td><a href=$href&accounttype=gifi>$ca->{gifi_accno}</a> </td>";
114 $column_data{description} = "<td>$ca->{description}</td>";
117 $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{debit}, 2, " ")."</td>\n";
118 $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{credit}, 2, " ")."</td>\n";
120 $totaldebit += $ca->{debit};
121 $totalcredit += $ca->{credit};
123 map { print $column_data{$_} } @column_index;
130 map { $column_data{$_} = "<td> </td>"; } qw(accno gifi_accno description);
132 $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebit, 2, 0)."</font></th>";
133 $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredit, 2, 0)."</font></th>";
135 print "<tr class=listtotal>";
137 map { print $column_data{$_} } @column_index;
142 <td colspan=$colspan><hr size=3 noshade></td>
155 $form->{title} = $locale->text('List Transactions');
156 if ($form->{accounttype} eq 'gifi') {
157 $form->{title} .= " - ".$locale->text('GIFI')." $form->{gifi_accno}";
159 $form->{title} .= " - ".$locale->text('Account')." $form->{accno}";
164 map { $form->{$_} =~ s/"/"/g; } qw(description gifi_description);
169 <form method=post action=$form->{script}>
171 <input type=hidden name=accno value=$form->{accno}>
172 <input type=hidden name=description value="$form->{description}">
173 <input type=hidden name=sort value=transdate>
175 <input type=hidden name=accounttype value=$form->{accounttype}>
176 <input type=hidden name=gifi_accno value=$form->{gifi_accno}>
177 <input type=hidden name=gifi_description value="$form->{gifi_description}">
179 <table border=0 width=100%>
180 <tr><th class=listtop>$form->{title}</font></th></tr>
186 <th align=right>|.$locale->text('From').qq|</th>
187 <td><input name=fromdate size=11 title="$myconfig{dateformat}"></td>
188 <th align=right>|.$locale->text('to').qq|</th>
189 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
192 <th align=right>|.$locale->text('Include in Report').qq|</th>
194 <input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
199 <tr><td><hr size=3 noshade></td></tr>
202 <input type=hidden name=login value=$form->{login}>
203 <input type=hidden name=path value=$form->{path}>
204 <input type=hidden name=password value=$form->{password}>
206 <br><input class=submit type=submit name=action value="|.$locale->text('List Transactions').qq|">
216 sub list_transactions {
218 CA->all_transactions(\%myconfig, \%$form);
220 $description = $form->escape($form->{description});
221 $gifi_description = $form->escape($form->{gifi_description});
224 $href = "$form->{script}?path=$form->{path}&action=list_transactions&accno=$form->{accno}&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&description=$description&accounttype=$form->{accounttype}&gifi_accno=$form->{gifi_accno}&gifi_description=$gifi_description&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}";
227 $callback = "rp.pl?path=$form->{path}&action=generate_trial_balance&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&accounttype=$form->{accounttype}";
229 # figure out which column comes first
230 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</a></th>|;
231 $column_header{reference} = qq|<th><a class=listheading href=$href&sort=reference>|.$locale->text('Reference').qq|</a></th>|;
232 $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
233 $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</th>|;
234 $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</th>|;
235 $column_header{balance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
237 @column_index = $form->sort_columns(qw(transdate reference description debit credit));
239 if ($form->{accounttype} eq 'gifi') {
240 map { $form->{$_} = $form->{"gifi_$_"} } qw(accno description);
242 if ($form->{accno}) {
243 push @column_index, "balance";
246 $form->{title} = ($form->{accounttype} eq 'gifi') ? $locale->text('GIFI') : $locale->text('Account');
248 $form->{title} .= " $form->{accno} - $form->{description}";
251 if ($form->{fromdate} || $form->{todate}) {
252 if ($form->{fromdate}) {
253 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
255 if ($form->{todate}) {
256 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
259 $form->{period} = "$fromdate - $todate";
261 $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig),1);
272 <th class=listtop>$form->{title}</font></th>
276 <td>$form->{period}</td>
281 <tr class=listheading>
284 map { print "$column_header{$_}\n" } @column_index;
290 # add sort to callback
291 $callback = $form->escape($callback . "&sort=$form->{sort}");
293 if (@{ $form->{CA} }) {
294 $sameitem = $form->{CA}->[0]->{$form->{sort}};
297 $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
298 if ($form->{accno} && $form->{balance}) {
300 map { $column_data{$_} = "<td> </td>" } @column_index;
302 $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
308 map { print $column_data{$_} } @column_index;
314 foreach $ca (@{ $form->{CA} }) {
316 if ($form->{l_subtotal} eq 'Y') {
317 if ($sameitem ne $ca->{$form->{sort}}) {
322 # construct link to source
323 $href = "<a href=$ca->{module}.pl?path=$form->{path}&action=edit&id=$ca->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{reference}</a>";
326 $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{debit}, 2, " ")."</td>";
327 $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{credit}, 2, " ")."</td>";
329 $form->{balance} += $ca->{amount};
330 $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
332 $subtotaldebit += $ca->{debit};
333 $subtotalcredit += $ca->{credit};
335 $totaldebit += $ca->{debit};
336 $totalcredit += $ca->{credit};
338 $column_data{transdate} = qq|<td>$ca->{transdate}</td>|;
339 $column_data{reference} = qq|<td>$href</td>|;
340 $column_data{description} = qq|<td>$ca->{description}</td>|;
347 map { print $column_data{$_} } @column_index;
356 if ($form->{l_subtotal} eq 'Y') {
361 map { $column_data{$_} = "<td> </td>" } @column_index;
363 $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebit, 2, " ")."</font></th>";
364 $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredit, 2, " ")."</font></th>";
365 $column_data{balance} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</font></th>";
371 map { print $column_data{$_} } @column_index;
379 <td><hr size=3 noshade></td>
392 map { $column_data{$_} = "<td> </td>" } @column_index;
394 $column_data{debit} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotaldebit, 2, " ") . "</font></th>";
395 $column_data{credit} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalcredit, 2, " ") . "</font></th>";
400 $sameitem = $ca->{$form->{sort}};
403 <tr class=listsubtotal>
406 map { print "$column_data{$_}\n" } @column_index;