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 #======================================================================
48 require "bin/mozilla/common.pl";
56 sub add { call_sub("add_$main::form->{type}"); }
57 sub delete { call_sub("delete_$main::form->{type}"); }
58 sub save { call_sub("save_$main::form->{type}"); }
59 sub edit { call_sub("edit_$main::form->{type}"); }
60 sub continue { call_sub($main::form->{"nextsub"}); }
61 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
64 $main::lxdebug->enter_sub();
66 my $form = $main::form;
67 my %myconfig = %main::myconfig;
69 $main::auth->assert('config');
71 $form->{title} = "Add";
72 $form->{charttype} = "A";
73 AM->get_account(\%myconfig, \%$form);
75 $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
80 $main::lxdebug->leave_sub();
84 $main::lxdebug->enter_sub();
86 my $form = $main::form;
87 my %myconfig = %main::myconfig;
89 $main::auth->assert('config');
91 $form->{title} = "Edit";
92 AM->get_account(\%myconfig, \%$form);
94 foreach my $item (split(/:/, $form->{link})) {
95 $form->{$item} = "checked";
101 $main::lxdebug->leave_sub();
105 $main::lxdebug->enter_sub();
107 my $form = $main::form;
108 my %myconfig = %main::myconfig;
109 my $locale = $main::locale;
111 $main::auth->assert('config');
113 if ( $form->{action} eq 'edit_account') {
114 $form->{account_exists} = '1';
117 $form->{title} = $locale->text("$form->{title} Account");
119 $form->{"$form->{charttype}_checked"} = "checked";
120 $form->{"$form->{category}_checked"} = "checked";
122 $form->{select_tax} = "";
124 my @tax_report_pos = USTVA->report_variables({
125 myconfig => \%myconfig,
128 attribute => 'position',
132 if (@{ $form->{TAXKEY} }) {
133 foreach my $item (@{ $form->{TAXKEY} }) {
134 $item->{rate} = $item->{rate} * 100 . '%';
137 # Fill in empty row for new Taxkey
138 my $newtaxkey_ref = {
143 taxdescription => '',
150 push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
153 foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
155 # Fill in a runningnumber
156 $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
158 # Fill in the Taxkeys as select options
159 foreach my $item (@{ $form->{TAXKEY} }) {
160 if ($item->{id} == $taxkey_used->{tax_id}) {
161 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
162 qq|<option value="$item->{id}" selected="selected">|
163 . sprintf("%.2d", $item->{taxkey})
164 . qq|. $item->{taxdescription} ($item->{rate}) |
165 . $locale->text('Tax-o-matic Account')
166 . qq|: $item->{chart_accno}\n|;
169 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
170 qq|<option value="$item->{id}">|
171 . sprintf("%.2d", $item->{taxkey})
172 . qq|. $item->{taxdescription} ($item->{rate}) |
173 . $locale->text('Tax-o-matic Account')
174 . qq|: $item->{chart_accno}\n|;
179 # Fill in the USTVA Numbers as select options
180 foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
182 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
184 elsif ( $item eq $taxkey_used->{pos_ustva} ) {
185 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
188 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
197 # Newaccount Folgekonto
198 if (@{ $form->{NEWACCOUNT} || [] }) {
199 if (!$form->{new_chart_valid}) {
200 $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
202 foreach my $item (@{ $form->{NEWACCOUNT} }) {
203 if ($item->{id} == $form->{new_chart_id}) {
204 $form->{selectnewaccount} .=
205 qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
206 } elsif (!$form->{new_chart_valid}) {
207 $form->{selectnewaccount} .=
208 qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
214 my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
217 2 => "sonstige Erlöse",
218 3 => "Privatanteile",
220 5 => "Ausserordentliche Erträge",
221 6 => "Vereinnahmte Umsatzst.",
222 7 => "Umsatzsteuererstattungen",
223 8 => "Wareneingänge",
224 9 => "Löhne und Gehälter",
225 10 => "Gesetzl. sozialer Aufw.",
227 12 => "Gas, Strom, Wasser",
228 13 => "Instandhaltung",
229 14 => "Steuern, Versich., Beiträge",
231 16 => "Kfz-Versicherungen",
232 17 => "Sonst. Fahrzeugkosten",
233 18 => "Werbe- und Reisekosten",
234 19 => "Instandhaltung u. Werkzeuge",
235 20 => "Fachzeitschriften, Bücher",
236 21 => "Miete für Einrichtungen",
237 22 => "Rechts- und Beratungskosten",
238 23 => "Bürobedarf, Porto, Telefon",
239 24 => "Sonstige Aufwendungen",
240 25 => "Abschreibungen auf Anlagever.",
241 26 => "Abschreibungen auf GWG",
243 28 => "Umsatzsteuerzahlungen",
245 30 => "Ausserordentlicher Aufwand",
246 31 => "Betriebliche Steuern");
247 foreach my $item (sort({ $a <=> $b } keys(%eur))) {
248 my $text = H(SL::Iconv::convert("ISO-8859-15", $main::dbcharset, $eur{$item}));
249 if ($item == $form->{pos_eur}) {
250 $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
252 $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
257 my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
261 2 => 'Best.Verdg.FE/UE',
262 3 => 'Aktiv.Eigenleistung',
263 4 => 'Mat./Wareneinkauf',
264 5 => 'So.betr.Erlöse',
265 10 => 'Personalkosten',
267 12 => 'Betriebl.Steuern',
268 13 => 'Vers./Beiträge',
269 14 => 'Kfz.Kosten o.St.',
270 15 => 'Werbe-Reisek.',
271 16 => 'Kosten Warenabgabe',
272 17 => 'Abschreibungen',
273 18 => 'Rep./instandhlt.',
274 19 => 'Übrige Steuern',
275 20 => 'Sonst.Kosten',
277 31 => 'Sonst.neutr.Aufw.',
279 33 => 'Sonst.neutr.Ertrag',
280 34 => 'Verr.kalk.Kosten',
281 35 => 'Steuern Eink.u.Ertr.');
282 foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
283 my $text = H(SL::Iconv::convert("ISO-8859-15", $main::dbcharset, $bwapos{$item}));
284 if ($item == $form->{pos_bwa}) {
285 $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
287 $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
292 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
293 my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
294 foreach my $item ((1, 2, 3, 4)) {
295 if ($item == $form->{pos_bilanz}) {
296 $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
298 $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
303 # this is for our parser only! Do not remove.
304 # type=submit $locale->text('Add Account')
305 # type=submit $locale->text('Edit Account')
307 $form->{type} = "account";
309 # preselections category
311 my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
314 'A' => $locale->text('Asset'),
315 'L' => $locale->text('Liability'),
316 'Q' => $locale->text('Equity'),
317 'I' => $locale->text('Revenue'),
318 'E' => $locale->text('Expense'),
319 'C' => $locale->text('Costs'),
321 foreach my $item ( sort({ $a <=> $b } keys %category) ) {
322 if ($item eq $form->{category}) {
323 $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
325 $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
330 # preselection chart type
331 my $select_charttype = q{};
334 'A' => $locale->text('Account'),
335 'H' => $locale->text('Heading'),
338 foreach my $item ( sort({ $a <=> $b } keys %charttype) ) {
339 if ($item eq $form->{charttype}) {
340 $select_charttype .= qq|<option value="$item" selected="selected">$charttype{$item}\n|;
343 $select_charttype .= qq|<option value="$item">$charttype{$item}\n|;
348 my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
352 my $parameters_ref = {
353 ChartTypeIsAccount => $ChartTypeIsAccount,
354 select_category => $select_category,
355 select_charttype => $select_charttype,
356 select_bwa => $select_bwa,
357 select_bilanz => $select_bilanz,
358 select_eur => $select_eur,
361 # Ausgabe des Templates
362 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
365 $main::lxdebug->leave_sub();
369 $main::lxdebug->enter_sub();
371 my $form = $main::form;
372 my $locale = $main::locale;
374 $main::auth->assert('config');
378 <input name=callback type=hidden value="| . H($form->{callback}) . qq|">
381 if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) {
383 <input type=submit class=submit name=action value="|
384 . $locale->text('Save') . qq|">
388 if ($form->{id} && $form->{orphaned}) {
389 print qq|<input type=submit class=submit name=action value="|
390 . $locale->text('Delete') . qq|">|;
393 if ($form->{id} && $form->{type} eq "account") {
395 <input class=submit type=submit name=action value="|
396 . $locale->text('Save as new') . qq|">|;
406 $main::lxdebug->leave_sub();
410 $main::lxdebug->enter_sub();
412 my $form = $main::form;
413 my %myconfig = %main::myconfig;
414 my $locale = $main::locale;
416 $main::auth->assert('config');
418 $form->isblank("accno", $locale->text('Account Number missing!'));
419 $form->isblank("description", $locale->text('Account Description missing!'));
421 if ($form->{charttype} eq 'A'){
422 $form->isblank("category", $locale->text('Account Type missing!'));
425 $form->redirect($locale->text('Account saved!'))
426 if (AM->save_account(\%myconfig, \%$form));
427 $form->error($locale->text('Cannot save account!'));
429 $main::lxdebug->leave_sub();
432 sub save_as_new_account {
433 $main::lxdebug->enter_sub();
435 my $form = $main::form;
436 my %myconfig = %main::myconfig;
437 my $locale = $main::locale;
439 $main::auth->assert('config');
441 $form->isblank("accno", $locale->text('Account Number missing!'));
442 $form->isblank("description", $locale->text('Account Description missing!'));
444 if ($form->{charttype} eq 'A'){
445 $form->isblank("category", $locale->text('Account Type missing!'));
448 for my $taxkey (0 .. 9) {
449 if ($form->{"taxkey_id_$taxkey"}) {
450 $form->{"taxkey_id_$taxkey"} = "NEW";
455 if ($form->{"original_accno"} &&
456 ($form->{"accno"} eq $form->{"original_accno"})) {
457 $form->error($locale->text('Account Number already used!'));
459 $form->redirect($locale->text('Account saved!'))
460 if (AM->save_account(\%myconfig, \%$form));
461 $form->error($locale->text('Cannot save account!'));
463 $main::lxdebug->leave_sub();
467 $main::lxdebug->enter_sub();
469 my $form = $main::form;
470 my %myconfig = %main::myconfig;
471 my $locale = $main::locale;
473 $main::auth->assert('config');
475 $form->{callback} = build_std_url('action=list_account');
476 my $link_edit_account = build_std_url('action=edit_account', 'callback');
478 CA->all_accounts(\%myconfig, \%$form);
480 foreach my $ca (@{ $form->{CA} }) {
485 if ($ca->{amount} > 0) {
486 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
488 if ($ca->{amount} < 0) {
489 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
491 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
492 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
496 my $pjx = new CGI::Ajax('list_account_details' => build_std_url('action=list_account_details'));
498 # Eneable AJAX debuging
502 push(@ { $form->{AJAX} }, $pjx);
504 $form->{stylesheets} = "list_accounts.css";
505 $form->{title} = $locale->text('Chart of Accounts');
510 my $parameters_ref = {
511 # hidden_variables => $_hidden_variables_ref,
514 # Ausgabe des Templates
515 print($form->parse_html_template('am/list_accounts', $parameters_ref));
517 $main::lxdebug->leave_sub();
522 sub list_account_details {
523 # Ajax Funktion aus list_account_details
524 $main::lxdebug->enter_sub();
526 my $form = $main::form;
527 my %myconfig = %main::myconfig;
528 my $locale = $main::locale;
530 $main::auth->assert('config');
532 my $chart_id = $form->{args};
534 CA->all_accounts(\%myconfig, \%$form, $chart_id);
536 foreach my $ca (@{ $form->{CA} }) {
538 $ca->{debit} = " ";
539 $ca->{credit} = " ";
541 if ($ca->{amount} > 0) {
543 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
545 if ($ca->{amount} < 0) {
547 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
550 my @links = split( q{:}, $ca->{link});
554 foreach my $link (@links){
555 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
556 : ( $link eq 'AP') ? $locale->text('Account Link AP')
557 : ( $link eq 'IC') ? $locale->text('Account Link IC')
558 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
559 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
560 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
561 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
562 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
563 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
564 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
565 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
566 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
567 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
568 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
569 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
570 # : ( $link eq 'CT_tax' ) ? $locale->text('Account Link CT_tax')
571 : $locale->text('Unknown Link') . ': ' . $link;
572 $ca->{link} .= ($link ne '') ? "[$link] ":'';
575 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
576 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
577 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
578 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
579 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
580 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
581 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
582 : $locale->text('Unknown Category') . ': ' . $ca->{category};
585 $form->{title} = $locale->text('Chart of Accounts');
588 print $form->parse_html_template('am/list_account_details');
590 $main::lxdebug->leave_sub();
595 $main::lxdebug->enter_sub();
597 my $form = $main::form;
598 my %myconfig = %main::myconfig;
599 my $locale = $main::locale;
601 $main::auth->assert('config');
603 $form->{title} = $locale->text('Delete Account');
606 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
608 if ($form->{id} == $form->{$id}) {
609 $form->error($locale->text('Cannot delete default account!'));
613 $form->redirect($locale->text('Account deleted!'))
614 if (AM->delete_account(\%myconfig, \%$form));
615 $form->error($locale->text('Cannot delete account!'));
617 $main::lxdebug->leave_sub();
621 $main::lxdebug->enter_sub();
623 my $form = $main::form;
625 $main::auth->assert('config');
627 $form->{title} = "Add";
630 $form->{callback} = "am.pl?action=add_department" unless $form->{callback};
635 $main::lxdebug->leave_sub();
638 sub edit_department {
639 $main::lxdebug->enter_sub();
641 my $form = $main::form;
642 my %myconfig = %main::myconfig;
644 $main::auth->assert('config');
646 $form->{title} = "Edit";
648 AM->get_department(\%myconfig, \%$form);
653 $main::lxdebug->leave_sub();
656 sub list_department {
657 $main::lxdebug->enter_sub();
659 my $form = $main::form;
660 my %myconfig = %main::myconfig;
661 my $locale = $main::locale;
663 $main::auth->assert('config');
665 AM->departments(\%myconfig, \%$form);
667 $form->{callback} = "am.pl?action=list_department";
669 my $callback = $form->escape($form->{callback});
671 $form->{title} = $locale->text('Departments');
673 my @column_index = qw(description cost profit);
675 $column_header{description} =
676 qq|<th class=listheading width=90%>|
677 . $locale->text('Description')
679 $column_header{cost} =
680 qq|<th class=listheading nowrap>|
681 . $locale->text('Cost Center')
683 $column_header{profit} =
684 qq|<th class=listheading nowrap>|
685 . $locale->text('Profit Center')
695 <th class=listtop>$form->{title}</th>
701 <tr class=listheading>
704 map { print "$column_header{$_}\n" } @column_index;
710 my ($i, %column_data);
711 foreach my $ref (@{ $form->{ALL} }) {
717 <tr valign=top class=listrow$i>
720 my $costcenter = ($ref->{role} eq "C") ? "X" : "";
721 my $profitcenter = ($ref->{role} eq "P") ? "X" : "";
723 $column_data{description} =
724 qq|<td><a href="am.pl?action=edit_department&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
725 $column_data{cost} = qq|<td align=center>$costcenter</td>|;
726 $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
728 map { print "$column_data{$_}\n" } @column_index;
740 <td><hr size=3 noshade></td>
745 <form method=post action=am.pl>
747 <input name=callback type=hidden value="$form->{callback}">
749 <input type=hidden name=type value=department>
751 <input class=submit type=submit name=action value="|
752 . $locale->text('Add') . qq|">
760 $main::lxdebug->leave_sub();
763 sub department_header {
764 $main::lxdebug->enter_sub();
766 my $form = $main::form;
767 my $locale = $main::locale;
769 $main::auth->assert('config');
771 $form->{title} = $locale->text("$form->{title} Department");
773 # $locale->text('Add Department')
774 # $locale->text('Edit Department')
776 $form->{description} =~ s/\"/"/g;
778 my ($rows, $description);
779 if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
781 qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
784 qq|<input name=description size=60 value="$form->{description}">|;
787 my $costcenter = "checked" if $form->{role} eq "C";
788 my $profitcenter = "checked" if $form->{role} eq "P";
795 <form method=post action=am.pl>
797 <input type=hidden name=id value=$form->{id}>
798 <input type=hidden name=type value=department>
802 <th class=listtop colspan=2>$form->{title}</th>
806 <th align=right>| . $locale->text('Description') . qq|</th>
807 <td>$description</td>
811 <td><input type=radio style=radio name=role value="C" $costcenter> |
812 . $locale->text('Cost Center') . qq|
813 <input type=radio style=radio name=role value="P" $profitcenter> |
814 . $locale->text('Profit Center') . qq|
817 <td colspan=2><hr size=3 noshade></td>
822 $main::lxdebug->leave_sub();
825 sub save_department {
826 $main::lxdebug->enter_sub();
828 my $form = $main::form;
829 my %myconfig = %main::myconfig;
830 my $locale = $main::locale;
832 $main::auth->assert('config');
834 $form->isblank("description", $locale->text('Description missing!'));
835 AM->save_department(\%myconfig, \%$form);
836 $form->redirect($locale->text('Department saved!'));
838 $main::lxdebug->leave_sub();
841 sub delete_department {
842 $main::lxdebug->enter_sub();
844 my $form = $main::form;
845 my %myconfig = %main::myconfig;
846 my $locale = $main::locale;
848 $main::auth->assert('config');
850 AM->delete_department(\%myconfig, \%$form);
851 $form->redirect($locale->text('Department deleted!'));
853 $main::lxdebug->leave_sub();
857 $main::lxdebug->enter_sub();
859 my $form = $main::form;
861 $main::auth->assert('config');
863 $form->{title} = "Add";
865 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
870 $main::lxdebug->leave_sub();
874 $main::lxdebug->enter_sub();
876 my $form = $main::form;
877 my %myconfig = %main::myconfig;
879 $main::auth->assert('config');
881 $form->{title} = "Edit";
883 AM->get_lead(\%myconfig, \%$form);
887 $form->{orphaned} = 1;
890 $main::lxdebug->leave_sub();
894 $main::lxdebug->enter_sub();
896 my $form = $main::form;
897 my %myconfig = %main::myconfig;
898 my $locale = $main::locale;
900 $main::auth->assert('config');
902 AM->lead(\%myconfig, \%$form);
904 $form->{callback} = "am.pl?action=list_lead";
906 my $callback = $form->escape($form->{callback});
908 $form->{title} = $locale->text('Lead');
910 my @column_index = qw(description cost profit);
912 $column_header{description} =
913 qq|<th class=listheading width=100%>|
914 . $locale->text('Description')
924 <th class=listtop>$form->{title}</th>
927 <tr class=listheading>
930 map { print "$column_header{$_}\n" } @column_index;
936 my ($i, %column_data);
937 foreach my $ref (@{ $form->{ALL} }) {
943 <tr valign=top class=listrow$i>
946 # $lead = $ref->{lead};
948 $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
950 map { print "$column_data{$_}\n" } @column_index;
959 <td><hr size=3 noshade></td>
964 <form method=post action=am.pl>
966 <input name=callback type=hidden value="$form->{callback}">
968 <input type=hidden name=type value=lead>
970 <input class=submit type=submit name=action value="|
971 . $locale->text('Add') . qq|">
979 $main::lxdebug->leave_sub();
983 $main::lxdebug->enter_sub();
985 my $form = $main::form;
986 my $locale = $main::locale;
988 $main::auth->assert('config');
990 $form->{title} = $locale->text("$form->{title} Lead");
992 # $locale->text('Add Lead')
993 # $locale->text('Edit Lead')
995 $form->{description} =~ s/\"/"/g;
998 qq|<input name=description size=50 value="$form->{lead}">|;
1005 <form method=post action=am.pl>
1007 <input type=hidden name=id value=$form->{id}>
1008 <input type=hidden name=type value=lead>
1012 <th class=listtop colspan=2>$form->{title}</th>
1014 <tr height="5"></tr>
1016 <th align=right>| . $locale->text('Description') . qq|</th>
1017 <td>$description</td>
1019 <td colspan=2><hr size=3 noshade></td>
1024 $main::lxdebug->leave_sub();
1028 $main::lxdebug->enter_sub();
1030 my $form = $main::form;
1031 my %myconfig = %main::myconfig;
1032 my $locale = $main::locale;
1034 $main::auth->assert('config');
1036 $form->isblank("description", $locale->text('Description missing!'));
1037 AM->save_lead(\%myconfig, \%$form);
1038 $form->redirect($locale->text('lead saved!'));
1040 $main::lxdebug->leave_sub();
1044 $main::lxdebug->enter_sub();
1046 my $form = $main::form;
1047 my %myconfig = %main::myconfig;
1048 my $locale = $main::locale;
1050 $main::auth->assert('config');
1052 AM->delete_lead(\%myconfig, \%$form);
1053 $form->redirect($locale->text('lead deleted!'));
1055 $main::lxdebug->leave_sub();
1059 $main::lxdebug->enter_sub();
1061 my $form = $main::form;
1063 $main::auth->assert('config');
1065 $form->{title} = "Add";
1067 $form->{callback} = "am.pl?action=add_business" unless $form->{callback};
1072 $main::lxdebug->leave_sub();
1076 $main::lxdebug->enter_sub();
1078 my $form = $main::form;
1079 my %myconfig = %main::myconfig;
1081 $form->{title} = "Edit";
1083 AM->get_business(\%myconfig, \%$form);
1087 $form->{orphaned} = 1;
1090 $main::lxdebug->leave_sub();
1094 $main::lxdebug->enter_sub();
1096 my $form = $main::form;
1097 my %myconfig = %main::myconfig;
1098 my $locale = $main::locale;
1100 $main::auth->assert('config');
1102 AM->business(\%myconfig, \%$form);
1104 $form->{callback} = "am.pl?action=list_business";
1106 my $callback = $form->escape($form->{callback});
1108 $form->{title} = $locale->text('Type of Business');
1110 my @column_index = qw(description discount customernumberinit);
1111 push @column_index, 'salesman' if $::vertreter;
1113 $column_header{description} =
1114 qq|<th class=listheading width=60%>|
1115 . $locale->text('Description')
1117 $column_header{discount} =
1118 qq|<th class=listheading width=10%>|
1119 . $locale->text('Discount')
1121 $column_header{customernumberinit} =
1122 qq|<th class=listheading>|
1123 . $locale->text('Customernumberinit')
1125 $column_header{salesman} =
1126 qq|<th class=listheading>|
1127 . $locale->text('Representative')
1137 <th class=listtop>$form->{title}</th>
1139 <tr height="5"></tr>
1143 <tr class=listheading>
1146 map { print "$column_header{$_}\n" } @column_index;
1152 my ($i, %column_data);
1153 foreach my $ref (@{ $form->{ALL} }) {
1159 <tr valign=top class=listrow$i>
1162 my $discount = $form->format_amount(\%myconfig, $ref->{discount} * 100);
1163 my $description = $ref->{description};
1164 $column_data{description} = qq|<td><a href="am.pl?action=edit_business&id=$ref->{id}&callback=$callback">$description</td>|;
1165 $column_data{discount} = qq|<td align=right>$discount</td>|;
1166 $column_data{customernumberinit} =
1167 qq|<td align=right>$ref->{customernumberinit}</td>|;
1168 $column_data{salesman} = '<td>' . ($ref->{salesman} ? $::locale->text('Yes') : $::locale->text('No')) . '</td>';
1170 map { print "$column_data{$_}\n" } @column_index;
1182 <td><hr size=3 noshade></td>
1187 <form method=post action=am.pl>
1189 <input name=callback type=hidden value="$form->{callback}">
1191 <input type=hidden name=type value=business>
1193 <input class=submit type=submit name=action value="|
1194 . $locale->text('Add') . qq|">
1202 $main::lxdebug->leave_sub();
1205 sub business_header {
1206 $main::lxdebug->enter_sub();
1208 my $form = $main::form;
1209 my %myconfig = %main::myconfig;
1210 my $locale = $main::locale;
1212 $main::auth->assert('config');
1214 $form->{title} = $locale->text("$form->{title} Business");
1216 # $locale->text('Add Business')
1217 # $locale->text('Edit Business')
1219 $form->{description} =~ s/\"/"/g;
1221 $form->format_amount(\%myconfig, $form->{discount} * 100);
1225 $salesman_code = qq|
1227 <th align="right">| . $locale->text('Representative') . qq|</th>
1228 <td>| . $::cgi->checkbox(-name => "salesman", -value => 1, -label => '', 'checked' => $form->{salesman} ? 1 : 0) . qq|</td>
1232 $salesman_code = $::cgi->hidden(-name => 'salesman', -value => $form->{salesman} ? 1 : 0);
1240 <form method=post action=am.pl>
1242 <input type=hidden name=id value=$form->{id}>
1243 <input type=hidden name=type value=business>
1247 <th class=listtop colspan=2>$form->{title}</th>
1249 <tr height="5"></tr>
1251 <th align=right>| . $locale->text('Type of Business') . qq|</th>
1252 <td><input name=description size=30 value="$form->{description}"></td>
1255 <th align=right>| . $locale->text('Discount') . qq| %</th>
1256 <td><input name=discount size=5 value=$form->{discount}></td>
1259 <th align=right>| . $locale->text('Customernumberinit') . qq|</th>
1260 <td><input name=customernumberinit size=10 value=$form->{customernumberinit}></td>
1263 <td colspan=2><hr size=3 noshade></td>
1268 $main::lxdebug->leave_sub();
1272 $main::lxdebug->enter_sub();
1274 my $form = $main::form;
1275 my %myconfig = %main::myconfig;
1276 my $locale = $main::locale;
1278 $main::auth->assert('config');
1280 $form->isblank("description", $locale->text('Description missing!'));
1281 $form->{discount} = $form->parse_amount(\%myconfig, $form->{discount}) / 100;
1282 AM->save_business(\%myconfig, \%$form);
1283 $form->redirect($locale->text('Business saved!'));
1285 $main::lxdebug->leave_sub();
1288 sub delete_business {
1289 $main::lxdebug->enter_sub();
1291 my $form = $main::form;
1292 my %myconfig = %main::myconfig;
1293 my $locale = $main::locale;
1295 $main::auth->assert('config');
1297 AM->delete_business(\%myconfig, \%$form);
1298 $form->redirect($locale->text('Business deleted!'));
1300 $main::lxdebug->leave_sub();
1304 $main::lxdebug->enter_sub();
1306 my $form = $main::form;
1308 $main::auth->assert('config');
1310 $form->{title} = "Add";
1312 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
1317 $main::lxdebug->leave_sub();
1321 $main::lxdebug->enter_sub();
1323 my $form = $main::form;
1324 my %myconfig = %main::myconfig;
1326 $main::auth->assert('config');
1328 $form->{title} = "Edit";
1330 AM->get_language(\%myconfig, \%$form);
1334 $form->{orphaned} = 1;
1337 $main::lxdebug->leave_sub();
1341 $main::lxdebug->enter_sub();
1343 my $form = $main::form;
1344 my %myconfig = %main::myconfig;
1345 my $locale = $main::locale;
1347 $main::auth->assert('config');
1349 AM->language(\%myconfig, \%$form);
1351 $form->{callback} = "am.pl?action=list_language";
1353 my $callback = $form->escape($form->{callback});
1355 $form->{title} = $locale->text('Languages');
1357 my @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
1359 $column_header{description} =
1360 qq|<th class=listheading width=60%>|
1361 . $locale->text('Description')
1363 $column_header{template_code} =
1364 qq|<th class=listheading width=10%>|
1365 . $locale->text('Template Code')
1367 $column_header{article_code} =
1368 qq|<th class=listheading>|
1369 . $locale->text('Article Code')
1371 $column_header{output_numberformat} =
1372 qq|<th class=listheading>|
1373 . $locale->text('Number Format')
1375 $column_header{output_dateformat} =
1376 qq|<th class=listheading>|
1377 . $locale->text('Date Format')
1379 $column_header{output_longdates} =
1380 qq|<th class=listheading>|
1381 . $locale->text('Long Dates')
1391 <th class=listtop>$form->{title}</th>
1393 <tr height="5"></tr>
1397 <tr class=listheading>
1400 map { print "$column_header{$_}\n" } @column_index;
1406 my ($i, %column_data);
1407 foreach my $ref (@{ $form->{ALL} }) {
1413 <tr valign=top class=listrow$i>
1417 $column_data{description} =
1418 qq|<td><a href="am.pl?action=edit_language&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
1419 $column_data{template_code} = qq|<td align=right>$ref->{template_code}</td>|;
1420 $column_data{article_code} =
1421 qq|<td align=right>$ref->{article_code}</td>|;
1422 $column_data{output_numberformat} =
1424 ($ref->{output_numberformat} ? $ref->{output_numberformat} :
1425 $locale->text("use program settings")) .
1427 $column_data{output_dateformat} =
1429 ($ref->{output_dateformat} ? $ref->{output_dateformat} :
1430 $locale->text("use program settings")) .
1432 $column_data{output_longdates} =
1434 ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
1437 map { print "$column_data{$_}\n" } @column_index;
1449 <td><hr size=3 noshade></td>
1454 <form method=post action=am.pl>
1456 <input name=callback type=hidden value="$form->{callback}">
1458 <input type=hidden name=type value=language>
1460 <input class=submit type=submit name=action value="|
1461 . $locale->text('Add') . qq|">
1469 $main::lxdebug->leave_sub();
1472 sub language_header {
1473 $main::lxdebug->enter_sub();
1475 my $form = $main::form;
1476 my $locale = $main::locale;
1478 $main::auth->assert('config');
1480 $form->{title} = $locale->text("$form->{title} Language");
1482 # $locale->text('Add Language')
1483 # $locale->text('Edit Language')
1485 $form->{description} =~ s/\"/"/g;
1486 $form->{template_code} =~ s/\"/"/g;
1487 $form->{article_code} =~ s/\"/"/g;
1493 qq|<option value="">| . $locale->text("use program settings") .
1495 foreach my $item (('1,000.00', '1000.00', '1.000,00', '1000,00')) {
1497 ($item eq $form->{output_numberformat})
1498 ? "<option selected>$item"
1504 qq|<option value="">| . $locale->text("use program settings") .
1506 foreach my $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
1508 ($item eq $form->{output_dateformat})
1509 ? "<option selected>$item"
1517 <form method=post action=am.pl>
1519 <input type=hidden name=id value=$form->{id}>
1520 <input type=hidden name=type value=language>
1524 <th class=listtop colspan=2>$form->{title}</th>
1526 <tr height="5"></tr>
1528 <th align=right>| . $locale->text('Language') . qq|</th>
1529 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1532 <th align=right>| . $locale->text('Template Code') . qq|</th>
1533 <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
1536 <th align=right>| . $locale->text('Article Code') . qq|</th>
1537 <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
1540 <th align=right>| . $locale->text('Number Format') . qq|</th>
1541 <td><select name="output_numberformat">$numberformat</select></td>
1544 <th align=right>| . $locale->text('Date Format') . qq|</th>
1545 <td><select name="output_dateformat">$dateformat</select></td>
1548 <th align=right>| . $locale->text('Long Dates') . qq|</th>
1549 <td><input type="radio" name="output_longdates" value="1"| .
1550 ($form->{output_longdates} ? " checked" : "") .
1551 qq|>| . $locale->text("Yes") .
1552 qq|<input type="radio" name="output_longdates" value="0"| .
1553 ($form->{output_longdates} ? "" : " checked") .
1554 qq|>| . $locale->text("No") .
1557 <td colspan=2><hr size=3 noshade></td>
1562 $main::lxdebug->leave_sub();
1566 $main::lxdebug->enter_sub();
1568 my $form = $main::form;
1569 my %myconfig = %main::myconfig;
1570 my $locale = $main::locale;
1572 $main::auth->assert('config');
1574 $form->isblank("description", $locale->text('Language missing!'));
1575 $form->isblank("template_code", $locale->text('Template Code missing!'));
1576 $form->isblank("article_code", $locale->text('Article Code missing!'));
1577 AM->save_language(\%myconfig, \%$form);
1578 $form->redirect($locale->text('Language saved!'));
1580 $main::lxdebug->leave_sub();
1583 sub delete_language {
1584 $main::lxdebug->enter_sub();
1586 my $form = $main::form;
1587 my %myconfig = %main::myconfig;
1588 my $locale = $main::locale;
1590 $main::auth->assert('config');
1592 AM->delete_language(\%myconfig, \%$form);
1593 $form->redirect($locale->text('Language deleted!'));
1595 $main::lxdebug->leave_sub();
1599 sub add_buchungsgruppe {
1600 $main::lxdebug->enter_sub();
1602 my $form = $main::form;
1603 my %myconfig = %main::myconfig;
1604 my $locale = $main::locale;
1606 $main::auth->assert('config');
1608 # $locale->text("Add Buchungsgruppe")
1609 # $locale->text("Edit Buchungsgruppe")
1610 $form->{title} = "Add";
1612 $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
1614 AM->get_buchungsgruppe(\%myconfig, \%$form);
1615 $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
1616 for (my $i = 0; 4 > $i; $i++) {
1617 map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
1618 qw(income expense));
1621 &buchungsgruppe_header;
1624 $main::lxdebug->leave_sub();
1627 sub edit_buchungsgruppe {
1628 $main::lxdebug->enter_sub();
1630 my $form = $main::form;
1631 my %myconfig = %main::myconfig;
1633 $main::auth->assert('config');
1635 $form->{title} = "Edit";
1637 AM->get_buchungsgruppe(\%myconfig, \%$form);
1639 &buchungsgruppe_header;
1643 $main::lxdebug->leave_sub();
1646 sub list_buchungsgruppe {
1647 $main::lxdebug->enter_sub();
1649 my $form = $main::form;
1650 my %myconfig = %main::myconfig;
1651 my $locale = $main::locale;
1653 $main::auth->assert('config');
1655 AM->buchungsgruppe(\%myconfig, \%$form);
1657 $form->{callback} = "am.pl?action=list_buchungsgruppe";
1659 my $callback = $form->escape($form->{callback});
1661 $form->{title} = $locale->text('Buchungsgruppen');
1663 my @column_index = qw(up down description inventory_accno
1664 income_accno_0 expense_accno_0
1665 income_accno_1 expense_accno_1
1666 income_accno_2 expense_accno_2
1667 income_accno_3 expense_accno_3 );
1669 $column_header{up} =
1670 qq|<th class="listheading" width="16">|
1671 . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
1673 $column_header{down} =
1674 qq|<th class="listheading" width="16">|
1675 . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
1677 $column_header{description} =
1678 qq|<th class="listheading" width="40%">|
1679 . $locale->text('Description')
1681 $column_header{inventory_accno} =
1682 qq|<th class=listheading>|
1683 . $locale->text('Bestandskonto')
1685 $column_header{income_accno_0} =
1686 qq|<th class=listheading>|
1687 . $locale->text('National Revenues')
1689 $column_header{expense_accno_0} =
1690 qq|<th class=listheading>|
1691 . $locale->text('National Expenses')
1693 $column_header{income_accno_1} =
1694 qq|<th class=listheading>|
1695 . $locale->text('Revenues EU with UStId')
1697 $column_header{expense_accno_1} =
1698 qq|<th class=listheading>|
1699 . $locale->text('Expenses EU with UStId')
1701 $column_header{income_accno_2} =
1702 qq|<th class=listheading>|
1703 . $locale->text('Revenues EU without UStId')
1705 $column_header{expense_accno_2} =
1706 qq|<th class=listheading>|
1707 . $locale->text('Expenses EU without UStId')
1709 $column_header{income_accno_3} =
1710 qq|<th class=listheading>|
1711 . $locale->text('Foreign Revenues')
1713 $column_header{expense_accno_3} =
1714 qq|<th class=listheading>|
1715 . $locale->text('Foreign Expenses')
1724 <th class=listtop>$form->{title}</th>
1726 <tr height="5"></tr>
1730 <tr class=listheading>
1733 map { print "$column_header{$_}\n" } @column_index;
1739 my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
1742 my ($i, %column_data);
1743 foreach my $ref (@{ $form->{ALL} }) {
1749 <tr valign=top class=listrow$i>
1753 my $pref = $form->{ALL}->[$row - 1];
1755 qq|<td align="center" valign="center" width="16">| .
1756 qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
1757 qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
1760 $column_data{up} = qq|<td width="16"> </td>|;
1763 if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
1764 $column_data{down} = qq|<td width="16"> </td>|;
1766 my $nref = $form->{ALL}->[$row + 1];
1767 $column_data{down} =
1768 qq|<td align="center" valign="center" width="16">| .
1769 qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
1770 qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
1774 $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
1775 $column_data{inventory_accno} = qq|<td align=right>$ref->{inventory_accno}</td>|;
1776 $column_data{income_accno_0} =
1777 qq|<td align=right>$ref->{income_accno_0}</td>|;
1778 $column_data{expense_accno_0} = qq|<td align=right>$ref->{expense_accno_0}</td>|;
1779 $column_data{income_accno_1} =
1780 qq|<td align=right>$ref->{income_accno_1}</td>|;
1781 $column_data{expense_accno_1} = qq|<td align=right>$ref->{expense_accno_1}</td>|;
1782 $column_data{income_accno_2} =
1783 qq|<td align=right>$ref->{income_accno_2}</td>|;
1784 $column_data{expense_accno_2} = qq|<td align=right>$ref->{expense_accno_2}</td>|;
1785 $column_data{income_accno_3} =
1786 qq|<td align=right>$ref->{income_accno_3}</td>|;
1787 $column_data{expense_accno_3} = qq|<td align=right>$ref->{expense_accno_3}</td>|;
1789 map { print "$column_data{$_}\n" } @column_index;
1803 <td><hr size=3 noshade></td>
1808 <form method=post action=am.pl>
1810 <input name=callback type=hidden value="$form->{callback}">
1812 <input type=hidden name=type value=buchungsgruppe>
1814 <input class=submit type=submit name=action value="|
1815 . $locale->text('Add') . qq|">
1823 $main::lxdebug->leave_sub();
1826 sub buchungsgruppe_header {
1827 $main::lxdebug->enter_sub();
1829 my $form = $main::form;
1830 my $locale = $main::locale;
1832 $main::auth->assert('config');
1834 $form->{title} = $locale->text("$form->{title} Buchungsgruppe");
1836 # $locale->text('Add Accounting Group')
1837 # $locale->text('Edit Accounting Group')
1839 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
1840 my %acc_type_map = (
1841 "IC" => $acc_inventory,
1842 "IC_income" => $acc_income,
1843 "IC_sale" => $acc_income,
1844 "IC_expense" => $acc_expense,
1845 "IC_cogs" => $acc_expense,
1848 foreach my $key (keys(%acc_type_map)) {
1849 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1850 $acc_type_map{$key}->{$ref->{"id"}} = $ref;
1854 foreach my $type (qw(IC IC_income IC_expense)) {
1855 $form->{"select$type"} =
1857 map({ "<option value=$_->{id} $_->{selected}>" .
1858 "$_->{accno}--" . H($_->{description}) . "</option>" }
1859 sort({ $a->{"accno"} cmp $b->{"accno"} }
1860 values(%{$acc_type_map{$type}}))));
1864 $form->{selectIC} =~ s/selected//g;
1865 $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/ value=$form->{inventory_accno_id} selected/;
1866 $form->{selectIC_income} =~ s/selected//g;
1867 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/ value=$form->{income_accno_id_0} selected/;
1868 $form->{selectIC_expense} =~ s/selected//g;
1869 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/ value=$form->{expense_accno_id_0} selected/;
1876 <th align=right>| . $locale->text('Inventory') . qq|</th>
1877 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
1878 <input name=selectIC type=hidden value="$form->{selectIC}">
1882 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
1886 $linkaccounts .= qq|
1888 <th align=right>| . $locale->text('National Revenues') . qq|</th>
1889 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
1892 <th align=right>| . $locale->text('National Expenses') . qq|</th>
1893 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
1896 $form->{selectIC_income} =~ s/selected//g;
1897 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/ value=$form->{income_accno_id_1} selected/;
1898 $form->{selectIC_expense} =~ s/selected//g;
1899 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/ value=$form->{expense_accno_id_1} selected/;
1901 $linkaccounts .= qq| <tr>
1902 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
1903 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
1906 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
1907 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
1911 $form->{selectIC_income} =~ s/selected//g;
1912 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/ value=$form->{income_accno_id_2} selected/;
1913 $form->{selectIC_expense} =~ s/selected//g;
1914 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/ value=$form->{expense_accno_id_2} selected/;
1917 $linkaccounts .= qq| <tr>
1918 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
1919 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
1922 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
1923 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
1927 $form->{selectIC_income} =~ s/selected//g;
1928 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/ value=$form->{income_accno_id_3} selected/;
1929 $form->{selectIC_expense} =~ s/selected//g;
1930 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/ value=$form->{expense_accno_id_3} selected/;
1933 $linkaccounts .= qq| <tr>
1934 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
1935 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
1938 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
1939 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
1949 <form method=post action=am.pl>
1951 <input type=hidden name=id value=$form->{id}>
1952 <input type=hidden name=type value=buchungsgruppe>
1956 <th class=listtop colspan=2>$form->{title}</th>
1958 <tr height="5"></tr>
1960 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
1961 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1964 <td colspan=2><hr size=3 noshade></td>
1969 $main::lxdebug->leave_sub();
1972 sub save_buchungsgruppe {
1973 $main::lxdebug->enter_sub();
1975 my $form = $main::form;
1976 my %myconfig = %main::myconfig;
1977 my $locale = $main::locale;
1979 $main::auth->assert('config');
1981 $form->isblank("description", $locale->text('Description missing!'));
1983 AM->save_buchungsgruppe(\%myconfig, \%$form);
1984 $form->redirect($locale->text('Accounting Group saved!'));
1986 $main::lxdebug->leave_sub();
1989 sub delete_buchungsgruppe {
1990 $main::lxdebug->enter_sub();
1992 my $form = $main::form;
1993 my %myconfig = %main::myconfig;
1994 my $locale = $main::locale;
1996 $main::auth->assert('config');
1998 AM->delete_buchungsgruppe(\%myconfig, \%$form);
1999 $form->redirect($locale->text('Accounting Group deleted!'));
2001 $main::lxdebug->leave_sub();
2004 sub swap_buchungsgruppen {
2005 $main::lxdebug->enter_sub();
2007 my $form = $main::form;
2008 my %myconfig = %main::myconfig;
2010 $main::auth->assert('config');
2012 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
2013 list_buchungsgruppe();
2015 $main::lxdebug->leave_sub();
2019 $main::lxdebug->enter_sub();
2021 my $form = $main::form;
2022 my %myconfig = %main::myconfig;
2024 $main::auth->assert('config');
2026 $form->{title} = "Add";
2028 $form->{callback} = "am.pl?action=add_payment" unless $form->{callback};
2030 $form->{terms_netto} = 0;
2031 $form->{terms_skonto} = 0;
2032 $form->{percent_skonto} = 0;
2033 my @languages = AM->language(\%myconfig, $form, 1);
2034 map({ $_->{"language"} = $_->{"description"};
2035 $_->{"language_id"} = $_->{"id"}; } @languages);
2036 $form->{"TRANSLATION"} = \@languages;
2040 $main::lxdebug->leave_sub();
2044 $main::lxdebug->enter_sub();
2046 my $form = $main::form;
2047 my %myconfig = %main::myconfig;
2049 $main::auth->assert('config');
2051 $form->{title} = "Edit";
2053 AM->get_payment(\%myconfig, $form);
2054 $form->{percent_skonto} =
2055 $form->format_amount(\%myconfig, $form->{percent_skonto} * 100);
2059 $form->{orphaned} = 1;
2062 $main::lxdebug->leave_sub();
2066 $main::lxdebug->enter_sub();
2068 my $form = $main::form;
2069 my %myconfig = %main::myconfig;
2070 my $locale = $main::locale;
2072 $main::auth->assert('config');
2074 AM->payment(\%myconfig, \%$form);
2076 $form->{callback} = build_std_url("action=list_payment");
2078 my $callback = $form->escape($form->{callback});
2080 $form->{title} = $locale->text('Payment Terms');
2082 my @column_index = qw(up down description description_long terms_netto
2083 terms_skonto percent_skonto);
2085 $column_header{up} =
2086 qq|<th class="listheading" align="center" valign="center" width="16">|
2087 . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
2089 $column_header{down} =
2090 qq|<th class="listheading" align="center" valign="center" width="16">|
2091 . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
2093 $column_header{description} =
2094 qq|<th class=listheading>|
2095 . $locale->text('Description')
2097 $column_header{description_long} =
2098 qq|<th class=listheading>|
2099 . $locale->text('Long Description')
2101 $column_header{terms_netto} =
2102 qq|<th class=listheading>|
2103 . $locale->text('Netto Terms')
2105 $column_header{terms_skonto} =
2106 qq|<th class=listheading>|
2107 . $locale->text('Skonto Terms')
2109 $column_header{percent_skonto} =
2110 qq|<th class=listheading>|
2111 . $locale->text('Skonto')
2121 <th class=listtop>$form->{title}</th>
2123 <tr height="5"></tr>
2127 <tr class=listheading>
2130 map { print "$column_header{$_}\n" } @column_index;
2136 my $swap_link = build_std_url("action=swap_payment_terms");
2139 my ($i, %column_data);
2140 foreach my $ref (@{ $form->{ALL} }) {
2146 <tr valign=top class=listrow$i>
2150 my $pref = $form->{ALL}->[$row - 1];
2152 qq|<td align="center" valign="center" width="16">| .
2153 qq|<a href="${swap_link}&id1=$ref->{id}&id2=$pref->{id}">| .
2154 qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
2157 $column_data{up} = qq|<td width="16"> </td>|;
2160 if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
2161 $column_data{down} = qq|<td width="16"> </td>|;
2163 my $nref = $form->{ALL}->[$row + 1];
2164 $column_data{down} =
2165 qq|<td align="center" valign="center" width="16">| .
2166 qq|<a href="${swap_link}&id1=$ref->{id}&id2=$nref->{id}">| .
2167 qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
2171 $column_data{description} =
2173 build_std_url("action=edit_payment", "id=$ref->{id}", "callback=$callback") .
2174 qq|">| . H($ref->{description}) . qq|</a></td>|;
2175 $column_data{description_long} =
2176 qq|<td>| . H($ref->{description_long}) . qq|</td>|;
2177 $column_data{terms_netto} =
2178 qq|<td align=right>$ref->{terms_netto}</td>|;
2179 $column_data{terms_skonto} =
2180 qq|<td align=right>$ref->{terms_skonto}</td>|;
2181 $column_data{percent_skonto} =
2182 qq|<td align=right>| .
2183 $form->format_amount(\%myconfig, $ref->{percent_skonto} * 100) .
2185 map { print "$column_data{$_}\n" } @column_index;
2198 <td><hr size=3 noshade></td>
2203 <form method=post action=am.pl>
2205 <input name=callback type=hidden value="$form->{callback}">
2207 <input type=hidden name=type value=payment>
2209 <input class=submit type=submit name=action value="|
2210 . $locale->text('Add') . qq|">
2218 $main::lxdebug->leave_sub();
2221 sub payment_header {
2222 $main::lxdebug->enter_sub();
2224 my $form = $main::form;
2225 my $locale = $main::locale;
2227 $main::auth->assert('config');
2229 $form->{title} = $locale->text("$form->{title} Payment Terms");
2231 # $locale->text('Add Payment Terms')
2232 # $locale->text('Edit Payment Terms')
2234 $form->{description} =~ s/\"/"/g;
2243 <form method=post action=am.pl>
2245 <input type=hidden name=id value=$form->{id}>
2246 <input type=hidden name=type value=payment>
2250 <th class=listtop colspan=2>$form->{title}</th>
2252 <tr height="5"></tr>
2254 <th align=right>| . $locale->text('Description') . qq|</th>
2255 <td><input name=description size=30 value="$form->{description}"></td>
2258 <th align=right>| . $locale->text('Long Description') . qq|</th>
2259 <td><input name=description_long size=50 value="$form->{description_long}"></td>
2263 foreach my $language (@{ $form->{"TRANSLATION"} }) {
2266 <th align="right">| .
2267 sprintf($locale->text('Translation (%s)'),
2268 $language->{"language"})
2270 <td><input name="description_long_$language->{language_id}" size="50"
2271 value="| . Q($language->{"description_long"}) . qq|"></td>
2278 <th align=right>| . $locale->text('Netto Terms') . qq|</th>
2279 <td><input name=terms_netto size=10 value="$form->{terms_netto}"></td>
2282 <th align=right>| . $locale->text('Skonto Terms') . qq|</th>
2283 <td><input name=terms_skonto size=10 value="$form->{terms_skonto}"></td>
2286 <th align=right>| . $locale->text('Skonto') . qq| %</th>
2287 <td><input name=percent_skonto size=10 value="$form->{percent_skonto}"></td>
2289 <td colspan=2><hr size=3 noshade></td>
2293 <p>| . $locale->text("You can use the following strings in the long " .
2294 "description and all translations. They will be " .
2295 "replaced by their actual values by Lx-Office " .
2296 "before they're output.")
2300 <li>| . $locale->text("<%netto_date%> -- Date the payment is due in " .
2303 <li>| . $locale->text("<%skonto_date%> -- Date the payment is due " .
2306 <li>| . $locale->text("<%skonto_amount%> -- The deductible amount")
2308 <li>| . $locale->text("<%skonto_in_percent%> -- The discount in percent")
2310 <li>| . $locale->text("<%total%> -- Amount payable")
2312 <li>| . $locale->text("<%total_wo_skonto%> -- Amount payable less discount")
2314 <li>| . $locale->text("<%invtotal%> -- Invoice total")
2316 <li>| . $locale->text("<%invtotal_wo_skonto%> -- Invoice total less discount")
2318 <li>| . $locale->text("<%currency%> -- The selected currency")
2320 <li>| . $locale->text("<%terms_netto%> -- The number of days for " .
2323 <li>| . $locale->text("<%account_number%> -- Your account number")
2325 <li>| . $locale->text("<%bank%> -- Your bank")
2327 <li>| . $locale->text("<%bank_code%> -- Your bank code")
2331 $main::lxdebug->leave_sub();
2335 $main::lxdebug->enter_sub();
2337 my $form = $main::form;
2338 my %myconfig = %main::myconfig;
2339 my $locale = $main::locale;
2341 $main::auth->assert('config');
2343 $form->isblank("description", $locale->text('Description missing!'));
2344 $form->{"percent_skonto"} =
2345 $form->parse_amount(\%myconfig, $form->{percent_skonto}) / 100;
2346 AM->save_payment(\%myconfig, \%$form);
2347 $form->redirect($locale->text('Payment Terms saved!'));
2349 $main::lxdebug->leave_sub();
2352 sub delete_payment {
2353 $main::lxdebug->enter_sub();
2355 my $form = $main::form;
2356 my %myconfig = %main::myconfig;
2357 my $locale = $main::locale;
2359 $main::auth->assert('config');
2361 AM->delete_payment(\%myconfig, \%$form);
2362 $form->redirect($locale->text('Payment terms deleted!'));
2364 $main::lxdebug->leave_sub();
2367 sub swap_payment_terms {
2368 $main::lxdebug->enter_sub();
2370 my $form = $main::form;
2371 my %myconfig = %main::myconfig;
2373 $main::auth->assert('config');
2375 AM->swap_sortkeys(\%myconfig, $form, "payment_terms");
2378 $main::lxdebug->leave_sub();
2382 $main::lxdebug->enter_sub();
2384 my $form = $main::form;
2385 my %myconfig = %main::myconfig;
2386 my $locale = $main::locale;
2388 # get defaults for account numbers and last numbers
2389 AM->defaultaccounts(\%myconfig, \%$form);
2390 $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
2392 map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
2394 foreach my $key (keys %{ $form->{IC} }) {
2395 foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
2396 my $array = "ACCNOS_" . uc($key);
2397 $form->{$array} ||= [];
2399 my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
2400 push @{ $form->{$array} }, {
2403 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
2408 $form->{title} = $locale->text('Ranges of numbers and default accounts');
2411 print $form->parse_html_template('am/edit_defaults');
2413 $main::lxdebug->leave_sub();
2417 $main::lxdebug->enter_sub();
2419 my $form = $main::form;
2420 my $locale = $main::locale;
2422 AM->save_defaults();
2424 $form->redirect($locale->text('Defaults saved.'));
2426 $main::lxdebug->leave_sub();
2429 sub _build_cfg_options {
2430 my $form = $main::form;
2431 my %myconfig = %main::myconfig;
2434 my $array = uc($idx) . 'S';
2436 $form->{$array} = [];
2437 foreach my $item (@_) {
2438 push @{ $form->{$array} }, {
2441 'selected' => $item eq $myconfig{$idx},
2447 $main::lxdebug->enter_sub();
2449 my $form = $main::form;
2450 my %myconfig = %main::myconfig;
2451 my $locale = $main::locale;
2453 _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
2454 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
2457 if ($main::opendocument_templates && $main::openofficeorg_writer_bin &&
2458 $main::xvfb_bin && (-x $main::openofficeorg_writer_bin) && (-x $main::xvfb_bin)) {
2459 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
2460 "value" => "opendocument_pdf" });
2462 if ($main::latex_templates) {
2463 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
2465 push(@formats, { "name" => "HTML", "value" => "html" });
2466 if ($main::latex_templates) {
2467 push(@formats, { "name" => $locale->text("Postscript"),
2468 "value" => "postscript" });
2470 if ($main::opendocument_templates) {
2471 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
2472 "value" => "opendocument" });
2475 if (!$myconfig{"template_format"}) {
2476 $myconfig{"template_format"} = "pdf";
2478 $form->{TEMPLATE_FORMATS} = [];
2479 foreach my $item (@formats) {
2480 push @{ $form->{TEMPLATE_FORMATS} }, {
2481 'name' => $item->{name},
2482 'value' => $item->{value},
2483 'selected' => $item->{value} eq $myconfig{template_format},
2487 if (!$myconfig{"default_media"}) {
2488 $myconfig{"default_media"} = "screen";
2491 my %selected = ($myconfig{"default_media"} => "selected");
2493 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
2494 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
2495 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
2498 $form->{PRINTERS} = [];
2499 foreach my $printer (SL::Printer->all_printers(%::myconfig)) {
2500 push @{ $form->{PRINTERS} }, {
2501 'name' => $printer->{printer_description},
2502 'value' => $printer->{id},
2503 'selected' => $printer->{id} == $myconfig{default_printer_id},
2507 my %countrycodes = User->country_codes;
2509 $form->{COUNTRYCODES} = [];
2510 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
2511 push @{ $form->{COUNTRYCODES} }, {
2512 'name' => $countrycodes{$countrycode},
2513 'value' => $countrycode,
2514 'selected' => $countrycode eq $myconfig{countrycode},
2518 $form->{STYLESHEETS} = [];
2519 foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
2520 push @{ $form->{STYLESHEETS} }, {
2523 'selected' => $item eq $myconfig{stylesheet},
2527 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
2528 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
2529 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
2531 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
2534 print $form->parse_html_template('am/config');
2536 $main::lxdebug->leave_sub();
2539 sub save_preferences {
2540 $main::lxdebug->enter_sub();
2542 my $form = $main::form;
2543 my %myconfig = %main::myconfig;
2544 my $locale = $main::locale;
2546 $form->{stylesheet} = $form->{usestylesheet};
2548 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
2550 $form->redirect($locale->text('Preferences saved!')) if (AM->save_preferences(\%myconfig, \%$form, 0));
2551 $form->error($locale->text('Cannot save preferences!'));
2553 $main::lxdebug->leave_sub();
2557 $main::lxdebug->enter_sub();
2559 my $form = $main::form;
2560 my %myconfig = %main::myconfig;
2561 my $locale = $main::locale;
2563 $main::auth->assert('config');
2565 $form->{title} = $locale->text('Audit Control');
2567 AM->closedto(\%myconfig, \%$form);
2574 <form method=post action=am.pl>
2577 <tr><th class=listtop>$form->{title}</th></tr>
2578 <tr height="5"></tr>
2583 <th>| . $locale->text('Close Books up to') . qq|</th>
2584 <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
2594 <input type=hidden name=nextsub value=doclose>
2596 <input type=submit class=submit name=action value="|
2597 . $locale->text('Continue') . qq|">
2605 $main::lxdebug->leave_sub();
2609 $main::lxdebug->enter_sub();
2611 my $form = $main::form;
2612 my %myconfig = %main::myconfig;
2613 my $locale = $main::locale;
2615 $main::auth->assert('config');
2617 AM->closebooks(\%myconfig, \%$form);
2619 if ($form->{closedto}) {
2621 $locale->text('Books closed up to') . " "
2622 . $locale->date(\%myconfig, $form->{closedto}, 1));
2624 $form->redirect($locale->text('Books are open'));
2627 $main::lxdebug->leave_sub();
2631 $main::lxdebug->enter_sub();
2633 my $form = $main::form;
2634 my %myconfig = %main::myconfig;
2635 my $locale = $main::locale;
2637 $main::auth->assert('config');
2639 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
2640 AM->units_in_use(\%myconfig, $form, $units);
2641 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
2643 my @languages = AM->language(\%myconfig, $form, 1);
2645 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
2648 foreach (@unit_list) {
2649 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
2650 $_->{"UNITLANGUAGES"} = [];
2651 foreach my $lang (@languages) {
2652 push(@{ $_->{"UNITLANGUAGES"} },
2654 "unit" => $_->{"name"},
2655 "language_id" => $lang->{"id"},
2656 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
2657 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
2663 $units = AM->retrieve_units(\%myconfig, $form);
2664 my $ddbox = AM->unit_select_data($units, undef, 1);
2666 my $updownlink = build_std_url("action=swap_units");
2668 $form->{"title"} = $locale->text("Add and edit units");
2670 print($form->parse_html_template("am/edit_units",
2671 { "UNITS" => \@unit_list,
2672 "NEW_BASE_UNIT_DDBOX" => $ddbox,
2673 "LANGUAGES" => \@languages,
2674 "updownlink" => $updownlink }));
2676 $main::lxdebug->leave_sub();
2680 $main::lxdebug->enter_sub();
2682 my $form = $main::form;
2683 my %myconfig = %main::myconfig;
2684 my $locale = $main::locale;
2686 $main::auth->assert('config');
2688 $form->isblank("new_name", $locale->text("The name is missing."));
2689 my $units = AM->retrieve_units(\%myconfig, $form);
2690 my $all_units = AM->retrieve_units(\%myconfig, $form);
2691 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
2693 my ($base_unit, $factor);
2694 if ($form->{"new_base_unit"}) {
2695 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
2697 $form->isblank("new_factor", $locale->text("The factor is missing."));
2698 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
2699 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
2700 $base_unit = $form->{"new_base_unit"};
2704 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
2705 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
2706 push(@languages, { "id" => $lang->{"id"},
2707 "localized" => $form->{"new_localized_$lang->{id}"},
2708 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
2712 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
2714 $form->{"saved_message"} = $locale->text("The unit has been saved.");
2718 $main::lxdebug->leave_sub();
2721 sub set_unit_languages {
2722 $main::lxdebug->enter_sub();
2724 my $form = $main::form;
2726 $main::auth->assert('config');
2728 my ($unit, $languages, $idx) = @_;
2730 $unit->{"LANGUAGES"} = [];
2732 foreach my $lang (@{$languages}) {
2733 push(@{ $unit->{"LANGUAGES"} },
2734 { "id" => $lang->{"id"},
2735 "localized" => $form->{"localized_${idx}_$lang->{id}"},
2736 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
2740 $main::lxdebug->leave_sub();
2744 $main::lxdebug->enter_sub();
2746 my $form = $main::form;
2747 my %myconfig = %main::myconfig;
2748 my $locale = $main::locale;
2750 $main::auth->assert('config');
2752 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
2753 AM->units_in_use(\%myconfig, $form, $old_units);
2755 my @languages = AM->language(\%myconfig, $form, 1);
2758 my @delete_units = ();
2759 foreach my $i (1..($form->{"rowcount"} * 1)) {
2760 my $old_unit = $old_units->{$form->{"old_name_$i"}};
2762 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
2765 if ($form->{"unchangeable_$i"}) {
2766 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
2767 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
2768 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
2772 if ($old_unit->{"in_use"}) {
2773 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
2776 if ($form->{"delete_$i"}) {
2777 push(@delete_units, $old_unit->{"name"});
2781 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
2783 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
2784 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
2785 $new_units->{$form->{"name_$i"}} = \%h;
2786 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
2787 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
2790 foreach my $unit (values(%{$new_units})) {
2791 next unless ($unit->{"old_name"});
2792 if ($unit->{"base_unit"}) {
2793 $form->show_generic_error(sprintf($locale->text("The base unit does not exist or it is about to be deleted in row %d."), $unit->{"row"}))
2794 unless (defined($new_units->{$unit->{"base_unit"}}));
2795 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
2796 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
2798 $unit->{"base_unit"} = undef;
2799 $unit->{"factor"} = undef;
2803 foreach my $unit (values(%{$new_units})) {
2804 next if ($unit->{"unchanged_unit"});
2806 map({ $_->{"seen"} = 0; } values(%{$new_units}));
2807 my $new_unit = $unit;
2808 while ($new_unit->{"base_unit"}) {
2809 $new_unit->{"seen"} = 1;
2810 $new_unit = $new_units->{$new_unit->{"base_unit"}};
2811 if ($new_unit->{"seen"}) {
2812 $form->show_generic_error(sprintf($locale->text("The base unit relations must not contain loops (e.g. by saying that unit A's base unit is B, " .
2813 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
2818 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
2820 $form->{"saved_message"} = $locale->text("The units have been saved.");
2824 $main::lxdebug->leave_sub();
2827 sub show_history_search {
2828 $main::lxdebug->enter_sub();
2830 my $form = $main::form;
2831 my $locale = $main::locale;
2833 $main::auth->assert('config');
2835 $form->{title} = $locale->text("History Search");
2838 print $form->parse_html_template("common/search_history");
2840 $main::lxdebug->leave_sub();
2843 sub show_am_history {
2844 $main::lxdebug->enter_sub();
2846 my $form = $main::form;
2847 my %myconfig = %main::myconfig;
2848 my $locale = $main::locale;
2850 $main::auth->assert('config');
2852 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
2853 $form->{order} ||= 'h.itime--1';
2855 my %search = ( "Artikelnummer" => "parts",
2856 "Kundennummer" => "customer",
2857 "Lieferantennummer" => "vendor",
2858 "Projektnummer" => "project",
2859 "Buchungsnummer" => "oe",
2860 "Eingangsrechnungnummer" => "ap",
2861 "Ausgangsrechnungnummer" => "ar",
2862 "Mahnungsnummer" => "dunning"
2864 my %searchNo = ( "Artikelnummer" => "partnumber",
2865 "Kundennummer" => "customernumber",
2866 "Lieferantennummer" => "vendornumber",
2867 "Projektnummer" => "projectnummer",
2868 "Buchungsnummer" => "ordnumber",
2869 "Eingangsrechnungnummer" => "invnumber",
2870 "Ausgangsrechnungnummer" => "invnumber",
2871 "Mahnungsnummer" => "dunning_id"
2874 my $dbh = $form->dbconnect(\%myconfig);
2876 my $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
2877 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
2878 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
2879 if ($form->{mitarbeiter} =~ m/^\d+$/) {
2880 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
2881 } elsif ($form->{mitarbeiter}) {
2882 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
2885 my $query = qq|SELECT trans_id AS id FROM history_erp | .
2886 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
2887 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
2889 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
2890 my $daten .= shift @ids;
2891 $daten .= join '', map { " OR trans_id = $_" } @ids;
2893 my ($sort, $sortby) = split(/\-\-/, $form->{order});
2894 $sort =~ s/.*\.(.*)$/$1/;
2896 $form->{title} = $locale->text("History Search");
2899 print $form->parse_html_template("common/show_history",
2900 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
2901 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
2904 uc($sort) . "BY" => $sortby,
2905 'callback' => $callback,
2909 $main::lxdebug->leave_sub();
2913 $main::lxdebug->enter_sub();
2915 my $form = $main::form;
2916 my %myconfig = %main::myconfig;
2918 $main::auth->assert('config');
2920 my $dir = $form->{"dir"} eq "down" ? "down" : "up";
2921 AM->swap_units(\%myconfig, $form, $dir, $form->{"name"});
2925 $main::lxdebug->leave_sub();
2929 $main::lxdebug->enter_sub();
2931 my $form = $main::form;
2932 my $locale = $main::locale;
2934 $main::auth->assert('config');
2936 $form->{title} = $locale->text('Add');
2938 $form->{callback} ||= "am.pl?action=add_tax";
2940 _get_taxaccount_selection();
2944 my $parameters_ref = {
2945 # ChartTypeIsAccount => $ChartTypeIsAccount,
2948 # Ausgabe des Templates
2949 print($form->parse_html_template('am/edit_tax', $parameters_ref));
2951 $main::lxdebug->leave_sub();
2955 $main::lxdebug->enter_sub();
2957 my $form = $main::form;
2958 my %myconfig = %main::myconfig;
2959 my $locale = $main::locale;
2961 $main::auth->assert('config');
2963 $form->{title} = $locale->text('Edit');
2965 AM->get_tax(\%myconfig, \%$form);
2966 _get_taxaccount_selection();
2968 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
2972 my $parameters_ref = {
2975 # Ausgabe des Templates
2976 print($form->parse_html_template('am/edit_tax', $parameters_ref));
2978 $main::lxdebug->leave_sub();
2982 $main::lxdebug->enter_sub();
2984 my $form = $main::form;
2985 my %myconfig = %main::myconfig;
2986 my $locale = $main::locale;
2988 $main::auth->assert('config');
2990 AM->taxes(\%myconfig, \%$form);
2992 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
2994 $form->{callback} = build_std_url('action=list_tax');
2996 $form->{title} = $locale->text('Tax-O-Matic');
3000 my $parameters_ref = {
3003 # Ausgabe des Templates
3004 print($form->parse_html_template('am/list_tax', $parameters_ref));
3006 $main::lxdebug->leave_sub();
3009 sub _get_taxaccount_selection{
3010 $main::lxdebug->enter_sub();
3012 my $form = $main::form;
3013 my %myconfig = %main::myconfig;
3015 $main::auth->assert('config');
3017 AM->get_tax_accounts(\%myconfig, \%$form);
3019 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
3021 $main::lxdebug->leave_sub();
3025 $main::lxdebug->enter_sub();
3027 my $form = $main::form;
3028 my %myconfig = %main::myconfig;
3029 my $locale = $main::locale;
3031 $main::auth->assert('config');
3033 $form->isblank("rate", $locale->text('Taxrate missing!'));
3034 $form->isblank("taxdescription", $locale->text('Taxdescription missing!'));
3035 $form->isblank("taxkey", $locale->text('Taxkey missing!'));
3037 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
3039 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
3040 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
3043 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
3044 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
3047 AM->save_tax(\%myconfig, \%$form);
3048 $form->redirect($locale->text('Tax saved!'));
3050 $main::lxdebug->leave_sub();
3054 $main::lxdebug->enter_sub();
3056 my $form = $main::form;
3057 my %myconfig = %main::myconfig;
3058 my $locale = $main::locale;
3060 $main::auth->assert('config');
3062 AM->delete_tax(\%myconfig, \%$form);
3063 $form->redirect($locale->text('Tax deleted!'));
3065 $main::lxdebug->leave_sub();
3068 sub add_price_factor {
3069 $main::lxdebug->enter_sub();
3071 my $form = $main::form;
3072 my $locale = $main::locale;
3074 $main::auth->assert('config');
3076 $form->{title} = $locale->text('Add Price Factor');
3077 $form->{callback} ||= build_std_url('action=add_price_factor');
3078 $form->{fokus} = 'description';
3081 print $form->parse_html_template('am/edit_price_factor');
3083 $main::lxdebug->leave_sub();
3086 sub edit_price_factor {
3087 $main::lxdebug->enter_sub();
3089 my $form = $main::form;
3090 my %myconfig = %main::myconfig;
3091 my $locale = $main::locale;
3093 $main::auth->assert('config');
3095 $form->{title} = $locale->text('Edit Price Factor');
3096 $form->{callback} ||= build_std_url('action=add_price_factor');
3097 $form->{fokus} = 'description';
3099 AM->get_price_factor(\%myconfig, $form);
3101 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
3104 print $form->parse_html_template('am/edit_price_factor');
3106 $main::lxdebug->leave_sub();
3109 sub list_price_factors {
3110 $main::lxdebug->enter_sub();
3112 my $form = $main::form;
3113 my %myconfig = %main::myconfig;
3114 my $locale = $main::locale;
3116 $main::auth->assert('config');
3118 AM->get_all_price_factors(\%myconfig, \%$form);
3121 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
3123 $previous->{next_id} = $current->{id};
3124 $current->{previous_id} = $previous->{id};
3127 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
3129 $previous = $current;
3132 $form->{callback} = build_std_url('action=list_price_factors');
3133 $form->{title} = $locale->text('Price Factors');
3134 $form->{url_base} = build_std_url('callback');
3137 print $form->parse_html_template('am/list_price_factors');
3139 $main::lxdebug->leave_sub();
3142 sub save_price_factor {
3143 $main::lxdebug->enter_sub();
3145 my $form = $main::form;
3146 my %myconfig = %main::myconfig;
3147 my $locale = $main::locale;
3149 $main::auth->assert('config');
3151 $form->isblank("description", $locale->text('Description missing!'));
3152 $form->isblank("factor", $locale->text('Factor missing!'));
3154 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
3156 AM->save_price_factor(\%myconfig, $form);
3158 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
3160 $form->redirect($locale->text('Price factor saved!'));
3162 $main::lxdebug->leave_sub();
3165 sub delete_price_factor {
3166 $main::lxdebug->enter_sub();
3168 my $form = $main::form;
3169 my %myconfig = %main::myconfig;
3170 my $locale = $main::locale;
3172 $main::auth->assert('config');
3174 AM->delete_price_factor(\%myconfig, \%$form);
3176 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
3178 $form->redirect($locale->text('Price factor deleted!'));
3180 $main::lxdebug->leave_sub();
3183 sub swap_price_factors {
3184 $main::lxdebug->enter_sub();
3186 my $form = $main::form;
3187 my %myconfig = %main::myconfig;
3189 $main::auth->assert('config');
3191 AM->swap_sortkeys(\%myconfig, $form, 'price_factors');
3192 list_price_factors();
3194 $main::lxdebug->leave_sub();
3198 $main::lxdebug->enter_sub();
3200 my $form = $main::form;
3201 my $locale = $main::locale;
3203 $main::auth->assert('config');
3205 $form->{title} = $locale->text('Add Warehouse');
3206 $form->{callback} ||= build_std_url('action=add_warehouse');
3207 $form->{fokus} = 'description';
3210 print $form->parse_html_template('am/edit_warehouse');
3212 $main::lxdebug->leave_sub();
3215 sub edit_warehouse {
3216 $main::lxdebug->enter_sub();
3218 my $form = $main::form;
3219 my %myconfig = %main::myconfig;
3220 my $locale = $main::locale;
3222 $main::auth->assert('config');
3224 AM->get_warehouse(\%myconfig, $form);
3226 $form->get_lists('employees' => 'EMPLOYEES');
3228 $form->{title} = $locale->text('Edit Warehouse');
3229 $form->{callback} ||= build_std_url('action=list_warehouses');
3230 $form->{fokus} = 'description';
3233 print $form->parse_html_template('am/edit_warehouse');
3235 $main::lxdebug->leave_sub();
3238 sub list_warehouses {
3239 $main::lxdebug->enter_sub();
3241 my $form = $main::form;
3242 my %myconfig = %main::myconfig;
3243 my $locale = $main::locale;
3245 $main::auth->assert('config');
3247 AM->get_all_warehouses(\%myconfig, $form);
3250 foreach my $current (@{ $form->{WAREHOUSES} }) {
3252 $previous->{next_id} = $current->{id};
3253 $current->{previous_id} = $previous->{id};
3256 $previous = $current;
3259 $form->{callback} = build_std_url('action=list_warehouses');
3260 $form->{title} = $locale->text('Warehouses');
3261 $form->{url_base} = build_std_url('callback');
3264 print $form->parse_html_template('am/list_warehouses');
3266 $main::lxdebug->leave_sub();
3269 sub save_warehouse {
3270 $main::lxdebug->enter_sub();
3272 my $form = $main::form;
3273 my %myconfig = %main::myconfig;
3274 my $locale = $main::locale;
3276 $main::auth->assert('config');
3278 $form->isblank("description", $locale->text('Description missing!'));
3280 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
3282 AM->save_warehouse(\%myconfig, $form);
3284 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
3286 $form->redirect($locale->text('Warehouse saved.'));
3288 $main::lxdebug->leave_sub();
3291 sub swap_warehouses {
3292 $main::lxdebug->enter_sub();
3294 my $form = $main::form;
3295 my %myconfig = %main::myconfig;
3297 $main::auth->assert('config');
3299 AM->swap_sortkeys(\%myconfig, $form, 'warehouse');
3302 $main::lxdebug->leave_sub();
3305 sub delete_warehouse {
3306 $main::lxdebug->enter_sub();
3308 my $form = $main::form;
3309 my %myconfig = %main::myconfig;
3310 my $locale = $main::locale;
3312 $main::auth->assert('config');
3314 if (!$form->{confirmed}) {
3315 $form->{title} = $locale->text('Confirmation');
3318 print $form->parse_html_template('am/confirm_delete_warehouse');
3322 if (AM->delete_warehouse(\%myconfig, $form)) {
3323 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
3324 $form->redirect($locale->text('Warehouse deleted.'));
3327 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
3330 $main::lxdebug->leave_sub();
3334 $main::lxdebug->enter_sub();
3336 my $form = $main::form;
3337 my %myconfig = %main::myconfig;
3338 my $locale = $main::locale;
3340 $main::auth->assert('config');
3342 AM->save_bins(\%myconfig, $form);
3344 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
3346 $form->redirect($locale->text('Bins saved.'));
3348 $main::lxdebug->leave_sub();