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 $main::lxdebug->enter_sub();
638 my $form = $main::form;
639 my $locale = $main::locale;
641 $main::auth->assert('config');
643 $form->{title} = $locale->text("$form->{title} Lead");
645 # $locale->text('Add Lead')
646 # $locale->text('Edit Lead')
648 $form->{description} =~ s/\"/"/g;
651 qq|<input name=description size=50 value="$form->{lead}">|;
658 <form method=post action=am.pl>
660 <input type=hidden name=id value=$form->{id}>
661 <input type=hidden name=type value=lead>
665 <th class=listtop colspan=2>$form->{title}</th>
669 <th align=right>| . $locale->text('Description') . qq|</th>
670 <td>$description</td>
672 <td colspan=2><hr size=3 noshade></td>
677 $main::lxdebug->leave_sub();
681 $main::lxdebug->enter_sub();
683 my $form = $main::form;
684 my %myconfig = %main::myconfig;
685 my $locale = $main::locale;
687 $main::auth->assert('config');
689 $form->isblank("description", $locale->text('Description missing!'));
690 AM->save_lead(\%myconfig, \%$form);
691 $form->redirect($locale->text('lead saved!'));
693 $main::lxdebug->leave_sub();
697 $main::lxdebug->enter_sub();
699 my $form = $main::form;
700 my %myconfig = %main::myconfig;
701 my $locale = $main::locale;
703 $main::auth->assert('config');
705 AM->delete_lead(\%myconfig, \%$form);
706 $form->redirect($locale->text('lead deleted!'));
708 $main::lxdebug->leave_sub();
712 $main::lxdebug->enter_sub();
714 my $form = $main::form;
716 $main::auth->assert('config');
718 $form->{title} = "Add";
720 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
725 $main::lxdebug->leave_sub();
729 $main::lxdebug->enter_sub();
731 my $form = $main::form;
732 my %myconfig = %main::myconfig;
734 $main::auth->assert('config');
736 $form->{title} = "Edit";
738 AM->get_language(\%myconfig, \%$form);
742 $form->{orphaned} = 1;
745 $main::lxdebug->leave_sub();
749 $::lxdebug->enter_sub;
750 $::auth->assert('config');
752 AM->language(\%::myconfig, $::form);
754 $::form->{callback} = "am.pl?action=list_language";
755 $::form->{title} = $::locale->text('Languages');
759 print $::form->parse_html_template('am/language_list');
761 $::lxdebug->leave_sub;
764 sub language_header {
765 $::lxdebug->enter_sub;
766 $::auth->assert('config');
768 # $locale->text('Add Language')
769 # $locale->text('Edit Language')
770 $::form->{title} = $::locale->text("$::form->{title} Language");
774 print $::form->parse_html_template('am/language_header', {
775 numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00' ],
776 dateformats => [ qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
779 $::lxdebug->leave_sub;
783 $main::lxdebug->enter_sub();
785 my $form = $main::form;
786 my %myconfig = %main::myconfig;
787 my $locale = $main::locale;
789 $main::auth->assert('config');
791 $form->isblank("description", $locale->text('Language missing!'));
792 $form->isblank("template_code", $locale->text('Template Code missing!'));
793 $form->isblank("article_code", $locale->text('Article Code missing!'));
794 AM->save_language(\%myconfig, \%$form);
795 $form->redirect($locale->text('Language saved!'));
797 $main::lxdebug->leave_sub();
800 sub delete_language {
801 $main::lxdebug->enter_sub();
803 my $form = $main::form;
804 my %myconfig = %main::myconfig;
805 my $locale = $main::locale;
807 $main::auth->assert('config');
809 AM->delete_language(\%myconfig, \%$form);
810 $form->redirect($locale->text('Language deleted!'));
812 $main::lxdebug->leave_sub();
816 sub add_buchungsgruppe {
817 $main::lxdebug->enter_sub();
819 my $form = $main::form;
820 my %myconfig = %main::myconfig;
821 my $locale = $main::locale;
823 $main::auth->assert('config');
825 # $locale->text("Add Buchungsgruppe")
826 # $locale->text("Edit Buchungsgruppe")
827 $form->{title} = "Add";
829 $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
831 AM->get_buchungsgruppe(\%myconfig, \%$form);
832 $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
833 for (my $i = 0; 4 > $i; $i++) {
834 map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
838 &buchungsgruppe_header;
841 $main::lxdebug->leave_sub();
844 sub edit_buchungsgruppe {
845 $main::lxdebug->enter_sub();
847 my $form = $main::form;
848 my %myconfig = %main::myconfig;
850 $main::auth->assert('config');
852 $form->{title} = "Edit";
854 AM->get_buchungsgruppe(\%myconfig, \%$form);
856 &buchungsgruppe_header;
860 $main::lxdebug->leave_sub();
863 sub list_buchungsgruppe {
864 $main::lxdebug->enter_sub();
866 my $form = $main::form;
867 my %myconfig = %main::myconfig;
868 my $locale = $main::locale;
870 $main::auth->assert('config');
872 AM->buchungsgruppe(\%myconfig, \%$form);
874 $form->{callback} = "am.pl?action=list_buchungsgruppe";
876 my $callback = $form->escape($form->{callback});
878 $form->{title} = $locale->text('Buchungsgruppen');
880 my @column_index = qw(up down description inventory_accno
881 income_accno_0 expense_accno_0
882 income_accno_1 expense_accno_1
883 income_accno_2 expense_accno_2
884 income_accno_3 expense_accno_3 );
887 qq|<th class="listheading" width="16">|
888 . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
890 $column_header{down} =
891 qq|<th class="listheading" width="16">|
892 . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
894 $column_header{description} =
895 qq|<th class="listheading" width="40%">|
896 . $locale->text('Description')
898 $column_header{inventory_accno} =
899 qq|<th class=listheading>|
900 . $locale->text('Bestandskonto')
902 $column_header{income_accno_0} =
903 qq|<th class=listheading>|
904 . $locale->text('National Revenues')
906 $column_header{expense_accno_0} =
907 qq|<th class=listheading>|
908 . $locale->text('National Expenses')
910 $column_header{income_accno_1} =
911 qq|<th class=listheading>|
912 . $locale->text('Revenues EU with UStId')
914 $column_header{expense_accno_1} =
915 qq|<th class=listheading>|
916 . $locale->text('Expenses EU with UStId')
918 $column_header{income_accno_2} =
919 qq|<th class=listheading>|
920 . $locale->text('Revenues EU without UStId')
922 $column_header{expense_accno_2} =
923 qq|<th class=listheading>|
924 . $locale->text('Expenses EU without UStId')
926 $column_header{income_accno_3} =
927 qq|<th class=listheading>|
928 . $locale->text('Foreign Revenues')
930 $column_header{expense_accno_3} =
931 qq|<th class=listheading>|
932 . $locale->text('Foreign Expenses')
941 <th class=listtop>$form->{title}</th>
947 <tr class=listheading>
950 map { print "$column_header{$_}\n" } @column_index;
956 my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
959 my ($i, %column_data);
960 foreach my $ref (@{ $form->{ALL} }) {
966 <tr valign=top class=listrow$i>
970 my $pref = $form->{ALL}->[$row - 1];
972 qq|<td align="center" valign="center" width="16">| .
973 qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
974 qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
977 $column_data{up} = qq|<td width="16"> </td>|;
980 if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
981 $column_data{down} = qq|<td width="16"> </td>|;
983 my $nref = $form->{ALL}->[$row + 1];
985 qq|<td align="center" valign="center" width="16">| .
986 qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
987 qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
991 $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
992 $column_data{inventory_accno} = qq|<td align=right>$ref->{inventory_accno}</td>|;
993 $column_data{income_accno_0} =
994 qq|<td align=right>$ref->{income_accno_0}</td>|;
995 $column_data{expense_accno_0} = qq|<td align=right>$ref->{expense_accno_0}</td>|;
996 $column_data{income_accno_1} =
997 qq|<td align=right>$ref->{income_accno_1}</td>|;
998 $column_data{expense_accno_1} = qq|<td align=right>$ref->{expense_accno_1}</td>|;
999 $column_data{income_accno_2} =
1000 qq|<td align=right>$ref->{income_accno_2}</td>|;
1001 $column_data{expense_accno_2} = qq|<td align=right>$ref->{expense_accno_2}</td>|;
1002 $column_data{income_accno_3} =
1003 qq|<td align=right>$ref->{income_accno_3}</td>|;
1004 $column_data{expense_accno_3} = qq|<td align=right>$ref->{expense_accno_3}</td>|;
1006 map { print "$column_data{$_}\n" } @column_index;
1020 <td><hr size=3 noshade></td>
1025 <form method=post action=am.pl>
1027 <input name=callback type=hidden value="$form->{callback}">
1029 <input type=hidden name=type value=buchungsgruppe>
1031 <input class=submit type=submit name=action value="|
1032 . $locale->text('Add') . qq|">
1040 $main::lxdebug->leave_sub();
1043 sub buchungsgruppe_header {
1044 $main::lxdebug->enter_sub();
1046 my $form = $main::form;
1047 my $locale = $main::locale;
1049 $main::auth->assert('config');
1051 $form->{title} = $locale->text("$form->{title} Buchungsgruppe");
1053 # $locale->text('Add Accounting Group')
1054 # $locale->text('Edit Accounting Group')
1056 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
1057 my %acc_type_map = (
1058 "IC" => $acc_inventory,
1059 "IC_income" => $acc_income,
1060 "IC_sale" => $acc_income,
1061 "IC_expense" => $acc_expense,
1062 "IC_cogs" => $acc_expense,
1065 foreach my $key (keys(%acc_type_map)) {
1066 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1067 $acc_type_map{$key}->{$ref->{"id"}} = $ref;
1071 foreach my $type (qw(IC IC_income IC_expense)) {
1072 $form->{"select$type"} =
1074 map({ "<option value=$_->{id} $_->{selected}>" .
1075 "$_->{accno}--" . H($_->{description}) . "</option>" }
1076 sort({ $a->{"accno"} cmp $b->{"accno"} }
1077 values(%{$acc_type_map{$type}}))));
1081 $form->{selectIC} =~ s/selected//g;
1082 $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/ value=$form->{inventory_accno_id} selected/;
1083 $form->{selectIC_income} =~ s/selected//g;
1084 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/ value=$form->{income_accno_id_0} selected/;
1085 $form->{selectIC_expense} =~ s/selected//g;
1086 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/ value=$form->{expense_accno_id_0} selected/;
1090 if ( $::instance_conf->get_inventory_system eq 'perpetual' ) { # was !$::lx_office_conf{system}->{eur}) { }
1093 <th align=right>| . $locale->text('Inventory') . qq|</th>
1094 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
1095 <input name=selectIC type=hidden value="$form->{selectIC}">
1097 } elsif ( $::instance_conf->get_inventory_system eq 'periodic' ) {
1098 # don't allow choice of inventory accno and don't show that line
1100 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
1104 $linkaccounts .= qq|
1106 <th align=right>| . $locale->text('National Revenues') . qq|</th>
1107 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
1110 <th align=right>| . $locale->text('National Expenses') . qq|</th>
1111 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
1114 $form->{selectIC_income} =~ s/selected//g;
1115 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/ value=$form->{income_accno_id_1} selected/;
1116 $form->{selectIC_expense} =~ s/selected//g;
1117 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/ value=$form->{expense_accno_id_1} selected/;
1119 $linkaccounts .= qq| <tr>
1120 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
1121 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
1124 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
1125 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
1129 $form->{selectIC_income} =~ s/selected//g;
1130 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/ value=$form->{income_accno_id_2} selected/;
1131 $form->{selectIC_expense} =~ s/selected//g;
1132 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/ value=$form->{expense_accno_id_2} selected/;
1135 $linkaccounts .= qq| <tr>
1136 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
1137 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
1140 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
1141 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
1145 $form->{selectIC_income} =~ s/selected//g;
1146 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/ value=$form->{income_accno_id_3} selected/;
1147 $form->{selectIC_expense} =~ s/selected//g;
1148 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/ value=$form->{expense_accno_id_3} selected/;
1151 $linkaccounts .= qq| <tr>
1152 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
1153 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
1156 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
1157 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
1167 <form method=post action=am.pl>
1169 <input type=hidden name=id value=$form->{id}>
1170 <input type=hidden name=type value=buchungsgruppe>
1174 <th class=listtop colspan=2>$form->{title}</th>
1176 <tr height="5"></tr>
1178 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
1179 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1182 <td colspan=2><hr size=3 noshade></td>
1187 $main::lxdebug->leave_sub();
1190 sub save_buchungsgruppe {
1191 $main::lxdebug->enter_sub();
1193 my $form = $main::form;
1194 my %myconfig = %main::myconfig;
1195 my $locale = $main::locale;
1197 $main::auth->assert('config');
1199 $form->isblank("description", $locale->text('Description missing!'));
1201 AM->save_buchungsgruppe(\%myconfig, \%$form);
1202 $form->redirect($locale->text('Accounting Group saved!'));
1204 $main::lxdebug->leave_sub();
1207 sub delete_buchungsgruppe {
1208 $main::lxdebug->enter_sub();
1210 my $form = $main::form;
1211 my %myconfig = %main::myconfig;
1212 my $locale = $main::locale;
1214 $main::auth->assert('config');
1216 AM->delete_buchungsgruppe(\%myconfig, \%$form);
1217 $form->redirect($locale->text('Accounting Group deleted!'));
1219 $main::lxdebug->leave_sub();
1222 sub swap_buchungsgruppen {
1223 $main::lxdebug->enter_sub();
1225 my $form = $main::form;
1226 my %myconfig = %main::myconfig;
1228 $main::auth->assert('config');
1230 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
1231 list_buchungsgruppe();
1233 $main::lxdebug->leave_sub();
1237 $main::lxdebug->enter_sub();
1239 my $form = $main::form;
1240 my %myconfig = %main::myconfig;
1241 my $locale = $main::locale;
1243 # get defaults for account numbers and last numbers
1244 AM->defaultaccounts(\%myconfig, \%$form);
1245 $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
1247 map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
1250 my $all_languages = SL::DB::Manager::Language->get_all;
1252 # EÜR = cash, Bilanzierung = accrual
1254 foreach my $key (keys %{ $form->{IC} }) {
1255 foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
1256 my $array = "ACCNOS_" . uc($key);
1257 $form->{$array} ||= [];
1259 my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
1260 push @{ $form->{$array} }, {
1263 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
1268 $form->{title} = $locale->text('Ranges of numbers and default accounts');
1271 print $form->parse_html_template('am/edit_defaults',
1272 { ALL_LANGUAGES => $all_languages, });
1274 $main::lxdebug->leave_sub();
1278 $main::lxdebug->enter_sub();
1280 my $form = $main::form;
1281 my $locale = $main::locale;
1283 AM->save_defaults();
1285 $form->redirect($locale->text('Defaults saved.'));
1287 $main::lxdebug->leave_sub();
1290 sub _build_cfg_options {
1291 my $form = $main::form;
1292 my %myconfig = %main::myconfig;
1295 my $array = uc($idx) . 'S';
1297 $form->{$array} = [];
1298 foreach my $item (@_) {
1299 push @{ $form->{$array} }, {
1302 'selected' => $item eq $myconfig{$idx},
1308 $main::lxdebug->enter_sub();
1310 my $form = $main::form;
1311 my %myconfig = %main::myconfig;
1312 my $locale = $main::locale;
1314 _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
1315 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
1318 if ($::lx_office_conf{print_templates}->{opendocument}
1319 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
1320 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
1321 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
1322 "value" => "opendocument_pdf" });
1324 if ($::lx_office_conf{print_templates}->{latex}) {
1325 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
1327 push(@formats, { "name" => "HTML", "value" => "html" });
1328 if ($::lx_office_conf{print_templates}->{latex}) {
1329 push(@formats, { "name" => $locale->text("Postscript"),
1330 "value" => "postscript" });
1332 if ($::lx_office_conf{print_templates}->{opendocument}) {
1333 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
1334 "value" => "opendocument" });
1337 if (!$myconfig{"template_format"}) {
1338 $myconfig{"template_format"} = "pdf";
1340 $form->{TEMPLATE_FORMATS} = [];
1341 foreach my $item (@formats) {
1342 push @{ $form->{TEMPLATE_FORMATS} }, {
1343 'name' => $item->{name},
1344 'value' => $item->{value},
1345 'selected' => $item->{value} eq $myconfig{template_format},
1349 if (!$myconfig{"default_media"}) {
1350 $myconfig{"default_media"} = "screen";
1353 my %selected = ($myconfig{"default_media"} => "selected");
1355 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
1356 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
1357 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
1360 $form->{PRINTERS} = [ SL::Printer->all_printers(%::myconfig) ];
1362 my %countrycodes = User->country_codes;
1364 $form->{COUNTRYCODES} = [];
1365 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
1366 push @{ $form->{COUNTRYCODES} }, {
1367 'name' => $countrycodes{$countrycode},
1368 'value' => $countrycode,
1369 'selected' => $countrycode eq $myconfig{countrycode},
1373 $form->{STYLESHEETS} = [];
1374 foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
1375 push @{ $form->{STYLESHEETS} }, {
1378 'selected' => $item eq $myconfig{stylesheet},
1382 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
1383 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
1384 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
1386 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
1389 print $form->parse_html_template('am/config');
1391 $main::lxdebug->leave_sub();
1394 sub save_preferences {
1395 $main::lxdebug->enter_sub();
1397 my $form = $main::form;
1398 my %myconfig = %main::myconfig;
1399 my $locale = $main::locale;
1401 $form->{stylesheet} = $form->{usestylesheet};
1403 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
1405 if (AM->save_preferences(\%myconfig, $form)) {
1406 if ($::auth->can_change_password()
1407 && defined $form->{new_password}
1408 && ($form->{new_password} ne '********')) {
1409 my $verifier = SL::Auth::PasswordPolicy->new;
1410 my $result = $verifier->verify($form->{new_password});
1412 if ($result != SL::Auth::PasswordPolicy->OK()) {
1413 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
1416 $::auth->change_password($form->{login}, $form->{new_password});
1418 $form->{password} = $form->{new_password};
1419 $::auth->set_session_value('password', $form->{password});
1420 $::auth->create_or_refresh_session();
1423 $form->redirect($locale->text('Preferences saved!'));
1426 $form->error($locale->text('Cannot save preferences!'));
1428 $main::lxdebug->leave_sub();
1432 $main::lxdebug->enter_sub();
1434 my $form = $main::form;
1435 my %myconfig = %main::myconfig;
1436 my $locale = $main::locale;
1438 $main::auth->assert('config');
1440 $form->{title} = $locale->text('Audit Control');
1442 AM->closedto(\%myconfig, \%$form);
1449 <form method=post action=am.pl>
1452 <tr><th class=listtop>$form->{title}</th></tr>
1453 <tr height="5"></tr>
1458 <th>| . $locale->text('Close Books up to') . qq|</th>
1459 <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
1469 <input type=hidden name=nextsub value=doclose>
1471 <input type=submit class=submit name=action value="|
1472 . $locale->text('Continue') . qq|">
1480 $main::lxdebug->leave_sub();
1484 $main::lxdebug->enter_sub();
1486 my $form = $main::form;
1487 my %myconfig = %main::myconfig;
1488 my $locale = $main::locale;
1490 $main::auth->assert('config');
1492 AM->closebooks(\%myconfig, \%$form);
1494 if ($form->{closedto}) {
1496 $locale->text('Books closed up to') . " "
1497 . $locale->date(\%myconfig, $form->{closedto}, 1));
1499 $form->redirect($locale->text('Books are open'));
1502 $main::lxdebug->leave_sub();
1506 $main::lxdebug->enter_sub();
1508 my $form = $main::form;
1509 my %myconfig = %main::myconfig;
1510 my $locale = $main::locale;
1512 $main::auth->assert('config');
1514 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1515 AM->units_in_use(\%myconfig, $form, $units);
1516 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1518 my @languages = AM->language(\%myconfig, $form, 1);
1520 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1523 foreach (@unit_list) {
1524 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1525 $_->{"UNITLANGUAGES"} = [];
1526 foreach my $lang (@languages) {
1527 push(@{ $_->{"UNITLANGUAGES"} },
1529 "unit" => $_->{"name"},
1530 "language_id" => $lang->{"id"},
1531 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1532 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1538 $units = AM->retrieve_units(\%myconfig, $form);
1539 my $ddbox = AM->unit_select_data($units, undef, 1);
1541 $form->{"title"} = $locale->text("Add and edit units");
1543 print($form->parse_html_template("am/edit_units",
1544 { "UNITS" => \@unit_list,
1545 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1546 "LANGUAGES" => \@languages,
1549 $main::lxdebug->leave_sub();
1553 $main::lxdebug->enter_sub();
1555 my $form = $main::form;
1556 my %myconfig = %main::myconfig;
1557 my $locale = $main::locale;
1559 $main::auth->assert('config');
1561 $form->isblank("new_name", $locale->text("The name is missing."));
1562 my $units = AM->retrieve_units(\%myconfig, $form);
1563 my $all_units = AM->retrieve_units(\%myconfig, $form);
1564 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1566 my ($base_unit, $factor);
1567 if ($form->{"new_base_unit"}) {
1568 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1570 $form->isblank("new_factor", $locale->text("The factor is missing."));
1571 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1572 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1573 $base_unit = $form->{"new_base_unit"};
1577 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1578 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1579 push(@languages, { "id" => $lang->{"id"},
1580 "localized" => $form->{"new_localized_$lang->{id}"},
1581 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1585 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1587 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1591 $main::lxdebug->leave_sub();
1594 sub set_unit_languages {
1595 $main::lxdebug->enter_sub();
1597 my $form = $main::form;
1599 $main::auth->assert('config');
1601 my ($unit, $languages, $idx) = @_;
1603 $unit->{"LANGUAGES"} = [];
1605 foreach my $lang (@{$languages}) {
1606 push(@{ $unit->{"LANGUAGES"} },
1607 { "id" => $lang->{"id"},
1608 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1609 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1613 $main::lxdebug->leave_sub();
1617 $main::lxdebug->enter_sub();
1619 my $form = $main::form;
1620 my %myconfig = %main::myconfig;
1621 my $locale = $main::locale;
1623 $main::auth->assert('config');
1625 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1626 AM->units_in_use(\%myconfig, $form, $old_units);
1628 my @languages = AM->language(\%myconfig, $form, 1);
1631 my @delete_units = ();
1632 foreach my $i (1..($form->{"rowcount"} * 1)) {
1633 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1635 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1638 if ($form->{"unchangeable_$i"}) {
1639 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1640 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1641 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1645 if ($old_unit->{"in_use"}) {
1646 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1649 if ($form->{"delete_$i"}) {
1650 push(@delete_units, $old_unit->{"name"});
1654 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1656 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1657 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1658 $new_units->{$form->{"name_$i"}} = \%h;
1659 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1660 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1663 foreach my $unit (values(%{$new_units})) {
1664 next unless ($unit->{"old_name"});
1665 if ($unit->{"base_unit"}) {
1666 $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"}))
1667 unless (defined($new_units->{$unit->{"base_unit"}}));
1668 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1669 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1671 $unit->{"base_unit"} = undef;
1672 $unit->{"factor"} = undef;
1676 foreach my $unit (values(%{$new_units})) {
1677 next if ($unit->{"unchanged_unit"});
1679 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1680 my $new_unit = $unit;
1681 while ($new_unit->{"base_unit"}) {
1682 $new_unit->{"seen"} = 1;
1683 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1684 if ($new_unit->{"seen"}) {
1685 $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, " .
1686 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1691 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1693 $form->{"saved_message"} = $locale->text("The units have been saved.");
1697 $main::lxdebug->leave_sub();
1700 sub show_history_search {
1701 $main::lxdebug->enter_sub();
1703 my $form = $main::form;
1704 my $locale = $main::locale;
1706 $main::auth->assert('config');
1708 $form->{title} = $locale->text("History Search");
1711 print $form->parse_html_template("common/search_history");
1713 $main::lxdebug->leave_sub();
1716 sub show_am_history {
1717 $main::lxdebug->enter_sub();
1719 my $form = $main::form;
1720 my %myconfig = %main::myconfig;
1721 my $locale = $main::locale;
1723 $main::auth->assert('config');
1725 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1726 $form->{order} ||= 'h.itime--1';
1728 my %search = ( "Artikelnummer" => "parts",
1729 "Kundennummer" => "customer",
1730 "Lieferantennummer" => "vendor",
1731 "Projektnummer" => "project",
1732 "Buchungsnummer" => "oe",
1733 "Eingangsrechnungnummer" => "ap",
1734 "Ausgangsrechnungnummer" => "ar",
1735 "Mahnungsnummer" => "dunning"
1737 my %searchNo = ( "Artikelnummer" => "partnumber",
1738 "Kundennummer" => "customernumber",
1739 "Lieferantennummer" => "vendornumber",
1740 "Projektnummer" => "projectnumber",
1741 "Buchungsnummer" => "ordnumber",
1742 "Eingangsrechnungnummer" => "invnumber",
1743 "Ausgangsrechnungnummer" => "invnumber",
1744 "Mahnungsnummer" => "dunning_id"
1747 my $dbh = $form->dbconnect(\%myconfig);
1750 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1751 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1752 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1753 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1754 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1755 } elsif ($form->{mitarbeiter}) {
1756 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1759 my $query = qq|SELECT trans_id AS id FROM history_erp | .
1760 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
1761 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
1763 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
1764 my $daten .= shift @ids;
1765 $daten .= join '', map { " OR trans_id = $_" } @ids;
1767 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1768 $sort =~ s/.*\.(.*)$/$1/;
1770 $form->{title} = $locale->text("History Search");
1773 print $form->parse_html_template("common/show_history",
1774 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1775 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1778 uc($sort) . "BY" => $sortby,
1779 'callback' => $callback,
1783 $main::lxdebug->leave_sub();
1787 $main::lxdebug->enter_sub();
1789 my $form = $main::form;
1790 my $locale = $main::locale;
1792 $main::auth->assert('config');
1794 $form->{title} = $locale->text('Add');
1796 $form->{callback} ||= "am.pl?action=add_tax";
1798 _get_taxaccount_selection();
1802 my $parameters_ref = {
1803 # ChartTypeIsAccount => $ChartTypeIsAccount,
1806 # Ausgabe des Templates
1807 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1809 $main::lxdebug->leave_sub();
1813 $main::lxdebug->enter_sub();
1815 my $form = $main::form;
1816 my %myconfig = %main::myconfig;
1817 my $locale = $main::locale;
1819 $main::auth->assert('config');
1821 $form->{title} = $locale->text('Edit');
1823 AM->get_tax(\%myconfig, \%$form);
1824 _get_taxaccount_selection();
1826 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1830 my $parameters_ref = {
1833 # Ausgabe des Templates
1834 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1836 $main::lxdebug->leave_sub();
1840 $main::lxdebug->enter_sub();
1842 my $form = $main::form;
1843 my %myconfig = %main::myconfig;
1844 my $locale = $main::locale;
1846 $main::auth->assert('config');
1848 AM->taxes(\%myconfig, \%$form);
1850 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1852 $form->{callback} = build_std_url('action=list_tax');
1854 $form->{title} = $locale->text('Tax-O-Matic');
1858 my $parameters_ref = {
1861 # Ausgabe des Templates
1862 print($form->parse_html_template('am/list_tax', $parameters_ref));
1864 $main::lxdebug->leave_sub();
1867 sub _get_taxaccount_selection{
1868 $main::lxdebug->enter_sub();
1870 my $form = $main::form;
1871 my %myconfig = %main::myconfig;
1873 $main::auth->assert('config');
1875 AM->get_tax_accounts(\%myconfig, \%$form);
1877 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1879 $main::lxdebug->leave_sub();
1883 $main::lxdebug->enter_sub();
1885 my $form = $main::form;
1886 my %myconfig = %main::myconfig;
1887 my $locale = $main::locale;
1889 $main::auth->assert('config');
1891 $form->isblank("rate", $locale->text('Taxrate missing!'));
1892 $form->isblank("taxdescription", $locale->text('Taxdescription missing!'));
1893 $form->isblank("taxkey", $locale->text('Taxkey missing!'));
1895 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1897 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1898 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1901 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
1902 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1905 AM->save_tax(\%myconfig, \%$form);
1906 $form->redirect($locale->text('Tax saved!'));
1908 $main::lxdebug->leave_sub();
1912 $main::lxdebug->enter_sub();
1914 my $form = $main::form;
1915 my %myconfig = %main::myconfig;
1916 my $locale = $main::locale;
1918 $main::auth->assert('config');
1920 AM->delete_tax(\%myconfig, \%$form);
1921 $form->redirect($locale->text('Tax deleted!'));
1923 $main::lxdebug->leave_sub();
1926 sub add_price_factor {
1927 $main::lxdebug->enter_sub();
1929 my $form = $main::form;
1930 my $locale = $main::locale;
1932 $main::auth->assert('config');
1934 $form->{title} = $locale->text('Add Price Factor');
1935 $form->{callback} ||= build_std_url('action=add_price_factor');
1936 $form->{fokus} = 'description';
1939 print $form->parse_html_template('am/edit_price_factor');
1941 $main::lxdebug->leave_sub();
1944 sub edit_price_factor {
1945 $main::lxdebug->enter_sub();
1947 my $form = $main::form;
1948 my %myconfig = %main::myconfig;
1949 my $locale = $main::locale;
1951 $main::auth->assert('config');
1953 $form->{title} = $locale->text('Edit Price Factor');
1954 $form->{callback} ||= build_std_url('action=add_price_factor');
1955 $form->{fokus} = 'description';
1957 AM->get_price_factor(\%myconfig, $form);
1959 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
1962 print $form->parse_html_template('am/edit_price_factor');
1964 $main::lxdebug->leave_sub();
1967 sub list_price_factors {
1968 $main::lxdebug->enter_sub();
1970 my $form = $main::form;
1971 my %myconfig = %main::myconfig;
1972 my $locale = $main::locale;
1974 $main::auth->assert('config');
1976 AM->get_all_price_factors(\%myconfig, \%$form);
1978 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
1979 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
1982 $form->{callback} = build_std_url('action=list_price_factors');
1983 $form->{title} = $locale->text('Price Factors');
1984 $form->{url_base} = build_std_url('callback');
1987 print $form->parse_html_template('am/list_price_factors');
1989 $main::lxdebug->leave_sub();
1992 sub save_price_factor {
1993 $main::lxdebug->enter_sub();
1995 my $form = $main::form;
1996 my %myconfig = %main::myconfig;
1997 my $locale = $main::locale;
1999 $main::auth->assert('config');
2001 $form->isblank("description", $locale->text('Description missing!'));
2002 $form->isblank("factor", $locale->text('Factor missing!'));
2004 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
2006 AM->save_price_factor(\%myconfig, $form);
2008 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
2010 $form->redirect($locale->text('Price factor saved!'));
2012 $main::lxdebug->leave_sub();
2015 sub delete_price_factor {
2016 $main::lxdebug->enter_sub();
2018 my $form = $main::form;
2019 my %myconfig = %main::myconfig;
2020 my $locale = $main::locale;
2022 $main::auth->assert('config');
2024 AM->delete_price_factor(\%myconfig, \%$form);
2026 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
2028 $form->redirect($locale->text('Price factor deleted!'));
2030 $main::lxdebug->leave_sub();
2034 $main::lxdebug->enter_sub();
2036 my $form = $main::form;
2037 my $locale = $main::locale;
2039 $main::auth->assert('config');
2041 $form->{title} = $locale->text('Add Warehouse');
2042 $form->{callback} ||= build_std_url('action=add_warehouse');
2043 $form->{fokus} = 'description';
2046 print $form->parse_html_template('am/edit_warehouse');
2048 $main::lxdebug->leave_sub();
2051 sub edit_warehouse {
2052 $main::lxdebug->enter_sub();
2054 my $form = $main::form;
2055 my %myconfig = %main::myconfig;
2056 my $locale = $main::locale;
2058 $main::auth->assert('config');
2060 AM->get_warehouse(\%myconfig, $form);
2062 $form->get_lists('employees' => 'EMPLOYEES');
2064 $form->{title} = $locale->text('Edit Warehouse');
2065 $form->{callback} ||= build_std_url('action=list_warehouses');
2066 $form->{fokus} = 'description';
2069 print $form->parse_html_template('am/edit_warehouse');
2071 $main::lxdebug->leave_sub();
2074 sub list_warehouses {
2075 $main::lxdebug->enter_sub();
2077 my $form = $main::form;
2078 my %myconfig = %main::myconfig;
2079 my $locale = $main::locale;
2081 $main::auth->assert('config');
2083 AM->get_all_warehouses(\%myconfig, $form);
2085 $form->{callback} = build_std_url('action=list_warehouses');
2086 $form->{title} = $locale->text('Warehouses');
2087 $form->{url_base} = build_std_url('callback');
2090 print $form->parse_html_template('am/list_warehouses');
2092 $main::lxdebug->leave_sub();
2095 sub save_warehouse {
2096 $main::lxdebug->enter_sub();
2098 my $form = $main::form;
2099 my %myconfig = %main::myconfig;
2100 my $locale = $main::locale;
2102 $main::auth->assert('config');
2104 $form->isblank("description", $locale->text('Description missing!'));
2106 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
2108 AM->save_warehouse(\%myconfig, $form);
2110 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
2112 $form->redirect($locale->text('Warehouse saved.'));
2114 $main::lxdebug->leave_sub();
2117 sub delete_warehouse {
2118 $main::lxdebug->enter_sub();
2120 my $form = $main::form;
2121 my %myconfig = %main::myconfig;
2122 my $locale = $main::locale;
2124 $main::auth->assert('config');
2126 if (!$form->{confirmed}) {
2127 $form->{title} = $locale->text('Confirmation');
2130 print $form->parse_html_template('am/confirm_delete_warehouse');
2134 if (AM->delete_warehouse(\%myconfig, $form)) {
2135 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
2136 $form->redirect($locale->text('Warehouse deleted.'));
2139 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
2142 $main::lxdebug->leave_sub();
2146 $main::lxdebug->enter_sub();
2148 my $form = $main::form;
2149 my %myconfig = %main::myconfig;
2150 my $locale = $main::locale;
2152 $main::auth->assert('config');
2154 AM->save_bins(\%myconfig, $form);
2156 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
2158 $form->redirect($locale->text('Bins saved.'));
2160 $main::lxdebug->leave_sub();