1 #=====================================================================
2 # SQL-Ledger Accounting
3 # Copyright (c) 1998-2002
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 #======================================================================
26 #======================================================================
32 require "$form->{path}/arap.pl";
38 # this is for our long dates
39 # $locale->text('January')
40 # $locale->text('February')
41 # $locale->text('March')
42 # $locale->text('April')
43 # $locale->text('May ')
44 # $locale->text('June')
45 # $locale->text('July')
46 # $locale->text('August')
47 # $locale->text('September')
48 # $locale->text('October')
49 # $locale->text('November')
50 # $locale->text('December')
52 # this is for our short month
53 # $locale->text('Jan')
54 # $locale->text('Feb')
55 # $locale->text('Mar')
56 # $locale->text('Apr')
57 # $locale->text('May')
58 # $locale->text('Jun')
59 # $locale->text('Jul')
60 # $locale->text('Aug')
61 # $locale->text('Sep')
62 # $locale->text('Oct')
63 # $locale->text('Nov')
64 # $locale->text('Dec')
69 $form->{title} = "Add";
71 $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback};
73 # we use this only to set a default date
74 GL->transaction(\%myconfig, \%$form);
76 map { $chart .= "<option>$_->{accno}--$_->{description}" } @{ $form->{chart} };
77 $form->{chart} = $chart;
79 $form->{rowcount} = 4;
87 GL->transaction(\%myconfig, \%$form);
89 map { $chart .= "<option>$_->{accno}--$_->{description}" } @{ $form->{chart} };
90 $form->{chart} = $chart;
92 $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig));
94 $form->{title} = "Edit";
99 foreach $ref (@{ $form->{GL} }) {
100 $form->{"accno_$i"} = $ref->{accno};
101 $form->{"oldprojectnumber_$i"} = $form->{"projectnumber_$i"} = $ref->{projectnumber};
102 $form->{"project_id_$i"} = $ref->{project_id};
104 if ($ref->{amount} < 0) {
105 $form->{totaldebit} -= $ref->{amount};
106 $form->{"debit_$i"} = $form->format_amount(\%myconfig, $ref->{amount} * -1, 2);
108 $form->{totalcredit} += $ref->{amount};
109 $form->{"credit_$i"} = ($ref->{amount} > 0) ? $form->format_amount(\%myconfig, $ref->{amount}, 2) : "";
125 $form->{title} = $locale->text('General Ledger')." ".$locale->text('Reports');
132 <form method=post action=$form->{script}>
134 <input type=hidden name=sort value=transdate>
138 <th class=listtop>$form->{title}</th>
145 <th align=right>|.$locale->text('Reference').qq|</th>
146 <td><input name=reference size=20></td>
147 <th align=right>|.$locale->text('Source').qq|</th>
148 <td><input name=source size=20></td>
151 <th align=right>|.$locale->text('Description').qq|</th>
152 <td colspan=3><input name=description size=40></td>
155 <th align=right>|.$locale->text('Notes').qq|</th>
156 <td colspan=3><input name=notes size=40></td>
159 <th align=right>|.$locale->text('From').qq|</th>
160 <td><input name=datefrom size=11 title="$myconfig{dateformat}"></td>
161 <th align=right>|.$locale->text('to').qq|</th>
162 <td><input name=dateto size=11 title="$myconfig{dateformat}"></td>
165 <th align=right>|.$locale->text('Include in Report').qq|</th>
170 <input name="category" class=radio type=radio value=X checked> |.$locale->text('All').qq|
171 <input name="category" class=radio type=radio value=A> |.$locale->text('Asset').qq|
172 <input name="category" class=radio type=radio value=L> |.$locale->text('Liability').qq|
173 <input name="category" class=radio type=radio value=Q> |.$locale->text('Equity').qq|
174 <input name="category" class=radio type=radio value=I> |.$locale->text('Income').qq|
175 <input name="category" class=radio type=radio value=E> |.$locale->text('Expense').qq|
181 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
182 <td>|.$locale->text('ID').qq|</td>
183 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
184 <td>|.$locale->text('Date').qq|</td>
185 <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
186 <td>|.$locale->text('Reference').qq|</td>
187 <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
188 <td>|.$locale->text('Description').qq|</td>
189 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
190 <td>|.$locale->text('Notes').qq|</td>
193 <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
194 <td>|.$locale->text('Debit').qq|</td>
195 <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
196 <td>|.$locale->text('Credit').qq|</td>
197 <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
198 <td>|.$locale->text('Source').qq|</td>
199 <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
200 <td>|.$locale->text('Account').qq|</td>
201 <td align=right><input name="l_gifi_accno" class=checkbox type=checkbox value=Y></td>
202 <td>|.$locale->text('GIFI').qq|</td>
205 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
206 <td>|.$locale->text('Subtotal').qq|</td>
216 <td><hr size=3 noshade></td>
220 <input type=hidden name=nextsub value=generate_report>
222 <input type=hidden name=path value=$form->{path}>
223 <input type=hidden name=login value=$form->{login}>
224 <input type=hidden name=password value=$form->{password}>
227 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
236 sub generate_report {
238 GL->all_transactions(\%myconfig, \%$form);
240 $callback = "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&password=$form->{password}";
242 %acctype = ( 'A' => $locale->text('Asset'),
243 'L' => $locale->text('Liability'),
244 'Q' => $locale->text('Equity'),
245 'I' => $locale->text('Income'),
246 'E' => $locale->text('Expense'),
249 $form->{title} = $locale->text('General Ledger');
251 $ml = ($form->{ml} =~ /(A|E)/) ? -1 : 1;
253 unless ($form->{category} eq 'X') {
254 $form->{title} .= " : ".$locale->text($acctype{$form->{category}});
256 if ($form->{accno}) {
257 $callback .= "&accno=$form->{accno}";
258 $option = $locale->text('Account')." : $form->{accno} $form->{account_description}";
260 if ($form->{gifi_accno}) {
261 $callback .= "&gifi_accno=$form->{gifi_accno}";
262 $option .= "\n<br>" if $option;
263 $option .= $locale->text('GIFI')." : $form->{gifi_accno} $form->{gifi_account_description}";
265 if ($form->{source}) {
266 $callback .= "&source=".$form->escape($form->{source});
267 $option .= "\n<br>" if $option;
268 $option .= $locale->text('Source')." : $form->{source}";
270 if ($form->{reference}) {
271 $callback .= "&reference=".$form->escape($form->{reference});
272 $option .= "\n<br>" if $option;
273 $option .= $locale->text('Reference')." : $form->{reference}";
275 if ($form->{description}) {
276 $callback .= "&description=".$form->escape($form->{description});
277 $option .= "\n<br>" if $option;
278 $option .= $locale->text('Description')." : $form->{description}";
280 if ($form->{notes}) {
281 $callback .= "¬es=".$form->escape($form->{notes});
282 $option .= "\n<br>" if $option;
283 $option .= $locale->text('Notes')." : $form->{notes}";
286 if ($form->{datefrom}) {
287 $callback .= "&datefrom=$form->{datefrom}";
288 $option .= "\n<br>" if $option;
289 $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{datefrom}, 1);
291 if ($form->{dateto}) {
292 $callback .= "&dateto=$form->{dateto}";
293 if ($form->{datefrom}) {
296 $option .= "\n<br>" if $option;
298 $option .= $locale->text('to')." ".$locale->date(\%myconfig, $form->{dateto}, 1);
302 @columns = $form->sort_columns(qw(transdate id reference description notes source debit credit accno gifi_accno));
304 if ($form->{accno} || $form->{gifi_accno}) {
305 @columns = grep !/(accno|gifi_accno)/, @columns;
306 push @columns, "balance";
307 $form->{l_balance} = "Y";
310 $href = "$callback&sort=$form->{sort}"; # needed for accno
312 foreach $item (@columns) {
313 if ($form->{"l_$item"} eq "Y") {
314 push @column_index, $item;
316 # add column to href and callback
317 $callback .= "&l_$item=Y";
318 $href .= "&l_$item=Y";
322 if ($form->{l_subtotal} eq 'Y') {
323 $callback .= "&l_subtotal=Y";
324 $href .= "&l_subtotal=Y";
327 $callback .= "&category=$form->{category}";
328 $href .= "&category=$form->{category}";
330 $column_header{id} = "<th><a class=listheading href=$callback&sort=id>".$locale->text('ID')."</a></th>";
331 $column_header{transdate} = "<th><a class=listheading href=$callback&sort=transdate>".$locale->text('Date')."</a></th>";
332 $column_header{reference} = "<th><a class=listheading href=$callback&sort=reference>".$locale->text('Reference')."</a></th>";
333 $column_header{source} = "<th><a class=listheading href=$callback&sort=source>".$locale->text('Source')."</a></th>";
334 $column_header{description} = "<th><a class=listheading href=$callback&sort=description>".$locale->text('Description')."</a></th>";
335 $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>";
336 $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</th>";
337 $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</th>";
338 $column_header{accno} = "<th><a class=listheading href=$callback&sort=accno>".$locale->text('Account')."</a></th>";
339 $column_header{gifi_accno} = "<th><a class=listheading href=$callback&sort=gifi_accno>".$locale->text('GIFI')."</a></th>";
340 $column_header{balance} = "<th class=listheading>".$locale->text('Balance')."</th>";
349 <th class=listtop>$form->{title}</th>
358 <tr class=listheading>
361 map { print "$column_header{$_}\n" } @column_index;
367 # add sort to callback
368 $form->{callback} = "$callback&sort=$form->{sort}";
369 $callback = $form->escape($form->{callback});
371 # initial item for subtotals
372 if (@{ $form->{GL} }) {
373 $sameitem = $form->{GL}->[0]->{$form->{sort}};
376 if (($form->{accno} || $form->{gifi_accno}) && $form->{balance}) {
378 map { $column_data{$_} = "<td> </td>" } @column_index;
379 $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
385 map { print "$column_data{$_}\n" } @column_index;
392 foreach $ref (@{ $form->{GL} }) {
394 # if item ne sort print subtotal
395 if ($form->{l_subtotal} eq 'Y') {
396 if ($sameitem ne $ref->{$form->{sort}}) {
401 $form->{balance} += $ref->{amount};
403 $subtotaldebit += $ref->{debit};
404 $subtotalcredit += $ref->{credit};
406 $totaldebit += $ref->{debit};
407 $totalcredit += $ref->{credit};
409 $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, " ");
410 $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, " ");
412 $column_data{id} = "<td>$ref->{id}</td>";
413 $column_data{transdate} = "<td>$ref->{transdate}</td>";
414 $column_data{reference} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{reference}</td>";
415 $column_data{description} = "<td>$ref->{description} </td>";
416 $column_data{source} = "<td>$ref->{source} </td>";
417 $column_data{notes} = "<td>$ref->{notes} </td>";
418 $column_data{debit} = "<td align=right>$ref->{debit}</td>";
419 $column_data{credit} = "<td align=right>$ref->{credit}</td>";
420 $column_data{accno} = "<td><a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{accno}</a></td>";
421 $column_data{gifi_accno} = "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a> </td>";
422 $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
426 <tr class=listrow$i>";
427 map { print "$column_data{$_}\n" } @column_index;
433 &gl_subtotal if ($form->{l_subtotal} eq 'Y');
436 map { $column_data{$_} = "<td> </td>" } @column_index;
438 $column_data{debit} = "<th align=right>".$form->format_amount(\%myconfig, $totaldebit, 2, " ")."</th>";
439 $column_data{credit} = "<th align=right>".$form->format_amount(\%myconfig, $totalcredit, 2, " ")."</th>";
440 $column_data{balance} = "<th align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</th>";
446 map { print "$column_data{$_}\n" } @column_index;
454 <td><hr size=3 noshade></td>
460 <form method=post action=$form->{script}>
462 <input name=callback type=hidden value="$form->{callback}">
464 <input type=hidden name=path value=$form->{path}>
465 <input type=hidden name=login value=$form->{login}>
466 <input type=hidden name=password value=$form->{password}>
468 <input class=submit type=submit name=action value="|.$locale->text('GL Transaction').qq|">
469 <input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|">
470 <input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|">
471 <input class=submit type=submit name=action value="|.$locale->text('Sales Invoice').qq|">
472 <input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice').qq|">
485 $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");
486 $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, " ");
488 map { $column_data{$_} = "<td> </td>" } qw(transdate id reference source description accno);
489 $column_data{debit} = "<th class=listsubtotal align=right>$subtotaldebit</td>";
490 $column_data{credit} = "<th class=listsubtotal align=right>$subtotalcredit</td>";
493 print "<tr class=listsubtotal>";
494 map { print "$column_data{$_}\n" } @column_index;
500 $sameitem = $ref->{$form->{sort}};
509 @flds = (qw(accno debit credit projectnumber project_id));
511 for $i (1 .. $form->{rowcount}) {
512 unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
514 ($form->{"accno_$i"}) = split(/--/, $form->{"accno_$i"});
519 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
524 for $i (1 .. $count) {
526 map { $form->{"${_}_$i"} = $a[$j]->{$_} } @flds;
529 for $i ($count + 1 .. $form->{rowcount}) {
530 map { delete $form->{"${_}_$i"} } @flds;
533 $form->{rowcount} = $count;
547 $form->{totaldebit} = 0;
548 $form->{totalcredit} = 0;
550 for $i (1 .. $form->{rowcount}) {
551 $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
552 $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
565 my $chart = $form->{chart};
566 $chart =~ s/<option>$form->{"accno_$i"}/<option selected>$form->{"accno_$i"}/;
569 <td><select name="accno_$i">$chart</select></td>
570 <td><input name="debit_$i" size=12 value=$form->{"debit_$i"}></td>
571 <td><input name="credit_$i" size=12 value=$form->{"credit_$i"}></td>
572 <td><input name="projectnumber_$i" size=12 value="$form->{"projectnumber_$i"}">
573 <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
574 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
576 <input type=hidden name=rowcount value=$i>
585 $title = $form->{title};
586 $form->{title} = $locale->text("$title General Ledger Transaction");
588 # $locale->text('Add General Ledger Transaction')
589 # $locale->text('Edit General Ledger Transaction')
591 map { $form->{$_} =~ s/"/"/g } qw(reference description chart);
593 if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
594 $description = qq|<textarea name=description rows=$rows cols=50 wrap=soft>$form->{description}</textarea>|;
596 $description = qq|<input name=description size=50 value="$form->{description}">|;
599 if (($rows = $form->numtextrows($form->{notes}, 50)) > 1) {
600 $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
602 $notes = qq|<input name=notes size=50 value="$form->{notes}">|;
610 <form method=post action=$form->{script}>
612 <input name=id type=hidden value=$form->{id}>
614 <input name=chart type=hidden value="$form->{chart}">
615 <input type=hidden name=closedto value=$form->{closedto}>
616 <input type=hidden name=locked value=$form->{locked}>
617 <input type=hidden name=title value="$title">
621 <th class=listtop>$form->{title}</th>
628 <th align=right>|.$locale->text('Reference').qq|</th>
629 <td><input name=reference size=20 value="$form->{reference}"></td>
633 <th align=right>|.$locale->text('Date').qq|</th>
634 <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
640 <th align=right>|.$locale->text('Description').qq|</th>
641 <td colspan=2>$description</td>
644 <th align=right>|.$locale->text('Notes').qq|</th>
645 <td colspan=2>$notes</td>
653 <tr class=listheading>
654 <th class=listheading>|.$locale->text('Account').qq|</th>
655 <th class=listheading>|.$locale->text('Debit').qq|</th>
656 <th class=listheading>|.$locale->text('Credit').qq|</th>
657 <th class=listheading>|.$locale->text('Project').qq|</th>
666 ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
668 $decimalplaces = ($dec > 2) ? $dec : 2;
670 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces, " ") } qw(totaldebit totalcredit);
675 <th class=listtotal align=right>$form->{totaldebit}</th>
676 <th class=listtotal align=right>$form->{totalcredit}</th>
683 <td><hr size=3 noshade></td>
687 <input type=hidden name=path value=$form->{path}>
688 <input type=hidden name=login value=$form->{login}>
689 <input type=hidden name=password value=$form->{password}>
691 <input name=callback type=hidden value="$form->{callback}">
696 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
697 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
700 print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
703 if (!$form->{revtrans}) {
704 if (!$form->{locked}) {
706 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">
707 <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">
712 if ($transdate > $closedto) {
714 <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">
719 if ($transdate > $closedto) {
720 print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
721 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
741 <form method=post action=$form->{script}>
744 map { $form->{$_} =~ s/"/"/g } qw(reference description chart);
746 foreach $key (keys %$form) {
747 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
751 <h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
753 <h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{reference}</h4>
755 <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
764 $form->redirect($locale->text('Transaction deleted!')) if (GL->delete_transaction(\%myconfig, \%$form));
765 $form->error($locale->text('Cannot delete transaction!'));
772 # check if there is something in reference and date
773 $form->isblank("reference", $locale->text('Reference missing!'));
774 $form->isblank("transdate", $locale->text('Transaction Date missing!'));
776 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
777 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
782 # this is just for the wise guys
783 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
785 if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
787 $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
788 $err[2] = $locale->text('Debit and credit out of balance!');
789 $err[3] = $locale->text('Cannot post a transaction without a value!');
791 $form->error($err[$errno]);
794 $form->redirect($locale->text('Transaction posted!'));