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;
48 require "bin/mozilla/common.pl";
56 sub add { call_sub("add_$main::form->{type}"); }
57 sub delete { call_sub("delete_$main::form->{type}"); }
58 sub save { call_sub("save_$main::form->{type}"); }
59 sub edit { call_sub("edit_$main::form->{type}"); }
60 sub continue { call_sub($main::form->{"nextsub"}); }
61 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
64 $main::lxdebug->enter_sub();
66 my $form = $main::form;
67 my %myconfig = %main::myconfig;
69 $main::auth->assert('config');
71 $form->{title} = "Add";
72 $form->{charttype} = "A";
73 AM->get_account(\%myconfig, \%$form);
75 $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
80 $main::lxdebug->leave_sub();
84 $main::lxdebug->enter_sub();
86 my $form = $main::form;
87 my %myconfig = %main::myconfig;
89 $main::auth->assert('config');
91 $form->{title} = "Edit";
92 AM->get_account(\%myconfig, \%$form);
94 foreach my $item (split(/:/, $form->{link})) {
95 $form->{$item} = "checked";
101 $main::lxdebug->leave_sub();
105 $main::lxdebug->enter_sub();
107 my $form = $main::form;
108 my %myconfig = %main::myconfig;
109 my $locale = $main::locale;
111 $main::auth->assert('config');
113 if ( $form->{action} eq 'edit_account') {
114 $form->{account_exists} = '1';
117 $form->{title} = $locale->text("$form->{title} Account");
119 $form->{"$form->{charttype}_checked"} = "checked";
120 $form->{"$form->{category}_checked"} = "checked";
122 $form->{select_tax} = "";
124 my @tax_report_pos = USTVA->report_variables({
125 myconfig => \%myconfig,
128 attribute => 'position',
132 if (@{ $form->{TAXKEY} }) {
133 foreach my $item (@{ $form->{TAXKEY} }) {
134 $item->{rate} = $item->{rate} * 100 . '%';
137 # Fill in empty row for new Taxkey
138 my $newtaxkey_ref = {
143 taxdescription => '',
150 push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
153 foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
155 # Fill in a runningnumber
156 $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
158 # Fill in the Taxkeys as select options
159 foreach my $item (@{ $form->{TAXKEY} }) {
160 if ($item->{id} == $taxkey_used->{tax_id}) {
161 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
162 qq|<option value="$item->{id}" selected="selected">|
163 . sprintf("%.2d", $item->{taxkey})
164 . qq|. $item->{taxdescription} ($item->{rate}) |
165 . $locale->text('Tax-o-matic Account')
166 . qq|: $item->{chart_accno}\n|;
169 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
170 qq|<option value="$item->{id}">|
171 . sprintf("%.2d", $item->{taxkey})
172 . qq|. $item->{taxdescription} ($item->{rate}) |
173 . $locale->text('Tax-o-matic Account')
174 . qq|: $item->{chart_accno}\n|;
179 # Fill in the USTVA Numbers as select options
180 foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
182 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
184 elsif ( $item eq $taxkey_used->{pos_ustva} ) {
185 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
188 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
197 # Newaccount Folgekonto
198 if (@{ $form->{NEWACCOUNT} || [] }) {
199 if (!$form->{new_chart_valid}) {
200 $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
202 foreach my $item (@{ $form->{NEWACCOUNT} }) {
203 if ($item->{id} == $form->{new_chart_id}) {
204 $form->{selectnewaccount} .=
205 qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
206 } elsif (!$form->{new_chart_valid}) {
207 $form->{selectnewaccount} .=
208 qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
214 my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
217 2 => "sonstige Erlöse",
218 3 => "Privatanteile",
220 5 => "Ausserordentliche Erträge",
221 6 => "Vereinnahmte Umsatzst.",
222 7 => "Umsatzsteuererstattungen",
223 8 => "Wareneingänge",
224 9 => "Löhne und Gehälter",
225 10 => "Gesetzl. sozialer Aufw.",
227 12 => "Gas, Strom, Wasser",
228 13 => "Instandhaltung",
229 14 => "Steuern, Versich., Beiträge",
231 16 => "Kfz-Versicherungen",
232 17 => "Sonst. Fahrzeugkosten",
233 18 => "Werbe- und Reisekosten",
234 19 => "Instandhaltung u. Werkzeuge",
235 20 => "Fachzeitschriften, Bücher",
236 21 => "Miete für Einrichtungen",
237 22 => "Rechts- und Beratungskosten",
238 23 => "Bürobedarf, Porto, Telefon",
239 24 => "Sonstige Aufwendungen",
240 25 => "Abschreibungen auf Anlagever.",
241 26 => "Abschreibungen auf GWG",
243 28 => "Umsatzsteuerzahlungen",
245 30 => "Ausserordentlicher Aufwand",
246 31 => "Betriebliche Steuern");
247 foreach my $item (sort({ $a <=> $b } keys(%eur))) {
248 my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
249 if ($item == $form->{pos_eur}) {
250 $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
252 $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
257 my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
261 2 => 'Best.Verdg.FE/UE',
262 3 => 'Aktiv.Eigenleistung',
263 4 => 'Mat./Wareneinkauf',
264 5 => 'So.betr.Erlöse',
265 10 => 'Personalkosten',
267 12 => 'Betriebl.Steuern',
268 13 => 'Vers./Beiträge',
269 14 => 'Kfz.Kosten o.St.',
270 15 => 'Werbe-Reisek.',
271 16 => 'Kosten Warenabgabe',
272 17 => 'Abschreibungen',
273 18 => 'Rep./instandhlt.',
274 19 => 'Übrige Steuern',
275 20 => 'Sonst.Kosten',
277 31 => 'Sonst.neutr.Aufw.',
279 33 => 'Sonst.neutr.Ertrag',
280 34 => 'Verr.kalk.Kosten',
281 35 => 'Steuern Eink.u.Ertr.');
282 foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
283 my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
284 if ($item == $form->{pos_bwa}) {
285 $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
287 $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
292 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
293 my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
294 foreach my $item ((1, 2, 3, 4)) {
295 if ($item == $form->{pos_bilanz}) {
296 $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
298 $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
303 # this is for our parser only! Do not remove.
304 # type=submit $locale->text('Add Account')
305 # type=submit $locale->text('Edit Account')
307 $form->{type} = "account";
309 # preselections category
311 my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
314 'A' => $locale->text('Asset'),
315 'L' => $locale->text('Liability'),
316 'Q' => $locale->text('Equity'),
317 'I' => $locale->text('Revenue'),
318 'E' => $locale->text('Expense'),
319 'C' => $locale->text('Costs'),
321 foreach my $item ( sort({ $a <=> $b } keys %category) ) {
322 if ($item eq $form->{category}) {
323 $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
325 $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
330 # preselection chart type
331 my $select_charttype = q{};
334 'A' => $locale->text('Account'),
335 'H' => $locale->text('Heading'),
338 foreach my $item ( sort({ $a <=> $b } keys %charttype) ) {
339 if ($item eq $form->{charttype}) {
340 $select_charttype .= qq|<option value="$item" selected="selected">$charttype{$item}\n|;
343 $select_charttype .= qq|<option value="$item">$charttype{$item}\n|;
348 # account where AR_tax or AP_tax is set are not orphaned if they are used as
349 # tax-o-matic account
350 if ( $form->{id} && !$form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
351 if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
352 $form->{orphaned} = 0;
356 my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
357 my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
361 my $parameters_ref = {
362 ChartTypeIsAccount => $ChartTypeIsAccount,
363 AccountIsPosted => $AccountIsPosted,
364 select_category => $select_category,
365 select_charttype => $select_charttype,
366 select_bwa => $select_bwa,
367 select_bilanz => $select_bilanz,
368 select_eur => $select_eur,
371 # Ausgabe des Templates
372 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
375 $main::lxdebug->leave_sub();
379 $main::lxdebug->enter_sub();
381 my $form = $main::form;
382 my $locale = $main::locale;
384 $main::auth->assert('config');
388 <input name=callback type=hidden value="| . H($form->{callback}) . qq|">
391 if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) {
393 <input type=submit class=submit name=action value="|
394 . $locale->text('Save') . qq|">
398 if ($form->{id} && $form->{orphaned}) {
399 print qq|<input type=submit class=submit name=action value="|
400 . $locale->text('Delete') . qq|">|;
403 if ($form->{id} && $form->{type} eq "account") {
405 <input class=submit type=submit name=action value="|
406 . $locale->text('Save as new') . qq|">|;
416 $main::lxdebug->leave_sub();
420 $main::lxdebug->enter_sub();
422 my $form = $main::form;
423 my %myconfig = %main::myconfig;
424 my $locale = $main::locale;
426 $main::auth->assert('config');
428 $form->isblank("accno", $locale->text('Account Number missing!'));
429 $form->isblank("description", $locale->text('Account Description missing!'));
431 if ($form->{charttype} eq 'A'){
432 $form->isblank("category", $locale->text('Account Type missing!'));
435 $form->redirect($locale->text('Account saved!'))
436 if (AM->save_account(\%myconfig, \%$form));
437 $form->error($locale->text('Cannot save account!'));
439 $main::lxdebug->leave_sub();
442 sub save_as_new_account {
443 $main::lxdebug->enter_sub();
445 my $form = $main::form;
446 my %myconfig = %main::myconfig;
447 my $locale = $main::locale;
449 $main::auth->assert('config');
451 $form->isblank("accno", $locale->text('Account Number missing!'));
452 $form->isblank("description", $locale->text('Account Description missing!'));
454 if ($form->{charttype} eq 'A'){
455 $form->isblank("category", $locale->text('Account Type missing!'));
458 for my $taxkey (0 .. 9) {
459 if ($form->{"taxkey_id_$taxkey"}) {
460 $form->{"taxkey_id_$taxkey"} = "NEW";
465 if ($form->{"original_accno"} &&
466 ($form->{"accno"} eq $form->{"original_accno"})) {
467 $form->error($locale->text('Account Number already used!'));
469 $form->redirect($locale->text('Account saved!'))
470 if (AM->save_account(\%myconfig, \%$form));
471 $form->error($locale->text('Cannot save account!'));
473 $main::lxdebug->leave_sub();
477 $main::lxdebug->enter_sub();
479 my $form = $main::form;
480 my %myconfig = %main::myconfig;
481 my $locale = $main::locale;
483 $main::auth->assert('config');
485 $form->{callback} = build_std_url('action=list_account');
486 my $link_edit_account = build_std_url('action=edit_account', 'callback');
488 CA->all_accounts(\%myconfig, \%$form);
490 foreach my $ca (@{ $form->{CA} }) {
495 if ($ca->{amount} > 0) {
496 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
498 if ($ca->{amount} < 0) {
499 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
501 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
502 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
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 : $locale->text('Unknown Link') . ': ' . $link;
572 $ca->{link} .= ($link ne '') ? "[$link] ":'';
575 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
576 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
577 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
578 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
579 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
580 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
581 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
582 : $locale->text('Unknown Category') . ': ' . $ca->{category};
585 $form->{title} = $locale->text('Chart of Accounts');
587 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
589 $main::lxdebug->leave_sub();
594 $main::lxdebug->enter_sub();
596 my $form = $main::form;
597 my %myconfig = %main::myconfig;
598 my $locale = $main::locale;
600 $main::auth->assert('config');
602 $form->{title} = $locale->text('Delete Account');
605 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
607 if ($form->{id} == $form->{$id}) {
608 $form->error($locale->text('Cannot delete default account!'));
612 $form->redirect($locale->text('Account deleted!'))
613 if (AM->delete_account(\%myconfig, \%$form));
614 $form->error($locale->text('Cannot delete account!'));
616 $main::lxdebug->leave_sub();
620 $main::lxdebug->enter_sub();
622 my $form = $main::form;
624 $main::auth->assert('config');
626 $form->{title} = "Add";
628 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
633 $main::lxdebug->leave_sub();
637 $main::lxdebug->enter_sub();
639 my $form = $main::form;
640 my %myconfig = %main::myconfig;
642 $main::auth->assert('config');
644 $form->{title} = "Edit";
646 AM->get_lead(\%myconfig, \%$form);
650 $form->{orphaned} = 1;
653 $main::lxdebug->leave_sub();
657 $main::lxdebug->enter_sub();
659 my $form = $main::form;
660 my %myconfig = %main::myconfig;
661 my $locale = $main::locale;
663 $main::auth->assert('config');
665 AM->lead(\%myconfig, \%$form);
667 $form->{callback} = "am.pl?action=list_lead";
669 my $callback = $form->escape($form->{callback});
671 $form->{title} = $locale->text('Lead');
673 my @column_index = qw(description cost profit);
675 $column_header{description} =
676 qq|<th class=listheading width=100%>|
677 . $locale->text('Description')
687 <th class=listtop>$form->{title}</th>
690 <tr class=listheading>
693 map { print "$column_header{$_}\n" } @column_index;
699 my ($i, %column_data);
700 foreach my $ref (@{ $form->{ALL} }) {
706 <tr valign=top class=listrow$i>
709 # $lead = $ref->{lead};
711 $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
713 map { print "$column_data{$_}\n" } @column_index;
722 <td><hr size=3 noshade></td>
727 <form method=post action=am.pl>
729 <input name=callback type=hidden value="$form->{callback}">
731 <input type=hidden name=type value=lead>
733 <input class=submit type=submit name=action value="|
734 . $locale->text('Add') . qq|">
742 $main::lxdebug->leave_sub();
746 $main::lxdebug->enter_sub();
748 my $form = $main::form;
749 my $locale = $main::locale;
751 $main::auth->assert('config');
753 $form->{title} = $locale->text("$form->{title} Lead");
755 # $locale->text('Add Lead')
756 # $locale->text('Edit Lead')
758 $form->{description} =~ s/\"/"/g;
761 qq|<input name=description size=50 value="$form->{lead}">|;
768 <form method=post action=am.pl>
770 <input type=hidden name=id value=$form->{id}>
771 <input type=hidden name=type value=lead>
775 <th class=listtop colspan=2>$form->{title}</th>
779 <th align=right>| . $locale->text('Description') . qq|</th>
780 <td>$description</td>
782 <td colspan=2><hr size=3 noshade></td>
787 $main::lxdebug->leave_sub();
791 $main::lxdebug->enter_sub();
793 my $form = $main::form;
794 my %myconfig = %main::myconfig;
795 my $locale = $main::locale;
797 $main::auth->assert('config');
799 $form->isblank("description", $locale->text('Description missing!'));
800 AM->save_lead(\%myconfig, \%$form);
801 $form->redirect($locale->text('lead saved!'));
803 $main::lxdebug->leave_sub();
807 $main::lxdebug->enter_sub();
809 my $form = $main::form;
810 my %myconfig = %main::myconfig;
811 my $locale = $main::locale;
813 $main::auth->assert('config');
815 AM->delete_lead(\%myconfig, \%$form);
816 $form->redirect($locale->text('lead deleted!'));
818 $main::lxdebug->leave_sub();
822 $main::lxdebug->enter_sub();
824 my $form = $main::form;
826 $main::auth->assert('config');
828 $form->{title} = "Add";
830 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
835 $main::lxdebug->leave_sub();
839 $main::lxdebug->enter_sub();
841 my $form = $main::form;
842 my %myconfig = %main::myconfig;
844 $main::auth->assert('config');
846 $form->{title} = "Edit";
848 AM->get_language(\%myconfig, \%$form);
852 $form->{orphaned} = 1;
855 $main::lxdebug->leave_sub();
859 $main::lxdebug->enter_sub();
861 my $form = $main::form;
862 my %myconfig = %main::myconfig;
863 my $locale = $main::locale;
865 $main::auth->assert('config');
867 AM->language(\%myconfig, \%$form);
869 $form->{callback} = "am.pl?action=list_language";
871 my $callback = $form->escape($form->{callback});
873 $form->{title} = $locale->text('Languages');
875 my @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
877 $column_header{description} =
878 qq|<th class=listheading width=60%>|
879 . $locale->text('Description')
881 $column_header{template_code} =
882 qq|<th class=listheading width=10%>|
883 . $locale->text('Template Code')
885 $column_header{article_code} =
886 qq|<th class=listheading>|
887 . $locale->text('Article Code')
889 $column_header{output_numberformat} =
890 qq|<th class=listheading>|
891 . $locale->text('Number Format')
893 $column_header{output_dateformat} =
894 qq|<th class=listheading>|
895 . $locale->text('Date Format')
897 $column_header{output_longdates} =
898 qq|<th class=listheading>|
899 . $locale->text('Long Dates')
909 <th class=listtop>$form->{title}</th>
915 <tr class=listheading>
918 map { print "$column_header{$_}\n" } @column_index;
924 my ($i, %column_data);
925 foreach my $ref (@{ $form->{ALL} }) {
931 <tr valign=top class=listrow$i>
935 $column_data{description} =
936 qq|<td><a href="am.pl?action=edit_language&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
937 $column_data{template_code} = qq|<td align=right>$ref->{template_code}</td>|;
938 $column_data{article_code} =
939 qq|<td align=right>$ref->{article_code}</td>|;
940 $column_data{output_numberformat} =
942 ($ref->{output_numberformat} ? $ref->{output_numberformat} :
943 $locale->text("use program settings")) .
945 $column_data{output_dateformat} =
947 ($ref->{output_dateformat} ? $ref->{output_dateformat} :
948 $locale->text("use program settings")) .
950 $column_data{output_longdates} =
952 ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
955 map { print "$column_data{$_}\n" } @column_index;
967 <td><hr size=3 noshade></td>
972 <form method=post action=am.pl>
974 <input name=callback type=hidden value="$form->{callback}">
976 <input type=hidden name=type value=language>
978 <input class=submit type=submit name=action value="|
979 . $locale->text('Add') . qq|">
987 $main::lxdebug->leave_sub();
990 sub language_header {
991 $main::lxdebug->enter_sub();
993 my $form = $main::form;
994 my $locale = $main::locale;
996 $main::auth->assert('config');
998 $form->{title} = $locale->text("$form->{title} Language");
1000 # $locale->text('Add Language')
1001 # $locale->text('Edit Language')
1003 $form->{description} =~ s/\"/"/g;
1004 $form->{template_code} =~ s/\"/"/g;
1005 $form->{article_code} =~ s/\"/"/g;
1011 qq|<option value="">| . $locale->text("use program settings") .
1013 foreach my $item (('1,000.00', '1000.00', '1.000,00', '1000,00')) {
1015 ($item eq $form->{output_numberformat})
1016 ? "<option selected>$item"
1022 qq|<option value="">| . $locale->text("use program settings") .
1024 foreach my $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
1026 ($item eq $form->{output_dateformat})
1027 ? "<option selected>$item"
1035 <form method=post action=am.pl>
1037 <input type=hidden name=id value=$form->{id}>
1038 <input type=hidden name=type value=language>
1042 <th class=listtop colspan=2>$form->{title}</th>
1044 <tr height="5"></tr>
1046 <th align=right>| . $locale->text('Language') . qq|</th>
1047 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1050 <th align=right>| . $locale->text('Template Code') . qq|</th>
1051 <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
1054 <th align=right>| . $locale->text('Article Code') . qq|</th>
1055 <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
1058 <th align=right>| . $locale->text('Number Format') . qq|</th>
1059 <td><select name="output_numberformat">$numberformat</select></td>
1062 <th align=right>| . $locale->text('Date Format') . qq|</th>
1063 <td><select name="output_dateformat">$dateformat</select></td>
1066 <th align=right>| . $locale->text('Long Dates') . qq|</th>
1067 <td><input type="radio" name="output_longdates" value="1"| .
1068 ($form->{output_longdates} ? " checked" : "") .
1069 qq|>| . $locale->text("Yes") .
1070 qq|<input type="radio" name="output_longdates" value="0"| .
1071 ($form->{output_longdates} ? "" : " checked") .
1072 qq|>| . $locale->text("No") .
1075 <td colspan=2><hr size=3 noshade></td>
1080 $main::lxdebug->leave_sub();
1084 $main::lxdebug->enter_sub();
1086 my $form = $main::form;
1087 my %myconfig = %main::myconfig;
1088 my $locale = $main::locale;
1090 $main::auth->assert('config');
1092 $form->isblank("description", $locale->text('Language missing!'));
1093 $form->isblank("template_code", $locale->text('Template Code missing!'));
1094 $form->isblank("article_code", $locale->text('Article Code missing!'));
1095 AM->save_language(\%myconfig, \%$form);
1096 $form->redirect($locale->text('Language saved!'));
1098 $main::lxdebug->leave_sub();
1101 sub delete_language {
1102 $main::lxdebug->enter_sub();
1104 my $form = $main::form;
1105 my %myconfig = %main::myconfig;
1106 my $locale = $main::locale;
1108 $main::auth->assert('config');
1110 AM->delete_language(\%myconfig, \%$form);
1111 $form->redirect($locale->text('Language deleted!'));
1113 $main::lxdebug->leave_sub();
1117 sub add_buchungsgruppe {
1118 $main::lxdebug->enter_sub();
1120 my $form = $main::form;
1121 my %myconfig = %main::myconfig;
1122 my $locale = $main::locale;
1124 $main::auth->assert('config');
1126 # $locale->text("Add Buchungsgruppe")
1127 # $locale->text("Edit Buchungsgruppe")
1128 $form->{title} = "Add";
1130 $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
1132 AM->get_buchungsgruppe(\%myconfig, \%$form);
1133 $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
1134 for (my $i = 0; 4 > $i; $i++) {
1135 map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
1136 qw(income expense));
1139 &buchungsgruppe_header;
1142 $main::lxdebug->leave_sub();
1145 sub edit_buchungsgruppe {
1146 $main::lxdebug->enter_sub();
1148 my $form = $main::form;
1149 my %myconfig = %main::myconfig;
1151 $main::auth->assert('config');
1153 $form->{title} = "Edit";
1155 AM->get_buchungsgruppe(\%myconfig, \%$form);
1157 &buchungsgruppe_header;
1161 $main::lxdebug->leave_sub();
1164 sub list_buchungsgruppe {
1165 $main::lxdebug->enter_sub();
1167 my $form = $main::form;
1168 my %myconfig = %main::myconfig;
1169 my $locale = $main::locale;
1171 $main::auth->assert('config');
1173 AM->buchungsgruppe(\%myconfig, \%$form);
1175 $form->{callback} = "am.pl?action=list_buchungsgruppe";
1177 my $callback = $form->escape($form->{callback});
1179 $form->{title} = $locale->text('Buchungsgruppen');
1181 my @column_index = qw(up down description inventory_accno
1182 income_accno_0 expense_accno_0
1183 income_accno_1 expense_accno_1
1184 income_accno_2 expense_accno_2
1185 income_accno_3 expense_accno_3 );
1187 $column_header{up} =
1188 qq|<th class="listheading" width="16">|
1189 . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
1191 $column_header{down} =
1192 qq|<th class="listheading" width="16">|
1193 . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
1195 $column_header{description} =
1196 qq|<th class="listheading" width="40%">|
1197 . $locale->text('Description')
1199 $column_header{inventory_accno} =
1200 qq|<th class=listheading>|
1201 . $locale->text('Bestandskonto')
1203 $column_header{income_accno_0} =
1204 qq|<th class=listheading>|
1205 . $locale->text('National Revenues')
1207 $column_header{expense_accno_0} =
1208 qq|<th class=listheading>|
1209 . $locale->text('National Expenses')
1211 $column_header{income_accno_1} =
1212 qq|<th class=listheading>|
1213 . $locale->text('Revenues EU with UStId')
1215 $column_header{expense_accno_1} =
1216 qq|<th class=listheading>|
1217 . $locale->text('Expenses EU with UStId')
1219 $column_header{income_accno_2} =
1220 qq|<th class=listheading>|
1221 . $locale->text('Revenues EU without UStId')
1223 $column_header{expense_accno_2} =
1224 qq|<th class=listheading>|
1225 . $locale->text('Expenses EU without UStId')
1227 $column_header{income_accno_3} =
1228 qq|<th class=listheading>|
1229 . $locale->text('Foreign Revenues')
1231 $column_header{expense_accno_3} =
1232 qq|<th class=listheading>|
1233 . $locale->text('Foreign Expenses')
1242 <th class=listtop>$form->{title}</th>
1244 <tr height="5"></tr>
1248 <tr class=listheading>
1251 map { print "$column_header{$_}\n" } @column_index;
1257 my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
1260 my ($i, %column_data);
1261 foreach my $ref (@{ $form->{ALL} }) {
1267 <tr valign=top class=listrow$i>
1271 my $pref = $form->{ALL}->[$row - 1];
1273 qq|<td align="center" valign="center" width="16">| .
1274 qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
1275 qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
1278 $column_data{up} = qq|<td width="16"> </td>|;
1281 if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
1282 $column_data{down} = qq|<td width="16"> </td>|;
1284 my $nref = $form->{ALL}->[$row + 1];
1285 $column_data{down} =
1286 qq|<td align="center" valign="center" width="16">| .
1287 qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
1288 qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
1292 $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
1293 $column_data{inventory_accno} = qq|<td align=right>$ref->{inventory_accno}</td>|;
1294 $column_data{income_accno_0} =
1295 qq|<td align=right>$ref->{income_accno_0}</td>|;
1296 $column_data{expense_accno_0} = qq|<td align=right>$ref->{expense_accno_0}</td>|;
1297 $column_data{income_accno_1} =
1298 qq|<td align=right>$ref->{income_accno_1}</td>|;
1299 $column_data{expense_accno_1} = qq|<td align=right>$ref->{expense_accno_1}</td>|;
1300 $column_data{income_accno_2} =
1301 qq|<td align=right>$ref->{income_accno_2}</td>|;
1302 $column_data{expense_accno_2} = qq|<td align=right>$ref->{expense_accno_2}</td>|;
1303 $column_data{income_accno_3} =
1304 qq|<td align=right>$ref->{income_accno_3}</td>|;
1305 $column_data{expense_accno_3} = qq|<td align=right>$ref->{expense_accno_3}</td>|;
1307 map { print "$column_data{$_}\n" } @column_index;
1321 <td><hr size=3 noshade></td>
1326 <form method=post action=am.pl>
1328 <input name=callback type=hidden value="$form->{callback}">
1330 <input type=hidden name=type value=buchungsgruppe>
1332 <input class=submit type=submit name=action value="|
1333 . $locale->text('Add') . qq|">
1341 $main::lxdebug->leave_sub();
1344 sub buchungsgruppe_header {
1345 $main::lxdebug->enter_sub();
1347 my $form = $main::form;
1348 my $locale = $main::locale;
1350 $main::auth->assert('config');
1352 $form->{title} = $locale->text("$form->{title} Buchungsgruppe");
1354 # $locale->text('Add Accounting Group')
1355 # $locale->text('Edit Accounting Group')
1357 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
1358 my %acc_type_map = (
1359 "IC" => $acc_inventory,
1360 "IC_income" => $acc_income,
1361 "IC_sale" => $acc_income,
1362 "IC_expense" => $acc_expense,
1363 "IC_cogs" => $acc_expense,
1366 foreach my $key (keys(%acc_type_map)) {
1367 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1368 $acc_type_map{$key}->{$ref->{"id"}} = $ref;
1372 foreach my $type (qw(IC IC_income IC_expense)) {
1373 $form->{"select$type"} =
1375 map({ "<option value=$_->{id} $_->{selected}>" .
1376 "$_->{accno}--" . H($_->{description}) . "</option>" }
1377 sort({ $a->{"accno"} cmp $b->{"accno"} }
1378 values(%{$acc_type_map{$type}}))));
1382 $form->{selectIC} =~ s/selected//g;
1383 $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/ value=$form->{inventory_accno_id} selected/;
1384 $form->{selectIC_income} =~ s/selected//g;
1385 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/ value=$form->{income_accno_id_0} selected/;
1386 $form->{selectIC_expense} =~ s/selected//g;
1387 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/ value=$form->{expense_accno_id_0} selected/;
1391 if ( $::instance_conf->get_inventory_system eq 'perpetual' ) { # was !$::lx_office_conf{system}->{eur}) {
1394 <th align=right>| . $locale->text('Inventory') . qq|</th>
1395 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
1396 <input name=selectIC type=hidden value="$form->{selectIC}">
1398 } elsif ( $::instance_conf->get_inventory_system eq 'periodic' ) {
1399 # don't allow choice of inventory accno and don't show that line
1401 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
1405 $linkaccounts .= qq|
1407 <th align=right>| . $locale->text('National Revenues') . qq|</th>
1408 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
1411 <th align=right>| . $locale->text('National Expenses') . qq|</th>
1412 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
1415 $form->{selectIC_income} =~ s/selected//g;
1416 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/ value=$form->{income_accno_id_1} selected/;
1417 $form->{selectIC_expense} =~ s/selected//g;
1418 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/ value=$form->{expense_accno_id_1} selected/;
1420 $linkaccounts .= qq| <tr>
1421 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
1422 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
1425 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
1426 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
1430 $form->{selectIC_income} =~ s/selected//g;
1431 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/ value=$form->{income_accno_id_2} selected/;
1432 $form->{selectIC_expense} =~ s/selected//g;
1433 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/ value=$form->{expense_accno_id_2} selected/;
1436 $linkaccounts .= qq| <tr>
1437 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
1438 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
1441 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
1442 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
1446 $form->{selectIC_income} =~ s/selected//g;
1447 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/ value=$form->{income_accno_id_3} selected/;
1448 $form->{selectIC_expense} =~ s/selected//g;
1449 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/ value=$form->{expense_accno_id_3} selected/;
1452 $linkaccounts .= qq| <tr>
1453 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
1454 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
1457 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
1458 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
1468 <form method=post action=am.pl>
1470 <input type=hidden name=id value=$form->{id}>
1471 <input type=hidden name=type value=buchungsgruppe>
1475 <th class=listtop colspan=2>$form->{title}</th>
1477 <tr height="5"></tr>
1479 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
1480 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1483 <td colspan=2><hr size=3 noshade></td>
1488 $main::lxdebug->leave_sub();
1491 sub save_buchungsgruppe {
1492 $main::lxdebug->enter_sub();
1494 my $form = $main::form;
1495 my %myconfig = %main::myconfig;
1496 my $locale = $main::locale;
1498 $main::auth->assert('config');
1500 $form->isblank("description", $locale->text('Description missing!'));
1502 AM->save_buchungsgruppe(\%myconfig, \%$form);
1503 $form->redirect($locale->text('Accounting Group saved!'));
1505 $main::lxdebug->leave_sub();
1508 sub delete_buchungsgruppe {
1509 $main::lxdebug->enter_sub();
1511 my $form = $main::form;
1512 my %myconfig = %main::myconfig;
1513 my $locale = $main::locale;
1515 $main::auth->assert('config');
1517 AM->delete_buchungsgruppe(\%myconfig, \%$form);
1518 $form->redirect($locale->text('Accounting Group deleted!'));
1520 $main::lxdebug->leave_sub();
1523 sub swap_buchungsgruppen {
1524 $main::lxdebug->enter_sub();
1526 my $form = $main::form;
1527 my %myconfig = %main::myconfig;
1529 $main::auth->assert('config');
1531 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
1532 list_buchungsgruppe();
1534 $main::lxdebug->leave_sub();
1538 $main::lxdebug->enter_sub();
1540 my $form = $main::form;
1541 my %myconfig = %main::myconfig;
1542 my $locale = $main::locale;
1544 # get defaults for account numbers and last numbers
1545 AM->defaultaccounts(\%myconfig, \%$form);
1546 $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
1548 map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
1551 my $all_languages = SL::DB::Manager::Language->get_all;
1553 # EÜR = cash, Bilanzierung = accrual
1555 foreach my $key (keys %{ $form->{IC} }) {
1556 foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
1557 my $array = "ACCNOS_" . uc($key);
1558 $form->{$array} ||= [];
1560 my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
1561 push @{ $form->{$array} }, {
1564 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
1569 $form->{title} = $locale->text('Ranges of numbers and default accounts');
1572 print $form->parse_html_template('am/edit_defaults',
1573 { ALL_LANGUAGES => $all_languages, });
1575 $main::lxdebug->leave_sub();
1579 $main::lxdebug->enter_sub();
1581 my $form = $main::form;
1582 my $locale = $main::locale;
1584 AM->save_defaults();
1586 $form->redirect($locale->text('Defaults saved.'));
1588 $main::lxdebug->leave_sub();
1591 sub _build_cfg_options {
1592 my $form = $main::form;
1593 my %myconfig = %main::myconfig;
1596 my $array = uc($idx) . 'S';
1598 $form->{$array} = [];
1599 foreach my $item (@_) {
1600 push @{ $form->{$array} }, {
1603 'selected' => $item eq $myconfig{$idx},
1609 $main::lxdebug->enter_sub();
1611 my $form = $main::form;
1612 my %myconfig = %main::myconfig;
1613 my $locale = $main::locale;
1615 _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
1616 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
1619 if ($::lx_office_conf{print_templates}->{opendocument}
1620 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
1621 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
1622 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
1623 "value" => "opendocument_pdf" });
1625 if ($::lx_office_conf{print_templates}->{latex}) {
1626 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
1628 push(@formats, { "name" => "HTML", "value" => "html" });
1629 if ($::lx_office_conf{print_templates}->{latex}) {
1630 push(@formats, { "name" => $locale->text("Postscript"),
1631 "value" => "postscript" });
1633 if ($::lx_office_conf{print_templates}->{opendocument}) {
1634 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
1635 "value" => "opendocument" });
1638 if (!$myconfig{"template_format"}) {
1639 $myconfig{"template_format"} = "pdf";
1641 $form->{TEMPLATE_FORMATS} = [];
1642 foreach my $item (@formats) {
1643 push @{ $form->{TEMPLATE_FORMATS} }, {
1644 'name' => $item->{name},
1645 'value' => $item->{value},
1646 'selected' => $item->{value} eq $myconfig{template_format},
1650 if (!$myconfig{"default_media"}) {
1651 $myconfig{"default_media"} = "screen";
1654 my %selected = ($myconfig{"default_media"} => "selected");
1656 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
1657 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
1658 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
1661 $form->{PRINTERS} = [ SL::Printer->all_printers(%::myconfig) ];
1663 my %countrycodes = User->country_codes;
1665 $form->{COUNTRYCODES} = [];
1666 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
1667 push @{ $form->{COUNTRYCODES} }, {
1668 'name' => $countrycodes{$countrycode},
1669 'value' => $countrycode,
1670 'selected' => $countrycode eq $myconfig{countrycode},
1674 $form->{STYLESHEETS} = [];
1675 foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
1676 push @{ $form->{STYLESHEETS} }, {
1679 'selected' => $item eq $myconfig{stylesheet},
1683 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
1684 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
1685 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
1687 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
1690 print $form->parse_html_template('am/config');
1692 $main::lxdebug->leave_sub();
1695 sub save_preferences {
1696 $main::lxdebug->enter_sub();
1698 my $form = $main::form;
1699 my %myconfig = %main::myconfig;
1700 my $locale = $main::locale;
1702 $form->{stylesheet} = $form->{usestylesheet};
1704 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
1706 if (AM->save_preferences(\%myconfig, $form)) {
1707 if ($::auth->can_change_password()
1708 && defined $form->{new_password}
1709 && ($form->{new_password} ne '********')) {
1710 my $verifier = SL::Auth::PasswordPolicy->new;
1711 my $result = $verifier->verify($form->{new_password});
1713 if ($result != SL::Auth::PasswordPolicy->OK()) {
1714 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
1717 $::auth->change_password($form->{login}, $form->{new_password});
1719 $form->{password} = $form->{new_password};
1720 $::auth->set_session_value('password', $form->{password});
1721 $::auth->create_or_refresh_session();
1724 $form->redirect($locale->text('Preferences saved!'));
1727 $form->error($locale->text('Cannot save preferences!'));
1729 $main::lxdebug->leave_sub();
1733 $main::lxdebug->enter_sub();
1735 my $form = $main::form;
1736 my %myconfig = %main::myconfig;
1737 my $locale = $main::locale;
1739 $main::auth->assert('config');
1741 $form->{title} = $locale->text('Audit Control');
1743 AM->closedto(\%myconfig, \%$form);
1750 <form method=post action=am.pl>
1753 <tr><th class=listtop>$form->{title}</th></tr>
1754 <tr height="5"></tr>
1759 <th>| . $locale->text('Close Books up to') . qq|</th>
1760 <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
1770 <input type=hidden name=nextsub value=doclose>
1772 <input type=submit class=submit name=action value="|
1773 . $locale->text('Continue') . qq|">
1781 $main::lxdebug->leave_sub();
1785 $main::lxdebug->enter_sub();
1787 my $form = $main::form;
1788 my %myconfig = %main::myconfig;
1789 my $locale = $main::locale;
1791 $main::auth->assert('config');
1793 AM->closebooks(\%myconfig, \%$form);
1795 if ($form->{closedto}) {
1797 $locale->text('Books closed up to') . " "
1798 . $locale->date(\%myconfig, $form->{closedto}, 1));
1800 $form->redirect($locale->text('Books are open'));
1803 $main::lxdebug->leave_sub();
1807 $main::lxdebug->enter_sub();
1809 my $form = $main::form;
1810 my %myconfig = %main::myconfig;
1811 my $locale = $main::locale;
1813 $main::auth->assert('config');
1815 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1816 AM->units_in_use(\%myconfig, $form, $units);
1817 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1819 my @languages = AM->language(\%myconfig, $form, 1);
1821 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1824 foreach (@unit_list) {
1825 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1826 $_->{"UNITLANGUAGES"} = [];
1827 foreach my $lang (@languages) {
1828 push(@{ $_->{"UNITLANGUAGES"} },
1830 "unit" => $_->{"name"},
1831 "language_id" => $lang->{"id"},
1832 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1833 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1839 $units = AM->retrieve_units(\%myconfig, $form);
1840 my $ddbox = AM->unit_select_data($units, undef, 1);
1842 $form->{"title"} = $locale->text("Add and edit units");
1844 print($form->parse_html_template("am/edit_units",
1845 { "UNITS" => \@unit_list,
1846 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1847 "LANGUAGES" => \@languages,
1850 $main::lxdebug->leave_sub();
1854 $main::lxdebug->enter_sub();
1856 my $form = $main::form;
1857 my %myconfig = %main::myconfig;
1858 my $locale = $main::locale;
1860 $main::auth->assert('config');
1862 $form->isblank("new_name", $locale->text("The name is missing."));
1863 my $units = AM->retrieve_units(\%myconfig, $form);
1864 my $all_units = AM->retrieve_units(\%myconfig, $form);
1865 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1867 my ($base_unit, $factor);
1868 if ($form->{"new_base_unit"}) {
1869 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1871 $form->isblank("new_factor", $locale->text("The factor is missing."));
1872 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1873 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1874 $base_unit = $form->{"new_base_unit"};
1878 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1879 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1880 push(@languages, { "id" => $lang->{"id"},
1881 "localized" => $form->{"new_localized_$lang->{id}"},
1882 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1886 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1888 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1892 $main::lxdebug->leave_sub();
1895 sub set_unit_languages {
1896 $main::lxdebug->enter_sub();
1898 my $form = $main::form;
1900 $main::auth->assert('config');
1902 my ($unit, $languages, $idx) = @_;
1904 $unit->{"LANGUAGES"} = [];
1906 foreach my $lang (@{$languages}) {
1907 push(@{ $unit->{"LANGUAGES"} },
1908 { "id" => $lang->{"id"},
1909 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1910 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1914 $main::lxdebug->leave_sub();
1918 $main::lxdebug->enter_sub();
1920 my $form = $main::form;
1921 my %myconfig = %main::myconfig;
1922 my $locale = $main::locale;
1924 $main::auth->assert('config');
1926 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1927 AM->units_in_use(\%myconfig, $form, $old_units);
1929 my @languages = AM->language(\%myconfig, $form, 1);
1932 my @delete_units = ();
1933 foreach my $i (1..($form->{"rowcount"} * 1)) {
1934 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1936 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1939 if ($form->{"unchangeable_$i"}) {
1940 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1941 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1942 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1946 if ($old_unit->{"in_use"}) {
1947 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1950 if ($form->{"delete_$i"}) {
1951 push(@delete_units, $old_unit->{"name"});
1955 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1957 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1958 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1959 $new_units->{$form->{"name_$i"}} = \%h;
1960 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1961 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1964 foreach my $unit (values(%{$new_units})) {
1965 next unless ($unit->{"old_name"});
1966 if ($unit->{"base_unit"}) {
1967 $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"}))
1968 unless (defined($new_units->{$unit->{"base_unit"}}));
1969 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1970 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1972 $unit->{"base_unit"} = undef;
1973 $unit->{"factor"} = undef;
1977 foreach my $unit (values(%{$new_units})) {
1978 next if ($unit->{"unchanged_unit"});
1980 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1981 my $new_unit = $unit;
1982 while ($new_unit->{"base_unit"}) {
1983 $new_unit->{"seen"} = 1;
1984 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1985 if ($new_unit->{"seen"}) {
1986 $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, " .
1987 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1992 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1994 $form->{"saved_message"} = $locale->text("The units have been saved.");
1998 $main::lxdebug->leave_sub();
2001 sub show_history_search {
2002 $main::lxdebug->enter_sub();
2004 my $form = $main::form;
2005 my $locale = $main::locale;
2007 $main::auth->assert('config');
2009 $form->{title} = $locale->text("History Search");
2012 print $form->parse_html_template("common/search_history");
2014 $main::lxdebug->leave_sub();
2017 sub show_am_history {
2018 $main::lxdebug->enter_sub();
2020 my $form = $main::form;
2021 my %myconfig = %main::myconfig;
2022 my $locale = $main::locale;
2024 $main::auth->assert('config');
2026 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
2027 $form->{order} ||= 'h.itime--1';
2029 my %search = ( "Artikelnummer" => "parts",
2030 "Kundennummer" => "customer",
2031 "Lieferantennummer" => "vendor",
2032 "Projektnummer" => "project",
2033 "Buchungsnummer" => "oe",
2034 "Eingangsrechnungnummer" => "ap",
2035 "Ausgangsrechnungnummer" => "ar",
2036 "Mahnungsnummer" => "dunning"
2038 my %searchNo = ( "Artikelnummer" => "partnumber",
2039 "Kundennummer" => "customernumber",
2040 "Lieferantennummer" => "vendornumber",
2041 "Projektnummer" => "projectnumber",
2042 "Buchungsnummer" => "ordnumber",
2043 "Eingangsrechnungnummer" => "invnumber",
2044 "Ausgangsrechnungnummer" => "invnumber",
2045 "Mahnungsnummer" => "dunning_id"
2048 my $dbh = $form->dbconnect(\%myconfig);
2051 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
2052 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
2053 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
2054 if ($form->{mitarbeiter} =~ m/^\d+$/) {
2055 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
2056 } elsif ($form->{mitarbeiter}) {
2057 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
2060 my $query = qq|SELECT trans_id AS id FROM history_erp | .
2061 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
2062 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
2064 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
2065 my $daten .= shift @ids;
2066 $daten .= join '', map { " OR trans_id = $_" } @ids;
2068 my ($sort, $sortby) = split(/\-\-/, $form->{order});
2069 $sort =~ s/.*\.(.*)$/$1/;
2071 $form->{title} = $locale->text("History Search");
2074 print $form->parse_html_template("common/show_history",
2075 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
2076 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
2079 uc($sort) . "BY" => $sortby,
2080 'callback' => $callback,
2084 $main::lxdebug->leave_sub();
2088 $main::lxdebug->enter_sub();
2090 my $form = $main::form;
2091 my $locale = $main::locale;
2093 $main::auth->assert('config');
2095 $form->{title} = $locale->text('Add');
2097 $form->{callback} ||= "am.pl?action=add_tax";
2099 _get_taxaccount_selection();
2103 my $parameters_ref = {
2104 # ChartTypeIsAccount => $ChartTypeIsAccount,
2107 # Ausgabe des Templates
2108 print($form->parse_html_template('am/edit_tax', $parameters_ref));
2110 $main::lxdebug->leave_sub();
2114 $main::lxdebug->enter_sub();
2116 my $form = $main::form;
2117 my %myconfig = %main::myconfig;
2118 my $locale = $main::locale;
2120 $main::auth->assert('config');
2122 $form->{title} = $locale->text('Edit');
2124 AM->get_tax(\%myconfig, \%$form);
2125 _get_taxaccount_selection();
2127 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
2131 my $parameters_ref = {
2134 # Ausgabe des Templates
2135 print($form->parse_html_template('am/edit_tax', $parameters_ref));
2137 $main::lxdebug->leave_sub();
2141 $main::lxdebug->enter_sub();
2143 my $form = $main::form;
2144 my %myconfig = %main::myconfig;
2145 my $locale = $main::locale;
2147 $main::auth->assert('config');
2149 AM->taxes(\%myconfig, \%$form);
2151 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
2153 $form->{callback} = build_std_url('action=list_tax');
2155 $form->{title} = $locale->text('Tax-O-Matic');
2159 my $parameters_ref = {
2162 # Ausgabe des Templates
2163 print($form->parse_html_template('am/list_tax', $parameters_ref));
2165 $main::lxdebug->leave_sub();
2168 sub _get_taxaccount_selection{
2169 $main::lxdebug->enter_sub();
2171 my $form = $main::form;
2172 my %myconfig = %main::myconfig;
2174 $main::auth->assert('config');
2176 AM->get_tax_accounts(\%myconfig, \%$form);
2178 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
2180 $main::lxdebug->leave_sub();
2184 $main::lxdebug->enter_sub();
2186 my $form = $main::form;
2187 my %myconfig = %main::myconfig;
2188 my $locale = $main::locale;
2190 $main::auth->assert('config');
2192 $form->isblank("rate", $locale->text('Taxrate missing!'));
2193 $form->isblank("taxdescription", $locale->text('Taxdescription missing!'));
2194 $form->isblank("taxkey", $locale->text('Taxkey missing!'));
2196 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
2198 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
2199 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
2202 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
2203 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
2206 AM->save_tax(\%myconfig, \%$form);
2207 $form->redirect($locale->text('Tax saved!'));
2209 $main::lxdebug->leave_sub();
2213 $main::lxdebug->enter_sub();
2215 my $form = $main::form;
2216 my %myconfig = %main::myconfig;
2217 my $locale = $main::locale;
2219 $main::auth->assert('config');
2221 AM->delete_tax(\%myconfig, \%$form);
2222 $form->redirect($locale->text('Tax deleted!'));
2224 $main::lxdebug->leave_sub();
2227 sub add_price_factor {
2228 $main::lxdebug->enter_sub();
2230 my $form = $main::form;
2231 my $locale = $main::locale;
2233 $main::auth->assert('config');
2235 $form->{title} = $locale->text('Add Price Factor');
2236 $form->{callback} ||= build_std_url('action=add_price_factor');
2237 $form->{fokus} = 'description';
2240 print $form->parse_html_template('am/edit_price_factor');
2242 $main::lxdebug->leave_sub();
2245 sub edit_price_factor {
2246 $main::lxdebug->enter_sub();
2248 my $form = $main::form;
2249 my %myconfig = %main::myconfig;
2250 my $locale = $main::locale;
2252 $main::auth->assert('config');
2254 $form->{title} = $locale->text('Edit Price Factor');
2255 $form->{callback} ||= build_std_url('action=add_price_factor');
2256 $form->{fokus} = 'description';
2258 AM->get_price_factor(\%myconfig, $form);
2260 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
2263 print $form->parse_html_template('am/edit_price_factor');
2265 $main::lxdebug->leave_sub();
2268 sub list_price_factors {
2269 $main::lxdebug->enter_sub();
2271 my $form = $main::form;
2272 my %myconfig = %main::myconfig;
2273 my $locale = $main::locale;
2275 $main::auth->assert('config');
2277 AM->get_all_price_factors(\%myconfig, \%$form);
2279 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
2280 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
2283 $form->{callback} = build_std_url('action=list_price_factors');
2284 $form->{title} = $locale->text('Price Factors');
2285 $form->{url_base} = build_std_url('callback');
2288 print $form->parse_html_template('am/list_price_factors');
2290 $main::lxdebug->leave_sub();
2293 sub save_price_factor {
2294 $main::lxdebug->enter_sub();
2296 my $form = $main::form;
2297 my %myconfig = %main::myconfig;
2298 my $locale = $main::locale;
2300 $main::auth->assert('config');
2302 $form->isblank("description", $locale->text('Description missing!'));
2303 $form->isblank("factor", $locale->text('Factor missing!'));
2305 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
2307 AM->save_price_factor(\%myconfig, $form);
2309 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
2311 $form->redirect($locale->text('Price factor saved!'));
2313 $main::lxdebug->leave_sub();
2316 sub delete_price_factor {
2317 $main::lxdebug->enter_sub();
2319 my $form = $main::form;
2320 my %myconfig = %main::myconfig;
2321 my $locale = $main::locale;
2323 $main::auth->assert('config');
2325 AM->delete_price_factor(\%myconfig, \%$form);
2327 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
2329 $form->redirect($locale->text('Price factor deleted!'));
2331 $main::lxdebug->leave_sub();
2335 $main::lxdebug->enter_sub();
2337 my $form = $main::form;
2338 my $locale = $main::locale;
2340 $main::auth->assert('config');
2342 $form->{title} = $locale->text('Add Warehouse');
2343 $form->{callback} ||= build_std_url('action=add_warehouse');
2344 $form->{fokus} = 'description';
2347 print $form->parse_html_template('am/edit_warehouse');
2349 $main::lxdebug->leave_sub();
2352 sub edit_warehouse {
2353 $main::lxdebug->enter_sub();
2355 my $form = $main::form;
2356 my %myconfig = %main::myconfig;
2357 my $locale = $main::locale;
2359 $main::auth->assert('config');
2361 AM->get_warehouse(\%myconfig, $form);
2363 $form->get_lists('employees' => 'EMPLOYEES');
2365 $form->{title} = $locale->text('Edit Warehouse');
2366 $form->{callback} ||= build_std_url('action=list_warehouses');
2367 $form->{fokus} = 'description';
2370 print $form->parse_html_template('am/edit_warehouse');
2372 $main::lxdebug->leave_sub();
2375 sub list_warehouses {
2376 $main::lxdebug->enter_sub();
2378 my $form = $main::form;
2379 my %myconfig = %main::myconfig;
2380 my $locale = $main::locale;
2382 $main::auth->assert('config');
2384 AM->get_all_warehouses(\%myconfig, $form);
2386 $form->{callback} = build_std_url('action=list_warehouses');
2387 $form->{title} = $locale->text('Warehouses');
2388 $form->{url_base} = build_std_url('callback');
2391 print $form->parse_html_template('am/list_warehouses');
2393 $main::lxdebug->leave_sub();
2396 sub save_warehouse {
2397 $main::lxdebug->enter_sub();
2399 my $form = $main::form;
2400 my %myconfig = %main::myconfig;
2401 my $locale = $main::locale;
2403 $main::auth->assert('config');
2405 $form->isblank("description", $locale->text('Description missing!'));
2407 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
2409 AM->save_warehouse(\%myconfig, $form);
2411 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
2413 $form->redirect($locale->text('Warehouse saved.'));
2415 $main::lxdebug->leave_sub();
2418 sub delete_warehouse {
2419 $main::lxdebug->enter_sub();
2421 my $form = $main::form;
2422 my %myconfig = %main::myconfig;
2423 my $locale = $main::locale;
2425 $main::auth->assert('config');
2427 if (!$form->{confirmed}) {
2428 $form->{title} = $locale->text('Confirmation');
2431 print $form->parse_html_template('am/confirm_delete_warehouse');
2435 if (AM->delete_warehouse(\%myconfig, $form)) {
2436 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
2437 $form->redirect($locale->text('Warehouse deleted.'));
2440 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
2443 $main::lxdebug->leave_sub();
2447 $main::lxdebug->enter_sub();
2449 my $form = $main::form;
2450 my %myconfig = %main::myconfig;
2451 my $locale = $main::locale;
2453 $main::auth->assert('config');
2455 AM->save_bins(\%myconfig, $form);
2457 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
2459 $form->redirect($locale->text('Bins saved.'));
2461 $main::lxdebug->leave_sub();