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 if ($form->{"original_accno"} &&
430 ($form->{"accno"} eq $form->{"original_accno"})) {
431 $form->error($locale->text('Account Number already used!'));
433 $form->redirect($locale->text('Account saved!'))
434 if (AM->save_account(\%myconfig, \%$form));
435 $form->error($locale->text('Cannot save account!'));
437 $main::lxdebug->leave_sub();
441 $main::lxdebug->enter_sub();
443 my $form = $main::form;
444 my %myconfig = %main::myconfig;
445 my $locale = $main::locale;
447 $main::auth->assert('config');
449 $form->{callback} = build_std_url('action=list_account');
450 my $link_edit_account = build_std_url('action=edit_account', 'callback');
452 CA->all_accounts(\%myconfig, \%$form);
454 foreach my $ca (@{ $form->{CA} }) {
459 if ($ca->{amount} > 0) {
460 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
462 if ($ca->{amount} < 0) {
463 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
465 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
466 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
469 $::request->{layout}->use_stylesheet("list_accounts.css");
470 $form->{title} = $locale->text('Chart of Accounts');
475 my $parameters_ref = {
476 # hidden_variables => $_hidden_variables_ref,
479 # Ausgabe des Templates
480 print($form->parse_html_template('am/list_accounts', $parameters_ref));
482 $main::lxdebug->leave_sub();
487 sub list_account_details {
488 # Ajax Funktion aus list_account_details
489 $main::lxdebug->enter_sub();
491 my $form = $main::form;
492 my %myconfig = %main::myconfig;
493 my $locale = $main::locale;
495 $main::auth->assert('config');
497 my $chart_id = $form->{args};
499 CA->all_accounts(\%myconfig, \%$form, $chart_id);
501 foreach my $ca (@{ $form->{CA} }) {
503 $ca->{debit} = " ";
504 $ca->{credit} = " ";
506 if ($ca->{amount} > 0) {
508 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
510 if ($ca->{amount} < 0) {
512 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
515 my @links = split( q{:}, $ca->{link});
519 foreach my $link (@links){
520 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
521 : ( $link eq 'AP') ? $locale->text('Account Link AP')
522 : ( $link eq 'IC') ? $locale->text('Account Link IC')
523 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
524 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
525 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
526 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
527 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
528 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
529 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
530 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
531 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
532 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
533 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
534 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
535 : $locale->text('Unknown Link') . ': ' . $link;
536 $ca->{link} .= ($link ne '') ? "[$link] ":'';
539 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
540 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
541 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
542 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
543 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
544 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
545 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
546 : $locale->text('Unknown Category') . ': ' . $ca->{category};
549 $form->{title} = $locale->text('Chart of Accounts');
551 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
553 $main::lxdebug->leave_sub();
558 $main::lxdebug->enter_sub();
560 my $form = $main::form;
561 my %myconfig = %main::myconfig;
562 my $locale = $main::locale;
564 $main::auth->assert('config');
566 $form->{title} = $locale->text('Delete Account');
569 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
571 if ($form->{id} == $form->{$id}) {
572 $form->error($locale->text('Cannot delete default account!'));
576 $form->redirect($locale->text('Account deleted!'))
577 if (AM->delete_account(\%myconfig, \%$form));
578 $form->error($locale->text('Cannot delete account!'));
580 $main::lxdebug->leave_sub();
584 $main::lxdebug->enter_sub();
586 my $form = $main::form;
588 $main::auth->assert('config');
590 $form->{title} = "Add";
592 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
597 $main::lxdebug->leave_sub();
601 $main::lxdebug->enter_sub();
603 my $form = $main::form;
604 my %myconfig = %main::myconfig;
606 $main::auth->assert('config');
608 $form->{title} = "Edit";
610 AM->get_lead(\%myconfig, \%$form);
614 $form->{orphaned} = 1;
617 $main::lxdebug->leave_sub();
621 $::lxdebug->enter_sub;
622 $::auth->assert('config');
624 AM->lead(\%::myconfig, $::form);
626 $::form->{callback} = "am.pl?action=list_lead";
627 $::form->{title} = $::locale->text('Lead');
630 print $::form->parse_html_template('am/lead_list');
632 $::lxdebug->leave_sub;
636 $::lxdebug->enter_sub;
637 $::auth->assert('config');
639 # $locale->text('Add Lead')
640 # $locale->text('Edit Lead')
641 $::form->{title} = $::locale->text("$::form->{title} Lead");
644 print $::form->parse_html_template('am/lead_header');
646 $::lxdebug->leave_sub;
650 $main::lxdebug->enter_sub();
652 my $form = $main::form;
653 my %myconfig = %main::myconfig;
654 my $locale = $main::locale;
656 $main::auth->assert('config');
658 $form->isblank("description", $locale->text('Description missing!'));
659 AM->save_lead(\%myconfig, \%$form);
660 $form->redirect($locale->text('lead saved!'));
662 $main::lxdebug->leave_sub();
666 $main::lxdebug->enter_sub();
668 my $form = $main::form;
669 my %myconfig = %main::myconfig;
670 my $locale = $main::locale;
672 $main::auth->assert('config');
674 AM->delete_lead(\%myconfig, \%$form);
675 $form->redirect($locale->text('lead deleted!'));
677 $main::lxdebug->leave_sub();
681 $main::lxdebug->enter_sub();
683 my $form = $main::form;
685 $main::auth->assert('config');
687 $form->{title} = "Add";
689 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
694 $main::lxdebug->leave_sub();
698 $main::lxdebug->enter_sub();
700 my $form = $main::form;
701 my %myconfig = %main::myconfig;
703 $main::auth->assert('config');
705 $form->{title} = "Edit";
707 AM->get_language(\%myconfig, \%$form);
711 $form->{orphaned} = 1;
714 $main::lxdebug->leave_sub();
718 $::lxdebug->enter_sub;
719 $::auth->assert('config');
721 AM->language(\%::myconfig, $::form);
723 $::form->{callback} = "am.pl?action=list_language";
724 $::form->{title} = $::locale->text('Languages');
728 print $::form->parse_html_template('am/language_list');
730 $::lxdebug->leave_sub;
733 sub language_header {
734 $::lxdebug->enter_sub;
735 $::auth->assert('config');
737 # $locale->text('Add Language')
738 # $locale->text('Edit Language')
739 $::form->{title} = $::locale->text("$::form->{title} Language");
743 print $::form->parse_html_template('am/language_header', {
744 numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00' ],
745 dateformats => [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
748 $::lxdebug->leave_sub;
752 $main::lxdebug->enter_sub();
754 my $form = $main::form;
755 my %myconfig = %main::myconfig;
756 my $locale = $main::locale;
758 $main::auth->assert('config');
760 $form->isblank("description", $locale->text('Language missing!'));
761 $form->isblank("template_code", $locale->text('Template Code missing!'));
762 $form->isblank("article_code", $locale->text('Article Code missing!'));
763 AM->save_language(\%myconfig, \%$form);
764 $form->redirect($locale->text('Language saved!'));
766 $main::lxdebug->leave_sub();
769 sub delete_language {
770 $main::lxdebug->enter_sub();
772 my $form = $main::form;
773 my %myconfig = %main::myconfig;
774 my $locale = $main::locale;
776 $main::auth->assert('config');
778 AM->delete_language(\%myconfig, \%$form);
779 $form->redirect($locale->text('Language deleted!'));
781 $main::lxdebug->leave_sub();
785 sub add_buchungsgruppe {
786 $main::lxdebug->enter_sub();
788 my $form = $main::form;
789 my %myconfig = %main::myconfig;
790 my $locale = $main::locale;
792 $main::auth->assert('config');
794 # $locale->text("Add Buchungsgruppe")
795 # $locale->text("Edit Buchungsgruppe")
796 $form->{title} = "Add";
798 $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
800 AM->get_buchungsgruppe(\%myconfig, \%$form);
801 $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
802 for (my $i = 0; 4 > $i; $i++) {
803 map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
807 &buchungsgruppe_header;
810 $main::lxdebug->leave_sub();
813 sub edit_buchungsgruppe {
814 $main::lxdebug->enter_sub();
816 my $form = $main::form;
817 my %myconfig = %main::myconfig;
819 $main::auth->assert('config');
821 $form->{title} = "Edit";
823 AM->get_buchungsgruppe(\%myconfig, \%$form);
825 &buchungsgruppe_header;
829 $main::lxdebug->leave_sub();
832 sub list_buchungsgruppe {
833 $::lxdebug->enter_sub;
834 $::auth->assert('config');
836 AM->buchungsgruppe(\%::myconfig, $::form);
838 $::form->{callback} = "am.pl?action=list_buchungsgruppe";
839 $::form->{title} = $::locale->text('Buchungsgruppen');
842 print $::form->parse_html_template('am/buchungsgruppe_list', {
843 swap_link => qq|am.pl?action=swap_buchungsgruppen&|,
846 $::lxdebug->leave_sub;
849 sub buchungsgruppe_header {
850 $::lxdebug->enter_sub;
851 $::auth->assert('config');
853 # $locale->text('Add Accounting Group')
854 # $locale->text('Edit Accounting Group')
855 $::form->{title} = $::locale->text("$::form->{title} Buchungsgruppe");
857 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
859 IC => $acc_inventory,
860 IC_income => $acc_income,
861 IC_sale => $acc_income,
862 IC_expense => $acc_expense,
863 IC_cogs => $acc_expense,
866 for my $key (keys %acc_type_map) {
867 for my $ref (@{ $::form->{IC_links}{$key} }) {
868 $acc_type_map{$key}{$ref->{id}} = $ref;
872 my %sorted_accounts = map {
873 $_ => [ sort { $a->{accno} cmp $b->{accno} } values %{ $acc_type_map{$_} } ],
874 } keys %acc_type_map;
877 print $::form->parse_html_template('am/buchungsgruppe_header', {
878 accounts => \%sorted_accounts,
879 account_label => sub { "$_[0]{accno}--$_[0]{description}" },
882 $::lxdebug->leave_sub;
885 sub save_buchungsgruppe {
886 $main::lxdebug->enter_sub();
888 my $form = $main::form;
889 my %myconfig = %main::myconfig;
890 my $locale = $main::locale;
892 $main::auth->assert('config');
894 $form->isblank("description", $locale->text('Description missing!'));
896 AM->save_buchungsgruppe(\%myconfig, \%$form);
897 $form->redirect($locale->text('Accounting Group saved!'));
899 $main::lxdebug->leave_sub();
902 sub delete_buchungsgruppe {
903 $main::lxdebug->enter_sub();
905 my $form = $main::form;
906 my %myconfig = %main::myconfig;
907 my $locale = $main::locale;
909 $main::auth->assert('config');
911 AM->delete_buchungsgruppe(\%myconfig, \%$form);
912 $form->redirect($locale->text('Accounting Group deleted!'));
914 $main::lxdebug->leave_sub();
917 sub swap_buchungsgruppen {
918 $main::lxdebug->enter_sub();
920 my $form = $main::form;
921 my %myconfig = %main::myconfig;
923 $main::auth->assert('config');
925 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
926 list_buchungsgruppe();
928 $main::lxdebug->leave_sub();
932 $main::lxdebug->enter_sub();
934 my $form = $main::form;
935 my %myconfig = %main::myconfig;
936 my $locale = $main::locale;
938 # get defaults for account numbers and last numbers
939 AM->defaultaccounts(\%myconfig, \%$form);
940 $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
942 map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
945 my $all_languages = SL::DB::Manager::Language->get_all;
947 # EÜR = cash, Bilanzierung = accrual
949 foreach my $key (keys %{ $form->{IC} }) {
950 foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
951 my $array = "ACCNOS_" . uc($key);
952 $form->{$array} ||= [];
954 my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
955 push @{ $form->{$array} }, {
958 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
963 $form->{title} = $locale->text('Ranges of numbers and default accounts');
966 print $form->parse_html_template('am/edit_defaults',
967 { ALL_LANGUAGES => $all_languages, });
969 $main::lxdebug->leave_sub();
973 $main::lxdebug->enter_sub();
975 my $form = $main::form;
976 my $locale = $main::locale;
980 $form->redirect($locale->text('Defaults saved.'));
982 $main::lxdebug->leave_sub();
985 sub _build_cfg_options {
986 my $form = $main::form;
987 my %myconfig = %main::myconfig;
990 my $array = uc($idx) . 'S';
992 $form->{$array} = [];
993 foreach my $item (@_) {
994 push @{ $form->{$array} }, {
997 'selected' => $item eq $myconfig{$idx},
1003 $main::lxdebug->enter_sub();
1005 my $form = $main::form;
1006 my %myconfig = %main::myconfig;
1007 my $locale = $main::locale;
1009 _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
1010 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
1013 if ($::lx_office_conf{print_templates}->{opendocument}
1014 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
1015 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
1016 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
1017 "value" => "opendocument_pdf" });
1019 if ($::lx_office_conf{print_templates}->{latex}) {
1020 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
1022 push(@formats, { "name" => "HTML", "value" => "html" });
1023 if ($::lx_office_conf{print_templates}->{latex}) {
1024 push(@formats, { "name" => $locale->text("Postscript"),
1025 "value" => "postscript" });
1027 if ($::lx_office_conf{print_templates}->{opendocument}) {
1028 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
1029 "value" => "opendocument" });
1032 if (!$myconfig{"template_format"}) {
1033 $myconfig{"template_format"} = "pdf";
1035 $form->{TEMPLATE_FORMATS} = [];
1036 foreach my $item (@formats) {
1037 push @{ $form->{TEMPLATE_FORMATS} }, {
1038 'name' => $item->{name},
1039 'value' => $item->{value},
1040 'selected' => $item->{value} eq $myconfig{template_format},
1044 if (!$myconfig{"default_media"}) {
1045 $myconfig{"default_media"} = "screen";
1048 my %selected = ($myconfig{"default_media"} => "selected");
1050 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
1051 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
1052 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
1055 $form->{PRINTERS} = [ SL::Printer->all_printers(%::myconfig) ];
1057 my %countrycodes = User->country_codes;
1059 $form->{COUNTRYCODES} = [];
1060 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
1061 push @{ $form->{COUNTRYCODES} }, {
1062 'name' => $countrycodes{$countrycode},
1063 'value' => $countrycode,
1064 'selected' => $countrycode eq $myconfig{countrycode},
1068 $form->{STYLESHEETS} = [];
1069 foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css kivitendo.css)) {
1070 push @{ $form->{STYLESHEETS} }, {
1073 'selected' => $item eq $myconfig{stylesheet},
1077 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
1078 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
1079 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
1081 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
1084 print $form->parse_html_template('am/config');
1086 $main::lxdebug->leave_sub();
1089 sub save_preferences {
1090 $main::lxdebug->enter_sub();
1092 my $form = $main::form;
1093 my %myconfig = %main::myconfig;
1094 my $locale = $main::locale;
1096 $form->{stylesheet} = $form->{usestylesheet};
1098 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
1100 if (AM->save_preferences(\%myconfig, $form)) {
1101 if ($::auth->can_change_password()
1102 && defined $form->{new_password}
1103 && ($form->{new_password} ne '********')) {
1104 my $verifier = SL::Auth::PasswordPolicy->new;
1105 my $result = $verifier->verify($form->{new_password});
1107 if ($result != SL::Auth::PasswordPolicy->OK()) {
1108 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
1111 $::auth->change_password($form->{login}, $form->{new_password});
1113 $form->{password} = $form->{new_password};
1114 $::auth->set_session_value('password', $form->{password});
1115 $::auth->create_or_refresh_session();
1118 $form->redirect($locale->text('Preferences saved!'));
1121 $form->error($locale->text('Cannot save preferences!'));
1123 $main::lxdebug->leave_sub();
1127 $::lxdebug->enter_sub;
1128 $::auth->assert('config');
1130 $::form->{title} = $::locale->text('Audit Control');
1132 AM->closedto(\%::myconfig, $::form);
1135 print $::form->parse_html_template('am/audit_control');
1137 $::lxdebug->leave_sub;
1141 $main::lxdebug->enter_sub();
1143 my $form = $main::form;
1144 my %myconfig = %main::myconfig;
1145 my $locale = $main::locale;
1147 $main::auth->assert('config');
1149 AM->closebooks(\%myconfig, \%$form);
1151 if ($form->{closedto}) {
1153 $locale->text('Books closed up to') . " "
1154 . $locale->date(\%myconfig, $form->{closedto}, 1));
1156 $form->redirect($locale->text('Books are open'));
1159 $main::lxdebug->leave_sub();
1163 $main::lxdebug->enter_sub();
1165 my $form = $main::form;
1166 my %myconfig = %main::myconfig;
1167 my $locale = $main::locale;
1169 $main::auth->assert('config');
1171 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1172 AM->units_in_use(\%myconfig, $form, $units);
1173 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1175 my @languages = AM->language(\%myconfig, $form, 1);
1177 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1180 foreach (@unit_list) {
1181 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1182 $_->{"UNITLANGUAGES"} = [];
1183 foreach my $lang (@languages) {
1184 push(@{ $_->{"UNITLANGUAGES"} },
1186 "unit" => $_->{"name"},
1187 "language_id" => $lang->{"id"},
1188 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1189 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1195 $units = AM->retrieve_units(\%myconfig, $form);
1196 my $ddbox = AM->unit_select_data($units, undef, 1);
1198 $form->{"title"} = $locale->text("Add and edit units");
1200 print($form->parse_html_template("am/edit_units",
1201 { "UNITS" => \@unit_list,
1202 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1203 "LANGUAGES" => \@languages,
1206 $main::lxdebug->leave_sub();
1210 $main::lxdebug->enter_sub();
1212 my $form = $main::form;
1213 my %myconfig = %main::myconfig;
1214 my $locale = $main::locale;
1216 $main::auth->assert('config');
1218 $form->isblank("new_name", $locale->text("The name is missing."));
1219 my $units = AM->retrieve_units(\%myconfig, $form);
1220 my $all_units = AM->retrieve_units(\%myconfig, $form);
1221 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1223 my ($base_unit, $factor);
1224 if ($form->{"new_base_unit"}) {
1225 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1227 $form->isblank("new_factor", $locale->text("The factor is missing."));
1228 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1229 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1230 $base_unit = $form->{"new_base_unit"};
1234 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1235 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1236 push(@languages, { "id" => $lang->{"id"},
1237 "localized" => $form->{"new_localized_$lang->{id}"},
1238 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1242 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1244 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1248 $main::lxdebug->leave_sub();
1251 sub set_unit_languages {
1252 $main::lxdebug->enter_sub();
1254 my $form = $main::form;
1256 $main::auth->assert('config');
1258 my ($unit, $languages, $idx) = @_;
1260 $unit->{"LANGUAGES"} = [];
1262 foreach my $lang (@{$languages}) {
1263 push(@{ $unit->{"LANGUAGES"} },
1264 { "id" => $lang->{"id"},
1265 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1266 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1270 $main::lxdebug->leave_sub();
1274 $main::lxdebug->enter_sub();
1276 my $form = $main::form;
1277 my %myconfig = %main::myconfig;
1278 my $locale = $main::locale;
1280 $main::auth->assert('config');
1282 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1283 AM->units_in_use(\%myconfig, $form, $old_units);
1285 my @languages = AM->language(\%myconfig, $form, 1);
1288 my @delete_units = ();
1289 foreach my $i (1..($form->{"rowcount"} * 1)) {
1290 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1292 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1295 if ($form->{"unchangeable_$i"}) {
1296 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1297 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1298 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1302 if ($old_unit->{"in_use"}) {
1303 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1306 if ($form->{"delete_$i"}) {
1307 push(@delete_units, $old_unit->{"name"});
1311 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1313 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1314 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1315 $new_units->{$form->{"name_$i"}} = \%h;
1316 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1317 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1320 foreach my $unit (values(%{$new_units})) {
1321 next unless ($unit->{"old_name"});
1322 if ($unit->{"base_unit"}) {
1323 $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"}))
1324 unless (defined($new_units->{$unit->{"base_unit"}}));
1325 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1326 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1328 $unit->{"base_unit"} = undef;
1329 $unit->{"factor"} = undef;
1333 foreach my $unit (values(%{$new_units})) {
1334 next if ($unit->{"unchanged_unit"});
1336 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1337 my $new_unit = $unit;
1338 while ($new_unit->{"base_unit"}) {
1339 $new_unit->{"seen"} = 1;
1340 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1341 if ($new_unit->{"seen"}) {
1342 $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, " .
1343 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1348 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1350 $form->{"saved_message"} = $locale->text("The units have been saved.");
1354 $main::lxdebug->leave_sub();
1357 sub show_history_search {
1358 $main::lxdebug->enter_sub();
1360 my $form = $main::form;
1361 my $locale = $main::locale;
1363 $main::auth->assert('config');
1365 $form->{title} = $locale->text("History Search");
1368 print $form->parse_html_template("common/search_history");
1370 $main::lxdebug->leave_sub();
1373 sub show_am_history {
1374 $main::lxdebug->enter_sub();
1376 my $form = $main::form;
1377 my %myconfig = %main::myconfig;
1378 my $locale = $main::locale;
1380 $main::auth->assert('config');
1382 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1383 $form->{order} ||= 'h.itime--1';
1385 my %search = ( "Artikelnummer" => "parts",
1386 "Kundennummer" => "customer",
1387 "Lieferantennummer" => "vendor",
1388 "Projektnummer" => "project",
1389 "Buchungsnummer" => "oe",
1390 "Eingangsrechnungnummer" => "ap",
1391 "Ausgangsrechnungnummer" => "ar",
1392 "Mahnungsnummer" => "dunning"
1394 my %searchNo = ( "Artikelnummer" => "partnumber",
1395 "Kundennummer" => "customernumber",
1396 "Lieferantennummer" => "vendornumber",
1397 "Projektnummer" => "projectnumber",
1398 "Buchungsnummer" => "ordnumber",
1399 "Eingangsrechnungnummer" => "invnumber",
1400 "Ausgangsrechnungnummer" => "invnumber",
1401 "Mahnungsnummer" => "dunning_id"
1404 my $dbh = $form->dbconnect(\%myconfig);
1407 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1408 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1409 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1410 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1411 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1412 } elsif ($form->{mitarbeiter}) {
1413 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1416 my $query = qq|SELECT trans_id AS id FROM history_erp | .
1417 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
1418 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
1420 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
1421 my $daten .= shift @ids;
1422 $daten .= join '', map { " OR trans_id = $_" } @ids;
1424 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1425 $sort =~ s/.*\.(.*)$/$1/;
1427 $form->{title} = $locale->text("History Search");
1430 print $form->parse_html_template("common/show_history",
1431 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1432 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1435 uc($sort) . "BY" => $sortby,
1436 'callback' => $callback,
1440 $main::lxdebug->leave_sub();
1444 $main::lxdebug->enter_sub();
1446 my $form = $main::form;
1447 my $locale = $main::locale;
1449 $main::auth->assert('config');
1451 $form->{title} = $locale->text('Add');
1453 $form->{callback} ||= "am.pl?action=add_tax";
1455 _get_taxaccount_selection();
1459 my $parameters_ref = {
1460 # ChartTypeIsAccount => $ChartTypeIsAccount,
1463 # Ausgabe des Templates
1464 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1466 $main::lxdebug->leave_sub();
1470 $main::lxdebug->enter_sub();
1472 my $form = $main::form;
1473 my %myconfig = %main::myconfig;
1474 my $locale = $main::locale;
1476 $main::auth->assert('config');
1478 $form->{title} = $locale->text('Edit');
1480 AM->get_tax(\%myconfig, \%$form);
1481 _get_taxaccount_selection();
1483 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1487 my $parameters_ref = {
1490 # Ausgabe des Templates
1491 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1493 $main::lxdebug->leave_sub();
1497 $main::lxdebug->enter_sub();
1499 my $form = $main::form;
1500 my %myconfig = %main::myconfig;
1501 my $locale = $main::locale;
1503 $main::auth->assert('config');
1505 AM->taxes(\%myconfig, \%$form);
1507 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1509 $form->{callback} = build_std_url('action=list_tax');
1511 $form->{title} = $locale->text('Tax-O-Matic');
1515 my $parameters_ref = {
1518 # Ausgabe des Templates
1519 print($form->parse_html_template('am/list_tax', $parameters_ref));
1521 $main::lxdebug->leave_sub();
1524 sub _get_taxaccount_selection{
1525 $main::lxdebug->enter_sub();
1527 my $form = $main::form;
1528 my %myconfig = %main::myconfig;
1530 $main::auth->assert('config');
1532 AM->get_tax_accounts(\%myconfig, \%$form);
1534 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1536 $main::lxdebug->leave_sub();
1540 $main::lxdebug->enter_sub();
1542 my $form = $main::form;
1543 my %myconfig = %main::myconfig;
1544 my $locale = $main::locale;
1546 $main::auth->assert('config');
1548 $form->isblank("rate", $locale->text('Taxrate missing!'));
1549 $form->isblank("taxdescription", $locale->text('Taxdescription missing!'));
1550 $form->isblank("taxkey", $locale->text('Taxkey missing!'));
1552 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1554 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1555 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1558 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
1559 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1562 AM->save_tax(\%myconfig, \%$form);
1563 $form->redirect($locale->text('Tax saved!'));
1565 $main::lxdebug->leave_sub();
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 AM->delete_tax(\%myconfig, \%$form);
1578 $form->redirect($locale->text('Tax deleted!'));
1580 $main::lxdebug->leave_sub();
1583 sub add_price_factor {
1584 $main::lxdebug->enter_sub();
1586 my $form = $main::form;
1587 my $locale = $main::locale;
1589 $main::auth->assert('config');
1591 $form->{title} = $locale->text('Add Price Factor');
1592 $form->{callback} ||= build_std_url('action=add_price_factor');
1593 $form->{fokus} = 'description';
1596 print $form->parse_html_template('am/edit_price_factor');
1598 $main::lxdebug->leave_sub();
1601 sub edit_price_factor {
1602 $main::lxdebug->enter_sub();
1604 my $form = $main::form;
1605 my %myconfig = %main::myconfig;
1606 my $locale = $main::locale;
1608 $main::auth->assert('config');
1610 $form->{title} = $locale->text('Edit Price Factor');
1611 $form->{callback} ||= build_std_url('action=add_price_factor');
1612 $form->{fokus} = 'description';
1614 AM->get_price_factor(\%myconfig, $form);
1616 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
1619 print $form->parse_html_template('am/edit_price_factor');
1621 $main::lxdebug->leave_sub();
1624 sub list_price_factors {
1625 $main::lxdebug->enter_sub();
1627 my $form = $main::form;
1628 my %myconfig = %main::myconfig;
1629 my $locale = $main::locale;
1631 $main::auth->assert('config');
1633 AM->get_all_price_factors(\%myconfig, \%$form);
1635 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
1636 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
1639 $form->{callback} = build_std_url('action=list_price_factors');
1640 $form->{title} = $locale->text('Price Factors');
1641 $form->{url_base} = build_std_url('callback');
1644 print $form->parse_html_template('am/list_price_factors');
1646 $main::lxdebug->leave_sub();
1649 sub save_price_factor {
1650 $main::lxdebug->enter_sub();
1652 my $form = $main::form;
1653 my %myconfig = %main::myconfig;
1654 my $locale = $main::locale;
1656 $main::auth->assert('config');
1658 $form->isblank("description", $locale->text('Description missing!'));
1659 $form->isblank("factor", $locale->text('Factor missing!'));
1661 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
1663 AM->save_price_factor(\%myconfig, $form);
1665 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
1667 $form->redirect($locale->text('Price factor saved!'));
1669 $main::lxdebug->leave_sub();
1672 sub delete_price_factor {
1673 $main::lxdebug->enter_sub();
1675 my $form = $main::form;
1676 my %myconfig = %main::myconfig;
1677 my $locale = $main::locale;
1679 $main::auth->assert('config');
1681 AM->delete_price_factor(\%myconfig, \%$form);
1683 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
1685 $form->redirect($locale->text('Price factor deleted!'));
1687 $main::lxdebug->leave_sub();
1691 $main::lxdebug->enter_sub();
1693 my $form = $main::form;
1694 my $locale = $main::locale;
1696 $main::auth->assert('config');
1698 $form->{title} = $locale->text('Add Warehouse');
1699 $form->{callback} ||= build_std_url('action=add_warehouse');
1700 $form->{fokus} = 'description';
1703 print $form->parse_html_template('am/edit_warehouse');
1705 $main::lxdebug->leave_sub();
1708 sub edit_warehouse {
1709 $main::lxdebug->enter_sub();
1711 my $form = $main::form;
1712 my %myconfig = %main::myconfig;
1713 my $locale = $main::locale;
1715 $main::auth->assert('config');
1717 AM->get_warehouse(\%myconfig, $form);
1719 $form->get_lists('employees' => 'EMPLOYEES');
1721 $form->{title} = $locale->text('Edit Warehouse');
1722 $form->{callback} ||= build_std_url('action=list_warehouses');
1723 $form->{fokus} = 'description';
1726 print $form->parse_html_template('am/edit_warehouse');
1728 $main::lxdebug->leave_sub();
1731 sub list_warehouses {
1732 $main::lxdebug->enter_sub();
1734 my $form = $main::form;
1735 my %myconfig = %main::myconfig;
1736 my $locale = $main::locale;
1738 $main::auth->assert('config');
1740 AM->get_all_warehouses(\%myconfig, $form);
1742 $form->{callback} = build_std_url('action=list_warehouses');
1743 $form->{title} = $locale->text('Warehouses');
1744 $form->{url_base} = build_std_url('callback');
1747 print $form->parse_html_template('am/list_warehouses');
1749 $main::lxdebug->leave_sub();
1752 sub save_warehouse {
1753 $main::lxdebug->enter_sub();
1755 my $form = $main::form;
1756 my %myconfig = %main::myconfig;
1757 my $locale = $main::locale;
1759 $main::auth->assert('config');
1761 $form->isblank("description", $locale->text('Description missing!'));
1763 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
1765 AM->save_warehouse(\%myconfig, $form);
1767 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
1769 $form->redirect($locale->text('Warehouse saved.'));
1771 $main::lxdebug->leave_sub();
1774 sub delete_warehouse {
1775 $main::lxdebug->enter_sub();
1777 my $form = $main::form;
1778 my %myconfig = %main::myconfig;
1779 my $locale = $main::locale;
1781 $main::auth->assert('config');
1783 if (!$form->{confirmed}) {
1784 $form->{title} = $locale->text('Confirmation');
1787 print $form->parse_html_template('am/confirm_delete_warehouse');
1791 if (AM->delete_warehouse(\%myconfig, $form)) {
1792 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
1793 $form->redirect($locale->text('Warehouse deleted.'));
1796 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
1799 $main::lxdebug->leave_sub();
1803 $main::lxdebug->enter_sub();
1805 my $form = $main::form;
1806 my %myconfig = %main::myconfig;
1807 my $locale = $main::locale;
1809 $main::auth->assert('config');
1811 AM->save_bins(\%myconfig, $form);
1813 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
1815 $form->redirect($locale->text('Bins saved.'));
1817 $main::lxdebug->leave_sub();