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('From') . qq|</th>
348 <th align=right>| . $locale->text('Employee') . qq|</th>
349 <td colspan=3>$employeenumber</td>
352 <th align=right>| . $locale->text('Date Sorting') . qq|</th>
354 <input name=datesort class=radio type=radio value=gldate checked> | . $locale->text('Booking Date') . qq|
355 <input name=datesort class=radio type=radio value=transdate> | . $locale->text('Invoice Date') . qq|
359 <th align=right>| . $locale->text('From') . qq|</th>
361 <th align=right>| . $locale->text('To (time)') . qq|</th>
365 <th align=right>| . $locale->text('Include in Report') . qq|</th>
370 <input name="category" class=radio type=radio value=X checked> |
371 . $locale->text('All') . qq|
372 <input name="category" class=radio type=radio value=A> |
373 . $locale->text('Asset') . qq|
374 <input name="category" class=radio type=radio value=L> |
375 . $locale->text('Liability') . qq|
376 <input name="category" class=radio type=radio value=I> |
377 . $locale->text('Revenue') . qq|
378 <input name="category" class=radio type=radio value=E> |
379 . $locale->text('Expense') . qq|
385 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
386 <td>| . $locale->text('ID') . qq|</td>
387 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
388 <td>| . $locale->text('Invoice Date') . qq|</td>
389 <td align=right><input name="l_gldate" class=checkbox type=checkbox value=Y checked></td>
390 <td>| . $locale->text('Booking Date') . qq|</td>
391 <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
392 <td>| . $locale->text('Reference') . qq|</td>
393 <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
394 <td>| . $locale->text('Description') . qq|</td>
395 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
396 <td>| . $locale->text('Notes') . qq|</td>
399 <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
400 <td>| . $locale->text('Debit') . qq|</td>
401 <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
402 <td>| . $locale->text('Credit') . qq|</td>
403 <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
404 <td>| . $locale->text('Source') . qq|</td>
405 <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
406 <td>| . $locale->text('Account') . qq|</td>
409 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
410 <td>| . $locale->text('Subtotal') . qq|</td>
411 <td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
412 <td>| . $locale->text('Project Number') . qq|</td>
413 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
414 <td>| . $locale->text('Employee') . qq|</td>
424 <td><hr size=3 noshade></td>
430 <input type=hidden name=nextsub value=generate_report>
433 <input class=submit type=submit name=action value="|
434 . $locale->text('Continue') . qq|">
440 $main::lxdebug->leave_sub();
443 sub create_subtotal_row {
444 $main::lxdebug->enter_sub();
446 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
448 my $form = $main::form;
449 my %myconfig = %main::myconfig;
451 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
453 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
455 map { $totals->{$_} = 0 } @{ $subtotal_columns };
457 $main::lxdebug->leave_sub();
462 sub generate_report {
463 $main::lxdebug->enter_sub();
465 $main::auth->assert('general_ledger');
467 my $form = $main::form;
468 my %myconfig = %main::myconfig;
469 my $locale = $main::locale;
471 # 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
473 # <form method=post action=gl.pl>
474 # <input type=hidden name=sort value=datesort> # form->{sort} setzen
475 # <input type=hidden name=nextsub value=generate_report>
477 # anhand von neuer Variable datesort wird jetzt $form->{sort} auf transdate oder gldate gesetzt
478 # damit ist die Hidden Variable "sort" wahrscheinlich sogar überflüssig
480 # ändert man die Sortierreihenfolge per Klick auf eine der Überschriften wird die Variable "sort" per GET übergeben, z.B. id,transdate, gldate, ...
481 # 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
483 if ( $form->{sort} eq 'datesort' ) { # sollte bei einem Post (Aufruf aus Suchmaske) immer wahr sein
484 # je nachdem ob in Suchmaske "transdate" oder "gldate" ausgesucht wurde erstes Suchergebnis entsprechend sortieren
485 $form->{sort} = $form->{datesort};
489 report_generator_set_default_sort("$form->{datesort}", 1);
490 # report_generator_set_default_sort('transdate', 1);
492 GL->all_transactions(\%myconfig, \%$form);
494 my %acctype = ('A' => $locale->text('Asset'),
495 'C' => $locale->text('Contra'),
496 'L' => $locale->text('Liability'),
497 'Q' => $locale->text('Equity'),
498 'I' => $locale->text('Revenue'),
499 'E' => $locale->text('Expense'),);
501 $form->{title} = $locale->text('Journal');
502 if ($form->{category} ne 'X') {
503 $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
506 $form->{landscape} = 1;
508 my $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
511 gldate transdate id reference description
512 notes source debit debit_accno
513 credit credit_accno debit_tax debit_tax_accno
514 credit_tax credit_tax_accno projectnumbers balance
517 # add employee here, so that variable is still known and passed in url when choosing a different sort order in resulting table
518 my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto employee datesort category l_subtotal);
519 push @hidden_variables, map { "l_${_}" } @columns;
520 foreach ( @hidden_variables ) {
524 my (@options, @date_options);
525 push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}" if ($form->{accno});
526 push @options, $locale->text('Source') . " : $form->{source}" if ($form->{source});
527 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
528 push @options, $locale->text('Description') . " : $form->{description}" if ($form->{description});
529 push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes});
530 push @options, $locale->text('Employee') . " : $form->{employee_name}" if ($form->{employee_name});
531 my $datesorttext = $form->{datesort} eq 'transdate' ? $locale->text('Invoice Date') : $locale->text('Booking Date');
532 push @date_options, "$datesorttext" if ($form->{datesort} and ($form->{datefrom} or $form->{dateto}));
533 push @date_options, $locale->text('From'), $locale->date(\%myconfig, $form->{datefrom}, 1) if ($form->{datefrom});
534 push @date_options, $locale->text('Bis'), $locale->date(\%myconfig, $form->{dateto}, 1) if ($form->{dateto});
535 push @options, join(' ', @date_options) if (scalar @date_options);
537 if ($form->{department}) {
538 my ($department) = split /--/, $form->{department};
539 push @options, $locale->text('Department') . " : $department";
543 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
547 $form->{l_credit_accno} = 'Y';
548 $form->{l_debit_accno} = 'Y';
549 $form->{l_credit_tax} = 'Y';
550 $form->{l_debit_tax} = 'Y';
551 # $form->{l_gldate} = 'Y'; # Spalte mit gldate immer anzeigen
552 $form->{l_credit_tax_accno} = 'Y';
553 $form->{l_datesort} = 'Y';
554 $form->{l_debit_tax_accno} = 'Y';
555 $form->{l_balance} = $form->{accno} ? 'Y' : '';
558 'id' => { 'text' => $locale->text('ID'), },
559 'transdate' => { 'text' => $locale->text('Invoice Date'), },
560 'gldate' => { 'text' => $locale->text('Booking Date'), },
561 'reference' => { 'text' => $locale->text('Reference'), },
562 'source' => { 'text' => $locale->text('Source'), },
563 'description' => { 'text' => $locale->text('Description'), },
564 'notes' => { 'text' => $locale->text('Notes'), },
565 'debit' => { 'text' => $locale->text('Debit'), },
566 'debit_accno' => { 'text' => $locale->text('Debit Account'), },
567 'credit' => { 'text' => $locale->text('Credit'), },
568 'credit_accno' => { 'text' => $locale->text('Credit Account'), },
569 'debit_tax' => { 'text' => $locale->text('Debit Tax'), },
570 'debit_tax_accno' => { 'text' => $locale->text('Debit Tax Account'), },
571 'credit_tax' => { 'text' => $locale->text('Credit Tax'), },
572 'credit_tax_accno' => { 'text' => $locale->text('Credit Tax Account'), },
573 'balance' => { 'text' => $locale->text('Balance'), },
574 'projectnumbers' => { 'text' => $locale->text('Project Numbers'), },
575 'employee' => { 'text' => $locale->text('Employee'), },
578 foreach my $name (qw(id transdate gldate reference description debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
579 my $sortname = $name =~ m/accno/ ? 'accno' : $name;
580 my $sortdir = $sortname eq $form->{sort} ? 1 - $form->{sortdir} : $form->{sortdir};
581 $column_defs{$name}->{link} = $callback . "&sort=$sortname&sortdir=$sortdir";
584 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
585 map { $column_defs{$_}->{visible} = 0 } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno) if $form->{accno};
587 my %column_alignment;
588 map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax balance);
589 map { $column_alignment{$_} = 'center' } qw(transdate gldate reference debit_accno credit_accno debit_tax_accno credit_tax_accno);
590 map { $column_alignment{$_} = 'left' } qw(description source notes);
591 map { $column_defs{$_}->{align} = $column_alignment{$_} } keys %column_alignment;
593 my $report = SL::ReportGenerator->new(\%myconfig, $form);
595 $report->set_columns(%column_defs);
596 $report->set_column_order(@columns);
598 $report->set_export_options('generate_report', @hidden_variables, qw(sort sortdir));
600 $report->set_sort_indicator($form->{sort} eq 'accno' ? 'debit_accno' : $form->{sort}, $form->{sortdir});
602 $report->set_options('top_info_text' => join("\n", @options),
603 'output_format' => 'HTML',
604 'title' => $form->{title},
605 'attachment_basename' => $locale->text('general_ledger_list') . strftime('_%Y%m%d', localtime time),
607 $report->set_options_from_form();
608 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
610 # add sort to callback
611 $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
614 my @totals_columns = qw(debit credit debit_tax credit_tax);
615 my %subtotals = map { $_ => 0 } @totals_columns;
616 my %totals = map { $_ => 0 } @totals_columns;
619 foreach my $ref (@{ $form->{GL} }) {
623 foreach my $key (qw(debit credit debit_tax credit_tax)) {
625 foreach my $idx (sort keys(%{ $ref->{$key} })) {
626 my $value = $ref->{$key}->{$idx};
627 $subtotals{$key} += $value;
628 $totals{$key} += $value;
629 if ($key =~ /debit.*/) {
634 $form->{balance} = $form->{balance} + $value * $ml;
635 push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2);
639 foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate source)) {
640 my $col = $key eq 'ac_transdate' ? 'transdate' : $key;
641 $rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ];
645 map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
648 if ($form->{balance} < 0) {
651 } elsif ($form->{balance} > 0) {
655 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
658 $row->{balance}->{data} = $data;
659 $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
661 map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description notes);
663 map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate gldate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno source);
665 foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
666 $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
669 map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
671 $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
673 my $row_set = [ $row ];
675 if (($form->{l_subtotal} eq 'Y')
676 && (($idx == (scalar @{ $form->{GL} } - 1))
677 || ($ref->{ $form->{sort} } ne $form->{GL}->[$idx + 1]->{ $form->{sort} }))) {
678 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, [ qw(debit credit) ], 'listsubtotal');
681 $report->add_data($row_set);
686 $report->add_separator();
688 # = 0 for balanced ledger
689 my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax};
691 my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal');
694 if ($form->{balance} < 0) {
697 } elsif ($form->{balance} > 0) {
701 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
704 $row->{balance}->{data} = $data;
706 $report->add_data($row);
708 my $raw_bottom_info_text;
710 if (!$form->{accno} && (abs($balanced_ledger) > 0.001)) {
711 $raw_bottom_info_text .=
712 '<p><span class="unbalanced_ledger">'
713 . $locale->text('Unbalanced Ledger')
715 . $form->format_amount(\%myconfig, $balanced_ledger, 3)
719 $raw_bottom_info_text .= $form->parse_html_template('gl/generate_report_bottom');
721 $report->set_options('raw_bottom_info_text' => $raw_bottom_info_text);
723 $report->generate_with_headers();
725 $main::lxdebug->leave_sub();
729 $main::lxdebug->enter_sub();
731 $main::auth->assert('general_ledger');
733 my $form = $main::form;
734 my %myconfig = %main::myconfig;
736 $form->{oldtransdate} = $form->{transdate};
744 my ($debitcredit, $amount);
747 qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
749 for my $i (1 .. $form->{rowcount}) {
751 unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
752 for (qw(debit credit tax)) {
754 $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
758 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
765 if (($debitcount >= 2) && ($creditcount == 2)) {
766 $form->{"credit_$i"} = 0;
767 $form->{"tax_$i"} = 0;
769 $form->{creditlock} = 1;
771 if (($creditcount >= 2) && ($debitcount == 2)) {
772 $form->{"debit_$i"} = 0;
773 $form->{"tax_$i"} = 0;
775 $form->{debitlock} = 1;
777 if (($creditcount == 1) && ($debitcount == 2)) {
778 $form->{creditlock} = 1;
780 if (($creditcount == 2) && ($debitcount == 1)) {
781 $form->{debitlock} = 1;
783 if ($debitcredit && $credittax) {
784 $form->{"taxchart_$i"} = "0--0.00";
786 if (!$debitcredit && $debittax) {
787 $form->{"taxchart_$i"} = "0--0.00";
790 ($form->{"debit_$i"} == 0)
791 ? $form->{"credit_$i"}
792 : $form->{"debit_$i"};
794 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
795 $form->{"taxchart_$i"} = "0--0.00";
796 $form->{"tax_$i"} = 0;
798 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
805 if ($form->{taxincluded}) {
806 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
808 $form->{"tax_$i"} = $amount * $rate;
811 $form->{"tax_$i"} = 0;
814 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
819 for my $i (1 .. $count) {
821 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
824 for my $i ($count + 1 .. $form->{rowcount}) {
825 for (@flds) { delete $form->{"${_}_$i"} }
828 $form->{rowcount} = $count + 1;
831 $main::lxdebug->leave_sub();
837 $main::lxdebug->enter_sub();
839 $main::auth->assert('general_ledger');
841 my $form = $main::form;
842 my %myconfig = %main::myconfig;
846 # for $i (1 .. $form->{rowcount}) {
847 # $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
848 # $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
852 &display_rows($init);
854 $main::lxdebug->leave_sub();
860 $main::lxdebug->enter_sub();
862 $main::auth->assert('general_ledger');
864 my $form = $main::form;
865 my %myconfig = %main::myconfig;
866 my $cgi = $main::cgi;
868 $form->{debit_1} = 0 if !$form->{"debit_1"};
869 $form->{totaldebit} = 0;
870 $form->{totalcredit} = 0;
872 my %project_labels = ();
873 my @project_values = ("");
874 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
875 push(@project_values, $item->{"id"});
876 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
879 my %chart_labels = ();
880 my @chart_values = ();
883 foreach my $item (@{ $form->{ALL_CHARTS} }) {
884 if ($item->{charttype} eq 'H'){ #falls überschrift
885 next; #überspringen (Bug 1150)
887 my $key = $item->{accno} . "--" . $item->{tax_id};
888 $taxchart_init = $item->{tax_id} unless (@chart_values);
889 push(@chart_values, $key);
890 $chart_labels{$key} = $item->{accno} . "--" . $item->{description};
891 $charts{$item->{accno}} = $item;
894 my %taxchart_labels = ();
895 my @taxchart_values = ();
897 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
898 my $key = $item->{id} . "--" . $item->{rate};
899 $taxchart_init = $key if ($taxchart_init == $item->{id});
900 push(@taxchart_values, $key);
901 $taxchart_labels{$key} = $item->{taxdescription} . " " . $item->{rate} * 100 . ' %';
902 $taxcharts{$item->{id}} = $item;
905 my ($source, $memo, $source_hidden, $memo_hidden);
906 for my $i (1 .. $form->{rowcount}) {
907 if ($form->{show_details}) {
909 <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
911 <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
914 <input type="hidden" name="source_$i" value="$form->{"source_$i"}" size="16">|;
916 <input type="hidden" name="memo_$i" value="$form->{"memo_$i"}" size="16">|;
919 my $selected_accno_full;
920 my ($accno_row) = split(/--/, $form->{"accno_$i"});
921 my $item = $charts{$accno_row};
922 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
924 my $selected_taxchart = $form->{"taxchart_$i"};
925 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
926 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
928 if ($previous_accno &&
929 ($previous_accno eq $selected_accno) &&
930 ($previous_tax_id ne $selected_tax_id)) {
931 my $item = $taxcharts{$selected_tax_id};
932 $selected_taxchart = "$item->{id}--$item->{rate}";
935 $selected_accno = '' if ($init);
936 $selected_taxchart ||= $taxchart_init;
938 my $accno = qq|<td>| .
939 NTI($cgi->popup_menu('-name' => "accno_$i",
941 '-onChange' => "setTaxkey($i)",
942 '-style' => 'width:200px',
943 '-values' => \@chart_values,
944 '-labels' => \%chart_labels,
945 '-default' => $selected_accno_full))
946 . $cgi->hidden('-name' => "previous_accno_$i",
947 '-default' => $selected_accno_full)
949 my $tax_ddbox = qq|<td>| .
950 NTI($cgi->popup_menu('-name' => "taxchart_$i",
951 '-id' => "taxchart_$i",
952 '-style' => 'width:200px',
953 '-values' => \@taxchart_values,
954 '-labels' => \%taxchart_labels,
955 '-default' => $selected_taxchart))
958 my ($fx_transaction, $checked);
960 if ($form->{transfer}) {
961 $fx_transaction = qq|
962 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
967 if ($form->{"debit_$i"} != 0) {
968 $form->{totaldebit} += $form->{"debit_$i"};
969 if (!$form->{taxincluded}) {
970 $form->{totaldebit} += $form->{"tax_$i"};
973 $form->{totalcredit} += $form->{"credit_$i"};
974 if (!$form->{taxincluded}) {
975 $form->{totalcredit} += $form->{"tax_$i"};
979 for (qw(debit credit tax)) {
982 ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
986 if ($i < $form->{rowcount}) {
987 if ($form->{transfer}) {
988 $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
989 my $x = ($checked) ? "x" : "";
990 $fx_transaction = qq|
991 <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
994 $form->hide_form("accno_$i");
997 if ($form->{transfer}) {
998 $fx_transaction = qq|
999 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
1004 my $debitreadonly = "";
1005 my $creditreadonly = "";
1006 if ($i == $form->{rowcount}) {
1007 if ($form->{debitlock}) {
1008 $debitreadonly = "readonly";
1009 } elsif ($form->{creditlock}) {
1010 $creditreadonly = "readonly";
1015 NTI($cgi->popup_menu('-name' => "project_id_$i",
1016 '-values' => \@project_values,
1017 '-labels' => \%project_labels,
1018 '-default' => $form->{"project_id_$i"} ));
1019 my $projectnumber_hidden = qq|
1020 <input type="hidden" name="project_id_$i" value="$form->{"project_id_$i"}">|;
1022 my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
1024 print qq|<tr valign=top>
1026 <td id="chart_balance_$i" align="right"> </td>
1028 <td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td>
1029 <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
1030 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
1033 if ($form->{show_details}) {
1037 <td>$projectnumber</td>
1043 $projectnumber_hidden
1051 $form->hide_form(qw(rowcount selectaccno));
1053 $main::lxdebug->leave_sub();
1059 $main::lxdebug->enter_sub();
1061 $main::auth->assert('general_ledger');
1063 my $form = $main::form;
1064 my %myconfig = %main::myconfig;
1065 my $locale = $main::locale;
1067 my @old_project_ids = ();
1068 map({ push(@old_project_ids, $form->{"project_id_$_"})
1069 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
1071 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1073 "old_id" => \@old_project_ids },
1074 "charts" => { "key" => "ALL_CHARTS",
1075 "transdate" => $form->{transdate} },
1076 "taxcharts" => "ALL_TAXCHARTS");
1078 GL->get_chart_balances('charts' => $form->{ALL_CHARTS});
1080 my $title = $form->{title};
1081 $form->{title} = $locale->text("$title General Ledger Transaction");
1082 my $readonly = ($form->{id}) ? "readonly" : "";
1084 my $show_details_checked = "checked" if $form->{show_details};
1086 my $ob_transaction_checked = "checked" if $form->{ob_transaction};
1087 my $cb_transaction_checked = "checked" if $form->{cb_transaction};
1089 # $locale->text('Add General Ledger Transaction')
1090 # $locale->text('Edit General Ledger Transaction')
1092 map { $form->{$_} =~ s/\"/"/g }
1093 qw(reference description chart taxchart);
1095 $form->{javascript} = qq|<script type="text/javascript">
1097 function setTaxkey(row) {
1098 var accno = document.getElementById('accno_' + row);
1099 var taxkey = accno.options[accno.selectedIndex].value;
1100 var reg = /--([0-9]*)/;
1101 var found = reg.exec(taxkey);
1102 var index = found[1];
1103 index = parseInt(index);
1104 var tax = 'taxchart_' + row;
1105 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
1106 var reg2 = new RegExp("^"+ index, "");
1107 if (reg2.exec(document.getElementById(tax).options[i].value)) {
1108 document.getElementById(tax).options[i].selected = true;
1114 function copy_debit_to_credit() {
1115 var txt = document.getElementsByName('debit_1')[0].value;
1116 document.getElementsByName('credit_2')[0].value = txt;
1120 <script type="text/javascript" src="js/show_form_details.js"></script>
1121 <script type="text/javascript" src="js/jquery.js"></script>
1124 $form->{selectdepartment} =~ s/ selected//;
1125 $form->{selectdepartment} =~
1126 s/option>\Q$form->{department}\E/option selected>$form->{department}/;
1129 if ((my $rows = $form->numtextrows($form->{description}, 50)) > 1) {
1131 qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
1134 qq|<input name=description size=50 value="$form->{description}" $readonly>|;
1137 my $taxincluded = ($form->{taxincluded}) ? "checked" : "";
1140 $taxincluded = "checked";
1146 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1147 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1148 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
1150 | if $form->{selectdepartment};
1152 $form->{fokus} = "gl.reference";
1154 $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
1157 # use JavaScript Calendar or not
1158 $form->{jsscript} = 1;
1160 my ($button1, $button2);
1161 if ($form->{jsscript}) {
1163 # with JavaScript Calendar
1165 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\">
1166 <input type=button name=transdate id="trigger1" value=|
1167 . $locale->text('button') . qq|></td>
1172 Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
1175 # without JavaScript Calendar
1177 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\"></td>|;
1180 $form->{previous_id} ||= "--";
1181 $form->{previous_gldate} ||= "--";
1183 $jsscript .= $form->parse_html_template('gl/form_header_chart_balances_js');
1188 <body onLoad="focus()">
1190 <script type="text/javascript" src="js/follow_up.js"></script>
1192 <form method=post name="gl" action=gl.pl>
1195 $form->hide_form(qw(id closedto locked storno storno_id previous_id previous_gldate));
1198 <input type=hidden name=title value="$title">
1200 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
1201 <input type="hidden" name="follow_up_trans_type_1" value="gl_transaction">
1202 <input type="hidden" name="follow_up_trans_info_1" value="| . H($form->{id}) . qq|">
1203 <input type="hidden" name="follow_up_rowcount" value="1">
1207 <th class=listtop>$form->{title}</th>
1210 ($form->{saved_message} ? qq|
1212 <td>$form->{saved_message}</th>
1216 <tr height="5"></tr>
1221 <td colspan="6" align="left">|
1222 . $locale->text("Previous transnumber text")
1223 . " $form->{previous_id} "
1224 . $locale->text("Previous transdate text")
1225 . " $form->{previous_gldate}"
1229 <th align=right>| . $locale->text('Reference') . qq|</th>
1230 <td><input name=reference size=20 value="$form->{reference}" $readonly></td>
1234 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
1243 <th align=right>| . $locale->text('Belegnummer') . qq|</th>
1244 <td><input name=id size=20 value="$form->{id}" $readonly></td>
1248 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
1249 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly onBlur=\"check_right_date_format(this)\"></td>
1260 <th align=right width=1%>| . $locale->text('Description') . qq|</th>
1261 <td width=1%>$description</td>
1265 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1266 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1273 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
1274 <td align=left><input name=employee size=20 value="| . H($form->{employee}) . qq|" readonly></td>
1282 <th align=left width=1%>| . $locale->text('Description') . qq|</th>
1283 <td width=1%>$description</td>
1287 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1288 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1297 <tr><td colspan=4><table><tr>
1299 | . $locale->text('OB Transaction') . qq|<input type="checkbox" name="ob_transaction" value="1" $ob_transaction_checked>
1302 | . $locale->text('CB Transaction') . qq|<input type="checkbox" name="cb_transaction" value="1" $cb_transaction_checked>
1304 </tr></table></td></tr>
1306 <td width="1%" align="right" nowrap>| . $locale->text('Show details') . qq|</td>
1307 <td width="1%"><input type="checkbox" onclick="show_form_details();" name="show_details" value="1" $show_details_checked></td>
1314 <tr class=listheading>
1315 <th class=listheading style="width:15%">|
1316 . $locale->text('Account') . qq|</th>
1317 <th class=listheading style="width:10%">| . $locale->text('Chart balance') . qq|</th>
1318 <th class=listheading style="width:10%">|
1319 . $locale->text('Debit') . qq|</th>
1320 <th class=listheading style="width:10%">|
1321 . $locale->text('Credit') . qq|</th>
1322 <th class=listheading style="width:10%">|
1323 . $locale->text('Tax') . qq|</th>
1324 <th class=listheading style="width:5%">|
1325 . $locale->text('Taxkey') . qq|</th>|;
1327 if ($form->{show_details}) {
1329 <th class=listheading style="width:20%">| . $locale->text('Source') . qq|</th>
1330 <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
1331 <th class=listheading style="width:20%">| . $locale->text('Project Number') . qq|</th>
1340 $main::lxdebug->leave_sub();
1345 $main::lxdebug->enter_sub();
1347 $main::auth->assert('general_ledger');
1349 my $form = $main::form;
1350 my %myconfig = %main::myconfig;
1351 my $locale = $main::locale;
1352 my $cgi = $main::cgi;
1354 my $follow_ups_block;
1356 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
1358 if (@{ $follow_ups} ) {
1359 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
1360 $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>|;
1364 my ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
1366 my $decimalplaces = ($dec > 2) ? $dec : 2;
1367 my $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
1370 $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
1371 } qw(totaldebit totalcredit);
1374 <tr class=listtotal>
1375 <th colspan="3" align=right class=listtotal> $form->{totaldebit}</th>
1376 <th align=right class=listtotal> $form->{totalcredit}</th>
1384 <input name=callback type=hidden value="$form->{callback}">
1391 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1392 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1396 if (!$form->{storno}) {
1397 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|;
1400 # Löschen und Ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
1401 if (!$form->{locked} && $radieren) {
1403 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|" accesskey="b">
1404 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">|;
1408 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1409 <input type="button" class="submit" onclick="follow_up_window()" value="|
1410 . $locale->text('Follow-Up')
1414 if ($form->{draft_id}) {
1415 my $remove_draft_checked = 'checked' if ($form->{remove_draft});
1417 . qq| <input name="remove_draft" id="remove_draft" type="checkbox" class="checkbox" ${remove_draft_checked}>|
1418 . qq| <label for="remove_draft">| . $locale->text('Remove Draft') . qq|</label>\n|
1423 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1424 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> |
1425 . NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'))
1426 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1427 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
1436 $main::lxdebug->leave_sub();
1441 $main::lxdebug->enter_sub();
1443 my $form = $main::form;
1444 my $locale = $main::locale;
1451 <form method=post action=gl.pl>
1454 map { $form->{$_} =~ s/\"/"/g } qw(reference description);
1456 delete $form->{header};
1458 foreach my $key (keys %$form) {
1459 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1460 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1464 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1467 . $locale->text('Are you sure you want to delete Transaction')
1468 . qq| $form->{reference}</h4>
1470 <input name=action class=submit type=submit value="|
1471 . $locale->text('Yes') . qq|">
1474 $main::lxdebug->leave_sub();
1479 $main::lxdebug->enter_sub();
1481 my $form = $main::form;
1482 my %myconfig = %main::myconfig;
1483 my $locale = $main::locale;
1485 if (GL->delete_transaction(\%myconfig, \%$form)){
1486 # saving the history
1487 if(!exists $form->{addition} && $form->{id} ne "") {
1488 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1489 $form->{addition} = "DELETED";
1490 $form->save_history;
1492 # /saving the history
1493 $form->redirect($locale->text('Transaction deleted!'))
1495 $form->error($locale->text('Cannot delete transaction!'));
1496 $main::lxdebug->leave_sub();
1500 sub post_transaction {
1501 $main::lxdebug->enter_sub();
1503 my $form = $main::form;
1504 my %myconfig = %main::myconfig;
1505 my $locale = $main::locale;
1507 # check if there is something in reference and date
1508 $form->isblank("reference", $locale->text('Reference missing!'));
1509 $form->isblank("transdate", $locale->text('Transaction Date missing!'));
1510 $form->isblank("description", $locale->text('Description missing!'));
1512 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1513 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1520 my $creditcount = 0;
1523 my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
1525 for my $i (1 .. $form->{rowcount}) {
1526 next if $form->{"debit_$i"} eq "" && $form->{"credit_$i"} eq "";
1528 for (qw(debit credit tax)) {
1529 $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
1533 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
1541 if (($debitcount >= 2) && ($creditcount == 2)) {
1542 $form->{"credit_$i"} = 0;
1543 $form->{"tax_$i"} = 0;
1545 $form->{creditlock} = 1;
1547 if (($creditcount >= 2) && ($debitcount == 2)) {
1548 $form->{"debit_$i"} = 0;
1549 $form->{"tax_$i"} = 0;
1551 $form->{debitlock} = 1;
1553 if (($creditcount == 1) && ($debitcount == 2)) {
1554 $form->{creditlock} = 1;
1556 if (($creditcount == 2) && ($debitcount == 1)) {
1557 $form->{debitlock} = 1;
1559 if ($debitcredit && $credittax) {
1560 $form->{"taxchart_$i"} = "0--0.00";
1562 if (!$debitcredit && $debittax) {
1563 $form->{"taxchart_$i"} = "0--0.00";
1565 my $amount = ($form->{"debit_$i"} == 0)
1566 ? $form->{"credit_$i"}
1567 : $form->{"debit_$i"};
1569 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
1570 $form->{"taxchart_$i"} = "0--0.00";
1571 $form->{"tax_$i"} = 0;
1573 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
1580 if ($form->{taxincluded}) {
1581 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
1583 $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
1585 $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
1588 $form->{"tax_$i"} = $amount * $rate;
1591 $form->{"tax_$i"} = 0;
1594 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
1598 for my $i (1 .. $count) {
1600 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
1603 for my $i ($count + 1 .. $form->{rowcount}) {
1604 for (@flds) { delete $form->{"${_}_$i"} }
1607 my ($debit, $credit, $taxtotal);
1608 for my $i (1 .. $form->{rowcount}) {
1609 my $dr = $form->{"debit_$i"};
1610 my $cr = $form->{"credit_$i"};
1611 my $tax = $form->{"tax_$i"};
1613 $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
1615 $debit += $dr + $tax if $dr;
1616 $credit += $cr + $tax if $cr;
1617 $taxtotal += $tax if $form->{taxincluded}
1620 $form->{taxincluded} = 0 if !$taxtotal;
1622 # this is just for the wise guys
1623 $form->error($locale->text('Cannot post transaction for a closed period!'))
1624 if ($form->date_closed($form->{"transdate"}, \%myconfig));
1625 if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
1626 $form->error($locale->text('Out of balance transaction!'));
1629 if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
1630 $form->error($locale->text('Empty transaction!'));
1633 if ((my $errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
1636 $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
1637 $err[2] = $locale->text('Debit and credit out of balance!');
1638 $err[3] = $locale->text('Cannot post a transaction without a value!');
1640 $form->error($err[$errno]);
1642 undef($form->{callback});
1643 # saving the history
1644 if(!exists $form->{addition} && $form->{id} ne "") {
1645 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1646 $form->{addition} = "SAVED";
1647 $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id};
1648 $form->save_history;
1650 # /saving the history
1652 $main::lxdebug->leave_sub();
1656 $main::lxdebug->enter_sub();
1658 $main::auth->assert('general_ledger');
1660 my $form = $main::form;
1661 my $locale = $main::locale;
1663 if ($::myconfig{mandatory_departments} && !$form->{department}) {
1664 $form->{saved_message} = $::locale->text('You have to specify a department.');
1669 $form->{title} = $locale->text("$form->{title} General Ledger Transaction");
1670 $form->{storno} = 0;
1674 remove_draft() if $form->{remove_draft};
1676 $form->{callback} = build_std_url("action=add&DONT_LOAD_DRAFT=1", "show_details");
1677 $form->redirect($form->{callback});
1679 $main::lxdebug->leave_sub();
1683 $main::lxdebug->enter_sub();
1685 $main::auth->assert('general_ledger');
1687 my $form = $main::form;
1691 $main::lxdebug->leave_sub();
1696 $main::lxdebug->enter_sub();
1698 $main::auth->assert('general_ledger');
1700 my $form = $main::form;
1701 my %myconfig = %main::myconfig;
1702 my $locale = $main::locale;
1704 # don't cancel cancelled transactions
1705 if (IS->has_storno(\%myconfig, $form, 'gl')) {
1706 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1707 $form->error($locale->text("Transaction has already been cancelled!"));
1710 GL->storno($form, \%myconfig, $form->{id});
1712 # saving the history
1713 if(!exists $form->{addition} && $form->{id} ne "") {
1714 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1715 $form->{addition} = "STORNO";
1716 $form->save_history;
1718 # /saving the history
1720 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1722 $main::lxdebug->leave_sub();
1726 call_sub($main::form->{nextsub});