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., 51 Franklin Street, Fifth Floor, Boston,
29 #======================================================================
33 #======================================================================
38 use SL::Auth::PasswordPolicy;
50 use SL::DBUtils qw(selectall_array_query conv_dateq);
53 require "bin/mozilla/common.pl";
61 sub add { call_sub("add_$main::form->{type}"); }
62 sub delete { call_sub("delete_$main::form->{type}"); }
63 sub save { call_sub("save_$main::form->{type}"); }
64 sub edit { call_sub("edit_$main::form->{type}"); }
65 sub continue { call_sub($main::form->{"nextsub"}); }
66 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
69 $main::lxdebug->enter_sub();
71 my $form = $main::form;
72 my %myconfig = %main::myconfig;
74 $main::auth->assert('config');
76 $form->{title} = "Add";
77 $form->{charttype} = "A";
78 AM->get_account(\%myconfig, \%$form);
80 $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
85 $main::lxdebug->leave_sub();
89 $main::lxdebug->enter_sub();
91 my $form = $main::form;
92 my %myconfig = %main::myconfig;
93 my $defaults = SL::DB::Default->get;
95 $main::auth->assert('config');
97 $form->{title} = "Edit";
98 $form->{feature_balance} = $defaults->feature_balance;
99 $form->{feature_datev} = $defaults->feature_datev;
100 $form->{feature_erfolgsrechnung} = $defaults->feature_erfolgsrechnung;
101 $form->{feature_eurechnung} = $defaults->feature_eurechnung;
102 $form->{feature_ustva} = $defaults->feature_ustva;
104 AM->get_account(\%myconfig, \%$form);
106 foreach my $item (split(/:/, $form->{link})) {
107 $form->{$item} = "checked";
113 $main::lxdebug->leave_sub();
117 $main::lxdebug->enter_sub();
119 my $form = $main::form;
120 my %myconfig = %main::myconfig;
121 my $locale = $main::locale;
123 $main::auth->assert('config');
125 if ( $form->{action} eq 'edit_account') {
126 $form->{account_exists} = '1';
129 $form->{title} = $locale->text("$form->{title} Account");
131 $form->{"$form->{charttype}_checked"} = "checked";
132 $form->{"$form->{category}_checked"} = "checked";
134 $form->{select_tax} = "";
136 my @tax_report_pos = USTVA->report_variables({
137 myconfig => \%myconfig,
140 attribute => 'position',
144 if (@{ $form->{TAXKEY} }) {
145 foreach my $item (@{ $form->{TAXKEY} }) {
146 $item->{rate} = $item->{rate} * 100 . '%';
149 # Fill in empty row for new Taxkey
150 my $newtaxkey_ref = {
155 taxdescription => '',
159 startdate => $form->{account_exists} ? '' : DateTime->new(year => 1970, month => 1, day => 1)->to_lxoffice,
162 push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
165 foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
167 # Fill in a runningnumber
168 $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
170 # Fill in the Taxkeys as select options
171 foreach my $item (@{ $form->{TAXKEY} }) {
172 if ($item->{id} == $taxkey_used->{tax_id}) {
173 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
174 qq|<option value="$item->{id}" selected="selected">|
175 . sprintf("%.2d", $item->{taxkey})
176 . qq|. $item->{taxdescription} ($item->{rate}) |
177 . $locale->text('Tax-o-matic Account')
178 . qq|: $item->{chart_accno}\n|;
181 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
182 qq|<option value="$item->{id}">|
183 . sprintf("%.2d", $item->{taxkey})
184 . qq|. $item->{taxdescription} ($item->{rate}) |
185 . $locale->text('Tax-o-matic Account')
186 . qq|: $item->{chart_accno}\n|;
191 # Fill in the USTVA Numbers as select options
192 foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
194 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
196 elsif ( $item eq $taxkey_used->{pos_ustva} ) {
197 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
200 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
209 # Newaccount Folgekonto
210 if (@{ $form->{NEWACCOUNT} || [] }) {
211 if (!$form->{new_chart_valid}) {
212 $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
214 foreach my $item (@{ $form->{NEWACCOUNT} }) {
215 if ($item->{id} == $form->{new_chart_id}) {
216 $form->{selectnewaccount} .=
217 qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
218 } elsif (!$form->{new_chart_valid}) {
219 $form->{selectnewaccount} .=
220 qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
226 my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
228 1 => "Umsatzerlöse",
229 2 => "sonstige Erlöse",
230 3 => "Privatanteile",
232 5 => "Ausserordentliche Erträge",
233 6 => "Vereinnahmte Umsatzst.",
234 7 => "Umsatzsteuererstattungen",
235 8 => "Wareneingänge",
236 9 => "Löhne und Gehälter",
237 10 => "Gesetzl. sozialer Aufw.",
239 12 => "Gas, Strom, Wasser",
240 13 => "Instandhaltung",
241 14 => "Steuern, Versich., Beiträge",
243 16 => "Kfz-Versicherungen",
244 17 => "Sonst. Fahrzeugkosten",
245 18 => "Werbe- und Reisekosten",
246 19 => "Instandhaltung u. Werkzeuge",
247 20 => "Fachzeitschriften, Bücher",
248 21 => "Miete für Einrichtungen",
249 22 => "Rechts- und Beratungskosten",
250 23 => "Bürobedarf, Porto, Telefon",
251 24 => "Sonstige Aufwendungen",
252 25 => "Abschreibungen auf Anlagever.",
253 26 => "Abschreibungen auf GWG",
255 28 => "Umsatzsteuerzahlungen",
257 30 => "Ausserordentlicher Aufwand",
258 31 => "Betriebliche Steuern");
259 foreach my $item (sort({ $a <=> $b } keys(%eur))) {
260 my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
261 if ($item == $form->{pos_eur}) {
262 $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
264 $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
269 my $select_er = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
273 foreach my $item (sort({ $a <=> $b } keys(%er))) {
274 my $text = H($::locale->{iconv_utf8}->convert($er{$item}));
275 if ($item == $form->{pos_er}) {
276 $select_er .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
278 $select_er .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
283 my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
286 1 => 'Umsatzerlöse',
287 2 => 'Best.Verdg.FE/UE',
288 3 => 'Aktiv.Eigenleistung',
289 4 => 'Mat./Wareneinkauf',
290 5 => 'So.betr.Erlöse',
291 10 => 'Personalkosten',
293 12 => 'Betriebl.Steuern',
294 13 => 'Vers./Beiträge',
295 14 => 'Kfz.Kosten o.St.',
296 15 => 'Werbe-Reisek.',
297 16 => 'Kosten Warenabgabe',
298 17 => 'Abschreibungen',
299 18 => 'Rep./instandhlt.',
300 19 => 'Ãœbrige Steuern',
301 20 => 'Sonst.Kosten',
303 31 => 'Sonst.neutr.Aufw.',
304 32 => 'Zinserträge',
305 33 => 'Sonst.neutr.Ertrag',
306 34 => 'Verr.kalk.Kosten',
307 35 => 'Steuern Eink.u.Ertr.');
308 foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
309 my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
310 if ($item == $form->{pos_bwa}) {
311 $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
313 $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
318 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
319 my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
320 foreach my $item ((1, 2, 3, 4)) {
321 if ($item == $form->{pos_bilanz}) {
322 $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
324 $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
329 # this is for our parser only! Do not remove.
330 # type=submit $locale->text('Add Account')
331 # type=submit $locale->text('Edit Account')
333 $form->{type} = "account";
335 # preselections category
337 my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
340 'A' => $locale->text('Asset'),
341 'L' => $locale->text('Liability'),
342 'Q' => $locale->text('Equity'),
343 'I' => $locale->text('Revenue'),
344 'E' => $locale->text('Expense'),
345 'C' => $locale->text('Costs'),
347 foreach my $item ( sort({ $a <=> $b } keys %category) ) {
348 if ($item eq $form->{category}) {
349 $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
351 $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
356 # preselection chart type
357 my @all_charttypes = ({'name' => $locale->text('Account'), 'value' => 'A'},
358 {'name' => $locale->text('Heading'), 'value' => 'H'},
360 my $selected_charttype = $form->{charttype};
363 # account where AR_tax or AP_tax is set are not orphaned if they are used as
364 # tax-o-matic account
365 if ( $form->{id} && $form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
366 if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
367 $form->{orphaned} = 0;
371 my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
372 my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
376 my $parameters_ref = {
377 ChartTypeIsAccount => $ChartTypeIsAccount,
378 AccountIsPosted => $AccountIsPosted,
379 select_category => $select_category,
380 all_charttypes => \@all_charttypes,
381 selected_charttype => $selected_charttype,
382 select_bwa => $select_bwa,
383 select_bilanz => $select_bilanz,
384 select_eur => $select_eur,
385 select_er => $select_er,
388 # Ausgabe des Templates
389 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
392 $main::lxdebug->leave_sub();
396 $::lxdebug->enter_sub;
397 $::auth->assert('config');
399 print $::form->parse_html_template('am/form_footer', {
400 show_save => !$::form->{id}
401 || ($::form->{id} && $::form->{orphaned})
402 || ($::form->{type} eq "account" && !$::form->{new_chart_valid}),
403 show_delete => $::form->{id} && $::form->{orphaned},
404 show_save_as_new => $::form->{id} && $::form->{type} eq "account",
407 $::lxdebug->leave_sub;
411 $main::lxdebug->enter_sub();
413 my $form = $main::form;
414 my %myconfig = %main::myconfig;
415 my $locale = $main::locale;
417 $main::auth->assert('config');
419 $form->isblank("accno", $locale->text('Account Number missing!'));
420 $form->isblank("description", $locale->text('Account Description missing!'));
422 if ($form->{charttype} eq 'A'){
423 $form->isblank("category", $locale->text('Account Type missing!'));
425 my $found_valid_taxkey = 0;
426 foreach my $i (0 .. 10) { # 10 is maximum count of taxkeys in form
427 if ($form->{"taxkey_startdate_$i"} and !$form->{"taxkey_del_$i"}) {
428 $found_valid_taxkey = 1;
432 if ($found_valid_taxkey == 0) {
433 $form->error($locale->text('A valid taxkey is missing!'));
437 $form->redirect($locale->text('Account saved!'))
438 if (AM->save_account(\%myconfig, \%$form));
439 $form->error($locale->text('Cannot save account!'));
441 $main::lxdebug->leave_sub();
444 sub save_as_new_account {
445 $main::lxdebug->enter_sub();
447 my $form = $main::form;
448 my %myconfig = %main::myconfig;
449 my $locale = $main::locale;
451 $main::auth->assert('config');
453 $form->isblank("accno", $locale->text('Account Number missing!'));
454 $form->isblank("description", $locale->text('Account Description missing!'));
456 if ($form->{charttype} eq 'A'){
457 $form->isblank("category", $locale->text('Account Type missing!'));
460 for my $taxkey (0 .. 9) {
461 if ($form->{"taxkey_id_$taxkey"}) {
462 $form->{"taxkey_id_$taxkey"} = "NEW";
467 $form->redirect($locale->text('Account saved!'))
468 if (AM->save_account(\%myconfig, \%$form));
469 $form->error($locale->text('Cannot save account!'));
471 $main::lxdebug->leave_sub();
475 $main::lxdebug->enter_sub();
477 my $form = $main::form;
478 my %myconfig = %main::myconfig;
479 my $locale = $main::locale;
481 $main::auth->assert('config');
483 $form->{callback} = build_std_url('action=list_account');
484 my $link_edit_account = build_std_url('action=edit_account', 'callback');
486 CA->all_accounts(\%myconfig, \%$form);
488 foreach my $ca (@{ $form->{CA} }) {
493 if ($ca->{amount} > 0) {
494 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
496 if ($ca->{amount} < 0) {
497 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
499 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
500 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
503 $::request->{layout}->use_stylesheet("list_accounts.css");
504 $form->{title} = $locale->text('Chart of Accounts');
509 my $parameters_ref = {
510 # hidden_variables => $_hidden_variables_ref,
513 # Ausgabe des Templates
514 print($form->parse_html_template('am/list_accounts', $parameters_ref));
516 $main::lxdebug->leave_sub();
521 sub list_account_details {
522 # Ajax Funktion aus list_account_details
523 $main::lxdebug->enter_sub();
525 my $form = $main::form;
526 my %myconfig = %main::myconfig;
527 my $locale = $main::locale;
529 $main::auth->assert('config');
531 my $chart_id = $form->{args};
533 CA->all_accounts(\%myconfig, \%$form, $chart_id);
535 foreach my $ca (@{ $form->{CA} }) {
537 $ca->{debit} = " ";
538 $ca->{credit} = " ";
540 if ($ca->{amount} > 0) {
542 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
544 if ($ca->{amount} < 0) {
546 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
549 my @links = split( q{:}, $ca->{link});
553 foreach my $link (@links){
554 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
555 : ( $link eq 'AP') ? $locale->text('Account Link AP')
556 : ( $link eq 'IC') ? $locale->text('Account Link IC')
557 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
558 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
559 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
560 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
561 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
562 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
563 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
564 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
565 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
566 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
567 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
568 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
569 : $locale->text('Unknown Link') . ': ' . $link;
570 $ca->{link} .= ($link ne '') ? "[$link] ":'';
573 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
574 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
575 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
576 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
577 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
578 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
579 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
580 : $locale->text('Unknown Category') . ': ' . $ca->{category};
583 $form->{title} = $locale->text('Chart of Accounts');
585 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
587 $main::lxdebug->leave_sub();
592 $main::lxdebug->enter_sub();
594 my $form = $main::form;
595 my %myconfig = %main::myconfig;
596 my $locale = $main::locale;
598 $main::auth->assert('config');
600 $form->{title} = $locale->text('Delete Account');
603 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id rndgain_accno_id rndloss_accno_id)
605 if ($form->{id} == $form->{$id}) {
606 $form->error($locale->text('Cannot delete default account!'));
610 $form->redirect($locale->text('Account deleted!'))
611 if (AM->delete_account(\%myconfig, \%$form));
612 $form->error($locale->text('Cannot delete account!'));
614 $main::lxdebug->leave_sub();
618 $main::lxdebug->enter_sub();
620 my $form = $main::form;
622 $main::auth->assert('config');
624 $form->{title} = "Add";
626 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
631 $main::lxdebug->leave_sub();
635 $main::lxdebug->enter_sub();
637 my $form = $main::form;
638 my %myconfig = %main::myconfig;
640 $main::auth->assert('config');
642 $form->{title} = "Edit";
644 AM->get_language(\%myconfig, \%$form);
648 $form->{orphaned} = 1;
651 $main::lxdebug->leave_sub();
655 $::lxdebug->enter_sub;
656 $::auth->assert('config');
658 AM->language(\%::myconfig, $::form);
660 $::form->{callback} = "am.pl?action=list_language";
661 $::form->{title} = $::locale->text('Languages');
665 print $::form->parse_html_template('am/language_list');
667 $::lxdebug->leave_sub;
670 sub language_header {
671 $::lxdebug->enter_sub;
672 $::auth->assert('config');
674 # $locale->text('Add Language')
675 # $locale->text('Edit Language')
676 $::form->{title} = $::locale->text("$::form->{title} Language");
680 print $::form->parse_html_template('am/language_header', {
681 numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00" ],
682 dateformats => [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
685 $::lxdebug->leave_sub;
689 $main::lxdebug->enter_sub();
691 my $form = $main::form;
692 my %myconfig = %main::myconfig;
693 my $locale = $main::locale;
695 $main::auth->assert('config');
697 $form->isblank("description", $locale->text('Language missing!'));
698 $form->isblank("template_code", $locale->text('Template Code missing!'));
699 $form->isblank("article_code", $locale->text('Article Code missing!'));
700 AM->save_language(\%myconfig, \%$form);
701 $form->redirect($locale->text('Language saved!'));
703 $main::lxdebug->leave_sub();
706 sub delete_language {
707 $main::lxdebug->enter_sub();
709 my $form = $main::form;
710 my %myconfig = %main::myconfig;
711 my $locale = $main::locale;
713 $main::auth->assert('config');
715 AM->delete_language(\%myconfig, \%$form);
716 $form->redirect($locale->text('Language deleted!'));
718 $main::lxdebug->leave_sub();
721 sub _build_cfg_options {
722 my $form = $main::form;
723 my %myconfig = %main::myconfig;
726 my $array = uc($idx) . 'S';
728 $form->{$array} = [];
729 foreach my $item (@_) {
730 push @{ $form->{$array} }, {
733 'selected' => $item eq $myconfig{$idx},
739 $main::lxdebug->enter_sub();
741 my $form = $main::form;
742 my %myconfig = %main::myconfig;
743 my $locale = $main::locale;
745 _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
746 _build_cfg_options('timeformat', qw(hh:mm hh:mm:ss));
747 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00"));
750 if ($::lx_office_conf{print_templates}->{opendocument}
751 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
752 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
753 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
754 "value" => "opendocument_pdf" });
756 if ($::lx_office_conf{print_templates}->{latex}) {
757 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
759 push(@formats, { "name" => "HTML", "value" => "html" });
760 if ($::lx_office_conf{print_templates}->{latex}) {
761 push(@formats, { "name" => $locale->text("Postscript"),
762 "value" => "postscript" });
764 if ($::lx_office_conf{print_templates}->{opendocument}) {
765 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
766 "value" => "opendocument" });
769 if (!$myconfig{"template_format"}) {
770 $myconfig{"template_format"} = "pdf";
772 $form->{TEMPLATE_FORMATS} = [];
773 foreach my $item (@formats) {
774 push @{ $form->{TEMPLATE_FORMATS} }, {
775 'name' => $item->{name},
776 'value' => $item->{value},
777 'selected' => $item->{value} eq $myconfig{template_format},
781 if (!$myconfig{"default_media"}) {
782 $myconfig{"default_media"} = "screen";
785 my %selected = ($myconfig{"default_media"} => "selected");
787 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
788 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
789 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
792 $form->{PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
794 my %countrycodes = User->country_codes;
796 $form->{COUNTRYCODES} = [];
797 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
798 push @{ $form->{COUNTRYCODES} }, {
799 'name' => $countrycodes{$countrycode},
800 'value' => $countrycode,
801 'selected' => $countrycode eq $myconfig{countrycode},
805 $form->{STYLESHEETS} = [];
806 foreach my $item (qw(lx-office-erp.css kivitendo.css)) {
807 push @{ $form->{STYLESHEETS} }, {
810 'selected' => $item eq $myconfig{stylesheet},
814 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
815 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
816 $form->{todo_cfg} = { TODO->get_user_config('login' => $::myconfig{login}) };
818 $form->{title} = $locale->text('Edit Preferences for #1', $::myconfig{login});
822 $form->{full_signature} = $form->create_email_signature();
824 print $form->parse_html_template('am/config');
826 $main::lxdebug->leave_sub();
829 sub save_preferences {
830 $main::lxdebug->enter_sub();
832 my $form = $main::form;
833 my %myconfig = %main::myconfig;
834 my $locale = $main::locale;
836 $form->{stylesheet} = $form->{usestylesheet};
838 TODO->save_user_config('login' => $::myconfig{login}, %{ $form->{todo_cfg} || { } });
840 if (AM->save_preferences($form)) {
841 if ($::auth->can_change_password()
842 && defined $form->{new_password}
843 && ($form->{new_password} ne '********')) {
844 my $verifier = SL::Auth::PasswordPolicy->new;
845 my $result = $verifier->verify($form->{new_password});
847 if ($result != SL::Auth::PasswordPolicy->OK()) {
848 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
851 $::auth->change_password($::myconfig{login}, $form->{new_password});
854 $form->redirect($locale->text('Preferences saved!'));
857 $form->error($locale->text('Cannot save preferences!'));
859 $main::lxdebug->leave_sub();
863 $::lxdebug->enter_sub;
864 $::auth->assert('config');
866 $::form->{title} = $::locale->text('Audit Control');
868 AM->closedto(\%::myconfig, $::form);
871 print $::form->parse_html_template('am/audit_control');
873 $::lxdebug->leave_sub;
877 $main::lxdebug->enter_sub();
879 my $form = $main::form;
880 my %myconfig = %main::myconfig;
881 my $locale = $main::locale;
883 $main::auth->assert('config');
885 AM->closebooks(\%myconfig, \%$form);
887 if ($form->{closedto}) {
889 $locale->text('Books closed up to') . " "
890 . $locale->date(\%myconfig, $form->{closedto}, 1));
892 $form->redirect($locale->text('Books are open'));
895 $main::lxdebug->leave_sub();
899 $main::lxdebug->enter_sub();
901 my $form = $main::form;
902 my %myconfig = %main::myconfig;
903 my $locale = $main::locale;
905 $main::auth->assert('config');
907 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
908 AM->units_in_use(\%myconfig, $form, $units);
909 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
911 my @languages = AM->language(\%myconfig, $form, 1);
913 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
916 foreach (@unit_list) {
917 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
918 $_->{"UNITLANGUAGES"} = [];
919 foreach my $lang (@languages) {
920 push(@{ $_->{"UNITLANGUAGES"} },
922 "unit" => $_->{"name"},
923 "language_id" => $lang->{"id"},
924 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
925 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
931 $units = AM->retrieve_units(\%myconfig, $form);
932 my $ddbox = AM->unit_select_data($units, undef, 1);
934 $form->{"title"} = $locale->text("Add and edit units");
936 print($form->parse_html_template("am/edit_units",
937 { "UNITS" => \@unit_list,
938 "NEW_BASE_UNIT_DDBOX" => $ddbox,
939 "LANGUAGES" => \@languages,
942 $main::lxdebug->leave_sub();
946 $main::lxdebug->enter_sub();
948 my $form = $main::form;
949 my %myconfig = %main::myconfig;
950 my $locale = $main::locale;
952 $main::auth->assert('config');
954 $form->isblank("new_name", $locale->text("The name is missing."));
955 my $units = AM->retrieve_units(\%myconfig, $form);
956 my $all_units = AM->retrieve_units(\%myconfig, $form);
957 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
959 my ($base_unit, $factor);
960 if ($form->{"new_base_unit"}) {
961 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
963 $form->isblank("new_factor", $locale->text("The factor is missing."));
964 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
965 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
966 $base_unit = $form->{"new_base_unit"};
970 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
971 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
972 push(@languages, { "id" => $lang->{"id"},
973 "localized" => $form->{"new_localized_$lang->{id}"},
974 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
978 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
980 $form->{"saved_message"} = $locale->text("The unit has been saved.");
984 $main::lxdebug->leave_sub();
987 sub set_unit_languages {
988 $main::lxdebug->enter_sub();
990 my $form = $main::form;
992 $main::auth->assert('config');
994 my ($unit, $languages, $idx) = @_;
996 $unit->{"LANGUAGES"} = [];
998 foreach my $lang (@{$languages}) {
999 push(@{ $unit->{"LANGUAGES"} },
1000 { "id" => $lang->{"id"},
1001 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1002 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1006 $main::lxdebug->leave_sub();
1010 $main::lxdebug->enter_sub();
1012 my $form = $main::form;
1013 my %myconfig = %main::myconfig;
1014 my $locale = $main::locale;
1016 $main::auth->assert('config');
1018 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1019 AM->units_in_use(\%myconfig, $form, $old_units);
1021 my @languages = AM->language(\%myconfig, $form, 1);
1024 my @delete_units = ();
1025 foreach my $i (1..($form->{"rowcount"} * 1)) {
1026 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1028 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1031 if ($form->{"unchangeable_$i"}) {
1032 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1033 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1034 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1038 if ($old_unit->{"in_use"}) {
1039 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1042 if ($form->{"delete_$i"}) {
1043 push(@delete_units, $old_unit->{"name"});
1047 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1049 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1050 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1051 $new_units->{$form->{"name_$i"}} = \%h;
1052 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1053 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1056 foreach my $unit (values(%{$new_units})) {
1057 next unless ($unit->{"old_name"});
1058 if ($unit->{"base_unit"}) {
1059 $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"}))
1060 unless (defined($new_units->{$unit->{"base_unit"}}));
1061 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1062 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1064 $unit->{"base_unit"} = undef;
1065 $unit->{"factor"} = undef;
1069 foreach my $unit (values(%{$new_units})) {
1070 next if ($unit->{"unchanged_unit"});
1072 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1073 my $new_unit = $unit;
1074 while ($new_unit->{"base_unit"}) {
1075 $new_unit->{"seen"} = 1;
1076 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1077 if ($new_unit->{"seen"}) {
1078 $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, " .
1079 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1084 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1086 $form->{"saved_message"} = $locale->text("The units have been saved.");
1090 $main::lxdebug->leave_sub();
1093 sub show_history_search {
1094 $main::lxdebug->enter_sub();
1096 my $form = $main::form;
1097 my $locale = $main::locale;
1099 $main::auth->assert('config');
1101 $form->{title} = $locale->text("History Search");
1104 print $form->parse_html_template("common/search_history");
1106 $main::lxdebug->leave_sub();
1109 sub show_am_history {
1110 $main::lxdebug->enter_sub();
1112 my $form = $main::form;
1113 my %myconfig = %main::myconfig;
1114 my $locale = $main::locale;
1116 $main::auth->assert('config');
1118 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1119 $form->{order} ||= 'h.itime--1';
1121 # my %search = ( "Artikelnummer" => "parts",
1122 # "Kundennummer" => "customer",
1123 # "Lieferantennummer" => "vendor",
1124 # "Projektnummer" => "project",
1125 # "Auftragsnummer" => "oe",
1126 # "Angebotsnummer" => "oe",
1127 # "Eingangsrechnungnummer" => "ap",
1128 # "Ausgangsrechnungnummer" => "ar",
1129 # "Mahnungsnummer" => "dunning",
1130 # "Buchungsnummer" => "gl",
1133 my %searchNo = ( "Artikelnummer" => "partnumber",
1134 "Kundennummer" => "customernumber",
1135 "Lieferantennummer" => "vendornumber",
1136 "Projektnummer" => "projectnumber",
1137 "Auftragsnummer" => "ordnumber",
1138 "Angebotsnummer" => "quonumber",
1139 "Eingangsrechnungnummer" => "invnumber",
1140 "Ausgangsrechnungnummer" => "invnumber",
1141 "Mahnungsnummer" => "dunning_id",
1142 "Buchungsnummer" => "gltransaction"
1145 my $dbh = $form->dbconnect(\%myconfig);
1148 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1149 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1150 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1151 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1152 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1153 } elsif ($form->{mitarbeiter}) {
1154 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1157 my $snumbers_where = '';
1159 if ($form->{'searchid'}) {
1160 $snumbers_where = ' WHERE snumbers = ?';
1161 $snumbers_value = $searchNo{$form->{'what2search'}} . '_' . $form->{'searchid'};
1163 $snumbers_where = ' WHERE snumbers ~ ?';
1164 $snumbers_value = '^' . $searchNo{$form->{'what2search'}};
1166 my $query = qq|SELECT trans_id AS id FROM history_erp $snumbers_where|;
1168 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query, $snumbers_value);
1169 my $daten .= shift @ids;
1170 if (scalar(@ids) > 0 ) {
1171 $daten .= ' OR trans_id IN (' . join(',', @ids) . ')';
1173 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1174 $sort =~ s/.*\.(.*)$/$1/;
1176 $form->{title} = $locale->text("History Search");
1179 print $form->parse_html_template("common/show_history",
1180 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1181 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1184 uc($sort) . "BY" => $sortby,
1185 'callback' => $callback,
1189 $main::lxdebug->leave_sub();
1193 $main::lxdebug->enter_sub();
1195 my $form = $main::form;
1196 my $locale = $main::locale;
1198 $main::auth->assert('config');
1200 $form->{title} = $locale->text('Add');
1202 $form->{callback} ||= "am.pl?action=add_tax";
1204 _get_taxaccount_selection();
1207 $form->{liability} = 1;
1208 $form->{equity} = 1;
1209 $form->{revenue} = 1;
1210 $form->{expense} = 1;
1215 my $parameters_ref = {
1216 # ChartTypeIsAccount => $ChartTypeIsAccount,
1217 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1220 # Ausgabe des Templates
1221 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1223 $main::lxdebug->leave_sub();
1227 $main::lxdebug->enter_sub();
1229 my $form = $main::form;
1230 my %myconfig = %main::myconfig;
1231 my $locale = $main::locale;
1233 $main::auth->assert('config');
1235 $form->{title} = $locale->text('Edit');
1237 AM->get_tax(\%myconfig, \%$form);
1239 _get_taxaccount_selection();
1241 $form->{asset} = $form->{chart_categories} =~ 'A' ? 1 : 0;
1242 $form->{liability} = $form->{chart_categories} =~ 'L' ? 1 : 0;
1243 $form->{equity} = $form->{chart_categories} =~ 'Q' ? 1 : 0;
1244 $form->{revenue} = $form->{chart_categories} =~ 'I' ? 1 : 0;
1245 $form->{expense} = $form->{chart_categories} =~ 'E' ? 1 : 0;
1246 $form->{costs} = $form->{chart_categories} =~ 'C' ? 1 : 0;
1248 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1252 my $parameters_ref = {
1253 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1254 TAX => SL::DB::Manager::Tax->find_by(id => $form->{id}),
1257 # Ausgabe des Templates
1258 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1260 $main::lxdebug->leave_sub();
1264 $main::lxdebug->enter_sub();
1266 my $form = $main::form;
1267 my %myconfig = %main::myconfig;
1268 my $locale = $main::locale;
1270 $main::auth->assert('config');
1272 AM->taxes(\%myconfig, \%$form);
1274 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1276 $form->{callback} = build_std_url('action=list_tax');
1278 $form->{title} = $locale->text('Tax-O-Matic');
1282 my $parameters_ref = {
1285 # Ausgabe des Templates
1286 print($form->parse_html_template('am/list_tax', $parameters_ref));
1288 $main::lxdebug->leave_sub();
1291 sub _get_taxaccount_selection{
1292 $main::lxdebug->enter_sub();
1294 my $form = $main::form;
1295 my %myconfig = %main::myconfig;
1297 $main::auth->assert('config');
1299 AM->get_tax_accounts(\%myconfig, \%$form);
1301 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1303 $main::lxdebug->leave_sub();
1307 $main::lxdebug->enter_sub();
1309 my $form = $main::form;
1310 my %myconfig = %main::myconfig;
1311 my $locale = $main::locale;
1313 $main::auth->assert('config');
1315 $form->error($locale->text('Taxkey missing!')) unless length($form->{taxkey}) != 0;
1316 $form->error($locale->text('Taxdescription missing!')) unless length($form->{taxdescription}) != 0;
1317 $form->error($locale->text('Taxrate missing!')) unless length($form->{rate}) != 0;
1319 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1321 if ($form->{taxkey} == 0 and $form->{rate} > 0) {
1322 $form->error($locale->text('Taxkey 0 is reserved for rate 0'));
1325 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1326 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1329 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
1330 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1333 my @translation_keys = grep { $_ =~ '^translation_\d+' } keys %$form;
1334 $form->{translations} = { map { $_ =~ '^translation_(\d+)'; $1 => $form->{$_} } @translation_keys };
1336 AM->save_tax(\%myconfig, \%$form);
1337 $form->redirect($locale->text('Tax saved!'));
1339 $main::lxdebug->leave_sub();
1343 $main::lxdebug->enter_sub();
1345 my $form = $main::form;
1346 my %myconfig = %main::myconfig;
1347 my $locale = $main::locale;
1349 $main::auth->assert('config');
1351 AM->delete_tax(\%myconfig, \%$form);
1352 $form->redirect($locale->text('Tax deleted!'));
1354 $main::lxdebug->leave_sub();
1357 sub add_price_factor {
1358 $main::lxdebug->enter_sub();
1360 my $form = $main::form;
1361 my $locale = $main::locale;
1363 $main::auth->assert('config');
1365 $form->{title} = $locale->text('Add Price Factor');
1366 $form->{callback} ||= build_std_url('action=add_price_factor');
1369 print $form->parse_html_template('am/edit_price_factor');
1371 $main::lxdebug->leave_sub();
1374 sub edit_price_factor {
1375 $main::lxdebug->enter_sub();
1377 my $form = $main::form;
1378 my %myconfig = %main::myconfig;
1379 my $locale = $main::locale;
1381 $main::auth->assert('config');
1383 $form->{title} = $locale->text('Edit Price Factor');
1384 $form->{callback} ||= build_std_url('action=add_price_factor');
1386 AM->get_price_factor(\%myconfig, $form);
1388 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
1391 print $form->parse_html_template('am/edit_price_factor');
1393 $main::lxdebug->leave_sub();
1396 sub list_price_factors {
1397 $main::lxdebug->enter_sub();
1399 my $form = $main::form;
1400 my %myconfig = %main::myconfig;
1401 my $locale = $main::locale;
1403 $main::auth->assert('config');
1405 AM->get_all_price_factors(\%myconfig, \%$form);
1407 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
1408 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
1411 $form->{callback} = build_std_url('action=list_price_factors');
1412 $form->{title} = $locale->text('Price Factors');
1413 $form->{url_base} = build_std_url('callback');
1416 print $form->parse_html_template('am/list_price_factors');
1418 $main::lxdebug->leave_sub();
1421 sub save_price_factor {
1422 $main::lxdebug->enter_sub();
1424 my $form = $main::form;
1425 my %myconfig = %main::myconfig;
1426 my $locale = $main::locale;
1428 $main::auth->assert('config');
1430 $form->isblank("description", $locale->text('Description missing!'));
1431 $form->isblank("factor", $locale->text('Factor missing!'));
1433 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
1435 AM->save_price_factor(\%myconfig, $form);
1437 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
1439 $form->redirect($locale->text('Price factor saved!'));
1441 $main::lxdebug->leave_sub();
1444 sub delete_price_factor {
1445 $main::lxdebug->enter_sub();
1447 my $form = $main::form;
1448 my %myconfig = %main::myconfig;
1449 my $locale = $main::locale;
1451 $main::auth->assert('config');
1453 AM->delete_price_factor(\%myconfig, \%$form);
1455 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
1457 $form->redirect($locale->text('Price factor deleted!'));
1459 $main::lxdebug->leave_sub();
1463 $main::lxdebug->enter_sub();
1465 my $form = $main::form;
1466 my $locale = $main::locale;
1468 $main::auth->assert('config');
1470 $form->{title} = $locale->text('Add Warehouse');
1471 $form->{callback} ||= build_std_url('action=add_warehouse');
1474 print $form->parse_html_template('am/edit_warehouse');
1476 $main::lxdebug->leave_sub();
1479 sub edit_warehouse {
1480 $main::lxdebug->enter_sub();
1482 my $form = $main::form;
1483 my %myconfig = %main::myconfig;
1484 my $locale = $main::locale;
1486 $main::auth->assert('config');
1488 AM->get_warehouse(\%myconfig, $form);
1490 $form->get_lists('employees' => 'EMPLOYEES');
1492 $form->{title} = $locale->text('Edit Warehouse');
1493 $form->{callback} ||= build_std_url('action=list_warehouses');
1496 print $form->parse_html_template('am/edit_warehouse');
1498 $main::lxdebug->leave_sub();
1501 sub list_warehouses {
1502 $main::lxdebug->enter_sub();
1504 my $form = $main::form;
1505 my %myconfig = %main::myconfig;
1506 my $locale = $main::locale;
1508 $main::auth->assert('config');
1510 AM->get_all_warehouses(\%myconfig, $form);
1512 $form->{callback} = build_std_url('action=list_warehouses');
1513 $form->{title} = $locale->text('Warehouses');
1514 $form->{url_base} = build_std_url('callback');
1517 print $form->parse_html_template('am/list_warehouses');
1519 $main::lxdebug->leave_sub();
1522 sub save_warehouse {
1523 $main::lxdebug->enter_sub();
1525 my $form = $main::form;
1526 my %myconfig = %main::myconfig;
1527 my $locale = $main::locale;
1529 $main::auth->assert('config');
1531 $form->isblank("description", $locale->text('Description missing!'));
1533 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
1535 AM->save_warehouse(\%myconfig, $form);
1537 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
1539 $form->redirect($locale->text('Warehouse saved.'));
1541 $main::lxdebug->leave_sub();
1544 sub delete_warehouse {
1545 $main::lxdebug->enter_sub();
1547 my $form = $main::form;
1548 my %myconfig = %main::myconfig;
1549 my $locale = $main::locale;
1551 $main::auth->assert('config');
1553 if (!$form->{confirmed}) {
1554 $form->{title} = $locale->text('Confirmation');
1557 print $form->parse_html_template('am/confirm_delete_warehouse');
1558 $::dispatcher->end_request;
1561 if (AM->delete_warehouse(\%myconfig, $form)) {
1562 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
1563 $form->redirect($locale->text('Warehouse deleted.'));
1566 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
1569 $main::lxdebug->leave_sub();
1573 $main::lxdebug->enter_sub();
1575 my $form = $main::form;
1576 my %myconfig = %main::myconfig;
1577 my $locale = $main::locale;
1579 $main::auth->assert('config');
1581 AM->save_bins(\%myconfig, $form);
1583 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
1585 $form->redirect($locale->text('Bins saved.'));
1587 $main::lxdebug->leave_sub();