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 = $::request->{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} || [] });
240 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
241 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
243 | if $form->{selectdepartment};
245 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
247 "employees" => "ALL_EMPLOYEES" );
249 my %project_labels = ();
250 my @project_values = ("");
251 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
252 push(@project_values, $item->{"id"});
253 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
257 NTI($cgi->popup_menu('-name' => "project_id",
258 '-values' => \@project_values,
259 '-labels' => \%project_labels));
261 my %employee_labels = ();
262 my @employee_values = ("");
263 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
264 # value in Form "1234--Name" übergeben
265 my $id = "$item->{'id'}--$item->{'name'}";
266 push(@employee_values, "$id");
267 $employee_labels{$id} = $item->{"name"};
271 NTI($cgi->popup_menu('-name' => "employee",
272 '-values' => \@employee_values,
273 '-labels' => \%employee_labels));
275 # use JavaScript Calendar or not
276 $form->{jsscript} = 1;
278 my ($button1, $button2, $onload);
279 if ($form->{jsscript}) {
281 # with JavaScript Calendar
283 <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
284 <input type=button name=datefrom id="trigger1" value=|
285 . $locale->text('button') . qq|></td>
288 <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
289 <input type=button name=dateto id="trigger2" value=|
290 . $locale->text('button') . qq|></td>
295 Form->write_trigger(\%myconfig, "2", "datefrom", "BR", "trigger1",
296 "dateto", "BL", "trigger2");
299 # without JavaScript Calendar
301 qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
303 qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
305 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
307 $onload = qq|focus()|;
308 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
309 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
311 <body onLoad="$onload">
313 <form method=post action=gl.pl>
315 <input type=hidden name=sort value=datesort>
319 <th class=listtop>$form->{title}</th>
326 <th align=right>| . $locale->text('Reference') . qq|</th>
327 <td><input name=reference size=20></td>
328 <th align=right>| . $locale->text('Source') . qq|</th>
329 <td><input name=source size=20></td>
333 <th align=right>| . $locale->text('Description') . qq|</th>
334 <td><input name=description size=40></td>
335 <th align=right>| . $locale->text('Account Number') . qq|</th>
336 <td><input name=accno size=20></td>
339 <th align=right>| . $locale->text('Notes') . qq|</th>
340 <td colspan=3><input name=notes size=40></td>
343 <th align=right>| . $locale->text('Project Number') . qq|</th>
344 <td colspan=3>$projectnumber</td>
347 <th align=right>| . $locale->text('Employee') . qq|</th>
348 <td colspan=3>$employeenumber</td>
351 <th align=right>| . $locale->text('Filter date by') . qq|</th>
353 <input name=datesort class=radio type=radio value=gldate checked> | . $locale->text('Booking Date') . qq|
354 <input name=datesort class=radio type=radio value=transdate> | . $locale->text('Invoice Date') . qq|
358 <th align=right>| . $locale->text('From') . qq|</th>
360 <th align=right>| . $locale->text('To (time)') . qq|</th>
364 <th align=right>| . $locale->text('Include in Report') . qq|</th>
369 <input name="category" class=radio type=radio value=X checked> |
370 . $locale->text('All') . qq|
371 <input name="category" class=radio type=radio value=A> |
372 . $locale->text('Asset') . qq|
373 <input name="category" class=radio type=radio value=L> |
374 . $locale->text('Liability') . qq|
375 <input name="category" class=radio type=radio value=I> |
376 . $locale->text('Revenue') . qq|
377 <input name="category" class=radio type=radio value=E> |
378 . $locale->text('Expense') . qq|
384 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
385 <td>| . $locale->text('ID') . qq|</td>
386 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
387 <td>| . $locale->text('Invoice Date') . qq|</td>
388 <td align=right><input name="l_gldate" class=checkbox type=checkbox value=Y checked></td>
389 <td>| . $locale->text('Booking Date') . qq|</td>
390 <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
391 <td>| . $locale->text('Reference') . qq|</td>
392 <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
393 <td>| . $locale->text('Description') . qq|</td>
394 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
395 <td>| . $locale->text('Notes') . qq|</td>
398 <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
399 <td>| . $locale->text('Debit') . qq|</td>
400 <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
401 <td>| . $locale->text('Credit') . qq|</td>
402 <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
403 <td>| . $locale->text('Source') . qq|</td>
404 <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
405 <td>| . $locale->text('Account') . qq|</td>
408 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
409 <td>| . $locale->text('Subtotal') . qq|</td>
410 <td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
411 <td>| . $locale->text('Project Number') . qq|</td>
412 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
413 <td>| . $locale->text('Employee') . qq|</td>
423 <td><hr size=3 noshade></td>
429 <input type=hidden name=nextsub value=generate_report>
432 <input class=submit type=submit name=action value="|
433 . $locale->text('Continue') . qq|">
439 $main::lxdebug->leave_sub();
442 sub create_subtotal_row {
443 $main::lxdebug->enter_sub();
445 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
447 my $form = $main::form;
448 my %myconfig = %main::myconfig;
450 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
452 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
454 map { $totals->{$_} = 0 } @{ $subtotal_columns };
456 $main::lxdebug->leave_sub();
461 sub generate_report {
462 $main::lxdebug->enter_sub();
464 $main::auth->assert('general_ledger');
466 my $form = $main::form;
467 my %myconfig = %main::myconfig;
468 my $locale = $main::locale;
470 # 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
472 # <form method=post action=gl.pl>
473 # <input type=hidden name=sort value=datesort> # form->{sort} setzen
474 # <input type=hidden name=nextsub value=generate_report>
476 # anhand von neuer Variable datesort wird jetzt $form->{sort} auf transdate oder gldate gesetzt
477 # damit ist die Hidden Variable "sort" wahrscheinlich sogar überflüssig
479 # ändert man die Sortierreihenfolge per Klick auf eine der Überschriften wird die Variable "sort" per GET übergeben, z.B. id,transdate, gldate, ...
480 # 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
482 if ( $form->{sort} eq 'datesort' ) { # sollte bei einem Post (Aufruf aus Suchmaske) immer wahr sein
483 # je nachdem ob in Suchmaske "transdate" oder "gldate" ausgesucht wurde erstes Suchergebnis entsprechend sortieren
484 $form->{sort} = $form->{datesort};
488 report_generator_set_default_sort("$form->{datesort}", 1);
489 # report_generator_set_default_sort('transdate', 1);
491 GL->all_transactions(\%myconfig, \%$form);
493 my %acctype = ('A' => $locale->text('Asset'),
494 'C' => $locale->text('Contra'),
495 'L' => $locale->text('Liability'),
496 'Q' => $locale->text('Equity'),
497 'I' => $locale->text('Revenue'),
498 'E' => $locale->text('Expense'),);
500 $form->{title} = $locale->text('Journal');
501 if ($form->{category} ne 'X') {
502 $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
505 $form->{landscape} = 1;
507 my $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
510 gldate transdate id reference description
511 notes source debit debit_accno
512 credit credit_accno debit_tax debit_tax_accno
513 credit_tax credit_tax_accno projectnumbers balance employee
516 # add employee here, so that variable is still known and passed in url when choosing a different sort order in resulting table
517 my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto employee datesort category l_subtotal);
518 push @hidden_variables, map { "l_${_}" } @columns;
519 foreach ( @hidden_variables ) {
523 my (@options, @date_options);
524 push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}" if ($form->{accno});
525 push @options, $locale->text('Source') . " : $form->{source}" if ($form->{source});
526 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
527 push @options, $locale->text('Description') . " : $form->{description}" if ($form->{description});
528 push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes});
529 push @options, $locale->text('Employee') . " : $form->{employee_name}" if ($form->{employee_name});
530 my $datesorttext = $form->{datesort} eq 'transdate' ? $locale->text('Invoice Date') : $locale->text('Booking Date');
531 push @date_options, "$datesorttext" if ($form->{datesort} and ($form->{datefrom} or $form->{dateto}));
532 push @date_options, $locale->text('From'), $locale->date(\%myconfig, $form->{datefrom}, 1) if ($form->{datefrom});
533 push @date_options, $locale->text('Bis'), $locale->date(\%myconfig, $form->{dateto}, 1) if ($form->{dateto});
534 push @options, join(' ', @date_options) if (scalar @date_options);
536 if ($form->{department}) {
537 my ($department) = split /--/, $form->{department};
538 push @options, $locale->text('Department') . " : $department";
542 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
546 $form->{l_credit_accno} = 'Y';
547 $form->{l_debit_accno} = 'Y';
548 $form->{l_credit_tax} = 'Y';
549 $form->{l_debit_tax} = 'Y';
550 # $form->{l_gldate} = 'Y'; # Spalte mit gldate immer anzeigen
551 $form->{l_credit_tax_accno} = 'Y';
552 $form->{l_datesort} = 'Y';
553 $form->{l_debit_tax_accno} = 'Y';
554 $form->{l_balance} = $form->{accno} ? 'Y' : '';
557 'id' => { 'text' => $locale->text('ID'), },
558 'transdate' => { 'text' => $locale->text('Invoice Date'), },
559 'gldate' => { 'text' => $locale->text('Booking Date'), },
560 'reference' => { 'text' => $locale->text('Reference'), },
561 'source' => { 'text' => $locale->text('Source'), },
562 'description' => { 'text' => $locale->text('Description'), },
563 'notes' => { 'text' => $locale->text('Notes'), },
564 'debit' => { 'text' => $locale->text('Debit'), },
565 'debit_accno' => { 'text' => $locale->text('Debit Account'), },
566 'credit' => { 'text' => $locale->text('Credit'), },
567 'credit_accno' => { 'text' => $locale->text('Credit Account'), },
568 'debit_tax' => { 'text' => $locale->text('Debit Tax'), },
569 'debit_tax_accno' => { 'text' => $locale->text('Debit Tax Account'), },
570 'credit_tax' => { 'text' => $locale->text('Credit Tax'), },
571 'credit_tax_accno' => { 'text' => $locale->text('Credit Tax Account'), },
572 'balance' => { 'text' => $locale->text('Balance'), },
573 'projectnumbers' => { 'text' => $locale->text('Project Numbers'), },
574 'employee' => { 'text' => $locale->text('Employee'), },
577 foreach my $name (qw(id transdate gldate reference description debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
578 my $sortname = $name =~ m/accno/ ? 'accno' : $name;
579 my $sortdir = $sortname eq $form->{sort} ? 1 - $form->{sortdir} : $form->{sortdir};
580 $column_defs{$name}->{link} = $callback . "&sort=$sortname&sortdir=$sortdir";
583 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
584 map { $column_defs{$_}->{visible} = 0 } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno) if $form->{accno};
586 my %column_alignment;
587 map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax balance);
588 map { $column_alignment{$_} = 'center' } qw(transdate gldate reference debit_accno credit_accno debit_tax_accno credit_tax_accno);
589 map { $column_alignment{$_} = 'left' } qw(description source notes);
590 map { $column_defs{$_}->{align} = $column_alignment{$_} } keys %column_alignment;
592 my $report = SL::ReportGenerator->new(\%myconfig, $form);
594 $report->set_columns(%column_defs);
595 $report->set_column_order(@columns);
597 $report->set_export_options('generate_report', @hidden_variables, qw(sort sortdir));
599 $report->set_sort_indicator($form->{sort} eq 'accno' ? 'debit_accno' : $form->{sort}, $form->{sortdir});
601 $report->set_options('top_info_text' => join("\n", @options),
602 'output_format' => 'HTML',
603 'title' => $form->{title},
604 'attachment_basename' => $locale->text('general_ledger_list') . strftime('_%Y%m%d', localtime time),
606 $report->set_options_from_form();
607 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
609 # add sort to callback
610 $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
613 my @totals_columns = qw(debit credit debit_tax credit_tax);
614 my %subtotals = map { $_ => 0 } @totals_columns;
615 my %totals = map { $_ => 0 } @totals_columns;
618 foreach my $ref (@{ $form->{GL} }) {
622 foreach my $key (qw(debit credit debit_tax credit_tax)) {
624 foreach my $idx (sort keys(%{ $ref->{$key} })) {
625 my $value = $ref->{$key}->{$idx};
626 $subtotals{$key} += $value;
627 $totals{$key} += $value;
628 if ($key =~ /debit.*/) {
633 $form->{balance} = $form->{balance} + $value * $ml;
634 push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2);
638 foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate source)) {
639 my $col = $key eq 'ac_transdate' ? 'transdate' : $key;
640 $rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ];
644 map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
647 if ($form->{balance} < 0) {
650 } elsif ($form->{balance} > 0) {
654 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
657 $row->{balance}->{data} = $data;
658 $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
660 map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description notes gldate employee);
662 map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno source);
664 foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
665 $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
668 map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
670 $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
672 my $row_set = [ $row ];
674 if (($form->{l_subtotal} eq 'Y')
675 && (($idx == (scalar @{ $form->{GL} } - 1))
676 || ($ref->{ $form->{sort} } ne $form->{GL}->[$idx + 1]->{ $form->{sort} }))) {
677 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, [ qw(debit credit) ], 'listsubtotal');
680 $report->add_data($row_set);
685 $report->add_separator();
687 # = 0 for balanced ledger
688 my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax};
690 my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal');
693 if ($form->{balance} < 0) {
696 } elsif ($form->{balance} > 0) {
700 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
703 $row->{balance}->{data} = $data;
705 $report->add_data($row);
707 my $raw_bottom_info_text;
709 if (!$form->{accno} && (abs($balanced_ledger) > 0.001)) {
710 $raw_bottom_info_text .=
711 '<p><span class="unbalanced_ledger">'
712 . $locale->text('Unbalanced Ledger')
714 . $form->format_amount(\%myconfig, $balanced_ledger, 3)
718 $raw_bottom_info_text .= $form->parse_html_template('gl/generate_report_bottom');
720 $report->set_options('raw_bottom_info_text' => $raw_bottom_info_text);
722 $report->generate_with_headers();
724 $main::lxdebug->leave_sub();
728 $main::lxdebug->enter_sub();
730 $main::auth->assert('general_ledger');
732 my $form = $main::form;
733 my %myconfig = %main::myconfig;
735 $form->{oldtransdate} = $form->{transdate};
743 my ($debitcredit, $amount);
746 qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
748 for my $i (1 .. $form->{rowcount}) {
750 unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
751 for (qw(debit credit tax)) {
753 $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
757 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
764 if (($debitcount >= 2) && ($creditcount == 2)) {
765 $form->{"credit_$i"} = 0;
766 $form->{"tax_$i"} = 0;
768 $form->{creditlock} = 1;
770 if (($creditcount >= 2) && ($debitcount == 2)) {
771 $form->{"debit_$i"} = 0;
772 $form->{"tax_$i"} = 0;
774 $form->{debitlock} = 1;
776 if (($creditcount == 1) && ($debitcount == 2)) {
777 $form->{creditlock} = 1;
779 if (($creditcount == 2) && ($debitcount == 1)) {
780 $form->{debitlock} = 1;
782 if ($debitcredit && $credittax) {
783 $form->{"taxchart_$i"} = "0--0.00";
785 if (!$debitcredit && $debittax) {
786 $form->{"taxchart_$i"} = "0--0.00";
789 ($form->{"debit_$i"} == 0)
790 ? $form->{"credit_$i"}
791 : $form->{"debit_$i"};
793 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
794 $form->{"taxchart_$i"} = "0--0.00";
795 $form->{"tax_$i"} = 0;
797 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
804 if ($form->{taxincluded}) {
805 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
807 $form->{"tax_$i"} = $amount * $rate;
810 $form->{"tax_$i"} = 0;
813 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
818 for my $i (1 .. $count) {
820 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
823 for my $i ($count + 1 .. $form->{rowcount}) {
824 for (@flds) { delete $form->{"${_}_$i"} }
827 $form->{rowcount} = $count + 1;
830 $main::lxdebug->leave_sub();
836 $main::lxdebug->enter_sub();
838 $main::auth->assert('general_ledger');
840 my $form = $main::form;
841 my %myconfig = %main::myconfig;
845 # for $i (1 .. $form->{rowcount}) {
846 # $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
847 # $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
851 &display_rows($init);
853 $main::lxdebug->leave_sub();
859 $main::lxdebug->enter_sub();
861 $main::auth->assert('general_ledger');
863 my $form = $main::form;
864 my %myconfig = %main::myconfig;
865 my $cgi = $::request->{cgi};
867 $form->{debit_1} = 0 if !$form->{"debit_1"};
868 $form->{totaldebit} = 0;
869 $form->{totalcredit} = 0;
871 my %project_labels = ();
872 my @project_values = ("");
873 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
874 push(@project_values, $item->{"id"});
875 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
878 my %chart_labels = ();
879 my @chart_values = ();
882 foreach my $item (@{ $form->{ALL_CHARTS} }) {
883 if ($item->{charttype} eq 'H'){ #falls überschrift
884 next; #überspringen (Bug 1150)
886 my $key = $item->{accno} . "--" . $item->{tax_id};
887 $taxchart_init = $item->{tax_id} unless (@chart_values);
888 push(@chart_values, $key);
889 $chart_labels{$key} = $item->{accno} . "--" . $item->{description};
890 $charts{$item->{accno}} = $item;
893 my %taxchart_labels = ();
894 my @taxchart_values = ();
896 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
897 my $key = $item->{id} . "--" . $item->{rate};
898 $taxchart_init = $key if ($taxchart_init == $item->{id});
899 push(@taxchart_values, $key);
900 $taxchart_labels{$key} = $item->{taxdescription} . " " . $item->{rate} * 100 . ' %';
901 $taxcharts{$item->{id}} = $item;
904 my ($source, $memo, $source_hidden, $memo_hidden);
905 for my $i (1 .. $form->{rowcount}) {
906 if ($form->{show_details}) {
908 <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
910 <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
913 <input type="hidden" name="source_$i" value="$form->{"source_$i"}" size="16">|;
915 <input type="hidden" name="memo_$i" value="$form->{"memo_$i"}" size="16">|;
918 my $selected_accno_full;
919 my ($accno_row) = split(/--/, $form->{"accno_$i"});
920 my $item = $charts{$accno_row};
921 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
923 my $selected_taxchart = $form->{"taxchart_$i"};
924 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
925 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
927 if ($previous_accno &&
928 ($previous_accno eq $selected_accno) &&
929 ($previous_tax_id ne $selected_tax_id)) {
930 my $item = $taxcharts{$selected_tax_id};
931 $selected_taxchart = "$item->{id}--$item->{rate}";
934 $selected_accno = '' if ($init);
935 $selected_taxchart ||= $taxchart_init;
937 my $accno = qq|<td>| .
938 NTI($cgi->popup_menu('-name' => "accno_$i",
940 '-onChange' => "setTaxkey($i)",
941 '-style' => 'width:200px',
942 '-values' => \@chart_values,
943 '-labels' => \%chart_labels,
944 '-default' => $selected_accno_full))
945 . $cgi->hidden('-name' => "previous_accno_$i",
946 '-default' => $selected_accno_full)
948 my $tax_ddbox = qq|<td>| .
949 NTI($cgi->popup_menu('-name' => "taxchart_$i",
950 '-id' => "taxchart_$i",
951 '-style' => 'width:200px',
952 '-values' => \@taxchart_values,
953 '-labels' => \%taxchart_labels,
954 '-default' => $selected_taxchart))
957 my ($fx_transaction, $checked);
959 if ($form->{transfer}) {
960 $fx_transaction = qq|
961 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
966 if ($form->{"debit_$i"} != 0) {
967 $form->{totaldebit} += $form->{"debit_$i"};
968 if (!$form->{taxincluded}) {
969 $form->{totaldebit} += $form->{"tax_$i"};
972 $form->{totalcredit} += $form->{"credit_$i"};
973 if (!$form->{taxincluded}) {
974 $form->{totalcredit} += $form->{"tax_$i"};
978 for (qw(debit credit tax)) {
981 ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
985 if ($i < $form->{rowcount}) {
986 if ($form->{transfer}) {
987 $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
988 my $x = ($checked) ? "x" : "";
989 $fx_transaction = qq|
990 <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
993 $form->hide_form("accno_$i");
996 if ($form->{transfer}) {
997 $fx_transaction = qq|
998 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
1003 my $debitreadonly = "";
1004 my $creditreadonly = "";
1005 if ($i == $form->{rowcount}) {
1006 if ($form->{debitlock}) {
1007 $debitreadonly = "readonly";
1008 } elsif ($form->{creditlock}) {
1009 $creditreadonly = "readonly";
1014 NTI($cgi->popup_menu('-name' => "project_id_$i",
1015 '-values' => \@project_values,
1016 '-labels' => \%project_labels,
1017 '-default' => $form->{"project_id_$i"} ));
1018 my $projectnumber_hidden = qq|
1019 <input type="hidden" name="project_id_$i" value="$form->{"project_id_$i"}">|;
1021 my $copy2credit = $i == 1 ? 'onkeyup="copy_debit_to_credit()"' : '';
1023 print qq|<tr valign=top>
1025 <td id="chart_balance_$i" align="right"> </td>
1027 <td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td>
1028 <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
1029 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
1032 if ($form->{show_details}) {
1036 <td>$projectnumber</td>
1042 $projectnumber_hidden
1050 $form->hide_form(qw(rowcount selectaccno));
1052 $main::lxdebug->leave_sub();
1058 $main::lxdebug->enter_sub();
1060 $main::auth->assert('general_ledger');
1062 my $form = $main::form;
1063 my %myconfig = %main::myconfig;
1064 my $locale = $main::locale;
1066 my @old_project_ids = ();
1067 map({ push(@old_project_ids, $form->{"project_id_$_"})
1068 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
1070 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1072 "old_id" => \@old_project_ids },
1073 "charts" => { "key" => "ALL_CHARTS",
1074 "transdate" => $form->{transdate} },
1075 "taxcharts" => "ALL_TAXCHARTS");
1077 GL->get_chart_balances('charts' => $form->{ALL_CHARTS});
1079 my $title = $form->{title};
1080 $form->{title} = $locale->text("$title General Ledger Transaction");
1081 my $readonly = ($form->{id}) ? "readonly" : "";
1083 my $show_details_checked = $form->{show_details} ? "checked" : '';
1084 my $ob_transaction_checked = $form->{ob_transaction} ? "checked" : '';
1085 my $cb_transaction_checked = $form->{cb_transaction} ? "checked" : '';
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 = $::request->{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 = $form->{remove_draft} ? 'checked' : '';
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});