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|;
218 if (($form->{country_mode} = SL::DB::Default->get->country_mode) eq 'CH') {
225 1 => "Umsatzerlöse",
226 2 => "sonstige Erlöse",
227 3 => "Privatanteile",
229 5 => "Ausserordentliche Erträge",
230 6 => "Vereinnahmte Umsatzst.",
231 7 => "Umsatzsteuererstattungen",
232 8 => "Wareneingänge",
233 9 => "Löhne und Gehälter",
234 10 => "Gesetzl. sozialer Aufw.",
236 12 => "Gas, Strom, Wasser",
237 13 => "Instandhaltung",
238 14 => "Steuern, Versich., Beiträge",
240 16 => "Kfz-Versicherungen",
241 17 => "Sonst. Fahrzeugkosten",
242 18 => "Werbe- und Reisekosten",
243 19 => "Instandhaltung u. Werkzeuge",
244 20 => "Fachzeitschriften, BĂĽcher",
245 21 => "Miete fĂĽr Einrichtungen",
246 22 => "Rechts- und Beratungskosten",
247 23 => "BĂĽrobedarf, Porto, Telefon",
248 24 => "Sonstige Aufwendungen",
249 25 => "Abschreibungen auf Anlagever.",
250 26 => "Abschreibungen auf GWG",
252 28 => "Umsatzsteuerzahlungen",
254 30 => "Ausserordentlicher Aufwand",
255 31 => "Betriebliche Steuern",
258 foreach my $item (sort({ $a <=> $b } keys(%eur))) {
259 my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
260 if ($item == $form->{pos_eur}) {
261 $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
263 $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
268 my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
271 1 => 'Umsatzerlöse',
272 2 => 'Best.Verdg.FE/UE',
273 3 => 'Aktiv.Eigenleistung',
274 4 => 'Mat./Wareneinkauf',
275 5 => 'So.betr.Erlöse',
276 10 => 'Personalkosten',
278 12 => 'Betriebl.Steuern',
279 13 => 'Vers./Beiträge',
280 14 => 'Kfz.Kosten o.St.',
281 15 => 'Werbe-Reisek.',
282 16 => 'Kosten Warenabgabe',
283 17 => 'Abschreibungen',
284 18 => 'Rep./instandhlt.',
285 19 => 'Ăśbrige Steuern',
286 20 => 'Sonst.Kosten',
288 31 => 'Sonst.neutr.Aufw.',
289 32 => 'Zinserträge',
290 33 => 'Sonst.neutr.Ertrag',
291 34 => 'Verr.kalk.Kosten',
292 35 => 'Steuern Eink.u.Ertr.');
293 foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
294 my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
295 if ($item == $form->{pos_bwa}) {
296 $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
298 $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
303 # Wieder hinzugefĂĽgt zu evaluationszwecken (us) 09.03.2007
304 my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
305 foreach my $item ((1, 2, 3, 4)) {
306 if ($item == $form->{pos_bilanz}) {
307 $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
309 $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
314 # this is for our parser only! Do not remove.
315 # type=submit $locale->text('Add Account')
316 # type=submit $locale->text('Edit Account')
318 $form->{type} = "account";
320 # preselections category
322 my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
325 'A' => $locale->text('Asset'),
326 'L' => $locale->text('Liability'),
327 'Q' => $locale->text('Equity'),
328 'I' => $locale->text('Revenue'),
329 'E' => $locale->text('Expense'),
330 'C' => $locale->text('Costs'),
332 foreach my $item ( sort({ $a <=> $b } keys %category) ) {
333 if ($item eq $form->{category}) {
334 $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
336 $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
341 # preselection chart type
342 my @all_charttypes = ({'name' => $locale->text('Account'), 'value' => 'A'},
343 {'name' => $locale->text('Heading'), 'value' => 'H'},
345 my $selected_charttype = $form->{charttype};
348 # account where AR_tax or AP_tax is set are not orphaned if they are used as
349 # tax-o-matic account
350 if ( $form->{id} && $form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
351 if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
352 $form->{orphaned} = 0;
356 my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
357 my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
361 my $parameters_ref = {
362 ChartTypeIsAccount => $ChartTypeIsAccount,
363 AccountIsPosted => $AccountIsPosted,
364 select_category => $select_category,
365 all_charttypes => \@all_charttypes,
366 selected_charttype => $selected_charttype,
367 select_bwa => $select_bwa,
368 select_bilanz => $select_bilanz,
369 select_eur => $select_eur,
372 # Ausgabe des Templates
373 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
376 $main::lxdebug->leave_sub();
380 $::lxdebug->enter_sub;
381 $::auth->assert('config');
383 print $::form->parse_html_template('am/form_footer', {
384 show_save => !$::form->{id}
385 || ($::form->{id} && $::form->{orphaned})
386 || ($::form->{type} eq "account" && !$::form->{new_chart_valid}),
387 show_delete => $::form->{id} && $::form->{orphaned},
388 show_save_as_new => $::form->{id} && $::form->{type} eq "account",
391 $::lxdebug->leave_sub;
395 $main::lxdebug->enter_sub();
397 my $form = $main::form;
398 my %myconfig = %main::myconfig;
399 my $locale = $main::locale;
401 $main::auth->assert('config');
403 $form->isblank("accno", $locale->text('Account Number missing!'));
404 $form->isblank("description", $locale->text('Account Description missing!'));
406 if ($form->{charttype} eq 'A'){
407 $form->isblank("category", $locale->text('Account Type missing!'));
409 my $found_valid_taxkey = 0;
410 foreach my $i (0 .. 10) { # 10 is maximum count of taxkeys in form
411 if ($form->{"taxkey_startdate_$i"} and !$form->{"taxkey_del_$i"}) {
412 $found_valid_taxkey = 1;
416 if ($found_valid_taxkey == 0) {
417 $form->error($locale->text('A valid taxkey is missing!'));
421 $form->redirect($locale->text('Account saved!'))
422 if (AM->save_account(\%myconfig, \%$form));
423 $form->error($locale->text('Cannot save account!'));
425 $main::lxdebug->leave_sub();
428 sub save_as_new_account {
429 $main::lxdebug->enter_sub();
431 my $form = $main::form;
432 my %myconfig = %main::myconfig;
433 my $locale = $main::locale;
435 $main::auth->assert('config');
437 $form->isblank("accno", $locale->text('Account Number missing!'));
438 $form->isblank("description", $locale->text('Account Description missing!'));
440 if ($form->{charttype} eq 'A'){
441 $form->isblank("category", $locale->text('Account Type missing!'));
444 for my $taxkey (0 .. 9) {
445 if ($form->{"taxkey_id_$taxkey"}) {
446 $form->{"taxkey_id_$taxkey"} = "NEW";
451 $form->redirect($locale->text('Account saved!'))
452 if (AM->save_account(\%myconfig, \%$form));
453 $form->error($locale->text('Cannot save account!'));
455 $main::lxdebug->leave_sub();
459 $main::lxdebug->enter_sub();
461 my $form = $main::form;
462 my %myconfig = %main::myconfig;
463 my $locale = $main::locale;
465 $main::auth->assert('config');
467 $form->{callback} = build_std_url('action=list_account');
468 my $link_edit_account = build_std_url('action=edit_account', 'callback');
470 CA->all_accounts(\%myconfig, \%$form);
472 foreach my $ca (@{ $form->{CA} }) {
477 if ($ca->{amount} > 0) {
478 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
480 if ($ca->{amount} < 0) {
481 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
483 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
484 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
487 $::request->{layout}->use_stylesheet("list_accounts.css");
488 $form->{title} = $locale->text('Chart of Accounts');
493 my $parameters_ref = {
494 # hidden_variables => $_hidden_variables_ref,
497 # Ausgabe des Templates
498 print($form->parse_html_template('am/list_accounts', $parameters_ref));
500 $main::lxdebug->leave_sub();
505 sub list_account_details {
506 # Ajax Funktion aus list_account_details
507 $main::lxdebug->enter_sub();
509 my $form = $main::form;
510 my %myconfig = %main::myconfig;
511 my $locale = $main::locale;
513 $main::auth->assert('config');
515 my $chart_id = $form->{args};
517 CA->all_accounts(\%myconfig, \%$form, $chart_id);
519 foreach my $ca (@{ $form->{CA} }) {
521 $ca->{debit} = " ";
522 $ca->{credit} = " ";
524 if ($ca->{amount} > 0) {
526 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
528 if ($ca->{amount} < 0) {
530 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
533 my @links = split( q{:}, $ca->{link});
537 foreach my $link (@links){
538 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
539 : ( $link eq 'AP') ? $locale->text('Account Link AP')
540 : ( $link eq 'IC') ? $locale->text('Account Link IC')
541 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
542 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
543 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
544 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
545 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
546 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
547 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
548 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
549 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
550 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
551 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
552 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
553 : $locale->text('Unknown Link') . ': ' . $link;
554 $ca->{link} .= ($link ne '') ? "[$link] ":'';
557 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
558 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
559 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
560 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
561 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
562 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
563 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
564 : $locale->text('Unknown Category') . ': ' . $ca->{category};
567 $form->{title} = $locale->text('Chart of Accounts');
569 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
571 $main::lxdebug->leave_sub();
576 $main::lxdebug->enter_sub();
578 my $form = $main::form;
579 my %myconfig = %main::myconfig;
580 my $locale = $main::locale;
582 $main::auth->assert('config');
584 $form->{title} = $locale->text('Delete Account');
587 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id rndgain_accno_id rndloss_accno_id)
589 if ($form->{id} == $form->{$id}) {
590 $form->error($locale->text('Cannot delete default account!'));
594 $form->redirect($locale->text('Account deleted!'))
595 if (AM->delete_account(\%myconfig, \%$form));
596 $form->error($locale->text('Cannot delete account!'));
598 $main::lxdebug->leave_sub();
602 $main::lxdebug->enter_sub();
604 my $form = $main::form;
606 $main::auth->assert('config');
608 $form->{title} = "Add";
610 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
615 $main::lxdebug->leave_sub();
619 $main::lxdebug->enter_sub();
621 my $form = $main::form;
622 my %myconfig = %main::myconfig;
624 $main::auth->assert('config');
626 $form->{title} = "Edit";
628 AM->get_lead(\%myconfig, \%$form);
632 $form->{orphaned} = 1;
635 $main::lxdebug->leave_sub();
639 $::lxdebug->enter_sub;
640 $::auth->assert('config');
642 AM->lead(\%::myconfig, $::form);
644 $::form->{callback} = "am.pl?action=list_lead";
645 $::form->{title} = $::locale->text('Lead');
648 print $::form->parse_html_template('am/lead_list');
650 $::lxdebug->leave_sub;
654 $::lxdebug->enter_sub;
655 $::auth->assert('config');
657 # $locale->text('Add Lead')
658 # $locale->text('Edit Lead')
659 $::form->{title} = $::locale->text("$::form->{title} Lead");
662 print $::form->parse_html_template('am/lead_header');
664 $::lxdebug->leave_sub;
668 $main::lxdebug->enter_sub();
670 my $form = $main::form;
671 my %myconfig = %main::myconfig;
672 my $locale = $main::locale;
674 $main::auth->assert('config');
676 $form->isblank("description", $locale->text('Description missing!'));
677 AM->save_lead(\%myconfig, \%$form);
678 $form->redirect($locale->text('lead saved!'));
680 $main::lxdebug->leave_sub();
684 $main::lxdebug->enter_sub();
686 my $form = $main::form;
687 my %myconfig = %main::myconfig;
688 my $locale = $main::locale;
690 $main::auth->assert('config');
692 AM->delete_lead(\%myconfig, \%$form);
693 $form->redirect($locale->text('lead deleted!'));
695 $main::lxdebug->leave_sub();
699 $main::lxdebug->enter_sub();
701 my $form = $main::form;
703 $main::auth->assert('config');
705 $form->{title} = "Add";
707 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
712 $main::lxdebug->leave_sub();
716 $main::lxdebug->enter_sub();
718 my $form = $main::form;
719 my %myconfig = %main::myconfig;
721 $main::auth->assert('config');
723 $form->{title} = "Edit";
725 AM->get_language(\%myconfig, \%$form);
729 $form->{orphaned} = 1;
732 $main::lxdebug->leave_sub();
736 $::lxdebug->enter_sub;
737 $::auth->assert('config');
739 AM->language(\%::myconfig, $::form);
741 $::form->{callback} = "am.pl?action=list_language";
742 $::form->{title} = $::locale->text('Languages');
746 print $::form->parse_html_template('am/language_list');
748 $::lxdebug->leave_sub;
751 sub language_header {
752 $::lxdebug->enter_sub;
753 $::auth->assert('config');
755 # $locale->text('Add Language')
756 # $locale->text('Edit Language')
757 $::form->{title} = $::locale->text("$::form->{title} Language");
761 print $::form->parse_html_template('am/language_header', {
762 numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00" ],
763 dateformats => [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
766 $::lxdebug->leave_sub;
770 $main::lxdebug->enter_sub();
772 my $form = $main::form;
773 my %myconfig = %main::myconfig;
774 my $locale = $main::locale;
776 $main::auth->assert('config');
778 $form->isblank("description", $locale->text('Language missing!'));
779 $form->isblank("template_code", $locale->text('Template Code missing!'));
780 $form->isblank("article_code", $locale->text('Article Code missing!'));
781 AM->save_language(\%myconfig, \%$form);
782 $form->redirect($locale->text('Language saved!'));
784 $main::lxdebug->leave_sub();
787 sub delete_language {
788 $main::lxdebug->enter_sub();
790 my $form = $main::form;
791 my %myconfig = %main::myconfig;
792 my $locale = $main::locale;
794 $main::auth->assert('config');
796 AM->delete_language(\%myconfig, \%$form);
797 $form->redirect($locale->text('Language deleted!'));
799 $main::lxdebug->leave_sub();
802 sub _build_cfg_options {
803 my $form = $main::form;
804 my %myconfig = %main::myconfig;
807 my $array = uc($idx) . 'S';
809 $form->{$array} = [];
810 foreach my $item (@_) {
811 push @{ $form->{$array} }, {
814 'selected' => $item eq $myconfig{$idx},
820 $main::lxdebug->enter_sub();
822 my $form = $main::form;
823 my %myconfig = %main::myconfig;
824 my $locale = $main::locale;
826 _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
827 _build_cfg_options('timeformat', qw(hh:mm hh:mm:ss));
828 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00"));
831 if ($::lx_office_conf{print_templates}->{opendocument}
832 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
833 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
834 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
835 "value" => "opendocument_pdf" });
837 if ($::lx_office_conf{print_templates}->{latex}) {
838 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
840 push(@formats, { "name" => "HTML", "value" => "html" });
841 if ($::lx_office_conf{print_templates}->{latex}) {
842 push(@formats, { "name" => $locale->text("Postscript"),
843 "value" => "postscript" });
845 if ($::lx_office_conf{print_templates}->{opendocument}) {
846 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
847 "value" => "opendocument" });
850 if (!$myconfig{"template_format"}) {
851 $myconfig{"template_format"} = "pdf";
853 $form->{TEMPLATE_FORMATS} = [];
854 foreach my $item (@formats) {
855 push @{ $form->{TEMPLATE_FORMATS} }, {
856 'name' => $item->{name},
857 'value' => $item->{value},
858 'selected' => $item->{value} eq $myconfig{template_format},
862 if (!$myconfig{"default_media"}) {
863 $myconfig{"default_media"} = "screen";
866 my %selected = ($myconfig{"default_media"} => "selected");
868 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
869 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
870 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
873 $form->{PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
875 my %countrycodes = User->country_codes;
877 $form->{COUNTRYCODES} = [];
878 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
879 push @{ $form->{COUNTRYCODES} }, {
880 'name' => $countrycodes{$countrycode},
881 'value' => $countrycode,
882 'selected' => $countrycode eq $myconfig{countrycode},
886 $form->{STYLESHEETS} = [];
887 foreach my $item (qw(lx-office-erp.css kivitendo.css)) {
888 push @{ $form->{STYLESHEETS} }, {
891 'selected' => $item eq $myconfig{stylesheet},
895 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
896 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
897 $form->{todo_cfg} = { TODO->get_user_config('login' => $::myconfig{login}) };
899 $form->{title} = $locale->text('Edit Preferences for #1', $::myconfig{login});
903 $form->{full_signature} = $form->create_email_signature();
905 print $form->parse_html_template('am/config');
907 $main::lxdebug->leave_sub();
910 sub save_preferences {
911 $main::lxdebug->enter_sub();
913 my $form = $main::form;
914 my %myconfig = %main::myconfig;
915 my $locale = $main::locale;
917 $form->{stylesheet} = $form->{usestylesheet};
919 TODO->save_user_config('login' => $::myconfig{login}, %{ $form->{todo_cfg} || { } });
921 if (AM->save_preferences($form)) {
922 if ($::auth->can_change_password()
923 && defined $form->{new_password}
924 && ($form->{new_password} ne '********')) {
925 my $verifier = SL::Auth::PasswordPolicy->new;
926 my $result = $verifier->verify($form->{new_password});
928 if ($result != SL::Auth::PasswordPolicy->OK()) {
929 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
932 $::auth->change_password($::myconfig{login}, $form->{new_password});
935 $form->redirect($locale->text('Preferences saved!'));
938 $form->error($locale->text('Cannot save preferences!'));
940 $main::lxdebug->leave_sub();
944 $::lxdebug->enter_sub;
945 $::auth->assert('config');
947 $::form->{title} = $::locale->text('Audit Control');
949 AM->closedto(\%::myconfig, $::form);
952 print $::form->parse_html_template('am/audit_control');
954 $::lxdebug->leave_sub;
958 $main::lxdebug->enter_sub();
960 my $form = $main::form;
961 my %myconfig = %main::myconfig;
962 my $locale = $main::locale;
964 $main::auth->assert('config');
966 AM->closebooks(\%myconfig, \%$form);
968 if ($form->{closedto}) {
970 $locale->text('Books closed up to') . " "
971 . $locale->date(\%myconfig, $form->{closedto}, 1));
973 $form->redirect($locale->text('Books are open'));
976 $main::lxdebug->leave_sub();
980 $main::lxdebug->enter_sub();
982 my $form = $main::form;
983 my %myconfig = %main::myconfig;
984 my $locale = $main::locale;
986 $main::auth->assert('config');
988 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
989 AM->units_in_use(\%myconfig, $form, $units);
990 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
992 my @languages = AM->language(\%myconfig, $form, 1);
994 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
997 foreach (@unit_list) {
998 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
999 $_->{"UNITLANGUAGES"} = [];
1000 foreach my $lang (@languages) {
1001 push(@{ $_->{"UNITLANGUAGES"} },
1003 "unit" => $_->{"name"},
1004 "language_id" => $lang->{"id"},
1005 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1006 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1012 $units = AM->retrieve_units(\%myconfig, $form);
1013 my $ddbox = AM->unit_select_data($units, undef, 1);
1015 $form->{"title"} = $locale->text("Add and edit units");
1017 print($form->parse_html_template("am/edit_units",
1018 { "UNITS" => \@unit_list,
1019 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1020 "LANGUAGES" => \@languages,
1023 $main::lxdebug->leave_sub();
1027 $main::lxdebug->enter_sub();
1029 my $form = $main::form;
1030 my %myconfig = %main::myconfig;
1031 my $locale = $main::locale;
1033 $main::auth->assert('config');
1035 $form->isblank("new_name", $locale->text("The name is missing."));
1036 my $units = AM->retrieve_units(\%myconfig, $form);
1037 my $all_units = AM->retrieve_units(\%myconfig, $form);
1038 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1040 my ($base_unit, $factor);
1041 if ($form->{"new_base_unit"}) {
1042 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1044 $form->isblank("new_factor", $locale->text("The factor is missing."));
1045 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1046 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1047 $base_unit = $form->{"new_base_unit"};
1051 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1052 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1053 push(@languages, { "id" => $lang->{"id"},
1054 "localized" => $form->{"new_localized_$lang->{id}"},
1055 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1059 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1061 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1065 $main::lxdebug->leave_sub();
1068 sub set_unit_languages {
1069 $main::lxdebug->enter_sub();
1071 my $form = $main::form;
1073 $main::auth->assert('config');
1075 my ($unit, $languages, $idx) = @_;
1077 $unit->{"LANGUAGES"} = [];
1079 foreach my $lang (@{$languages}) {
1080 push(@{ $unit->{"LANGUAGES"} },
1081 { "id" => $lang->{"id"},
1082 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1083 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1087 $main::lxdebug->leave_sub();
1091 $main::lxdebug->enter_sub();
1093 my $form = $main::form;
1094 my %myconfig = %main::myconfig;
1095 my $locale = $main::locale;
1097 $main::auth->assert('config');
1099 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1100 AM->units_in_use(\%myconfig, $form, $old_units);
1102 my @languages = AM->language(\%myconfig, $form, 1);
1105 my @delete_units = ();
1106 foreach my $i (1..($form->{"rowcount"} * 1)) {
1107 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1109 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1112 if ($form->{"unchangeable_$i"}) {
1113 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1114 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1115 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1119 if ($old_unit->{"in_use"}) {
1120 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1123 if ($form->{"delete_$i"}) {
1124 push(@delete_units, $old_unit->{"name"});
1128 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1130 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1131 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1132 $new_units->{$form->{"name_$i"}} = \%h;
1133 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1134 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1137 foreach my $unit (values(%{$new_units})) {
1138 next unless ($unit->{"old_name"});
1139 if ($unit->{"base_unit"}) {
1140 $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"}))
1141 unless (defined($new_units->{$unit->{"base_unit"}}));
1142 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1143 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1145 $unit->{"base_unit"} = undef;
1146 $unit->{"factor"} = undef;
1150 foreach my $unit (values(%{$new_units})) {
1151 next if ($unit->{"unchanged_unit"});
1153 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1154 my $new_unit = $unit;
1155 while ($new_unit->{"base_unit"}) {
1156 $new_unit->{"seen"} = 1;
1157 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1158 if ($new_unit->{"seen"}) {
1159 $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, " .
1160 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1165 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1167 $form->{"saved_message"} = $locale->text("The units have been saved.");
1171 $main::lxdebug->leave_sub();
1174 sub show_history_search {
1175 $main::lxdebug->enter_sub();
1177 my $form = $main::form;
1178 my $locale = $main::locale;
1180 $main::auth->assert('config');
1182 $form->{title} = $locale->text("History Search");
1185 print $form->parse_html_template("common/search_history");
1187 $main::lxdebug->leave_sub();
1190 sub show_am_history {
1191 $main::lxdebug->enter_sub();
1193 my $form = $main::form;
1194 my %myconfig = %main::myconfig;
1195 my $locale = $main::locale;
1197 $main::auth->assert('config');
1199 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1200 $form->{order} ||= 'h.itime--1';
1202 # my %search = ( "Artikelnummer" => "parts",
1203 # "Kundennummer" => "customer",
1204 # "Lieferantennummer" => "vendor",
1205 # "Projektnummer" => "project",
1206 # "Auftragsnummer" => "oe",
1207 # "Angebotsnummer" => "oe",
1208 # "Eingangsrechnungnummer" => "ap",
1209 # "Ausgangsrechnungnummer" => "ar",
1210 # "Mahnungsnummer" => "dunning",
1211 # "Buchungsnummer" => "gl",
1214 my %searchNo = ( "Artikelnummer" => "partnumber",
1215 "Kundennummer" => "customernumber",
1216 "Lieferantennummer" => "vendornumber",
1217 "Projektnummer" => "projectnumber",
1218 "Auftragsnummer" => "ordnumber",
1219 "Angebotsnummer" => "quonumber",
1220 "Eingangsrechnungnummer" => "invnumber",
1221 "Ausgangsrechnungnummer" => "invnumber",
1222 "Mahnungsnummer" => "dunning_id",
1223 "Buchungsnummer" => "gltransaction"
1226 my $dbh = $form->dbconnect(\%myconfig);
1229 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1230 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1231 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1232 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1233 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1234 } elsif ($form->{mitarbeiter}) {
1235 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1238 my $query = qq|SELECT trans_id AS id FROM history_erp | .
1239 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
1240 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
1242 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
1243 my $daten .= shift @ids;
1244 $daten .= join '', map { " OR trans_id = $_" } @ids;
1246 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1247 $sort =~ s/.*\.(.*)$/$1/;
1249 $form->{title} = $locale->text("History Search");
1252 print $form->parse_html_template("common/show_history",
1253 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1254 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1257 uc($sort) . "BY" => $sortby,
1258 'callback' => $callback,
1262 $main::lxdebug->leave_sub();
1266 $main::lxdebug->enter_sub();
1268 my $form = $main::form;
1269 my $locale = $main::locale;
1271 $main::auth->assert('config');
1273 $form->{title} = $locale->text('Add');
1275 $form->{callback} ||= "am.pl?action=add_tax";
1277 _get_taxaccount_selection();
1280 $form->{liability} = 1;
1281 $form->{equity} = 1;
1282 $form->{revenue} = 1;
1283 $form->{expense} = 1;
1288 my $parameters_ref = {
1289 # ChartTypeIsAccount => $ChartTypeIsAccount,
1290 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1293 # Ausgabe des Templates
1294 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1296 $main::lxdebug->leave_sub();
1300 $main::lxdebug->enter_sub();
1302 my $form = $main::form;
1303 my %myconfig = %main::myconfig;
1304 my $locale = $main::locale;
1306 $main::auth->assert('config');
1308 $form->{title} = $locale->text('Edit');
1310 AM->get_tax(\%myconfig, \%$form);
1312 _get_taxaccount_selection();
1314 $form->{asset} = $form->{chart_categories} =~ 'A' ? 1 : 0;
1315 $form->{liability} = $form->{chart_categories} =~ 'L' ? 1 : 0;
1316 $form->{equity} = $form->{chart_categories} =~ 'Q' ? 1 : 0;
1317 $form->{revenue} = $form->{chart_categories} =~ 'I' ? 1 : 0;
1318 $form->{expense} = $form->{chart_categories} =~ 'E' ? 1 : 0;
1319 $form->{costs} = $form->{chart_categories} =~ 'C' ? 1 : 0;
1321 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1325 my $parameters_ref = {
1326 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1327 TAX => SL::DB::Manager::Tax->find_by(id => $form->{id}),
1330 # Ausgabe des Templates
1331 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1333 $main::lxdebug->leave_sub();
1337 $main::lxdebug->enter_sub();
1339 my $form = $main::form;
1340 my %myconfig = %main::myconfig;
1341 my $locale = $main::locale;
1343 $main::auth->assert('config');
1345 AM->taxes(\%myconfig, \%$form);
1347 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1349 $form->{callback} = build_std_url('action=list_tax');
1351 $form->{title} = $locale->text('Tax-O-Matic');
1355 my $parameters_ref = {
1358 # Ausgabe des Templates
1359 print($form->parse_html_template('am/list_tax', $parameters_ref));
1361 $main::lxdebug->leave_sub();
1364 sub _get_taxaccount_selection{
1365 $main::lxdebug->enter_sub();
1367 my $form = $main::form;
1368 my %myconfig = %main::myconfig;
1370 $main::auth->assert('config');
1372 AM->get_tax_accounts(\%myconfig, \%$form);
1374 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1376 $main::lxdebug->leave_sub();
1380 $main::lxdebug->enter_sub();
1382 my $form = $main::form;
1383 my %myconfig = %main::myconfig;
1384 my $locale = $main::locale;
1386 $main::auth->assert('config');
1388 $form->error($locale->text('Taxkey missing!')) unless length($form->{taxkey}) != 0;
1389 $form->error($locale->text('Taxdescription missing!')) unless length($form->{taxdescription}) != 0;
1390 $form->error($locale->text('Taxrate missing!')) unless length($form->{rate}) != 0;
1392 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1394 if ($form->{taxkey} == 0 and $form->{rate} > 0) {
1395 $form->error($locale->text('Taxkey 0 is reserved for rate 0'));
1398 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1399 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1402 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
1403 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1406 my @translation_keys = grep { $_ =~ '^translation_\d+' } keys %$form;
1407 $form->{translations} = { map { $_ =~ '^translation_(\d+)'; $1 => $form->{$_} } @translation_keys };
1409 AM->save_tax(\%myconfig, \%$form);
1410 $form->redirect($locale->text('Tax saved!'));
1412 $main::lxdebug->leave_sub();
1416 $main::lxdebug->enter_sub();
1418 my $form = $main::form;
1419 my %myconfig = %main::myconfig;
1420 my $locale = $main::locale;
1422 $main::auth->assert('config');
1424 AM->delete_tax(\%myconfig, \%$form);
1425 $form->redirect($locale->text('Tax deleted!'));
1427 $main::lxdebug->leave_sub();
1430 sub add_price_factor {
1431 $main::lxdebug->enter_sub();
1433 my $form = $main::form;
1434 my $locale = $main::locale;
1436 $main::auth->assert('config');
1438 $form->{title} = $locale->text('Add Price Factor');
1439 $form->{callback} ||= build_std_url('action=add_price_factor');
1442 print $form->parse_html_template('am/edit_price_factor');
1444 $main::lxdebug->leave_sub();
1447 sub edit_price_factor {
1448 $main::lxdebug->enter_sub();
1450 my $form = $main::form;
1451 my %myconfig = %main::myconfig;
1452 my $locale = $main::locale;
1454 $main::auth->assert('config');
1456 $form->{title} = $locale->text('Edit Price Factor');
1457 $form->{callback} ||= build_std_url('action=add_price_factor');
1459 AM->get_price_factor(\%myconfig, $form);
1461 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
1464 print $form->parse_html_template('am/edit_price_factor');
1466 $main::lxdebug->leave_sub();
1469 sub list_price_factors {
1470 $main::lxdebug->enter_sub();
1472 my $form = $main::form;
1473 my %myconfig = %main::myconfig;
1474 my $locale = $main::locale;
1476 $main::auth->assert('config');
1478 AM->get_all_price_factors(\%myconfig, \%$form);
1480 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
1481 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
1484 $form->{callback} = build_std_url('action=list_price_factors');
1485 $form->{title} = $locale->text('Price Factors');
1486 $form->{url_base} = build_std_url('callback');
1489 print $form->parse_html_template('am/list_price_factors');
1491 $main::lxdebug->leave_sub();
1494 sub save_price_factor {
1495 $main::lxdebug->enter_sub();
1497 my $form = $main::form;
1498 my %myconfig = %main::myconfig;
1499 my $locale = $main::locale;
1501 $main::auth->assert('config');
1503 $form->isblank("description", $locale->text('Description missing!'));
1504 $form->isblank("factor", $locale->text('Factor missing!'));
1506 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
1508 AM->save_price_factor(\%myconfig, $form);
1510 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
1512 $form->redirect($locale->text('Price factor saved!'));
1514 $main::lxdebug->leave_sub();
1517 sub delete_price_factor {
1518 $main::lxdebug->enter_sub();
1520 my $form = $main::form;
1521 my %myconfig = %main::myconfig;
1522 my $locale = $main::locale;
1524 $main::auth->assert('config');
1526 AM->delete_price_factor(\%myconfig, \%$form);
1528 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
1530 $form->redirect($locale->text('Price factor deleted!'));
1532 $main::lxdebug->leave_sub();
1536 $main::lxdebug->enter_sub();
1538 my $form = $main::form;
1539 my $locale = $main::locale;
1541 $main::auth->assert('config');
1543 $form->{title} = $locale->text('Add Warehouse');
1544 $form->{callback} ||= build_std_url('action=add_warehouse');
1547 print $form->parse_html_template('am/edit_warehouse');
1549 $main::lxdebug->leave_sub();
1552 sub edit_warehouse {
1553 $main::lxdebug->enter_sub();
1555 my $form = $main::form;
1556 my %myconfig = %main::myconfig;
1557 my $locale = $main::locale;
1559 $main::auth->assert('config');
1561 AM->get_warehouse(\%myconfig, $form);
1563 $form->get_lists('employees' => 'EMPLOYEES');
1565 $form->{title} = $locale->text('Edit Warehouse');
1566 $form->{callback} ||= build_std_url('action=list_warehouses');
1569 print $form->parse_html_template('am/edit_warehouse');
1571 $main::lxdebug->leave_sub();
1574 sub list_warehouses {
1575 $main::lxdebug->enter_sub();
1577 my $form = $main::form;
1578 my %myconfig = %main::myconfig;
1579 my $locale = $main::locale;
1581 $main::auth->assert('config');
1583 AM->get_all_warehouses(\%myconfig, $form);
1585 $form->{callback} = build_std_url('action=list_warehouses');
1586 $form->{title} = $locale->text('Warehouses');
1587 $form->{url_base} = build_std_url('callback');
1590 print $form->parse_html_template('am/list_warehouses');
1592 $main::lxdebug->leave_sub();
1595 sub save_warehouse {
1596 $main::lxdebug->enter_sub();
1598 my $form = $main::form;
1599 my %myconfig = %main::myconfig;
1600 my $locale = $main::locale;
1602 $main::auth->assert('config');
1604 $form->isblank("description", $locale->text('Description missing!'));
1606 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
1608 AM->save_warehouse(\%myconfig, $form);
1610 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
1612 $form->redirect($locale->text('Warehouse saved.'));
1614 $main::lxdebug->leave_sub();
1617 sub delete_warehouse {
1618 $main::lxdebug->enter_sub();
1620 my $form = $main::form;
1621 my %myconfig = %main::myconfig;
1622 my $locale = $main::locale;
1624 $main::auth->assert('config');
1626 if (!$form->{confirmed}) {
1627 $form->{title} = $locale->text('Confirmation');
1630 print $form->parse_html_template('am/confirm_delete_warehouse');
1634 if (AM->delete_warehouse(\%myconfig, $form)) {
1635 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
1636 $form->redirect($locale->text('Warehouse deleted.'));
1639 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
1642 $main::lxdebug->leave_sub();
1646 $main::lxdebug->enter_sub();
1648 my $form = $main::form;
1649 my %myconfig = %main::myconfig;
1650 my $locale = $main::locale;
1652 $main::auth->assert('config');
1654 AM->save_bins(\%myconfig, $form);
1656 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
1658 $form->redirect($locale->text('Bins saved.'));
1660 $main::lxdebug->leave_sub();