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 $form->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 mm/dd/yy dd-mm-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 $main::lxdebug->enter_sub();
835 my $form = $main::form;
836 my %myconfig = %main::myconfig;
837 my $locale = $main::locale;
839 $main::auth->assert('config');
841 AM->buchungsgruppe(\%myconfig, \%$form);
843 $form->{callback} = "am.pl?action=list_buchungsgruppe";
845 my $callback = $form->escape($form->{callback});
847 $form->{title} = $locale->text('Buchungsgruppen');
849 my @column_index = qw(up down description inventory_accno
850 income_accno_0 expense_accno_0
851 income_accno_1 expense_accno_1
852 income_accno_2 expense_accno_2
853 income_accno_3 expense_accno_3 );
856 qq|<th class="listheading" width="16">|
857 . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
859 $column_header{down} =
860 qq|<th class="listheading" width="16">|
861 . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
863 $column_header{description} =
864 qq|<th class="listheading" width="40%">|
865 . $locale->text('Description')
867 $column_header{inventory_accno} =
868 qq|<th class=listheading>|
869 . $locale->text('Bestandskonto')
871 $column_header{income_accno_0} =
872 qq|<th class=listheading>|
873 . $locale->text('National Revenues')
875 $column_header{expense_accno_0} =
876 qq|<th class=listheading>|
877 . $locale->text('National Expenses')
879 $column_header{income_accno_1} =
880 qq|<th class=listheading>|
881 . $locale->text('Revenues EU with UStId')
883 $column_header{expense_accno_1} =
884 qq|<th class=listheading>|
885 . $locale->text('Expenses EU with UStId')
887 $column_header{income_accno_2} =
888 qq|<th class=listheading>|
889 . $locale->text('Revenues EU without UStId')
891 $column_header{expense_accno_2} =
892 qq|<th class=listheading>|
893 . $locale->text('Expenses EU without UStId')
895 $column_header{income_accno_3} =
896 qq|<th class=listheading>|
897 . $locale->text('Foreign Revenues')
899 $column_header{expense_accno_3} =
900 qq|<th class=listheading>|
901 . $locale->text('Foreign Expenses')
910 <th class=listtop>$form->{title}</th>
916 <tr class=listheading>
919 map { print "$column_header{$_}\n" } @column_index;
925 my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
928 my ($i, %column_data);
929 foreach my $ref (@{ $form->{ALL} }) {
935 <tr valign=top class=listrow$i>
939 my $pref = $form->{ALL}->[$row - 1];
941 qq|<td align="center" valign="center" width="16">| .
942 qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
943 qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
946 $column_data{up} = qq|<td width="16"> </td>|;
949 if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
950 $column_data{down} = qq|<td width="16"> </td>|;
952 my $nref = $form->{ALL}->[$row + 1];
954 qq|<td align="center" valign="center" width="16">| .
955 qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
956 qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
960 $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
961 $column_data{inventory_accno} = qq|<td align=right>$ref->{inventory_accno}</td>|;
962 $column_data{income_accno_0} =
963 qq|<td align=right>$ref->{income_accno_0}</td>|;
964 $column_data{expense_accno_0} = qq|<td align=right>$ref->{expense_accno_0}</td>|;
965 $column_data{income_accno_1} =
966 qq|<td align=right>$ref->{income_accno_1}</td>|;
967 $column_data{expense_accno_1} = qq|<td align=right>$ref->{expense_accno_1}</td>|;
968 $column_data{income_accno_2} =
969 qq|<td align=right>$ref->{income_accno_2}</td>|;
970 $column_data{expense_accno_2} = qq|<td align=right>$ref->{expense_accno_2}</td>|;
971 $column_data{income_accno_3} =
972 qq|<td align=right>$ref->{income_accno_3}</td>|;
973 $column_data{expense_accno_3} = qq|<td align=right>$ref->{expense_accno_3}</td>|;
975 map { print "$column_data{$_}\n" } @column_index;
989 <td><hr size=3 noshade></td>
994 <form method=post action=am.pl>
996 <input name=callback type=hidden value="$form->{callback}">
998 <input type=hidden name=type value=buchungsgruppe>
1000 <input class=submit type=submit name=action value="|
1001 . $locale->text('Add') . qq|">
1009 $main::lxdebug->leave_sub();
1012 sub buchungsgruppe_header {
1013 $main::lxdebug->enter_sub();
1015 my $form = $main::form;
1016 my $locale = $main::locale;
1018 $main::auth->assert('config');
1020 $form->{title} = $locale->text("$form->{title} Buchungsgruppe");
1022 # $locale->text('Add Accounting Group')
1023 # $locale->text('Edit Accounting Group')
1025 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
1026 my %acc_type_map = (
1027 "IC" => $acc_inventory,
1028 "IC_income" => $acc_income,
1029 "IC_sale" => $acc_income,
1030 "IC_expense" => $acc_expense,
1031 "IC_cogs" => $acc_expense,
1034 foreach my $key (keys(%acc_type_map)) {
1035 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1036 $acc_type_map{$key}->{$ref->{"id"}} = $ref;
1040 foreach my $type (qw(IC IC_income IC_expense)) {
1041 $form->{"select$type"} =
1043 map({ "<option value=$_->{id} $_->{selected}>" .
1044 "$_->{accno}--" . H($_->{description}) . "</option>" }
1045 sort({ $a->{"accno"} cmp $b->{"accno"} }
1046 values(%{$acc_type_map{$type}}))));
1050 $form->{selectIC} =~ s/selected//g;
1051 $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/ value=$form->{inventory_accno_id} selected/;
1052 $form->{selectIC_income} =~ s/selected//g;
1053 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/ value=$form->{income_accno_id_0} selected/;
1054 $form->{selectIC_expense} =~ s/selected//g;
1055 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/ value=$form->{expense_accno_id_0} selected/;
1059 if ( $::instance_conf->get_inventory_system eq 'perpetual' ) { # was !$::lx_office_conf{system}->{eur}) { }
1062 <th align=right>| . $locale->text('Inventory') . qq|</th>
1063 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
1064 <input name=selectIC type=hidden value="$form->{selectIC}">
1066 } elsif ( $::instance_conf->get_inventory_system eq 'periodic' ) {
1067 # don't allow choice of inventory accno and don't show that line
1069 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
1073 $linkaccounts .= qq|
1075 <th align=right>| . $locale->text('National Revenues') . qq|</th>
1076 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
1079 <th align=right>| . $locale->text('National Expenses') . qq|</th>
1080 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
1083 $form->{selectIC_income} =~ s/selected//g;
1084 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/ value=$form->{income_accno_id_1} selected/;
1085 $form->{selectIC_expense} =~ s/selected//g;
1086 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/ value=$form->{expense_accno_id_1} selected/;
1088 $linkaccounts .= qq| <tr>
1089 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
1090 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
1093 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
1094 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
1098 $form->{selectIC_income} =~ s/selected//g;
1099 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/ value=$form->{income_accno_id_2} selected/;
1100 $form->{selectIC_expense} =~ s/selected//g;
1101 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/ value=$form->{expense_accno_id_2} selected/;
1104 $linkaccounts .= qq| <tr>
1105 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
1106 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
1109 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
1110 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
1114 $form->{selectIC_income} =~ s/selected//g;
1115 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/ value=$form->{income_accno_id_3} selected/;
1116 $form->{selectIC_expense} =~ s/selected//g;
1117 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/ value=$form->{expense_accno_id_3} selected/;
1120 $linkaccounts .= qq| <tr>
1121 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
1122 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
1125 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
1126 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
1136 <form method=post action=am.pl>
1138 <input type=hidden name=id value=$form->{id}>
1139 <input type=hidden name=type value=buchungsgruppe>
1143 <th class=listtop colspan=2>$form->{title}</th>
1145 <tr height="5"></tr>
1147 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
1148 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1151 <td colspan=2><hr size=3 noshade></td>
1156 $main::lxdebug->leave_sub();
1159 sub save_buchungsgruppe {
1160 $main::lxdebug->enter_sub();
1162 my $form = $main::form;
1163 my %myconfig = %main::myconfig;
1164 my $locale = $main::locale;
1166 $main::auth->assert('config');
1168 $form->isblank("description", $locale->text('Description missing!'));
1170 AM->save_buchungsgruppe(\%myconfig, \%$form);
1171 $form->redirect($locale->text('Accounting Group saved!'));
1173 $main::lxdebug->leave_sub();
1176 sub delete_buchungsgruppe {
1177 $main::lxdebug->enter_sub();
1179 my $form = $main::form;
1180 my %myconfig = %main::myconfig;
1181 my $locale = $main::locale;
1183 $main::auth->assert('config');
1185 AM->delete_buchungsgruppe(\%myconfig, \%$form);
1186 $form->redirect($locale->text('Accounting Group deleted!'));
1188 $main::lxdebug->leave_sub();
1191 sub swap_buchungsgruppen {
1192 $main::lxdebug->enter_sub();
1194 my $form = $main::form;
1195 my %myconfig = %main::myconfig;
1197 $main::auth->assert('config');
1199 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
1200 list_buchungsgruppe();
1202 $main::lxdebug->leave_sub();
1206 $main::lxdebug->enter_sub();
1208 my $form = $main::form;
1209 my %myconfig = %main::myconfig;
1210 my $locale = $main::locale;
1212 # get defaults for account numbers and last numbers
1213 AM->defaultaccounts(\%myconfig, \%$form);
1214 $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
1216 map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
1219 my $all_languages = SL::DB::Manager::Language->get_all;
1221 # EÜR = cash, Bilanzierung = accrual
1223 foreach my $key (keys %{ $form->{IC} }) {
1224 foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
1225 my $array = "ACCNOS_" . uc($key);
1226 $form->{$array} ||= [];
1228 my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
1229 push @{ $form->{$array} }, {
1232 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
1237 $form->{title} = $locale->text('Ranges of numbers and default accounts');
1240 print $form->parse_html_template('am/edit_defaults',
1241 { ALL_LANGUAGES => $all_languages, });
1243 $main::lxdebug->leave_sub();
1247 $main::lxdebug->enter_sub();
1249 my $form = $main::form;
1250 my $locale = $main::locale;
1252 AM->save_defaults();
1254 $form->redirect($locale->text('Defaults saved.'));
1256 $main::lxdebug->leave_sub();
1259 sub _build_cfg_options {
1260 my $form = $main::form;
1261 my %myconfig = %main::myconfig;
1264 my $array = uc($idx) . 'S';
1266 $form->{$array} = [];
1267 foreach my $item (@_) {
1268 push @{ $form->{$array} }, {
1271 'selected' => $item eq $myconfig{$idx},
1277 $main::lxdebug->enter_sub();
1279 my $form = $main::form;
1280 my %myconfig = %main::myconfig;
1281 my $locale = $main::locale;
1283 _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
1284 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
1287 if ($::lx_office_conf{print_templates}->{opendocument}
1288 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
1289 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
1290 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
1291 "value" => "opendocument_pdf" });
1293 if ($::lx_office_conf{print_templates}->{latex}) {
1294 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
1296 push(@formats, { "name" => "HTML", "value" => "html" });
1297 if ($::lx_office_conf{print_templates}->{latex}) {
1298 push(@formats, { "name" => $locale->text("Postscript"),
1299 "value" => "postscript" });
1301 if ($::lx_office_conf{print_templates}->{opendocument}) {
1302 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
1303 "value" => "opendocument" });
1306 if (!$myconfig{"template_format"}) {
1307 $myconfig{"template_format"} = "pdf";
1309 $form->{TEMPLATE_FORMATS} = [];
1310 foreach my $item (@formats) {
1311 push @{ $form->{TEMPLATE_FORMATS} }, {
1312 'name' => $item->{name},
1313 'value' => $item->{value},
1314 'selected' => $item->{value} eq $myconfig{template_format},
1318 if (!$myconfig{"default_media"}) {
1319 $myconfig{"default_media"} = "screen";
1322 my %selected = ($myconfig{"default_media"} => "selected");
1324 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
1325 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
1326 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
1329 $form->{PRINTERS} = [ SL::Printer->all_printers(%::myconfig) ];
1331 my %countrycodes = User->country_codes;
1333 $form->{COUNTRYCODES} = [];
1334 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
1335 push @{ $form->{COUNTRYCODES} }, {
1336 'name' => $countrycodes{$countrycode},
1337 'value' => $countrycode,
1338 'selected' => $countrycode eq $myconfig{countrycode},
1342 $form->{STYLESHEETS} = [];
1343 foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
1344 push @{ $form->{STYLESHEETS} }, {
1347 'selected' => $item eq $myconfig{stylesheet},
1351 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
1352 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
1353 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
1355 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
1358 print $form->parse_html_template('am/config');
1360 $main::lxdebug->leave_sub();
1363 sub save_preferences {
1364 $main::lxdebug->enter_sub();
1366 my $form = $main::form;
1367 my %myconfig = %main::myconfig;
1368 my $locale = $main::locale;
1370 $form->{stylesheet} = $form->{usestylesheet};
1372 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
1374 if (AM->save_preferences(\%myconfig, $form)) {
1375 if ($::auth->can_change_password()
1376 && defined $form->{new_password}
1377 && ($form->{new_password} ne '********')) {
1378 my $verifier = SL::Auth::PasswordPolicy->new;
1379 my $result = $verifier->verify($form->{new_password});
1381 if ($result != SL::Auth::PasswordPolicy->OK()) {
1382 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
1385 $::auth->change_password($form->{login}, $form->{new_password});
1387 $form->{password} = $form->{new_password};
1388 $::auth->set_session_value('password', $form->{password});
1389 $::auth->create_or_refresh_session();
1392 $form->redirect($locale->text('Preferences saved!'));
1395 $form->error($locale->text('Cannot save preferences!'));
1397 $main::lxdebug->leave_sub();
1401 $main::lxdebug->enter_sub();
1403 my $form = $main::form;
1404 my %myconfig = %main::myconfig;
1405 my $locale = $main::locale;
1407 $main::auth->assert('config');
1409 $form->{title} = $locale->text('Audit Control');
1411 AM->closedto(\%myconfig, \%$form);
1418 <form method=post action=am.pl>
1421 <tr><th class=listtop>$form->{title}</th></tr>
1422 <tr height="5"></tr>
1427 <th>| . $locale->text('Close Books up to') . qq|</th>
1428 <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
1438 <input type=hidden name=nextsub value=doclose>
1440 <input type=submit class=submit name=action value="|
1441 . $locale->text('Continue') . qq|">
1449 $main::lxdebug->leave_sub();
1453 $main::lxdebug->enter_sub();
1455 my $form = $main::form;
1456 my %myconfig = %main::myconfig;
1457 my $locale = $main::locale;
1459 $main::auth->assert('config');
1461 AM->closebooks(\%myconfig, \%$form);
1463 if ($form->{closedto}) {
1465 $locale->text('Books closed up to') . " "
1466 . $locale->date(\%myconfig, $form->{closedto}, 1));
1468 $form->redirect($locale->text('Books are open'));
1471 $main::lxdebug->leave_sub();
1475 $main::lxdebug->enter_sub();
1477 my $form = $main::form;
1478 my %myconfig = %main::myconfig;
1479 my $locale = $main::locale;
1481 $main::auth->assert('config');
1483 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1484 AM->units_in_use(\%myconfig, $form, $units);
1485 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1487 my @languages = AM->language(\%myconfig, $form, 1);
1489 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1492 foreach (@unit_list) {
1493 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1494 $_->{"UNITLANGUAGES"} = [];
1495 foreach my $lang (@languages) {
1496 push(@{ $_->{"UNITLANGUAGES"} },
1498 "unit" => $_->{"name"},
1499 "language_id" => $lang->{"id"},
1500 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1501 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1507 $units = AM->retrieve_units(\%myconfig, $form);
1508 my $ddbox = AM->unit_select_data($units, undef, 1);
1510 $form->{"title"} = $locale->text("Add and edit units");
1512 print($form->parse_html_template("am/edit_units",
1513 { "UNITS" => \@unit_list,
1514 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1515 "LANGUAGES" => \@languages,
1518 $main::lxdebug->leave_sub();
1522 $main::lxdebug->enter_sub();
1524 my $form = $main::form;
1525 my %myconfig = %main::myconfig;
1526 my $locale = $main::locale;
1528 $main::auth->assert('config');
1530 $form->isblank("new_name", $locale->text("The name is missing."));
1531 my $units = AM->retrieve_units(\%myconfig, $form);
1532 my $all_units = AM->retrieve_units(\%myconfig, $form);
1533 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1535 my ($base_unit, $factor);
1536 if ($form->{"new_base_unit"}) {
1537 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1539 $form->isblank("new_factor", $locale->text("The factor is missing."));
1540 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1541 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1542 $base_unit = $form->{"new_base_unit"};
1546 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1547 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1548 push(@languages, { "id" => $lang->{"id"},
1549 "localized" => $form->{"new_localized_$lang->{id}"},
1550 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1554 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1556 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1560 $main::lxdebug->leave_sub();
1563 sub set_unit_languages {
1564 $main::lxdebug->enter_sub();
1566 my $form = $main::form;
1568 $main::auth->assert('config');
1570 my ($unit, $languages, $idx) = @_;
1572 $unit->{"LANGUAGES"} = [];
1574 foreach my $lang (@{$languages}) {
1575 push(@{ $unit->{"LANGUAGES"} },
1576 { "id" => $lang->{"id"},
1577 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1578 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1582 $main::lxdebug->leave_sub();
1586 $main::lxdebug->enter_sub();
1588 my $form = $main::form;
1589 my %myconfig = %main::myconfig;
1590 my $locale = $main::locale;
1592 $main::auth->assert('config');
1594 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1595 AM->units_in_use(\%myconfig, $form, $old_units);
1597 my @languages = AM->language(\%myconfig, $form, 1);
1600 my @delete_units = ();
1601 foreach my $i (1..($form->{"rowcount"} * 1)) {
1602 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1604 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1607 if ($form->{"unchangeable_$i"}) {
1608 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1609 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1610 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1614 if ($old_unit->{"in_use"}) {
1615 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1618 if ($form->{"delete_$i"}) {
1619 push(@delete_units, $old_unit->{"name"});
1623 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1625 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1626 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1627 $new_units->{$form->{"name_$i"}} = \%h;
1628 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1629 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1632 foreach my $unit (values(%{$new_units})) {
1633 next unless ($unit->{"old_name"});
1634 if ($unit->{"base_unit"}) {
1635 $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"}))
1636 unless (defined($new_units->{$unit->{"base_unit"}}));
1637 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1638 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1640 $unit->{"base_unit"} = undef;
1641 $unit->{"factor"} = undef;
1645 foreach my $unit (values(%{$new_units})) {
1646 next if ($unit->{"unchanged_unit"});
1648 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1649 my $new_unit = $unit;
1650 while ($new_unit->{"base_unit"}) {
1651 $new_unit->{"seen"} = 1;
1652 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1653 if ($new_unit->{"seen"}) {
1654 $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, " .
1655 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1660 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1662 $form->{"saved_message"} = $locale->text("The units have been saved.");
1666 $main::lxdebug->leave_sub();
1669 sub show_history_search {
1670 $main::lxdebug->enter_sub();
1672 my $form = $main::form;
1673 my $locale = $main::locale;
1675 $main::auth->assert('config');
1677 $form->{title} = $locale->text("History Search");
1680 print $form->parse_html_template("common/search_history");
1682 $main::lxdebug->leave_sub();
1685 sub show_am_history {
1686 $main::lxdebug->enter_sub();
1688 my $form = $main::form;
1689 my %myconfig = %main::myconfig;
1690 my $locale = $main::locale;
1692 $main::auth->assert('config');
1694 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1695 $form->{order} ||= 'h.itime--1';
1697 my %search = ( "Artikelnummer" => "parts",
1698 "Kundennummer" => "customer",
1699 "Lieferantennummer" => "vendor",
1700 "Projektnummer" => "project",
1701 "Buchungsnummer" => "oe",
1702 "Eingangsrechnungnummer" => "ap",
1703 "Ausgangsrechnungnummer" => "ar",
1704 "Mahnungsnummer" => "dunning"
1706 my %searchNo = ( "Artikelnummer" => "partnumber",
1707 "Kundennummer" => "customernumber",
1708 "Lieferantennummer" => "vendornumber",
1709 "Projektnummer" => "projectnumber",
1710 "Buchungsnummer" => "ordnumber",
1711 "Eingangsrechnungnummer" => "invnumber",
1712 "Ausgangsrechnungnummer" => "invnumber",
1713 "Mahnungsnummer" => "dunning_id"
1716 my $dbh = $form->dbconnect(\%myconfig);
1719 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1720 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1721 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1722 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1723 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1724 } elsif ($form->{mitarbeiter}) {
1725 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1728 my $query = qq|SELECT trans_id AS id FROM history_erp | .
1729 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
1730 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
1732 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
1733 my $daten .= shift @ids;
1734 $daten .= join '', map { " OR trans_id = $_" } @ids;
1736 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1737 $sort =~ s/.*\.(.*)$/$1/;
1739 $form->{title} = $locale->text("History Search");
1742 print $form->parse_html_template("common/show_history",
1743 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1744 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1747 uc($sort) . "BY" => $sortby,
1748 'callback' => $callback,
1752 $main::lxdebug->leave_sub();
1756 $main::lxdebug->enter_sub();
1758 my $form = $main::form;
1759 my $locale = $main::locale;
1761 $main::auth->assert('config');
1763 $form->{title} = $locale->text('Add');
1765 $form->{callback} ||= "am.pl?action=add_tax";
1767 _get_taxaccount_selection();
1771 my $parameters_ref = {
1772 # ChartTypeIsAccount => $ChartTypeIsAccount,
1775 # Ausgabe des Templates
1776 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1778 $main::lxdebug->leave_sub();
1782 $main::lxdebug->enter_sub();
1784 my $form = $main::form;
1785 my %myconfig = %main::myconfig;
1786 my $locale = $main::locale;
1788 $main::auth->assert('config');
1790 $form->{title} = $locale->text('Edit');
1792 AM->get_tax(\%myconfig, \%$form);
1793 _get_taxaccount_selection();
1795 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1799 my $parameters_ref = {
1802 # Ausgabe des Templates
1803 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1805 $main::lxdebug->leave_sub();
1809 $main::lxdebug->enter_sub();
1811 my $form = $main::form;
1812 my %myconfig = %main::myconfig;
1813 my $locale = $main::locale;
1815 $main::auth->assert('config');
1817 AM->taxes(\%myconfig, \%$form);
1819 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1821 $form->{callback} = build_std_url('action=list_tax');
1823 $form->{title} = $locale->text('Tax-O-Matic');
1827 my $parameters_ref = {
1830 # Ausgabe des Templates
1831 print($form->parse_html_template('am/list_tax', $parameters_ref));
1833 $main::lxdebug->leave_sub();
1836 sub _get_taxaccount_selection{
1837 $main::lxdebug->enter_sub();
1839 my $form = $main::form;
1840 my %myconfig = %main::myconfig;
1842 $main::auth->assert('config');
1844 AM->get_tax_accounts(\%myconfig, \%$form);
1846 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1848 $main::lxdebug->leave_sub();
1852 $main::lxdebug->enter_sub();
1854 my $form = $main::form;
1855 my %myconfig = %main::myconfig;
1856 my $locale = $main::locale;
1858 $main::auth->assert('config');
1860 $form->isblank("rate", $locale->text('Taxrate missing!'));
1861 $form->isblank("taxdescription", $locale->text('Taxdescription missing!'));
1862 $form->isblank("taxkey", $locale->text('Taxkey missing!'));
1864 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1866 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1867 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1870 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
1871 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1874 AM->save_tax(\%myconfig, \%$form);
1875 $form->redirect($locale->text('Tax saved!'));
1877 $main::lxdebug->leave_sub();
1881 $main::lxdebug->enter_sub();
1883 my $form = $main::form;
1884 my %myconfig = %main::myconfig;
1885 my $locale = $main::locale;
1887 $main::auth->assert('config');
1889 AM->delete_tax(\%myconfig, \%$form);
1890 $form->redirect($locale->text('Tax deleted!'));
1892 $main::lxdebug->leave_sub();
1895 sub add_price_factor {
1896 $main::lxdebug->enter_sub();
1898 my $form = $main::form;
1899 my $locale = $main::locale;
1901 $main::auth->assert('config');
1903 $form->{title} = $locale->text('Add Price Factor');
1904 $form->{callback} ||= build_std_url('action=add_price_factor');
1905 $form->{fokus} = 'description';
1908 print $form->parse_html_template('am/edit_price_factor');
1910 $main::lxdebug->leave_sub();
1913 sub edit_price_factor {
1914 $main::lxdebug->enter_sub();
1916 my $form = $main::form;
1917 my %myconfig = %main::myconfig;
1918 my $locale = $main::locale;
1920 $main::auth->assert('config');
1922 $form->{title} = $locale->text('Edit Price Factor');
1923 $form->{callback} ||= build_std_url('action=add_price_factor');
1924 $form->{fokus} = 'description';
1926 AM->get_price_factor(\%myconfig, $form);
1928 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
1931 print $form->parse_html_template('am/edit_price_factor');
1933 $main::lxdebug->leave_sub();
1936 sub list_price_factors {
1937 $main::lxdebug->enter_sub();
1939 my $form = $main::form;
1940 my %myconfig = %main::myconfig;
1941 my $locale = $main::locale;
1943 $main::auth->assert('config');
1945 AM->get_all_price_factors(\%myconfig, \%$form);
1947 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
1948 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
1951 $form->{callback} = build_std_url('action=list_price_factors');
1952 $form->{title} = $locale->text('Price Factors');
1953 $form->{url_base} = build_std_url('callback');
1956 print $form->parse_html_template('am/list_price_factors');
1958 $main::lxdebug->leave_sub();
1961 sub save_price_factor {
1962 $main::lxdebug->enter_sub();
1964 my $form = $main::form;
1965 my %myconfig = %main::myconfig;
1966 my $locale = $main::locale;
1968 $main::auth->assert('config');
1970 $form->isblank("description", $locale->text('Description missing!'));
1971 $form->isblank("factor", $locale->text('Factor missing!'));
1973 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
1975 AM->save_price_factor(\%myconfig, $form);
1977 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
1979 $form->redirect($locale->text('Price factor saved!'));
1981 $main::lxdebug->leave_sub();
1984 sub delete_price_factor {
1985 $main::lxdebug->enter_sub();
1987 my $form = $main::form;
1988 my %myconfig = %main::myconfig;
1989 my $locale = $main::locale;
1991 $main::auth->assert('config');
1993 AM->delete_price_factor(\%myconfig, \%$form);
1995 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
1997 $form->redirect($locale->text('Price factor deleted!'));
1999 $main::lxdebug->leave_sub();
2003 $main::lxdebug->enter_sub();
2005 my $form = $main::form;
2006 my $locale = $main::locale;
2008 $main::auth->assert('config');
2010 $form->{title} = $locale->text('Add Warehouse');
2011 $form->{callback} ||= build_std_url('action=add_warehouse');
2012 $form->{fokus} = 'description';
2015 print $form->parse_html_template('am/edit_warehouse');
2017 $main::lxdebug->leave_sub();
2020 sub edit_warehouse {
2021 $main::lxdebug->enter_sub();
2023 my $form = $main::form;
2024 my %myconfig = %main::myconfig;
2025 my $locale = $main::locale;
2027 $main::auth->assert('config');
2029 AM->get_warehouse(\%myconfig, $form);
2031 $form->get_lists('employees' => 'EMPLOYEES');
2033 $form->{title} = $locale->text('Edit Warehouse');
2034 $form->{callback} ||= build_std_url('action=list_warehouses');
2035 $form->{fokus} = 'description';
2038 print $form->parse_html_template('am/edit_warehouse');
2040 $main::lxdebug->leave_sub();
2043 sub list_warehouses {
2044 $main::lxdebug->enter_sub();
2046 my $form = $main::form;
2047 my %myconfig = %main::myconfig;
2048 my $locale = $main::locale;
2050 $main::auth->assert('config');
2052 AM->get_all_warehouses(\%myconfig, $form);
2054 $form->{callback} = build_std_url('action=list_warehouses');
2055 $form->{title} = $locale->text('Warehouses');
2056 $form->{url_base} = build_std_url('callback');
2059 print $form->parse_html_template('am/list_warehouses');
2061 $main::lxdebug->leave_sub();
2064 sub save_warehouse {
2065 $main::lxdebug->enter_sub();
2067 my $form = $main::form;
2068 my %myconfig = %main::myconfig;
2069 my $locale = $main::locale;
2071 $main::auth->assert('config');
2073 $form->isblank("description", $locale->text('Description missing!'));
2075 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
2077 AM->save_warehouse(\%myconfig, $form);
2079 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
2081 $form->redirect($locale->text('Warehouse saved.'));
2083 $main::lxdebug->leave_sub();
2086 sub delete_warehouse {
2087 $main::lxdebug->enter_sub();
2089 my $form = $main::form;
2090 my %myconfig = %main::myconfig;
2091 my $locale = $main::locale;
2093 $main::auth->assert('config');
2095 if (!$form->{confirmed}) {
2096 $form->{title} = $locale->text('Confirmation');
2099 print $form->parse_html_template('am/confirm_delete_warehouse');
2103 if (AM->delete_warehouse(\%myconfig, $form)) {
2104 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
2105 $form->redirect($locale->text('Warehouse deleted.'));
2108 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
2111 $main::lxdebug->leave_sub();
2115 $main::lxdebug->enter_sub();
2117 my $form = $main::form;
2118 my %myconfig = %main::myconfig;
2119 my $locale = $main::locale;
2121 $main::auth->assert('config');
2123 AM->save_bins(\%myconfig, $form);
2125 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
2127 $form->redirect($locale->text('Bins saved.'));
2129 $main::lxdebug->leave_sub();