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;
51 require "bin/mozilla/common.pl";
59 sub add { call_sub("add_$main::form->{type}"); }
60 sub delete { call_sub("delete_$main::form->{type}"); }
61 sub save { call_sub("save_$main::form->{type}"); }
62 sub edit { call_sub("edit_$main::form->{type}"); }
63 sub continue { call_sub($main::form->{"nextsub"}); }
64 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
67 $main::lxdebug->enter_sub();
69 my $form = $main::form;
70 my %myconfig = %main::myconfig;
72 $main::auth->assert('config');
74 $form->{title} = "Add";
75 $form->{charttype} = "A";
76 AM->get_account(\%myconfig, \%$form);
78 $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
83 $main::lxdebug->leave_sub();
87 $main::lxdebug->enter_sub();
89 my $form = $main::form;
90 my %myconfig = %main::myconfig;
91 my $defaults = SL::DB::Default->get;
93 $main::auth->assert('config');
95 $form->{title} = "Edit";
96 $form->{feature_balance} = $defaults->feature_balance;
97 $form->{feature_datev} = $defaults->feature_datev;
98 $form->{feature_erfolgsrechnung} = $defaults->feature_erfolgsrechnung;
99 $form->{feature_eurechnung} = $defaults->feature_eurechnung;
100 $form->{feature_ustva} = $defaults->feature_ustva;
102 AM->get_account(\%myconfig, \%$form);
104 foreach my $item (split(/:/, $form->{link})) {
105 $form->{$item} = "checked";
111 $main::lxdebug->leave_sub();
115 $main::lxdebug->enter_sub();
117 my $form = $main::form;
118 my %myconfig = %main::myconfig;
119 my $locale = $main::locale;
121 $main::auth->assert('config');
123 if ( $form->{action} eq 'edit_account') {
124 $form->{account_exists} = '1';
127 $form->{title} = $locale->text("$form->{title} Account");
129 $form->{"$form->{charttype}_checked"} = "checked";
130 $form->{"$form->{category}_checked"} = "checked";
132 $form->{select_tax} = "";
134 my @tax_report_pos = USTVA->report_variables({
135 myconfig => \%myconfig,
138 attribute => 'position',
142 if (@{ $form->{TAXKEY} }) {
143 foreach my $item (@{ $form->{TAXKEY} }) {
144 $item->{rate} = $item->{rate} * 100 . '%';
147 # Fill in empty row for new Taxkey
148 my $newtaxkey_ref = {
153 taxdescription => '',
157 startdate => $form->{account_exists} ? '' : DateTime->new(year => 1970, month => 1, day => 1)->to_lxoffice,
160 push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
163 foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
165 # Fill in a runningnumber
166 $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
168 # Fill in the Taxkeys as select options
169 foreach my $item (@{ $form->{TAXKEY} }) {
170 if ($item->{id} == $taxkey_used->{tax_id}) {
171 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
172 qq|<option value="$item->{id}" selected="selected">|
173 . sprintf("%.2d", $item->{taxkey})
174 . qq|. $item->{taxdescription} ($item->{rate}) |
175 . $locale->text('Tax-o-matic Account')
176 . qq|: $item->{chart_accno}\n|;
179 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
180 qq|<option value="$item->{id}">|
181 . sprintf("%.2d", $item->{taxkey})
182 . qq|. $item->{taxdescription} ($item->{rate}) |
183 . $locale->text('Tax-o-matic Account')
184 . qq|: $item->{chart_accno}\n|;
189 # Fill in the USTVA Numbers as select options
190 foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
192 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
194 elsif ( $item eq $taxkey_used->{pos_ustva} ) {
195 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
198 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
207 # Newaccount Folgekonto
208 if (@{ $form->{NEWACCOUNT} || [] }) {
209 if (!$form->{new_chart_valid}) {
210 $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
212 foreach my $item (@{ $form->{NEWACCOUNT} }) {
213 if ($item->{id} == $form->{new_chart_id}) {
214 $form->{selectnewaccount} .=
215 qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
216 } elsif (!$form->{new_chart_valid}) {
217 $form->{selectnewaccount} .=
218 qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
224 my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
226 1 => "Umsatzerlöse",
227 2 => "sonstige Erlöse",
228 3 => "Privatanteile",
230 5 => "Ausserordentliche Erträge",
231 6 => "Vereinnahmte Umsatzst.",
232 7 => "Umsatzsteuererstattungen",
233 8 => "Wareneingänge",
234 9 => "Löhne und Gehälter",
235 10 => "Gesetzl. sozialer Aufw.",
237 12 => "Gas, Strom, Wasser",
238 13 => "Instandhaltung",
239 14 => "Steuern, Versich., Beiträge",
241 16 => "Kfz-Versicherungen",
242 17 => "Sonst. Fahrzeugkosten",
243 18 => "Werbe- und Reisekosten",
244 19 => "Instandhaltung u. Werkzeuge",
245 20 => "Fachzeitschriften, BĂĽcher",
246 21 => "Miete fĂĽr Einrichtungen",
247 22 => "Rechts- und Beratungskosten",
248 23 => "BĂĽrobedarf, Porto, Telefon",
249 24 => "Sonstige Aufwendungen",
250 25 => "Abschreibungen auf Anlagever.",
251 26 => "Abschreibungen auf GWG",
253 28 => "Umsatzsteuerzahlungen",
255 30 => "Ausserordentlicher Aufwand",
256 31 => "Betriebliche Steuern");
257 foreach my $item (sort({ $a <=> $b } keys(%eur))) {
258 my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
259 if ($item == $form->{pos_eur}) {
260 $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
262 $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
267 my $select_er = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
271 foreach my $item (sort({ $a <=> $b } keys(%er))) {
272 my $text = H($::locale->{iconv_utf8}->convert($er{$item}));
273 if ($item == $form->{pos_er}) {
274 $select_er .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
276 $select_er .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
281 my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
284 1 => 'Umsatzerlöse',
285 2 => 'Best.Verdg.FE/UE',
286 3 => 'Aktiv.Eigenleistung',
287 4 => 'Mat./Wareneinkauf',
288 5 => 'So.betr.Erlöse',
289 10 => 'Personalkosten',
291 12 => 'Betriebl.Steuern',
292 13 => 'Vers./Beiträge',
293 14 => 'Kfz.Kosten o.St.',
294 15 => 'Werbe-Reisek.',
295 16 => 'Kosten Warenabgabe',
296 17 => 'Abschreibungen',
297 18 => 'Rep./instandhlt.',
298 19 => 'Ăśbrige Steuern',
299 20 => 'Sonst.Kosten',
301 31 => 'Sonst.neutr.Aufw.',
302 32 => 'Zinserträge',
303 33 => 'Sonst.neutr.Ertrag',
304 34 => 'Verr.kalk.Kosten',
305 35 => 'Steuern Eink.u.Ertr.');
306 foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
307 my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
308 if ($item == $form->{pos_bwa}) {
309 $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
311 $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
316 # Wieder hinzugefĂĽgt zu evaluationszwecken (us) 09.03.2007
317 my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
318 foreach my $item ((1, 2, 3, 4)) {
319 if ($item == $form->{pos_bilanz}) {
320 $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
322 $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
327 # this is for our parser only! Do not remove.
328 # type=submit $locale->text('Add Account')
329 # type=submit $locale->text('Edit Account')
331 $form->{type} = "account";
333 # preselections category
335 my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
338 'A' => $locale->text('Asset'),
339 'L' => $locale->text('Liability'),
340 'Q' => $locale->text('Equity'),
341 'I' => $locale->text('Revenue'),
342 'E' => $locale->text('Expense'),
343 'C' => $locale->text('Costs'),
345 foreach my $item ( sort({ $a <=> $b } keys %category) ) {
346 if ($item eq $form->{category}) {
347 $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
349 $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
354 # preselection chart type
355 my @all_charttypes = ({'name' => $locale->text('Account'), 'value' => 'A'},
356 {'name' => $locale->text('Heading'), 'value' => 'H'},
358 my $selected_charttype = $form->{charttype};
361 # account where AR_tax or AP_tax is set are not orphaned if they are used as
362 # tax-o-matic account
363 if ( $form->{id} && $form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
364 if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
365 $form->{orphaned} = 0;
369 my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
370 my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
374 my $parameters_ref = {
375 ChartTypeIsAccount => $ChartTypeIsAccount,
376 AccountIsPosted => $AccountIsPosted,
377 select_category => $select_category,
378 all_charttypes => \@all_charttypes,
379 selected_charttype => $selected_charttype,
380 select_bwa => $select_bwa,
381 select_bilanz => $select_bilanz,
382 select_eur => $select_eur,
383 select_er => $select_er,
386 # Ausgabe des Templates
387 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
390 $main::lxdebug->leave_sub();
394 $::lxdebug->enter_sub;
395 $::auth->assert('config');
397 print $::form->parse_html_template('am/form_footer', {
398 show_save => !$::form->{id}
399 || ($::form->{id} && $::form->{orphaned})
400 || ($::form->{type} eq "account" && !$::form->{new_chart_valid}),
401 show_delete => $::form->{id} && $::form->{orphaned},
402 show_save_as_new => $::form->{id} && $::form->{type} eq "account",
405 $::lxdebug->leave_sub;
409 $main::lxdebug->enter_sub();
411 my $form = $main::form;
412 my %myconfig = %main::myconfig;
413 my $locale = $main::locale;
415 $main::auth->assert('config');
417 $form->isblank("accno", $locale->text('Account Number missing!'));
418 $form->isblank("description", $locale->text('Account Description missing!'));
420 if ($form->{charttype} eq 'A'){
421 $form->isblank("category", $locale->text('Account Type missing!'));
423 my $found_valid_taxkey = 0;
424 foreach my $i (0 .. 10) { # 10 is maximum count of taxkeys in form
425 if ($form->{"taxkey_startdate_$i"} and !$form->{"taxkey_del_$i"}) {
426 $found_valid_taxkey = 1;
430 if ($found_valid_taxkey == 0) {
431 $form->error($locale->text('A valid taxkey is missing!'));
435 $form->redirect($locale->text('Account saved!'))
436 if (AM->save_account(\%myconfig, \%$form));
437 $form->error($locale->text('Cannot save account!'));
439 $main::lxdebug->leave_sub();
442 sub save_as_new_account {
443 $main::lxdebug->enter_sub();
445 my $form = $main::form;
446 my %myconfig = %main::myconfig;
447 my $locale = $main::locale;
449 $main::auth->assert('config');
451 $form->isblank("accno", $locale->text('Account Number missing!'));
452 $form->isblank("description", $locale->text('Account Description missing!'));
454 if ($form->{charttype} eq 'A'){
455 $form->isblank("category", $locale->text('Account Type missing!'));
458 for my $taxkey (0 .. 9) {
459 if ($form->{"taxkey_id_$taxkey"}) {
460 $form->{"taxkey_id_$taxkey"} = "NEW";
465 $form->redirect($locale->text('Account saved!'))
466 if (AM->save_account(\%myconfig, \%$form));
467 $form->error($locale->text('Cannot save account!'));
469 $main::lxdebug->leave_sub();
473 $main::lxdebug->enter_sub();
475 my $form = $main::form;
476 my %myconfig = %main::myconfig;
477 my $locale = $main::locale;
479 $main::auth->assert('config');
481 $form->{callback} = build_std_url('action=list_account');
482 my $link_edit_account = build_std_url('action=edit_account', 'callback');
484 CA->all_accounts(\%myconfig, \%$form);
486 foreach my $ca (@{ $form->{CA} }) {
491 if ($ca->{amount} > 0) {
492 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
494 if ($ca->{amount} < 0) {
495 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
497 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
498 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
501 $::request->{layout}->use_stylesheet("list_accounts.css");
502 $form->{title} = $locale->text('Chart of Accounts');
507 my $parameters_ref = {
508 # hidden_variables => $_hidden_variables_ref,
511 # Ausgabe des Templates
512 print($form->parse_html_template('am/list_accounts', $parameters_ref));
514 $main::lxdebug->leave_sub();
519 sub list_account_details {
520 # Ajax Funktion aus list_account_details
521 $main::lxdebug->enter_sub();
523 my $form = $main::form;
524 my %myconfig = %main::myconfig;
525 my $locale = $main::locale;
527 $main::auth->assert('config');
529 my $chart_id = $form->{args};
531 CA->all_accounts(\%myconfig, \%$form, $chart_id);
533 foreach my $ca (@{ $form->{CA} }) {
535 $ca->{debit} = " ";
536 $ca->{credit} = " ";
538 if ($ca->{amount} > 0) {
540 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
542 if ($ca->{amount} < 0) {
544 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
547 my @links = split( q{:}, $ca->{link});
551 foreach my $link (@links){
552 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
553 : ( $link eq 'AP') ? $locale->text('Account Link AP')
554 : ( $link eq 'IC') ? $locale->text('Account Link IC')
555 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
556 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
557 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
558 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
559 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
560 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
561 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
562 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
563 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
564 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
565 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
566 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
567 : $locale->text('Unknown Link') . ': ' . $link;
568 $ca->{link} .= ($link ne '') ? "[$link] ":'';
571 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
572 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
573 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
574 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
575 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
576 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
577 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
578 : $locale->text('Unknown Category') . ': ' . $ca->{category};
581 $form->{title} = $locale->text('Chart of Accounts');
583 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
585 $main::lxdebug->leave_sub();
590 $main::lxdebug->enter_sub();
592 my $form = $main::form;
593 my %myconfig = %main::myconfig;
594 my $locale = $main::locale;
596 $main::auth->assert('config');
598 $form->{title} = $locale->text('Delete Account');
601 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id rndgain_accno_id rndloss_accno_id)
603 if ($form->{id} == $form->{$id}) {
604 $form->error($locale->text('Cannot delete default account!'));
608 $form->redirect($locale->text('Account deleted!'))
609 if (AM->delete_account(\%myconfig, \%$form));
610 $form->error($locale->text('Cannot delete account!'));
612 $main::lxdebug->leave_sub();
616 $main::lxdebug->enter_sub();
618 my $form = $main::form;
620 $main::auth->assert('config');
622 $form->{title} = "Add";
624 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
629 $main::lxdebug->leave_sub();
633 $main::lxdebug->enter_sub();
635 my $form = $main::form;
636 my %myconfig = %main::myconfig;
638 $main::auth->assert('config');
640 $form->{title} = "Edit";
642 AM->get_lead(\%myconfig, \%$form);
646 $form->{orphaned} = 1;
649 $main::lxdebug->leave_sub();
653 $::lxdebug->enter_sub;
654 $::auth->assert('config');
656 AM->lead(\%::myconfig, $::form);
658 $::form->{callback} = "am.pl?action=list_lead";
659 $::form->{title} = $::locale->text('Lead');
662 print $::form->parse_html_template('am/lead_list');
664 $::lxdebug->leave_sub;
668 $::lxdebug->enter_sub;
669 $::auth->assert('config');
671 # $locale->text('Add Lead')
672 # $locale->text('Edit Lead')
673 $::form->{title} = $::locale->text("$::form->{title} Lead");
676 print $::form->parse_html_template('am/lead_header');
678 $::lxdebug->leave_sub;
682 $main::lxdebug->enter_sub();
684 my $form = $main::form;
685 my %myconfig = %main::myconfig;
686 my $locale = $main::locale;
688 $main::auth->assert('config');
690 $form->isblank("description", $locale->text('Description missing!'));
691 AM->save_lead(\%myconfig, \%$form);
692 $form->redirect($locale->text('lead saved!'));
694 $main::lxdebug->leave_sub();
698 $main::lxdebug->enter_sub();
700 my $form = $main::form;
701 my %myconfig = %main::myconfig;
702 my $locale = $main::locale;
704 $main::auth->assert('config');
706 AM->delete_lead(\%myconfig, \%$form);
707 $form->redirect($locale->text('lead deleted!'));
709 $main::lxdebug->leave_sub();
713 $main::lxdebug->enter_sub();
715 my $form = $main::form;
717 $main::auth->assert('config');
719 $form->{title} = "Add";
721 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
726 $main::lxdebug->leave_sub();
730 $main::lxdebug->enter_sub();
732 my $form = $main::form;
733 my %myconfig = %main::myconfig;
735 $main::auth->assert('config');
737 $form->{title} = "Edit";
739 AM->get_language(\%myconfig, \%$form);
743 $form->{orphaned} = 1;
746 $main::lxdebug->leave_sub();
750 $::lxdebug->enter_sub;
751 $::auth->assert('config');
753 AM->language(\%::myconfig, $::form);
755 $::form->{callback} = "am.pl?action=list_language";
756 $::form->{title} = $::locale->text('Languages');
760 print $::form->parse_html_template('am/language_list');
762 $::lxdebug->leave_sub;
765 sub language_header {
766 $::lxdebug->enter_sub;
767 $::auth->assert('config');
769 # $locale->text('Add Language')
770 # $locale->text('Edit Language')
771 $::form->{title} = $::locale->text("$::form->{title} Language");
775 print $::form->parse_html_template('am/language_header', {
776 numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00" ],
777 dateformats => [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
780 $::lxdebug->leave_sub;
784 $main::lxdebug->enter_sub();
786 my $form = $main::form;
787 my %myconfig = %main::myconfig;
788 my $locale = $main::locale;
790 $main::auth->assert('config');
792 $form->isblank("description", $locale->text('Language missing!'));
793 $form->isblank("template_code", $locale->text('Template Code missing!'));
794 $form->isblank("article_code", $locale->text('Article Code missing!'));
795 AM->save_language(\%myconfig, \%$form);
796 $form->redirect($locale->text('Language saved!'));
798 $main::lxdebug->leave_sub();
801 sub delete_language {
802 $main::lxdebug->enter_sub();
804 my $form = $main::form;
805 my %myconfig = %main::myconfig;
806 my $locale = $main::locale;
808 $main::auth->assert('config');
810 AM->delete_language(\%myconfig, \%$form);
811 $form->redirect($locale->text('Language deleted!'));
813 $main::lxdebug->leave_sub();
816 sub _build_cfg_options {
817 my $form = $main::form;
818 my %myconfig = %main::myconfig;
821 my $array = uc($idx) . 'S';
823 $form->{$array} = [];
824 foreach my $item (@_) {
825 push @{ $form->{$array} }, {
828 'selected' => $item eq $myconfig{$idx},
834 $main::lxdebug->enter_sub();
836 my $form = $main::form;
837 my %myconfig = %main::myconfig;
838 my $locale = $main::locale;
840 _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
841 _build_cfg_options('timeformat', qw(hh:mm hh:mm:ss));
842 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00"));
845 if ($::lx_office_conf{print_templates}->{opendocument}
846 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
847 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
848 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
849 "value" => "opendocument_pdf" });
851 if ($::lx_office_conf{print_templates}->{latex}) {
852 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
854 push(@formats, { "name" => "HTML", "value" => "html" });
855 if ($::lx_office_conf{print_templates}->{latex}) {
856 push(@formats, { "name" => $locale->text("Postscript"),
857 "value" => "postscript" });
859 if ($::lx_office_conf{print_templates}->{opendocument}) {
860 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
861 "value" => "opendocument" });
864 if (!$myconfig{"template_format"}) {
865 $myconfig{"template_format"} = "pdf";
867 $form->{TEMPLATE_FORMATS} = [];
868 foreach my $item (@formats) {
869 push @{ $form->{TEMPLATE_FORMATS} }, {
870 'name' => $item->{name},
871 'value' => $item->{value},
872 'selected' => $item->{value} eq $myconfig{template_format},
876 if (!$myconfig{"default_media"}) {
877 $myconfig{"default_media"} = "screen";
880 my %selected = ($myconfig{"default_media"} => "selected");
882 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
883 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
884 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
887 $form->{PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
889 my %countrycodes = User->country_codes;
891 $form->{COUNTRYCODES} = [];
892 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
893 push @{ $form->{COUNTRYCODES} }, {
894 'name' => $countrycodes{$countrycode},
895 'value' => $countrycode,
896 'selected' => $countrycode eq $myconfig{countrycode},
900 $form->{STYLESHEETS} = [];
901 foreach my $item (qw(lx-office-erp.css kivitendo.css)) {
902 push @{ $form->{STYLESHEETS} }, {
905 'selected' => $item eq $myconfig{stylesheet},
909 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
910 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
911 $form->{todo_cfg} = { TODO->get_user_config('login' => $::myconfig{login}) };
913 $form->{title} = $locale->text('Edit Preferences for #1', $::myconfig{login});
917 $form->{full_signature} = $form->create_email_signature();
919 print $form->parse_html_template('am/config');
921 $main::lxdebug->leave_sub();
924 sub save_preferences {
925 $main::lxdebug->enter_sub();
927 my $form = $main::form;
928 my %myconfig = %main::myconfig;
929 my $locale = $main::locale;
931 $form->{stylesheet} = $form->{usestylesheet};
933 TODO->save_user_config('login' => $::myconfig{login}, %{ $form->{todo_cfg} || { } });
935 if (AM->save_preferences($form)) {
936 if ($::auth->can_change_password()
937 && defined $form->{new_password}
938 && ($form->{new_password} ne '********')) {
939 my $verifier = SL::Auth::PasswordPolicy->new;
940 my $result = $verifier->verify($form->{new_password});
942 if ($result != SL::Auth::PasswordPolicy->OK()) {
943 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
946 $::auth->change_password($::myconfig{login}, $form->{new_password});
949 $form->redirect($locale->text('Preferences saved!'));
952 $form->error($locale->text('Cannot save preferences!'));
954 $main::lxdebug->leave_sub();
958 $::lxdebug->enter_sub;
959 $::auth->assert('config');
961 $::form->{title} = $::locale->text('Audit Control');
963 AM->closedto(\%::myconfig, $::form);
966 print $::form->parse_html_template('am/audit_control');
968 $::lxdebug->leave_sub;
972 $main::lxdebug->enter_sub();
974 my $form = $main::form;
975 my %myconfig = %main::myconfig;
976 my $locale = $main::locale;
978 $main::auth->assert('config');
980 AM->closebooks(\%myconfig, \%$form);
982 if ($form->{closedto}) {
984 $locale->text('Books closed up to') . " "
985 . $locale->date(\%myconfig, $form->{closedto}, 1));
987 $form->redirect($locale->text('Books are open'));
990 $main::lxdebug->leave_sub();
994 $main::lxdebug->enter_sub();
996 my $form = $main::form;
997 my %myconfig = %main::myconfig;
998 my $locale = $main::locale;
1000 $main::auth->assert('config');
1002 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1003 AM->units_in_use(\%myconfig, $form, $units);
1004 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1006 my @languages = AM->language(\%myconfig, $form, 1);
1008 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1011 foreach (@unit_list) {
1012 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1013 $_->{"UNITLANGUAGES"} = [];
1014 foreach my $lang (@languages) {
1015 push(@{ $_->{"UNITLANGUAGES"} },
1017 "unit" => $_->{"name"},
1018 "language_id" => $lang->{"id"},
1019 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1020 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1026 $units = AM->retrieve_units(\%myconfig, $form);
1027 my $ddbox = AM->unit_select_data($units, undef, 1);
1029 $form->{"title"} = $locale->text("Add and edit units");
1031 print($form->parse_html_template("am/edit_units",
1032 { "UNITS" => \@unit_list,
1033 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1034 "LANGUAGES" => \@languages,
1037 $main::lxdebug->leave_sub();
1041 $main::lxdebug->enter_sub();
1043 my $form = $main::form;
1044 my %myconfig = %main::myconfig;
1045 my $locale = $main::locale;
1047 $main::auth->assert('config');
1049 $form->isblank("new_name", $locale->text("The name is missing."));
1050 my $units = AM->retrieve_units(\%myconfig, $form);
1051 my $all_units = AM->retrieve_units(\%myconfig, $form);
1052 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1054 my ($base_unit, $factor);
1055 if ($form->{"new_base_unit"}) {
1056 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1058 $form->isblank("new_factor", $locale->text("The factor is missing."));
1059 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1060 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1061 $base_unit = $form->{"new_base_unit"};
1065 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1066 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1067 push(@languages, { "id" => $lang->{"id"},
1068 "localized" => $form->{"new_localized_$lang->{id}"},
1069 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1073 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1075 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1079 $main::lxdebug->leave_sub();
1082 sub set_unit_languages {
1083 $main::lxdebug->enter_sub();
1085 my $form = $main::form;
1087 $main::auth->assert('config');
1089 my ($unit, $languages, $idx) = @_;
1091 $unit->{"LANGUAGES"} = [];
1093 foreach my $lang (@{$languages}) {
1094 push(@{ $unit->{"LANGUAGES"} },
1095 { "id" => $lang->{"id"},
1096 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1097 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1101 $main::lxdebug->leave_sub();
1105 $main::lxdebug->enter_sub();
1107 my $form = $main::form;
1108 my %myconfig = %main::myconfig;
1109 my $locale = $main::locale;
1111 $main::auth->assert('config');
1113 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1114 AM->units_in_use(\%myconfig, $form, $old_units);
1116 my @languages = AM->language(\%myconfig, $form, 1);
1119 my @delete_units = ();
1120 foreach my $i (1..($form->{"rowcount"} * 1)) {
1121 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1123 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1126 if ($form->{"unchangeable_$i"}) {
1127 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1128 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1129 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1133 if ($old_unit->{"in_use"}) {
1134 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1137 if ($form->{"delete_$i"}) {
1138 push(@delete_units, $old_unit->{"name"});
1142 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1144 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1145 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1146 $new_units->{$form->{"name_$i"}} = \%h;
1147 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1148 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1151 foreach my $unit (values(%{$new_units})) {
1152 next unless ($unit->{"old_name"});
1153 if ($unit->{"base_unit"}) {
1154 $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"}))
1155 unless (defined($new_units->{$unit->{"base_unit"}}));
1156 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1157 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1159 $unit->{"base_unit"} = undef;
1160 $unit->{"factor"} = undef;
1164 foreach my $unit (values(%{$new_units})) {
1165 next if ($unit->{"unchanged_unit"});
1167 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1168 my $new_unit = $unit;
1169 while ($new_unit->{"base_unit"}) {
1170 $new_unit->{"seen"} = 1;
1171 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1172 if ($new_unit->{"seen"}) {
1173 $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, " .
1174 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1179 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1181 $form->{"saved_message"} = $locale->text("The units have been saved.");
1185 $main::lxdebug->leave_sub();
1188 sub show_history_search {
1189 $main::lxdebug->enter_sub();
1191 my $form = $main::form;
1192 my $locale = $main::locale;
1194 $main::auth->assert('config');
1196 $form->{title} = $locale->text("History Search");
1199 print $form->parse_html_template("common/search_history");
1201 $main::lxdebug->leave_sub();
1204 sub show_am_history {
1205 $main::lxdebug->enter_sub();
1207 my $form = $main::form;
1208 my %myconfig = %main::myconfig;
1209 my $locale = $main::locale;
1211 $main::auth->assert('config');
1213 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1214 $form->{order} ||= 'h.itime--1';
1216 # my %search = ( "Artikelnummer" => "parts",
1217 # "Kundennummer" => "customer",
1218 # "Lieferantennummer" => "vendor",
1219 # "Projektnummer" => "project",
1220 # "Auftragsnummer" => "oe",
1221 # "Angebotsnummer" => "oe",
1222 # "Eingangsrechnungnummer" => "ap",
1223 # "Ausgangsrechnungnummer" => "ar",
1224 # "Mahnungsnummer" => "dunning",
1225 # "Buchungsnummer" => "gl",
1228 my %searchNo = ( "Artikelnummer" => "partnumber",
1229 "Kundennummer" => "customernumber",
1230 "Lieferantennummer" => "vendornumber",
1231 "Projektnummer" => "projectnumber",
1232 "Auftragsnummer" => "ordnumber",
1233 "Angebotsnummer" => "quonumber",
1234 "Eingangsrechnungnummer" => "invnumber",
1235 "Ausgangsrechnungnummer" => "invnumber",
1236 "Mahnungsnummer" => "dunning_id",
1237 "Buchungsnummer" => "gltransaction"
1240 my $dbh = $form->dbconnect(\%myconfig);
1243 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1244 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1245 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1246 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1247 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1248 } elsif ($form->{mitarbeiter}) {
1249 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1252 my $query = qq|SELECT trans_id AS id FROM history_erp | .
1253 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
1254 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
1256 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
1257 my $daten .= shift @ids;
1258 $daten .= join '', map { " OR trans_id = $_" } @ids;
1260 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1261 $sort =~ s/.*\.(.*)$/$1/;
1263 $form->{title} = $locale->text("History Search");
1266 print $form->parse_html_template("common/show_history",
1267 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1268 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1271 uc($sort) . "BY" => $sortby,
1272 'callback' => $callback,
1276 $main::lxdebug->leave_sub();
1280 $main::lxdebug->enter_sub();
1282 my $form = $main::form;
1283 my $locale = $main::locale;
1285 $main::auth->assert('config');
1287 $form->{title} = $locale->text('Add');
1289 $form->{callback} ||= "am.pl?action=add_tax";
1291 _get_taxaccount_selection();
1294 $form->{liability} = 1;
1295 $form->{equity} = 1;
1296 $form->{revenue} = 1;
1297 $form->{expense} = 1;
1302 my $parameters_ref = {
1303 # ChartTypeIsAccount => $ChartTypeIsAccount,
1304 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1307 # Ausgabe des Templates
1308 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1310 $main::lxdebug->leave_sub();
1314 $main::lxdebug->enter_sub();
1316 my $form = $main::form;
1317 my %myconfig = %main::myconfig;
1318 my $locale = $main::locale;
1320 $main::auth->assert('config');
1322 $form->{title} = $locale->text('Edit');
1324 AM->get_tax(\%myconfig, \%$form);
1326 _get_taxaccount_selection();
1328 $form->{asset} = $form->{chart_categories} =~ 'A' ? 1 : 0;
1329 $form->{liability} = $form->{chart_categories} =~ 'L' ? 1 : 0;
1330 $form->{equity} = $form->{chart_categories} =~ 'Q' ? 1 : 0;
1331 $form->{revenue} = $form->{chart_categories} =~ 'I' ? 1 : 0;
1332 $form->{expense} = $form->{chart_categories} =~ 'E' ? 1 : 0;
1333 $form->{costs} = $form->{chart_categories} =~ 'C' ? 1 : 0;
1335 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1339 my $parameters_ref = {
1340 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1341 TAX => SL::DB::Manager::Tax->find_by(id => $form->{id}),
1344 # Ausgabe des Templates
1345 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1347 $main::lxdebug->leave_sub();
1351 $main::lxdebug->enter_sub();
1353 my $form = $main::form;
1354 my %myconfig = %main::myconfig;
1355 my $locale = $main::locale;
1357 $main::auth->assert('config');
1359 AM->taxes(\%myconfig, \%$form);
1361 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1363 $form->{callback} = build_std_url('action=list_tax');
1365 $form->{title} = $locale->text('Tax-O-Matic');
1369 my $parameters_ref = {
1372 # Ausgabe des Templates
1373 print($form->parse_html_template('am/list_tax', $parameters_ref));
1375 $main::lxdebug->leave_sub();
1378 sub _get_taxaccount_selection{
1379 $main::lxdebug->enter_sub();
1381 my $form = $main::form;
1382 my %myconfig = %main::myconfig;
1384 $main::auth->assert('config');
1386 AM->get_tax_accounts(\%myconfig, \%$form);
1388 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1390 $main::lxdebug->leave_sub();
1394 $main::lxdebug->enter_sub();
1396 my $form = $main::form;
1397 my %myconfig = %main::myconfig;
1398 my $locale = $main::locale;
1400 $main::auth->assert('config');
1402 $form->error($locale->text('Taxkey missing!')) unless length($form->{taxkey}) != 0;
1403 $form->error($locale->text('Taxdescription missing!')) unless length($form->{taxdescription}) != 0;
1404 $form->error($locale->text('Taxrate missing!')) unless length($form->{rate}) != 0;
1406 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1408 if ($form->{taxkey} == 0 and $form->{rate} > 0) {
1409 $form->error($locale->text('Taxkey 0 is reserved for rate 0'));
1412 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1413 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1416 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
1417 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1420 my @translation_keys = grep { $_ =~ '^translation_\d+' } keys %$form;
1421 $form->{translations} = { map { $_ =~ '^translation_(\d+)'; $1 => $form->{$_} } @translation_keys };
1423 AM->save_tax(\%myconfig, \%$form);
1424 $form->redirect($locale->text('Tax saved!'));
1426 $main::lxdebug->leave_sub();
1430 $main::lxdebug->enter_sub();
1432 my $form = $main::form;
1433 my %myconfig = %main::myconfig;
1434 my $locale = $main::locale;
1436 $main::auth->assert('config');
1438 AM->delete_tax(\%myconfig, \%$form);
1439 $form->redirect($locale->text('Tax deleted!'));
1441 $main::lxdebug->leave_sub();
1444 sub add_price_factor {
1445 $main::lxdebug->enter_sub();
1447 my $form = $main::form;
1448 my $locale = $main::locale;
1450 $main::auth->assert('config');
1452 $form->{title} = $locale->text('Add Price Factor');
1453 $form->{callback} ||= build_std_url('action=add_price_factor');
1456 print $form->parse_html_template('am/edit_price_factor');
1458 $main::lxdebug->leave_sub();
1461 sub edit_price_factor {
1462 $main::lxdebug->enter_sub();
1464 my $form = $main::form;
1465 my %myconfig = %main::myconfig;
1466 my $locale = $main::locale;
1468 $main::auth->assert('config');
1470 $form->{title} = $locale->text('Edit Price Factor');
1471 $form->{callback} ||= build_std_url('action=add_price_factor');
1473 AM->get_price_factor(\%myconfig, $form);
1475 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
1478 print $form->parse_html_template('am/edit_price_factor');
1480 $main::lxdebug->leave_sub();
1483 sub list_price_factors {
1484 $main::lxdebug->enter_sub();
1486 my $form = $main::form;
1487 my %myconfig = %main::myconfig;
1488 my $locale = $main::locale;
1490 $main::auth->assert('config');
1492 AM->get_all_price_factors(\%myconfig, \%$form);
1494 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
1495 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
1498 $form->{callback} = build_std_url('action=list_price_factors');
1499 $form->{title} = $locale->text('Price Factors');
1500 $form->{url_base} = build_std_url('callback');
1503 print $form->parse_html_template('am/list_price_factors');
1505 $main::lxdebug->leave_sub();
1508 sub save_price_factor {
1509 $main::lxdebug->enter_sub();
1511 my $form = $main::form;
1512 my %myconfig = %main::myconfig;
1513 my $locale = $main::locale;
1515 $main::auth->assert('config');
1517 $form->isblank("description", $locale->text('Description missing!'));
1518 $form->isblank("factor", $locale->text('Factor missing!'));
1520 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
1522 AM->save_price_factor(\%myconfig, $form);
1524 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
1526 $form->redirect($locale->text('Price factor saved!'));
1528 $main::lxdebug->leave_sub();
1531 sub delete_price_factor {
1532 $main::lxdebug->enter_sub();
1534 my $form = $main::form;
1535 my %myconfig = %main::myconfig;
1536 my $locale = $main::locale;
1538 $main::auth->assert('config');
1540 AM->delete_price_factor(\%myconfig, \%$form);
1542 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
1544 $form->redirect($locale->text('Price factor deleted!'));
1546 $main::lxdebug->leave_sub();
1550 $main::lxdebug->enter_sub();
1552 my $form = $main::form;
1553 my $locale = $main::locale;
1555 $main::auth->assert('config');
1557 $form->{title} = $locale->text('Add Warehouse');
1558 $form->{callback} ||= build_std_url('action=add_warehouse');
1561 print $form->parse_html_template('am/edit_warehouse');
1563 $main::lxdebug->leave_sub();
1566 sub edit_warehouse {
1567 $main::lxdebug->enter_sub();
1569 my $form = $main::form;
1570 my %myconfig = %main::myconfig;
1571 my $locale = $main::locale;
1573 $main::auth->assert('config');
1575 AM->get_warehouse(\%myconfig, $form);
1577 $form->get_lists('employees' => 'EMPLOYEES');
1579 $form->{title} = $locale->text('Edit Warehouse');
1580 $form->{callback} ||= build_std_url('action=list_warehouses');
1583 print $form->parse_html_template('am/edit_warehouse');
1585 $main::lxdebug->leave_sub();
1588 sub list_warehouses {
1589 $main::lxdebug->enter_sub();
1591 my $form = $main::form;
1592 my %myconfig = %main::myconfig;
1593 my $locale = $main::locale;
1595 $main::auth->assert('config');
1597 AM->get_all_warehouses(\%myconfig, $form);
1599 $form->{callback} = build_std_url('action=list_warehouses');
1600 $form->{title} = $locale->text('Warehouses');
1601 $form->{url_base} = build_std_url('callback');
1604 print $form->parse_html_template('am/list_warehouses');
1606 $main::lxdebug->leave_sub();
1609 sub save_warehouse {
1610 $main::lxdebug->enter_sub();
1612 my $form = $main::form;
1613 my %myconfig = %main::myconfig;
1614 my $locale = $main::locale;
1616 $main::auth->assert('config');
1618 $form->isblank("description", $locale->text('Description missing!'));
1620 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
1622 AM->save_warehouse(\%myconfig, $form);
1624 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
1626 $form->redirect($locale->text('Warehouse saved.'));
1628 $main::lxdebug->leave_sub();
1631 sub delete_warehouse {
1632 $main::lxdebug->enter_sub();
1634 my $form = $main::form;
1635 my %myconfig = %main::myconfig;
1636 my $locale = $main::locale;
1638 $main::auth->assert('config');
1640 if (!$form->{confirmed}) {
1641 $form->{title} = $locale->text('Confirmation');
1644 print $form->parse_html_template('am/confirm_delete_warehouse');
1645 $::dispatcher->end_request;
1648 if (AM->delete_warehouse(\%myconfig, $form)) {
1649 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
1650 $form->redirect($locale->text('Warehouse deleted.'));
1653 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
1656 $main::lxdebug->leave_sub();
1660 $main::lxdebug->enter_sub();
1662 my $form = $main::form;
1663 my %myconfig = %main::myconfig;
1664 my $locale = $main::locale;
1666 $main::auth->assert('config');
1668 AM->save_bins(\%myconfig, $form);
1670 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
1672 $form->redirect($locale->text('Bins saved.'));
1674 $main::lxdebug->leave_sub();