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(scalar(grep(/^Switzerland/, (selectrow_query($form, $form->get_standard_dbh, 'SELECT coa FROM defaults'))[0]))) {
222 3 => "Mitgliederbeiträge",
223 4 => "Finanzerträge",
224 5 => "Ertragsminderungen",
226 7 => "Löhne und Gehälter",
227 8 => "Sozialversicherungen",
229 10 => "Betriebsversicherungen",
230 11 => "Material- und Warenverluste",
231 12 => "Werbeaufwand",
232 13 => "Werkzeuge, Unterhalt, Betriebsmaterial",
233 14 => "Internet- und Serverhousingkosten",
234 15 => "Arbeitsleistungen externer Firmen",
235 16 => "Bürobedarf, Versandspesen, Telefon",
236 17 => "Sonstige Aufwendungen",
237 18 => "Abschreibungen",
238 19 => "Finanzaufwand",
239 20 => "Aufwandsminderungen",
240 21 => "Betriebliche Steuern",
245 2 => "sonstige Erlöse",
246 3 => "Privatanteile",
248 5 => "Ausserordentliche Erträge",
249 6 => "Vereinnahmte Umsatzst.",
250 7 => "Umsatzsteuererstattungen",
251 8 => "Wareneingänge",
252 9 => "Löhne und Gehälter",
253 10 => "Gesetzl. sozialer Aufw.",
255 12 => "Gas, Strom, Wasser",
256 13 => "Instandhaltung",
257 14 => "Steuern, Versich., Beiträge",
259 16 => "Kfz-Versicherungen",
260 17 => "Sonst. Fahrzeugkosten",
261 18 => "Werbe- und Reisekosten",
262 19 => "Instandhaltung u. Werkzeuge",
263 20 => "Fachzeitschriften, Bücher",
264 21 => "Miete für Einrichtungen",
265 22 => "Rechts- und Beratungskosten",
266 23 => "Bürobedarf, Porto, Telefon",
267 24 => "Sonstige Aufwendungen",
268 25 => "Abschreibungen auf Anlagever.",
269 26 => "Abschreibungen auf GWG",
271 28 => "Umsatzsteuerzahlungen",
273 30 => "Ausserordentlicher Aufwand",
274 31 => "Betriebliche Steuern",
277 foreach my $item (sort({ $a <=> $b } keys(%eur))) {
278 my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
279 if ($item == $form->{pos_eur}) {
280 $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
282 $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
287 my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
291 2 => 'Best.Verdg.FE/UE',
292 3 => 'Aktiv.Eigenleistung',
293 4 => 'Mat./Wareneinkauf',
294 5 => 'So.betr.Erlöse',
295 10 => 'Personalkosten',
297 12 => 'Betriebl.Steuern',
298 13 => 'Vers./Beiträge',
299 14 => 'Kfz.Kosten o.St.',
300 15 => 'Werbe-Reisek.',
301 16 => 'Kosten Warenabgabe',
302 17 => 'Abschreibungen',
303 18 => 'Rep./instandhlt.',
304 19 => 'Übrige Steuern',
305 20 => 'Sonst.Kosten',
307 31 => 'Sonst.neutr.Aufw.',
309 33 => 'Sonst.neutr.Ertrag',
310 34 => 'Verr.kalk.Kosten',
311 35 => 'Steuern Eink.u.Ertr.');
312 foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
313 my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
314 if ($item == $form->{pos_bwa}) {
315 $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
317 $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
322 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
323 my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
324 foreach my $item ((1, 2, 3, 4)) {
325 if ($item == $form->{pos_bilanz}) {
326 $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
328 $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
333 # this is for our parser only! Do not remove.
334 # type=submit $locale->text('Add Account')
335 # type=submit $locale->text('Edit Account')
337 $form->{type} = "account";
339 # preselections category
341 my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
344 'A' => $locale->text('Asset'),
345 'L' => $locale->text('Liability'),
346 'Q' => $locale->text('Equity'),
347 'I' => $locale->text('Revenue'),
348 'E' => $locale->text('Expense'),
349 'C' => $locale->text('Costs'),
351 foreach my $item ( sort({ $a <=> $b } keys %category) ) {
352 if ($item eq $form->{category}) {
353 $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
355 $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
360 # preselection chart type
361 my @all_charttypes = ({'name' => $locale->text('Account'), 'value' => 'A'},
362 {'name' => $locale->text('Heading'), 'value' => 'H'},
364 my $selected_charttype = $form->{charttype};
367 # account where AR_tax or AP_tax is set are not orphaned if they are used as
368 # tax-o-matic account
369 if ( $form->{id} && $form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
370 if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
371 $form->{orphaned} = 0;
375 my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
376 my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
380 my $parameters_ref = {
381 ChartTypeIsAccount => $ChartTypeIsAccount,
382 AccountIsPosted => $AccountIsPosted,
383 select_category => $select_category,
384 all_charttypes => \@all_charttypes,
385 selected_charttype => $selected_charttype,
386 select_bwa => $select_bwa,
387 select_bilanz => $select_bilanz,
388 select_eur => $select_eur,
391 # Ausgabe des Templates
392 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
395 $main::lxdebug->leave_sub();
399 $::lxdebug->enter_sub;
400 $::auth->assert('config');
402 print $::form->parse_html_template('am/form_footer', {
403 show_save => !$::form->{id}
404 || ($::form->{id} && $::form->{orphaned})
405 || ($::form->{type} eq "account" && !$::form->{new_chart_valid}),
406 show_delete => $::form->{id} && $::form->{orphaned},
407 show_save_as_new => $::form->{id} && $::form->{type} eq "account",
410 $::lxdebug->leave_sub;
414 $main::lxdebug->enter_sub();
416 my $form = $main::form;
417 my %myconfig = %main::myconfig;
418 my $locale = $main::locale;
420 $main::auth->assert('config');
422 $form->isblank("accno", $locale->text('Account Number missing!'));
423 $form->isblank("description", $locale->text('Account Description missing!'));
425 if ($form->{charttype} eq 'A'){
426 $form->isblank("category", $locale->text('Account Type missing!'));
428 my $found_valid_taxkey = 0;
429 foreach my $i (0 .. 10) { # 10 is maximum count of taxkeys in form
430 if ($form->{"taxkey_startdate_$i"} and !$form->{"taxkey_del_$i"}) {
431 $found_valid_taxkey = 1;
435 if ($found_valid_taxkey == 0) {
436 $form->error($locale->text('A valid taxkey is missing!'));
440 $form->redirect($locale->text('Account saved!'))
441 if (AM->save_account(\%myconfig, \%$form));
442 $form->error($locale->text('Cannot save account!'));
444 $main::lxdebug->leave_sub();
447 sub save_as_new_account {
448 $main::lxdebug->enter_sub();
450 my $form = $main::form;
451 my %myconfig = %main::myconfig;
452 my $locale = $main::locale;
454 $main::auth->assert('config');
456 $form->isblank("accno", $locale->text('Account Number missing!'));
457 $form->isblank("description", $locale->text('Account Description missing!'));
459 if ($form->{charttype} eq 'A'){
460 $form->isblank("category", $locale->text('Account Type missing!'));
463 for my $taxkey (0 .. 9) {
464 if ($form->{"taxkey_id_$taxkey"}) {
465 $form->{"taxkey_id_$taxkey"} = "NEW";
470 $form->redirect($locale->text('Account saved!'))
471 if (AM->save_account(\%myconfig, \%$form));
472 $form->error($locale->text('Cannot save account!'));
474 $main::lxdebug->leave_sub();
478 $main::lxdebug->enter_sub();
480 my $form = $main::form;
481 my %myconfig = %main::myconfig;
482 my $locale = $main::locale;
484 $main::auth->assert('config');
486 $form->{callback} = build_std_url('action=list_account');
487 my $link_edit_account = build_std_url('action=edit_account', 'callback');
489 CA->all_accounts(\%myconfig, \%$form);
491 foreach my $ca (@{ $form->{CA} }) {
496 if ($ca->{amount} > 0) {
497 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
499 if ($ca->{amount} < 0) {
500 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
502 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
503 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
506 $::request->{layout}->use_stylesheet("list_accounts.css");
507 $form->{title} = $locale->text('Chart of Accounts');
512 my $parameters_ref = {
513 # hidden_variables => $_hidden_variables_ref,
516 # Ausgabe des Templates
517 print($form->parse_html_template('am/list_accounts', $parameters_ref));
519 $main::lxdebug->leave_sub();
524 sub list_account_details {
525 # Ajax Funktion aus list_account_details
526 $main::lxdebug->enter_sub();
528 my $form = $main::form;
529 my %myconfig = %main::myconfig;
530 my $locale = $main::locale;
532 $main::auth->assert('config');
534 my $chart_id = $form->{args};
536 CA->all_accounts(\%myconfig, \%$form, $chart_id);
538 foreach my $ca (@{ $form->{CA} }) {
540 $ca->{debit} = " ";
541 $ca->{credit} = " ";
543 if ($ca->{amount} > 0) {
545 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
547 if ($ca->{amount} < 0) {
549 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
552 my @links = split( q{:}, $ca->{link});
556 foreach my $link (@links){
557 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
558 : ( $link eq 'AP') ? $locale->text('Account Link AP')
559 : ( $link eq 'IC') ? $locale->text('Account Link IC')
560 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
561 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
562 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
563 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
564 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
565 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
566 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
567 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
568 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
569 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
570 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
571 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
572 : $locale->text('Unknown Link') . ': ' . $link;
573 $ca->{link} .= ($link ne '') ? "[$link] ":'';
576 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
577 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
578 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
579 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
580 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
581 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
582 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
583 : $locale->text('Unknown Category') . ': ' . $ca->{category};
586 $form->{title} = $locale->text('Chart of Accounts');
588 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
590 $main::lxdebug->leave_sub();
595 $main::lxdebug->enter_sub();
597 my $form = $main::form;
598 my %myconfig = %main::myconfig;
599 my $locale = $main::locale;
601 $main::auth->assert('config');
603 $form->{title} = $locale->text('Delete Account');
606 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
608 if ($form->{id} == $form->{$id}) {
609 $form->error($locale->text('Cannot delete default account!'));
613 $form->redirect($locale->text('Account deleted!'))
614 if (AM->delete_account(\%myconfig, \%$form));
615 $form->error($locale->text('Cannot delete account!'));
617 $main::lxdebug->leave_sub();
621 $main::lxdebug->enter_sub();
623 my $form = $main::form;
625 $main::auth->assert('config');
627 $form->{title} = "Add";
629 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
634 $main::lxdebug->leave_sub();
638 $main::lxdebug->enter_sub();
640 my $form = $main::form;
641 my %myconfig = %main::myconfig;
643 $main::auth->assert('config');
645 $form->{title} = "Edit";
647 AM->get_lead(\%myconfig, \%$form);
651 $form->{orphaned} = 1;
654 $main::lxdebug->leave_sub();
658 $::lxdebug->enter_sub;
659 $::auth->assert('config');
661 AM->lead(\%::myconfig, $::form);
663 $::form->{callback} = "am.pl?action=list_lead";
664 $::form->{title} = $::locale->text('Lead');
667 print $::form->parse_html_template('am/lead_list');
669 $::lxdebug->leave_sub;
673 $::lxdebug->enter_sub;
674 $::auth->assert('config');
676 # $locale->text('Add Lead')
677 # $locale->text('Edit Lead')
678 $::form->{title} = $::locale->text("$::form->{title} Lead");
681 print $::form->parse_html_template('am/lead_header');
683 $::lxdebug->leave_sub;
687 $main::lxdebug->enter_sub();
689 my $form = $main::form;
690 my %myconfig = %main::myconfig;
691 my $locale = $main::locale;
693 $main::auth->assert('config');
695 $form->isblank("description", $locale->text('Description missing!'));
696 AM->save_lead(\%myconfig, \%$form);
697 $form->redirect($locale->text('lead saved!'));
699 $main::lxdebug->leave_sub();
703 $main::lxdebug->enter_sub();
705 my $form = $main::form;
706 my %myconfig = %main::myconfig;
707 my $locale = $main::locale;
709 $main::auth->assert('config');
711 AM->delete_lead(\%myconfig, \%$form);
712 $form->redirect($locale->text('lead deleted!'));
714 $main::lxdebug->leave_sub();
718 $main::lxdebug->enter_sub();
720 my $form = $main::form;
722 $main::auth->assert('config');
724 $form->{title} = "Add";
726 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
731 $main::lxdebug->leave_sub();
735 $main::lxdebug->enter_sub();
737 my $form = $main::form;
738 my %myconfig = %main::myconfig;
740 $main::auth->assert('config');
742 $form->{title} = "Edit";
744 AM->get_language(\%myconfig, \%$form);
748 $form->{orphaned} = 1;
751 $main::lxdebug->leave_sub();
755 $::lxdebug->enter_sub;
756 $::auth->assert('config');
758 AM->language(\%::myconfig, $::form);
760 $::form->{callback} = "am.pl?action=list_language";
761 $::form->{title} = $::locale->text('Languages');
765 print $::form->parse_html_template('am/language_list');
767 $::lxdebug->leave_sub;
770 sub language_header {
771 $::lxdebug->enter_sub;
772 $::auth->assert('config');
774 # $locale->text('Add Language')
775 # $locale->text('Edit Language')
776 $::form->{title} = $::locale->text("$::form->{title} Language");
780 print $::form->parse_html_template('am/language_header', {
781 numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00" ],
782 dateformats => [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
785 $::lxdebug->leave_sub;
789 $main::lxdebug->enter_sub();
791 my $form = $main::form;
792 my %myconfig = %main::myconfig;
793 my $locale = $main::locale;
795 $main::auth->assert('config');
797 $form->isblank("description", $locale->text('Language missing!'));
798 $form->isblank("template_code", $locale->text('Template Code missing!'));
799 $form->isblank("article_code", $locale->text('Article Code missing!'));
800 AM->save_language(\%myconfig, \%$form);
801 $form->redirect($locale->text('Language saved!'));
803 $main::lxdebug->leave_sub();
806 sub delete_language {
807 $main::lxdebug->enter_sub();
809 my $form = $main::form;
810 my %myconfig = %main::myconfig;
811 my $locale = $main::locale;
813 $main::auth->assert('config');
815 AM->delete_language(\%myconfig, \%$form);
816 $form->redirect($locale->text('Language deleted!'));
818 $main::lxdebug->leave_sub();
821 sub _build_cfg_options {
822 my $form = $main::form;
823 my %myconfig = %main::myconfig;
826 my $array = uc($idx) . 'S';
828 $form->{$array} = [];
829 foreach my $item (@_) {
830 push @{ $form->{$array} }, {
833 'selected' => $item eq $myconfig{$idx},
839 $main::lxdebug->enter_sub();
841 my $form = $main::form;
842 my %myconfig = %main::myconfig;
843 my $locale = $main::locale;
845 _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
846 _build_cfg_options('timeformat', qw(hh:mm hh:mm:ss));
847 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00"));
850 if ($::lx_office_conf{print_templates}->{opendocument}
851 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
852 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
853 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
854 "value" => "opendocument_pdf" });
856 if ($::lx_office_conf{print_templates}->{latex}) {
857 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
859 push(@formats, { "name" => "HTML", "value" => "html" });
860 if ($::lx_office_conf{print_templates}->{latex}) {
861 push(@formats, { "name" => $locale->text("Postscript"),
862 "value" => "postscript" });
864 if ($::lx_office_conf{print_templates}->{opendocument}) {
865 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
866 "value" => "opendocument" });
869 if (!$myconfig{"template_format"}) {
870 $myconfig{"template_format"} = "pdf";
872 $form->{TEMPLATE_FORMATS} = [];
873 foreach my $item (@formats) {
874 push @{ $form->{TEMPLATE_FORMATS} }, {
875 'name' => $item->{name},
876 'value' => $item->{value},
877 'selected' => $item->{value} eq $myconfig{template_format},
881 if (!$myconfig{"default_media"}) {
882 $myconfig{"default_media"} = "screen";
885 my %selected = ($myconfig{"default_media"} => "selected");
887 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
888 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
889 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
892 $form->{PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
894 my %countrycodes = User->country_codes;
896 $form->{COUNTRYCODES} = [];
897 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
898 push @{ $form->{COUNTRYCODES} }, {
899 'name' => $countrycodes{$countrycode},
900 'value' => $countrycode,
901 'selected' => $countrycode eq $myconfig{countrycode},
905 $form->{STYLESHEETS} = [];
906 foreach my $item (qw(lx-office-erp.css kivitendo.css)) {
907 push @{ $form->{STYLESHEETS} }, {
910 'selected' => $item eq $myconfig{stylesheet},
914 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
915 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
916 $form->{todo_cfg} = { TODO->get_user_config('login' => $::myconfig{login}) };
918 $form->{title} = $locale->text('Edit Preferences for #1', $::myconfig{login});
922 $form->{full_signature} = $form->create_email_signature();
924 print $form->parse_html_template('am/config');
926 $main::lxdebug->leave_sub();
929 sub save_preferences {
930 $main::lxdebug->enter_sub();
932 my $form = $main::form;
933 my %myconfig = %main::myconfig;
934 my $locale = $main::locale;
936 $form->{stylesheet} = $form->{usestylesheet};
938 TODO->save_user_config('login' => $::myconfig{login}, %{ $form->{todo_cfg} || { } });
940 if (AM->save_preferences($form)) {
941 if ($::auth->can_change_password()
942 && defined $form->{new_password}
943 && ($form->{new_password} ne '********')) {
944 my $verifier = SL::Auth::PasswordPolicy->new;
945 my $result = $verifier->verify($form->{new_password});
947 if ($result != SL::Auth::PasswordPolicy->OK()) {
948 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
951 $::auth->change_password($::myconfig{login}, $form->{new_password});
954 $form->redirect($locale->text('Preferences saved!'));
957 $form->error($locale->text('Cannot save preferences!'));
959 $main::lxdebug->leave_sub();
963 $::lxdebug->enter_sub;
964 $::auth->assert('config');
966 $::form->{title} = $::locale->text('Audit Control');
968 AM->closedto(\%::myconfig, $::form);
971 print $::form->parse_html_template('am/audit_control');
973 $::lxdebug->leave_sub;
977 $main::lxdebug->enter_sub();
979 my $form = $main::form;
980 my %myconfig = %main::myconfig;
981 my $locale = $main::locale;
983 $main::auth->assert('config');
985 AM->closebooks(\%myconfig, \%$form);
987 if ($form->{closedto}) {
989 $locale->text('Books closed up to') . " "
990 . $locale->date(\%myconfig, $form->{closedto}, 1));
992 $form->redirect($locale->text('Books are open'));
995 $main::lxdebug->leave_sub();
999 $main::lxdebug->enter_sub();
1001 my $form = $main::form;
1002 my %myconfig = %main::myconfig;
1003 my $locale = $main::locale;
1005 $main::auth->assert('config');
1007 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1008 AM->units_in_use(\%myconfig, $form, $units);
1009 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1011 my @languages = AM->language(\%myconfig, $form, 1);
1013 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1016 foreach (@unit_list) {
1017 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1018 $_->{"UNITLANGUAGES"} = [];
1019 foreach my $lang (@languages) {
1020 push(@{ $_->{"UNITLANGUAGES"} },
1022 "unit" => $_->{"name"},
1023 "language_id" => $lang->{"id"},
1024 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1025 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1031 $units = AM->retrieve_units(\%myconfig, $form);
1032 my $ddbox = AM->unit_select_data($units, undef, 1);
1034 $form->{"title"} = $locale->text("Add and edit units");
1036 print($form->parse_html_template("am/edit_units",
1037 { "UNITS" => \@unit_list,
1038 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1039 "LANGUAGES" => \@languages,
1042 $main::lxdebug->leave_sub();
1046 $main::lxdebug->enter_sub();
1048 my $form = $main::form;
1049 my %myconfig = %main::myconfig;
1050 my $locale = $main::locale;
1052 $main::auth->assert('config');
1054 $form->isblank("new_name", $locale->text("The name is missing."));
1055 my $units = AM->retrieve_units(\%myconfig, $form);
1056 my $all_units = AM->retrieve_units(\%myconfig, $form);
1057 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1059 my ($base_unit, $factor);
1060 if ($form->{"new_base_unit"}) {
1061 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1063 $form->isblank("new_factor", $locale->text("The factor is missing."));
1064 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1065 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1066 $base_unit = $form->{"new_base_unit"};
1070 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1071 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1072 push(@languages, { "id" => $lang->{"id"},
1073 "localized" => $form->{"new_localized_$lang->{id}"},
1074 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1078 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1080 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1084 $main::lxdebug->leave_sub();
1087 sub set_unit_languages {
1088 $main::lxdebug->enter_sub();
1090 my $form = $main::form;
1092 $main::auth->assert('config');
1094 my ($unit, $languages, $idx) = @_;
1096 $unit->{"LANGUAGES"} = [];
1098 foreach my $lang (@{$languages}) {
1099 push(@{ $unit->{"LANGUAGES"} },
1100 { "id" => $lang->{"id"},
1101 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1102 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1106 $main::lxdebug->leave_sub();
1110 $main::lxdebug->enter_sub();
1112 my $form = $main::form;
1113 my %myconfig = %main::myconfig;
1114 my $locale = $main::locale;
1116 $main::auth->assert('config');
1118 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1119 AM->units_in_use(\%myconfig, $form, $old_units);
1121 my @languages = AM->language(\%myconfig, $form, 1);
1124 my @delete_units = ();
1125 foreach my $i (1..($form->{"rowcount"} * 1)) {
1126 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1128 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1131 if ($form->{"unchangeable_$i"}) {
1132 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1133 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1134 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1138 if ($old_unit->{"in_use"}) {
1139 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1142 if ($form->{"delete_$i"}) {
1143 push(@delete_units, $old_unit->{"name"});
1147 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1149 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1150 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1151 $new_units->{$form->{"name_$i"}} = \%h;
1152 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1153 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1156 foreach my $unit (values(%{$new_units})) {
1157 next unless ($unit->{"old_name"});
1158 if ($unit->{"base_unit"}) {
1159 $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"}))
1160 unless (defined($new_units->{$unit->{"base_unit"}}));
1161 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1162 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1164 $unit->{"base_unit"} = undef;
1165 $unit->{"factor"} = undef;
1169 foreach my $unit (values(%{$new_units})) {
1170 next if ($unit->{"unchanged_unit"});
1172 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1173 my $new_unit = $unit;
1174 while ($new_unit->{"base_unit"}) {
1175 $new_unit->{"seen"} = 1;
1176 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1177 if ($new_unit->{"seen"}) {
1178 $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, " .
1179 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1184 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1186 $form->{"saved_message"} = $locale->text("The units have been saved.");
1190 $main::lxdebug->leave_sub();
1193 sub show_history_search {
1194 $main::lxdebug->enter_sub();
1196 my $form = $main::form;
1197 my $locale = $main::locale;
1199 $main::auth->assert('config');
1201 $form->{title} = $locale->text("History Search");
1204 print $form->parse_html_template("common/search_history");
1206 $main::lxdebug->leave_sub();
1209 sub show_am_history {
1210 $main::lxdebug->enter_sub();
1212 my $form = $main::form;
1213 my %myconfig = %main::myconfig;
1214 my $locale = $main::locale;
1216 $main::auth->assert('config');
1218 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1219 $form->{order} ||= 'h.itime--1';
1221 # my %search = ( "Artikelnummer" => "parts",
1222 # "Kundennummer" => "customer",
1223 # "Lieferantennummer" => "vendor",
1224 # "Projektnummer" => "project",
1225 # "Auftragsnummer" => "oe",
1226 # "Angebotsnummer" => "oe",
1227 # "Eingangsrechnungnummer" => "ap",
1228 # "Ausgangsrechnungnummer" => "ar",
1229 # "Mahnungsnummer" => "dunning",
1230 # "Buchungsnummer" => "gl",
1233 my %searchNo = ( "Artikelnummer" => "partnumber",
1234 "Kundennummer" => "customernumber",
1235 "Lieferantennummer" => "vendornumber",
1236 "Projektnummer" => "projectnumber",
1237 "Auftragsnummer" => "ordnumber",
1238 "Angebotsnummer" => "quonumber",
1239 "Eingangsrechnungnummer" => "invnumber",
1240 "Ausgangsrechnungnummer" => "invnumber",
1241 "Mahnungsnummer" => "dunning_id",
1242 "Buchungsnummer" => "gltransaction"
1245 my $dbh = $form->dbconnect(\%myconfig);
1248 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1249 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1250 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1251 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1252 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1253 } elsif ($form->{mitarbeiter}) {
1254 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1257 my $query = qq|SELECT trans_id AS id FROM history_erp | .
1258 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
1259 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
1261 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
1262 my $daten .= shift @ids;
1263 $daten .= join '', map { " OR trans_id = $_" } @ids;
1265 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1266 $sort =~ s/.*\.(.*)$/$1/;
1268 $form->{title} = $locale->text("History Search");
1271 print $form->parse_html_template("common/show_history",
1272 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1273 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1276 uc($sort) . "BY" => $sortby,
1277 'callback' => $callback,
1281 $main::lxdebug->leave_sub();
1285 $main::lxdebug->enter_sub();
1287 my $form = $main::form;
1288 my $locale = $main::locale;
1290 $main::auth->assert('config');
1292 $form->{title} = $locale->text('Add');
1294 $form->{callback} ||= "am.pl?action=add_tax";
1296 _get_taxaccount_selection();
1299 $form->{liability} = 1;
1300 $form->{equity} = 1;
1301 $form->{revenue} = 1;
1302 $form->{expense} = 1;
1307 my $parameters_ref = {
1308 # ChartTypeIsAccount => $ChartTypeIsAccount,
1309 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1312 # Ausgabe des Templates
1313 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1315 $main::lxdebug->leave_sub();
1319 $main::lxdebug->enter_sub();
1321 my $form = $main::form;
1322 my %myconfig = %main::myconfig;
1323 my $locale = $main::locale;
1325 $main::auth->assert('config');
1327 $form->{title} = $locale->text('Edit');
1329 AM->get_tax(\%myconfig, \%$form);
1331 _get_taxaccount_selection();
1333 $form->{asset} = $form->{chart_categories} =~ 'A' ? 1 : 0;
1334 $form->{liability} = $form->{chart_categories} =~ 'L' ? 1 : 0;
1335 $form->{equity} = $form->{chart_categories} =~ 'Q' ? 1 : 0;
1336 $form->{revenue} = $form->{chart_categories} =~ 'I' ? 1 : 0;
1337 $form->{expense} = $form->{chart_categories} =~ 'E' ? 1 : 0;
1338 $form->{costs} = $form->{chart_categories} =~ 'C' ? 1 : 0;
1340 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1344 my $parameters_ref = {
1345 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1346 TAX => SL::DB::Manager::Tax->find_by(id => $form->{id}),
1349 # Ausgabe des Templates
1350 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1352 $main::lxdebug->leave_sub();
1356 $main::lxdebug->enter_sub();
1358 my $form = $main::form;
1359 my %myconfig = %main::myconfig;
1360 my $locale = $main::locale;
1362 $main::auth->assert('config');
1364 AM->taxes(\%myconfig, \%$form);
1366 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1368 $form->{callback} = build_std_url('action=list_tax');
1370 $form->{title} = $locale->text('Tax-O-Matic');
1374 my $parameters_ref = {
1377 # Ausgabe des Templates
1378 print($form->parse_html_template('am/list_tax', $parameters_ref));
1380 $main::lxdebug->leave_sub();
1383 sub _get_taxaccount_selection{
1384 $main::lxdebug->enter_sub();
1386 my $form = $main::form;
1387 my %myconfig = %main::myconfig;
1389 $main::auth->assert('config');
1391 AM->get_tax_accounts(\%myconfig, \%$form);
1393 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1395 $main::lxdebug->leave_sub();
1399 $main::lxdebug->enter_sub();
1401 my $form = $main::form;
1402 my %myconfig = %main::myconfig;
1403 my $locale = $main::locale;
1405 $main::auth->assert('config');
1407 $form->error($locale->text('Taxkey missing!')) unless length($form->{taxkey}) != 0;
1408 $form->error($locale->text('Taxdescription missing!')) unless length($form->{taxdescription}) != 0;
1409 $form->error($locale->text('Taxrate missing!')) unless length($form->{rate}) != 0;
1411 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1413 if ($form->{taxkey} == 0 and $form->{rate} > 0) {
1414 $form->error($locale->text('Taxkey 0 is reserved for rate 0'));
1417 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1418 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1421 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
1422 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1425 my @translation_keys = grep { $_ =~ '^translation_\d+' } keys %$form;
1426 $form->{translations} = { map { $_ =~ '^translation_(\d+)'; $1 => $form->{$_} } @translation_keys };
1428 AM->save_tax(\%myconfig, \%$form);
1429 $form->redirect($locale->text('Tax saved!'));
1431 $main::lxdebug->leave_sub();
1435 $main::lxdebug->enter_sub();
1437 my $form = $main::form;
1438 my %myconfig = %main::myconfig;
1439 my $locale = $main::locale;
1441 $main::auth->assert('config');
1443 AM->delete_tax(\%myconfig, \%$form);
1444 $form->redirect($locale->text('Tax deleted!'));
1446 $main::lxdebug->leave_sub();
1449 sub add_price_factor {
1450 $main::lxdebug->enter_sub();
1452 my $form = $main::form;
1453 my $locale = $main::locale;
1455 $main::auth->assert('config');
1457 $form->{title} = $locale->text('Add Price Factor');
1458 $form->{callback} ||= build_std_url('action=add_price_factor');
1461 print $form->parse_html_template('am/edit_price_factor');
1463 $main::lxdebug->leave_sub();
1466 sub edit_price_factor {
1467 $main::lxdebug->enter_sub();
1469 my $form = $main::form;
1470 my %myconfig = %main::myconfig;
1471 my $locale = $main::locale;
1473 $main::auth->assert('config');
1475 $form->{title} = $locale->text('Edit Price Factor');
1476 $form->{callback} ||= build_std_url('action=add_price_factor');
1478 AM->get_price_factor(\%myconfig, $form);
1480 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
1483 print $form->parse_html_template('am/edit_price_factor');
1485 $main::lxdebug->leave_sub();
1488 sub list_price_factors {
1489 $main::lxdebug->enter_sub();
1491 my $form = $main::form;
1492 my %myconfig = %main::myconfig;
1493 my $locale = $main::locale;
1495 $main::auth->assert('config');
1497 AM->get_all_price_factors(\%myconfig, \%$form);
1499 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
1500 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
1503 $form->{callback} = build_std_url('action=list_price_factors');
1504 $form->{title} = $locale->text('Price Factors');
1505 $form->{url_base} = build_std_url('callback');
1508 print $form->parse_html_template('am/list_price_factors');
1510 $main::lxdebug->leave_sub();
1513 sub save_price_factor {
1514 $main::lxdebug->enter_sub();
1516 my $form = $main::form;
1517 my %myconfig = %main::myconfig;
1518 my $locale = $main::locale;
1520 $main::auth->assert('config');
1522 $form->isblank("description", $locale->text('Description missing!'));
1523 $form->isblank("factor", $locale->text('Factor missing!'));
1525 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
1527 AM->save_price_factor(\%myconfig, $form);
1529 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
1531 $form->redirect($locale->text('Price factor saved!'));
1533 $main::lxdebug->leave_sub();
1536 sub delete_price_factor {
1537 $main::lxdebug->enter_sub();
1539 my $form = $main::form;
1540 my %myconfig = %main::myconfig;
1541 my $locale = $main::locale;
1543 $main::auth->assert('config');
1545 AM->delete_price_factor(\%myconfig, \%$form);
1547 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
1549 $form->redirect($locale->text('Price factor deleted!'));
1551 $main::lxdebug->leave_sub();
1555 $main::lxdebug->enter_sub();
1557 my $form = $main::form;
1558 my $locale = $main::locale;
1560 $main::auth->assert('config');
1562 $form->{title} = $locale->text('Add Warehouse');
1563 $form->{callback} ||= build_std_url('action=add_warehouse');
1566 print $form->parse_html_template('am/edit_warehouse');
1568 $main::lxdebug->leave_sub();
1571 sub edit_warehouse {
1572 $main::lxdebug->enter_sub();
1574 my $form = $main::form;
1575 my %myconfig = %main::myconfig;
1576 my $locale = $main::locale;
1578 $main::auth->assert('config');
1580 AM->get_warehouse(\%myconfig, $form);
1582 $form->get_lists('employees' => 'EMPLOYEES');
1584 $form->{title} = $locale->text('Edit Warehouse');
1585 $form->{callback} ||= build_std_url('action=list_warehouses');
1588 print $form->parse_html_template('am/edit_warehouse');
1590 $main::lxdebug->leave_sub();
1593 sub list_warehouses {
1594 $main::lxdebug->enter_sub();
1596 my $form = $main::form;
1597 my %myconfig = %main::myconfig;
1598 my $locale = $main::locale;
1600 $main::auth->assert('config');
1602 AM->get_all_warehouses(\%myconfig, $form);
1604 $form->{callback} = build_std_url('action=list_warehouses');
1605 $form->{title} = $locale->text('Warehouses');
1606 $form->{url_base} = build_std_url('callback');
1609 print $form->parse_html_template('am/list_warehouses');
1611 $main::lxdebug->leave_sub();
1614 sub save_warehouse {
1615 $main::lxdebug->enter_sub();
1617 my $form = $main::form;
1618 my %myconfig = %main::myconfig;
1619 my $locale = $main::locale;
1621 $main::auth->assert('config');
1623 $form->isblank("description", $locale->text('Description missing!'));
1625 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
1627 AM->save_warehouse(\%myconfig, $form);
1629 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
1631 $form->redirect($locale->text('Warehouse saved.'));
1633 $main::lxdebug->leave_sub();
1636 sub delete_warehouse {
1637 $main::lxdebug->enter_sub();
1639 my $form = $main::form;
1640 my %myconfig = %main::myconfig;
1641 my $locale = $main::locale;
1643 $main::auth->assert('config');
1645 if (!$form->{confirmed}) {
1646 $form->{title} = $locale->text('Confirmation');
1649 print $form->parse_html_template('am/confirm_delete_warehouse');
1653 if (AM->delete_warehouse(\%myconfig, $form)) {
1654 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
1655 $form->redirect($locale->text('Warehouse deleted.'));
1658 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
1661 $main::lxdebug->leave_sub();
1665 $main::lxdebug->enter_sub();
1667 my $form = $main::form;
1668 my %myconfig = %main::myconfig;
1669 my $locale = $main::locale;
1671 $main::auth->assert('config');
1673 AM->save_bins(\%myconfig, $form);
1675 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
1677 $form->redirect($locale->text('Bins saved.'));
1679 $main::lxdebug->leave_sub();