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 => '',
147 startdate => $form->{account_exists} ? '' : DateTime->new(year => 1970, month => 1, day => 1)->to_lxoffice,
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!'));
398 my $found_valid_taxkey = 0;
399 foreach my $i (0 .. 10) { # 10 is maximum count of taxkeys in form
400 if ($form->{"taxkey_startdate_$i"} and !$form->{"taxkey_del_$i"}) {
401 $found_valid_taxkey = 1;
405 if ($found_valid_taxkey == 0) {
406 $form->error($locale->text('A valid taxkey is missing!'));
410 $form->redirect($locale->text('Account saved!'))
411 if (AM->save_account(\%myconfig, \%$form));
412 $form->error($locale->text('Cannot save account!'));
414 $main::lxdebug->leave_sub();
417 sub save_as_new_account {
418 $main::lxdebug->enter_sub();
420 my $form = $main::form;
421 my %myconfig = %main::myconfig;
422 my $locale = $main::locale;
424 $main::auth->assert('config');
426 $form->isblank("accno", $locale->text('Account Number missing!'));
427 $form->isblank("description", $locale->text('Account Description missing!'));
429 if ($form->{charttype} eq 'A'){
430 $form->isblank("category", $locale->text('Account Type missing!'));
433 for my $taxkey (0 .. 9) {
434 if ($form->{"taxkey_id_$taxkey"}) {
435 $form->{"taxkey_id_$taxkey"} = "NEW";
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();
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->{callback} = build_std_url('action=list_account');
457 my $link_edit_account = build_std_url('action=edit_account', 'callback');
459 CA->all_accounts(\%myconfig, \%$form);
461 foreach my $ca (@{ $form->{CA} }) {
466 if ($ca->{amount} > 0) {
467 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
469 if ($ca->{amount} < 0) {
470 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
472 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
473 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
476 $::request->{layout}->use_stylesheet("list_accounts.css");
477 $form->{title} = $locale->text('Chart of Accounts');
482 my $parameters_ref = {
483 # hidden_variables => $_hidden_variables_ref,
486 # Ausgabe des Templates
487 print($form->parse_html_template('am/list_accounts', $parameters_ref));
489 $main::lxdebug->leave_sub();
494 sub list_account_details {
495 # Ajax Funktion aus list_account_details
496 $main::lxdebug->enter_sub();
498 my $form = $main::form;
499 my %myconfig = %main::myconfig;
500 my $locale = $main::locale;
502 $main::auth->assert('config');
504 my $chart_id = $form->{args};
506 CA->all_accounts(\%myconfig, \%$form, $chart_id);
508 foreach my $ca (@{ $form->{CA} }) {
510 $ca->{debit} = " ";
511 $ca->{credit} = " ";
513 if ($ca->{amount} > 0) {
515 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
517 if ($ca->{amount} < 0) {
519 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
522 my @links = split( q{:}, $ca->{link});
526 foreach my $link (@links){
527 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
528 : ( $link eq 'AP') ? $locale->text('Account Link AP')
529 : ( $link eq 'IC') ? $locale->text('Account Link IC')
530 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
531 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
532 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
533 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
534 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
535 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
536 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
537 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
538 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
539 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
540 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
541 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
542 : $locale->text('Unknown Link') . ': ' . $link;
543 $ca->{link} .= ($link ne '') ? "[$link] ":'';
546 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
547 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
548 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
549 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
550 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
551 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
552 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
553 : $locale->text('Unknown Category') . ': ' . $ca->{category};
556 $form->{title} = $locale->text('Chart of Accounts');
558 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
560 $main::lxdebug->leave_sub();
565 $main::lxdebug->enter_sub();
567 my $form = $main::form;
568 my %myconfig = %main::myconfig;
569 my $locale = $main::locale;
571 $main::auth->assert('config');
573 $form->{title} = $locale->text('Delete Account');
576 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
578 if ($form->{id} == $form->{$id}) {
579 $form->error($locale->text('Cannot delete default account!'));
583 $form->redirect($locale->text('Account deleted!'))
584 if (AM->delete_account(\%myconfig, \%$form));
585 $form->error($locale->text('Cannot delete account!'));
587 $main::lxdebug->leave_sub();
591 $main::lxdebug->enter_sub();
593 my $form = $main::form;
595 $main::auth->assert('config');
597 $form->{title} = "Add";
599 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
604 $main::lxdebug->leave_sub();
608 $main::lxdebug->enter_sub();
610 my $form = $main::form;
611 my %myconfig = %main::myconfig;
613 $main::auth->assert('config');
615 $form->{title} = "Edit";
617 AM->get_lead(\%myconfig, \%$form);
621 $form->{orphaned} = 1;
624 $main::lxdebug->leave_sub();
628 $::lxdebug->enter_sub;
629 $::auth->assert('config');
631 AM->lead(\%::myconfig, $::form);
633 $::form->{callback} = "am.pl?action=list_lead";
634 $::form->{title} = $::locale->text('Lead');
637 print $::form->parse_html_template('am/lead_list');
639 $::lxdebug->leave_sub;
643 $::lxdebug->enter_sub;
644 $::auth->assert('config');
646 # $locale->text('Add Lead')
647 # $locale->text('Edit Lead')
648 $::form->{title} = $::locale->text("$::form->{title} Lead");
651 print $::form->parse_html_template('am/lead_header');
653 $::lxdebug->leave_sub;
657 $main::lxdebug->enter_sub();
659 my $form = $main::form;
660 my %myconfig = %main::myconfig;
661 my $locale = $main::locale;
663 $main::auth->assert('config');
665 $form->isblank("description", $locale->text('Description missing!'));
666 AM->save_lead(\%myconfig, \%$form);
667 $form->redirect($locale->text('lead saved!'));
669 $main::lxdebug->leave_sub();
673 $main::lxdebug->enter_sub();
675 my $form = $main::form;
676 my %myconfig = %main::myconfig;
677 my $locale = $main::locale;
679 $main::auth->assert('config');
681 AM->delete_lead(\%myconfig, \%$form);
682 $form->redirect($locale->text('lead deleted!'));
684 $main::lxdebug->leave_sub();
688 $main::lxdebug->enter_sub();
690 my $form = $main::form;
692 $main::auth->assert('config');
694 $form->{title} = "Add";
696 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
701 $main::lxdebug->leave_sub();
705 $main::lxdebug->enter_sub();
707 my $form = $main::form;
708 my %myconfig = %main::myconfig;
710 $main::auth->assert('config');
712 $form->{title} = "Edit";
714 AM->get_language(\%myconfig, \%$form);
718 $form->{orphaned} = 1;
721 $main::lxdebug->leave_sub();
725 $::lxdebug->enter_sub;
726 $::auth->assert('config');
728 AM->language(\%::myconfig, $::form);
730 $::form->{callback} = "am.pl?action=list_language";
731 $::form->{title} = $::locale->text('Languages');
735 print $::form->parse_html_template('am/language_list');
737 $::lxdebug->leave_sub;
740 sub language_header {
741 $::lxdebug->enter_sub;
742 $::auth->assert('config');
744 # $locale->text('Add Language')
745 # $locale->text('Edit Language')
746 $::form->{title} = $::locale->text("$::form->{title} Language");
750 print $::form->parse_html_template('am/language_header', {
751 numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00' ],
752 dateformats => [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
755 $::lxdebug->leave_sub;
759 $main::lxdebug->enter_sub();
761 my $form = $main::form;
762 my %myconfig = %main::myconfig;
763 my $locale = $main::locale;
765 $main::auth->assert('config');
767 $form->isblank("description", $locale->text('Language missing!'));
768 $form->isblank("template_code", $locale->text('Template Code missing!'));
769 $form->isblank("article_code", $locale->text('Article Code missing!'));
770 AM->save_language(\%myconfig, \%$form);
771 $form->redirect($locale->text('Language saved!'));
773 $main::lxdebug->leave_sub();
776 sub delete_language {
777 $main::lxdebug->enter_sub();
779 my $form = $main::form;
780 my %myconfig = %main::myconfig;
781 my $locale = $main::locale;
783 $main::auth->assert('config');
785 AM->delete_language(\%myconfig, \%$form);
786 $form->redirect($locale->text('Language deleted!'));
788 $main::lxdebug->leave_sub();
792 sub add_buchungsgruppe {
793 $main::lxdebug->enter_sub();
795 my $form = $main::form;
796 my %myconfig = %main::myconfig;
797 my $locale = $main::locale;
799 $main::auth->assert('config');
801 # $locale->text("Add Buchungsgruppe")
802 # $locale->text("Edit Buchungsgruppe")
803 $form->{title} = "Add";
805 $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
807 AM->get_buchungsgruppe(\%myconfig, \%$form);
808 $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
809 for (my $i = 0; 4 > $i; $i++) {
810 map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
814 &buchungsgruppe_header;
817 $main::lxdebug->leave_sub();
820 sub edit_buchungsgruppe {
821 $main::lxdebug->enter_sub();
823 my $form = $main::form;
824 my %myconfig = %main::myconfig;
826 $main::auth->assert('config');
828 $form->{title} = "Edit";
830 AM->get_buchungsgruppe(\%myconfig, \%$form);
832 &buchungsgruppe_header;
836 $main::lxdebug->leave_sub();
839 sub list_buchungsgruppe {
840 $::lxdebug->enter_sub;
841 $::auth->assert('config');
843 AM->buchungsgruppe(\%::myconfig, $::form);
845 $::form->{callback} = "am.pl?action=list_buchungsgruppe";
846 $::form->{title} = $::locale->text('Buchungsgruppen');
849 print $::form->parse_html_template('am/buchungsgruppe_list', {
850 swap_link => qq|am.pl?action=swap_buchungsgruppen&|,
853 $::lxdebug->leave_sub;
856 sub buchungsgruppe_header {
857 $::lxdebug->enter_sub;
858 $::auth->assert('config');
860 # $locale->text('Add Accounting Group')
861 # $locale->text('Edit Accounting Group')
862 $::form->{title} = $::locale->text("$::form->{title} Buchungsgruppe");
864 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
866 IC => $acc_inventory,
867 IC_income => $acc_income,
868 IC_sale => $acc_income,
869 IC_expense => $acc_expense,
870 IC_cogs => $acc_expense,
873 for my $key (keys %acc_type_map) {
874 for my $ref (@{ $::form->{IC_links}{$key} }) {
875 $acc_type_map{$key}{$ref->{id}} = $ref;
879 my %sorted_accounts = map {
880 $_ => [ sort { $a->{accno} cmp $b->{accno} } values %{ $acc_type_map{$_} } ],
881 } keys %acc_type_map;
884 print $::form->parse_html_template('am/buchungsgruppe_header', {
885 accounts => \%sorted_accounts,
886 account_label => sub { "$_[0]{accno}--$_[0]{description}" },
889 $::lxdebug->leave_sub;
892 sub save_buchungsgruppe {
893 $main::lxdebug->enter_sub();
895 my $form = $main::form;
896 my %myconfig = %main::myconfig;
897 my $locale = $main::locale;
899 $main::auth->assert('config');
901 $form->isblank("description", $locale->text('Description missing!'));
903 AM->save_buchungsgruppe(\%myconfig, \%$form);
904 $form->redirect($locale->text('Accounting Group saved!'));
906 $main::lxdebug->leave_sub();
909 sub delete_buchungsgruppe {
910 $main::lxdebug->enter_sub();
912 my $form = $main::form;
913 my %myconfig = %main::myconfig;
914 my $locale = $main::locale;
916 $main::auth->assert('config');
918 AM->delete_buchungsgruppe(\%myconfig, \%$form);
919 $form->redirect($locale->text('Accounting Group deleted!'));
921 $main::lxdebug->leave_sub();
924 sub swap_buchungsgruppen {
925 $main::lxdebug->enter_sub();
927 my $form = $main::form;
928 my %myconfig = %main::myconfig;
930 $main::auth->assert('config');
932 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
933 list_buchungsgruppe();
935 $main::lxdebug->leave_sub();
938 sub _build_cfg_options {
939 my $form = $main::form;
940 my %myconfig = %main::myconfig;
943 my $array = uc($idx) . 'S';
945 $form->{$array} = [];
946 foreach my $item (@_) {
947 push @{ $form->{$array} }, {
950 'selected' => $item eq $myconfig{$idx},
956 $main::lxdebug->enter_sub();
958 my $form = $main::form;
959 my %myconfig = %main::myconfig;
960 my $locale = $main::locale;
962 _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
963 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
966 if ($::lx_office_conf{print_templates}->{opendocument}
967 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
968 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
969 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
970 "value" => "opendocument_pdf" });
972 if ($::lx_office_conf{print_templates}->{latex}) {
973 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
975 push(@formats, { "name" => "HTML", "value" => "html" });
976 if ($::lx_office_conf{print_templates}->{latex}) {
977 push(@formats, { "name" => $locale->text("Postscript"),
978 "value" => "postscript" });
980 if ($::lx_office_conf{print_templates}->{opendocument}) {
981 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
982 "value" => "opendocument" });
985 if (!$myconfig{"template_format"}) {
986 $myconfig{"template_format"} = "pdf";
988 $form->{TEMPLATE_FORMATS} = [];
989 foreach my $item (@formats) {
990 push @{ $form->{TEMPLATE_FORMATS} }, {
991 'name' => $item->{name},
992 'value' => $item->{value},
993 'selected' => $item->{value} eq $myconfig{template_format},
997 if (!$myconfig{"default_media"}) {
998 $myconfig{"default_media"} = "screen";
1001 my %selected = ($myconfig{"default_media"} => "selected");
1003 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
1004 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
1005 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
1008 $form->{PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
1010 my %countrycodes = User->country_codes;
1012 $form->{COUNTRYCODES} = [];
1013 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
1014 push @{ $form->{COUNTRYCODES} }, {
1015 'name' => $countrycodes{$countrycode},
1016 'value' => $countrycode,
1017 'selected' => $countrycode eq $myconfig{countrycode},
1021 $form->{STYLESHEETS} = [];
1022 foreach my $item (qw(lx-office-erp.css Mobile.css kivitendo.css)) {
1023 push @{ $form->{STYLESHEETS} }, {
1026 'selected' => $item eq $myconfig{stylesheet},
1030 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
1031 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
1032 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
1034 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
1037 print $form->parse_html_template('am/config');
1039 $main::lxdebug->leave_sub();
1042 sub save_preferences {
1043 $main::lxdebug->enter_sub();
1045 my $form = $main::form;
1046 my %myconfig = %main::myconfig;
1047 my $locale = $main::locale;
1049 $form->{stylesheet} = $form->{usestylesheet};
1051 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
1053 if (AM->save_preferences($form)) {
1054 if ($::auth->can_change_password()
1055 && defined $form->{new_password}
1056 && ($form->{new_password} ne '********')) {
1057 my $verifier = SL::Auth::PasswordPolicy->new;
1058 my $result = $verifier->verify($form->{new_password});
1060 if ($result != SL::Auth::PasswordPolicy->OK()) {
1061 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
1064 $::auth->change_password($form->{login}, $form->{new_password});
1067 $form->redirect($locale->text('Preferences saved!'));
1070 $form->error($locale->text('Cannot save preferences!'));
1072 $main::lxdebug->leave_sub();
1076 $::lxdebug->enter_sub;
1077 $::auth->assert('config');
1079 $::form->{title} = $::locale->text('Audit Control');
1081 AM->closedto(\%::myconfig, $::form);
1084 print $::form->parse_html_template('am/audit_control');
1086 $::lxdebug->leave_sub;
1090 $main::lxdebug->enter_sub();
1092 my $form = $main::form;
1093 my %myconfig = %main::myconfig;
1094 my $locale = $main::locale;
1096 $main::auth->assert('config');
1098 AM->closebooks(\%myconfig, \%$form);
1100 if ($form->{closedto}) {
1102 $locale->text('Books closed up to') . " "
1103 . $locale->date(\%myconfig, $form->{closedto}, 1));
1105 $form->redirect($locale->text('Books are open'));
1108 $main::lxdebug->leave_sub();
1112 $main::lxdebug->enter_sub();
1114 my $form = $main::form;
1115 my %myconfig = %main::myconfig;
1116 my $locale = $main::locale;
1118 $main::auth->assert('config');
1120 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1121 AM->units_in_use(\%myconfig, $form, $units);
1122 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1124 my @languages = AM->language(\%myconfig, $form, 1);
1126 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1129 foreach (@unit_list) {
1130 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1131 $_->{"UNITLANGUAGES"} = [];
1132 foreach my $lang (@languages) {
1133 push(@{ $_->{"UNITLANGUAGES"} },
1135 "unit" => $_->{"name"},
1136 "language_id" => $lang->{"id"},
1137 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1138 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1144 $units = AM->retrieve_units(\%myconfig, $form);
1145 my $ddbox = AM->unit_select_data($units, undef, 1);
1147 $form->{"title"} = $locale->text("Add and edit units");
1149 print($form->parse_html_template("am/edit_units",
1150 { "UNITS" => \@unit_list,
1151 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1152 "LANGUAGES" => \@languages,
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 $form->isblank("new_name", $locale->text("The name is missing."));
1168 my $units = AM->retrieve_units(\%myconfig, $form);
1169 my $all_units = AM->retrieve_units(\%myconfig, $form);
1170 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1172 my ($base_unit, $factor);
1173 if ($form->{"new_base_unit"}) {
1174 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1176 $form->isblank("new_factor", $locale->text("The factor is missing."));
1177 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1178 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1179 $base_unit = $form->{"new_base_unit"};
1183 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1184 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1185 push(@languages, { "id" => $lang->{"id"},
1186 "localized" => $form->{"new_localized_$lang->{id}"},
1187 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1191 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1193 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1197 $main::lxdebug->leave_sub();
1200 sub set_unit_languages {
1201 $main::lxdebug->enter_sub();
1203 my $form = $main::form;
1205 $main::auth->assert('config');
1207 my ($unit, $languages, $idx) = @_;
1209 $unit->{"LANGUAGES"} = [];
1211 foreach my $lang (@{$languages}) {
1212 push(@{ $unit->{"LANGUAGES"} },
1213 { "id" => $lang->{"id"},
1214 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1215 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1219 $main::lxdebug->leave_sub();
1223 $main::lxdebug->enter_sub();
1225 my $form = $main::form;
1226 my %myconfig = %main::myconfig;
1227 my $locale = $main::locale;
1229 $main::auth->assert('config');
1231 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1232 AM->units_in_use(\%myconfig, $form, $old_units);
1234 my @languages = AM->language(\%myconfig, $form, 1);
1237 my @delete_units = ();
1238 foreach my $i (1..($form->{"rowcount"} * 1)) {
1239 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1241 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1244 if ($form->{"unchangeable_$i"}) {
1245 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1246 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1247 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1251 if ($old_unit->{"in_use"}) {
1252 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1255 if ($form->{"delete_$i"}) {
1256 push(@delete_units, $old_unit->{"name"});
1260 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1262 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1263 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1264 $new_units->{$form->{"name_$i"}} = \%h;
1265 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1266 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1269 foreach my $unit (values(%{$new_units})) {
1270 next unless ($unit->{"old_name"});
1271 if ($unit->{"base_unit"}) {
1272 $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"}))
1273 unless (defined($new_units->{$unit->{"base_unit"}}));
1274 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1275 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1277 $unit->{"base_unit"} = undef;
1278 $unit->{"factor"} = undef;
1282 foreach my $unit (values(%{$new_units})) {
1283 next if ($unit->{"unchanged_unit"});
1285 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1286 my $new_unit = $unit;
1287 while ($new_unit->{"base_unit"}) {
1288 $new_unit->{"seen"} = 1;
1289 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1290 if ($new_unit->{"seen"}) {
1291 $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, " .
1292 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1297 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1299 $form->{"saved_message"} = $locale->text("The units have been saved.");
1303 $main::lxdebug->leave_sub();
1306 sub show_history_search {
1307 $main::lxdebug->enter_sub();
1309 my $form = $main::form;
1310 my $locale = $main::locale;
1312 $main::auth->assert('config');
1314 $form->{title} = $locale->text("History Search");
1317 print $form->parse_html_template("common/search_history");
1319 $main::lxdebug->leave_sub();
1322 sub show_am_history {
1323 $main::lxdebug->enter_sub();
1325 my $form = $main::form;
1326 my %myconfig = %main::myconfig;
1327 my $locale = $main::locale;
1329 $main::auth->assert('config');
1331 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1332 $form->{order} ||= 'h.itime--1';
1334 my %search = ( "Artikelnummer" => "parts",
1335 "Kundennummer" => "customer",
1336 "Lieferantennummer" => "vendor",
1337 "Projektnummer" => "project",
1338 "Buchungsnummer" => "oe",
1339 "Eingangsrechnungnummer" => "ap",
1340 "Ausgangsrechnungnummer" => "ar",
1341 "Mahnungsnummer" => "dunning"
1343 my %searchNo = ( "Artikelnummer" => "partnumber",
1344 "Kundennummer" => "customernumber",
1345 "Lieferantennummer" => "vendornumber",
1346 "Projektnummer" => "projectnumber",
1347 "Buchungsnummer" => "ordnumber",
1348 "Eingangsrechnungnummer" => "invnumber",
1349 "Ausgangsrechnungnummer" => "invnumber",
1350 "Mahnungsnummer" => "dunning_id"
1353 my $dbh = $form->dbconnect(\%myconfig);
1356 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1357 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1358 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1359 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1360 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1361 } elsif ($form->{mitarbeiter}) {
1362 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1365 my $query = qq|SELECT trans_id AS id FROM history_erp | .
1366 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
1367 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
1369 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
1370 my $daten .= shift @ids;
1371 $daten .= join '', map { " OR trans_id = $_" } @ids;
1373 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1374 $sort =~ s/.*\.(.*)$/$1/;
1376 $form->{title} = $locale->text("History Search");
1379 print $form->parse_html_template("common/show_history",
1380 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1381 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1384 uc($sort) . "BY" => $sortby,
1385 'callback' => $callback,
1389 $main::lxdebug->leave_sub();
1393 $main::lxdebug->enter_sub();
1395 my $form = $main::form;
1396 my $locale = $main::locale;
1398 $main::auth->assert('config');
1400 $form->{title} = $locale->text('Add');
1402 $form->{callback} ||= "am.pl?action=add_tax";
1404 _get_taxaccount_selection();
1407 $form->{liability} = 1;
1408 $form->{equity} = 1;
1409 $form->{revenue} = 1;
1410 $form->{expense} = 1;
1415 my $parameters_ref = {
1416 # ChartTypeIsAccount => $ChartTypeIsAccount,
1419 # Ausgabe des Templates
1420 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1422 $main::lxdebug->leave_sub();
1426 $main::lxdebug->enter_sub();
1428 my $form = $main::form;
1429 my %myconfig = %main::myconfig;
1430 my $locale = $main::locale;
1432 $main::auth->assert('config');
1434 $form->{title} = $locale->text('Edit');
1436 AM->get_tax(\%myconfig, \%$form);
1438 _get_taxaccount_selection();
1440 $form->{asset} = $form->{chart_categories} =~ 'A' ? 1 : 0;
1441 $form->{liability} = $form->{chart_categories} =~ 'L' ? 1 : 0;
1442 $form->{equity} = $form->{chart_categories} =~ 'Q' ? 1 : 0;
1443 $form->{revenue} = $form->{chart_categories} =~ 'I' ? 1 : 0;
1444 $form->{expense} = $form->{chart_categories} =~ 'E' ? 1 : 0;
1445 $form->{costs} = $form->{chart_categories} =~ 'C' ? 1 : 0;
1447 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1451 my $parameters_ref = {
1454 # Ausgabe des Templates
1455 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1457 $main::lxdebug->leave_sub();
1461 $main::lxdebug->enter_sub();
1463 my $form = $main::form;
1464 my %myconfig = %main::myconfig;
1465 my $locale = $main::locale;
1467 $main::auth->assert('config');
1469 AM->taxes(\%myconfig, \%$form);
1471 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1473 $form->{callback} = build_std_url('action=list_tax');
1475 $form->{title} = $locale->text('Tax-O-Matic');
1479 my $parameters_ref = {
1482 # Ausgabe des Templates
1483 print($form->parse_html_template('am/list_tax', $parameters_ref));
1485 $main::lxdebug->leave_sub();
1488 sub _get_taxaccount_selection{
1489 $main::lxdebug->enter_sub();
1491 my $form = $main::form;
1492 my %myconfig = %main::myconfig;
1494 $main::auth->assert('config');
1496 AM->get_tax_accounts(\%myconfig, \%$form);
1498 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1500 $main::lxdebug->leave_sub();
1504 $main::lxdebug->enter_sub();
1506 my $form = $main::form;
1507 my %myconfig = %main::myconfig;
1508 my $locale = $main::locale;
1510 $main::auth->assert('config');
1512 $form->error($locale->text('Taxkey missing!')) unless length($form->{taxkey}) != 0;
1513 $form->error($locale->text('Taxdescription missing!')) unless length($form->{taxdescription}) != 0;
1514 $form->error($locale->text('Taxrate missing!')) unless length($form->{rate}) != 0;
1516 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1518 if ($form->{taxkey} == 0 and $form->{rate} > 0) {
1519 $form->error($locale->text('Taxkey 0 is reserved for rate 0'));
1522 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1523 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1526 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
1527 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1530 AM->save_tax(\%myconfig, \%$form);
1531 $form->redirect($locale->text('Tax saved!'));
1533 $main::lxdebug->leave_sub();
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_tax(\%myconfig, \%$form);
1546 $form->redirect($locale->text('Tax deleted!'));
1548 $main::lxdebug->leave_sub();
1551 sub add_price_factor {
1552 $main::lxdebug->enter_sub();
1554 my $form = $main::form;
1555 my $locale = $main::locale;
1557 $main::auth->assert('config');
1559 $form->{title} = $locale->text('Add Price Factor');
1560 $form->{callback} ||= build_std_url('action=add_price_factor');
1563 print $form->parse_html_template('am/edit_price_factor');
1565 $main::lxdebug->leave_sub();
1568 sub edit_price_factor {
1569 $main::lxdebug->enter_sub();
1571 my $form = $main::form;
1572 my %myconfig = %main::myconfig;
1573 my $locale = $main::locale;
1575 $main::auth->assert('config');
1577 $form->{title} = $locale->text('Edit Price Factor');
1578 $form->{callback} ||= build_std_url('action=add_price_factor');
1580 AM->get_price_factor(\%myconfig, $form);
1582 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
1585 print $form->parse_html_template('am/edit_price_factor');
1587 $main::lxdebug->leave_sub();
1590 sub list_price_factors {
1591 $main::lxdebug->enter_sub();
1593 my $form = $main::form;
1594 my %myconfig = %main::myconfig;
1595 my $locale = $main::locale;
1597 $main::auth->assert('config');
1599 AM->get_all_price_factors(\%myconfig, \%$form);
1601 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
1602 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
1605 $form->{callback} = build_std_url('action=list_price_factors');
1606 $form->{title} = $locale->text('Price Factors');
1607 $form->{url_base} = build_std_url('callback');
1610 print $form->parse_html_template('am/list_price_factors');
1612 $main::lxdebug->leave_sub();
1615 sub save_price_factor {
1616 $main::lxdebug->enter_sub();
1618 my $form = $main::form;
1619 my %myconfig = %main::myconfig;
1620 my $locale = $main::locale;
1622 $main::auth->assert('config');
1624 $form->isblank("description", $locale->text('Description missing!'));
1625 $form->isblank("factor", $locale->text('Factor missing!'));
1627 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
1629 AM->save_price_factor(\%myconfig, $form);
1631 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
1633 $form->redirect($locale->text('Price factor saved!'));
1635 $main::lxdebug->leave_sub();
1638 sub delete_price_factor {
1639 $main::lxdebug->enter_sub();
1641 my $form = $main::form;
1642 my %myconfig = %main::myconfig;
1643 my $locale = $main::locale;
1645 $main::auth->assert('config');
1647 AM->delete_price_factor(\%myconfig, \%$form);
1649 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
1651 $form->redirect($locale->text('Price factor deleted!'));
1653 $main::lxdebug->leave_sub();
1657 $main::lxdebug->enter_sub();
1659 my $form = $main::form;
1660 my $locale = $main::locale;
1662 $main::auth->assert('config');
1664 $form->{title} = $locale->text('Add Warehouse');
1665 $form->{callback} ||= build_std_url('action=add_warehouse');
1668 print $form->parse_html_template('am/edit_warehouse');
1670 $main::lxdebug->leave_sub();
1673 sub edit_warehouse {
1674 $main::lxdebug->enter_sub();
1676 my $form = $main::form;
1677 my %myconfig = %main::myconfig;
1678 my $locale = $main::locale;
1680 $main::auth->assert('config');
1682 AM->get_warehouse(\%myconfig, $form);
1684 $form->get_lists('employees' => 'EMPLOYEES');
1686 $form->{title} = $locale->text('Edit Warehouse');
1687 $form->{callback} ||= build_std_url('action=list_warehouses');
1690 print $form->parse_html_template('am/edit_warehouse');
1692 $main::lxdebug->leave_sub();
1695 sub list_warehouses {
1696 $main::lxdebug->enter_sub();
1698 my $form = $main::form;
1699 my %myconfig = %main::myconfig;
1700 my $locale = $main::locale;
1702 $main::auth->assert('config');
1704 AM->get_all_warehouses(\%myconfig, $form);
1706 $form->{callback} = build_std_url('action=list_warehouses');
1707 $form->{title} = $locale->text('Warehouses');
1708 $form->{url_base} = build_std_url('callback');
1711 print $form->parse_html_template('am/list_warehouses');
1713 $main::lxdebug->leave_sub();
1716 sub save_warehouse {
1717 $main::lxdebug->enter_sub();
1719 my $form = $main::form;
1720 my %myconfig = %main::myconfig;
1721 my $locale = $main::locale;
1723 $main::auth->assert('config');
1725 $form->isblank("description", $locale->text('Description missing!'));
1727 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
1729 AM->save_warehouse(\%myconfig, $form);
1731 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
1733 $form->redirect($locale->text('Warehouse saved.'));
1735 $main::lxdebug->leave_sub();
1738 sub delete_warehouse {
1739 $main::lxdebug->enter_sub();
1741 my $form = $main::form;
1742 my %myconfig = %main::myconfig;
1743 my $locale = $main::locale;
1745 $main::auth->assert('config');
1747 if (!$form->{confirmed}) {
1748 $form->{title} = $locale->text('Confirmation');
1751 print $form->parse_html_template('am/confirm_delete_warehouse');
1755 if (AM->delete_warehouse(\%myconfig, $form)) {
1756 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
1757 $form->redirect($locale->text('Warehouse deleted.'));
1760 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
1763 $main::lxdebug->leave_sub();
1767 $main::lxdebug->enter_sub();
1769 my $form = $main::form;
1770 my %myconfig = %main::myconfig;
1771 my $locale = $main::locale;
1773 $main::auth->assert('config');
1775 AM->save_bins(\%myconfig, $form);
1777 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
1779 $form->redirect($locale->text('Bins saved.'));
1781 $main::lxdebug->leave_sub();