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 SL::Auth::PasswordPolicy;
49 require "bin/mozilla/common.pl";
57 sub add { call_sub("add_$main::form->{type}"); }
58 sub delete { call_sub("delete_$main::form->{type}"); }
59 sub save { call_sub("save_$main::form->{type}"); }
60 sub edit { call_sub("edit_$main::form->{type}"); }
61 sub continue { call_sub($main::form->{"nextsub"}); }
62 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
65 $main::lxdebug->enter_sub();
67 my $form = $main::form;
68 my %myconfig = %main::myconfig;
70 $main::auth->assert('config');
72 $form->{title} = "Add";
73 $form->{charttype} = "A";
74 AM->get_account(\%myconfig, \%$form);
76 $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
81 $main::lxdebug->leave_sub();
85 $main::lxdebug->enter_sub();
87 my $form = $main::form;
88 my %myconfig = %main::myconfig;
90 $main::auth->assert('config');
92 $form->{title} = "Edit";
93 AM->get_account(\%myconfig, \%$form);
95 foreach my $item (split(/:/, $form->{link})) {
96 $form->{$item} = "checked";
102 $main::lxdebug->leave_sub();
106 $main::lxdebug->enter_sub();
108 my $form = $main::form;
109 my %myconfig = %main::myconfig;
110 my $locale = $main::locale;
112 $main::auth->assert('config');
114 if ( $form->{action} eq 'edit_account') {
115 $form->{account_exists} = '1';
118 $form->{title} = $locale->text("$form->{title} Account");
120 $form->{"$form->{charttype}_checked"} = "checked";
121 $form->{"$form->{category}_checked"} = "checked";
123 $form->{select_tax} = "";
125 my @tax_report_pos = USTVA->report_variables({
126 myconfig => \%myconfig,
129 attribute => 'position',
133 if (@{ $form->{TAXKEY} }) {
134 foreach my $item (@{ $form->{TAXKEY} }) {
135 $item->{rate} = $item->{rate} * 100 . '%';
138 # Fill in empty row for new Taxkey
139 my $newtaxkey_ref = {
144 taxdescription => '',
151 push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
154 foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
156 # Fill in a runningnumber
157 $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
159 # Fill in the Taxkeys as select options
160 foreach my $item (@{ $form->{TAXKEY} }) {
161 if ($item->{id} == $taxkey_used->{tax_id}) {
162 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
163 qq|<option value="$item->{id}" selected="selected">|
164 . sprintf("%.2d", $item->{taxkey})
165 . qq|. $item->{taxdescription} ($item->{rate}) |
166 . $locale->text('Tax-o-matic Account')
167 . qq|: $item->{chart_accno}\n|;
170 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
171 qq|<option value="$item->{id}">|
172 . sprintf("%.2d", $item->{taxkey})
173 . qq|. $item->{taxdescription} ($item->{rate}) |
174 . $locale->text('Tax-o-matic Account')
175 . qq|: $item->{chart_accno}\n|;
180 # Fill in the USTVA Numbers as select options
181 foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
183 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
185 elsif ( $item eq $taxkey_used->{pos_ustva} ) {
186 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
189 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
198 # Newaccount Folgekonto
199 if (@{ $form->{NEWACCOUNT} || [] }) {
200 if (!$form->{new_chart_valid}) {
201 $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
203 foreach my $item (@{ $form->{NEWACCOUNT} }) {
204 if ($item->{id} == $form->{new_chart_id}) {
205 $form->{selectnewaccount} .=
206 qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
207 } elsif (!$form->{new_chart_valid}) {
208 $form->{selectnewaccount} .=
209 qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
215 my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
218 2 => "sonstige Erlöse",
219 3 => "Privatanteile",
221 5 => "Ausserordentliche Erträge",
222 6 => "Vereinnahmte Umsatzst.",
223 7 => "Umsatzsteuererstattungen",
224 8 => "Wareneingänge",
225 9 => "Löhne und Gehälter",
226 10 => "Gesetzl. sozialer Aufw.",
228 12 => "Gas, Strom, Wasser",
229 13 => "Instandhaltung",
230 14 => "Steuern, Versich., Beiträge",
232 16 => "Kfz-Versicherungen",
233 17 => "Sonst. Fahrzeugkosten",
234 18 => "Werbe- und Reisekosten",
235 19 => "Instandhaltung u. Werkzeuge",
236 20 => "Fachzeitschriften, Bücher",
237 21 => "Miete für Einrichtungen",
238 22 => "Rechts- und Beratungskosten",
239 23 => "Bürobedarf, Porto, Telefon",
240 24 => "Sonstige Aufwendungen",
241 25 => "Abschreibungen auf Anlagever.",
242 26 => "Abschreibungen auf GWG",
244 28 => "Umsatzsteuerzahlungen",
246 30 => "Ausserordentlicher Aufwand",
247 31 => "Betriebliche Steuern");
248 foreach my $item (sort({ $a <=> $b } keys(%eur))) {
249 my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
250 if ($item == $form->{pos_eur}) {
251 $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
253 $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
258 my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
262 2 => 'Best.Verdg.FE/UE',
263 3 => 'Aktiv.Eigenleistung',
264 4 => 'Mat./Wareneinkauf',
265 5 => 'So.betr.Erlöse',
266 10 => 'Personalkosten',
268 12 => 'Betriebl.Steuern',
269 13 => 'Vers./Beiträge',
270 14 => 'Kfz.Kosten o.St.',
271 15 => 'Werbe-Reisek.',
272 16 => 'Kosten Warenabgabe',
273 17 => 'Abschreibungen',
274 18 => 'Rep./instandhlt.',
275 19 => 'Übrige Steuern',
276 20 => 'Sonst.Kosten',
278 31 => 'Sonst.neutr.Aufw.',
280 33 => 'Sonst.neutr.Ertrag',
281 34 => 'Verr.kalk.Kosten',
282 35 => 'Steuern Eink.u.Ertr.');
283 foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
284 my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
285 if ($item == $form->{pos_bwa}) {
286 $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
288 $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
293 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
294 my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
295 foreach my $item ((1, 2, 3, 4)) {
296 if ($item == $form->{pos_bilanz}) {
297 $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
299 $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
304 # this is for our parser only! Do not remove.
305 # type=submit $locale->text('Add Account')
306 # type=submit $locale->text('Edit Account')
308 $form->{type} = "account";
310 # preselections category
312 my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
315 'A' => $locale->text('Asset'),
316 'L' => $locale->text('Liability'),
317 'Q' => $locale->text('Equity'),
318 'I' => $locale->text('Revenue'),
319 'E' => $locale->text('Expense'),
320 'C' => $locale->text('Costs'),
322 foreach my $item ( sort({ $a <=> $b } keys %category) ) {
323 if ($item eq $form->{category}) {
324 $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
326 $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
331 # preselection chart type
332 my $select_charttype = q{};
335 'A' => $locale->text('Account'),
336 'H' => $locale->text('Heading'),
339 foreach my $item ( sort({ $a <=> $b } keys %charttype) ) {
340 if ($item eq $form->{charttype}) {
341 $select_charttype .= qq|<option value="$item" selected="selected">$charttype{$item}\n|;
344 $select_charttype .= qq|<option value="$item">$charttype{$item}\n|;
349 my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
353 my $parameters_ref = {
354 ChartTypeIsAccount => $ChartTypeIsAccount,
355 select_category => $select_category,
356 select_charttype => $select_charttype,
357 select_bwa => $select_bwa,
358 select_bilanz => $select_bilanz,
359 select_eur => $select_eur,
362 # Ausgabe des Templates
363 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
366 $main::lxdebug->leave_sub();
370 $main::lxdebug->enter_sub();
372 my $form = $main::form;
373 my $locale = $main::locale;
375 $main::auth->assert('config');
379 <input name=callback type=hidden value="| . H($form->{callback}) . qq|">
382 if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) {
384 <input type=submit class=submit name=action value="|
385 . $locale->text('Save') . qq|">
389 if ($form->{id} && $form->{orphaned}) {
390 print qq|<input type=submit class=submit name=action value="|
391 . $locale->text('Delete') . qq|">|;
394 if ($form->{id} && $form->{type} eq "account") {
396 <input class=submit type=submit name=action value="|
397 . $locale->text('Save as new') . qq|">|;
407 $main::lxdebug->leave_sub();
411 $main::lxdebug->enter_sub();
413 my $form = $main::form;
414 my %myconfig = %main::myconfig;
415 my $locale = $main::locale;
417 $main::auth->assert('config');
419 $form->isblank("accno", $locale->text('Account Number missing!'));
420 $form->isblank("description", $locale->text('Account Description missing!'));
422 if ($form->{charttype} eq 'A'){
423 $form->isblank("category", $locale->text('Account Type missing!'));
426 $form->redirect($locale->text('Account saved!'))
427 if (AM->save_account(\%myconfig, \%$form));
428 $form->error($locale->text('Cannot save account!'));
430 $main::lxdebug->leave_sub();
433 sub save_as_new_account {
434 $main::lxdebug->enter_sub();
436 my $form = $main::form;
437 my %myconfig = %main::myconfig;
438 my $locale = $main::locale;
440 $main::auth->assert('config');
442 $form->isblank("accno", $locale->text('Account Number missing!'));
443 $form->isblank("description", $locale->text('Account Description missing!'));
445 if ($form->{charttype} eq 'A'){
446 $form->isblank("category", $locale->text('Account Type missing!'));
449 for my $taxkey (0 .. 9) {
450 if ($form->{"taxkey_id_$taxkey"}) {
451 $form->{"taxkey_id_$taxkey"} = "NEW";
456 if ($form->{"original_accno"} &&
457 ($form->{"accno"} eq $form->{"original_accno"})) {
458 $form->error($locale->text('Account Number already used!'));
460 $form->redirect($locale->text('Account saved!'))
461 if (AM->save_account(\%myconfig, \%$form));
462 $form->error($locale->text('Cannot save account!'));
464 $main::lxdebug->leave_sub();
468 $main::lxdebug->enter_sub();
470 my $form = $main::form;
471 my %myconfig = %main::myconfig;
472 my $locale = $main::locale;
474 $main::auth->assert('config');
476 $form->{callback} = build_std_url('action=list_account');
477 my $link_edit_account = build_std_url('action=edit_account', 'callback');
479 CA->all_accounts(\%myconfig, \%$form);
481 foreach my $ca (@{ $form->{CA} }) {
486 if ($ca->{amount} > 0) {
487 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
489 if ($ca->{amount} < 0) {
490 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
492 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
493 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
497 my $pjx = new CGI::Ajax('list_account_details' => build_std_url('action=list_account_details'));
499 # Eneable AJAX debuging
503 push(@ { $form->{AJAX} }, $pjx);
505 $form->use_stylesheet("list_accounts.css");
506 $form->{title} = $locale->text('Chart of Accounts');
511 my $parameters_ref = {
512 # hidden_variables => $_hidden_variables_ref,
515 # Ausgabe des Templates
516 print($form->parse_html_template('am/list_accounts', $parameters_ref));
518 $main::lxdebug->leave_sub();
523 sub list_account_details {
524 # Ajax Funktion aus list_account_details
525 $main::lxdebug->enter_sub();
527 my $form = $main::form;
528 my %myconfig = %main::myconfig;
529 my $locale = $main::locale;
531 $main::auth->assert('config');
533 my $chart_id = $form->{args};
535 CA->all_accounts(\%myconfig, \%$form, $chart_id);
537 foreach my $ca (@{ $form->{CA} }) {
539 $ca->{debit} = " ";
540 $ca->{credit} = " ";
542 if ($ca->{amount} > 0) {
544 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
546 if ($ca->{amount} < 0) {
548 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
551 my @links = split( q{:}, $ca->{link});
555 foreach my $link (@links){
556 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
557 : ( $link eq 'AP') ? $locale->text('Account Link AP')
558 : ( $link eq 'IC') ? $locale->text('Account Link IC')
559 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
560 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
561 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
562 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
563 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
564 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
565 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
566 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
567 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
568 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
569 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
570 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
571 # : ( $link eq 'CT_tax' ) ? $locale->text('Account Link CT_tax')
572 : $locale->text('Unknown Link') . ': ' . $link;
573 $ca->{link} .= ($link ne '') ? "[$link] ":'';
576 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
577 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
578 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
579 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
580 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
581 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
582 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
583 : $locale->text('Unknown Category') . ': ' . $ca->{category};
586 $form->{title} = $locale->text('Chart of Accounts');
589 print $form->parse_html_template('am/list_account_details');
591 $main::lxdebug->leave_sub();
596 $main::lxdebug->enter_sub();
598 my $form = $main::form;
599 my %myconfig = %main::myconfig;
600 my $locale = $main::locale;
602 $main::auth->assert('config');
604 $form->{title} = $locale->text('Delete Account');
607 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
609 if ($form->{id} == $form->{$id}) {
610 $form->error($locale->text('Cannot delete default account!'));
614 $form->redirect($locale->text('Account deleted!'))
615 if (AM->delete_account(\%myconfig, \%$form));
616 $form->error($locale->text('Cannot delete account!'));
618 $main::lxdebug->leave_sub();
622 $main::lxdebug->enter_sub();
624 my $form = $main::form;
626 $main::auth->assert('config');
628 $form->{title} = "Add";
630 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
635 $main::lxdebug->leave_sub();
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_lead(\%myconfig, \%$form);
652 $form->{orphaned} = 1;
655 $main::lxdebug->leave_sub();
659 $main::lxdebug->enter_sub();
661 my $form = $main::form;
662 my %myconfig = %main::myconfig;
663 my $locale = $main::locale;
665 $main::auth->assert('config');
667 AM->lead(\%myconfig, \%$form);
669 $form->{callback} = "am.pl?action=list_lead";
671 my $callback = $form->escape($form->{callback});
673 $form->{title} = $locale->text('Lead');
675 my @column_index = qw(description cost profit);
677 $column_header{description} =
678 qq|<th class=listheading width=100%>|
679 . $locale->text('Description')
689 <th class=listtop>$form->{title}</th>
692 <tr class=listheading>
695 map { print "$column_header{$_}\n" } @column_index;
701 my ($i, %column_data);
702 foreach my $ref (@{ $form->{ALL} }) {
708 <tr valign=top class=listrow$i>
711 # $lead = $ref->{lead};
713 $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
715 map { print "$column_data{$_}\n" } @column_index;
724 <td><hr size=3 noshade></td>
729 <form method=post action=am.pl>
731 <input name=callback type=hidden value="$form->{callback}">
733 <input type=hidden name=type value=lead>
735 <input class=submit type=submit name=action value="|
736 . $locale->text('Add') . qq|">
744 $main::lxdebug->leave_sub();
748 $main::lxdebug->enter_sub();
750 my $form = $main::form;
751 my $locale = $main::locale;
753 $main::auth->assert('config');
755 $form->{title} = $locale->text("$form->{title} Lead");
757 # $locale->text('Add Lead')
758 # $locale->text('Edit Lead')
760 $form->{description} =~ s/\"/"/g;
763 qq|<input name=description size=50 value="$form->{lead}">|;
770 <form method=post action=am.pl>
772 <input type=hidden name=id value=$form->{id}>
773 <input type=hidden name=type value=lead>
777 <th class=listtop colspan=2>$form->{title}</th>
781 <th align=right>| . $locale->text('Description') . qq|</th>
782 <td>$description</td>
784 <td colspan=2><hr size=3 noshade></td>
789 $main::lxdebug->leave_sub();
793 $main::lxdebug->enter_sub();
795 my $form = $main::form;
796 my %myconfig = %main::myconfig;
797 my $locale = $main::locale;
799 $main::auth->assert('config');
801 $form->isblank("description", $locale->text('Description missing!'));
802 AM->save_lead(\%myconfig, \%$form);
803 $form->redirect($locale->text('lead saved!'));
805 $main::lxdebug->leave_sub();
809 $main::lxdebug->enter_sub();
811 my $form = $main::form;
812 my %myconfig = %main::myconfig;
813 my $locale = $main::locale;
815 $main::auth->assert('config');
817 AM->delete_lead(\%myconfig, \%$form);
818 $form->redirect($locale->text('lead deleted!'));
820 $main::lxdebug->leave_sub();
824 $main::lxdebug->enter_sub();
826 my $form = $main::form;
828 $main::auth->assert('config');
830 $form->{title} = "Add";
832 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
837 $main::lxdebug->leave_sub();
841 $main::lxdebug->enter_sub();
843 my $form = $main::form;
844 my %myconfig = %main::myconfig;
846 $main::auth->assert('config');
848 $form->{title} = "Edit";
850 AM->get_language(\%myconfig, \%$form);
854 $form->{orphaned} = 1;
857 $main::lxdebug->leave_sub();
861 $main::lxdebug->enter_sub();
863 my $form = $main::form;
864 my %myconfig = %main::myconfig;
865 my $locale = $main::locale;
867 $main::auth->assert('config');
869 AM->language(\%myconfig, \%$form);
871 $form->{callback} = "am.pl?action=list_language";
873 my $callback = $form->escape($form->{callback});
875 $form->{title} = $locale->text('Languages');
877 my @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
879 $column_header{description} =
880 qq|<th class=listheading width=60%>|
881 . $locale->text('Description')
883 $column_header{template_code} =
884 qq|<th class=listheading width=10%>|
885 . $locale->text('Template Code')
887 $column_header{article_code} =
888 qq|<th class=listheading>|
889 . $locale->text('Article Code')
891 $column_header{output_numberformat} =
892 qq|<th class=listheading>|
893 . $locale->text('Number Format')
895 $column_header{output_dateformat} =
896 qq|<th class=listheading>|
897 . $locale->text('Date Format')
899 $column_header{output_longdates} =
900 qq|<th class=listheading>|
901 . $locale->text('Long Dates')
911 <th class=listtop>$form->{title}</th>
917 <tr class=listheading>
920 map { print "$column_header{$_}\n" } @column_index;
926 my ($i, %column_data);
927 foreach my $ref (@{ $form->{ALL} }) {
933 <tr valign=top class=listrow$i>
937 $column_data{description} =
938 qq|<td><a href="am.pl?action=edit_language&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
939 $column_data{template_code} = qq|<td align=right>$ref->{template_code}</td>|;
940 $column_data{article_code} =
941 qq|<td align=right>$ref->{article_code}</td>|;
942 $column_data{output_numberformat} =
944 ($ref->{output_numberformat} ? $ref->{output_numberformat} :
945 $locale->text("use program settings")) .
947 $column_data{output_dateformat} =
949 ($ref->{output_dateformat} ? $ref->{output_dateformat} :
950 $locale->text("use program settings")) .
952 $column_data{output_longdates} =
954 ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
957 map { print "$column_data{$_}\n" } @column_index;
969 <td><hr size=3 noshade></td>
974 <form method=post action=am.pl>
976 <input name=callback type=hidden value="$form->{callback}">
978 <input type=hidden name=type value=language>
980 <input class=submit type=submit name=action value="|
981 . $locale->text('Add') . qq|">
989 $main::lxdebug->leave_sub();
992 sub language_header {
993 $main::lxdebug->enter_sub();
995 my $form = $main::form;
996 my $locale = $main::locale;
998 $main::auth->assert('config');
1000 $form->{title} = $locale->text("$form->{title} Language");
1002 # $locale->text('Add Language')
1003 # $locale->text('Edit Language')
1005 $form->{description} =~ s/\"/"/g;
1006 $form->{template_code} =~ s/\"/"/g;
1007 $form->{article_code} =~ s/\"/"/g;
1013 qq|<option value="">| . $locale->text("use program settings") .
1015 foreach my $item (('1,000.00', '1000.00', '1.000,00', '1000,00')) {
1017 ($item eq $form->{output_numberformat})
1018 ? "<option selected>$item"
1024 qq|<option value="">| . $locale->text("use program settings") .
1026 foreach my $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
1028 ($item eq $form->{output_dateformat})
1029 ? "<option selected>$item"
1037 <form method=post action=am.pl>
1039 <input type=hidden name=id value=$form->{id}>
1040 <input type=hidden name=type value=language>
1044 <th class=listtop colspan=2>$form->{title}</th>
1046 <tr height="5"></tr>
1048 <th align=right>| . $locale->text('Language') . qq|</th>
1049 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1052 <th align=right>| . $locale->text('Template Code') . qq|</th>
1053 <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
1056 <th align=right>| . $locale->text('Article Code') . qq|</th>
1057 <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
1060 <th align=right>| . $locale->text('Number Format') . qq|</th>
1061 <td><select name="output_numberformat">$numberformat</select></td>
1064 <th align=right>| . $locale->text('Date Format') . qq|</th>
1065 <td><select name="output_dateformat">$dateformat</select></td>
1068 <th align=right>| . $locale->text('Long Dates') . qq|</th>
1069 <td><input type="radio" name="output_longdates" value="1"| .
1070 ($form->{output_longdates} ? " checked" : "") .
1071 qq|>| . $locale->text("Yes") .
1072 qq|<input type="radio" name="output_longdates" value="0"| .
1073 ($form->{output_longdates} ? "" : " checked") .
1074 qq|>| . $locale->text("No") .
1077 <td colspan=2><hr size=3 noshade></td>
1082 $main::lxdebug->leave_sub();
1086 $main::lxdebug->enter_sub();
1088 my $form = $main::form;
1089 my %myconfig = %main::myconfig;
1090 my $locale = $main::locale;
1092 $main::auth->assert('config');
1094 $form->isblank("description", $locale->text('Language missing!'));
1095 $form->isblank("template_code", $locale->text('Template Code missing!'));
1096 $form->isblank("article_code", $locale->text('Article Code missing!'));
1097 AM->save_language(\%myconfig, \%$form);
1098 $form->redirect($locale->text('Language saved!'));
1100 $main::lxdebug->leave_sub();
1103 sub delete_language {
1104 $main::lxdebug->enter_sub();
1106 my $form = $main::form;
1107 my %myconfig = %main::myconfig;
1108 my $locale = $main::locale;
1110 $main::auth->assert('config');
1112 AM->delete_language(\%myconfig, \%$form);
1113 $form->redirect($locale->text('Language deleted!'));
1115 $main::lxdebug->leave_sub();
1119 sub add_buchungsgruppe {
1120 $main::lxdebug->enter_sub();
1122 my $form = $main::form;
1123 my %myconfig = %main::myconfig;
1124 my $locale = $main::locale;
1126 $main::auth->assert('config');
1128 # $locale->text("Add Buchungsgruppe")
1129 # $locale->text("Edit Buchungsgruppe")
1130 $form->{title} = "Add";
1132 $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
1134 AM->get_buchungsgruppe(\%myconfig, \%$form);
1135 $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
1136 for (my $i = 0; 4 > $i; $i++) {
1137 map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
1138 qw(income expense));
1141 &buchungsgruppe_header;
1144 $main::lxdebug->leave_sub();
1147 sub edit_buchungsgruppe {
1148 $main::lxdebug->enter_sub();
1150 my $form = $main::form;
1151 my %myconfig = %main::myconfig;
1153 $main::auth->assert('config');
1155 $form->{title} = "Edit";
1157 AM->get_buchungsgruppe(\%myconfig, \%$form);
1159 &buchungsgruppe_header;
1163 $main::lxdebug->leave_sub();
1166 sub list_buchungsgruppe {
1167 $main::lxdebug->enter_sub();
1169 my $form = $main::form;
1170 my %myconfig = %main::myconfig;
1171 my $locale = $main::locale;
1173 $main::auth->assert('config');
1175 AM->buchungsgruppe(\%myconfig, \%$form);
1177 $form->{callback} = "am.pl?action=list_buchungsgruppe";
1179 my $callback = $form->escape($form->{callback});
1181 $form->{title} = $locale->text('Buchungsgruppen');
1183 my @column_index = qw(up down description inventory_accno
1184 income_accno_0 expense_accno_0
1185 income_accno_1 expense_accno_1
1186 income_accno_2 expense_accno_2
1187 income_accno_3 expense_accno_3 );
1189 $column_header{up} =
1190 qq|<th class="listheading" width="16">|
1191 . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
1193 $column_header{down} =
1194 qq|<th class="listheading" width="16">|
1195 . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
1197 $column_header{description} =
1198 qq|<th class="listheading" width="40%">|
1199 . $locale->text('Description')
1201 $column_header{inventory_accno} =
1202 qq|<th class=listheading>|
1203 . $locale->text('Bestandskonto')
1205 $column_header{income_accno_0} =
1206 qq|<th class=listheading>|
1207 . $locale->text('National Revenues')
1209 $column_header{expense_accno_0} =
1210 qq|<th class=listheading>|
1211 . $locale->text('National Expenses')
1213 $column_header{income_accno_1} =
1214 qq|<th class=listheading>|
1215 . $locale->text('Revenues EU with UStId')
1217 $column_header{expense_accno_1} =
1218 qq|<th class=listheading>|
1219 . $locale->text('Expenses EU with UStId')
1221 $column_header{income_accno_2} =
1222 qq|<th class=listheading>|
1223 . $locale->text('Revenues EU without UStId')
1225 $column_header{expense_accno_2} =
1226 qq|<th class=listheading>|
1227 . $locale->text('Expenses EU without UStId')
1229 $column_header{income_accno_3} =
1230 qq|<th class=listheading>|
1231 . $locale->text('Foreign Revenues')
1233 $column_header{expense_accno_3} =
1234 qq|<th class=listheading>|
1235 . $locale->text('Foreign Expenses')
1244 <th class=listtop>$form->{title}</th>
1246 <tr height="5"></tr>
1250 <tr class=listheading>
1253 map { print "$column_header{$_}\n" } @column_index;
1259 my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
1262 my ($i, %column_data);
1263 foreach my $ref (@{ $form->{ALL} }) {
1269 <tr valign=top class=listrow$i>
1273 my $pref = $form->{ALL}->[$row - 1];
1275 qq|<td align="center" valign="center" width="16">| .
1276 qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
1277 qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
1280 $column_data{up} = qq|<td width="16"> </td>|;
1283 if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
1284 $column_data{down} = qq|<td width="16"> </td>|;
1286 my $nref = $form->{ALL}->[$row + 1];
1287 $column_data{down} =
1288 qq|<td align="center" valign="center" width="16">| .
1289 qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
1290 qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
1294 $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
1295 $column_data{inventory_accno} = qq|<td align=right>$ref->{inventory_accno}</td>|;
1296 $column_data{income_accno_0} =
1297 qq|<td align=right>$ref->{income_accno_0}</td>|;
1298 $column_data{expense_accno_0} = qq|<td align=right>$ref->{expense_accno_0}</td>|;
1299 $column_data{income_accno_1} =
1300 qq|<td align=right>$ref->{income_accno_1}</td>|;
1301 $column_data{expense_accno_1} = qq|<td align=right>$ref->{expense_accno_1}</td>|;
1302 $column_data{income_accno_2} =
1303 qq|<td align=right>$ref->{income_accno_2}</td>|;
1304 $column_data{expense_accno_2} = qq|<td align=right>$ref->{expense_accno_2}</td>|;
1305 $column_data{income_accno_3} =
1306 qq|<td align=right>$ref->{income_accno_3}</td>|;
1307 $column_data{expense_accno_3} = qq|<td align=right>$ref->{expense_accno_3}</td>|;
1309 map { print "$column_data{$_}\n" } @column_index;
1323 <td><hr size=3 noshade></td>
1328 <form method=post action=am.pl>
1330 <input name=callback type=hidden value="$form->{callback}">
1332 <input type=hidden name=type value=buchungsgruppe>
1334 <input class=submit type=submit name=action value="|
1335 . $locale->text('Add') . qq|">
1343 $main::lxdebug->leave_sub();
1346 sub buchungsgruppe_header {
1347 $main::lxdebug->enter_sub();
1349 my $form = $main::form;
1350 my $locale = $main::locale;
1352 $main::auth->assert('config');
1354 $form->{title} = $locale->text("$form->{title} Buchungsgruppe");
1356 # $locale->text('Add Accounting Group')
1357 # $locale->text('Edit Accounting Group')
1359 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
1360 my %acc_type_map = (
1361 "IC" => $acc_inventory,
1362 "IC_income" => $acc_income,
1363 "IC_sale" => $acc_income,
1364 "IC_expense" => $acc_expense,
1365 "IC_cogs" => $acc_expense,
1368 foreach my $key (keys(%acc_type_map)) {
1369 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1370 $acc_type_map{$key}->{$ref->{"id"}} = $ref;
1374 foreach my $type (qw(IC IC_income IC_expense)) {
1375 $form->{"select$type"} =
1377 map({ "<option value=$_->{id} $_->{selected}>" .
1378 "$_->{accno}--" . H($_->{description}) . "</option>" }
1379 sort({ $a->{"accno"} cmp $b->{"accno"} }
1380 values(%{$acc_type_map{$type}}))));
1384 $form->{selectIC} =~ s/selected//g;
1385 $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/ value=$form->{inventory_accno_id} selected/;
1386 $form->{selectIC_income} =~ s/selected//g;
1387 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/ value=$form->{income_accno_id_0} selected/;
1388 $form->{selectIC_expense} =~ s/selected//g;
1389 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/ value=$form->{expense_accno_id_0} selected/;
1393 if ( $::instance_conf->get_inventory_system eq 'perpetual' ) { # was !$::lx_office_conf{system}->{eur}) {
1396 <th align=right>| . $locale->text('Inventory') . qq|</th>
1397 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
1398 <input name=selectIC type=hidden value="$form->{selectIC}">
1400 } elsif ( $::instance_conf->get_inventory_system eq 'periodic' ) {
1401 # don't allow choice of inventory accno and don't show that line
1403 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
1407 $linkaccounts .= qq|
1409 <th align=right>| . $locale->text('National Revenues') . qq|</th>
1410 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
1413 <th align=right>| . $locale->text('National Expenses') . qq|</th>
1414 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
1417 $form->{selectIC_income} =~ s/selected//g;
1418 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/ value=$form->{income_accno_id_1} selected/;
1419 $form->{selectIC_expense} =~ s/selected//g;
1420 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/ value=$form->{expense_accno_id_1} selected/;
1422 $linkaccounts .= qq| <tr>
1423 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
1424 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
1427 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
1428 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
1432 $form->{selectIC_income} =~ s/selected//g;
1433 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/ value=$form->{income_accno_id_2} selected/;
1434 $form->{selectIC_expense} =~ s/selected//g;
1435 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/ value=$form->{expense_accno_id_2} selected/;
1438 $linkaccounts .= qq| <tr>
1439 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
1440 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
1443 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
1444 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
1448 $form->{selectIC_income} =~ s/selected//g;
1449 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/ value=$form->{income_accno_id_3} selected/;
1450 $form->{selectIC_expense} =~ s/selected//g;
1451 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/ value=$form->{expense_accno_id_3} selected/;
1454 $linkaccounts .= qq| <tr>
1455 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
1456 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
1459 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
1460 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
1470 <form method=post action=am.pl>
1472 <input type=hidden name=id value=$form->{id}>
1473 <input type=hidden name=type value=buchungsgruppe>
1477 <th class=listtop colspan=2>$form->{title}</th>
1479 <tr height="5"></tr>
1481 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
1482 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1485 <td colspan=2><hr size=3 noshade></td>
1490 $main::lxdebug->leave_sub();
1493 sub save_buchungsgruppe {
1494 $main::lxdebug->enter_sub();
1496 my $form = $main::form;
1497 my %myconfig = %main::myconfig;
1498 my $locale = $main::locale;
1500 $main::auth->assert('config');
1502 $form->isblank("description", $locale->text('Description missing!'));
1504 AM->save_buchungsgruppe(\%myconfig, \%$form);
1505 $form->redirect($locale->text('Accounting Group saved!'));
1507 $main::lxdebug->leave_sub();
1510 sub delete_buchungsgruppe {
1511 $main::lxdebug->enter_sub();
1513 my $form = $main::form;
1514 my %myconfig = %main::myconfig;
1515 my $locale = $main::locale;
1517 $main::auth->assert('config');
1519 AM->delete_buchungsgruppe(\%myconfig, \%$form);
1520 $form->redirect($locale->text('Accounting Group deleted!'));
1522 $main::lxdebug->leave_sub();
1525 sub swap_buchungsgruppen {
1526 $main::lxdebug->enter_sub();
1528 my $form = $main::form;
1529 my %myconfig = %main::myconfig;
1531 $main::auth->assert('config');
1533 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
1534 list_buchungsgruppe();
1536 $main::lxdebug->leave_sub();
1540 $main::lxdebug->enter_sub();
1542 my $form = $main::form;
1543 my %myconfig = %main::myconfig;
1544 my $locale = $main::locale;
1546 # get defaults for account numbers and last numbers
1547 AM->defaultaccounts(\%myconfig, \%$form);
1548 $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
1550 map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
1553 my $all_languages = SL::DB::Manager::Language->get_all;
1555 # EÜR = cash, Bilanzierung = accrual
1557 foreach my $key (keys %{ $form->{IC} }) {
1558 foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
1559 my $array = "ACCNOS_" . uc($key);
1560 $form->{$array} ||= [];
1562 my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
1563 push @{ $form->{$array} }, {
1566 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
1571 $form->{title} = $locale->text('Ranges of numbers and default accounts');
1574 print $form->parse_html_template('am/edit_defaults',
1575 { ALL_LANGUAGES => $all_languages, });
1577 $main::lxdebug->leave_sub();
1581 $main::lxdebug->enter_sub();
1583 my $form = $main::form;
1584 my $locale = $main::locale;
1586 AM->save_defaults();
1588 $form->redirect($locale->text('Defaults saved.'));
1590 $main::lxdebug->leave_sub();
1593 sub _build_cfg_options {
1594 my $form = $main::form;
1595 my %myconfig = %main::myconfig;
1598 my $array = uc($idx) . 'S';
1600 $form->{$array} = [];
1601 foreach my $item (@_) {
1602 push @{ $form->{$array} }, {
1605 'selected' => $item eq $myconfig{$idx},
1611 $main::lxdebug->enter_sub();
1613 my $form = $main::form;
1614 my %myconfig = %main::myconfig;
1615 my $locale = $main::locale;
1617 _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
1618 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
1621 if ($::lx_office_conf{print_templates}->{opendocument}
1622 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
1623 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
1624 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
1625 "value" => "opendocument_pdf" });
1627 if ($::lx_office_conf{print_templates}->{latex}) {
1628 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
1630 push(@formats, { "name" => "HTML", "value" => "html" });
1631 if ($::lx_office_conf{print_templates}->{latex}) {
1632 push(@formats, { "name" => $locale->text("Postscript"),
1633 "value" => "postscript" });
1635 if ($::lx_office_conf{print_templates}->{opendocument}) {
1636 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
1637 "value" => "opendocument" });
1640 if (!$myconfig{"template_format"}) {
1641 $myconfig{"template_format"} = "pdf";
1643 $form->{TEMPLATE_FORMATS} = [];
1644 foreach my $item (@formats) {
1645 push @{ $form->{TEMPLATE_FORMATS} }, {
1646 'name' => $item->{name},
1647 'value' => $item->{value},
1648 'selected' => $item->{value} eq $myconfig{template_format},
1652 if (!$myconfig{"default_media"}) {
1653 $myconfig{"default_media"} = "screen";
1656 my %selected = ($myconfig{"default_media"} => "selected");
1658 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
1659 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
1660 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
1663 $form->{PRINTERS} = [];
1664 foreach my $printer (SL::Printer->all_printers(%::myconfig)) {
1665 push @{ $form->{PRINTERS} }, {
1666 'name' => $printer->{printer_description},
1667 'value' => $printer->{id},
1668 'selected' => $printer->{id} == $myconfig{default_printer_id},
1672 my %countrycodes = User->country_codes;
1674 $form->{COUNTRYCODES} = [];
1675 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
1676 push @{ $form->{COUNTRYCODES} }, {
1677 'name' => $countrycodes{$countrycode},
1678 'value' => $countrycode,
1679 'selected' => $countrycode eq $myconfig{countrycode},
1683 $form->{STYLESHEETS} = [];
1684 foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
1685 push @{ $form->{STYLESHEETS} }, {
1688 'selected' => $item eq $myconfig{stylesheet},
1692 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
1693 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
1694 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
1696 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
1699 print $form->parse_html_template('am/config');
1701 $main::lxdebug->leave_sub();
1704 sub save_preferences {
1705 $main::lxdebug->enter_sub();
1707 my $form = $main::form;
1708 my %myconfig = %main::myconfig;
1709 my $locale = $main::locale;
1711 $form->{stylesheet} = $form->{usestylesheet};
1713 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
1715 if (AM->save_preferences(\%myconfig, $form)) {
1716 if ($::auth->can_change_password()
1717 && defined $form->{new_password}
1718 && ($form->{new_password} ne '********')) {
1719 my $verifier = SL::Auth::PasswordPolicy->new;
1720 my $result = $verifier->verify($form->{new_password});
1722 if ($result != SL::Auth::PasswordPolicy->OK()) {
1723 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
1726 $::auth->change_password($form->{login}, $form->{new_password});
1728 $form->{password} = $form->{new_password};
1729 $::auth->set_session_value('password', $form->{password});
1730 $::auth->create_or_refresh_session();
1733 $form->redirect($locale->text('Preferences saved!'));
1736 $form->error($locale->text('Cannot save preferences!'));
1738 $main::lxdebug->leave_sub();
1742 $main::lxdebug->enter_sub();
1744 my $form = $main::form;
1745 my %myconfig = %main::myconfig;
1746 my $locale = $main::locale;
1748 $main::auth->assert('config');
1750 $form->{title} = $locale->text('Audit Control');
1752 AM->closedto(\%myconfig, \%$form);
1759 <form method=post action=am.pl>
1762 <tr><th class=listtop>$form->{title}</th></tr>
1763 <tr height="5"></tr>
1768 <th>| . $locale->text('Close Books up to') . qq|</th>
1769 <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
1779 <input type=hidden name=nextsub value=doclose>
1781 <input type=submit class=submit name=action value="|
1782 . $locale->text('Continue') . qq|">
1790 $main::lxdebug->leave_sub();
1794 $main::lxdebug->enter_sub();
1796 my $form = $main::form;
1797 my %myconfig = %main::myconfig;
1798 my $locale = $main::locale;
1800 $main::auth->assert('config');
1802 AM->closebooks(\%myconfig, \%$form);
1804 if ($form->{closedto}) {
1806 $locale->text('Books closed up to') . " "
1807 . $locale->date(\%myconfig, $form->{closedto}, 1));
1809 $form->redirect($locale->text('Books are open'));
1812 $main::lxdebug->leave_sub();
1816 $main::lxdebug->enter_sub();
1818 my $form = $main::form;
1819 my %myconfig = %main::myconfig;
1820 my $locale = $main::locale;
1822 $main::auth->assert('config');
1824 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1825 AM->units_in_use(\%myconfig, $form, $units);
1826 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1828 my @languages = AM->language(\%myconfig, $form, 1);
1830 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1833 foreach (@unit_list) {
1834 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1835 $_->{"UNITLANGUAGES"} = [];
1836 foreach my $lang (@languages) {
1837 push(@{ $_->{"UNITLANGUAGES"} },
1839 "unit" => $_->{"name"},
1840 "language_id" => $lang->{"id"},
1841 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1842 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1848 $units = AM->retrieve_units(\%myconfig, $form);
1849 my $ddbox = AM->unit_select_data($units, undef, 1);
1851 $form->{"title"} = $locale->text("Add and edit units");
1853 print($form->parse_html_template("am/edit_units",
1854 { "UNITS" => \@unit_list,
1855 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1856 "LANGUAGES" => \@languages,
1859 $main::lxdebug->leave_sub();
1863 $main::lxdebug->enter_sub();
1865 my $form = $main::form;
1866 my %myconfig = %main::myconfig;
1867 my $locale = $main::locale;
1869 $main::auth->assert('config');
1871 $form->isblank("new_name", $locale->text("The name is missing."));
1872 my $units = AM->retrieve_units(\%myconfig, $form);
1873 my $all_units = AM->retrieve_units(\%myconfig, $form);
1874 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1876 my ($base_unit, $factor);
1877 if ($form->{"new_base_unit"}) {
1878 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1880 $form->isblank("new_factor", $locale->text("The factor is missing."));
1881 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1882 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1883 $base_unit = $form->{"new_base_unit"};
1887 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1888 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1889 push(@languages, { "id" => $lang->{"id"},
1890 "localized" => $form->{"new_localized_$lang->{id}"},
1891 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1895 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1897 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1901 $main::lxdebug->leave_sub();
1904 sub set_unit_languages {
1905 $main::lxdebug->enter_sub();
1907 my $form = $main::form;
1909 $main::auth->assert('config');
1911 my ($unit, $languages, $idx) = @_;
1913 $unit->{"LANGUAGES"} = [];
1915 foreach my $lang (@{$languages}) {
1916 push(@{ $unit->{"LANGUAGES"} },
1917 { "id" => $lang->{"id"},
1918 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1919 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1923 $main::lxdebug->leave_sub();
1927 $main::lxdebug->enter_sub();
1929 my $form = $main::form;
1930 my %myconfig = %main::myconfig;
1931 my $locale = $main::locale;
1933 $main::auth->assert('config');
1935 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1936 AM->units_in_use(\%myconfig, $form, $old_units);
1938 my @languages = AM->language(\%myconfig, $form, 1);
1941 my @delete_units = ();
1942 foreach my $i (1..($form->{"rowcount"} * 1)) {
1943 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1945 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1948 if ($form->{"unchangeable_$i"}) {
1949 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1950 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1951 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1955 if ($old_unit->{"in_use"}) {
1956 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1959 if ($form->{"delete_$i"}) {
1960 push(@delete_units, $old_unit->{"name"});
1964 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1966 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1967 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1968 $new_units->{$form->{"name_$i"}} = \%h;
1969 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1970 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1973 foreach my $unit (values(%{$new_units})) {
1974 next unless ($unit->{"old_name"});
1975 if ($unit->{"base_unit"}) {
1976 $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"}))
1977 unless (defined($new_units->{$unit->{"base_unit"}}));
1978 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1979 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1981 $unit->{"base_unit"} = undef;
1982 $unit->{"factor"} = undef;
1986 foreach my $unit (values(%{$new_units})) {
1987 next if ($unit->{"unchanged_unit"});
1989 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1990 my $new_unit = $unit;
1991 while ($new_unit->{"base_unit"}) {
1992 $new_unit->{"seen"} = 1;
1993 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1994 if ($new_unit->{"seen"}) {
1995 $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, " .
1996 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
2001 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
2003 $form->{"saved_message"} = $locale->text("The units have been saved.");
2007 $main::lxdebug->leave_sub();
2010 sub show_history_search {
2011 $main::lxdebug->enter_sub();
2013 my $form = $main::form;
2014 my $locale = $main::locale;
2016 $main::auth->assert('config');
2018 $form->{title} = $locale->text("History Search");
2021 print $form->parse_html_template("common/search_history");
2023 $main::lxdebug->leave_sub();
2026 sub show_am_history {
2027 $main::lxdebug->enter_sub();
2029 my $form = $main::form;
2030 my %myconfig = %main::myconfig;
2031 my $locale = $main::locale;
2033 $main::auth->assert('config');
2035 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
2036 $form->{order} ||= 'h.itime--1';
2038 my %search = ( "Artikelnummer" => "parts",
2039 "Kundennummer" => "customer",
2040 "Lieferantennummer" => "vendor",
2041 "Projektnummer" => "project",
2042 "Buchungsnummer" => "oe",
2043 "Eingangsrechnungnummer" => "ap",
2044 "Ausgangsrechnungnummer" => "ar",
2045 "Mahnungsnummer" => "dunning"
2047 my %searchNo = ( "Artikelnummer" => "partnumber",
2048 "Kundennummer" => "customernumber",
2049 "Lieferantennummer" => "vendornumber",
2050 "Projektnummer" => "projectnumber",
2051 "Buchungsnummer" => "ordnumber",
2052 "Eingangsrechnungnummer" => "invnumber",
2053 "Ausgangsrechnungnummer" => "invnumber",
2054 "Mahnungsnummer" => "dunning_id"
2057 my $dbh = $form->dbconnect(\%myconfig);
2059 my $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
2060 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
2061 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
2062 if ($form->{mitarbeiter} =~ m/^\d+$/) {
2063 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
2064 } elsif ($form->{mitarbeiter}) {
2065 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
2068 my $query = qq|SELECT trans_id AS id FROM history_erp | .
2069 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
2070 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
2072 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
2073 my $daten .= shift @ids;
2074 $daten .= join '', map { " OR trans_id = $_" } @ids;
2076 my ($sort, $sortby) = split(/\-\-/, $form->{order});
2077 $sort =~ s/.*\.(.*)$/$1/;
2079 $form->{title} = $locale->text("History Search");
2082 print $form->parse_html_template("common/show_history",
2083 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
2084 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
2087 uc($sort) . "BY" => $sortby,
2088 'callback' => $callback,
2092 $main::lxdebug->leave_sub();
2096 $main::lxdebug->enter_sub();
2098 my $form = $main::form;
2099 my $locale = $main::locale;
2101 $main::auth->assert('config');
2103 $form->{title} = $locale->text('Add');
2105 $form->{callback} ||= "am.pl?action=add_tax";
2107 _get_taxaccount_selection();
2111 my $parameters_ref = {
2112 # ChartTypeIsAccount => $ChartTypeIsAccount,
2115 # Ausgabe des Templates
2116 print($form->parse_html_template('am/edit_tax', $parameters_ref));
2118 $main::lxdebug->leave_sub();
2122 $main::lxdebug->enter_sub();
2124 my $form = $main::form;
2125 my %myconfig = %main::myconfig;
2126 my $locale = $main::locale;
2128 $main::auth->assert('config');
2130 $form->{title} = $locale->text('Edit');
2132 AM->get_tax(\%myconfig, \%$form);
2133 _get_taxaccount_selection();
2135 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
2139 my $parameters_ref = {
2142 # Ausgabe des Templates
2143 print($form->parse_html_template('am/edit_tax', $parameters_ref));
2145 $main::lxdebug->leave_sub();
2149 $main::lxdebug->enter_sub();
2151 my $form = $main::form;
2152 my %myconfig = %main::myconfig;
2153 my $locale = $main::locale;
2155 $main::auth->assert('config');
2157 AM->taxes(\%myconfig, \%$form);
2159 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
2161 $form->{callback} = build_std_url('action=list_tax');
2163 $form->{title} = $locale->text('Tax-O-Matic');
2167 my $parameters_ref = {
2170 # Ausgabe des Templates
2171 print($form->parse_html_template('am/list_tax', $parameters_ref));
2173 $main::lxdebug->leave_sub();
2176 sub _get_taxaccount_selection{
2177 $main::lxdebug->enter_sub();
2179 my $form = $main::form;
2180 my %myconfig = %main::myconfig;
2182 $main::auth->assert('config');
2184 AM->get_tax_accounts(\%myconfig, \%$form);
2186 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
2188 $main::lxdebug->leave_sub();
2192 $main::lxdebug->enter_sub();
2194 my $form = $main::form;
2195 my %myconfig = %main::myconfig;
2196 my $locale = $main::locale;
2198 $main::auth->assert('config');
2200 $form->isblank("rate", $locale->text('Taxrate missing!'));
2201 $form->isblank("taxdescription", $locale->text('Taxdescription missing!'));
2202 $form->isblank("taxkey", $locale->text('Taxkey missing!'));
2204 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
2206 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
2207 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
2210 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
2211 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
2214 AM->save_tax(\%myconfig, \%$form);
2215 $form->redirect($locale->text('Tax saved!'));
2217 $main::lxdebug->leave_sub();
2221 $main::lxdebug->enter_sub();
2223 my $form = $main::form;
2224 my %myconfig = %main::myconfig;
2225 my $locale = $main::locale;
2227 $main::auth->assert('config');
2229 AM->delete_tax(\%myconfig, \%$form);
2230 $form->redirect($locale->text('Tax deleted!'));
2232 $main::lxdebug->leave_sub();
2235 sub add_price_factor {
2236 $main::lxdebug->enter_sub();
2238 my $form = $main::form;
2239 my $locale = $main::locale;
2241 $main::auth->assert('config');
2243 $form->{title} = $locale->text('Add Price Factor');
2244 $form->{callback} ||= build_std_url('action=add_price_factor');
2245 $form->{fokus} = 'description';
2248 print $form->parse_html_template('am/edit_price_factor');
2250 $main::lxdebug->leave_sub();
2253 sub edit_price_factor {
2254 $main::lxdebug->enter_sub();
2256 my $form = $main::form;
2257 my %myconfig = %main::myconfig;
2258 my $locale = $main::locale;
2260 $main::auth->assert('config');
2262 $form->{title} = $locale->text('Edit Price Factor');
2263 $form->{callback} ||= build_std_url('action=add_price_factor');
2264 $form->{fokus} = 'description';
2266 AM->get_price_factor(\%myconfig, $form);
2268 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
2271 print $form->parse_html_template('am/edit_price_factor');
2273 $main::lxdebug->leave_sub();
2276 sub list_price_factors {
2277 $main::lxdebug->enter_sub();
2279 my $form = $main::form;
2280 my %myconfig = %main::myconfig;
2281 my $locale = $main::locale;
2283 $main::auth->assert('config');
2285 AM->get_all_price_factors(\%myconfig, \%$form);
2287 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
2288 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
2291 $form->{callback} = build_std_url('action=list_price_factors');
2292 $form->{title} = $locale->text('Price Factors');
2293 $form->{url_base} = build_std_url('callback');
2296 print $form->parse_html_template('am/list_price_factors');
2298 $main::lxdebug->leave_sub();
2301 sub save_price_factor {
2302 $main::lxdebug->enter_sub();
2304 my $form = $main::form;
2305 my %myconfig = %main::myconfig;
2306 my $locale = $main::locale;
2308 $main::auth->assert('config');
2310 $form->isblank("description", $locale->text('Description missing!'));
2311 $form->isblank("factor", $locale->text('Factor missing!'));
2313 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
2315 AM->save_price_factor(\%myconfig, $form);
2317 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
2319 $form->redirect($locale->text('Price factor saved!'));
2321 $main::lxdebug->leave_sub();
2324 sub delete_price_factor {
2325 $main::lxdebug->enter_sub();
2327 my $form = $main::form;
2328 my %myconfig = %main::myconfig;
2329 my $locale = $main::locale;
2331 $main::auth->assert('config');
2333 AM->delete_price_factor(\%myconfig, \%$form);
2335 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
2337 $form->redirect($locale->text('Price factor deleted!'));
2339 $main::lxdebug->leave_sub();
2343 $main::lxdebug->enter_sub();
2345 my $form = $main::form;
2346 my $locale = $main::locale;
2348 $main::auth->assert('config');
2350 $form->{title} = $locale->text('Add Warehouse');
2351 $form->{callback} ||= build_std_url('action=add_warehouse');
2352 $form->{fokus} = 'description';
2355 print $form->parse_html_template('am/edit_warehouse');
2357 $main::lxdebug->leave_sub();
2360 sub edit_warehouse {
2361 $main::lxdebug->enter_sub();
2363 my $form = $main::form;
2364 my %myconfig = %main::myconfig;
2365 my $locale = $main::locale;
2367 $main::auth->assert('config');
2369 AM->get_warehouse(\%myconfig, $form);
2371 $form->get_lists('employees' => 'EMPLOYEES');
2373 $form->{title} = $locale->text('Edit Warehouse');
2374 $form->{callback} ||= build_std_url('action=list_warehouses');
2375 $form->{fokus} = 'description';
2378 print $form->parse_html_template('am/edit_warehouse');
2380 $main::lxdebug->leave_sub();
2383 sub list_warehouses {
2384 $main::lxdebug->enter_sub();
2386 my $form = $main::form;
2387 my %myconfig = %main::myconfig;
2388 my $locale = $main::locale;
2390 $main::auth->assert('config');
2392 AM->get_all_warehouses(\%myconfig, $form);
2394 $form->{callback} = build_std_url('action=list_warehouses');
2395 $form->{title} = $locale->text('Warehouses');
2396 $form->{url_base} = build_std_url('callback');
2399 print $form->parse_html_template('am/list_warehouses');
2401 $main::lxdebug->leave_sub();
2404 sub save_warehouse {
2405 $main::lxdebug->enter_sub();
2407 my $form = $main::form;
2408 my %myconfig = %main::myconfig;
2409 my $locale = $main::locale;
2411 $main::auth->assert('config');
2413 $form->isblank("description", $locale->text('Description missing!'));
2415 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
2417 AM->save_warehouse(\%myconfig, $form);
2419 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
2421 $form->redirect($locale->text('Warehouse saved.'));
2423 $main::lxdebug->leave_sub();
2426 sub delete_warehouse {
2427 $main::lxdebug->enter_sub();
2429 my $form = $main::form;
2430 my %myconfig = %main::myconfig;
2431 my $locale = $main::locale;
2433 $main::auth->assert('config');
2435 if (!$form->{confirmed}) {
2436 $form->{title} = $locale->text('Confirmation');
2439 print $form->parse_html_template('am/confirm_delete_warehouse');
2443 if (AM->delete_warehouse(\%myconfig, $form)) {
2444 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
2445 $form->redirect($locale->text('Warehouse deleted.'));
2448 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
2451 $main::lxdebug->leave_sub();
2455 $main::lxdebug->enter_sub();
2457 my $form = $main::form;
2458 my %myconfig = %main::myconfig;
2459 my $locale = $main::locale;
2461 $main::auth->assert('config');
2463 AM->save_bins(\%myconfig, $form);
2465 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
2467 $form->redirect($locale->text('Bins saved.'));
2469 $main::lxdebug->leave_sub();