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":"";
350 my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
354 my $parameters_ref = {
355 ChartTypeIsAccount => $ChartTypeIsAccount,
356 AccountIsPosted => $AccountIsPosted,
357 select_category => $select_category,
358 select_charttype => $select_charttype,
359 select_bwa => $select_bwa,
360 select_bilanz => $select_bilanz,
361 select_eur => $select_eur,
364 # Ausgabe des Templates
365 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
368 $main::lxdebug->leave_sub();
372 $main::lxdebug->enter_sub();
374 my $form = $main::form;
375 my $locale = $main::locale;
377 $main::auth->assert('config');
381 <input name=callback type=hidden value="| . H($form->{callback}) . qq|">
384 if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) {
386 <input type=submit class=submit name=action value="|
387 . $locale->text('Save') . qq|">
391 if ($form->{id} && $form->{orphaned}) {
392 print qq|<input type=submit class=submit name=action value="|
393 . $locale->text('Delete') . qq|">|;
396 if ($form->{id} && $form->{type} eq "account") {
398 <input class=submit type=submit name=action value="|
399 . $locale->text('Save as new') . qq|">|;
409 $main::lxdebug->leave_sub();
413 $main::lxdebug->enter_sub();
415 my $form = $main::form;
416 my %myconfig = %main::myconfig;
417 my $locale = $main::locale;
419 $main::auth->assert('config');
421 $form->isblank("accno", $locale->text('Account Number missing!'));
422 $form->isblank("description", $locale->text('Account Description missing!'));
424 if ($form->{charttype} eq 'A'){
425 $form->isblank("category", $locale->text('Account Type missing!'));
428 $form->redirect($locale->text('Account saved!'))
429 if (AM->save_account(\%myconfig, \%$form));
430 $form->error($locale->text('Cannot save account!'));
432 $main::lxdebug->leave_sub();
435 sub save_as_new_account {
436 $main::lxdebug->enter_sub();
438 my $form = $main::form;
439 my %myconfig = %main::myconfig;
440 my $locale = $main::locale;
442 $main::auth->assert('config');
444 $form->isblank("accno", $locale->text('Account Number missing!'));
445 $form->isblank("description", $locale->text('Account Description missing!'));
447 if ($form->{charttype} eq 'A'){
448 $form->isblank("category", $locale->text('Account Type missing!'));
451 for my $taxkey (0 .. 9) {
452 if ($form->{"taxkey_id_$taxkey"}) {
453 $form->{"taxkey_id_$taxkey"} = "NEW";
458 if ($form->{"original_accno"} &&
459 ($form->{"accno"} eq $form->{"original_accno"})) {
460 $form->error($locale->text('Account Number already used!'));
462 $form->redirect($locale->text('Account saved!'))
463 if (AM->save_account(\%myconfig, \%$form));
464 $form->error($locale->text('Cannot save account!'));
466 $main::lxdebug->leave_sub();
470 $main::lxdebug->enter_sub();
472 my $form = $main::form;
473 my %myconfig = %main::myconfig;
474 my $locale = $main::locale;
476 $main::auth->assert('config');
478 $form->{callback} = build_std_url('action=list_account');
479 my $link_edit_account = build_std_url('action=edit_account', 'callback');
481 CA->all_accounts(\%myconfig, \%$form);
483 foreach my $ca (@{ $form->{CA} }) {
488 if ($ca->{amount} > 0) {
489 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
491 if ($ca->{amount} < 0) {
492 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
494 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
495 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
499 my $pjx = new CGI::Ajax('list_account_details' => build_std_url('action=list_account_details'));
501 # Eneable AJAX debuging
505 push(@ { $form->{AJAX} }, $pjx);
507 $form->use_stylesheet("list_accounts.css");
508 $form->{title} = $locale->text('Chart of Accounts');
513 my $parameters_ref = {
514 # hidden_variables => $_hidden_variables_ref,
517 # Ausgabe des Templates
518 print($form->parse_html_template('am/list_accounts', $parameters_ref));
520 $main::lxdebug->leave_sub();
525 sub list_account_details {
526 # Ajax Funktion aus list_account_details
527 $main::lxdebug->enter_sub();
529 my $form = $main::form;
530 my %myconfig = %main::myconfig;
531 my $locale = $main::locale;
533 $main::auth->assert('config');
535 my $chart_id = $form->{args};
537 CA->all_accounts(\%myconfig, \%$form, $chart_id);
539 foreach my $ca (@{ $form->{CA} }) {
541 $ca->{debit} = " ";
542 $ca->{credit} = " ";
544 if ($ca->{amount} > 0) {
546 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
548 if ($ca->{amount} < 0) {
550 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
553 my @links = split( q{:}, $ca->{link});
557 foreach my $link (@links){
558 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
559 : ( $link eq 'AP') ? $locale->text('Account Link AP')
560 : ( $link eq 'IC') ? $locale->text('Account Link IC')
561 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
562 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
563 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
564 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
565 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
566 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
567 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
568 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
569 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
570 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
571 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
572 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
573 # : ( $link eq 'CT_tax' ) ? $locale->text('Account Link CT_tax')
574 : $locale->text('Unknown Link') . ': ' . $link;
575 $ca->{link} .= ($link ne '') ? "[$link] ":'';
578 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
579 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
580 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
581 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
582 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
583 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
584 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
585 : $locale->text('Unknown Category') . ': ' . $ca->{category};
588 $form->{title} = $locale->text('Chart of Accounts');
591 print $form->parse_html_template('am/list_account_details');
593 $main::lxdebug->leave_sub();
598 $main::lxdebug->enter_sub();
600 my $form = $main::form;
601 my %myconfig = %main::myconfig;
602 my $locale = $main::locale;
604 $main::auth->assert('config');
606 $form->{title} = $locale->text('Delete Account');
609 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
611 if ($form->{id} == $form->{$id}) {
612 $form->error($locale->text('Cannot delete default account!'));
616 $form->redirect($locale->text('Account deleted!'))
617 if (AM->delete_account(\%myconfig, \%$form));
618 $form->error($locale->text('Cannot delete account!'));
620 $main::lxdebug->leave_sub();
624 $main::lxdebug->enter_sub();
626 my $form = $main::form;
628 $main::auth->assert('config');
630 $form->{title} = "Add";
632 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
637 $main::lxdebug->leave_sub();
641 $main::lxdebug->enter_sub();
643 my $form = $main::form;
644 my %myconfig = %main::myconfig;
646 $main::auth->assert('config');
648 $form->{title} = "Edit";
650 AM->get_lead(\%myconfig, \%$form);
654 $form->{orphaned} = 1;
657 $main::lxdebug->leave_sub();
661 $main::lxdebug->enter_sub();
663 my $form = $main::form;
664 my %myconfig = %main::myconfig;
665 my $locale = $main::locale;
667 $main::auth->assert('config');
669 AM->lead(\%myconfig, \%$form);
671 $form->{callback} = "am.pl?action=list_lead";
673 my $callback = $form->escape($form->{callback});
675 $form->{title} = $locale->text('Lead');
677 my @column_index = qw(description cost profit);
679 $column_header{description} =
680 qq|<th class=listheading width=100%>|
681 . $locale->text('Description')
691 <th class=listtop>$form->{title}</th>
694 <tr class=listheading>
697 map { print "$column_header{$_}\n" } @column_index;
703 my ($i, %column_data);
704 foreach my $ref (@{ $form->{ALL} }) {
710 <tr valign=top class=listrow$i>
713 # $lead = $ref->{lead};
715 $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
717 map { print "$column_data{$_}\n" } @column_index;
726 <td><hr size=3 noshade></td>
731 <form method=post action=am.pl>
733 <input name=callback type=hidden value="$form->{callback}">
735 <input type=hidden name=type value=lead>
737 <input class=submit type=submit name=action value="|
738 . $locale->text('Add') . qq|">
746 $main::lxdebug->leave_sub();
750 $main::lxdebug->enter_sub();
752 my $form = $main::form;
753 my $locale = $main::locale;
755 $main::auth->assert('config');
757 $form->{title} = $locale->text("$form->{title} Lead");
759 # $locale->text('Add Lead')
760 # $locale->text('Edit Lead')
762 $form->{description} =~ s/\"/"/g;
765 qq|<input name=description size=50 value="$form->{lead}">|;
772 <form method=post action=am.pl>
774 <input type=hidden name=id value=$form->{id}>
775 <input type=hidden name=type value=lead>
779 <th class=listtop colspan=2>$form->{title}</th>
783 <th align=right>| . $locale->text('Description') . qq|</th>
784 <td>$description</td>
786 <td colspan=2><hr size=3 noshade></td>
791 $main::lxdebug->leave_sub();
795 $main::lxdebug->enter_sub();
797 my $form = $main::form;
798 my %myconfig = %main::myconfig;
799 my $locale = $main::locale;
801 $main::auth->assert('config');
803 $form->isblank("description", $locale->text('Description missing!'));
804 AM->save_lead(\%myconfig, \%$form);
805 $form->redirect($locale->text('lead saved!'));
807 $main::lxdebug->leave_sub();
811 $main::lxdebug->enter_sub();
813 my $form = $main::form;
814 my %myconfig = %main::myconfig;
815 my $locale = $main::locale;
817 $main::auth->assert('config');
819 AM->delete_lead(\%myconfig, \%$form);
820 $form->redirect($locale->text('lead deleted!'));
822 $main::lxdebug->leave_sub();
826 $main::lxdebug->enter_sub();
828 my $form = $main::form;
830 $main::auth->assert('config');
832 $form->{title} = "Add";
834 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
839 $main::lxdebug->leave_sub();
843 $main::lxdebug->enter_sub();
845 my $form = $main::form;
846 my %myconfig = %main::myconfig;
848 $main::auth->assert('config');
850 $form->{title} = "Edit";
852 AM->get_language(\%myconfig, \%$form);
856 $form->{orphaned} = 1;
859 $main::lxdebug->leave_sub();
863 $main::lxdebug->enter_sub();
865 my $form = $main::form;
866 my %myconfig = %main::myconfig;
867 my $locale = $main::locale;
869 $main::auth->assert('config');
871 AM->language(\%myconfig, \%$form);
873 $form->{callback} = "am.pl?action=list_language";
875 my $callback = $form->escape($form->{callback});
877 $form->{title} = $locale->text('Languages');
879 my @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
881 $column_header{description} =
882 qq|<th class=listheading width=60%>|
883 . $locale->text('Description')
885 $column_header{template_code} =
886 qq|<th class=listheading width=10%>|
887 . $locale->text('Template Code')
889 $column_header{article_code} =
890 qq|<th class=listheading>|
891 . $locale->text('Article Code')
893 $column_header{output_numberformat} =
894 qq|<th class=listheading>|
895 . $locale->text('Number Format')
897 $column_header{output_dateformat} =
898 qq|<th class=listheading>|
899 . $locale->text('Date Format')
901 $column_header{output_longdates} =
902 qq|<th class=listheading>|
903 . $locale->text('Long Dates')
913 <th class=listtop>$form->{title}</th>
919 <tr class=listheading>
922 map { print "$column_header{$_}\n" } @column_index;
928 my ($i, %column_data);
929 foreach my $ref (@{ $form->{ALL} }) {
935 <tr valign=top class=listrow$i>
939 $column_data{description} =
940 qq|<td><a href="am.pl?action=edit_language&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
941 $column_data{template_code} = qq|<td align=right>$ref->{template_code}</td>|;
942 $column_data{article_code} =
943 qq|<td align=right>$ref->{article_code}</td>|;
944 $column_data{output_numberformat} =
946 ($ref->{output_numberformat} ? $ref->{output_numberformat} :
947 $locale->text("use program settings")) .
949 $column_data{output_dateformat} =
951 ($ref->{output_dateformat} ? $ref->{output_dateformat} :
952 $locale->text("use program settings")) .
954 $column_data{output_longdates} =
956 ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
959 map { print "$column_data{$_}\n" } @column_index;
971 <td><hr size=3 noshade></td>
976 <form method=post action=am.pl>
978 <input name=callback type=hidden value="$form->{callback}">
980 <input type=hidden name=type value=language>
982 <input class=submit type=submit name=action value="|
983 . $locale->text('Add') . qq|">
991 $main::lxdebug->leave_sub();
994 sub language_header {
995 $main::lxdebug->enter_sub();
997 my $form = $main::form;
998 my $locale = $main::locale;
1000 $main::auth->assert('config');
1002 $form->{title} = $locale->text("$form->{title} Language");
1004 # $locale->text('Add Language')
1005 # $locale->text('Edit Language')
1007 $form->{description} =~ s/\"/"/g;
1008 $form->{template_code} =~ s/\"/"/g;
1009 $form->{article_code} =~ s/\"/"/g;
1015 qq|<option value="">| . $locale->text("use program settings") .
1017 foreach my $item (('1,000.00', '1000.00', '1.000,00', '1000,00')) {
1019 ($item eq $form->{output_numberformat})
1020 ? "<option selected>$item"
1026 qq|<option value="">| . $locale->text("use program settings") .
1028 foreach my $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
1030 ($item eq $form->{output_dateformat})
1031 ? "<option selected>$item"
1039 <form method=post action=am.pl>
1041 <input type=hidden name=id value=$form->{id}>
1042 <input type=hidden name=type value=language>
1046 <th class=listtop colspan=2>$form->{title}</th>
1048 <tr height="5"></tr>
1050 <th align=right>| . $locale->text('Language') . qq|</th>
1051 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1054 <th align=right>| . $locale->text('Template Code') . qq|</th>
1055 <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
1058 <th align=right>| . $locale->text('Article Code') . qq|</th>
1059 <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
1062 <th align=right>| . $locale->text('Number Format') . qq|</th>
1063 <td><select name="output_numberformat">$numberformat</select></td>
1066 <th align=right>| . $locale->text('Date Format') . qq|</th>
1067 <td><select name="output_dateformat">$dateformat</select></td>
1070 <th align=right>| . $locale->text('Long Dates') . qq|</th>
1071 <td><input type="radio" name="output_longdates" value="1"| .
1072 ($form->{output_longdates} ? " checked" : "") .
1073 qq|>| . $locale->text("Yes") .
1074 qq|<input type="radio" name="output_longdates" value="0"| .
1075 ($form->{output_longdates} ? "" : " checked") .
1076 qq|>| . $locale->text("No") .
1079 <td colspan=2><hr size=3 noshade></td>
1084 $main::lxdebug->leave_sub();
1088 $main::lxdebug->enter_sub();
1090 my $form = $main::form;
1091 my %myconfig = %main::myconfig;
1092 my $locale = $main::locale;
1094 $main::auth->assert('config');
1096 $form->isblank("description", $locale->text('Language missing!'));
1097 $form->isblank("template_code", $locale->text('Template Code missing!'));
1098 $form->isblank("article_code", $locale->text('Article Code missing!'));
1099 AM->save_language(\%myconfig, \%$form);
1100 $form->redirect($locale->text('Language saved!'));
1102 $main::lxdebug->leave_sub();
1105 sub delete_language {
1106 $main::lxdebug->enter_sub();
1108 my $form = $main::form;
1109 my %myconfig = %main::myconfig;
1110 my $locale = $main::locale;
1112 $main::auth->assert('config');
1114 AM->delete_language(\%myconfig, \%$form);
1115 $form->redirect($locale->text('Language deleted!'));
1117 $main::lxdebug->leave_sub();
1121 sub add_buchungsgruppe {
1122 $main::lxdebug->enter_sub();
1124 my $form = $main::form;
1125 my %myconfig = %main::myconfig;
1126 my $locale = $main::locale;
1128 $main::auth->assert('config');
1130 # $locale->text("Add Buchungsgruppe")
1131 # $locale->text("Edit Buchungsgruppe")
1132 $form->{title} = "Add";
1134 $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
1136 AM->get_buchungsgruppe(\%myconfig, \%$form);
1137 $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
1138 for (my $i = 0; 4 > $i; $i++) {
1139 map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
1140 qw(income expense));
1143 &buchungsgruppe_header;
1146 $main::lxdebug->leave_sub();
1149 sub edit_buchungsgruppe {
1150 $main::lxdebug->enter_sub();
1152 my $form = $main::form;
1153 my %myconfig = %main::myconfig;
1155 $main::auth->assert('config');
1157 $form->{title} = "Edit";
1159 AM->get_buchungsgruppe(\%myconfig, \%$form);
1161 &buchungsgruppe_header;
1165 $main::lxdebug->leave_sub();
1168 sub list_buchungsgruppe {
1169 $main::lxdebug->enter_sub();
1171 my $form = $main::form;
1172 my %myconfig = %main::myconfig;
1173 my $locale = $main::locale;
1175 $main::auth->assert('config');
1177 AM->buchungsgruppe(\%myconfig, \%$form);
1179 $form->{callback} = "am.pl?action=list_buchungsgruppe";
1181 my $callback = $form->escape($form->{callback});
1183 $form->{title} = $locale->text('Buchungsgruppen');
1185 my @column_index = qw(up down description inventory_accno
1186 income_accno_0 expense_accno_0
1187 income_accno_1 expense_accno_1
1188 income_accno_2 expense_accno_2
1189 income_accno_3 expense_accno_3 );
1191 $column_header{up} =
1192 qq|<th class="listheading" width="16">|
1193 . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
1195 $column_header{down} =
1196 qq|<th class="listheading" width="16">|
1197 . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
1199 $column_header{description} =
1200 qq|<th class="listheading" width="40%">|
1201 . $locale->text('Description')
1203 $column_header{inventory_accno} =
1204 qq|<th class=listheading>|
1205 . $locale->text('Bestandskonto')
1207 $column_header{income_accno_0} =
1208 qq|<th class=listheading>|
1209 . $locale->text('National Revenues')
1211 $column_header{expense_accno_0} =
1212 qq|<th class=listheading>|
1213 . $locale->text('National Expenses')
1215 $column_header{income_accno_1} =
1216 qq|<th class=listheading>|
1217 . $locale->text('Revenues EU with UStId')
1219 $column_header{expense_accno_1} =
1220 qq|<th class=listheading>|
1221 . $locale->text('Expenses EU with UStId')
1223 $column_header{income_accno_2} =
1224 qq|<th class=listheading>|
1225 . $locale->text('Revenues EU without UStId')
1227 $column_header{expense_accno_2} =
1228 qq|<th class=listheading>|
1229 . $locale->text('Expenses EU without UStId')
1231 $column_header{income_accno_3} =
1232 qq|<th class=listheading>|
1233 . $locale->text('Foreign Revenues')
1235 $column_header{expense_accno_3} =
1236 qq|<th class=listheading>|
1237 . $locale->text('Foreign Expenses')
1246 <th class=listtop>$form->{title}</th>
1248 <tr height="5"></tr>
1252 <tr class=listheading>
1255 map { print "$column_header{$_}\n" } @column_index;
1261 my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
1264 my ($i, %column_data);
1265 foreach my $ref (@{ $form->{ALL} }) {
1271 <tr valign=top class=listrow$i>
1275 my $pref = $form->{ALL}->[$row - 1];
1277 qq|<td align="center" valign="center" width="16">| .
1278 qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
1279 qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
1282 $column_data{up} = qq|<td width="16"> </td>|;
1285 if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
1286 $column_data{down} = qq|<td width="16"> </td>|;
1288 my $nref = $form->{ALL}->[$row + 1];
1289 $column_data{down} =
1290 qq|<td align="center" valign="center" width="16">| .
1291 qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
1292 qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
1296 $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
1297 $column_data{inventory_accno} = qq|<td align=right>$ref->{inventory_accno}</td>|;
1298 $column_data{income_accno_0} =
1299 qq|<td align=right>$ref->{income_accno_0}</td>|;
1300 $column_data{expense_accno_0} = qq|<td align=right>$ref->{expense_accno_0}</td>|;
1301 $column_data{income_accno_1} =
1302 qq|<td align=right>$ref->{income_accno_1}</td>|;
1303 $column_data{expense_accno_1} = qq|<td align=right>$ref->{expense_accno_1}</td>|;
1304 $column_data{income_accno_2} =
1305 qq|<td align=right>$ref->{income_accno_2}</td>|;
1306 $column_data{expense_accno_2} = qq|<td align=right>$ref->{expense_accno_2}</td>|;
1307 $column_data{income_accno_3} =
1308 qq|<td align=right>$ref->{income_accno_3}</td>|;
1309 $column_data{expense_accno_3} = qq|<td align=right>$ref->{expense_accno_3}</td>|;
1311 map { print "$column_data{$_}\n" } @column_index;
1325 <td><hr size=3 noshade></td>
1330 <form method=post action=am.pl>
1332 <input name=callback type=hidden value="$form->{callback}">
1334 <input type=hidden name=type value=buchungsgruppe>
1336 <input class=submit type=submit name=action value="|
1337 . $locale->text('Add') . qq|">
1345 $main::lxdebug->leave_sub();
1348 sub buchungsgruppe_header {
1349 $main::lxdebug->enter_sub();
1351 my $form = $main::form;
1352 my $locale = $main::locale;
1354 $main::auth->assert('config');
1356 $form->{title} = $locale->text("$form->{title} Buchungsgruppe");
1358 # $locale->text('Add Accounting Group')
1359 # $locale->text('Edit Accounting Group')
1361 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
1362 my %acc_type_map = (
1363 "IC" => $acc_inventory,
1364 "IC_income" => $acc_income,
1365 "IC_sale" => $acc_income,
1366 "IC_expense" => $acc_expense,
1367 "IC_cogs" => $acc_expense,
1370 foreach my $key (keys(%acc_type_map)) {
1371 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1372 $acc_type_map{$key}->{$ref->{"id"}} = $ref;
1376 foreach my $type (qw(IC IC_income IC_expense)) {
1377 $form->{"select$type"} =
1379 map({ "<option value=$_->{id} $_->{selected}>" .
1380 "$_->{accno}--" . H($_->{description}) . "</option>" }
1381 sort({ $a->{"accno"} cmp $b->{"accno"} }
1382 values(%{$acc_type_map{$type}}))));
1386 $form->{selectIC} =~ s/selected//g;
1387 $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/ value=$form->{inventory_accno_id} selected/;
1388 $form->{selectIC_income} =~ s/selected//g;
1389 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/ value=$form->{income_accno_id_0} selected/;
1390 $form->{selectIC_expense} =~ s/selected//g;
1391 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/ value=$form->{expense_accno_id_0} selected/;
1395 if ( $::instance_conf->get_inventory_system eq 'perpetual' ) { # was !$::lx_office_conf{system}->{eur}) {
1398 <th align=right>| . $locale->text('Inventory') . qq|</th>
1399 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
1400 <input name=selectIC type=hidden value="$form->{selectIC}">
1402 } elsif ( $::instance_conf->get_inventory_system eq 'periodic' ) {
1403 # don't allow choice of inventory accno and don't show that line
1405 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
1409 $linkaccounts .= qq|
1411 <th align=right>| . $locale->text('National Revenues') . qq|</th>
1412 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
1415 <th align=right>| . $locale->text('National Expenses') . qq|</th>
1416 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
1419 $form->{selectIC_income} =~ s/selected//g;
1420 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/ value=$form->{income_accno_id_1} selected/;
1421 $form->{selectIC_expense} =~ s/selected//g;
1422 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/ value=$form->{expense_accno_id_1} selected/;
1424 $linkaccounts .= qq| <tr>
1425 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
1426 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
1429 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
1430 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
1434 $form->{selectIC_income} =~ s/selected//g;
1435 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/ value=$form->{income_accno_id_2} selected/;
1436 $form->{selectIC_expense} =~ s/selected//g;
1437 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/ value=$form->{expense_accno_id_2} selected/;
1440 $linkaccounts .= qq| <tr>
1441 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
1442 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
1445 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
1446 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
1450 $form->{selectIC_income} =~ s/selected//g;
1451 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/ value=$form->{income_accno_id_3} selected/;
1452 $form->{selectIC_expense} =~ s/selected//g;
1453 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/ value=$form->{expense_accno_id_3} selected/;
1456 $linkaccounts .= qq| <tr>
1457 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
1458 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
1461 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
1462 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
1472 <form method=post action=am.pl>
1474 <input type=hidden name=id value=$form->{id}>
1475 <input type=hidden name=type value=buchungsgruppe>
1479 <th class=listtop colspan=2>$form->{title}</th>
1481 <tr height="5"></tr>
1483 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
1484 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1487 <td colspan=2><hr size=3 noshade></td>
1492 $main::lxdebug->leave_sub();
1495 sub save_buchungsgruppe {
1496 $main::lxdebug->enter_sub();
1498 my $form = $main::form;
1499 my %myconfig = %main::myconfig;
1500 my $locale = $main::locale;
1502 $main::auth->assert('config');
1504 $form->isblank("description", $locale->text('Description missing!'));
1506 AM->save_buchungsgruppe(\%myconfig, \%$form);
1507 $form->redirect($locale->text('Accounting Group saved!'));
1509 $main::lxdebug->leave_sub();
1512 sub delete_buchungsgruppe {
1513 $main::lxdebug->enter_sub();
1515 my $form = $main::form;
1516 my %myconfig = %main::myconfig;
1517 my $locale = $main::locale;
1519 $main::auth->assert('config');
1521 AM->delete_buchungsgruppe(\%myconfig, \%$form);
1522 $form->redirect($locale->text('Accounting Group deleted!'));
1524 $main::lxdebug->leave_sub();
1527 sub swap_buchungsgruppen {
1528 $main::lxdebug->enter_sub();
1530 my $form = $main::form;
1531 my %myconfig = %main::myconfig;
1533 $main::auth->assert('config');
1535 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
1536 list_buchungsgruppe();
1538 $main::lxdebug->leave_sub();
1542 $main::lxdebug->enter_sub();
1544 my $form = $main::form;
1545 my %myconfig = %main::myconfig;
1546 my $locale = $main::locale;
1548 # get defaults for account numbers and last numbers
1549 AM->defaultaccounts(\%myconfig, \%$form);
1550 $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
1552 map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
1555 my $all_languages = SL::DB::Manager::Language->get_all;
1557 # EÜR = cash, Bilanzierung = accrual
1559 foreach my $key (keys %{ $form->{IC} }) {
1560 foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
1561 my $array = "ACCNOS_" . uc($key);
1562 $form->{$array} ||= [];
1564 my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
1565 push @{ $form->{$array} }, {
1568 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
1573 $form->{title} = $locale->text('Ranges of numbers and default accounts');
1576 print $form->parse_html_template('am/edit_defaults',
1577 { ALL_LANGUAGES => $all_languages, });
1579 $main::lxdebug->leave_sub();
1583 $main::lxdebug->enter_sub();
1585 my $form = $main::form;
1586 my $locale = $main::locale;
1588 AM->save_defaults();
1590 $form->redirect($locale->text('Defaults saved.'));
1592 $main::lxdebug->leave_sub();
1595 sub _build_cfg_options {
1596 my $form = $main::form;
1597 my %myconfig = %main::myconfig;
1600 my $array = uc($idx) . 'S';
1602 $form->{$array} = [];
1603 foreach my $item (@_) {
1604 push @{ $form->{$array} }, {
1607 'selected' => $item eq $myconfig{$idx},
1613 $main::lxdebug->enter_sub();
1615 my $form = $main::form;
1616 my %myconfig = %main::myconfig;
1617 my $locale = $main::locale;
1619 _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
1620 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
1623 if ($::lx_office_conf{print_templates}->{opendocument}
1624 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
1625 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
1626 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
1627 "value" => "opendocument_pdf" });
1629 if ($::lx_office_conf{print_templates}->{latex}) {
1630 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
1632 push(@formats, { "name" => "HTML", "value" => "html" });
1633 if ($::lx_office_conf{print_templates}->{latex}) {
1634 push(@formats, { "name" => $locale->text("Postscript"),
1635 "value" => "postscript" });
1637 if ($::lx_office_conf{print_templates}->{opendocument}) {
1638 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
1639 "value" => "opendocument" });
1642 if (!$myconfig{"template_format"}) {
1643 $myconfig{"template_format"} = "pdf";
1645 $form->{TEMPLATE_FORMATS} = [];
1646 foreach my $item (@formats) {
1647 push @{ $form->{TEMPLATE_FORMATS} }, {
1648 'name' => $item->{name},
1649 'value' => $item->{value},
1650 'selected' => $item->{value} eq $myconfig{template_format},
1654 if (!$myconfig{"default_media"}) {
1655 $myconfig{"default_media"} = "screen";
1658 my %selected = ($myconfig{"default_media"} => "selected");
1660 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
1661 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
1662 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
1665 $form->{PRINTERS} = [ SL::Printer->all_printers(%::myconfig) ];
1667 my %countrycodes = User->country_codes;
1669 $form->{COUNTRYCODES} = [];
1670 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
1671 push @{ $form->{COUNTRYCODES} }, {
1672 'name' => $countrycodes{$countrycode},
1673 'value' => $countrycode,
1674 'selected' => $countrycode eq $myconfig{countrycode},
1678 $form->{STYLESHEETS} = [];
1679 foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
1680 push @{ $form->{STYLESHEETS} }, {
1683 'selected' => $item eq $myconfig{stylesheet},
1687 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
1688 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
1689 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
1691 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
1694 print $form->parse_html_template('am/config');
1696 $main::lxdebug->leave_sub();
1699 sub save_preferences {
1700 $main::lxdebug->enter_sub();
1702 my $form = $main::form;
1703 my %myconfig = %main::myconfig;
1704 my $locale = $main::locale;
1706 $form->{stylesheet} = $form->{usestylesheet};
1708 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
1710 if (AM->save_preferences(\%myconfig, $form)) {
1711 if ($::auth->can_change_password()
1712 && defined $form->{new_password}
1713 && ($form->{new_password} ne '********')) {
1714 my $verifier = SL::Auth::PasswordPolicy->new;
1715 my $result = $verifier->verify($form->{new_password});
1717 if ($result != SL::Auth::PasswordPolicy->OK()) {
1718 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
1721 $::auth->change_password($form->{login}, $form->{new_password});
1723 $form->{password} = $form->{new_password};
1724 $::auth->set_session_value('password', $form->{password});
1725 $::auth->create_or_refresh_session();
1728 $form->redirect($locale->text('Preferences saved!'));
1731 $form->error($locale->text('Cannot save preferences!'));
1733 $main::lxdebug->leave_sub();
1737 $main::lxdebug->enter_sub();
1739 my $form = $main::form;
1740 my %myconfig = %main::myconfig;
1741 my $locale = $main::locale;
1743 $main::auth->assert('config');
1745 $form->{title} = $locale->text('Audit Control');
1747 AM->closedto(\%myconfig, \%$form);
1754 <form method=post action=am.pl>
1757 <tr><th class=listtop>$form->{title}</th></tr>
1758 <tr height="5"></tr>
1763 <th>| . $locale->text('Close Books up to') . qq|</th>
1764 <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
1774 <input type=hidden name=nextsub value=doclose>
1776 <input type=submit class=submit name=action value="|
1777 . $locale->text('Continue') . qq|">
1785 $main::lxdebug->leave_sub();
1789 $main::lxdebug->enter_sub();
1791 my $form = $main::form;
1792 my %myconfig = %main::myconfig;
1793 my $locale = $main::locale;
1795 $main::auth->assert('config');
1797 AM->closebooks(\%myconfig, \%$form);
1799 if ($form->{closedto}) {
1801 $locale->text('Books closed up to') . " "
1802 . $locale->date(\%myconfig, $form->{closedto}, 1));
1804 $form->redirect($locale->text('Books are open'));
1807 $main::lxdebug->leave_sub();
1811 $main::lxdebug->enter_sub();
1813 my $form = $main::form;
1814 my %myconfig = %main::myconfig;
1815 my $locale = $main::locale;
1817 $main::auth->assert('config');
1819 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1820 AM->units_in_use(\%myconfig, $form, $units);
1821 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1823 my @languages = AM->language(\%myconfig, $form, 1);
1825 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1828 foreach (@unit_list) {
1829 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1830 $_->{"UNITLANGUAGES"} = [];
1831 foreach my $lang (@languages) {
1832 push(@{ $_->{"UNITLANGUAGES"} },
1834 "unit" => $_->{"name"},
1835 "language_id" => $lang->{"id"},
1836 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1837 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1843 $units = AM->retrieve_units(\%myconfig, $form);
1844 my $ddbox = AM->unit_select_data($units, undef, 1);
1846 $form->{"title"} = $locale->text("Add and edit units");
1848 print($form->parse_html_template("am/edit_units",
1849 { "UNITS" => \@unit_list,
1850 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1851 "LANGUAGES" => \@languages,
1854 $main::lxdebug->leave_sub();
1858 $main::lxdebug->enter_sub();
1860 my $form = $main::form;
1861 my %myconfig = %main::myconfig;
1862 my $locale = $main::locale;
1864 $main::auth->assert('config');
1866 $form->isblank("new_name", $locale->text("The name is missing."));
1867 my $units = AM->retrieve_units(\%myconfig, $form);
1868 my $all_units = AM->retrieve_units(\%myconfig, $form);
1869 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1871 my ($base_unit, $factor);
1872 if ($form->{"new_base_unit"}) {
1873 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1875 $form->isblank("new_factor", $locale->text("The factor is missing."));
1876 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1877 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1878 $base_unit = $form->{"new_base_unit"};
1882 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1883 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1884 push(@languages, { "id" => $lang->{"id"},
1885 "localized" => $form->{"new_localized_$lang->{id}"},
1886 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1890 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1892 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1896 $main::lxdebug->leave_sub();
1899 sub set_unit_languages {
1900 $main::lxdebug->enter_sub();
1902 my $form = $main::form;
1904 $main::auth->assert('config');
1906 my ($unit, $languages, $idx) = @_;
1908 $unit->{"LANGUAGES"} = [];
1910 foreach my $lang (@{$languages}) {
1911 push(@{ $unit->{"LANGUAGES"} },
1912 { "id" => $lang->{"id"},
1913 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1914 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1918 $main::lxdebug->leave_sub();
1922 $main::lxdebug->enter_sub();
1924 my $form = $main::form;
1925 my %myconfig = %main::myconfig;
1926 my $locale = $main::locale;
1928 $main::auth->assert('config');
1930 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1931 AM->units_in_use(\%myconfig, $form, $old_units);
1933 my @languages = AM->language(\%myconfig, $form, 1);
1936 my @delete_units = ();
1937 foreach my $i (1..($form->{"rowcount"} * 1)) {
1938 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1940 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1943 if ($form->{"unchangeable_$i"}) {
1944 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1945 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1946 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1950 if ($old_unit->{"in_use"}) {
1951 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1954 if ($form->{"delete_$i"}) {
1955 push(@delete_units, $old_unit->{"name"});
1959 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1961 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1962 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1963 $new_units->{$form->{"name_$i"}} = \%h;
1964 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1965 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1968 foreach my $unit (values(%{$new_units})) {
1969 next unless ($unit->{"old_name"});
1970 if ($unit->{"base_unit"}) {
1971 $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"}))
1972 unless (defined($new_units->{$unit->{"base_unit"}}));
1973 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1974 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1976 $unit->{"base_unit"} = undef;
1977 $unit->{"factor"} = undef;
1981 foreach my $unit (values(%{$new_units})) {
1982 next if ($unit->{"unchanged_unit"});
1984 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1985 my $new_unit = $unit;
1986 while ($new_unit->{"base_unit"}) {
1987 $new_unit->{"seen"} = 1;
1988 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1989 if ($new_unit->{"seen"}) {
1990 $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, " .
1991 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1996 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1998 $form->{"saved_message"} = $locale->text("The units have been saved.");
2002 $main::lxdebug->leave_sub();
2005 sub show_history_search {
2006 $main::lxdebug->enter_sub();
2008 my $form = $main::form;
2009 my $locale = $main::locale;
2011 $main::auth->assert('config');
2013 $form->{title} = $locale->text("History Search");
2016 print $form->parse_html_template("common/search_history");
2018 $main::lxdebug->leave_sub();
2021 sub show_am_history {
2022 $main::lxdebug->enter_sub();
2024 my $form = $main::form;
2025 my %myconfig = %main::myconfig;
2026 my $locale = $main::locale;
2028 $main::auth->assert('config');
2030 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
2031 $form->{order} ||= 'h.itime--1';
2033 my %search = ( "Artikelnummer" => "parts",
2034 "Kundennummer" => "customer",
2035 "Lieferantennummer" => "vendor",
2036 "Projektnummer" => "project",
2037 "Buchungsnummer" => "oe",
2038 "Eingangsrechnungnummer" => "ap",
2039 "Ausgangsrechnungnummer" => "ar",
2040 "Mahnungsnummer" => "dunning"
2042 my %searchNo = ( "Artikelnummer" => "partnumber",
2043 "Kundennummer" => "customernumber",
2044 "Lieferantennummer" => "vendornumber",
2045 "Projektnummer" => "projectnumber",
2046 "Buchungsnummer" => "ordnumber",
2047 "Eingangsrechnungnummer" => "invnumber",
2048 "Ausgangsrechnungnummer" => "invnumber",
2049 "Mahnungsnummer" => "dunning_id"
2052 my $dbh = $form->dbconnect(\%myconfig);
2055 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
2056 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
2057 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
2058 if ($form->{mitarbeiter} =~ m/^\d+$/) {
2059 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
2060 } elsif ($form->{mitarbeiter}) {
2061 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
2064 my $query = qq|SELECT trans_id AS id FROM history_erp | .
2065 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
2066 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
2068 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
2069 my $daten .= shift @ids;
2070 $daten .= join '', map { " OR trans_id = $_" } @ids;
2072 my ($sort, $sortby) = split(/\-\-/, $form->{order});
2073 $sort =~ s/.*\.(.*)$/$1/;
2075 $form->{title} = $locale->text("History Search");
2078 print $form->parse_html_template("common/show_history",
2079 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
2080 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
2083 uc($sort) . "BY" => $sortby,
2084 'callback' => $callback,
2088 $main::lxdebug->leave_sub();
2092 $main::lxdebug->enter_sub();
2094 my $form = $main::form;
2095 my $locale = $main::locale;
2097 $main::auth->assert('config');
2099 $form->{title} = $locale->text('Add');
2101 $form->{callback} ||= "am.pl?action=add_tax";
2103 _get_taxaccount_selection();
2107 my $parameters_ref = {
2108 # ChartTypeIsAccount => $ChartTypeIsAccount,
2111 # Ausgabe des Templates
2112 print($form->parse_html_template('am/edit_tax', $parameters_ref));
2114 $main::lxdebug->leave_sub();
2118 $main::lxdebug->enter_sub();
2120 my $form = $main::form;
2121 my %myconfig = %main::myconfig;
2122 my $locale = $main::locale;
2124 $main::auth->assert('config');
2126 $form->{title} = $locale->text('Edit');
2128 AM->get_tax(\%myconfig, \%$form);
2129 _get_taxaccount_selection();
2131 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
2135 my $parameters_ref = {
2138 # Ausgabe des Templates
2139 print($form->parse_html_template('am/edit_tax', $parameters_ref));
2141 $main::lxdebug->leave_sub();
2145 $main::lxdebug->enter_sub();
2147 my $form = $main::form;
2148 my %myconfig = %main::myconfig;
2149 my $locale = $main::locale;
2151 $main::auth->assert('config');
2153 AM->taxes(\%myconfig, \%$form);
2155 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
2157 $form->{callback} = build_std_url('action=list_tax');
2159 $form->{title} = $locale->text('Tax-O-Matic');
2163 my $parameters_ref = {
2166 # Ausgabe des Templates
2167 print($form->parse_html_template('am/list_tax', $parameters_ref));
2169 $main::lxdebug->leave_sub();
2172 sub _get_taxaccount_selection{
2173 $main::lxdebug->enter_sub();
2175 my $form = $main::form;
2176 my %myconfig = %main::myconfig;
2178 $main::auth->assert('config');
2180 AM->get_tax_accounts(\%myconfig, \%$form);
2182 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
2184 $main::lxdebug->leave_sub();
2188 $main::lxdebug->enter_sub();
2190 my $form = $main::form;
2191 my %myconfig = %main::myconfig;
2192 my $locale = $main::locale;
2194 $main::auth->assert('config');
2196 $form->isblank("rate", $locale->text('Taxrate missing!'));
2197 $form->isblank("taxdescription", $locale->text('Taxdescription missing!'));
2198 $form->isblank("taxkey", $locale->text('Taxkey missing!'));
2200 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
2202 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
2203 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
2206 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
2207 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
2210 AM->save_tax(\%myconfig, \%$form);
2211 $form->redirect($locale->text('Tax saved!'));
2213 $main::lxdebug->leave_sub();
2217 $main::lxdebug->enter_sub();
2219 my $form = $main::form;
2220 my %myconfig = %main::myconfig;
2221 my $locale = $main::locale;
2223 $main::auth->assert('config');
2225 AM->delete_tax(\%myconfig, \%$form);
2226 $form->redirect($locale->text('Tax deleted!'));
2228 $main::lxdebug->leave_sub();
2231 sub add_price_factor {
2232 $main::lxdebug->enter_sub();
2234 my $form = $main::form;
2235 my $locale = $main::locale;
2237 $main::auth->assert('config');
2239 $form->{title} = $locale->text('Add Price Factor');
2240 $form->{callback} ||= build_std_url('action=add_price_factor');
2241 $form->{fokus} = 'description';
2244 print $form->parse_html_template('am/edit_price_factor');
2246 $main::lxdebug->leave_sub();
2249 sub edit_price_factor {
2250 $main::lxdebug->enter_sub();
2252 my $form = $main::form;
2253 my %myconfig = %main::myconfig;
2254 my $locale = $main::locale;
2256 $main::auth->assert('config');
2258 $form->{title} = $locale->text('Edit Price Factor');
2259 $form->{callback} ||= build_std_url('action=add_price_factor');
2260 $form->{fokus} = 'description';
2262 AM->get_price_factor(\%myconfig, $form);
2264 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
2267 print $form->parse_html_template('am/edit_price_factor');
2269 $main::lxdebug->leave_sub();
2272 sub list_price_factors {
2273 $main::lxdebug->enter_sub();
2275 my $form = $main::form;
2276 my %myconfig = %main::myconfig;
2277 my $locale = $main::locale;
2279 $main::auth->assert('config');
2281 AM->get_all_price_factors(\%myconfig, \%$form);
2283 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
2284 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
2287 $form->{callback} = build_std_url('action=list_price_factors');
2288 $form->{title} = $locale->text('Price Factors');
2289 $form->{url_base} = build_std_url('callback');
2292 print $form->parse_html_template('am/list_price_factors');
2294 $main::lxdebug->leave_sub();
2297 sub save_price_factor {
2298 $main::lxdebug->enter_sub();
2300 my $form = $main::form;
2301 my %myconfig = %main::myconfig;
2302 my $locale = $main::locale;
2304 $main::auth->assert('config');
2306 $form->isblank("description", $locale->text('Description missing!'));
2307 $form->isblank("factor", $locale->text('Factor missing!'));
2309 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
2311 AM->save_price_factor(\%myconfig, $form);
2313 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
2315 $form->redirect($locale->text('Price factor saved!'));
2317 $main::lxdebug->leave_sub();
2320 sub delete_price_factor {
2321 $main::lxdebug->enter_sub();
2323 my $form = $main::form;
2324 my %myconfig = %main::myconfig;
2325 my $locale = $main::locale;
2327 $main::auth->assert('config');
2329 AM->delete_price_factor(\%myconfig, \%$form);
2331 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
2333 $form->redirect($locale->text('Price factor deleted!'));
2335 $main::lxdebug->leave_sub();
2339 $main::lxdebug->enter_sub();
2341 my $form = $main::form;
2342 my $locale = $main::locale;
2344 $main::auth->assert('config');
2346 $form->{title} = $locale->text('Add Warehouse');
2347 $form->{callback} ||= build_std_url('action=add_warehouse');
2348 $form->{fokus} = 'description';
2351 print $form->parse_html_template('am/edit_warehouse');
2353 $main::lxdebug->leave_sub();
2356 sub edit_warehouse {
2357 $main::lxdebug->enter_sub();
2359 my $form = $main::form;
2360 my %myconfig = %main::myconfig;
2361 my $locale = $main::locale;
2363 $main::auth->assert('config');
2365 AM->get_warehouse(\%myconfig, $form);
2367 $form->get_lists('employees' => 'EMPLOYEES');
2369 $form->{title} = $locale->text('Edit Warehouse');
2370 $form->{callback} ||= build_std_url('action=list_warehouses');
2371 $form->{fokus} = 'description';
2374 print $form->parse_html_template('am/edit_warehouse');
2376 $main::lxdebug->leave_sub();
2379 sub list_warehouses {
2380 $main::lxdebug->enter_sub();
2382 my $form = $main::form;
2383 my %myconfig = %main::myconfig;
2384 my $locale = $main::locale;
2386 $main::auth->assert('config');
2388 AM->get_all_warehouses(\%myconfig, $form);
2390 $form->{callback} = build_std_url('action=list_warehouses');
2391 $form->{title} = $locale->text('Warehouses');
2392 $form->{url_base} = build_std_url('callback');
2395 print $form->parse_html_template('am/list_warehouses');
2397 $main::lxdebug->leave_sub();
2400 sub save_warehouse {
2401 $main::lxdebug->enter_sub();
2403 my $form = $main::form;
2404 my %myconfig = %main::myconfig;
2405 my $locale = $main::locale;
2407 $main::auth->assert('config');
2409 $form->isblank("description", $locale->text('Description missing!'));
2411 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
2413 AM->save_warehouse(\%myconfig, $form);
2415 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
2417 $form->redirect($locale->text('Warehouse saved.'));
2419 $main::lxdebug->leave_sub();
2422 sub delete_warehouse {
2423 $main::lxdebug->enter_sub();
2425 my $form = $main::form;
2426 my %myconfig = %main::myconfig;
2427 my $locale = $main::locale;
2429 $main::auth->assert('config');
2431 if (!$form->{confirmed}) {
2432 $form->{title} = $locale->text('Confirmation');
2435 print $form->parse_html_template('am/confirm_delete_warehouse');
2439 if (AM->delete_warehouse(\%myconfig, $form)) {
2440 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
2441 $form->redirect($locale->text('Warehouse deleted.'));
2444 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
2447 $main::lxdebug->leave_sub();
2451 $main::lxdebug->enter_sub();
2453 my $form = $main::form;
2454 my %myconfig = %main::myconfig;
2455 my $locale = $main::locale;
2457 $main::auth->assert('config');
2459 AM->save_bins(\%myconfig, $form);
2461 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
2463 $form->redirect($locale->text('Bins saved.'));
2465 $main::lxdebug->leave_sub();