1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
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 #======================================================================
32 #======================================================================
37 use POSIX qw(strftime);
38 use List::Util qw(sum);
44 use SL::ReportGenerator;
46 require "bin/mozilla/common.pl";
47 require "bin/mozilla/drafts.pl";
48 require "bin/mozilla/reportgenerator.pl";
50 # this is for our long dates
51 # $locale->text('January')
52 # $locale->text('February')
53 # $locale->text('March')
54 # $locale->text('April')
55 # $locale->text('May ')
56 # $locale->text('June')
57 # $locale->text('July')
58 # $locale->text('August')
59 # $locale->text('September')
60 # $locale->text('October')
61 # $locale->text('November')
62 # $locale->text('December')
64 # this is for our short month
65 # $locale->text('Jan')
66 # $locale->text('Feb')
67 # $locale->text('Mar')
68 # $locale->text('Apr')
69 # $locale->text('May')
70 # $locale->text('Jun')
71 # $locale->text('Jul')
72 # $locale->text('Aug')
73 # $locale->text('Sep')
74 # $locale->text('Oct')
75 # $locale->text('Nov')
76 # $locale->text('Dec')
79 $main::lxdebug->enter_sub();
81 $main::auth->assert('general_ledger');
83 my $form = $main::form;
84 my %myconfig = %main::myconfig;
86 return $main::lxdebug->leave_sub() if (load_draft_maybe());
88 $form->{title} = "Add";
90 $form->{callback} = "gl.pl?action=add" unless $form->{callback};
92 # we use this only to set a default date
93 # yep. aber er holt hier auch schon ALL_CHARTS. Aufwand / Nutzen? jb
94 GL->transaction(\%myconfig, \%$form);
96 $form->{rowcount} = 2;
103 $form->all_departments(\%myconfig);
104 if (@{ $form->{all_departments} || [] }) {
105 $form->{selectdepartment} = "<option>\n";
108 $form->{selectdepartment} .=
109 "<option>$_->{description}--$_->{id}\n"
110 } (@{ $form->{all_departments} || [] });
113 $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
116 $main::lxdebug->leave_sub();
120 sub prepare_transaction {
121 $main::lxdebug->enter_sub();
123 $main::auth->assert('general_ledger');
125 my $form = $main::form;
126 my %myconfig = %main::myconfig;
128 GL->transaction(\%myconfig, \%$form);
130 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
133 $form->all_departments(\%myconfig);
134 if (@{ $form->{all_departments} || [] }) {
135 $form->{selectdepartment} = "<option>\n";
138 $form->{selectdepartment} .=
139 "<option>$_->{description}--$_->{id}\n"
140 } (@{ $form->{all_departments} || [] });
146 foreach my $ref (@{ $form->{GL} }) {
148 if ($tax && ($ref->{accno} eq $taxaccno)) {
149 $form->{"tax_$j"} = abs($ref->{amount});
150 $form->{"taxchart_$j"} = $ref->{id} . "--" . $ref->{taxrate};
151 if ($form->{taxincluded}) {
152 if ($ref->{amount} < 0) {
153 $form->{"debit_$j"} += $form->{"tax_$j"};
155 $form->{"credit_$j"} += $form->{"tax_$j"};
158 $form->{"project_id_$j"} = $ref->{project_id};
161 $form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
162 for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
163 if ($ref->{amount} < 0) {
164 $form->{totaldebit} -= $ref->{amount};
165 $form->{"debit_$i"} = $ref->{amount} * -1;
167 $form->{totalcredit} += $ref->{amount};
168 $form->{"credit_$i"} = $ref->{amount};
170 $form->{"taxchart_$i"} = "0--0.00";
171 $form->{"project_id_$i"} = $ref->{project_id};
174 if ($ref->{taxaccno} && !$tax) {
175 $taxaccno = $ref->{taxaccno};
183 $form->{rowcount} = $i;
185 ($form->datetonum($form->{transdate}, \%myconfig) <=
186 $form->datetonum($form->{closedto}, \%myconfig));
188 $main::lxdebug->leave_sub();
192 $main::lxdebug->enter_sub();
194 $main::auth->assert('general_ledger');
196 my $form = $main::form;
197 my %myconfig = %main::myconfig;
199 prepare_transaction();
201 $form->{title} = "Edit";
203 $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
209 $main::lxdebug->leave_sub();
214 $main::lxdebug->enter_sub();
216 $main::auth->assert('general_ledger');
218 my $form = $main::form;
219 my %myconfig = %main::myconfig;
220 my $locale = $main::locale;
221 my $cgi = $main::cgi;
223 $form->{title} = $locale->text('Journal');
225 $form->all_departments(\%myconfig);
228 if (@{ $form->{all_departments} || [] }) {
229 $form->{selectdepartment} = "<option>\n";
232 $form->{selectdepartment} .=
233 "<option>$_->{description}--$_->{id}\n"
234 } (@{ $form->{all_departments} || [] });
239 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
240 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
242 | if $form->{selectdepartment};
244 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
246 "employees" => "ALL_EMPLOYEES" );
248 my %project_labels = ();
249 my @project_values = ("");
250 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
251 push(@project_values, $item->{"id"});
252 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
256 NTI($cgi->popup_menu('-name' => "project_id",
257 '-values' => \@project_values,
258 '-labels' => \%project_labels));
260 my %employee_labels = ();
261 my @employee_values = ("");
262 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
263 # value in Form "1234--Name" übergeben
264 my $id = "$item->{'id'}--$item->{'name'}";
265 push(@employee_values, "$id");
266 $employee_labels{$id} = $item->{"name"};
270 NTI($cgi->popup_menu('-name' => "employee",
271 '-values' => \@employee_values,
272 '-labels' => \%employee_labels));
274 # use JavaScript Calendar or not
275 $form->{jsscript} = 1;
277 my ($button1, $button2, $onload);
278 if ($form->{jsscript}) {
280 # with JavaScript Calendar
282 <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
283 <input type=button name=datefrom id="trigger1" value=|
284 . $locale->text('button') . qq|></td>
287 <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
288 <input type=button name=dateto id="trigger2" value=|
289 . $locale->text('button') . qq|></td>
294 Form->write_trigger(\%myconfig, "2", "datefrom", "BR", "trigger1",
295 "dateto", "BL", "trigger2");
298 # without JavaScript Calendar
300 qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
302 qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
304 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
306 $onload = qq|focus()|;
307 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
308 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
310 <body onLoad="$onload">
312 <form method=post action=gl.pl>
314 <input type=hidden name=sort value=datesort>
318 <th class=listtop>$form->{title}</th>
325 <th align=right>| . $locale->text('Reference') . qq|</th>
326 <td><input name=reference size=20></td>
327 <th align=right>| . $locale->text('Source') . qq|</th>
328 <td><input name=source size=20></td>
332 <th align=right>| . $locale->text('Description') . qq|</th>
333 <td><input name=description size=40></td>
334 <th align=right>| . $locale->text('Account Number') . qq|</th>
335 <td><input name=accno size=20></td>
338 <th align=right>| . $locale->text('Notes') . qq|</th>
339 <td colspan=3><input name=notes size=40></td>
342 <th align=right>| . $locale->text('Project Number') . qq|</th>
343 <td colspan=3>$projectnumber</td>
346 <th align=right>| . $locale->text('Employee') . qq|</th>
347 <td colspan=3>$employeenumber</td>
350 <th align=right>| . $locale->text('Filter date by') . qq|</th>
352 <input name=datesort class=radio type=radio value=gldate checked> | . $locale->text('Booking Date') . qq|
353 <input name=datesort class=radio type=radio value=transdate> | . $locale->text('Invoice Date') . qq|
357 <th align=right>| . $locale->text('From') . qq|</th>
359 <th align=right>| . $locale->text('To (time)') . qq|</th>
363 <th align=right>| . $locale->text('Include in Report') . qq|</th>
368 <input name="category" class=radio type=radio value=X checked> |
369 . $locale->text('All') . qq|
370 <input name="category" class=radio type=radio value=A> |
371 . $locale->text('Asset') . qq|
372 <input name="category" class=radio type=radio value=L> |
373 . $locale->text('Liability') . qq|
374 <input name="category" class=radio type=radio value=I> |
375 . $locale->text('Revenue') . qq|
376 <input name="category" class=radio type=radio value=E> |
377 . $locale->text('Expense') . qq|
383 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
384 <td>| . $locale->text('ID') . qq|</td>
385 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
386 <td>| . $locale->text('Invoice Date') . qq|</td>
387 <td align=right><input name="l_gldate" class=checkbox type=checkbox value=Y checked></td>
388 <td>| . $locale->text('Booking Date') . qq|</td>
389 <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
390 <td>| . $locale->text('Reference') . qq|</td>
391 <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
392 <td>| . $locale->text('Description') . qq|</td>
393 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
394 <td>| . $locale->text('Notes') . qq|</td>
397 <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
398 <td>| . $locale->text('Debit') . qq|</td>
399 <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
400 <td>| . $locale->text('Credit') . qq|</td>
401 <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
402 <td>| . $locale->text('Source') . qq|</td>
403 <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
404 <td>| . $locale->text('Account') . qq|</td>
407 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
408 <td>| . $locale->text('Subtotal') . qq|</td>
409 <td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
410 <td>| . $locale->text('Project Number') . qq|</td>
411 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
412 <td>| . $locale->text('Employee') . qq|</td>
422 <td><hr size=3 noshade></td>
428 <input type=hidden name=nextsub value=generate_report>
431 <input class=submit type=submit name=action value="|
432 . $locale->text('Continue') . qq|">
438 $main::lxdebug->leave_sub();
441 sub create_subtotal_row {
442 $main::lxdebug->enter_sub();
444 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
446 my $form = $main::form;
447 my %myconfig = %main::myconfig;
449 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
451 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
453 map { $totals->{$_} = 0 } @{ $subtotal_columns };
455 $main::lxdebug->leave_sub();
460 sub generate_report {
461 $main::lxdebug->enter_sub();
463 $main::auth->assert('general_ledger');
465 my $form = $main::form;
466 my %myconfig = %main::myconfig;
467 my $locale = $main::locale;
469 # generate_report wird beim ersten Aufruf per Weiter-Knopf und POST mit der hidden Variablen sort mit Wert "datesort" (früher "transdate" als Defaultsortiervariable) übertragen
471 # <form method=post action=gl.pl>
472 # <input type=hidden name=sort value=datesort> # form->{sort} setzen
473 # <input type=hidden name=nextsub value=generate_report>
475 # anhand von neuer Variable datesort wird jetzt $form->{sort} auf transdate oder gldate gesetzt
476 # damit ist die Hidden Variable "sort" wahrscheinlich sogar überflüssig
478 # ändert man die Sortierreihenfolge per Klick auf eine der Überschriften wird die Variable "sort" per GET übergeben, z.B. id,transdate, gldate, ...
479 # gl.pl?action=generate_report&employee=18383--Jan%20B%c3%bcren&datesort=transdate&category=X&l_transdate=Y&l_gldate=Y&l_id=Y&l_reference=Y&l_description=Y&l_source=Y&l_debit=Y&l_credit=Y&sort=gldate&sortdir=0
481 if ( $form->{sort} eq 'datesort' ) { # sollte bei einem Post (Aufruf aus Suchmaske) immer wahr sein
482 # je nachdem ob in Suchmaske "transdate" oder "gldate" ausgesucht wurde erstes Suchergebnis entsprechend sortieren
483 $form->{sort} = $form->{datesort};
487 report_generator_set_default_sort("$form->{datesort}", 1);
488 # report_generator_set_default_sort('transdate', 1);
490 GL->all_transactions(\%myconfig, \%$form);
492 my %acctype = ('A' => $locale->text('Asset'),
493 'C' => $locale->text('Contra'),
494 'L' => $locale->text('Liability'),
495 'Q' => $locale->text('Equity'),
496 'I' => $locale->text('Revenue'),
497 'E' => $locale->text('Expense'),);
499 $form->{title} = $locale->text('Journal');
500 if ($form->{category} ne 'X') {
501 $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
504 $form->{landscape} = 1;
506 my $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
509 gldate transdate id reference description
510 notes source debit debit_accno
511 credit credit_accno debit_tax debit_tax_accno
512 credit_tax credit_tax_accno projectnumbers balance employee
515 # add employee here, so that variable is still known and passed in url when choosing a different sort order in resulting table
516 my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto employee datesort category l_subtotal);
517 push @hidden_variables, map { "l_${_}" } @columns;
518 foreach ( @hidden_variables ) {
522 my (@options, @date_options);
523 push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}" if ($form->{accno});
524 push @options, $locale->text('Source') . " : $form->{source}" if ($form->{source});
525 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
526 push @options, $locale->text('Description') . " : $form->{description}" if ($form->{description});
527 push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes});
528 push @options, $locale->text('Employee') . " : $form->{employee_name}" if ($form->{employee_name});
529 my $datesorttext = $form->{datesort} eq 'transdate' ? $locale->text('Invoice Date') : $locale->text('Booking Date');
530 push @date_options, "$datesorttext" if ($form->{datesort} and ($form->{datefrom} or $form->{dateto}));
531 push @date_options, $locale->text('From'), $locale->date(\%myconfig, $form->{datefrom}, 1) if ($form->{datefrom});
532 push @date_options, $locale->text('Bis'), $locale->date(\%myconfig, $form->{dateto}, 1) if ($form->{dateto});
533 push @options, join(' ', @date_options) if (scalar @date_options);
535 if ($form->{department}) {
536 my ($department) = split /--/, $form->{department};
537 push @options, $locale->text('Department') . " : $department";
541 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
545 $form->{l_credit_accno} = 'Y';
546 $form->{l_debit_accno} = 'Y';
547 $form->{l_credit_tax} = 'Y';
548 $form->{l_debit_tax} = 'Y';
549 # $form->{l_gldate} = 'Y'; # Spalte mit gldate immer anzeigen
550 $form->{l_credit_tax_accno} = 'Y';
551 $form->{l_datesort} = 'Y';
552 $form->{l_debit_tax_accno} = 'Y';
553 $form->{l_balance} = $form->{accno} ? 'Y' : '';
556 'id' => { 'text' => $locale->text('ID'), },
557 'transdate' => { 'text' => $locale->text('Invoice Date'), },
558 'gldate' => { 'text' => $locale->text('Booking Date'), },
559 'reference' => { 'text' => $locale->text('Reference'), },
560 'source' => { 'text' => $locale->text('Source'), },
561 'description' => { 'text' => $locale->text('Description'), },
562 'notes' => { 'text' => $locale->text('Notes'), },
563 'debit' => { 'text' => $locale->text('Debit'), },
564 'debit_accno' => { 'text' => $locale->text('Debit Account'), },
565 'credit' => { 'text' => $locale->text('Credit'), },
566 'credit_accno' => { 'text' => $locale->text('Credit Account'), },
567 'debit_tax' => { 'text' => $locale->text('Debit Tax'), },
568 'debit_tax_accno' => { 'text' => $locale->text('Debit Tax Account'), },
569 'credit_tax' => { 'text' => $locale->text('Credit Tax'), },
570 'credit_tax_accno' => { 'text' => $locale->text('Credit Tax Account'), },
571 'balance' => { 'text' => $locale->text('Balance'), },
572 'projectnumbers' => { 'text' => $locale->text('Project Numbers'), },
573 'employee' => { 'text' => $locale->text('Employee'), },
576 foreach my $name (qw(id transdate gldate reference description debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
577 my $sortname = $name =~ m/accno/ ? 'accno' : $name;
578 my $sortdir = $sortname eq $form->{sort} ? 1 - $form->{sortdir} : $form->{sortdir};
579 $column_defs{$name}->{link} = $callback . "&sort=$sortname&sortdir=$sortdir";
582 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
583 map { $column_defs{$_}->{visible} = 0 } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno) if $form->{accno};
585 my %column_alignment;
586 map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax balance);
587 map { $column_alignment{$_} = 'center' } qw(transdate gldate reference debit_accno credit_accno debit_tax_accno credit_tax_accno);
588 map { $column_alignment{$_} = 'left' } qw(description source notes);
589 map { $column_defs{$_}->{align} = $column_alignment{$_} } keys %column_alignment;
591 my $report = SL::ReportGenerator->new(\%myconfig, $form);
593 $report->set_columns(%column_defs);
594 $report->set_column_order(@columns);
596 $report->set_export_options('generate_report', @hidden_variables, qw(sort sortdir));
598 $report->set_sort_indicator($form->{sort} eq 'accno' ? 'debit_accno' : $form->{sort}, $form->{sortdir});
600 $report->set_options('top_info_text' => join("\n", @options),
601 'output_format' => 'HTML',
602 'title' => $form->{title},
603 'attachment_basename' => $locale->text('general_ledger_list') . strftime('_%Y%m%d', localtime time),
605 $report->set_options_from_form();
606 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
608 # add sort to callback
609 $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
612 my @totals_columns = qw(debit credit debit_tax credit_tax);
613 my %subtotals = map { $_ => 0 } @totals_columns;
614 my %totals = map { $_ => 0 } @totals_columns;
617 foreach my $ref (@{ $form->{GL} }) {
621 foreach my $key (qw(debit credit debit_tax credit_tax)) {
623 foreach my $idx (sort keys(%{ $ref->{$key} })) {
624 my $value = $ref->{$key}->{$idx};
625 $subtotals{$key} += $value;
626 $totals{$key} += $value;
627 if ($key =~ /debit.*/) {
632 $form->{balance} = $form->{balance} + $value * $ml;
633 push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2);
637 foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate source)) {
638 my $col = $key eq 'ac_transdate' ? 'transdate' : $key;
639 $rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ];
643 map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
646 if ($form->{balance} < 0) {
649 } elsif ($form->{balance} > 0) {
653 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
656 $row->{balance}->{data} = $data;
657 $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
659 map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description notes gldate employee);
661 map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno source);
663 foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
664 $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
667 map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
669 $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
671 my $row_set = [ $row ];
673 if (($form->{l_subtotal} eq 'Y')
674 && (($idx == (scalar @{ $form->{GL} } - 1))
675 || ($ref->{ $form->{sort} } ne $form->{GL}->[$idx + 1]->{ $form->{sort} }))) {
676 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, [ qw(debit credit) ], 'listsubtotal');
679 $report->add_data($row_set);
684 $report->add_separator();
686 # = 0 for balanced ledger
687 my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax};
689 my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal');
692 if ($form->{balance} < 0) {
695 } elsif ($form->{balance} > 0) {
699 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
702 $row->{balance}->{data} = $data;
704 $report->add_data($row);
706 my $raw_bottom_info_text;
708 if (!$form->{accno} && (abs($balanced_ledger) > 0.001)) {
709 $raw_bottom_info_text .=
710 '<p><span class="unbalanced_ledger">'
711 . $locale->text('Unbalanced Ledger')
713 . $form->format_amount(\%myconfig, $balanced_ledger, 3)
717 $raw_bottom_info_text .= $form->parse_html_template('gl/generate_report_bottom');
719 $report->set_options('raw_bottom_info_text' => $raw_bottom_info_text);
721 $report->generate_with_headers();
723 $main::lxdebug->leave_sub();
727 $main::lxdebug->enter_sub();
729 $main::auth->assert('general_ledger');
731 my $form = $main::form;
732 my %myconfig = %main::myconfig;
734 $form->{oldtransdate} = $form->{transdate};
742 my ($debitcredit, $amount);
745 qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
747 for my $i (1 .. $form->{rowcount}) {
749 unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
750 for (qw(debit credit tax)) {
752 $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
756 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
763 if (($debitcount >= 2) && ($creditcount == 2)) {
764 $form->{"credit_$i"} = 0;
765 $form->{"tax_$i"} = 0;
767 $form->{creditlock} = 1;
769 if (($creditcount >= 2) && ($debitcount == 2)) {
770 $form->{"debit_$i"} = 0;
771 $form->{"tax_$i"} = 0;
773 $form->{debitlock} = 1;
775 if (($creditcount == 1) && ($debitcount == 2)) {
776 $form->{creditlock} = 1;
778 if (($creditcount == 2) && ($debitcount == 1)) {
779 $form->{debitlock} = 1;
781 if ($debitcredit && $credittax) {
782 $form->{"taxchart_$i"} = "0--0.00";
784 if (!$debitcredit && $debittax) {
785 $form->{"taxchart_$i"} = "0--0.00";
788 ($form->{"debit_$i"} == 0)
789 ? $form->{"credit_$i"}
790 : $form->{"debit_$i"};
792 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
793 $form->{"taxchart_$i"} = "0--0.00";
794 $form->{"tax_$i"} = 0;
796 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
803 if ($form->{taxincluded}) {
804 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
806 $form->{"tax_$i"} = $amount * $rate;
809 $form->{"tax_$i"} = 0;
812 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
817 for my $i (1 .. $count) {
819 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
822 for my $i ($count + 1 .. $form->{rowcount}) {
823 for (@flds) { delete $form->{"${_}_$i"} }
826 $form->{rowcount} = $count + 1;
829 $main::lxdebug->leave_sub();
835 $main::lxdebug->enter_sub();
837 $main::auth->assert('general_ledger');
839 my $form = $main::form;
840 my %myconfig = %main::myconfig;
844 # for $i (1 .. $form->{rowcount}) {
845 # $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
846 # $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
850 &display_rows($init);
852 $main::lxdebug->leave_sub();
858 $main::lxdebug->enter_sub();
860 $main::auth->assert('general_ledger');
862 my $form = $main::form;
863 my %myconfig = %main::myconfig;
864 my $cgi = $main::cgi;
866 $form->{debit_1} = 0 if !$form->{"debit_1"};
867 $form->{totaldebit} = 0;
868 $form->{totalcredit} = 0;
870 my %project_labels = ();
871 my @project_values = ("");
872 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
873 push(@project_values, $item->{"id"});
874 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
877 my %chart_labels = ();
878 my @chart_values = ();
881 foreach my $item (@{ $form->{ALL_CHARTS} }) {
882 if ($item->{charttype} eq 'H'){ #falls überschrift
883 next; #überspringen (Bug 1150)
885 my $key = $item->{accno} . "--" . $item->{tax_id};
886 $taxchart_init = $item->{tax_id} unless (@chart_values);
887 push(@chart_values, $key);
888 $chart_labels{$key} = $item->{accno} . "--" . $item->{description};
889 $charts{$item->{accno}} = $item;
892 my %taxchart_labels = ();
893 my @taxchart_values = ();
895 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
896 my $key = $item->{id} . "--" . $item->{rate};
897 $taxchart_init = $key if ($taxchart_init == $item->{id});
898 push(@taxchart_values, $key);
899 $taxchart_labels{$key} = $item->{taxdescription} . " " . $item->{rate} * 100 . ' %';
900 $taxcharts{$item->{id}} = $item;
903 my ($source, $memo, $source_hidden, $memo_hidden);
904 for my $i (1 .. $form->{rowcount}) {
905 if ($form->{show_details}) {
907 <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
909 <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
912 <input type="hidden" name="source_$i" value="$form->{"source_$i"}" size="16">|;
914 <input type="hidden" name="memo_$i" value="$form->{"memo_$i"}" size="16">|;
917 my $selected_accno_full;
918 my ($accno_row) = split(/--/, $form->{"accno_$i"});
919 my $item = $charts{$accno_row};
920 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
922 my $selected_taxchart = $form->{"taxchart_$i"};
923 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
924 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
926 if ($previous_accno &&
927 ($previous_accno eq $selected_accno) &&
928 ($previous_tax_id ne $selected_tax_id)) {
929 my $item = $taxcharts{$selected_tax_id};
930 $selected_taxchart = "$item->{id}--$item->{rate}";
933 $selected_accno = '' if ($init);
934 $selected_taxchart ||= $taxchart_init;
936 my $accno = qq|<td>| .
937 NTI($cgi->popup_menu('-name' => "accno_$i",
939 '-onChange' => "setTaxkey($i)",
940 '-style' => 'width:200px',
941 '-values' => \@chart_values,
942 '-labels' => \%chart_labels,
943 '-default' => $selected_accno_full))
944 . $cgi->hidden('-name' => "previous_accno_$i",
945 '-default' => $selected_accno_full)
947 my $tax_ddbox = qq|<td>| .
948 NTI($cgi->popup_menu('-name' => "taxchart_$i",
949 '-id' => "taxchart_$i",
950 '-style' => 'width:200px',
951 '-values' => \@taxchart_values,
952 '-labels' => \%taxchart_labels,
953 '-default' => $selected_taxchart))
956 my ($fx_transaction, $checked);
958 if ($form->{transfer}) {
959 $fx_transaction = qq|
960 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
965 if ($form->{"debit_$i"} != 0) {
966 $form->{totaldebit} += $form->{"debit_$i"};
967 if (!$form->{taxincluded}) {
968 $form->{totaldebit} += $form->{"tax_$i"};
971 $form->{totalcredit} += $form->{"credit_$i"};
972 if (!$form->{taxincluded}) {
973 $form->{totalcredit} += $form->{"tax_$i"};
977 for (qw(debit credit tax)) {
980 ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
984 if ($i < $form->{rowcount}) {
985 if ($form->{transfer}) {
986 $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
987 my $x = ($checked) ? "x" : "";
988 $fx_transaction = qq|
989 <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
992 $form->hide_form("accno_$i");
995 if ($form->{transfer}) {
996 $fx_transaction = qq|
997 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
1002 my $debitreadonly = "";
1003 my $creditreadonly = "";
1004 if ($i == $form->{rowcount}) {
1005 if ($form->{debitlock}) {
1006 $debitreadonly = "readonly";
1007 } elsif ($form->{creditlock}) {
1008 $creditreadonly = "readonly";
1013 NTI($cgi->popup_menu('-name' => "project_id_$i",
1014 '-values' => \@project_values,
1015 '-labels' => \%project_labels,
1016 '-default' => $form->{"project_id_$i"} ));
1017 my $projectnumber_hidden = qq|
1018 <input type="hidden" name="project_id_$i" value="$form->{"project_id_$i"}">|;
1020 my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
1022 print qq|<tr valign=top>
1024 <td id="chart_balance_$i" align="right"> </td>
1026 <td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td>
1027 <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
1028 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
1031 if ($form->{show_details}) {
1035 <td>$projectnumber</td>
1041 $projectnumber_hidden
1049 $form->hide_form(qw(rowcount selectaccno));
1051 $main::lxdebug->leave_sub();
1057 $main::lxdebug->enter_sub();
1059 $main::auth->assert('general_ledger');
1061 my $form = $main::form;
1062 my %myconfig = %main::myconfig;
1063 my $locale = $main::locale;
1065 my @old_project_ids = ();
1066 map({ push(@old_project_ids, $form->{"project_id_$_"})
1067 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
1069 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1071 "old_id" => \@old_project_ids },
1072 "charts" => { "key" => "ALL_CHARTS",
1073 "transdate" => $form->{transdate} },
1074 "taxcharts" => "ALL_TAXCHARTS");
1076 GL->get_chart_balances('charts' => $form->{ALL_CHARTS});
1078 my $title = $form->{title};
1079 $form->{title} = $locale->text("$title General Ledger Transaction");
1080 my $readonly = ($form->{id}) ? "readonly" : "";
1082 my $show_details_checked = "checked" if $form->{show_details};
1084 my $ob_transaction_checked = "checked" if $form->{ob_transaction};
1085 my $cb_transaction_checked = "checked" if $form->{cb_transaction};
1087 # $locale->text('Add General Ledger Transaction')
1088 # $locale->text('Edit General Ledger Transaction')
1090 map { $form->{$_} =~ s/\"/"/g }
1091 qw(reference description chart taxchart);
1093 $form->{javascript} = qq|<script type="text/javascript">
1095 function setTaxkey(row) {
1096 var accno = document.getElementById('accno_' + row);
1097 var taxkey = accno.options[accno.selectedIndex].value;
1098 var reg = /--([0-9]*)/;
1099 var found = reg.exec(taxkey);
1100 var index = found[1];
1101 index = parseInt(index);
1102 var tax = 'taxchart_' + row;
1103 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
1104 var reg2 = new RegExp("^"+ index, "");
1105 if (reg2.exec(document.getElementById(tax).options[i].value)) {
1106 document.getElementById(tax).options[i].selected = true;
1112 function copy_debit_to_credit() {
1113 var txt = document.getElementsByName('debit_1')[0].value;
1114 document.getElementsByName('credit_2')[0].value = txt;
1118 <script type="text/javascript" src="js/show_form_details.js"></script>
1119 <script type="text/javascript" src="js/jquery.js"></script>
1122 $form->{selectdepartment} =~ s/ selected//;
1123 $form->{selectdepartment} =~
1124 s/option>\Q$form->{department}\E/option selected>$form->{department}/;
1127 if ((my $rows = $form->numtextrows($form->{description}, 50)) > 1) {
1129 qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
1132 qq|<input name=description size=50 value="$form->{description}" $readonly>|;
1135 my $taxincluded = ($form->{taxincluded}) ? "checked" : "";
1138 $taxincluded = "checked";
1144 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1145 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1146 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
1148 | if $form->{selectdepartment};
1150 $form->{fokus} = "gl.reference";
1152 $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
1155 # use JavaScript Calendar or not
1156 $form->{jsscript} = 1;
1158 my ($button1, $button2);
1159 if ($form->{jsscript}) {
1161 # with JavaScript Calendar
1163 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\">
1164 <input type=button name=transdate id="trigger1" value=|
1165 . $locale->text('button') . qq|></td>
1170 Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
1173 # without JavaScript Calendar
1175 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\"></td>|;
1178 $form->{previous_id} ||= "--";
1179 $form->{previous_gldate} ||= "--";
1181 $jsscript .= $form->parse_html_template('gl/form_header_chart_balances_js');
1186 <body onLoad="focus()">
1188 <script type="text/javascript" src="js/follow_up.js"></script>
1190 <form method=post name="gl" action=gl.pl>
1193 $form->hide_form(qw(id closedto locked storno storno_id previous_id previous_gldate));
1196 <input type=hidden name=title value="$title">
1198 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
1199 <input type="hidden" name="follow_up_trans_type_1" value="gl_transaction">
1200 <input type="hidden" name="follow_up_trans_info_1" value="| . H($form->{id}) . qq|">
1201 <input type="hidden" name="follow_up_rowcount" value="1">
1205 <th class=listtop>$form->{title}</th>
1208 ($form->{saved_message} ? qq|
1210 <td>$form->{saved_message}</th>
1214 <tr height="5"></tr>
1219 <td colspan="6" align="left">|
1220 . $locale->text("Previous transnumber text")
1221 . " $form->{previous_id} "
1222 . $locale->text("Previous transdate text")
1223 . " $form->{previous_gldate}"
1227 <th align=right>| . $locale->text('Reference') . qq|</th>
1228 <td><input name=reference size=20 value="$form->{reference}" $readonly></td>
1232 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
1241 <th align=right>| . $locale->text('Belegnummer') . qq|</th>
1242 <td><input name=id size=20 value="$form->{id}" $readonly></td>
1246 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
1247 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly onBlur=\"check_right_date_format(this)\"></td>
1258 <th align=right width=1%>| . $locale->text('Description') . qq|</th>
1259 <td width=1%>$description</td>
1263 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1264 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1271 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
1272 <td align=left><input name=employee size=20 value="| . H($form->{employee}) . qq|" readonly></td>
1280 <th align=left width=1%>| . $locale->text('Description') . qq|</th>
1281 <td width=1%>$description</td>
1285 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1286 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1295 <tr><td colspan=4><table><tr>
1297 | . $locale->text('OB Transaction') . qq|<input type="checkbox" name="ob_transaction" value="1" $ob_transaction_checked>
1300 | . $locale->text('CB Transaction') . qq|<input type="checkbox" name="cb_transaction" value="1" $cb_transaction_checked>
1302 </tr></table></td></tr>
1304 <td width="1%" align="right" nowrap>| . $locale->text('Show details') . qq|</td>
1305 <td width="1%"><input type="checkbox" onclick="show_form_details();" name="show_details" value="1" $show_details_checked></td>
1312 <tr class=listheading>
1313 <th class=listheading style="width:15%">|
1314 . $locale->text('Account') . qq|</th>
1315 <th class=listheading style="width:10%">| . $locale->text('Chart balance') . qq|</th>
1316 <th class=listheading style="width:10%">|
1317 . $locale->text('Debit') . qq|</th>
1318 <th class=listheading style="width:10%">|
1319 . $locale->text('Credit') . qq|</th>
1320 <th class=listheading style="width:10%">|
1321 . $locale->text('Tax') . qq|</th>
1322 <th class=listheading style="width:5%">|
1323 . $locale->text('Taxkey') . qq|</th>|;
1325 if ($form->{show_details}) {
1327 <th class=listheading style="width:20%">| . $locale->text('Source') . qq|</th>
1328 <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
1329 <th class=listheading style="width:20%">| . $locale->text('Project Number') . qq|</th>
1338 $main::lxdebug->leave_sub();
1343 $main::lxdebug->enter_sub();
1345 $main::auth->assert('general_ledger');
1347 my $form = $main::form;
1348 my %myconfig = %main::myconfig;
1349 my $locale = $main::locale;
1350 my $cgi = $main::cgi;
1352 my $follow_ups_block;
1354 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
1356 if (@{ $follow_ups} ) {
1357 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
1358 $follow_ups_block = qq|<p>| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</p>|;
1362 my ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
1364 my $decimalplaces = ($dec > 2) ? $dec : 2;
1365 my $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
1368 $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
1369 } qw(totaldebit totalcredit);
1372 <tr class=listtotal>
1373 <th colspan="3" align=right class=listtotal> $form->{totaldebit}</th>
1374 <th align=right class=listtotal> $form->{totalcredit}</th>
1382 <input name=callback type=hidden value="$form->{callback}">
1389 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1390 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1394 if (!$form->{storno}) {
1395 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|;
1398 # Löschen und Ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
1399 if (!$form->{locked} && $radieren) {
1401 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|" accesskey="b">
1402 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">|;
1406 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1407 <input type="button" class="submit" onclick="follow_up_window()" value="|
1408 . $locale->text('Follow-Up')
1412 if ($form->{draft_id}) {
1413 my $remove_draft_checked = 'checked' if ($form->{remove_draft});
1415 . qq| <input name="remove_draft" id="remove_draft" type="checkbox" class="checkbox" ${remove_draft_checked}>|
1416 . qq| <label for="remove_draft">| . $locale->text('Remove Draft') . qq|</label>\n|
1421 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1422 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> |
1423 . NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'))
1424 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1425 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
1434 $main::lxdebug->leave_sub();
1439 $main::lxdebug->enter_sub();
1441 my $form = $main::form;
1442 my $locale = $main::locale;
1449 <form method=post action=gl.pl>
1452 map { $form->{$_} =~ s/\"/"/g } qw(reference description);
1454 delete $form->{header};
1456 foreach my $key (keys %$form) {
1457 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1458 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1462 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1465 . $locale->text('Are you sure you want to delete Transaction')
1466 . qq| $form->{reference}</h4>
1468 <input name=action class=submit type=submit value="|
1469 . $locale->text('Yes') . qq|">
1472 $main::lxdebug->leave_sub();
1477 $main::lxdebug->enter_sub();
1479 my $form = $main::form;
1480 my %myconfig = %main::myconfig;
1481 my $locale = $main::locale;
1483 if (GL->delete_transaction(\%myconfig, \%$form)){
1484 # saving the history
1485 if(!exists $form->{addition} && $form->{id} ne "") {
1486 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1487 $form->{addition} = "DELETED";
1488 $form->save_history;
1490 # /saving the history
1491 $form->redirect($locale->text('Transaction deleted!'))
1493 $form->error($locale->text('Cannot delete transaction!'));
1494 $main::lxdebug->leave_sub();
1498 sub post_transaction {
1499 $main::lxdebug->enter_sub();
1501 my $form = $main::form;
1502 my %myconfig = %main::myconfig;
1503 my $locale = $main::locale;
1505 # check if there is something in reference and date
1506 $form->isblank("reference", $locale->text('Reference missing!'));
1507 $form->isblank("transdate", $locale->text('Transaction Date missing!'));
1508 $form->isblank("description", $locale->text('Description missing!'));
1510 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1511 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1518 my $creditcount = 0;
1521 my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
1523 for my $i (1 .. $form->{rowcount}) {
1524 next if $form->{"debit_$i"} eq "" && $form->{"credit_$i"} eq "";
1526 for (qw(debit credit tax)) {
1527 $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
1531 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
1539 if (($debitcount >= 2) && ($creditcount == 2)) {
1540 $form->{"credit_$i"} = 0;
1541 $form->{"tax_$i"} = 0;
1543 $form->{creditlock} = 1;
1545 if (($creditcount >= 2) && ($debitcount == 2)) {
1546 $form->{"debit_$i"} = 0;
1547 $form->{"tax_$i"} = 0;
1549 $form->{debitlock} = 1;
1551 if (($creditcount == 1) && ($debitcount == 2)) {
1552 $form->{creditlock} = 1;
1554 if (($creditcount == 2) && ($debitcount == 1)) {
1555 $form->{debitlock} = 1;
1557 if ($debitcredit && $credittax) {
1558 $form->{"taxchart_$i"} = "0--0.00";
1560 if (!$debitcredit && $debittax) {
1561 $form->{"taxchart_$i"} = "0--0.00";
1563 my $amount = ($form->{"debit_$i"} == 0)
1564 ? $form->{"credit_$i"}
1565 : $form->{"debit_$i"};
1567 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
1568 $form->{"taxchart_$i"} = "0--0.00";
1569 $form->{"tax_$i"} = 0;
1571 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
1578 if ($form->{taxincluded}) {
1579 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
1581 $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
1583 $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
1586 $form->{"tax_$i"} = $amount * $rate;
1589 $form->{"tax_$i"} = 0;
1592 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
1596 for my $i (1 .. $count) {
1598 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
1601 for my $i ($count + 1 .. $form->{rowcount}) {
1602 for (@flds) { delete $form->{"${_}_$i"} }
1605 my ($debit, $credit, $taxtotal);
1606 for my $i (1 .. $form->{rowcount}) {
1607 my $dr = $form->{"debit_$i"};
1608 my $cr = $form->{"credit_$i"};
1609 my $tax = $form->{"tax_$i"};
1611 $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
1613 $debit += $dr + $tax if $dr;
1614 $credit += $cr + $tax if $cr;
1615 $taxtotal += $tax if $form->{taxincluded}
1618 $form->{taxincluded} = 0 if !$taxtotal;
1620 # this is just for the wise guys
1621 $form->error($locale->text('Cannot post transaction for a closed period!'))
1622 if ($form->date_closed($form->{"transdate"}, \%myconfig));
1623 if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
1624 $form->error($locale->text('Out of balance transaction!'));
1627 if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
1628 $form->error($locale->text('Empty transaction!'));
1631 if ((my $errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
1634 $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
1635 $err[2] = $locale->text('Debit and credit out of balance!');
1636 $err[3] = $locale->text('Cannot post a transaction without a value!');
1638 $form->error($err[$errno]);
1640 undef($form->{callback});
1641 # saving the history
1642 if(!exists $form->{addition} && $form->{id} ne "") {
1643 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1644 $form->{addition} = "SAVED";
1645 $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id};
1646 $form->save_history;
1648 # /saving the history
1650 $main::lxdebug->leave_sub();
1654 $main::lxdebug->enter_sub();
1656 $main::auth->assert('general_ledger');
1658 my $form = $main::form;
1659 my $locale = $main::locale;
1661 if ($::myconfig{mandatory_departments} && !$form->{department}) {
1662 $form->{saved_message} = $::locale->text('You have to specify a department.');
1667 $form->{title} = $locale->text("$form->{title} General Ledger Transaction");
1668 $form->{storno} = 0;
1672 remove_draft() if $form->{remove_draft};
1674 $form->{callback} = build_std_url("action=add&DONT_LOAD_DRAFT=1", "show_details");
1675 $form->redirect($form->{callback});
1677 $main::lxdebug->leave_sub();
1681 $main::lxdebug->enter_sub();
1683 $main::auth->assert('general_ledger');
1685 my $form = $main::form;
1689 $main::lxdebug->leave_sub();
1694 $main::lxdebug->enter_sub();
1696 $main::auth->assert('general_ledger');
1698 my $form = $main::form;
1699 my %myconfig = %main::myconfig;
1700 my $locale = $main::locale;
1702 # don't cancel cancelled transactions
1703 if (IS->has_storno(\%myconfig, $form, 'gl')) {
1704 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1705 $form->error($locale->text("Transaction has already been cancelled!"));
1708 GL->storno($form, \%myconfig, $form->{id});
1710 # saving the history
1711 if(!exists $form->{addition} && $form->{id} ne "") {
1712 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1713 $form->{addition} = "STORNO";
1714 $form->save_history;
1716 # /saving the history
1718 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1720 $main::lxdebug->leave_sub();
1724 call_sub($main::form->{nextsub});