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 use SL::DBUtils qw(selectall_array_query);
52 require "bin/mozilla/common.pl";
60 sub add { call_sub("add_$main::form->{type}"); }
61 sub delete { call_sub("delete_$main::form->{type}"); }
62 sub save { call_sub("save_$main::form->{type}"); }
63 sub edit { call_sub("edit_$main::form->{type}"); }
64 sub continue { call_sub($main::form->{"nextsub"}); }
65 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
68 $main::lxdebug->enter_sub();
70 my $form = $main::form;
71 my %myconfig = %main::myconfig;
73 $main::auth->assert('config');
75 $form->{title} = "Add";
76 $form->{charttype} = "A";
77 AM->get_account(\%myconfig, \%$form);
79 $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
84 $main::lxdebug->leave_sub();
88 $main::lxdebug->enter_sub();
90 my $form = $main::form;
91 my %myconfig = %main::myconfig;
92 my $defaults = SL::DB::Default->get;
94 $main::auth->assert('config');
96 $form->{title} = "Edit";
97 $form->{feature_balance} = $defaults->feature_balance;
98 $form->{feature_datev} = $defaults->feature_datev;
99 $form->{feature_erfolgsrechnung} = $defaults->feature_erfolgsrechnung;
100 $form->{feature_eurechnung} = $defaults->feature_eurechnung;
101 $form->{feature_ustva} = $defaults->feature_ustva;
103 AM->get_account(\%myconfig, \%$form);
105 foreach my $item (split(/:/, $form->{link})) {
106 $form->{$item} = "checked";
112 $main::lxdebug->leave_sub();
116 $main::lxdebug->enter_sub();
118 my $form = $main::form;
119 my %myconfig = %main::myconfig;
120 my $locale = $main::locale;
122 $main::auth->assert('config');
124 if ( $form->{action} eq 'edit_account') {
125 $form->{account_exists} = '1';
128 $form->{title} = $locale->text("$form->{title} Account");
130 $form->{"$form->{charttype}_checked"} = "checked";
131 $form->{"$form->{category}_checked"} = "checked";
133 $form->{select_tax} = "";
135 my @tax_report_pos = USTVA->report_variables({
136 myconfig => \%myconfig,
139 attribute => 'position',
143 if (@{ $form->{TAXKEY} }) {
144 foreach my $item (@{ $form->{TAXKEY} }) {
145 $item->{rate} = $item->{rate} * 100 . '%';
148 # Fill in empty row for new Taxkey
149 my $newtaxkey_ref = {
154 taxdescription => '',
158 startdate => $form->{account_exists} ? '' : DateTime->new(year => 1970, month => 1, day => 1)->to_lxoffice,
161 push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
164 foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
166 # Fill in a runningnumber
167 $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
169 # Fill in the Taxkeys as select options
170 foreach my $item (@{ $form->{TAXKEY} }) {
171 if ($item->{id} == $taxkey_used->{tax_id}) {
172 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
173 qq|<option value="$item->{id}" selected="selected">|
174 . sprintf("%.2d", $item->{taxkey})
175 . qq|. $item->{taxdescription} ($item->{rate}) |
176 . $locale->text('Tax-o-matic Account')
177 . qq|: $item->{chart_accno}\n|;
180 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
181 qq|<option value="$item->{id}">|
182 . sprintf("%.2d", $item->{taxkey})
183 . qq|. $item->{taxdescription} ($item->{rate}) |
184 . $locale->text('Tax-o-matic Account')
185 . qq|: $item->{chart_accno}\n|;
190 # Fill in the USTVA Numbers as select options
191 foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
193 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
195 elsif ( $item eq $taxkey_used->{pos_ustva} ) {
196 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
199 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
208 # Newaccount Folgekonto
209 if (@{ $form->{NEWACCOUNT} || [] }) {
210 if (!$form->{new_chart_valid}) {
211 $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
213 foreach my $item (@{ $form->{NEWACCOUNT} }) {
214 if ($item->{id} == $form->{new_chart_id}) {
215 $form->{selectnewaccount} .=
216 qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
217 } elsif (!$form->{new_chart_valid}) {
218 $form->{selectnewaccount} .=
219 qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
225 my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
227 1 => "Umsatzerlöse",
228 2 => "sonstige Erlöse",
229 3 => "Privatanteile",
231 5 => "Ausserordentliche Erträge",
232 6 => "Vereinnahmte Umsatzst.",
233 7 => "Umsatzsteuererstattungen",
234 8 => "Wareneingänge",
235 9 => "Löhne und Gehälter",
236 10 => "Gesetzl. sozialer Aufw.",
238 12 => "Gas, Strom, Wasser",
239 13 => "Instandhaltung",
240 14 => "Steuern, Versich., Beiträge",
242 16 => "Kfz-Versicherungen",
243 17 => "Sonst. Fahrzeugkosten",
244 18 => "Werbe- und Reisekosten",
245 19 => "Instandhaltung u. Werkzeuge",
246 20 => "Fachzeitschriften, Bücher",
247 21 => "Miete für Einrichtungen",
248 22 => "Rechts- und Beratungskosten",
249 23 => "Bürobedarf, Porto, Telefon",
250 24 => "Sonstige Aufwendungen",
251 25 => "Abschreibungen auf Anlagever.",
252 26 => "Abschreibungen auf GWG",
254 28 => "Umsatzsteuerzahlungen",
256 30 => "Ausserordentlicher Aufwand",
257 31 => "Betriebliche Steuern");
258 foreach my $item (sort({ $a <=> $b } keys(%eur))) {
259 my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
260 if ($item == $form->{pos_eur}) {
261 $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
263 $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
268 my $select_er = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
272 foreach my $item (sort({ $a <=> $b } keys(%er))) {
273 my $text = H($::locale->{iconv_utf8}->convert($er{$item}));
274 if ($item == $form->{pos_er}) {
275 $select_er .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
277 $select_er .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
282 my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
285 1 => 'Umsatzerlöse',
286 2 => 'Best.Verdg.FE/UE',
287 3 => 'Aktiv.Eigenleistung',
288 4 => 'Mat./Wareneinkauf',
289 5 => 'So.betr.Erlöse',
290 10 => 'Personalkosten',
292 12 => 'Betriebl.Steuern',
293 13 => 'Vers./Beiträge',
294 14 => 'Kfz.Kosten o.St.',
295 15 => 'Werbe-Reisek.',
296 16 => 'Kosten Warenabgabe',
297 17 => 'Abschreibungen',
298 18 => 'Rep./instandhlt.',
299 19 => 'Ãœbrige Steuern',
300 20 => 'Sonst.Kosten',
302 31 => 'Sonst.neutr.Aufw.',
303 32 => 'Zinserträge',
304 33 => 'Sonst.neutr.Ertrag',
305 34 => 'Verr.kalk.Kosten',
306 35 => 'Steuern Eink.u.Ertr.');
307 foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
308 my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
309 if ($item == $form->{pos_bwa}) {
310 $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
312 $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
317 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
318 my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
319 foreach my $item ((1, 2, 3, 4)) {
320 if ($item == $form->{pos_bilanz}) {
321 $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
323 $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
328 # this is for our parser only! Do not remove.
329 # type=submit $locale->text('Add Account')
330 # type=submit $locale->text('Edit Account')
332 $form->{type} = "account";
334 # preselections category
336 my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
339 'A' => $locale->text('Asset'),
340 'L' => $locale->text('Liability'),
341 'Q' => $locale->text('Equity'),
342 'I' => $locale->text('Revenue'),
343 'E' => $locale->text('Expense'),
344 'C' => $locale->text('Costs'),
346 foreach my $item ( sort({ $a <=> $b } keys %category) ) {
347 if ($item eq $form->{category}) {
348 $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
350 $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
355 # preselection chart type
356 my @all_charttypes = ({'name' => $locale->text('Account'), 'value' => 'A'},
357 {'name' => $locale->text('Heading'), 'value' => 'H'},
359 my $selected_charttype = $form->{charttype};
362 # account where AR_tax or AP_tax is set are not orphaned if they are used as
363 # tax-o-matic account
364 if ( $form->{id} && $form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
365 if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
366 $form->{orphaned} = 0;
370 my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
371 my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
375 my $parameters_ref = {
376 ChartTypeIsAccount => $ChartTypeIsAccount,
377 AccountIsPosted => $AccountIsPosted,
378 select_category => $select_category,
379 all_charttypes => \@all_charttypes,
380 selected_charttype => $selected_charttype,
381 select_bwa => $select_bwa,
382 select_bilanz => $select_bilanz,
383 select_eur => $select_eur,
384 select_er => $select_er,
387 # Ausgabe des Templates
388 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
391 $main::lxdebug->leave_sub();
395 $::lxdebug->enter_sub;
396 $::auth->assert('config');
398 print $::form->parse_html_template('am/form_footer', {
399 show_save => !$::form->{id}
400 || ($::form->{id} && $::form->{orphaned})
401 || ($::form->{type} eq "account" && !$::form->{new_chart_valid}),
402 show_delete => $::form->{id} && $::form->{orphaned},
403 show_save_as_new => $::form->{id} && $::form->{type} eq "account",
406 $::lxdebug->leave_sub;
410 $main::lxdebug->enter_sub();
412 my $form = $main::form;
413 my %myconfig = %main::myconfig;
414 my $locale = $main::locale;
416 $main::auth->assert('config');
418 $form->isblank("accno", $locale->text('Account Number missing!'));
419 $form->isblank("description", $locale->text('Account Description missing!'));
421 if ($form->{charttype} eq 'A'){
422 $form->isblank("category", $locale->text('Account Type missing!'));
424 my $found_valid_taxkey = 0;
425 foreach my $i (0 .. 10) { # 10 is maximum count of taxkeys in form
426 if ($form->{"taxkey_startdate_$i"} and !$form->{"taxkey_del_$i"}) {
427 $found_valid_taxkey = 1;
431 if ($found_valid_taxkey == 0) {
432 $form->error($locale->text('A valid taxkey is missing!'));
436 $form->redirect($locale->text('Account saved!'))
437 if (AM->save_account(\%myconfig, \%$form));
438 $form->error($locale->text('Cannot save account!'));
440 $main::lxdebug->leave_sub();
443 sub save_as_new_account {
444 $main::lxdebug->enter_sub();
446 my $form = $main::form;
447 my %myconfig = %main::myconfig;
448 my $locale = $main::locale;
450 $main::auth->assert('config');
452 $form->isblank("accno", $locale->text('Account Number missing!'));
453 $form->isblank("description", $locale->text('Account Description missing!'));
455 if ($form->{charttype} eq 'A'){
456 $form->isblank("category", $locale->text('Account Type missing!'));
459 for my $taxkey (0 .. 9) {
460 if ($form->{"taxkey_id_$taxkey"}) {
461 $form->{"taxkey_id_$taxkey"} = "NEW";
466 $form->redirect($locale->text('Account saved!'))
467 if (AM->save_account(\%myconfig, \%$form));
468 $form->error($locale->text('Cannot save account!'));
470 $main::lxdebug->leave_sub();
474 $main::lxdebug->enter_sub();
476 my $form = $main::form;
477 my %myconfig = %main::myconfig;
478 my $locale = $main::locale;
480 $main::auth->assert('config');
482 $form->{callback} = build_std_url('action=list_account');
483 my $link_edit_account = build_std_url('action=edit_account', 'callback');
485 CA->all_accounts(\%myconfig, \%$form);
487 foreach my $ca (@{ $form->{CA} }) {
492 if ($ca->{amount} > 0) {
493 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
495 if ($ca->{amount} < 0) {
496 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
498 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
499 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
502 $::request->{layout}->use_stylesheet("list_accounts.css");
503 $form->{title} = $locale->text('Chart of Accounts');
508 my $parameters_ref = {
509 # hidden_variables => $_hidden_variables_ref,
512 # Ausgabe des Templates
513 print($form->parse_html_template('am/list_accounts', $parameters_ref));
515 $main::lxdebug->leave_sub();
520 sub list_account_details {
521 # Ajax Funktion aus list_account_details
522 $main::lxdebug->enter_sub();
524 my $form = $main::form;
525 my %myconfig = %main::myconfig;
526 my $locale = $main::locale;
528 $main::auth->assert('config');
530 my $chart_id = $form->{args};
532 CA->all_accounts(\%myconfig, \%$form, $chart_id);
534 foreach my $ca (@{ $form->{CA} }) {
536 $ca->{debit} = " ";
537 $ca->{credit} = " ";
539 if ($ca->{amount} > 0) {
541 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
543 if ($ca->{amount} < 0) {
545 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
548 my @links = split( q{:}, $ca->{link});
552 foreach my $link (@links){
553 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
554 : ( $link eq 'AP') ? $locale->text('Account Link AP')
555 : ( $link eq 'IC') ? $locale->text('Account Link IC')
556 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
557 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
558 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
559 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
560 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
561 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
562 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
563 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
564 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
565 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
566 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
567 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
568 : $locale->text('Unknown Link') . ': ' . $link;
569 $ca->{link} .= ($link ne '') ? "[$link] ":'';
572 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
573 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
574 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
575 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
576 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
577 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
578 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
579 : $locale->text('Unknown Category') . ': ' . $ca->{category};
582 $form->{title} = $locale->text('Chart of Accounts');
584 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
586 $main::lxdebug->leave_sub();
591 $main::lxdebug->enter_sub();
593 my $form = $main::form;
594 my %myconfig = %main::myconfig;
595 my $locale = $main::locale;
597 $main::auth->assert('config');
599 $form->{title} = $locale->text('Delete Account');
602 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id rndgain_accno_id rndloss_accno_id)
604 if ($form->{id} == $form->{$id}) {
605 $form->error($locale->text('Cannot delete default account!'));
609 $form->redirect($locale->text('Account deleted!'))
610 if (AM->delete_account(\%myconfig, \%$form));
611 $form->error($locale->text('Cannot delete account!'));
613 $main::lxdebug->leave_sub();
617 $main::lxdebug->enter_sub();
619 my $form = $main::form;
621 $main::auth->assert('config');
623 $form->{title} = "Add";
625 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
630 $main::lxdebug->leave_sub();
634 $main::lxdebug->enter_sub();
636 my $form = $main::form;
637 my %myconfig = %main::myconfig;
639 $main::auth->assert('config');
641 $form->{title} = "Edit";
643 AM->get_lead(\%myconfig, \%$form);
647 $form->{orphaned} = 1;
650 $main::lxdebug->leave_sub();
654 $::lxdebug->enter_sub;
655 $::auth->assert('config');
657 AM->lead(\%::myconfig, $::form);
659 $::form->{callback} = "am.pl?action=list_lead";
660 $::form->{title} = $::locale->text('Lead');
663 print $::form->parse_html_template('am/lead_list');
665 $::lxdebug->leave_sub;
669 $::lxdebug->enter_sub;
670 $::auth->assert('config');
672 # $locale->text('Add Lead')
673 # $locale->text('Edit Lead')
674 $::form->{title} = $::locale->text("$::form->{title} Lead");
677 print $::form->parse_html_template('am/lead_header');
679 $::lxdebug->leave_sub;
683 $main::lxdebug->enter_sub();
685 my $form = $main::form;
686 my %myconfig = %main::myconfig;
687 my $locale = $main::locale;
689 $main::auth->assert('config');
691 $form->isblank("description", $locale->text('Description missing!'));
692 AM->save_lead(\%myconfig, \%$form);
693 $form->redirect($locale->text('lead saved!'));
695 $main::lxdebug->leave_sub();
699 $main::lxdebug->enter_sub();
701 my $form = $main::form;
702 my %myconfig = %main::myconfig;
703 my $locale = $main::locale;
705 $main::auth->assert('config');
707 AM->delete_lead(\%myconfig, \%$form);
708 $form->redirect($locale->text('lead deleted!'));
710 $main::lxdebug->leave_sub();
714 $main::lxdebug->enter_sub();
716 my $form = $main::form;
718 $main::auth->assert('config');
720 $form->{title} = "Add";
722 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
727 $main::lxdebug->leave_sub();
731 $main::lxdebug->enter_sub();
733 my $form = $main::form;
734 my %myconfig = %main::myconfig;
736 $main::auth->assert('config');
738 $form->{title} = "Edit";
740 AM->get_language(\%myconfig, \%$form);
744 $form->{orphaned} = 1;
747 $main::lxdebug->leave_sub();
751 $::lxdebug->enter_sub;
752 $::auth->assert('config');
754 AM->language(\%::myconfig, $::form);
756 $::form->{callback} = "am.pl?action=list_language";
757 $::form->{title} = $::locale->text('Languages');
761 print $::form->parse_html_template('am/language_list');
763 $::lxdebug->leave_sub;
766 sub language_header {
767 $::lxdebug->enter_sub;
768 $::auth->assert('config');
770 # $locale->text('Add Language')
771 # $locale->text('Edit Language')
772 $::form->{title} = $::locale->text("$::form->{title} Language");
776 print $::form->parse_html_template('am/language_header', {
777 numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00" ],
778 dateformats => [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
781 $::lxdebug->leave_sub;
785 $main::lxdebug->enter_sub();
787 my $form = $main::form;
788 my %myconfig = %main::myconfig;
789 my $locale = $main::locale;
791 $main::auth->assert('config');
793 $form->isblank("description", $locale->text('Language missing!'));
794 $form->isblank("template_code", $locale->text('Template Code missing!'));
795 $form->isblank("article_code", $locale->text('Article Code missing!'));
796 AM->save_language(\%myconfig, \%$form);
797 $form->redirect($locale->text('Language saved!'));
799 $main::lxdebug->leave_sub();
802 sub delete_language {
803 $main::lxdebug->enter_sub();
805 my $form = $main::form;
806 my %myconfig = %main::myconfig;
807 my $locale = $main::locale;
809 $main::auth->assert('config');
811 AM->delete_language(\%myconfig, \%$form);
812 $form->redirect($locale->text('Language deleted!'));
814 $main::lxdebug->leave_sub();
817 sub _build_cfg_options {
818 my $form = $main::form;
819 my %myconfig = %main::myconfig;
822 my $array = uc($idx) . 'S';
824 $form->{$array} = [];
825 foreach my $item (@_) {
826 push @{ $form->{$array} }, {
829 'selected' => $item eq $myconfig{$idx},
835 $main::lxdebug->enter_sub();
837 my $form = $main::form;
838 my %myconfig = %main::myconfig;
839 my $locale = $main::locale;
841 _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
842 _build_cfg_options('timeformat', qw(hh:mm hh:mm:ss));
843 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00"));
846 if ($::lx_office_conf{print_templates}->{opendocument}
847 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
848 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
849 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
850 "value" => "opendocument_pdf" });
852 if ($::lx_office_conf{print_templates}->{latex}) {
853 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
855 push(@formats, { "name" => "HTML", "value" => "html" });
856 if ($::lx_office_conf{print_templates}->{latex}) {
857 push(@formats, { "name" => $locale->text("Postscript"),
858 "value" => "postscript" });
860 if ($::lx_office_conf{print_templates}->{opendocument}) {
861 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
862 "value" => "opendocument" });
865 if (!$myconfig{"template_format"}) {
866 $myconfig{"template_format"} = "pdf";
868 $form->{TEMPLATE_FORMATS} = [];
869 foreach my $item (@formats) {
870 push @{ $form->{TEMPLATE_FORMATS} }, {
871 'name' => $item->{name},
872 'value' => $item->{value},
873 'selected' => $item->{value} eq $myconfig{template_format},
877 if (!$myconfig{"default_media"}) {
878 $myconfig{"default_media"} = "screen";
881 my %selected = ($myconfig{"default_media"} => "selected");
883 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
884 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
885 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
888 $form->{PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
890 my %countrycodes = User->country_codes;
892 $form->{COUNTRYCODES} = [];
893 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
894 push @{ $form->{COUNTRYCODES} }, {
895 'name' => $countrycodes{$countrycode},
896 'value' => $countrycode,
897 'selected' => $countrycode eq $myconfig{countrycode},
901 $form->{STYLESHEETS} = [];
902 foreach my $item (qw(lx-office-erp.css kivitendo.css)) {
903 push @{ $form->{STYLESHEETS} }, {
906 'selected' => $item eq $myconfig{stylesheet},
910 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
911 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
912 $form->{todo_cfg} = { TODO->get_user_config('login' => $::myconfig{login}) };
914 $form->{title} = $locale->text('Edit Preferences for #1', $::myconfig{login});
918 $form->{full_signature} = $form->create_email_signature();
920 print $form->parse_html_template('am/config');
922 $main::lxdebug->leave_sub();
925 sub save_preferences {
926 $main::lxdebug->enter_sub();
928 my $form = $main::form;
929 my %myconfig = %main::myconfig;
930 my $locale = $main::locale;
932 $form->{stylesheet} = $form->{usestylesheet};
934 TODO->save_user_config('login' => $::myconfig{login}, %{ $form->{todo_cfg} || { } });
936 if (AM->save_preferences($form)) {
937 if ($::auth->can_change_password()
938 && defined $form->{new_password}
939 && ($form->{new_password} ne '********')) {
940 my $verifier = SL::Auth::PasswordPolicy->new;
941 my $result = $verifier->verify($form->{new_password});
943 if ($result != SL::Auth::PasswordPolicy->OK()) {
944 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
947 $::auth->change_password($::myconfig{login}, $form->{new_password});
950 $form->redirect($locale->text('Preferences saved!'));
953 $form->error($locale->text('Cannot save preferences!'));
955 $main::lxdebug->leave_sub();
959 $::lxdebug->enter_sub;
960 $::auth->assert('config');
962 $::form->{title} = $::locale->text('Audit Control');
964 AM->closedto(\%::myconfig, $::form);
967 print $::form->parse_html_template('am/audit_control');
969 $::lxdebug->leave_sub;
973 $main::lxdebug->enter_sub();
975 my $form = $main::form;
976 my %myconfig = %main::myconfig;
977 my $locale = $main::locale;
979 $main::auth->assert('config');
981 AM->closebooks(\%myconfig, \%$form);
983 if ($form->{closedto}) {
985 $locale->text('Books closed up to') . " "
986 . $locale->date(\%myconfig, $form->{closedto}, 1));
988 $form->redirect($locale->text('Books are open'));
991 $main::lxdebug->leave_sub();
995 $main::lxdebug->enter_sub();
997 my $form = $main::form;
998 my %myconfig = %main::myconfig;
999 my $locale = $main::locale;
1001 $main::auth->assert('config');
1003 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1004 AM->units_in_use(\%myconfig, $form, $units);
1005 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1007 my @languages = AM->language(\%myconfig, $form, 1);
1009 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1012 foreach (@unit_list) {
1013 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1014 $_->{"UNITLANGUAGES"} = [];
1015 foreach my $lang (@languages) {
1016 push(@{ $_->{"UNITLANGUAGES"} },
1018 "unit" => $_->{"name"},
1019 "language_id" => $lang->{"id"},
1020 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1021 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1027 $units = AM->retrieve_units(\%myconfig, $form);
1028 my $ddbox = AM->unit_select_data($units, undef, 1);
1030 $form->{"title"} = $locale->text("Add and edit units");
1032 print($form->parse_html_template("am/edit_units",
1033 { "UNITS" => \@unit_list,
1034 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1035 "LANGUAGES" => \@languages,
1038 $main::lxdebug->leave_sub();
1042 $main::lxdebug->enter_sub();
1044 my $form = $main::form;
1045 my %myconfig = %main::myconfig;
1046 my $locale = $main::locale;
1048 $main::auth->assert('config');
1050 $form->isblank("new_name", $locale->text("The name is missing."));
1051 my $units = AM->retrieve_units(\%myconfig, $form);
1052 my $all_units = AM->retrieve_units(\%myconfig, $form);
1053 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1055 my ($base_unit, $factor);
1056 if ($form->{"new_base_unit"}) {
1057 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1059 $form->isblank("new_factor", $locale->text("The factor is missing."));
1060 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1061 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1062 $base_unit = $form->{"new_base_unit"};
1066 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1067 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1068 push(@languages, { "id" => $lang->{"id"},
1069 "localized" => $form->{"new_localized_$lang->{id}"},
1070 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1074 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1076 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1080 $main::lxdebug->leave_sub();
1083 sub set_unit_languages {
1084 $main::lxdebug->enter_sub();
1086 my $form = $main::form;
1088 $main::auth->assert('config');
1090 my ($unit, $languages, $idx) = @_;
1092 $unit->{"LANGUAGES"} = [];
1094 foreach my $lang (@{$languages}) {
1095 push(@{ $unit->{"LANGUAGES"} },
1096 { "id" => $lang->{"id"},
1097 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1098 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1102 $main::lxdebug->leave_sub();
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 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1115 AM->units_in_use(\%myconfig, $form, $old_units);
1117 my @languages = AM->language(\%myconfig, $form, 1);
1120 my @delete_units = ();
1121 foreach my $i (1..($form->{"rowcount"} * 1)) {
1122 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1124 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1127 if ($form->{"unchangeable_$i"}) {
1128 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1129 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1130 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1134 if ($old_unit->{"in_use"}) {
1135 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1138 if ($form->{"delete_$i"}) {
1139 push(@delete_units, $old_unit->{"name"});
1143 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1145 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1146 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1147 $new_units->{$form->{"name_$i"}} = \%h;
1148 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1149 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1152 foreach my $unit (values(%{$new_units})) {
1153 next unless ($unit->{"old_name"});
1154 if ($unit->{"base_unit"}) {
1155 $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"}))
1156 unless (defined($new_units->{$unit->{"base_unit"}}));
1157 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1158 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1160 $unit->{"base_unit"} = undef;
1161 $unit->{"factor"} = undef;
1165 foreach my $unit (values(%{$new_units})) {
1166 next if ($unit->{"unchanged_unit"});
1168 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1169 my $new_unit = $unit;
1170 while ($new_unit->{"base_unit"}) {
1171 $new_unit->{"seen"} = 1;
1172 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1173 if ($new_unit->{"seen"}) {
1174 $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, " .
1175 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1180 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1182 $form->{"saved_message"} = $locale->text("The units have been saved.");
1186 $main::lxdebug->leave_sub();
1189 sub show_history_search {
1190 $main::lxdebug->enter_sub();
1192 my $form = $main::form;
1193 my $locale = $main::locale;
1195 $main::auth->assert('config');
1197 $form->{title} = $locale->text("History Search");
1200 print $form->parse_html_template("common/search_history");
1202 $main::lxdebug->leave_sub();
1205 sub show_am_history {
1206 $main::lxdebug->enter_sub();
1208 my $form = $main::form;
1209 my %myconfig = %main::myconfig;
1210 my $locale = $main::locale;
1212 $main::auth->assert('config');
1214 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1215 $form->{order} ||= 'h.itime--1';
1217 # my %search = ( "Artikelnummer" => "parts",
1218 # "Kundennummer" => "customer",
1219 # "Lieferantennummer" => "vendor",
1220 # "Projektnummer" => "project",
1221 # "Auftragsnummer" => "oe",
1222 # "Angebotsnummer" => "oe",
1223 # "Eingangsrechnungnummer" => "ap",
1224 # "Ausgangsrechnungnummer" => "ar",
1225 # "Mahnungsnummer" => "dunning",
1226 # "Buchungsnummer" => "gl",
1229 my %searchNo = ( "Artikelnummer" => "partnumber",
1230 "Kundennummer" => "customernumber",
1231 "Lieferantennummer" => "vendornumber",
1232 "Projektnummer" => "projectnumber",
1233 "Auftragsnummer" => "ordnumber",
1234 "Angebotsnummer" => "quonumber",
1235 "Eingangsrechnungnummer" => "invnumber",
1236 "Ausgangsrechnungnummer" => "invnumber",
1237 "Mahnungsnummer" => "dunning_id",
1238 "Buchungsnummer" => "gltransaction"
1241 my $dbh = $form->dbconnect(\%myconfig);
1244 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1245 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1246 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1247 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1248 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1249 } elsif ($form->{mitarbeiter}) {
1250 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1253 my $query = qq|SELECT trans_id AS id FROM history_erp | .
1254 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
1255 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
1257 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
1258 my $daten .= shift @ids;
1259 $daten .= join '', map { " OR trans_id = $_" } @ids;
1261 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1262 $sort =~ s/.*\.(.*)$/$1/;
1264 $form->{title} = $locale->text("History Search");
1267 print $form->parse_html_template("common/show_history",
1268 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1269 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1272 uc($sort) . "BY" => $sortby,
1273 'callback' => $callback,
1277 $main::lxdebug->leave_sub();
1281 $main::lxdebug->enter_sub();
1283 my $form = $main::form;
1284 my $locale = $main::locale;
1286 $main::auth->assert('config');
1288 $form->{title} = $locale->text('Add');
1290 $form->{callback} ||= "am.pl?action=add_tax";
1292 _get_taxaccount_selection();
1295 $form->{liability} = 1;
1296 $form->{equity} = 1;
1297 $form->{revenue} = 1;
1298 $form->{expense} = 1;
1303 my $parameters_ref = {
1304 # ChartTypeIsAccount => $ChartTypeIsAccount,
1305 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1308 # Ausgabe des Templates
1309 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1311 $main::lxdebug->leave_sub();
1315 $main::lxdebug->enter_sub();
1317 my $form = $main::form;
1318 my %myconfig = %main::myconfig;
1319 my $locale = $main::locale;
1321 $main::auth->assert('config');
1323 $form->{title} = $locale->text('Edit');
1325 AM->get_tax(\%myconfig, \%$form);
1327 _get_taxaccount_selection();
1329 $form->{asset} = $form->{chart_categories} =~ 'A' ? 1 : 0;
1330 $form->{liability} = $form->{chart_categories} =~ 'L' ? 1 : 0;
1331 $form->{equity} = $form->{chart_categories} =~ 'Q' ? 1 : 0;
1332 $form->{revenue} = $form->{chart_categories} =~ 'I' ? 1 : 0;
1333 $form->{expense} = $form->{chart_categories} =~ 'E' ? 1 : 0;
1334 $form->{costs} = $form->{chart_categories} =~ 'C' ? 1 : 0;
1336 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1340 my $parameters_ref = {
1341 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1342 TAX => SL::DB::Manager::Tax->find_by(id => $form->{id}),
1345 # Ausgabe des Templates
1346 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1348 $main::lxdebug->leave_sub();
1352 $main::lxdebug->enter_sub();
1354 my $form = $main::form;
1355 my %myconfig = %main::myconfig;
1356 my $locale = $main::locale;
1358 $main::auth->assert('config');
1360 AM->taxes(\%myconfig, \%$form);
1362 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1364 $form->{callback} = build_std_url('action=list_tax');
1366 $form->{title} = $locale->text('Tax-O-Matic');
1370 my $parameters_ref = {
1373 # Ausgabe des Templates
1374 print($form->parse_html_template('am/list_tax', $parameters_ref));
1376 $main::lxdebug->leave_sub();
1379 sub _get_taxaccount_selection{
1380 $main::lxdebug->enter_sub();
1382 my $form = $main::form;
1383 my %myconfig = %main::myconfig;
1385 $main::auth->assert('config');
1387 AM->get_tax_accounts(\%myconfig, \%$form);
1389 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1391 $main::lxdebug->leave_sub();
1395 $main::lxdebug->enter_sub();
1397 my $form = $main::form;
1398 my %myconfig = %main::myconfig;
1399 my $locale = $main::locale;
1401 $main::auth->assert('config');
1403 $form->error($locale->text('Taxkey missing!')) unless length($form->{taxkey}) != 0;
1404 $form->error($locale->text('Taxdescription missing!')) unless length($form->{taxdescription}) != 0;
1405 $form->error($locale->text('Taxrate missing!')) unless length($form->{rate}) != 0;
1407 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1409 if ($form->{taxkey} == 0 and $form->{rate} > 0) {
1410 $form->error($locale->text('Taxkey 0 is reserved for rate 0'));
1413 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1414 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1417 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
1418 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1421 my @translation_keys = grep { $_ =~ '^translation_\d+' } keys %$form;
1422 $form->{translations} = { map { $_ =~ '^translation_(\d+)'; $1 => $form->{$_} } @translation_keys };
1424 AM->save_tax(\%myconfig, \%$form);
1425 $form->redirect($locale->text('Tax saved!'));
1427 $main::lxdebug->leave_sub();
1431 $main::lxdebug->enter_sub();
1433 my $form = $main::form;
1434 my %myconfig = %main::myconfig;
1435 my $locale = $main::locale;
1437 $main::auth->assert('config');
1439 AM->delete_tax(\%myconfig, \%$form);
1440 $form->redirect($locale->text('Tax deleted!'));
1442 $main::lxdebug->leave_sub();
1445 sub add_price_factor {
1446 $main::lxdebug->enter_sub();
1448 my $form = $main::form;
1449 my $locale = $main::locale;
1451 $main::auth->assert('config');
1453 $form->{title} = $locale->text('Add Price Factor');
1454 $form->{callback} ||= build_std_url('action=add_price_factor');
1457 print $form->parse_html_template('am/edit_price_factor');
1459 $main::lxdebug->leave_sub();
1462 sub edit_price_factor {
1463 $main::lxdebug->enter_sub();
1465 my $form = $main::form;
1466 my %myconfig = %main::myconfig;
1467 my $locale = $main::locale;
1469 $main::auth->assert('config');
1471 $form->{title} = $locale->text('Edit Price Factor');
1472 $form->{callback} ||= build_std_url('action=add_price_factor');
1474 AM->get_price_factor(\%myconfig, $form);
1476 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
1479 print $form->parse_html_template('am/edit_price_factor');
1481 $main::lxdebug->leave_sub();
1484 sub list_price_factors {
1485 $main::lxdebug->enter_sub();
1487 my $form = $main::form;
1488 my %myconfig = %main::myconfig;
1489 my $locale = $main::locale;
1491 $main::auth->assert('config');
1493 AM->get_all_price_factors(\%myconfig, \%$form);
1495 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
1496 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
1499 $form->{callback} = build_std_url('action=list_price_factors');
1500 $form->{title} = $locale->text('Price Factors');
1501 $form->{url_base} = build_std_url('callback');
1504 print $form->parse_html_template('am/list_price_factors');
1506 $main::lxdebug->leave_sub();
1509 sub save_price_factor {
1510 $main::lxdebug->enter_sub();
1512 my $form = $main::form;
1513 my %myconfig = %main::myconfig;
1514 my $locale = $main::locale;
1516 $main::auth->assert('config');
1518 $form->isblank("description", $locale->text('Description missing!'));
1519 $form->isblank("factor", $locale->text('Factor missing!'));
1521 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
1523 AM->save_price_factor(\%myconfig, $form);
1525 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
1527 $form->redirect($locale->text('Price factor saved!'));
1529 $main::lxdebug->leave_sub();
1532 sub delete_price_factor {
1533 $main::lxdebug->enter_sub();
1535 my $form = $main::form;
1536 my %myconfig = %main::myconfig;
1537 my $locale = $main::locale;
1539 $main::auth->assert('config');
1541 AM->delete_price_factor(\%myconfig, \%$form);
1543 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
1545 $form->redirect($locale->text('Price factor deleted!'));
1547 $main::lxdebug->leave_sub();
1551 $main::lxdebug->enter_sub();
1553 my $form = $main::form;
1554 my $locale = $main::locale;
1556 $main::auth->assert('config');
1558 $form->{title} = $locale->text('Add Warehouse');
1559 $form->{callback} ||= build_std_url('action=add_warehouse');
1562 print $form->parse_html_template('am/edit_warehouse');
1564 $main::lxdebug->leave_sub();
1567 sub edit_warehouse {
1568 $main::lxdebug->enter_sub();
1570 my $form = $main::form;
1571 my %myconfig = %main::myconfig;
1572 my $locale = $main::locale;
1574 $main::auth->assert('config');
1576 AM->get_warehouse(\%myconfig, $form);
1578 $form->get_lists('employees' => 'EMPLOYEES');
1580 $form->{title} = $locale->text('Edit Warehouse');
1581 $form->{callback} ||= build_std_url('action=list_warehouses');
1584 print $form->parse_html_template('am/edit_warehouse');
1586 $main::lxdebug->leave_sub();
1589 sub list_warehouses {
1590 $main::lxdebug->enter_sub();
1592 my $form = $main::form;
1593 my %myconfig = %main::myconfig;
1594 my $locale = $main::locale;
1596 $main::auth->assert('config');
1598 AM->get_all_warehouses(\%myconfig, $form);
1600 $form->{callback} = build_std_url('action=list_warehouses');
1601 $form->{title} = $locale->text('Warehouses');
1602 $form->{url_base} = build_std_url('callback');
1605 print $form->parse_html_template('am/list_warehouses');
1607 $main::lxdebug->leave_sub();
1610 sub save_warehouse {
1611 $main::lxdebug->enter_sub();
1613 my $form = $main::form;
1614 my %myconfig = %main::myconfig;
1615 my $locale = $main::locale;
1617 $main::auth->assert('config');
1619 $form->isblank("description", $locale->text('Description missing!'));
1621 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
1623 AM->save_warehouse(\%myconfig, $form);
1625 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
1627 $form->redirect($locale->text('Warehouse saved.'));
1629 $main::lxdebug->leave_sub();
1632 sub delete_warehouse {
1633 $main::lxdebug->enter_sub();
1635 my $form = $main::form;
1636 my %myconfig = %main::myconfig;
1637 my $locale = $main::locale;
1639 $main::auth->assert('config');
1641 if (!$form->{confirmed}) {
1642 $form->{title} = $locale->text('Confirmation');
1645 print $form->parse_html_template('am/confirm_delete_warehouse');
1646 $::dispatcher->end_request;
1649 if (AM->delete_warehouse(\%myconfig, $form)) {
1650 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
1651 $form->redirect($locale->text('Warehouse deleted.'));
1654 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
1657 $main::lxdebug->leave_sub();
1661 $main::lxdebug->enter_sub();
1663 my $form = $main::form;
1664 my %myconfig = %main::myconfig;
1665 my $locale = $main::locale;
1667 $main::auth->assert('config');
1669 AM->save_bins(\%myconfig, $form);
1671 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
1673 $form->redirect($locale->text('Bins saved.'));
1675 $main::lxdebug->leave_sub();