1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
32 #======================================================================
37 use SL::Auth::PasswordPolicy;
50 require "bin/mozilla/common.pl";
58 sub add { call_sub("add_$main::form->{type}"); }
59 sub delete { call_sub("delete_$main::form->{type}"); }
60 sub save { call_sub("save_$main::form->{type}"); }
61 sub edit { call_sub("edit_$main::form->{type}"); }
62 sub continue { call_sub($main::form->{"nextsub"}); }
63 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
66 $main::lxdebug->enter_sub();
68 my $form = $main::form;
69 my %myconfig = %main::myconfig;
71 $main::auth->assert('config');
73 $form->{title} = "Add";
74 $form->{charttype} = "A";
75 AM->get_account(\%myconfig, \%$form);
77 $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
82 $main::lxdebug->leave_sub();
86 $main::lxdebug->enter_sub();
88 my $form = $main::form;
89 my %myconfig = %main::myconfig;
91 $main::auth->assert('config');
93 $form->{title} = "Edit";
94 AM->get_account(\%myconfig, \%$form);
96 foreach my $item (split(/:/, $form->{link})) {
97 $form->{$item} = "checked";
103 $main::lxdebug->leave_sub();
107 $main::lxdebug->enter_sub();
109 my $form = $main::form;
110 my %myconfig = %main::myconfig;
111 my $locale = $main::locale;
113 $main::auth->assert('config');
115 if ( $form->{action} eq 'edit_account') {
116 $form->{account_exists} = '1';
119 $form->{title} = $locale->text("$form->{title} Account");
121 $form->{"$form->{charttype}_checked"} = "checked";
122 $form->{"$form->{category}_checked"} = "checked";
124 $form->{select_tax} = "";
126 my @tax_report_pos = USTVA->report_variables({
127 myconfig => \%myconfig,
130 attribute => 'position',
134 if (@{ $form->{TAXKEY} }) {
135 foreach my $item (@{ $form->{TAXKEY} }) {
136 $item->{rate} = $item->{rate} * 100 . '%';
139 # Fill in empty row for new Taxkey
140 my $newtaxkey_ref = {
145 taxdescription => '',
149 startdate => $form->{account_exists} ? '' : DateTime->new(year => 1970, month => 1, day => 1)->to_lxoffice,
152 push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
155 foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
157 # Fill in a runningnumber
158 $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
160 # Fill in the Taxkeys as select options
161 foreach my $item (@{ $form->{TAXKEY} }) {
162 if ($item->{id} == $taxkey_used->{tax_id}) {
163 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
164 qq|<option value="$item->{id}" selected="selected">|
165 . sprintf("%.2d", $item->{taxkey})
166 . qq|. $item->{taxdescription} ($item->{rate}) |
167 . $locale->text('Tax-o-matic Account')
168 . qq|: $item->{chart_accno}\n|;
171 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
172 qq|<option value="$item->{id}">|
173 . sprintf("%.2d", $item->{taxkey})
174 . qq|. $item->{taxdescription} ($item->{rate}) |
175 . $locale->text('Tax-o-matic Account')
176 . qq|: $item->{chart_accno}\n|;
181 # Fill in the USTVA Numbers as select options
182 foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
184 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
186 elsif ( $item eq $taxkey_used->{pos_ustva} ) {
187 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
190 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
199 # Newaccount Folgekonto
200 if (@{ $form->{NEWACCOUNT} || [] }) {
201 if (!$form->{new_chart_valid}) {
202 $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
204 foreach my $item (@{ $form->{NEWACCOUNT} }) {
205 if ($item->{id} == $form->{new_chart_id}) {
206 $form->{selectnewaccount} .=
207 qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
208 } elsif (!$form->{new_chart_valid}) {
209 $form->{selectnewaccount} .=
210 qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
216 my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
219 2 => "sonstige Erlöse",
220 3 => "Privatanteile",
222 5 => "Ausserordentliche Erträge",
223 6 => "Vereinnahmte Umsatzst.",
224 7 => "Umsatzsteuererstattungen",
225 8 => "Wareneingänge",
226 9 => "Löhne und Gehälter",
227 10 => "Gesetzl. sozialer Aufw.",
229 12 => "Gas, Strom, Wasser",
230 13 => "Instandhaltung",
231 14 => "Steuern, Versich., Beiträge",
233 16 => "Kfz-Versicherungen",
234 17 => "Sonst. Fahrzeugkosten",
235 18 => "Werbe- und Reisekosten",
236 19 => "Instandhaltung u. Werkzeuge",
237 20 => "Fachzeitschriften, Bücher",
238 21 => "Miete für Einrichtungen",
239 22 => "Rechts- und Beratungskosten",
240 23 => "Bürobedarf, Porto, Telefon",
241 24 => "Sonstige Aufwendungen",
242 25 => "Abschreibungen auf Anlagever.",
243 26 => "Abschreibungen auf GWG",
245 28 => "Umsatzsteuerzahlungen",
247 30 => "Ausserordentlicher Aufwand",
248 31 => "Betriebliche Steuern");
249 foreach my $item (sort({ $a <=> $b } keys(%eur))) {
250 my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
251 if ($item == $form->{pos_eur}) {
252 $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
254 $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
259 my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
263 2 => 'Best.Verdg.FE/UE',
264 3 => 'Aktiv.Eigenleistung',
265 4 => 'Mat./Wareneinkauf',
266 5 => 'So.betr.Erlöse',
267 10 => 'Personalkosten',
269 12 => 'Betriebl.Steuern',
270 13 => 'Vers./Beiträge',
271 14 => 'Kfz.Kosten o.St.',
272 15 => 'Werbe-Reisek.',
273 16 => 'Kosten Warenabgabe',
274 17 => 'Abschreibungen',
275 18 => 'Rep./instandhlt.',
276 19 => 'Übrige Steuern',
277 20 => 'Sonst.Kosten',
279 31 => 'Sonst.neutr.Aufw.',
281 33 => 'Sonst.neutr.Ertrag',
282 34 => 'Verr.kalk.Kosten',
283 35 => 'Steuern Eink.u.Ertr.');
284 foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
285 my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
286 if ($item == $form->{pos_bwa}) {
287 $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
289 $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
294 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
295 my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
296 foreach my $item ((1, 2, 3, 4)) {
297 if ($item == $form->{pos_bilanz}) {
298 $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
300 $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
305 # this is for our parser only! Do not remove.
306 # type=submit $locale->text('Add Account')
307 # type=submit $locale->text('Edit Account')
309 $form->{type} = "account";
311 # preselections category
313 my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
316 'A' => $locale->text('Asset'),
317 'L' => $locale->text('Liability'),
318 'Q' => $locale->text('Equity'),
319 'I' => $locale->text('Revenue'),
320 'E' => $locale->text('Expense'),
321 'C' => $locale->text('Costs'),
323 foreach my $item ( sort({ $a <=> $b } keys %category) ) {
324 if ($item eq $form->{category}) {
325 $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
327 $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
332 # preselection chart type
333 my @all_charttypes = ({'name' => $locale->text('Account'), 'value' => 'A'},
334 {'name' => $locale->text('Heading'), 'value' => 'H'},
336 my $selected_charttype = $form->{charttype};
339 # account where AR_tax or AP_tax is set are not orphaned if they are used as
340 # tax-o-matic account
341 if ( $form->{id} && $form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
342 if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
343 $form->{orphaned} = 0;
347 my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
348 my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
352 my $parameters_ref = {
353 ChartTypeIsAccount => $ChartTypeIsAccount,
354 AccountIsPosted => $AccountIsPosted,
355 select_category => $select_category,
356 all_charttypes => \@all_charttypes,
357 selected_charttype => $selected_charttype,
358 select_bwa => $select_bwa,
359 select_bilanz => $select_bilanz,
360 select_eur => $select_eur,
363 # Ausgabe des Templates
364 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
367 $main::lxdebug->leave_sub();
371 $::lxdebug->enter_sub;
372 $::auth->assert('config');
374 print $::form->parse_html_template('am/form_footer', {
375 show_save => !$::form->{id}
376 || ($::form->{id} && $::form->{orphaned})
377 || ($::form->{type} eq "account" && !$::form->{new_chart_valid}),
378 show_delete => $::form->{id} && $::form->{orphaned},
379 show_save_as_new => $::form->{id} && $::form->{type} eq "account",
382 $::lxdebug->leave_sub;
386 $main::lxdebug->enter_sub();
388 my $form = $main::form;
389 my %myconfig = %main::myconfig;
390 my $locale = $main::locale;
392 $main::auth->assert('config');
394 $form->isblank("accno", $locale->text('Account Number missing!'));
395 $form->isblank("description", $locale->text('Account Description missing!'));
397 if ($form->{charttype} eq 'A'){
398 $form->isblank("category", $locale->text('Account Type missing!'));
400 my $found_valid_taxkey = 0;
401 foreach my $i (0 .. 10) { # 10 is maximum count of taxkeys in form
402 if ($form->{"taxkey_startdate_$i"} and !$form->{"taxkey_del_$i"}) {
403 $found_valid_taxkey = 1;
407 if ($found_valid_taxkey == 0) {
408 $form->error($locale->text('A valid taxkey is missing!'));
412 $form->redirect($locale->text('Account saved!'))
413 if (AM->save_account(\%myconfig, \%$form));
414 $form->error($locale->text('Cannot save account!'));
416 $main::lxdebug->leave_sub();
419 sub save_as_new_account {
420 $main::lxdebug->enter_sub();
422 my $form = $main::form;
423 my %myconfig = %main::myconfig;
424 my $locale = $main::locale;
426 $main::auth->assert('config');
428 $form->isblank("accno", $locale->text('Account Number missing!'));
429 $form->isblank("description", $locale->text('Account Description missing!'));
431 if ($form->{charttype} eq 'A'){
432 $form->isblank("category", $locale->text('Account Type missing!'));
435 for my $taxkey (0 .. 9) {
436 if ($form->{"taxkey_id_$taxkey"}) {
437 $form->{"taxkey_id_$taxkey"} = "NEW";
442 $form->redirect($locale->text('Account saved!'))
443 if (AM->save_account(\%myconfig, \%$form));
444 $form->error($locale->text('Cannot save account!'));
446 $main::lxdebug->leave_sub();
450 $main::lxdebug->enter_sub();
452 my $form = $main::form;
453 my %myconfig = %main::myconfig;
454 my $locale = $main::locale;
456 $main::auth->assert('config');
458 $form->{callback} = build_std_url('action=list_account');
459 my $link_edit_account = build_std_url('action=edit_account', 'callback');
461 CA->all_accounts(\%myconfig, \%$form);
463 foreach my $ca (@{ $form->{CA} }) {
468 if ($ca->{amount} > 0) {
469 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
471 if ($ca->{amount} < 0) {
472 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
474 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
475 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
478 $::request->{layout}->use_stylesheet("list_accounts.css");
479 $form->{title} = $locale->text('Chart of Accounts');
484 my $parameters_ref = {
485 # hidden_variables => $_hidden_variables_ref,
488 # Ausgabe des Templates
489 print($form->parse_html_template('am/list_accounts', $parameters_ref));
491 $main::lxdebug->leave_sub();
496 sub list_account_details {
497 # Ajax Funktion aus list_account_details
498 $main::lxdebug->enter_sub();
500 my $form = $main::form;
501 my %myconfig = %main::myconfig;
502 my $locale = $main::locale;
504 $main::auth->assert('config');
506 my $chart_id = $form->{args};
508 CA->all_accounts(\%myconfig, \%$form, $chart_id);
510 foreach my $ca (@{ $form->{CA} }) {
512 $ca->{debit} = " ";
513 $ca->{credit} = " ";
515 if ($ca->{amount} > 0) {
517 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
519 if ($ca->{amount} < 0) {
521 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
524 my @links = split( q{:}, $ca->{link});
528 foreach my $link (@links){
529 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
530 : ( $link eq 'AP') ? $locale->text('Account Link AP')
531 : ( $link eq 'IC') ? $locale->text('Account Link IC')
532 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
533 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
534 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
535 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
536 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
537 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
538 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
539 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
540 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
541 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
542 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
543 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
544 : $locale->text('Unknown Link') . ': ' . $link;
545 $ca->{link} .= ($link ne '') ? "[$link] ":'';
548 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
549 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
550 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
551 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
552 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
553 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
554 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
555 : $locale->text('Unknown Category') . ': ' . $ca->{category};
558 $form->{title} = $locale->text('Chart of Accounts');
560 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
562 $main::lxdebug->leave_sub();
567 $main::lxdebug->enter_sub();
569 my $form = $main::form;
570 my %myconfig = %main::myconfig;
571 my $locale = $main::locale;
573 $main::auth->assert('config');
575 $form->{title} = $locale->text('Delete Account');
578 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
580 if ($form->{id} == $form->{$id}) {
581 $form->error($locale->text('Cannot delete default account!'));
585 $form->redirect($locale->text('Account deleted!'))
586 if (AM->delete_account(\%myconfig, \%$form));
587 $form->error($locale->text('Cannot delete account!'));
589 $main::lxdebug->leave_sub();
593 $main::lxdebug->enter_sub();
595 my $form = $main::form;
597 $main::auth->assert('config');
599 $form->{title} = "Add";
601 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
606 $main::lxdebug->leave_sub();
610 $main::lxdebug->enter_sub();
612 my $form = $main::form;
613 my %myconfig = %main::myconfig;
615 $main::auth->assert('config');
617 $form->{title} = "Edit";
619 AM->get_lead(\%myconfig, \%$form);
623 $form->{orphaned} = 1;
626 $main::lxdebug->leave_sub();
630 $::lxdebug->enter_sub;
631 $::auth->assert('config');
633 AM->lead(\%::myconfig, $::form);
635 $::form->{callback} = "am.pl?action=list_lead";
636 $::form->{title} = $::locale->text('Lead');
639 print $::form->parse_html_template('am/lead_list');
641 $::lxdebug->leave_sub;
645 $::lxdebug->enter_sub;
646 $::auth->assert('config');
648 # $locale->text('Add Lead')
649 # $locale->text('Edit Lead')
650 $::form->{title} = $::locale->text("$::form->{title} Lead");
653 print $::form->parse_html_template('am/lead_header');
655 $::lxdebug->leave_sub;
659 $main::lxdebug->enter_sub();
661 my $form = $main::form;
662 my %myconfig = %main::myconfig;
663 my $locale = $main::locale;
665 $main::auth->assert('config');
667 $form->isblank("description", $locale->text('Description missing!'));
668 AM->save_lead(\%myconfig, \%$form);
669 $form->redirect($locale->text('lead saved!'));
671 $main::lxdebug->leave_sub();
675 $main::lxdebug->enter_sub();
677 my $form = $main::form;
678 my %myconfig = %main::myconfig;
679 my $locale = $main::locale;
681 $main::auth->assert('config');
683 AM->delete_lead(\%myconfig, \%$form);
684 $form->redirect($locale->text('lead deleted!'));
686 $main::lxdebug->leave_sub();
690 $main::lxdebug->enter_sub();
692 my $form = $main::form;
694 $main::auth->assert('config');
696 $form->{title} = "Add";
698 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
703 $main::lxdebug->leave_sub();
707 $main::lxdebug->enter_sub();
709 my $form = $main::form;
710 my %myconfig = %main::myconfig;
712 $main::auth->assert('config');
714 $form->{title} = "Edit";
716 AM->get_language(\%myconfig, \%$form);
720 $form->{orphaned} = 1;
723 $main::lxdebug->leave_sub();
727 $::lxdebug->enter_sub;
728 $::auth->assert('config');
730 AM->language(\%::myconfig, $::form);
732 $::form->{callback} = "am.pl?action=list_language";
733 $::form->{title} = $::locale->text('Languages');
737 print $::form->parse_html_template('am/language_list');
739 $::lxdebug->leave_sub;
742 sub language_header {
743 $::lxdebug->enter_sub;
744 $::auth->assert('config');
746 # $locale->text('Add Language')
747 # $locale->text('Edit Language')
748 $::form->{title} = $::locale->text("$::form->{title} Language");
752 print $::form->parse_html_template('am/language_header', {
753 numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00' ],
754 dateformats => [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
757 $::lxdebug->leave_sub;
761 $main::lxdebug->enter_sub();
763 my $form = $main::form;
764 my %myconfig = %main::myconfig;
765 my $locale = $main::locale;
767 $main::auth->assert('config');
769 $form->isblank("description", $locale->text('Language missing!'));
770 $form->isblank("template_code", $locale->text('Template Code missing!'));
771 $form->isblank("article_code", $locale->text('Article Code missing!'));
772 AM->save_language(\%myconfig, \%$form);
773 $form->redirect($locale->text('Language saved!'));
775 $main::lxdebug->leave_sub();
778 sub delete_language {
779 $main::lxdebug->enter_sub();
781 my $form = $main::form;
782 my %myconfig = %main::myconfig;
783 my $locale = $main::locale;
785 $main::auth->assert('config');
787 AM->delete_language(\%myconfig, \%$form);
788 $form->redirect($locale->text('Language deleted!'));
790 $main::lxdebug->leave_sub();
794 sub add_buchungsgruppe {
795 $main::lxdebug->enter_sub();
797 my $form = $main::form;
798 my %myconfig = %main::myconfig;
799 my $locale = $main::locale;
801 $main::auth->assert('config');
803 # $locale->text("Add Buchungsgruppe")
804 # $locale->text("Edit Buchungsgruppe")
805 $form->{title} = "Add";
807 $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
809 AM->get_buchungsgruppe(\%myconfig, \%$form);
810 $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
811 for (my $i = 0; 4 > $i; $i++) {
812 map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
816 &buchungsgruppe_header;
819 $main::lxdebug->leave_sub();
822 sub edit_buchungsgruppe {
823 $main::lxdebug->enter_sub();
825 my $form = $main::form;
826 my %myconfig = %main::myconfig;
828 $main::auth->assert('config');
830 $form->{title} = "Edit";
832 AM->get_buchungsgruppe(\%myconfig, \%$form);
834 &buchungsgruppe_header;
838 $main::lxdebug->leave_sub();
841 sub list_buchungsgruppe {
842 $::lxdebug->enter_sub;
843 $::auth->assert('config');
845 AM->buchungsgruppe(\%::myconfig, $::form);
847 $::form->{callback} = "am.pl?action=list_buchungsgruppe";
848 $::form->{title} = $::locale->text('Buchungsgruppen');
851 print $::form->parse_html_template('am/buchungsgruppe_list', {
852 swap_link => qq|am.pl?action=swap_buchungsgruppen&|,
855 $::lxdebug->leave_sub;
858 sub buchungsgruppe_header {
859 $::lxdebug->enter_sub;
860 $::auth->assert('config');
862 # $locale->text('Add Accounting Group')
863 # $locale->text('Edit Accounting Group')
864 $::form->{title} = $::locale->text("$::form->{title} Buchungsgruppe");
866 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
868 IC => $acc_inventory,
869 IC_income => $acc_income,
870 IC_sale => $acc_income,
871 IC_expense => $acc_expense,
872 IC_cogs => $acc_expense,
875 for my $key (keys %acc_type_map) {
876 for my $ref (@{ $::form->{IC_links}{$key} }) {
877 $acc_type_map{$key}{$ref->{id}} = $ref;
881 my %sorted_accounts = map {
882 $_ => [ sort { $a->{accno} cmp $b->{accno} } values %{ $acc_type_map{$_} } ],
883 } keys %acc_type_map;
886 print $::form->parse_html_template('am/buchungsgruppe_header', {
887 accounts => \%sorted_accounts,
888 account_label => sub { "$_[0]{accno}--$_[0]{description}" },
891 $::lxdebug->leave_sub;
894 sub save_buchungsgruppe {
895 $main::lxdebug->enter_sub();
897 my $form = $main::form;
898 my %myconfig = %main::myconfig;
899 my $locale = $main::locale;
901 $main::auth->assert('config');
903 $form->isblank("description", $locale->text('Description missing!'));
905 AM->save_buchungsgruppe(\%myconfig, \%$form);
906 $form->redirect($locale->text('Accounting Group saved!'));
908 $main::lxdebug->leave_sub();
911 sub delete_buchungsgruppe {
912 $main::lxdebug->enter_sub();
914 my $form = $main::form;
915 my %myconfig = %main::myconfig;
916 my $locale = $main::locale;
918 $main::auth->assert('config');
920 AM->delete_buchungsgruppe(\%myconfig, \%$form);
921 $form->redirect($locale->text('Accounting Group deleted!'));
923 $main::lxdebug->leave_sub();
926 sub swap_buchungsgruppen {
927 $main::lxdebug->enter_sub();
929 my $form = $main::form;
930 my %myconfig = %main::myconfig;
932 $main::auth->assert('config');
934 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
935 list_buchungsgruppe();
937 $main::lxdebug->leave_sub();
940 sub _build_cfg_options {
941 my $form = $main::form;
942 my %myconfig = %main::myconfig;
945 my $array = uc($idx) . 'S';
947 $form->{$array} = [];
948 foreach my $item (@_) {
949 push @{ $form->{$array} }, {
952 'selected' => $item eq $myconfig{$idx},
958 $main::lxdebug->enter_sub();
960 my $form = $main::form;
961 my %myconfig = %main::myconfig;
962 my $locale = $main::locale;
964 _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
965 _build_cfg_options('timeformat', qw(hh:mm hh:mm:ss));
966 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
969 if ($::lx_office_conf{print_templates}->{opendocument}
970 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
971 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
972 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
973 "value" => "opendocument_pdf" });
975 if ($::lx_office_conf{print_templates}->{latex}) {
976 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
978 push(@formats, { "name" => "HTML", "value" => "html" });
979 if ($::lx_office_conf{print_templates}->{latex}) {
980 push(@formats, { "name" => $locale->text("Postscript"),
981 "value" => "postscript" });
983 if ($::lx_office_conf{print_templates}->{opendocument}) {
984 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
985 "value" => "opendocument" });
988 if (!$myconfig{"template_format"}) {
989 $myconfig{"template_format"} = "pdf";
991 $form->{TEMPLATE_FORMATS} = [];
992 foreach my $item (@formats) {
993 push @{ $form->{TEMPLATE_FORMATS} }, {
994 'name' => $item->{name},
995 'value' => $item->{value},
996 'selected' => $item->{value} eq $myconfig{template_format},
1000 if (!$myconfig{"default_media"}) {
1001 $myconfig{"default_media"} = "screen";
1004 my %selected = ($myconfig{"default_media"} => "selected");
1006 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
1007 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
1008 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
1011 $form->{PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
1013 my %countrycodes = User->country_codes;
1015 $form->{COUNTRYCODES} = [];
1016 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
1017 push @{ $form->{COUNTRYCODES} }, {
1018 'name' => $countrycodes{$countrycode},
1019 'value' => $countrycode,
1020 'selected' => $countrycode eq $myconfig{countrycode},
1024 $form->{STYLESHEETS} = [];
1025 foreach my $item (qw(lx-office-erp.css Mobile.css kivitendo.css)) {
1026 push @{ $form->{STYLESHEETS} }, {
1029 'selected' => $item eq $myconfig{stylesheet},
1033 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
1034 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
1035 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
1037 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
1040 print $form->parse_html_template('am/config');
1042 $main::lxdebug->leave_sub();
1045 sub save_preferences {
1046 $main::lxdebug->enter_sub();
1048 my $form = $main::form;
1049 my %myconfig = %main::myconfig;
1050 my $locale = $main::locale;
1052 $form->{stylesheet} = $form->{usestylesheet};
1054 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
1056 if (AM->save_preferences($form)) {
1057 if ($::auth->can_change_password()
1058 && defined $form->{new_password}
1059 && ($form->{new_password} ne '********')) {
1060 my $verifier = SL::Auth::PasswordPolicy->new;
1061 my $result = $verifier->verify($form->{new_password});
1063 if ($result != SL::Auth::PasswordPolicy->OK()) {
1064 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
1067 $::auth->change_password($form->{login}, $form->{new_password});
1070 $form->redirect($locale->text('Preferences saved!'));
1073 $form->error($locale->text('Cannot save preferences!'));
1075 $main::lxdebug->leave_sub();
1079 $::lxdebug->enter_sub;
1080 $::auth->assert('config');
1082 $::form->{title} = $::locale->text('Audit Control');
1084 AM->closedto(\%::myconfig, $::form);
1087 print $::form->parse_html_template('am/audit_control');
1089 $::lxdebug->leave_sub;
1093 $main::lxdebug->enter_sub();
1095 my $form = $main::form;
1096 my %myconfig = %main::myconfig;
1097 my $locale = $main::locale;
1099 $main::auth->assert('config');
1101 AM->closebooks(\%myconfig, \%$form);
1103 if ($form->{closedto}) {
1105 $locale->text('Books closed up to') . " "
1106 . $locale->date(\%myconfig, $form->{closedto}, 1));
1108 $form->redirect($locale->text('Books are open'));
1111 $main::lxdebug->leave_sub();
1115 $main::lxdebug->enter_sub();
1117 my $form = $main::form;
1118 my %myconfig = %main::myconfig;
1119 my $locale = $main::locale;
1121 $main::auth->assert('config');
1123 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1124 AM->units_in_use(\%myconfig, $form, $units);
1125 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1127 my @languages = AM->language(\%myconfig, $form, 1);
1129 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1132 foreach (@unit_list) {
1133 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1134 $_->{"UNITLANGUAGES"} = [];
1135 foreach my $lang (@languages) {
1136 push(@{ $_->{"UNITLANGUAGES"} },
1138 "unit" => $_->{"name"},
1139 "language_id" => $lang->{"id"},
1140 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1141 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1147 $units = AM->retrieve_units(\%myconfig, $form);
1148 my $ddbox = AM->unit_select_data($units, undef, 1);
1150 $form->{"title"} = $locale->text("Add and edit units");
1152 print($form->parse_html_template("am/edit_units",
1153 { "UNITS" => \@unit_list,
1154 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1155 "LANGUAGES" => \@languages,
1158 $main::lxdebug->leave_sub();
1162 $main::lxdebug->enter_sub();
1164 my $form = $main::form;
1165 my %myconfig = %main::myconfig;
1166 my $locale = $main::locale;
1168 $main::auth->assert('config');
1170 $form->isblank("new_name", $locale->text("The name is missing."));
1171 my $units = AM->retrieve_units(\%myconfig, $form);
1172 my $all_units = AM->retrieve_units(\%myconfig, $form);
1173 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1175 my ($base_unit, $factor);
1176 if ($form->{"new_base_unit"}) {
1177 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1179 $form->isblank("new_factor", $locale->text("The factor is missing."));
1180 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1181 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1182 $base_unit = $form->{"new_base_unit"};
1186 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1187 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1188 push(@languages, { "id" => $lang->{"id"},
1189 "localized" => $form->{"new_localized_$lang->{id}"},
1190 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1194 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1196 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1200 $main::lxdebug->leave_sub();
1203 sub set_unit_languages {
1204 $main::lxdebug->enter_sub();
1206 my $form = $main::form;
1208 $main::auth->assert('config');
1210 my ($unit, $languages, $idx) = @_;
1212 $unit->{"LANGUAGES"} = [];
1214 foreach my $lang (@{$languages}) {
1215 push(@{ $unit->{"LANGUAGES"} },
1216 { "id" => $lang->{"id"},
1217 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1218 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1222 $main::lxdebug->leave_sub();
1226 $main::lxdebug->enter_sub();
1228 my $form = $main::form;
1229 my %myconfig = %main::myconfig;
1230 my $locale = $main::locale;
1232 $main::auth->assert('config');
1234 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1235 AM->units_in_use(\%myconfig, $form, $old_units);
1237 my @languages = AM->language(\%myconfig, $form, 1);
1240 my @delete_units = ();
1241 foreach my $i (1..($form->{"rowcount"} * 1)) {
1242 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1244 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1247 if ($form->{"unchangeable_$i"}) {
1248 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1249 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1250 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1254 if ($old_unit->{"in_use"}) {
1255 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1258 if ($form->{"delete_$i"}) {
1259 push(@delete_units, $old_unit->{"name"});
1263 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1265 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1266 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1267 $new_units->{$form->{"name_$i"}} = \%h;
1268 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1269 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1272 foreach my $unit (values(%{$new_units})) {
1273 next unless ($unit->{"old_name"});
1274 if ($unit->{"base_unit"}) {
1275 $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"}))
1276 unless (defined($new_units->{$unit->{"base_unit"}}));
1277 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1278 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1280 $unit->{"base_unit"} = undef;
1281 $unit->{"factor"} = undef;
1285 foreach my $unit (values(%{$new_units})) {
1286 next if ($unit->{"unchanged_unit"});
1288 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1289 my $new_unit = $unit;
1290 while ($new_unit->{"base_unit"}) {
1291 $new_unit->{"seen"} = 1;
1292 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1293 if ($new_unit->{"seen"}) {
1294 $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, " .
1295 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1300 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1302 $form->{"saved_message"} = $locale->text("The units have been saved.");
1306 $main::lxdebug->leave_sub();
1309 sub show_history_search {
1310 $main::lxdebug->enter_sub();
1312 my $form = $main::form;
1313 my $locale = $main::locale;
1315 $main::auth->assert('config');
1317 $form->{title} = $locale->text("History Search");
1320 print $form->parse_html_template("common/search_history");
1322 $main::lxdebug->leave_sub();
1325 sub show_am_history {
1326 $main::lxdebug->enter_sub();
1328 my $form = $main::form;
1329 my %myconfig = %main::myconfig;
1330 my $locale = $main::locale;
1332 $main::auth->assert('config');
1334 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1335 $form->{order} ||= 'h.itime--1';
1337 my %search = ( "Artikelnummer" => "parts",
1338 "Kundennummer" => "customer",
1339 "Lieferantennummer" => "vendor",
1340 "Projektnummer" => "project",
1341 "Buchungsnummer" => "oe",
1342 "Eingangsrechnungnummer" => "ap",
1343 "Ausgangsrechnungnummer" => "ar",
1344 "Mahnungsnummer" => "dunning"
1346 my %searchNo = ( "Artikelnummer" => "partnumber",
1347 "Kundennummer" => "customernumber",
1348 "Lieferantennummer" => "vendornumber",
1349 "Projektnummer" => "projectnumber",
1350 "Buchungsnummer" => "ordnumber",
1351 "Eingangsrechnungnummer" => "invnumber",
1352 "Ausgangsrechnungnummer" => "invnumber",
1353 "Mahnungsnummer" => "dunning_id"
1356 my $dbh = $form->dbconnect(\%myconfig);
1359 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1360 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1361 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1362 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1363 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1364 } elsif ($form->{mitarbeiter}) {
1365 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1368 my $query = qq|SELECT trans_id AS id FROM history_erp | .
1369 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
1370 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
1372 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
1373 my $daten .= shift @ids;
1374 $daten .= join '', map { " OR trans_id = $_" } @ids;
1376 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1377 $sort =~ s/.*\.(.*)$/$1/;
1379 $form->{title} = $locale->text("History Search");
1382 print $form->parse_html_template("common/show_history",
1383 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1384 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1387 uc($sort) . "BY" => $sortby,
1388 'callback' => $callback,
1392 $main::lxdebug->leave_sub();
1396 $main::lxdebug->enter_sub();
1398 my $form = $main::form;
1399 my $locale = $main::locale;
1401 $main::auth->assert('config');
1403 $form->{title} = $locale->text('Add');
1405 $form->{callback} ||= "am.pl?action=add_tax";
1407 _get_taxaccount_selection();
1410 $form->{liability} = 1;
1411 $form->{equity} = 1;
1412 $form->{revenue} = 1;
1413 $form->{expense} = 1;
1418 my $parameters_ref = {
1419 # ChartTypeIsAccount => $ChartTypeIsAccount,
1420 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1423 # Ausgabe des Templates
1424 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1426 $main::lxdebug->leave_sub();
1430 $main::lxdebug->enter_sub();
1432 my $form = $main::form;
1433 my %myconfig = %main::myconfig;
1434 my $locale = $main::locale;
1436 $main::auth->assert('config');
1438 $form->{title} = $locale->text('Edit');
1440 AM->get_tax(\%myconfig, \%$form);
1442 _get_taxaccount_selection();
1444 $form->{asset} = $form->{chart_categories} =~ 'A' ? 1 : 0;
1445 $form->{liability} = $form->{chart_categories} =~ 'L' ? 1 : 0;
1446 $form->{equity} = $form->{chart_categories} =~ 'Q' ? 1 : 0;
1447 $form->{revenue} = $form->{chart_categories} =~ 'I' ? 1 : 0;
1448 $form->{expense} = $form->{chart_categories} =~ 'E' ? 1 : 0;
1449 $form->{costs} = $form->{chart_categories} =~ 'C' ? 1 : 0;
1451 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1455 my $parameters_ref = {
1456 LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
1457 TAX => SL::DB::Manager::Tax->find_by(id => $form->{id}),
1460 # Ausgabe des Templates
1461 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1463 $main::lxdebug->leave_sub();
1467 $main::lxdebug->enter_sub();
1469 my $form = $main::form;
1470 my %myconfig = %main::myconfig;
1471 my $locale = $main::locale;
1473 $main::auth->assert('config');
1475 AM->taxes(\%myconfig, \%$form);
1477 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1479 $form->{callback} = build_std_url('action=list_tax');
1481 $form->{title} = $locale->text('Tax-O-Matic');
1485 my $parameters_ref = {
1488 # Ausgabe des Templates
1489 print($form->parse_html_template('am/list_tax', $parameters_ref));
1491 $main::lxdebug->leave_sub();
1494 sub _get_taxaccount_selection{
1495 $main::lxdebug->enter_sub();
1497 my $form = $main::form;
1498 my %myconfig = %main::myconfig;
1500 $main::auth->assert('config');
1502 AM->get_tax_accounts(\%myconfig, \%$form);
1504 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1506 $main::lxdebug->leave_sub();
1510 $main::lxdebug->enter_sub();
1512 my $form = $main::form;
1513 my %myconfig = %main::myconfig;
1514 my $locale = $main::locale;
1516 $main::auth->assert('config');
1518 $form->error($locale->text('Taxkey missing!')) unless length($form->{taxkey}) != 0;
1519 $form->error($locale->text('Taxdescription missing!')) unless length($form->{taxdescription}) != 0;
1520 $form->error($locale->text('Taxrate missing!')) unless length($form->{rate}) != 0;
1522 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1524 if ($form->{taxkey} == 0 and $form->{rate} > 0) {
1525 $form->error($locale->text('Taxkey 0 is reserved for rate 0'));
1528 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1529 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1532 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
1533 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1536 my @translation_keys = grep { $_ =~ '^translation_\d+' } keys %$form;
1537 $form->{translations} = { map { $_ =~ '^translation_(\d+)'; $1 => $form->{$_} } @translation_keys };
1539 AM->save_tax(\%myconfig, \%$form);
1540 $form->redirect($locale->text('Tax saved!'));
1542 $main::lxdebug->leave_sub();
1546 $main::lxdebug->enter_sub();
1548 my $form = $main::form;
1549 my %myconfig = %main::myconfig;
1550 my $locale = $main::locale;
1552 $main::auth->assert('config');
1554 AM->delete_tax(\%myconfig, \%$form);
1555 $form->redirect($locale->text('Tax deleted!'));
1557 $main::lxdebug->leave_sub();
1560 sub add_price_factor {
1561 $main::lxdebug->enter_sub();
1563 my $form = $main::form;
1564 my $locale = $main::locale;
1566 $main::auth->assert('config');
1568 $form->{title} = $locale->text('Add Price Factor');
1569 $form->{callback} ||= build_std_url('action=add_price_factor');
1572 print $form->parse_html_template('am/edit_price_factor');
1574 $main::lxdebug->leave_sub();
1577 sub edit_price_factor {
1578 $main::lxdebug->enter_sub();
1580 my $form = $main::form;
1581 my %myconfig = %main::myconfig;
1582 my $locale = $main::locale;
1584 $main::auth->assert('config');
1586 $form->{title} = $locale->text('Edit Price Factor');
1587 $form->{callback} ||= build_std_url('action=add_price_factor');
1589 AM->get_price_factor(\%myconfig, $form);
1591 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
1594 print $form->parse_html_template('am/edit_price_factor');
1596 $main::lxdebug->leave_sub();
1599 sub list_price_factors {
1600 $main::lxdebug->enter_sub();
1602 my $form = $main::form;
1603 my %myconfig = %main::myconfig;
1604 my $locale = $main::locale;
1606 $main::auth->assert('config');
1608 AM->get_all_price_factors(\%myconfig, \%$form);
1610 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
1611 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
1614 $form->{callback} = build_std_url('action=list_price_factors');
1615 $form->{title} = $locale->text('Price Factors');
1616 $form->{url_base} = build_std_url('callback');
1619 print $form->parse_html_template('am/list_price_factors');
1621 $main::lxdebug->leave_sub();
1624 sub save_price_factor {
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 $form->isblank("description", $locale->text('Description missing!'));
1634 $form->isblank("factor", $locale->text('Factor missing!'));
1636 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
1638 AM->save_price_factor(\%myconfig, $form);
1640 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
1642 $form->redirect($locale->text('Price factor saved!'));
1644 $main::lxdebug->leave_sub();
1647 sub delete_price_factor {
1648 $main::lxdebug->enter_sub();
1650 my $form = $main::form;
1651 my %myconfig = %main::myconfig;
1652 my $locale = $main::locale;
1654 $main::auth->assert('config');
1656 AM->delete_price_factor(\%myconfig, \%$form);
1658 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
1660 $form->redirect($locale->text('Price factor deleted!'));
1662 $main::lxdebug->leave_sub();
1666 $main::lxdebug->enter_sub();
1668 my $form = $main::form;
1669 my $locale = $main::locale;
1671 $main::auth->assert('config');
1673 $form->{title} = $locale->text('Add Warehouse');
1674 $form->{callback} ||= build_std_url('action=add_warehouse');
1677 print $form->parse_html_template('am/edit_warehouse');
1679 $main::lxdebug->leave_sub();
1682 sub edit_warehouse {
1683 $main::lxdebug->enter_sub();
1685 my $form = $main::form;
1686 my %myconfig = %main::myconfig;
1687 my $locale = $main::locale;
1689 $main::auth->assert('config');
1691 AM->get_warehouse(\%myconfig, $form);
1693 $form->get_lists('employees' => 'EMPLOYEES');
1695 $form->{title} = $locale->text('Edit Warehouse');
1696 $form->{callback} ||= build_std_url('action=list_warehouses');
1699 print $form->parse_html_template('am/edit_warehouse');
1701 $main::lxdebug->leave_sub();
1704 sub list_warehouses {
1705 $main::lxdebug->enter_sub();
1707 my $form = $main::form;
1708 my %myconfig = %main::myconfig;
1709 my $locale = $main::locale;
1711 $main::auth->assert('config');
1713 AM->get_all_warehouses(\%myconfig, $form);
1715 $form->{callback} = build_std_url('action=list_warehouses');
1716 $form->{title} = $locale->text('Warehouses');
1717 $form->{url_base} = build_std_url('callback');
1720 print $form->parse_html_template('am/list_warehouses');
1722 $main::lxdebug->leave_sub();
1725 sub save_warehouse {
1726 $main::lxdebug->enter_sub();
1728 my $form = $main::form;
1729 my %myconfig = %main::myconfig;
1730 my $locale = $main::locale;
1732 $main::auth->assert('config');
1734 $form->isblank("description", $locale->text('Description missing!'));
1736 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
1738 AM->save_warehouse(\%myconfig, $form);
1740 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
1742 $form->redirect($locale->text('Warehouse saved.'));
1744 $main::lxdebug->leave_sub();
1747 sub delete_warehouse {
1748 $main::lxdebug->enter_sub();
1750 my $form = $main::form;
1751 my %myconfig = %main::myconfig;
1752 my $locale = $main::locale;
1754 $main::auth->assert('config');
1756 if (!$form->{confirmed}) {
1757 $form->{title} = $locale->text('Confirmation');
1760 print $form->parse_html_template('am/confirm_delete_warehouse');
1764 if (AM->delete_warehouse(\%myconfig, $form)) {
1765 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
1766 $form->redirect($locale->text('Warehouse deleted.'));
1769 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
1772 $main::lxdebug->leave_sub();
1776 $main::lxdebug->enter_sub();
1778 my $form = $main::form;
1779 my %myconfig = %main::myconfig;
1780 my $locale = $main::locale;
1782 $main::auth->assert('config');
1784 AM->save_bins(\%myconfig, $form);
1786 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
1788 $form->redirect($locale->text('Bins saved.'));
1790 $main::lxdebug->leave_sub();