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;
48 require "bin/mozilla/common.pl";
56 sub add { call_sub("add_$main::form->{type}"); }
57 sub delete { call_sub("delete_$main::form->{type}"); }
58 sub save { call_sub("save_$main::form->{type}"); }
59 sub edit { call_sub("edit_$main::form->{type}"); }
60 sub continue { call_sub($main::form->{"nextsub"}); }
61 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
64 $main::lxdebug->enter_sub();
66 my $form = $main::form;
67 my %myconfig = %main::myconfig;
69 $main::auth->assert('config');
71 $form->{title} = "Add";
72 $form->{charttype} = "A";
73 AM->get_account(\%myconfig, \%$form);
75 $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
80 $main::lxdebug->leave_sub();
84 $main::lxdebug->enter_sub();
86 my $form = $main::form;
87 my %myconfig = %main::myconfig;
89 $main::auth->assert('config');
91 $form->{title} = "Edit";
92 AM->get_account(\%myconfig, \%$form);
94 foreach my $item (split(/:/, $form->{link})) {
95 $form->{$item} = "checked";
101 $main::lxdebug->leave_sub();
105 $main::lxdebug->enter_sub();
107 my $form = $main::form;
108 my %myconfig = %main::myconfig;
109 my $locale = $main::locale;
111 $main::auth->assert('config');
113 if ( $form->{action} eq 'edit_account') {
114 $form->{account_exists} = '1';
117 $form->{title} = $locale->text("$form->{title} Account");
119 $form->{"$form->{charttype}_checked"} = "checked";
120 $form->{"$form->{category}_checked"} = "checked";
122 $form->{select_tax} = "";
124 my @tax_report_pos = USTVA->report_variables({
125 myconfig => \%myconfig,
128 attribute => 'position',
132 if (@{ $form->{TAXKEY} }) {
133 foreach my $item (@{ $form->{TAXKEY} }) {
134 $item->{rate} = $item->{rate} * 100 . '%';
137 # Fill in empty row for new Taxkey
138 my $newtaxkey_ref = {
143 taxdescription => '',
150 push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
153 foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
155 # Fill in a runningnumber
156 $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
158 # Fill in the Taxkeys as select options
159 foreach my $item (@{ $form->{TAXKEY} }) {
160 if ($item->{id} == $taxkey_used->{tax_id}) {
161 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
162 qq|<option value="$item->{id}" selected="selected">|
163 . sprintf("%.2d", $item->{taxkey})
164 . qq|. $item->{taxdescription} ($item->{rate}) |
165 . $locale->text('Tax-o-matic Account')
166 . qq|: $item->{chart_accno}\n|;
169 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
170 qq|<option value="$item->{id}">|
171 . sprintf("%.2d", $item->{taxkey})
172 . qq|. $item->{taxdescription} ($item->{rate}) |
173 . $locale->text('Tax-o-matic Account')
174 . qq|: $item->{chart_accno}\n|;
179 # Fill in the USTVA Numbers as select options
180 foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
182 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
184 elsif ( $item eq $taxkey_used->{pos_ustva} ) {
185 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
188 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
197 # Newaccount Folgekonto
198 if (@{ $form->{NEWACCOUNT} || [] }) {
199 if (!$form->{new_chart_valid}) {
200 $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
202 foreach my $item (@{ $form->{NEWACCOUNT} }) {
203 if ($item->{id} == $form->{new_chart_id}) {
204 $form->{selectnewaccount} .=
205 qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
206 } elsif (!$form->{new_chart_valid}) {
207 $form->{selectnewaccount} .=
208 qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
214 my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
217 2 => "sonstige Erlöse",
218 3 => "Privatanteile",
220 5 => "Ausserordentliche Erträge",
221 6 => "Vereinnahmte Umsatzst.",
222 7 => "Umsatzsteuererstattungen",
223 8 => "Wareneingänge",
224 9 => "Löhne und Gehälter",
225 10 => "Gesetzl. sozialer Aufw.",
227 12 => "Gas, Strom, Wasser",
228 13 => "Instandhaltung",
229 14 => "Steuern, Versich., Beiträge",
231 16 => "Kfz-Versicherungen",
232 17 => "Sonst. Fahrzeugkosten",
233 18 => "Werbe- und Reisekosten",
234 19 => "Instandhaltung u. Werkzeuge",
235 20 => "Fachzeitschriften, Bücher",
236 21 => "Miete für Einrichtungen",
237 22 => "Rechts- und Beratungskosten",
238 23 => "Bürobedarf, Porto, Telefon",
239 24 => "Sonstige Aufwendungen",
240 25 => "Abschreibungen auf Anlagever.",
241 26 => "Abschreibungen auf GWG",
243 28 => "Umsatzsteuerzahlungen",
245 30 => "Ausserordentlicher Aufwand",
246 31 => "Betriebliche Steuern");
247 foreach my $item (sort({ $a <=> $b } keys(%eur))) {
248 my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
249 if ($item == $form->{pos_eur}) {
250 $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
252 $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
257 my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
261 2 => 'Best.Verdg.FE/UE',
262 3 => 'Aktiv.Eigenleistung',
263 4 => 'Mat./Wareneinkauf',
264 5 => 'So.betr.Erlöse',
265 10 => 'Personalkosten',
267 12 => 'Betriebl.Steuern',
268 13 => 'Vers./Beiträge',
269 14 => 'Kfz.Kosten o.St.',
270 15 => 'Werbe-Reisek.',
271 16 => 'Kosten Warenabgabe',
272 17 => 'Abschreibungen',
273 18 => 'Rep./instandhlt.',
274 19 => 'Übrige Steuern',
275 20 => 'Sonst.Kosten',
277 31 => 'Sonst.neutr.Aufw.',
279 33 => 'Sonst.neutr.Ertrag',
280 34 => 'Verr.kalk.Kosten',
281 35 => 'Steuern Eink.u.Ertr.');
282 foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
283 my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
284 if ($item == $form->{pos_bwa}) {
285 $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
287 $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
292 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
293 my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
294 foreach my $item ((1, 2, 3, 4)) {
295 if ($item == $form->{pos_bilanz}) {
296 $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
298 $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
303 # this is for our parser only! Do not remove.
304 # type=submit $locale->text('Add Account')
305 # type=submit $locale->text('Edit Account')
307 $form->{type} = "account";
309 # preselections category
311 my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
314 'A' => $locale->text('Asset'),
315 'L' => $locale->text('Liability'),
316 'Q' => $locale->text('Equity'),
317 'I' => $locale->text('Revenue'),
318 'E' => $locale->text('Expense'),
319 'C' => $locale->text('Costs'),
321 foreach my $item ( sort({ $a <=> $b } keys %category) ) {
322 if ($item eq $form->{category}) {
323 $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
325 $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
330 # preselection chart type
331 my @all_charttypes = ({'name' => $locale->text('Account'), 'value' => 'A'},
332 {'name' => $locale->text('Heading'), 'value' => 'H'},
334 my $selected_charttype = $form->{charttype};
337 # account where AR_tax or AP_tax is set are not orphaned if they are used as
338 # tax-o-matic account
339 if ( $form->{id} && $form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
340 if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
341 $form->{orphaned} = 0;
345 my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
346 my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
350 my $parameters_ref = {
351 ChartTypeIsAccount => $ChartTypeIsAccount,
352 AccountIsPosted => $AccountIsPosted,
353 select_category => $select_category,
354 all_charttypes => \@all_charttypes,
355 selected_charttype => $selected_charttype,
356 select_bwa => $select_bwa,
357 select_bilanz => $select_bilanz,
358 select_eur => $select_eur,
361 # Ausgabe des Templates
362 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
365 $main::lxdebug->leave_sub();
369 $::lxdebug->enter_sub;
370 $::auth->assert('config');
372 print $::form->parse_html_template('am/form_footer', {
373 show_save => !$::form->{id}
374 || ($::form->{id} && $::form->{orphaned})
375 || ($::form->{type} eq "account" && !$::form->{new_chart_valid}),
376 show_delete => $::form->{id} && $::form->{orphaned},
377 show_save_as_new => $::form->{id} && $::form->{type} eq "account",
380 $::lxdebug->leave_sub;
384 $main::lxdebug->enter_sub();
386 my $form = $main::form;
387 my %myconfig = %main::myconfig;
388 my $locale = $main::locale;
390 $main::auth->assert('config');
392 $form->isblank("accno", $locale->text('Account Number missing!'));
393 $form->isblank("description", $locale->text('Account Description missing!'));
395 if ($form->{charttype} eq 'A'){
396 $form->isblank("category", $locale->text('Account Type missing!'));
399 $form->redirect($locale->text('Account saved!'))
400 if (AM->save_account(\%myconfig, \%$form));
401 $form->error($locale->text('Cannot save account!'));
403 $main::lxdebug->leave_sub();
406 sub save_as_new_account {
407 $main::lxdebug->enter_sub();
409 my $form = $main::form;
410 my %myconfig = %main::myconfig;
411 my $locale = $main::locale;
413 $main::auth->assert('config');
415 $form->isblank("accno", $locale->text('Account Number missing!'));
416 $form->isblank("description", $locale->text('Account Description missing!'));
418 if ($form->{charttype} eq 'A'){
419 $form->isblank("category", $locale->text('Account Type missing!'));
422 for my $taxkey (0 .. 9) {
423 if ($form->{"taxkey_id_$taxkey"}) {
424 $form->{"taxkey_id_$taxkey"} = "NEW";
429 $form->redirect($locale->text('Account saved!'))
430 if (AM->save_account(\%myconfig, \%$form));
431 $form->error($locale->text('Cannot save account!'));
433 $main::lxdebug->leave_sub();
437 $main::lxdebug->enter_sub();
439 my $form = $main::form;
440 my %myconfig = %main::myconfig;
441 my $locale = $main::locale;
443 $main::auth->assert('config');
445 $form->{callback} = build_std_url('action=list_account');
446 my $link_edit_account = build_std_url('action=edit_account', 'callback');
448 CA->all_accounts(\%myconfig, \%$form);
450 foreach my $ca (@{ $form->{CA} }) {
455 if ($ca->{amount} > 0) {
456 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
458 if ($ca->{amount} < 0) {
459 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
461 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
462 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
465 $::request->{layout}->use_stylesheet("list_accounts.css");
466 $form->{title} = $locale->text('Chart of Accounts');
471 my $parameters_ref = {
472 # hidden_variables => $_hidden_variables_ref,
475 # Ausgabe des Templates
476 print($form->parse_html_template('am/list_accounts', $parameters_ref));
478 $main::lxdebug->leave_sub();
483 sub list_account_details {
484 # Ajax Funktion aus list_account_details
485 $main::lxdebug->enter_sub();
487 my $form = $main::form;
488 my %myconfig = %main::myconfig;
489 my $locale = $main::locale;
491 $main::auth->assert('config');
493 my $chart_id = $form->{args};
495 CA->all_accounts(\%myconfig, \%$form, $chart_id);
497 foreach my $ca (@{ $form->{CA} }) {
499 $ca->{debit} = " ";
500 $ca->{credit} = " ";
502 if ($ca->{amount} > 0) {
504 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
506 if ($ca->{amount} < 0) {
508 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
511 my @links = split( q{:}, $ca->{link});
515 foreach my $link (@links){
516 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
517 : ( $link eq 'AP') ? $locale->text('Account Link AP')
518 : ( $link eq 'IC') ? $locale->text('Account Link IC')
519 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
520 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
521 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
522 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
523 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
524 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
525 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
526 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
527 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
528 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
529 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
530 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
531 : $locale->text('Unknown Link') . ': ' . $link;
532 $ca->{link} .= ($link ne '') ? "[$link] ":'';
535 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
536 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
537 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
538 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
539 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
540 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
541 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
542 : $locale->text('Unknown Category') . ': ' . $ca->{category};
545 $form->{title} = $locale->text('Chart of Accounts');
547 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
549 $main::lxdebug->leave_sub();
554 $main::lxdebug->enter_sub();
556 my $form = $main::form;
557 my %myconfig = %main::myconfig;
558 my $locale = $main::locale;
560 $main::auth->assert('config');
562 $form->{title} = $locale->text('Delete Account');
565 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
567 if ($form->{id} == $form->{$id}) {
568 $form->error($locale->text('Cannot delete default account!'));
572 $form->redirect($locale->text('Account deleted!'))
573 if (AM->delete_account(\%myconfig, \%$form));
574 $form->error($locale->text('Cannot delete account!'));
576 $main::lxdebug->leave_sub();
580 $main::lxdebug->enter_sub();
582 my $form = $main::form;
584 $main::auth->assert('config');
586 $form->{title} = "Add";
588 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
593 $main::lxdebug->leave_sub();
597 $main::lxdebug->enter_sub();
599 my $form = $main::form;
600 my %myconfig = %main::myconfig;
602 $main::auth->assert('config');
604 $form->{title} = "Edit";
606 AM->get_lead(\%myconfig, \%$form);
610 $form->{orphaned} = 1;
613 $main::lxdebug->leave_sub();
617 $::lxdebug->enter_sub;
618 $::auth->assert('config');
620 AM->lead(\%::myconfig, $::form);
622 $::form->{callback} = "am.pl?action=list_lead";
623 $::form->{title} = $::locale->text('Lead');
626 print $::form->parse_html_template('am/lead_list');
628 $::lxdebug->leave_sub;
632 $::lxdebug->enter_sub;
633 $::auth->assert('config');
635 # $locale->text('Add Lead')
636 # $locale->text('Edit Lead')
637 $::form->{title} = $::locale->text("$::form->{title} Lead");
640 print $::form->parse_html_template('am/lead_header');
642 $::lxdebug->leave_sub;
646 $main::lxdebug->enter_sub();
648 my $form = $main::form;
649 my %myconfig = %main::myconfig;
650 my $locale = $main::locale;
652 $main::auth->assert('config');
654 $form->isblank("description", $locale->text('Description missing!'));
655 AM->save_lead(\%myconfig, \%$form);
656 $form->redirect($locale->text('lead saved!'));
658 $main::lxdebug->leave_sub();
662 $main::lxdebug->enter_sub();
664 my $form = $main::form;
665 my %myconfig = %main::myconfig;
666 my $locale = $main::locale;
668 $main::auth->assert('config');
670 AM->delete_lead(\%myconfig, \%$form);
671 $form->redirect($locale->text('lead deleted!'));
673 $main::lxdebug->leave_sub();
677 $main::lxdebug->enter_sub();
679 my $form = $main::form;
681 $main::auth->assert('config');
683 $form->{title} = "Add";
685 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
690 $main::lxdebug->leave_sub();
694 $main::lxdebug->enter_sub();
696 my $form = $main::form;
697 my %myconfig = %main::myconfig;
699 $main::auth->assert('config');
701 $form->{title} = "Edit";
703 AM->get_language(\%myconfig, \%$form);
707 $form->{orphaned} = 1;
710 $main::lxdebug->leave_sub();
714 $::lxdebug->enter_sub;
715 $::auth->assert('config');
717 AM->language(\%::myconfig, $::form);
719 $::form->{callback} = "am.pl?action=list_language";
720 $::form->{title} = $::locale->text('Languages');
724 print $::form->parse_html_template('am/language_list');
726 $::lxdebug->leave_sub;
729 sub language_header {
730 $::lxdebug->enter_sub;
731 $::auth->assert('config');
733 # $locale->text('Add Language')
734 # $locale->text('Edit Language')
735 $::form->{title} = $::locale->text("$::form->{title} Language");
739 print $::form->parse_html_template('am/language_header', {
740 numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00' ],
741 dateformats => [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
744 $::lxdebug->leave_sub;
748 $main::lxdebug->enter_sub();
750 my $form = $main::form;
751 my %myconfig = %main::myconfig;
752 my $locale = $main::locale;
754 $main::auth->assert('config');
756 $form->isblank("description", $locale->text('Language missing!'));
757 $form->isblank("template_code", $locale->text('Template Code missing!'));
758 $form->isblank("article_code", $locale->text('Article Code missing!'));
759 AM->save_language(\%myconfig, \%$form);
760 $form->redirect($locale->text('Language saved!'));
762 $main::lxdebug->leave_sub();
765 sub delete_language {
766 $main::lxdebug->enter_sub();
768 my $form = $main::form;
769 my %myconfig = %main::myconfig;
770 my $locale = $main::locale;
772 $main::auth->assert('config');
774 AM->delete_language(\%myconfig, \%$form);
775 $form->redirect($locale->text('Language deleted!'));
777 $main::lxdebug->leave_sub();
781 sub add_buchungsgruppe {
782 $main::lxdebug->enter_sub();
784 my $form = $main::form;
785 my %myconfig = %main::myconfig;
786 my $locale = $main::locale;
788 $main::auth->assert('config');
790 # $locale->text("Add Buchungsgruppe")
791 # $locale->text("Edit Buchungsgruppe")
792 $form->{title} = "Add";
794 $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
796 AM->get_buchungsgruppe(\%myconfig, \%$form);
797 $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
798 for (my $i = 0; 4 > $i; $i++) {
799 map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
803 &buchungsgruppe_header;
806 $main::lxdebug->leave_sub();
809 sub edit_buchungsgruppe {
810 $main::lxdebug->enter_sub();
812 my $form = $main::form;
813 my %myconfig = %main::myconfig;
815 $main::auth->assert('config');
817 $form->{title} = "Edit";
819 AM->get_buchungsgruppe(\%myconfig, \%$form);
821 &buchungsgruppe_header;
825 $main::lxdebug->leave_sub();
828 sub list_buchungsgruppe {
829 $::lxdebug->enter_sub;
830 $::auth->assert('config');
832 AM->buchungsgruppe(\%::myconfig, $::form);
834 $::form->{callback} = "am.pl?action=list_buchungsgruppe";
835 $::form->{title} = $::locale->text('Buchungsgruppen');
838 print $::form->parse_html_template('am/buchungsgruppe_list', {
839 swap_link => qq|am.pl?action=swap_buchungsgruppen&|,
842 $::lxdebug->leave_sub;
845 sub buchungsgruppe_header {
846 $::lxdebug->enter_sub;
847 $::auth->assert('config');
849 # $locale->text('Add Accounting Group')
850 # $locale->text('Edit Accounting Group')
851 $::form->{title} = $::locale->text("$::form->{title} Buchungsgruppe");
853 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
855 IC => $acc_inventory,
856 IC_income => $acc_income,
857 IC_sale => $acc_income,
858 IC_expense => $acc_expense,
859 IC_cogs => $acc_expense,
862 for my $key (keys %acc_type_map) {
863 for my $ref (@{ $::form->{IC_links}{$key} }) {
864 $acc_type_map{$key}{$ref->{id}} = $ref;
868 my %sorted_accounts = map {
869 $_ => [ sort { $a->{accno} cmp $b->{accno} } values %{ $acc_type_map{$_} } ],
870 } keys %acc_type_map;
873 print $::form->parse_html_template('am/buchungsgruppe_header', {
874 accounts => \%sorted_accounts,
875 account_label => sub { "$_[0]{accno}--$_[0]{description}" },
878 $::lxdebug->leave_sub;
881 sub save_buchungsgruppe {
882 $main::lxdebug->enter_sub();
884 my $form = $main::form;
885 my %myconfig = %main::myconfig;
886 my $locale = $main::locale;
888 $main::auth->assert('config');
890 $form->isblank("description", $locale->text('Description missing!'));
892 AM->save_buchungsgruppe(\%myconfig, \%$form);
893 $form->redirect($locale->text('Accounting Group saved!'));
895 $main::lxdebug->leave_sub();
898 sub delete_buchungsgruppe {
899 $main::lxdebug->enter_sub();
901 my $form = $main::form;
902 my %myconfig = %main::myconfig;
903 my $locale = $main::locale;
905 $main::auth->assert('config');
907 AM->delete_buchungsgruppe(\%myconfig, \%$form);
908 $form->redirect($locale->text('Accounting Group deleted!'));
910 $main::lxdebug->leave_sub();
913 sub swap_buchungsgruppen {
914 $main::lxdebug->enter_sub();
916 my $form = $main::form;
917 my %myconfig = %main::myconfig;
919 $main::auth->assert('config');
921 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
922 list_buchungsgruppe();
924 $main::lxdebug->leave_sub();
928 $main::lxdebug->enter_sub();
930 my $form = $main::form;
931 my %myconfig = %main::myconfig;
932 my $locale = $main::locale;
934 # get defaults for account numbers and last numbers
935 AM->defaultaccounts(\%myconfig, \%$form);
936 $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
938 map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
941 my $all_languages = SL::DB::Manager::Language->get_all;
943 # cash = IST-Versteuerung, accrual = SOLL-Versteuerung
945 foreach my $key (keys %{ $form->{IC} }) {
946 foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
947 my $array = "ACCNOS_" . uc($key);
948 $form->{$array} ||= [];
950 my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
951 push @{ $form->{$array} }, {
954 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
959 $form->{title} = $locale->text('Ranges of numbers and default accounts');
962 print $form->parse_html_template('am/edit_defaults',
963 { ALL_LANGUAGES => $all_languages, });
965 $main::lxdebug->leave_sub();
969 $main::lxdebug->enter_sub();
971 my $form = $main::form;
972 my $locale = $main::locale;
976 $form->redirect($locale->text('Defaults saved.'));
978 $main::lxdebug->leave_sub();
981 sub _build_cfg_options {
982 my $form = $main::form;
983 my %myconfig = %main::myconfig;
986 my $array = uc($idx) . 'S';
988 $form->{$array} = [];
989 foreach my $item (@_) {
990 push @{ $form->{$array} }, {
993 'selected' => $item eq $myconfig{$idx},
999 $main::lxdebug->enter_sub();
1001 my $form = $main::form;
1002 my %myconfig = %main::myconfig;
1003 my $locale = $main::locale;
1005 _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
1006 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
1009 if ($::lx_office_conf{print_templates}->{opendocument}
1010 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
1011 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
1012 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
1013 "value" => "opendocument_pdf" });
1015 if ($::lx_office_conf{print_templates}->{latex}) {
1016 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
1018 push(@formats, { "name" => "HTML", "value" => "html" });
1019 if ($::lx_office_conf{print_templates}->{latex}) {
1020 push(@formats, { "name" => $locale->text("Postscript"),
1021 "value" => "postscript" });
1023 if ($::lx_office_conf{print_templates}->{opendocument}) {
1024 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
1025 "value" => "opendocument" });
1028 if (!$myconfig{"template_format"}) {
1029 $myconfig{"template_format"} = "pdf";
1031 $form->{TEMPLATE_FORMATS} = [];
1032 foreach my $item (@formats) {
1033 push @{ $form->{TEMPLATE_FORMATS} }, {
1034 'name' => $item->{name},
1035 'value' => $item->{value},
1036 'selected' => $item->{value} eq $myconfig{template_format},
1040 if (!$myconfig{"default_media"}) {
1041 $myconfig{"default_media"} = "screen";
1044 my %selected = ($myconfig{"default_media"} => "selected");
1046 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
1047 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
1048 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
1051 $form->{PRINTERS} = [ SL::Printer->all_printers(%::myconfig) ];
1053 my %countrycodes = User->country_codes;
1055 $form->{COUNTRYCODES} = [];
1056 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
1057 push @{ $form->{COUNTRYCODES} }, {
1058 'name' => $countrycodes{$countrycode},
1059 'value' => $countrycode,
1060 'selected' => $countrycode eq $myconfig{countrycode},
1064 $form->{STYLESHEETS} = [];
1065 foreach my $item (qw(lx-office-erp.css Mobile.css kivitendo.css)) {
1066 push @{ $form->{STYLESHEETS} }, {
1069 'selected' => $item eq $myconfig{stylesheet},
1073 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
1074 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
1075 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
1077 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
1080 print $form->parse_html_template('am/config');
1082 $main::lxdebug->leave_sub();
1085 sub save_preferences {
1086 $main::lxdebug->enter_sub();
1088 my $form = $main::form;
1089 my %myconfig = %main::myconfig;
1090 my $locale = $main::locale;
1092 $form->{stylesheet} = $form->{usestylesheet};
1094 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
1096 if (AM->save_preferences(\%myconfig, $form)) {
1097 if ($::auth->can_change_password()
1098 && defined $form->{new_password}
1099 && ($form->{new_password} ne '********')) {
1100 my $verifier = SL::Auth::PasswordPolicy->new;
1101 my $result = $verifier->verify($form->{new_password});
1103 if ($result != SL::Auth::PasswordPolicy->OK()) {
1104 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
1107 $::auth->change_password($form->{login}, $form->{new_password});
1109 $form->{password} = $form->{new_password};
1110 $::auth->set_session_value('password', $form->{password});
1111 $::auth->create_or_refresh_session();
1114 $form->redirect($locale->text('Preferences saved!'));
1117 $form->error($locale->text('Cannot save preferences!'));
1119 $main::lxdebug->leave_sub();
1123 $::lxdebug->enter_sub;
1124 $::auth->assert('config');
1126 $::form->{title} = $::locale->text('Audit Control');
1128 AM->closedto(\%::myconfig, $::form);
1131 print $::form->parse_html_template('am/audit_control');
1133 $::lxdebug->leave_sub;
1137 $main::lxdebug->enter_sub();
1139 my $form = $main::form;
1140 my %myconfig = %main::myconfig;
1141 my $locale = $main::locale;
1143 $main::auth->assert('config');
1145 AM->closebooks(\%myconfig, \%$form);
1147 if ($form->{closedto}) {
1149 $locale->text('Books closed up to') . " "
1150 . $locale->date(\%myconfig, $form->{closedto}, 1));
1152 $form->redirect($locale->text('Books are open'));
1155 $main::lxdebug->leave_sub();
1159 $main::lxdebug->enter_sub();
1161 my $form = $main::form;
1162 my %myconfig = %main::myconfig;
1163 my $locale = $main::locale;
1165 $main::auth->assert('config');
1167 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1168 AM->units_in_use(\%myconfig, $form, $units);
1169 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1171 my @languages = AM->language(\%myconfig, $form, 1);
1173 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1176 foreach (@unit_list) {
1177 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1178 $_->{"UNITLANGUAGES"} = [];
1179 foreach my $lang (@languages) {
1180 push(@{ $_->{"UNITLANGUAGES"} },
1182 "unit" => $_->{"name"},
1183 "language_id" => $lang->{"id"},
1184 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1185 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1191 $units = AM->retrieve_units(\%myconfig, $form);
1192 my $ddbox = AM->unit_select_data($units, undef, 1);
1194 $form->{"title"} = $locale->text("Add and edit units");
1196 print($form->parse_html_template("am/edit_units",
1197 { "UNITS" => \@unit_list,
1198 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1199 "LANGUAGES" => \@languages,
1202 $main::lxdebug->leave_sub();
1206 $main::lxdebug->enter_sub();
1208 my $form = $main::form;
1209 my %myconfig = %main::myconfig;
1210 my $locale = $main::locale;
1212 $main::auth->assert('config');
1214 $form->isblank("new_name", $locale->text("The name is missing."));
1215 my $units = AM->retrieve_units(\%myconfig, $form);
1216 my $all_units = AM->retrieve_units(\%myconfig, $form);
1217 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1219 my ($base_unit, $factor);
1220 if ($form->{"new_base_unit"}) {
1221 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1223 $form->isblank("new_factor", $locale->text("The factor is missing."));
1224 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1225 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1226 $base_unit = $form->{"new_base_unit"};
1230 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1231 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1232 push(@languages, { "id" => $lang->{"id"},
1233 "localized" => $form->{"new_localized_$lang->{id}"},
1234 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1238 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1240 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1244 $main::lxdebug->leave_sub();
1247 sub set_unit_languages {
1248 $main::lxdebug->enter_sub();
1250 my $form = $main::form;
1252 $main::auth->assert('config');
1254 my ($unit, $languages, $idx) = @_;
1256 $unit->{"LANGUAGES"} = [];
1258 foreach my $lang (@{$languages}) {
1259 push(@{ $unit->{"LANGUAGES"} },
1260 { "id" => $lang->{"id"},
1261 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1262 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1266 $main::lxdebug->leave_sub();
1270 $main::lxdebug->enter_sub();
1272 my $form = $main::form;
1273 my %myconfig = %main::myconfig;
1274 my $locale = $main::locale;
1276 $main::auth->assert('config');
1278 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1279 AM->units_in_use(\%myconfig, $form, $old_units);
1281 my @languages = AM->language(\%myconfig, $form, 1);
1284 my @delete_units = ();
1285 foreach my $i (1..($form->{"rowcount"} * 1)) {
1286 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1288 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1291 if ($form->{"unchangeable_$i"}) {
1292 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1293 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1294 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1298 if ($old_unit->{"in_use"}) {
1299 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1302 if ($form->{"delete_$i"}) {
1303 push(@delete_units, $old_unit->{"name"});
1307 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1309 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1310 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1311 $new_units->{$form->{"name_$i"}} = \%h;
1312 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1313 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1316 foreach my $unit (values(%{$new_units})) {
1317 next unless ($unit->{"old_name"});
1318 if ($unit->{"base_unit"}) {
1319 $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"}))
1320 unless (defined($new_units->{$unit->{"base_unit"}}));
1321 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1322 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1324 $unit->{"base_unit"} = undef;
1325 $unit->{"factor"} = undef;
1329 foreach my $unit (values(%{$new_units})) {
1330 next if ($unit->{"unchanged_unit"});
1332 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1333 my $new_unit = $unit;
1334 while ($new_unit->{"base_unit"}) {
1335 $new_unit->{"seen"} = 1;
1336 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1337 if ($new_unit->{"seen"}) {
1338 $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, " .
1339 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1344 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1346 $form->{"saved_message"} = $locale->text("The units have been saved.");
1350 $main::lxdebug->leave_sub();
1353 sub show_history_search {
1354 $main::lxdebug->enter_sub();
1356 my $form = $main::form;
1357 my $locale = $main::locale;
1359 $main::auth->assert('config');
1361 $form->{title} = $locale->text("History Search");
1364 print $form->parse_html_template("common/search_history");
1366 $main::lxdebug->leave_sub();
1369 sub show_am_history {
1370 $main::lxdebug->enter_sub();
1372 my $form = $main::form;
1373 my %myconfig = %main::myconfig;
1374 my $locale = $main::locale;
1376 $main::auth->assert('config');
1378 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1379 $form->{order} ||= 'h.itime--1';
1381 my %search = ( "Artikelnummer" => "parts",
1382 "Kundennummer" => "customer",
1383 "Lieferantennummer" => "vendor",
1384 "Projektnummer" => "project",
1385 "Buchungsnummer" => "oe",
1386 "Eingangsrechnungnummer" => "ap",
1387 "Ausgangsrechnungnummer" => "ar",
1388 "Mahnungsnummer" => "dunning"
1390 my %searchNo = ( "Artikelnummer" => "partnumber",
1391 "Kundennummer" => "customernumber",
1392 "Lieferantennummer" => "vendornumber",
1393 "Projektnummer" => "projectnumber",
1394 "Buchungsnummer" => "ordnumber",
1395 "Eingangsrechnungnummer" => "invnumber",
1396 "Ausgangsrechnungnummer" => "invnumber",
1397 "Mahnungsnummer" => "dunning_id"
1400 my $dbh = $form->dbconnect(\%myconfig);
1403 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1404 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1405 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1406 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1407 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1408 } elsif ($form->{mitarbeiter}) {
1409 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1412 my $query = qq|SELECT trans_id AS id FROM history_erp | .
1413 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
1414 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
1416 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
1417 my $daten .= shift @ids;
1418 $daten .= join '', map { " OR trans_id = $_" } @ids;
1420 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1421 $sort =~ s/.*\.(.*)$/$1/;
1423 $form->{title} = $locale->text("History Search");
1426 print $form->parse_html_template("common/show_history",
1427 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1428 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1431 uc($sort) . "BY" => $sortby,
1432 'callback' => $callback,
1436 $main::lxdebug->leave_sub();
1440 $main::lxdebug->enter_sub();
1442 my $form = $main::form;
1443 my $locale = $main::locale;
1445 $main::auth->assert('config');
1447 $form->{title} = $locale->text('Add');
1449 $form->{callback} ||= "am.pl?action=add_tax";
1451 _get_taxaccount_selection();
1455 my $parameters_ref = {
1456 # ChartTypeIsAccount => $ChartTypeIsAccount,
1459 # Ausgabe des Templates
1460 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1462 $main::lxdebug->leave_sub();
1466 $main::lxdebug->enter_sub();
1468 my $form = $main::form;
1469 my %myconfig = %main::myconfig;
1470 my $locale = $main::locale;
1472 $main::auth->assert('config');
1474 $form->{title} = $locale->text('Edit');
1476 AM->get_tax(\%myconfig, \%$form);
1477 _get_taxaccount_selection();
1479 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1483 my $parameters_ref = {
1486 # Ausgabe des Templates
1487 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1489 $main::lxdebug->leave_sub();
1493 $main::lxdebug->enter_sub();
1495 my $form = $main::form;
1496 my %myconfig = %main::myconfig;
1497 my $locale = $main::locale;
1499 $main::auth->assert('config');
1501 AM->taxes(\%myconfig, \%$form);
1503 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1505 $form->{callback} = build_std_url('action=list_tax');
1507 $form->{title} = $locale->text('Tax-O-Matic');
1511 my $parameters_ref = {
1514 # Ausgabe des Templates
1515 print($form->parse_html_template('am/list_tax', $parameters_ref));
1517 $main::lxdebug->leave_sub();
1520 sub _get_taxaccount_selection{
1521 $main::lxdebug->enter_sub();
1523 my $form = $main::form;
1524 my %myconfig = %main::myconfig;
1526 $main::auth->assert('config');
1528 AM->get_tax_accounts(\%myconfig, \%$form);
1530 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1532 $main::lxdebug->leave_sub();
1536 $main::lxdebug->enter_sub();
1538 my $form = $main::form;
1539 my %myconfig = %main::myconfig;
1540 my $locale = $main::locale;
1542 $main::auth->assert('config');
1544 $form->isblank("rate", $locale->text('Taxrate missing!'));
1545 $form->isblank("taxdescription", $locale->text('Taxdescription missing!'));
1546 $form->isblank("taxkey", $locale->text('Taxkey missing!'));
1548 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1550 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1551 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1554 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
1555 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1558 AM->save_tax(\%myconfig, \%$form);
1559 $form->redirect($locale->text('Tax saved!'));
1561 $main::lxdebug->leave_sub();
1565 $main::lxdebug->enter_sub();
1567 my $form = $main::form;
1568 my %myconfig = %main::myconfig;
1569 my $locale = $main::locale;
1571 $main::auth->assert('config');
1573 AM->delete_tax(\%myconfig, \%$form);
1574 $form->redirect($locale->text('Tax deleted!'));
1576 $main::lxdebug->leave_sub();
1579 sub add_price_factor {
1580 $main::lxdebug->enter_sub();
1582 my $form = $main::form;
1583 my $locale = $main::locale;
1585 $main::auth->assert('config');
1587 $form->{title} = $locale->text('Add Price Factor');
1588 $form->{callback} ||= build_std_url('action=add_price_factor');
1589 $::request->{layout}->focus('#description');
1592 print $form->parse_html_template('am/edit_price_factor');
1594 $main::lxdebug->leave_sub();
1597 sub edit_price_factor {
1598 $main::lxdebug->enter_sub();
1600 my $form = $main::form;
1601 my %myconfig = %main::myconfig;
1602 my $locale = $main::locale;
1604 $main::auth->assert('config');
1606 $form->{title} = $locale->text('Edit Price Factor');
1607 $form->{callback} ||= build_std_url('action=add_price_factor');
1608 $::request->{layout}->focus('#description');
1610 AM->get_price_factor(\%myconfig, $form);
1612 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
1615 print $form->parse_html_template('am/edit_price_factor');
1617 $main::lxdebug->leave_sub();
1620 sub list_price_factors {
1621 $main::lxdebug->enter_sub();
1623 my $form = $main::form;
1624 my %myconfig = %main::myconfig;
1625 my $locale = $main::locale;
1627 $main::auth->assert('config');
1629 AM->get_all_price_factors(\%myconfig, \%$form);
1631 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
1632 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
1635 $form->{callback} = build_std_url('action=list_price_factors');
1636 $form->{title} = $locale->text('Price Factors');
1637 $form->{url_base} = build_std_url('callback');
1640 print $form->parse_html_template('am/list_price_factors');
1642 $main::lxdebug->leave_sub();
1645 sub save_price_factor {
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 $form->isblank("description", $locale->text('Description missing!'));
1655 $form->isblank("factor", $locale->text('Factor missing!'));
1657 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
1659 AM->save_price_factor(\%myconfig, $form);
1661 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
1663 $form->redirect($locale->text('Price factor saved!'));
1665 $main::lxdebug->leave_sub();
1668 sub delete_price_factor {
1669 $main::lxdebug->enter_sub();
1671 my $form = $main::form;
1672 my %myconfig = %main::myconfig;
1673 my $locale = $main::locale;
1675 $main::auth->assert('config');
1677 AM->delete_price_factor(\%myconfig, \%$form);
1679 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
1681 $form->redirect($locale->text('Price factor deleted!'));
1683 $main::lxdebug->leave_sub();
1687 $main::lxdebug->enter_sub();
1689 my $form = $main::form;
1690 my $locale = $main::locale;
1692 $main::auth->assert('config');
1694 $form->{title} = $locale->text('Add Warehouse');
1695 $form->{callback} ||= build_std_url('action=add_warehouse');
1696 $::request->{layout}->focus('#description');
1699 print $form->parse_html_template('am/edit_warehouse');
1701 $main::lxdebug->leave_sub();
1704 sub edit_warehouse {
1705 $main::lxdebug->enter_sub();
1707 my $form = $main::form;
1708 my %myconfig = %main::myconfig;
1709 my $locale = $main::locale;
1711 $main::auth->assert('config');
1713 AM->get_warehouse(\%myconfig, $form);
1715 $form->get_lists('employees' => 'EMPLOYEES');
1717 $form->{title} = $locale->text('Edit Warehouse');
1718 $form->{callback} ||= build_std_url('action=list_warehouses');
1719 $::request->{layout}->focus('#description');
1722 print $form->parse_html_template('am/edit_warehouse');
1724 $main::lxdebug->leave_sub();
1727 sub list_warehouses {
1728 $main::lxdebug->enter_sub();
1730 my $form = $main::form;
1731 my %myconfig = %main::myconfig;
1732 my $locale = $main::locale;
1734 $main::auth->assert('config');
1736 AM->get_all_warehouses(\%myconfig, $form);
1738 $form->{callback} = build_std_url('action=list_warehouses');
1739 $form->{title} = $locale->text('Warehouses');
1740 $form->{url_base} = build_std_url('callback');
1743 print $form->parse_html_template('am/list_warehouses');
1745 $main::lxdebug->leave_sub();
1748 sub save_warehouse {
1749 $main::lxdebug->enter_sub();
1751 my $form = $main::form;
1752 my %myconfig = %main::myconfig;
1753 my $locale = $main::locale;
1755 $main::auth->assert('config');
1757 $form->isblank("description", $locale->text('Description missing!'));
1759 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
1761 AM->save_warehouse(\%myconfig, $form);
1763 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
1765 $form->redirect($locale->text('Warehouse saved.'));
1767 $main::lxdebug->leave_sub();
1770 sub delete_warehouse {
1771 $main::lxdebug->enter_sub();
1773 my $form = $main::form;
1774 my %myconfig = %main::myconfig;
1775 my $locale = $main::locale;
1777 $main::auth->assert('config');
1779 if (!$form->{confirmed}) {
1780 $form->{title} = $locale->text('Confirmation');
1783 print $form->parse_html_template('am/confirm_delete_warehouse');
1787 if (AM->delete_warehouse(\%myconfig, $form)) {
1788 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
1789 $form->redirect($locale->text('Warehouse deleted.'));
1792 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
1795 $main::lxdebug->leave_sub();
1799 $main::lxdebug->enter_sub();
1801 my $form = $main::form;
1802 my %myconfig = %main::myconfig;
1803 my $locale = $main::locale;
1805 $main::auth->assert('config');
1807 AM->save_bins(\%myconfig, $form);
1809 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
1811 $form->redirect($locale->text('Bins saved.'));
1813 $main::lxdebug->leave_sub();