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;
50 require "bin/mozilla/common.pl";
58 sub add { call_sub("add_$main::form->{type}"); }
59 sub delete { call_sub("delete_$main::form->{type}"); }
60 sub save { call_sub("save_$main::form->{type}"); }
61 sub edit { call_sub("edit_$main::form->{type}"); }
62 sub continue { call_sub($main::form->{"nextsub"}); }
63 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
66 $main::lxdebug->enter_sub();
68 my $form = $main::form;
69 my %myconfig = %main::myconfig;
71 $main::auth->assert('config');
73 $form->{title} = "Add";
74 $form->{charttype} = "A";
75 AM->get_account(\%myconfig, \%$form);
77 $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
82 $main::lxdebug->leave_sub();
86 $main::lxdebug->enter_sub();
88 my $form = $main::form;
89 my %myconfig = %main::myconfig;
91 $main::auth->assert('config');
93 $form->{title} = "Edit";
94 AM->get_account(\%myconfig, \%$form);
96 foreach my $item (split(/:/, $form->{link})) {
97 $form->{$item} = "checked";
103 $main::lxdebug->leave_sub();
107 $main::lxdebug->enter_sub();
109 my $form = $main::form;
110 my %myconfig = %main::myconfig;
111 my $locale = $main::locale;
113 $main::auth->assert('config');
115 if ( $form->{action} eq 'edit_account') {
116 $form->{account_exists} = '1';
119 $form->{title} = $locale->text("$form->{title} Account");
121 $form->{"$form->{charttype}_checked"} = "checked";
122 $form->{"$form->{category}_checked"} = "checked";
124 $form->{select_tax} = "";
126 my @tax_report_pos = USTVA->report_variables({
127 myconfig => \%myconfig,
130 attribute => 'position',
134 if (@{ $form->{TAXKEY} }) {
135 foreach my $item (@{ $form->{TAXKEY} }) {
136 $item->{rate} = $item->{rate} * 100 . '%';
139 # Fill in empty row for new Taxkey
140 my $newtaxkey_ref = {
145 taxdescription => '',
149 startdate => $form->{account_exists} ? '' : DateTime->new(year => 1970, month => 1, day => 1)->to_lxoffice,
152 push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
155 foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
157 # Fill in a runningnumber
158 $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
160 # Fill in the Taxkeys as select options
161 foreach my $item (@{ $form->{TAXKEY} }) {
162 if ($item->{id} == $taxkey_used->{tax_id}) {
163 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
164 qq|<option value="$item->{id}" selected="selected">|
165 . sprintf("%.2d", $item->{taxkey})
166 . qq|. $item->{taxdescription} ($item->{rate}) |
167 . $locale->text('Tax-o-matic Account')
168 . qq|: $item->{chart_accno}\n|;
171 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
172 qq|<option value="$item->{id}">|
173 . sprintf("%.2d", $item->{taxkey})
174 . qq|. $item->{taxdescription} ($item->{rate}) |
175 . $locale->text('Tax-o-matic Account')
176 . qq|: $item->{chart_accno}\n|;
181 # Fill in the USTVA Numbers as select options
182 foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
184 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
186 elsif ( $item eq $taxkey_used->{pos_ustva} ) {
187 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
190 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
199 # Newaccount Folgekonto
200 if (@{ $form->{NEWACCOUNT} || [] }) {
201 if (!$form->{new_chart_valid}) {
202 $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
204 foreach my $item (@{ $form->{NEWACCOUNT} }) {
205 if ($item->{id} == $form->{new_chart_id}) {
206 $form->{selectnewaccount} .=
207 qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
208 } elsif (!$form->{new_chart_valid}) {
209 $form->{selectnewaccount} .=
210 qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
216 my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
219 2 => "sonstige Erlöse",
220 3 => "Privatanteile",
222 5 => "Ausserordentliche Erträge",
223 6 => "Vereinnahmte Umsatzst.",
224 7 => "Umsatzsteuererstattungen",
225 8 => "Wareneingänge",
226 9 => "Löhne und Gehälter",
227 10 => "Gesetzl. sozialer Aufw.",
229 12 => "Gas, Strom, Wasser",
230 13 => "Instandhaltung",
231 14 => "Steuern, Versich., Beiträge",
233 16 => "Kfz-Versicherungen",
234 17 => "Sonst. Fahrzeugkosten",
235 18 => "Werbe- und Reisekosten",
236 19 => "Instandhaltung u. Werkzeuge",
237 20 => "Fachzeitschriften, Bücher",
238 21 => "Miete für Einrichtungen",
239 22 => "Rechts- und Beratungskosten",
240 23 => "Bürobedarf, Porto, Telefon",
241 24 => "Sonstige Aufwendungen",
242 25 => "Abschreibungen auf Anlagever.",
243 26 => "Abschreibungen auf GWG",
245 28 => "Umsatzsteuerzahlungen",
247 30 => "Ausserordentlicher Aufwand",
248 31 => "Betriebliche Steuern");
249 foreach my $item (sort({ $a <=> $b } keys(%eur))) {
250 my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
251 if ($item == $form->{pos_eur}) {
252 $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
254 $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
259 my $select_er = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
263 foreach my $item (sort({ $a <=> $b } keys(%er))) {
264 my $text = H($::locale->{iconv_utf8}->convert($er{$item}));
265 if ($item == $form->{pos_er}) {
266 $select_er .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
268 $select_er .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
273 my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
277 2 => 'Best.Verdg.FE/UE',
278 3 => 'Aktiv.Eigenleistung',
279 4 => 'Mat./Wareneinkauf',
280 5 => 'So.betr.Erlöse',
281 10 => 'Personalkosten',
283 12 => 'Betriebl.Steuern',
284 13 => 'Vers./Beiträge',
285 14 => 'Kfz.Kosten o.St.',
286 15 => 'Werbe-Reisek.',
287 16 => 'Kosten Warenabgabe',
288 17 => 'Abschreibungen',
289 18 => 'Rep./instandhlt.',
290 19 => 'Übrige Steuern',
291 20 => 'Sonst.Kosten',
293 31 => 'Sonst.neutr.Aufw.',
295 33 => 'Sonst.neutr.Ertrag',
296 34 => 'Verr.kalk.Kosten',
297 35 => 'Steuern Eink.u.Ertr.');
298 foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
299 my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
300 if ($item == $form->{pos_bwa}) {
301 $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
303 $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
308 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
309 my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
310 foreach my $item ((1, 2, 3, 4)) {
311 if ($item == $form->{pos_bilanz}) {
312 $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
314 $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
319 # this is for our parser only! Do not remove.
320 # type=submit $locale->text('Add Account')
321 # type=submit $locale->text('Edit Account')
323 $form->{type} = "account";
325 # preselections category
327 my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
330 'A' => $locale->text('Asset'),
331 'L' => $locale->text('Liability'),
332 'Q' => $locale->text('Equity'),
333 'I' => $locale->text('Revenue'),
334 'E' => $locale->text('Expense'),
335 'C' => $locale->text('Costs'),
337 foreach my $item ( sort({ $a <=> $b } keys %category) ) {
338 if ($item eq $form->{category}) {
339 $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
341 $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
346 # preselection chart type
347 my @all_charttypes = ({'name' => $locale->text('Account'), 'value' => 'A'},
348 {'name' => $locale->text('Heading'), 'value' => 'H'},
350 my $selected_charttype = $form->{charttype};
353 # account where AR_tax or AP_tax is set are not orphaned if they are used as
354 # tax-o-matic account
355 if ( $form->{id} && $form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
356 if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
357 $form->{orphaned} = 0;
361 my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
362 my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
366 my $parameters_ref = {
367 ChartTypeIsAccount => $ChartTypeIsAccount,
368 AccountIsPosted => $AccountIsPosted,
369 select_category => $select_category,
370 all_charttypes => \@all_charttypes,
371 selected_charttype => $selected_charttype,
372 select_bwa => $select_bwa,
373 select_bilanz => $select_bilanz,
374 select_eur => $select_eur,
375 select_er => $select_er,
378 # Ausgabe des Templates
379 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
382 $main::lxdebug->leave_sub();
386 $::lxdebug->enter_sub;
387 $::auth->assert('config');
389 print $::form->parse_html_template('am/form_footer', {
390 show_save => !$::form->{id}
391 || ($::form->{id} && $::form->{orphaned})
392 || ($::form->{type} eq "account" && !$::form->{new_chart_valid}),
393 show_delete => $::form->{id} && $::form->{orphaned},
394 show_save_as_new => $::form->{id} && $::form->{type} eq "account",
397 $::lxdebug->leave_sub;
401 $main::lxdebug->enter_sub();
403 my $form = $main::form;
404 my %myconfig = %main::myconfig;
405 my $locale = $main::locale;
407 $main::auth->assert('config');
409 $form->isblank("accno", $locale->text('Account Number missing!'));
410 $form->isblank("description", $locale->text('Account Description missing!'));
412 if ($form->{charttype} eq 'A'){
413 $form->isblank("category", $locale->text('Account Type missing!'));
415 my $found_valid_taxkey = 0;
416 foreach my $i (0 .. 10) { # 10 is maximum count of taxkeys in form
417 if ($form->{"taxkey_startdate_$i"} and !$form->{"taxkey_del_$i"}) {
418 $found_valid_taxkey = 1;
422 if ($found_valid_taxkey == 0) {
423 $form->error($locale->text('A valid taxkey is missing!'));
427 $form->redirect($locale->text('Account saved!'))
428 if (AM->save_account(\%myconfig, \%$form));
429 $form->error($locale->text('Cannot save account!'));
431 $main::lxdebug->leave_sub();
434 sub save_as_new_account {
435 $main::lxdebug->enter_sub();
437 my $form = $main::form;
438 my %myconfig = %main::myconfig;
439 my $locale = $main::locale;
441 $main::auth->assert('config');
443 $form->isblank("accno", $locale->text('Account Number missing!'));
444 $form->isblank("description", $locale->text('Account Description missing!'));
446 if ($form->{charttype} eq 'A'){
447 $form->isblank("category", $locale->text('Account Type missing!'));
450 for my $taxkey (0 .. 9) {
451 if ($form->{"taxkey_id_$taxkey"}) {
452 $form->{"taxkey_id_$taxkey"} = "NEW";
457 $form->redirect($locale->text('Account saved!'))
458 if (AM->save_account(\%myconfig, \%$form));
459 $form->error($locale->text('Cannot save account!'));
461 $main::lxdebug->leave_sub();
465 $main::lxdebug->enter_sub();
467 my $form = $main::form;
468 my %myconfig = %main::myconfig;
469 my $locale = $main::locale;
471 $main::auth->assert('config');
473 $form->{callback} = build_std_url('action=list_account');
474 my $link_edit_account = build_std_url('action=edit_account', 'callback');
476 CA->all_accounts(\%myconfig, \%$form);
478 foreach my $ca (@{ $form->{CA} }) {
483 if ($ca->{amount} > 0) {
484 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
486 if ($ca->{amount} < 0) {
487 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
489 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
490 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
493 $::request->{layout}->use_stylesheet("list_accounts.css");
494 $form->{title} = $locale->text('Chart of Accounts');
499 my $parameters_ref = {
500 # hidden_variables => $_hidden_variables_ref,
503 # Ausgabe des Templates
504 print($form->parse_html_template('am/list_accounts', $parameters_ref));
506 $main::lxdebug->leave_sub();
511 sub list_account_details {
512 # Ajax Funktion aus list_account_details
513 $main::lxdebug->enter_sub();
515 my $form = $main::form;
516 my %myconfig = %main::myconfig;
517 my $locale = $main::locale;
519 $main::auth->assert('config');
521 my $chart_id = $form->{args};
523 CA->all_accounts(\%myconfig, \%$form, $chart_id);
525 foreach my $ca (@{ $form->{CA} }) {
527 $ca->{debit} = " ";
528 $ca->{credit} = " ";
530 if ($ca->{amount} > 0) {
532 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
534 if ($ca->{amount} < 0) {
536 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
539 my @links = split( q{:}, $ca->{link});
543 foreach my $link (@links){
544 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
545 : ( $link eq 'AP') ? $locale->text('Account Link AP')
546 : ( $link eq 'IC') ? $locale->text('Account Link IC')
547 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
548 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
549 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
550 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
551 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
552 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
553 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
554 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
555 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
556 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
557 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
558 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
559 : $locale->text('Unknown Link') . ': ' . $link;
560 $ca->{link} .= ($link ne '') ? "[$link] ":'';
563 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
564 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
565 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
566 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
567 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
568 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
569 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
570 : $locale->text('Unknown Category') . ': ' . $ca->{category};
573 $form->{title} = $locale->text('Chart of Accounts');
575 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
577 $main::lxdebug->leave_sub();
582 $main::lxdebug->enter_sub();
584 my $form = $main::form;
585 my %myconfig = %main::myconfig;
586 my $locale = $main::locale;
588 $main::auth->assert('config');
590 $form->{title} = $locale->text('Delete Account');
593 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id rndgain_accno_id rndloss_accno_id)
595 if ($form->{id} == $form->{$id}) {
596 $form->error($locale->text('Cannot delete default account!'));
600 $form->redirect($locale->text('Account deleted!'))
601 if (AM->delete_account(\%myconfig, \%$form));
602 $form->error($locale->text('Cannot delete account!'));
604 $main::lxdebug->leave_sub();
608 $main::lxdebug->enter_sub();
610 my $form = $main::form;
612 $main::auth->assert('config');
614 $form->{title} = "Add";
616 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
621 $main::lxdebug->leave_sub();
625 $main::lxdebug->enter_sub();
627 my $form = $main::form;
628 my %myconfig = %main::myconfig;
630 $main::auth->assert('config');
632 $form->{title} = "Edit";
634 AM->get_lead(\%myconfig, \%$form);
638 $form->{orphaned} = 1;
641 $main::lxdebug->leave_sub();
645 $::lxdebug->enter_sub;
646 $::auth->assert('config');
648 AM->lead(\%::myconfig, $::form);
650 $::form->{callback} = "am.pl?action=list_lead";
651 $::form->{title} = $::locale->text('Lead');
654 print $::form->parse_html_template('am/lead_list');
656 $::lxdebug->leave_sub;
660 $::lxdebug->enter_sub;
661 $::auth->assert('config');
663 # $locale->text('Add Lead')
664 # $locale->text('Edit Lead')
665 $::form->{title} = $::locale->text("$::form->{title} Lead");
668 print $::form->parse_html_template('am/lead_header');
670 $::lxdebug->leave_sub;
674 $main::lxdebug->enter_sub();
676 my $form = $main::form;
677 my %myconfig = %main::myconfig;
678 my $locale = $main::locale;
680 $main::auth->assert('config');
682 $form->isblank("description", $locale->text('Description missing!'));
683 AM->save_lead(\%myconfig, \%$form);
684 $form->redirect($locale->text('lead saved!'));
686 $main::lxdebug->leave_sub();
690 $main::lxdebug->enter_sub();
692 my $form = $main::form;
693 my %myconfig = %main::myconfig;
694 my $locale = $main::locale;
696 $main::auth->assert('config');
698 AM->delete_lead(\%myconfig, \%$form);
699 $form->redirect($locale->text('lead deleted!'));
701 $main::lxdebug->leave_sub();
705 $main::lxdebug->enter_sub();
707 my $form = $main::form;
709 $main::auth->assert('config');
711 $form->{title} = "Add";
713 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
718 $main::lxdebug->leave_sub();
722 $main::lxdebug->enter_sub();
724 my $form = $main::form;
725 my %myconfig = %main::myconfig;
727 $main::auth->assert('config');
729 $form->{title} = "Edit";
731 AM->get_language(\%myconfig, \%$form);
735 $form->{orphaned} = 1;
738 $main::lxdebug->leave_sub();
742 $::lxdebug->enter_sub;
743 $::auth->assert('config');
745 AM->language(\%::myconfig, $::form);
747 $::form->{callback} = "am.pl?action=list_language";
748 $::form->{title} = $::locale->text('Languages');
752 print $::form->parse_html_template('am/language_list');
754 $::lxdebug->leave_sub;
757 sub language_header {
758 $::lxdebug->enter_sub;
759 $::auth->assert('config');
761 # $locale->text('Add Language')
762 # $locale->text('Edit Language')
763 $::form->{title} = $::locale->text("$::form->{title} Language");
767 print $::form->parse_html_template('am/language_header', {
768 numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00" ],
769 dateformats => [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
772 $::lxdebug->leave_sub;
776 $main::lxdebug->enter_sub();
778 my $form = $main::form;
779 my %myconfig = %main::myconfig;
780 my $locale = $main::locale;
782 $main::auth->assert('config');
784 $form->isblank("description", $locale->text('Language missing!'));
785 $form->isblank("template_code", $locale->text('Template Code missing!'));
786 $form->isblank("article_code", $locale->text('Article Code missing!'));
787 AM->save_language(\%myconfig, \%$form);
788 $form->redirect($locale->text('Language saved!'));
790 $main::lxdebug->leave_sub();
793 sub delete_language {
794 $main::lxdebug->enter_sub();
796 my $form = $main::form;
797 my %myconfig = %main::myconfig;
798 my $locale = $main::locale;
800 $main::auth->assert('config');
802 AM->delete_language(\%myconfig, \%$form);
803 $form->redirect($locale->text('Language deleted!'));
805 $main::lxdebug->leave_sub();
808 sub _build_cfg_options {
809 my $form = $main::form;
810 my %myconfig = %main::myconfig;
813 my $array = uc($idx) . 'S';
815 $form->{$array} = [];
816 foreach my $item (@_) {
817 push @{ $form->{$array} }, {
820 'selected' => $item eq $myconfig{$idx},
826 $main::lxdebug->enter_sub();
828 my $form = $main::form;
829 my %myconfig = %main::myconfig;
830 my $locale = $main::locale;
832 _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
833 _build_cfg_options('timeformat', qw(hh:mm hh:mm:ss));
834 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00"));
837 if ($::lx_office_conf{print_templates}->{opendocument}
838 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
839 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
840 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
841 "value" => "opendocument_pdf" });
843 if ($::lx_office_conf{print_templates}->{latex}) {
844 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
846 push(@formats, { "name" => "HTML", "value" => "html" });
847 if ($::lx_office_conf{print_templates}->{latex}) {
848 push(@formats, { "name" => $locale->text("Postscript"),
849 "value" => "postscript" });
851 if ($::lx_office_conf{print_templates}->{opendocument}) {
852 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
853 "value" => "opendocument" });
856 if (!$myconfig{"template_format"}) {
857 $myconfig{"template_format"} = "pdf";
859 $form->{TEMPLATE_FORMATS} = [];
860 foreach my $item (@formats) {
861 push @{ $form->{TEMPLATE_FORMATS} }, {
862 'name' => $item->{name},
863 'value' => $item->{value},
864 'selected' => $item->{value} eq $myconfig{template_format},
868 if (!$myconfig{"default_media"}) {
869 $myconfig{"default_media"} = "screen";
872 my %selected = ($myconfig{"default_media"} => "selected");
874 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
875 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
876 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
879 $form->{PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
881 my %countrycodes = User->country_codes;
883 $form->{COUNTRYCODES} = [];
884 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
885 push @{ $form->{COUNTRYCODES} }, {
886 'name' => $countrycodes{$countrycode},
887 'value' => $countrycode,
888 'selected' => $countrycode eq $myconfig{countrycode},
892 $form->{STYLESHEETS} = [];
893 foreach my $item (qw(lx-office-erp.css kivitendo.css)) {
894 push @{ $form->{STYLESHEETS} }, {
897 'selected' => $item eq $myconfig{stylesheet},
901 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
902 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
903 $form->{todo_cfg} = { TODO->get_user_config('login' => $::myconfig{login}) };
905 $form->{title} = $locale->text('Edit Preferences for #1', $::myconfig{login});
909 $form->{full_signature} = $form->create_email_signature();
911 print $form->parse_html_template('am/config');
913 $main::lxdebug->leave_sub();
916 sub save_preferences {
917 $main::lxdebug->enter_sub();
919 my $form = $main::form;
920 my %myconfig = %main::myconfig;
921 my $locale = $main::locale;
923 $form->{stylesheet} = $form->{usestylesheet};
925 TODO->save_user_config('login' => $::myconfig{login}, %{ $form->{todo_cfg} || { } });
927 if (AM->save_preferences($form)) {
928 if ($::auth->can_change_password()
929 && defined $form->{new_password}
930 && ($form->{new_password} ne '********')) {
931 my $verifier = SL::Auth::PasswordPolicy->new;
932 my $result = $verifier->verify($form->{new_password});
934 if ($result != SL::Auth::PasswordPolicy->OK()) {
935 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
938 $::auth->change_password($::myconfig{login}, $form->{new_password});
941 $form->redirect($locale->text('Preferences saved!'));
944 $form->error($locale->text('Cannot save preferences!'));
946 $main::lxdebug->leave_sub();
950 $::lxdebug->enter_sub;
951 $::auth->assert('config');
953 $::form->{title} = $::locale->text('Audit Control');
955 AM->closedto(\%::myconfig, $::form);
958 print $::form->parse_html_template('am/audit_control');
960 $::lxdebug->leave_sub;
964 $main::lxdebug->enter_sub();
966 my $form = $main::form;
967 my %myconfig = %main::myconfig;
968 my $locale = $main::locale;
970 $main::auth->assert('config');
972 AM->closebooks(\%myconfig, \%$form);
974 if ($form->{closedto}) {
976 $locale->text('Books closed up to') . " "
977 . $locale->date(\%myconfig, $form->{closedto}, 1));
979 $form->redirect($locale->text('Books are open'));
982 $main::lxdebug->leave_sub();
986 $main::lxdebug->enter_sub();
988 my $form = $main::form;
989 my %myconfig = %main::myconfig;
990 my $locale = $main::locale;
992 $main::auth->assert('config');
994 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
995 AM->units_in_use(\%myconfig, $form, $units);
996 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
998 my @languages = AM->language(\%myconfig, $form, 1);
1000 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1003 foreach (@unit_list) {
1004 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1005 $_->{"UNITLANGUAGES"} = [];
1006 foreach my $lang (@languages) {
1007 push(@{ $_->{"UNITLANGUAGES"} },
1009 "unit" => $_->{"name"},
1010 "language_id" => $lang->{"id"},
1011 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1012 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1018 $units = AM->retrieve_units(\%myconfig, $form);
1019 my $ddbox = AM->unit_select_data($units, undef, 1);
1021 $form->{"title"} = $locale->text("Add and edit units");
1023 print($form->parse_html_template("am/edit_units",
1024 { "UNITS" => \@unit_list,
1025 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1026 "LANGUAGES" => \@languages,
1029 $main::lxdebug->leave_sub();
1033 $main::lxdebug->enter_sub();
1035 my $form = $main::form;
1036 my %myconfig = %main::myconfig;
1037 my $locale = $main::locale;
1039 $main::auth->assert('config');
1041 $form->isblank("new_name", $locale->text("The name is missing."));
1042 my $units = AM->retrieve_units(\%myconfig, $form);
1043 my $all_units = AM->retrieve_units(\%myconfig, $form);
1044 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1046 my ($base_unit, $factor);
1047 if ($form->{"new_base_unit"}) {
1048 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1050 $form->isblank("new_factor", $locale->text("The factor is missing."));
1051 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1052 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1053 $base_unit = $form->{"new_base_unit"};
1057 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1058 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1059 push(@languages, { "id" => $lang->{"id"},
1060 "localized" => $form->{"new_localized_$lang->{id}"},
1061 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1065 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1067 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1071 $main::lxdebug->leave_sub();
1074 sub set_unit_languages {
1075 $main::lxdebug->enter_sub();
1077 my $form = $main::form;
1079 $main::auth->assert('config');
1081 my ($unit, $languages, $idx) = @_;
1083 $unit->{"LANGUAGES"} = [];
1085 foreach my $lang (@{$languages}) {
1086 push(@{ $unit->{"LANGUAGES"} },
1087 { "id" => $lang->{"id"},
1088 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1089 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1093 $main::lxdebug->leave_sub();
1097 $main::lxdebug->enter_sub();
1099 my $form = $main::form;
1100 my %myconfig = %main::myconfig;
1101 my $locale = $main::locale;
1103 $main::auth->assert('config');
1105 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1106 AM->units_in_use(\%myconfig, $form, $old_units);
1108 my @languages = AM->language(\%myconfig, $form, 1);
1111 my @delete_units = ();
1112 foreach my $i (1..($form->{"rowcount"} * 1)) {
1113 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1115 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1118 if ($form->{"unchangeable_$i"}) {
1119 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1120 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1121 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1125 if ($old_unit->{"in_use"}) {
1126 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1129 if ($form->{"delete_$i"}) {
1130 push(@delete_units, $old_unit->{"name"});
1134 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1136 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1137 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1138 $new_units->{$form->{"name_$i"}} = \%h;
1139 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1140 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1143 foreach my $unit (values(%{$new_units})) {
1144 next unless ($unit->{"old_name"});
1145 if ($unit->{"base_unit"}) {
1146 $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"}))
1147 unless (defined($new_units->{$unit->{"base_unit"}}));
1148 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1149 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1151 $unit->{"base_unit"} = undef;
1152 $unit->{"factor"} = undef;
1156 foreach my $unit (values(%{$new_units})) {
1157 next if ($unit->{"unchanged_unit"});
1159 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1160 my $new_unit = $unit;
1161 while ($new_unit->{"base_unit"}) {
1162 $new_unit->{"seen"} = 1;
1163 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1164 if ($new_unit->{"seen"}) {
1165 $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, " .
1166 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1171 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1173 $form->{"saved_message"} = $locale->text("The units have been saved.");
1177 $main::lxdebug->leave_sub();
1180 sub show_history_search {
1181 $main::lxdebug->enter_sub();
1183 my $form = $main::form;
1184 my $locale = $main::locale;
1186 $main::auth->assert('config');
1188 $form->{title} = $locale->text("History Search");
1191 print $form->parse_html_template("common/search_history");
1193 $main::lxdebug->leave_sub();
1196 sub show_am_history {
1197 $main::lxdebug->enter_sub();
1199 my $form = $main::form;
1200 my %myconfig = %main::myconfig;
1201 my $locale = $main::locale;
1203 $main::auth->assert('config');
1205 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1206 $form->{order} ||= 'h.itime--1';
1208 # my %search = ( "Artikelnummer" => "parts",
1209 # "Kundennummer" => "customer",
1210 # "Lieferantennummer" => "vendor",
1211 # "Projektnummer" => "project",
1212 # "Auftragsnummer" => "oe",
1213 # "Angebotsnummer" => "oe",
1214 # "Eingangsrechnungnummer" => "ap",
1215 # "Ausgangsrechnungnummer" => "ar",
1216 # "Mahnungsnummer" => "dunning",
1217 # "Buchungsnummer" => "gl",
1220 my %searchNo = ( "Artikelnummer" => "partnumber",
1221 "Kundennummer" => "customernumber",
1222 "Lieferantennummer" => "vendornumber",
1223 "Projektnummer" => "projectnumber",
1224 "Auftragsnummer" => "ordnumber",
1225 "Angebotsnummer" => "quonumber",
1226 "Eingangsrechnungnummer" => "invnumber",
1227 "Ausgangsrechnungnummer" => "invnumber",
1228 "Mahnungsnummer" => "dunning_id",
1229 "Buchungsnummer" => "gltransaction"
1232 my $dbh = $form->dbconnect(\%myconfig);
1235 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1236 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1237 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1238 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1239 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1240 } elsif ($form->{mitarbeiter}) {
1241 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1244 my $query = qq|SELECT trans_id AS id FROM history_erp | .
1245 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
1246 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
1248 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
1249 my $daten .= shift @ids;
1250 $daten .= join '', map { " OR trans_id = $_" } @ids;
1252 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1253 $sort =~ s/.*\.(.*)$/$1/;
1255 $form->{title} = $locale->text("History Search");
1258 print $form->parse_html_template("common/show_history",
1259 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1260 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1263 uc($sort) . "BY" => $sortby,
1264 'callback' => $callback,
1268 $main::lxdebug->leave_sub();
1272 $main::lxdebug->enter_sub();
1274 my $form = $main::form;
1275 my $locale = $main::locale;
1277 $main::auth->assert('config');
1279 $form->{title} = $locale->text('Add');
1281 $form->{callback} ||= "am.pl?action=add_tax";
1283 _get_taxaccount_selection();
1286 $form->{liability} = 1;
1287 $form->{equity} = 1;
1288 $form->{revenue} = 1;
1289 $form->{expense} = 1;
1294 my $parameters_ref = {
1295 # ChartTypeIsAccount => $ChartTypeIsAccount,
1296 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1299 # Ausgabe des Templates
1300 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1302 $main::lxdebug->leave_sub();
1306 $main::lxdebug->enter_sub();
1308 my $form = $main::form;
1309 my %myconfig = %main::myconfig;
1310 my $locale = $main::locale;
1312 $main::auth->assert('config');
1314 $form->{title} = $locale->text('Edit');
1316 AM->get_tax(\%myconfig, \%$form);
1318 _get_taxaccount_selection();
1320 $form->{asset} = $form->{chart_categories} =~ 'A' ? 1 : 0;
1321 $form->{liability} = $form->{chart_categories} =~ 'L' ? 1 : 0;
1322 $form->{equity} = $form->{chart_categories} =~ 'Q' ? 1 : 0;
1323 $form->{revenue} = $form->{chart_categories} =~ 'I' ? 1 : 0;
1324 $form->{expense} = $form->{chart_categories} =~ 'E' ? 1 : 0;
1325 $form->{costs} = $form->{chart_categories} =~ 'C' ? 1 : 0;
1327 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1331 my $parameters_ref = {
1332 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1333 TAX => SL::DB::Manager::Tax->find_by(id => $form->{id}),
1336 # Ausgabe des Templates
1337 print($form->parse_html_template('am/edit_tax', $parameters_ref));
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->taxes(\%myconfig, \%$form);
1353 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1355 $form->{callback} = build_std_url('action=list_tax');
1357 $form->{title} = $locale->text('Tax-O-Matic');
1361 my $parameters_ref = {
1364 # Ausgabe des Templates
1365 print($form->parse_html_template('am/list_tax', $parameters_ref));
1367 $main::lxdebug->leave_sub();
1370 sub _get_taxaccount_selection{
1371 $main::lxdebug->enter_sub();
1373 my $form = $main::form;
1374 my %myconfig = %main::myconfig;
1376 $main::auth->assert('config');
1378 AM->get_tax_accounts(\%myconfig, \%$form);
1380 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1382 $main::lxdebug->leave_sub();
1386 $main::lxdebug->enter_sub();
1388 my $form = $main::form;
1389 my %myconfig = %main::myconfig;
1390 my $locale = $main::locale;
1392 $main::auth->assert('config');
1394 $form->error($locale->text('Taxkey missing!')) unless length($form->{taxkey}) != 0;
1395 $form->error($locale->text('Taxdescription missing!')) unless length($form->{taxdescription}) != 0;
1396 $form->error($locale->text('Taxrate missing!')) unless length($form->{rate}) != 0;
1398 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1400 if ($form->{taxkey} == 0 and $form->{rate} > 0) {
1401 $form->error($locale->text('Taxkey 0 is reserved for rate 0'));
1404 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1405 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1408 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
1409 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1412 my @translation_keys = grep { $_ =~ '^translation_\d+' } keys %$form;
1413 $form->{translations} = { map { $_ =~ '^translation_(\d+)'; $1 => $form->{$_} } @translation_keys };
1415 AM->save_tax(\%myconfig, \%$form);
1416 $form->redirect($locale->text('Tax saved!'));
1418 $main::lxdebug->leave_sub();
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 AM->delete_tax(\%myconfig, \%$form);
1431 $form->redirect($locale->text('Tax deleted!'));
1433 $main::lxdebug->leave_sub();
1436 sub add_price_factor {
1437 $main::lxdebug->enter_sub();
1439 my $form = $main::form;
1440 my $locale = $main::locale;
1442 $main::auth->assert('config');
1444 $form->{title} = $locale->text('Add Price Factor');
1445 $form->{callback} ||= build_std_url('action=add_price_factor');
1448 print $form->parse_html_template('am/edit_price_factor');
1450 $main::lxdebug->leave_sub();
1453 sub edit_price_factor {
1454 $main::lxdebug->enter_sub();
1456 my $form = $main::form;
1457 my %myconfig = %main::myconfig;
1458 my $locale = $main::locale;
1460 $main::auth->assert('config');
1462 $form->{title} = $locale->text('Edit Price Factor');
1463 $form->{callback} ||= build_std_url('action=add_price_factor');
1465 AM->get_price_factor(\%myconfig, $form);
1467 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
1470 print $form->parse_html_template('am/edit_price_factor');
1472 $main::lxdebug->leave_sub();
1475 sub list_price_factors {
1476 $main::lxdebug->enter_sub();
1478 my $form = $main::form;
1479 my %myconfig = %main::myconfig;
1480 my $locale = $main::locale;
1482 $main::auth->assert('config');
1484 AM->get_all_price_factors(\%myconfig, \%$form);
1486 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
1487 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
1490 $form->{callback} = build_std_url('action=list_price_factors');
1491 $form->{title} = $locale->text('Price Factors');
1492 $form->{url_base} = build_std_url('callback');
1495 print $form->parse_html_template('am/list_price_factors');
1497 $main::lxdebug->leave_sub();
1500 sub save_price_factor {
1501 $main::lxdebug->enter_sub();
1503 my $form = $main::form;
1504 my %myconfig = %main::myconfig;
1505 my $locale = $main::locale;
1507 $main::auth->assert('config');
1509 $form->isblank("description", $locale->text('Description missing!'));
1510 $form->isblank("factor", $locale->text('Factor missing!'));
1512 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
1514 AM->save_price_factor(\%myconfig, $form);
1516 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
1518 $form->redirect($locale->text('Price factor saved!'));
1520 $main::lxdebug->leave_sub();
1523 sub delete_price_factor {
1524 $main::lxdebug->enter_sub();
1526 my $form = $main::form;
1527 my %myconfig = %main::myconfig;
1528 my $locale = $main::locale;
1530 $main::auth->assert('config');
1532 AM->delete_price_factor(\%myconfig, \%$form);
1534 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
1536 $form->redirect($locale->text('Price factor deleted!'));
1538 $main::lxdebug->leave_sub();
1542 $main::lxdebug->enter_sub();
1544 my $form = $main::form;
1545 my $locale = $main::locale;
1547 $main::auth->assert('config');
1549 $form->{title} = $locale->text('Add Warehouse');
1550 $form->{callback} ||= build_std_url('action=add_warehouse');
1553 print $form->parse_html_template('am/edit_warehouse');
1555 $main::lxdebug->leave_sub();
1558 sub edit_warehouse {
1559 $main::lxdebug->enter_sub();
1561 my $form = $main::form;
1562 my %myconfig = %main::myconfig;
1563 my $locale = $main::locale;
1565 $main::auth->assert('config');
1567 AM->get_warehouse(\%myconfig, $form);
1569 $form->get_lists('employees' => 'EMPLOYEES');
1571 $form->{title} = $locale->text('Edit Warehouse');
1572 $form->{callback} ||= build_std_url('action=list_warehouses');
1575 print $form->parse_html_template('am/edit_warehouse');
1577 $main::lxdebug->leave_sub();
1580 sub list_warehouses {
1581 $main::lxdebug->enter_sub();
1583 my $form = $main::form;
1584 my %myconfig = %main::myconfig;
1585 my $locale = $main::locale;
1587 $main::auth->assert('config');
1589 AM->get_all_warehouses(\%myconfig, $form);
1591 $form->{callback} = build_std_url('action=list_warehouses');
1592 $form->{title} = $locale->text('Warehouses');
1593 $form->{url_base} = build_std_url('callback');
1596 print $form->parse_html_template('am/list_warehouses');
1598 $main::lxdebug->leave_sub();
1601 sub save_warehouse {
1602 $main::lxdebug->enter_sub();
1604 my $form = $main::form;
1605 my %myconfig = %main::myconfig;
1606 my $locale = $main::locale;
1608 $main::auth->assert('config');
1610 $form->isblank("description", $locale->text('Description missing!'));
1612 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
1614 AM->save_warehouse(\%myconfig, $form);
1616 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
1618 $form->redirect($locale->text('Warehouse saved.'));
1620 $main::lxdebug->leave_sub();
1623 sub delete_warehouse {
1624 $main::lxdebug->enter_sub();
1626 my $form = $main::form;
1627 my %myconfig = %main::myconfig;
1628 my $locale = $main::locale;
1630 $main::auth->assert('config');
1632 if (!$form->{confirmed}) {
1633 $form->{title} = $locale->text('Confirmation');
1636 print $form->parse_html_template('am/confirm_delete_warehouse');
1640 if (AM->delete_warehouse(\%myconfig, $form)) {
1641 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
1642 $form->redirect($locale->text('Warehouse deleted.'));
1645 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
1648 $main::lxdebug->leave_sub();
1652 $main::lxdebug->enter_sub();
1654 my $form = $main::form;
1655 my %myconfig = %main::myconfig;
1656 my $locale = $main::locale;
1658 $main::auth->assert('config');
1660 AM->save_bins(\%myconfig, $form);
1662 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
1664 $form->redirect($locale->text('Bins saved.'));
1666 $main::lxdebug->leave_sub();