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 $main::lxdebug->enter_sub();
371 my $form = $main::form;
372 my $locale = $main::locale;
374 $main::auth->assert('config');
378 <input name=callback type=hidden value="| . H($form->{callback}) . qq|">
381 if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) {
383 <input type=submit class=submit name=action value="|
384 . $locale->text('Save') . qq|">
388 if ($form->{id} && $form->{orphaned}) {
389 print qq|<input type=submit class=submit name=action value="|
390 . $locale->text('Delete') . qq|">|;
393 if ($form->{id} && $form->{type} eq "account") {
395 <input class=submit type=submit name=action value="|
396 . $locale->text('Save as new') . qq|">|;
406 $main::lxdebug->leave_sub();
410 $main::lxdebug->enter_sub();
412 my $form = $main::form;
413 my %myconfig = %main::myconfig;
414 my $locale = $main::locale;
416 $main::auth->assert('config');
418 $form->isblank("accno", $locale->text('Account Number missing!'));
419 $form->isblank("description", $locale->text('Account Description missing!'));
421 if ($form->{charttype} eq 'A'){
422 $form->isblank("category", $locale->text('Account Type missing!'));
425 $form->redirect($locale->text('Account saved!'))
426 if (AM->save_account(\%myconfig, \%$form));
427 $form->error($locale->text('Cannot save account!'));
429 $main::lxdebug->leave_sub();
432 sub save_as_new_account {
433 $main::lxdebug->enter_sub();
435 my $form = $main::form;
436 my %myconfig = %main::myconfig;
437 my $locale = $main::locale;
439 $main::auth->assert('config');
441 $form->isblank("accno", $locale->text('Account Number missing!'));
442 $form->isblank("description", $locale->text('Account Description missing!'));
444 if ($form->{charttype} eq 'A'){
445 $form->isblank("category", $locale->text('Account Type missing!'));
448 for my $taxkey (0 .. 9) {
449 if ($form->{"taxkey_id_$taxkey"}) {
450 $form->{"taxkey_id_$taxkey"} = "NEW";
455 if ($form->{"original_accno"} &&
456 ($form->{"accno"} eq $form->{"original_accno"})) {
457 $form->error($locale->text('Account Number already used!'));
459 $form->redirect($locale->text('Account saved!'))
460 if (AM->save_account(\%myconfig, \%$form));
461 $form->error($locale->text('Cannot save account!'));
463 $main::lxdebug->leave_sub();
467 $main::lxdebug->enter_sub();
469 my $form = $main::form;
470 my %myconfig = %main::myconfig;
471 my $locale = $main::locale;
473 $main::auth->assert('config');
475 $form->{callback} = build_std_url('action=list_account');
476 my $link_edit_account = build_std_url('action=edit_account', 'callback');
478 CA->all_accounts(\%myconfig, \%$form);
480 foreach my $ca (@{ $form->{CA} }) {
485 if ($ca->{amount} > 0) {
486 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
488 if ($ca->{amount} < 0) {
489 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
491 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
492 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
495 $form->use_stylesheet("list_accounts.css");
496 $form->{title} = $locale->text('Chart of Accounts');
501 my $parameters_ref = {
502 # hidden_variables => $_hidden_variables_ref,
505 # Ausgabe des Templates
506 print($form->parse_html_template('am/list_accounts', $parameters_ref));
508 $main::lxdebug->leave_sub();
513 sub list_account_details {
514 # Ajax Funktion aus list_account_details
515 $main::lxdebug->enter_sub();
517 my $form = $main::form;
518 my %myconfig = %main::myconfig;
519 my $locale = $main::locale;
521 $main::auth->assert('config');
523 my $chart_id = $form->{args};
525 CA->all_accounts(\%myconfig, \%$form, $chart_id);
527 foreach my $ca (@{ $form->{CA} }) {
529 $ca->{debit} = " ";
530 $ca->{credit} = " ";
532 if ($ca->{amount} > 0) {
534 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
536 if ($ca->{amount} < 0) {
538 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
541 my @links = split( q{:}, $ca->{link});
545 foreach my $link (@links){
546 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
547 : ( $link eq 'AP') ? $locale->text('Account Link AP')
548 : ( $link eq 'IC') ? $locale->text('Account Link IC')
549 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
550 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
551 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
552 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
553 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
554 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
555 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
556 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
557 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
558 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
559 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
560 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
561 : $locale->text('Unknown Link') . ': ' . $link;
562 $ca->{link} .= ($link ne '') ? "[$link] ":'';
565 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
566 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
567 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
568 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
569 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
570 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
571 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
572 : $locale->text('Unknown Category') . ': ' . $ca->{category};
575 $form->{title} = $locale->text('Chart of Accounts');
577 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
579 $main::lxdebug->leave_sub();
584 $main::lxdebug->enter_sub();
586 my $form = $main::form;
587 my %myconfig = %main::myconfig;
588 my $locale = $main::locale;
590 $main::auth->assert('config');
592 $form->{title} = $locale->text('Delete Account');
595 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
597 if ($form->{id} == $form->{$id}) {
598 $form->error($locale->text('Cannot delete default account!'));
602 $form->redirect($locale->text('Account deleted!'))
603 if (AM->delete_account(\%myconfig, \%$form));
604 $form->error($locale->text('Cannot delete account!'));
606 $main::lxdebug->leave_sub();
610 $main::lxdebug->enter_sub();
612 my $form = $main::form;
614 $main::auth->assert('config');
616 $form->{title} = "Add";
618 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
623 $main::lxdebug->leave_sub();
627 $main::lxdebug->enter_sub();
629 my $form = $main::form;
630 my %myconfig = %main::myconfig;
632 $main::auth->assert('config');
634 $form->{title} = "Edit";
636 AM->get_lead(\%myconfig, \%$form);
640 $form->{orphaned} = 1;
643 $main::lxdebug->leave_sub();
647 $main::lxdebug->enter_sub();
649 my $form = $main::form;
650 my %myconfig = %main::myconfig;
651 my $locale = $main::locale;
653 $main::auth->assert('config');
655 AM->lead(\%myconfig, \%$form);
657 $form->{callback} = "am.pl?action=list_lead";
659 my $callback = $form->escape($form->{callback});
661 $form->{title} = $locale->text('Lead');
663 my @column_index = qw(description cost profit);
665 $column_header{description} =
666 qq|<th class=listheading width=100%>|
667 . $locale->text('Description')
677 <th class=listtop>$form->{title}</th>
680 <tr class=listheading>
683 map { print "$column_header{$_}\n" } @column_index;
689 my ($i, %column_data);
690 foreach my $ref (@{ $form->{ALL} }) {
696 <tr valign=top class=listrow$i>
699 # $lead = $ref->{lead};
701 $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
703 map { print "$column_data{$_}\n" } @column_index;
712 <td><hr size=3 noshade></td>
717 <form method=post action=am.pl>
719 <input name=callback type=hidden value="$form->{callback}">
721 <input type=hidden name=type value=lead>
723 <input class=submit type=submit name=action value="|
724 . $locale->text('Add') . qq|">
732 $main::lxdebug->leave_sub();
736 $main::lxdebug->enter_sub();
738 my $form = $main::form;
739 my $locale = $main::locale;
741 $main::auth->assert('config');
743 $form->{title} = $locale->text("$form->{title} Lead");
745 # $locale->text('Add Lead')
746 # $locale->text('Edit Lead')
748 $form->{description} =~ s/\"/"/g;
751 qq|<input name=description size=50 value="$form->{lead}">|;
758 <form method=post action=am.pl>
760 <input type=hidden name=id value=$form->{id}>
761 <input type=hidden name=type value=lead>
765 <th class=listtop colspan=2>$form->{title}</th>
769 <th align=right>| . $locale->text('Description') . qq|</th>
770 <td>$description</td>
772 <td colspan=2><hr size=3 noshade></td>
777 $main::lxdebug->leave_sub();
781 $main::lxdebug->enter_sub();
783 my $form = $main::form;
784 my %myconfig = %main::myconfig;
785 my $locale = $main::locale;
787 $main::auth->assert('config');
789 $form->isblank("description", $locale->text('Description missing!'));
790 AM->save_lead(\%myconfig, \%$form);
791 $form->redirect($locale->text('lead saved!'));
793 $main::lxdebug->leave_sub();
797 $main::lxdebug->enter_sub();
799 my $form = $main::form;
800 my %myconfig = %main::myconfig;
801 my $locale = $main::locale;
803 $main::auth->assert('config');
805 AM->delete_lead(\%myconfig, \%$form);
806 $form->redirect($locale->text('lead deleted!'));
808 $main::lxdebug->leave_sub();
812 $main::lxdebug->enter_sub();
814 my $form = $main::form;
816 $main::auth->assert('config');
818 $form->{title} = "Add";
820 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
825 $main::lxdebug->leave_sub();
829 $main::lxdebug->enter_sub();
831 my $form = $main::form;
832 my %myconfig = %main::myconfig;
834 $main::auth->assert('config');
836 $form->{title} = "Edit";
838 AM->get_language(\%myconfig, \%$form);
842 $form->{orphaned} = 1;
845 $main::lxdebug->leave_sub();
849 $::lxdebug->enter_sub;
850 $::auth->assert('config');
852 AM->language(\%::myconfig, $::form);
854 $::form->{callback} = "am.pl?action=list_language";
855 $::form->{title} = $::locale->text('Languages');
859 print $::form->parse_html_template('am/language_list');
861 $::lxdebug->leave_sub;
864 sub language_header {
865 $::lxdebug->enter_sub;
866 $::auth->assert('config');
868 # $locale->text('Add Language')
869 # $locale->text('Edit Language')
870 $::form->{title} = $::locale->text("$::form->{title} Language");
874 print $::form->parse_html_template('am/language_header', {
875 numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00' ],
876 dateformats => [ qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
879 $::lxdebug->leave_sub;
883 $main::lxdebug->enter_sub();
885 my $form = $main::form;
886 my %myconfig = %main::myconfig;
887 my $locale = $main::locale;
889 $main::auth->assert('config');
891 $form->isblank("description", $locale->text('Language missing!'));
892 $form->isblank("template_code", $locale->text('Template Code missing!'));
893 $form->isblank("article_code", $locale->text('Article Code missing!'));
894 AM->save_language(\%myconfig, \%$form);
895 $form->redirect($locale->text('Language saved!'));
897 $main::lxdebug->leave_sub();
900 sub delete_language {
901 $main::lxdebug->enter_sub();
903 my $form = $main::form;
904 my %myconfig = %main::myconfig;
905 my $locale = $main::locale;
907 $main::auth->assert('config');
909 AM->delete_language(\%myconfig, \%$form);
910 $form->redirect($locale->text('Language deleted!'));
912 $main::lxdebug->leave_sub();
916 sub add_buchungsgruppe {
917 $main::lxdebug->enter_sub();
919 my $form = $main::form;
920 my %myconfig = %main::myconfig;
921 my $locale = $main::locale;
923 $main::auth->assert('config');
925 # $locale->text("Add Buchungsgruppe")
926 # $locale->text("Edit Buchungsgruppe")
927 $form->{title} = "Add";
929 $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
931 AM->get_buchungsgruppe(\%myconfig, \%$form);
932 $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
933 for (my $i = 0; 4 > $i; $i++) {
934 map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
938 &buchungsgruppe_header;
941 $main::lxdebug->leave_sub();
944 sub edit_buchungsgruppe {
945 $main::lxdebug->enter_sub();
947 my $form = $main::form;
948 my %myconfig = %main::myconfig;
950 $main::auth->assert('config');
952 $form->{title} = "Edit";
954 AM->get_buchungsgruppe(\%myconfig, \%$form);
956 &buchungsgruppe_header;
960 $main::lxdebug->leave_sub();
963 sub list_buchungsgruppe {
964 $main::lxdebug->enter_sub();
966 my $form = $main::form;
967 my %myconfig = %main::myconfig;
968 my $locale = $main::locale;
970 $main::auth->assert('config');
972 AM->buchungsgruppe(\%myconfig, \%$form);
974 $form->{callback} = "am.pl?action=list_buchungsgruppe";
976 my $callback = $form->escape($form->{callback});
978 $form->{title} = $locale->text('Buchungsgruppen');
980 my @column_index = qw(up down description inventory_accno
981 income_accno_0 expense_accno_0
982 income_accno_1 expense_accno_1
983 income_accno_2 expense_accno_2
984 income_accno_3 expense_accno_3 );
987 qq|<th class="listheading" width="16">|
988 . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
990 $column_header{down} =
991 qq|<th class="listheading" width="16">|
992 . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
994 $column_header{description} =
995 qq|<th class="listheading" width="40%">|
996 . $locale->text('Description')
998 $column_header{inventory_accno} =
999 qq|<th class=listheading>|
1000 . $locale->text('Bestandskonto')
1002 $column_header{income_accno_0} =
1003 qq|<th class=listheading>|
1004 . $locale->text('National Revenues')
1006 $column_header{expense_accno_0} =
1007 qq|<th class=listheading>|
1008 . $locale->text('National Expenses')
1010 $column_header{income_accno_1} =
1011 qq|<th class=listheading>|
1012 . $locale->text('Revenues EU with UStId')
1014 $column_header{expense_accno_1} =
1015 qq|<th class=listheading>|
1016 . $locale->text('Expenses EU with UStId')
1018 $column_header{income_accno_2} =
1019 qq|<th class=listheading>|
1020 . $locale->text('Revenues EU without UStId')
1022 $column_header{expense_accno_2} =
1023 qq|<th class=listheading>|
1024 . $locale->text('Expenses EU without UStId')
1026 $column_header{income_accno_3} =
1027 qq|<th class=listheading>|
1028 . $locale->text('Foreign Revenues')
1030 $column_header{expense_accno_3} =
1031 qq|<th class=listheading>|
1032 . $locale->text('Foreign Expenses')
1041 <th class=listtop>$form->{title}</th>
1043 <tr height="5"></tr>
1047 <tr class=listheading>
1050 map { print "$column_header{$_}\n" } @column_index;
1056 my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
1059 my ($i, %column_data);
1060 foreach my $ref (@{ $form->{ALL} }) {
1066 <tr valign=top class=listrow$i>
1070 my $pref = $form->{ALL}->[$row - 1];
1072 qq|<td align="center" valign="center" width="16">| .
1073 qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
1074 qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
1077 $column_data{up} = qq|<td width="16"> </td>|;
1080 if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
1081 $column_data{down} = qq|<td width="16"> </td>|;
1083 my $nref = $form->{ALL}->[$row + 1];
1084 $column_data{down} =
1085 qq|<td align="center" valign="center" width="16">| .
1086 qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
1087 qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
1091 $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
1092 $column_data{inventory_accno} = qq|<td align=right>$ref->{inventory_accno}</td>|;
1093 $column_data{income_accno_0} =
1094 qq|<td align=right>$ref->{income_accno_0}</td>|;
1095 $column_data{expense_accno_0} = qq|<td align=right>$ref->{expense_accno_0}</td>|;
1096 $column_data{income_accno_1} =
1097 qq|<td align=right>$ref->{income_accno_1}</td>|;
1098 $column_data{expense_accno_1} = qq|<td align=right>$ref->{expense_accno_1}</td>|;
1099 $column_data{income_accno_2} =
1100 qq|<td align=right>$ref->{income_accno_2}</td>|;
1101 $column_data{expense_accno_2} = qq|<td align=right>$ref->{expense_accno_2}</td>|;
1102 $column_data{income_accno_3} =
1103 qq|<td align=right>$ref->{income_accno_3}</td>|;
1104 $column_data{expense_accno_3} = qq|<td align=right>$ref->{expense_accno_3}</td>|;
1106 map { print "$column_data{$_}\n" } @column_index;
1120 <td><hr size=3 noshade></td>
1125 <form method=post action=am.pl>
1127 <input name=callback type=hidden value="$form->{callback}">
1129 <input type=hidden name=type value=buchungsgruppe>
1131 <input class=submit type=submit name=action value="|
1132 . $locale->text('Add') . qq|">
1140 $main::lxdebug->leave_sub();
1143 sub buchungsgruppe_header {
1144 $main::lxdebug->enter_sub();
1146 my $form = $main::form;
1147 my $locale = $main::locale;
1149 $main::auth->assert('config');
1151 $form->{title} = $locale->text("$form->{title} Buchungsgruppe");
1153 # $locale->text('Add Accounting Group')
1154 # $locale->text('Edit Accounting Group')
1156 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
1157 my %acc_type_map = (
1158 "IC" => $acc_inventory,
1159 "IC_income" => $acc_income,
1160 "IC_sale" => $acc_income,
1161 "IC_expense" => $acc_expense,
1162 "IC_cogs" => $acc_expense,
1165 foreach my $key (keys(%acc_type_map)) {
1166 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1167 $acc_type_map{$key}->{$ref->{"id"}} = $ref;
1171 foreach my $type (qw(IC IC_income IC_expense)) {
1172 $form->{"select$type"} =
1174 map({ "<option value=$_->{id} $_->{selected}>" .
1175 "$_->{accno}--" . H($_->{description}) . "</option>" }
1176 sort({ $a->{"accno"} cmp $b->{"accno"} }
1177 values(%{$acc_type_map{$type}}))));
1181 $form->{selectIC} =~ s/selected//g;
1182 $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/ value=$form->{inventory_accno_id} selected/;
1183 $form->{selectIC_income} =~ s/selected//g;
1184 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/ value=$form->{income_accno_id_0} selected/;
1185 $form->{selectIC_expense} =~ s/selected//g;
1186 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/ value=$form->{expense_accno_id_0} selected/;
1190 if ( $::instance_conf->get_inventory_system eq 'perpetual' ) { # was !$::lx_office_conf{system}->{eur}) { }
1193 <th align=right>| . $locale->text('Inventory') . qq|</th>
1194 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
1195 <input name=selectIC type=hidden value="$form->{selectIC}">
1197 } elsif ( $::instance_conf->get_inventory_system eq 'periodic' ) {
1198 # don't allow choice of inventory accno and don't show that line
1200 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
1204 $linkaccounts .= qq|
1206 <th align=right>| . $locale->text('National Revenues') . qq|</th>
1207 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
1210 <th align=right>| . $locale->text('National Expenses') . qq|</th>
1211 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
1214 $form->{selectIC_income} =~ s/selected//g;
1215 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/ value=$form->{income_accno_id_1} selected/;
1216 $form->{selectIC_expense} =~ s/selected//g;
1217 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/ value=$form->{expense_accno_id_1} selected/;
1219 $linkaccounts .= qq| <tr>
1220 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
1221 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
1224 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
1225 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
1229 $form->{selectIC_income} =~ s/selected//g;
1230 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/ value=$form->{income_accno_id_2} selected/;
1231 $form->{selectIC_expense} =~ s/selected//g;
1232 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/ value=$form->{expense_accno_id_2} selected/;
1235 $linkaccounts .= qq| <tr>
1236 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
1237 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
1240 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
1241 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
1245 $form->{selectIC_income} =~ s/selected//g;
1246 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/ value=$form->{income_accno_id_3} selected/;
1247 $form->{selectIC_expense} =~ s/selected//g;
1248 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/ value=$form->{expense_accno_id_3} selected/;
1251 $linkaccounts .= qq| <tr>
1252 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
1253 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
1256 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
1257 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
1267 <form method=post action=am.pl>
1269 <input type=hidden name=id value=$form->{id}>
1270 <input type=hidden name=type value=buchungsgruppe>
1274 <th class=listtop colspan=2>$form->{title}</th>
1276 <tr height="5"></tr>
1278 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
1279 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1282 <td colspan=2><hr size=3 noshade></td>
1287 $main::lxdebug->leave_sub();
1290 sub save_buchungsgruppe {
1291 $main::lxdebug->enter_sub();
1293 my $form = $main::form;
1294 my %myconfig = %main::myconfig;
1295 my $locale = $main::locale;
1297 $main::auth->assert('config');
1299 $form->isblank("description", $locale->text('Description missing!'));
1301 AM->save_buchungsgruppe(\%myconfig, \%$form);
1302 $form->redirect($locale->text('Accounting Group saved!'));
1304 $main::lxdebug->leave_sub();
1307 sub delete_buchungsgruppe {
1308 $main::lxdebug->enter_sub();
1310 my $form = $main::form;
1311 my %myconfig = %main::myconfig;
1312 my $locale = $main::locale;
1314 $main::auth->assert('config');
1316 AM->delete_buchungsgruppe(\%myconfig, \%$form);
1317 $form->redirect($locale->text('Accounting Group deleted!'));
1319 $main::lxdebug->leave_sub();
1322 sub swap_buchungsgruppen {
1323 $main::lxdebug->enter_sub();
1325 my $form = $main::form;
1326 my %myconfig = %main::myconfig;
1328 $main::auth->assert('config');
1330 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
1331 list_buchungsgruppe();
1333 $main::lxdebug->leave_sub();
1337 $main::lxdebug->enter_sub();
1339 my $form = $main::form;
1340 my %myconfig = %main::myconfig;
1341 my $locale = $main::locale;
1343 # get defaults for account numbers and last numbers
1344 AM->defaultaccounts(\%myconfig, \%$form);
1345 $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
1347 map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
1350 my $all_languages = SL::DB::Manager::Language->get_all;
1352 # EÜR = cash, Bilanzierung = accrual
1354 foreach my $key (keys %{ $form->{IC} }) {
1355 foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
1356 my $array = "ACCNOS_" . uc($key);
1357 $form->{$array} ||= [];
1359 my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
1360 push @{ $form->{$array} }, {
1363 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
1368 $form->{title} = $locale->text('Ranges of numbers and default accounts');
1371 print $form->parse_html_template('am/edit_defaults',
1372 { ALL_LANGUAGES => $all_languages, });
1374 $main::lxdebug->leave_sub();
1378 $main::lxdebug->enter_sub();
1380 my $form = $main::form;
1381 my $locale = $main::locale;
1383 AM->save_defaults();
1385 $form->redirect($locale->text('Defaults saved.'));
1387 $main::lxdebug->leave_sub();
1390 sub _build_cfg_options {
1391 my $form = $main::form;
1392 my %myconfig = %main::myconfig;
1395 my $array = uc($idx) . 'S';
1397 $form->{$array} = [];
1398 foreach my $item (@_) {
1399 push @{ $form->{$array} }, {
1402 'selected' => $item eq $myconfig{$idx},
1408 $main::lxdebug->enter_sub();
1410 my $form = $main::form;
1411 my %myconfig = %main::myconfig;
1412 my $locale = $main::locale;
1414 _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
1415 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
1418 if ($::lx_office_conf{print_templates}->{opendocument}
1419 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
1420 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
1421 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
1422 "value" => "opendocument_pdf" });
1424 if ($::lx_office_conf{print_templates}->{latex}) {
1425 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
1427 push(@formats, { "name" => "HTML", "value" => "html" });
1428 if ($::lx_office_conf{print_templates}->{latex}) {
1429 push(@formats, { "name" => $locale->text("Postscript"),
1430 "value" => "postscript" });
1432 if ($::lx_office_conf{print_templates}->{opendocument}) {
1433 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
1434 "value" => "opendocument" });
1437 if (!$myconfig{"template_format"}) {
1438 $myconfig{"template_format"} = "pdf";
1440 $form->{TEMPLATE_FORMATS} = [];
1441 foreach my $item (@formats) {
1442 push @{ $form->{TEMPLATE_FORMATS} }, {
1443 'name' => $item->{name},
1444 'value' => $item->{value},
1445 'selected' => $item->{value} eq $myconfig{template_format},
1449 if (!$myconfig{"default_media"}) {
1450 $myconfig{"default_media"} = "screen";
1453 my %selected = ($myconfig{"default_media"} => "selected");
1455 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
1456 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
1457 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
1460 $form->{PRINTERS} = [ SL::Printer->all_printers(%::myconfig) ];
1462 my %countrycodes = User->country_codes;
1464 $form->{COUNTRYCODES} = [];
1465 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
1466 push @{ $form->{COUNTRYCODES} }, {
1467 'name' => $countrycodes{$countrycode},
1468 'value' => $countrycode,
1469 'selected' => $countrycode eq $myconfig{countrycode},
1473 $form->{STYLESHEETS} = [];
1474 foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
1475 push @{ $form->{STYLESHEETS} }, {
1478 'selected' => $item eq $myconfig{stylesheet},
1482 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
1483 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
1484 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
1486 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
1489 print $form->parse_html_template('am/config');
1491 $main::lxdebug->leave_sub();
1494 sub save_preferences {
1495 $main::lxdebug->enter_sub();
1497 my $form = $main::form;
1498 my %myconfig = %main::myconfig;
1499 my $locale = $main::locale;
1501 $form->{stylesheet} = $form->{usestylesheet};
1503 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
1505 if (AM->save_preferences(\%myconfig, $form)) {
1506 if ($::auth->can_change_password()
1507 && defined $form->{new_password}
1508 && ($form->{new_password} ne '********')) {
1509 my $verifier = SL::Auth::PasswordPolicy->new;
1510 my $result = $verifier->verify($form->{new_password});
1512 if ($result != SL::Auth::PasswordPolicy->OK()) {
1513 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
1516 $::auth->change_password($form->{login}, $form->{new_password});
1518 $form->{password} = $form->{new_password};
1519 $::auth->set_session_value('password', $form->{password});
1520 $::auth->create_or_refresh_session();
1523 $form->redirect($locale->text('Preferences saved!'));
1526 $form->error($locale->text('Cannot save preferences!'));
1528 $main::lxdebug->leave_sub();
1532 $main::lxdebug->enter_sub();
1534 my $form = $main::form;
1535 my %myconfig = %main::myconfig;
1536 my $locale = $main::locale;
1538 $main::auth->assert('config');
1540 $form->{title} = $locale->text('Audit Control');
1542 AM->closedto(\%myconfig, \%$form);
1549 <form method=post action=am.pl>
1552 <tr><th class=listtop>$form->{title}</th></tr>
1553 <tr height="5"></tr>
1558 <th>| . $locale->text('Close Books up to') . qq|</th>
1559 <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
1569 <input type=hidden name=nextsub value=doclose>
1571 <input type=submit class=submit name=action value="|
1572 . $locale->text('Continue') . qq|">
1580 $main::lxdebug->leave_sub();
1584 $main::lxdebug->enter_sub();
1586 my $form = $main::form;
1587 my %myconfig = %main::myconfig;
1588 my $locale = $main::locale;
1590 $main::auth->assert('config');
1592 AM->closebooks(\%myconfig, \%$form);
1594 if ($form->{closedto}) {
1596 $locale->text('Books closed up to') . " "
1597 . $locale->date(\%myconfig, $form->{closedto}, 1));
1599 $form->redirect($locale->text('Books are open'));
1602 $main::lxdebug->leave_sub();
1606 $main::lxdebug->enter_sub();
1608 my $form = $main::form;
1609 my %myconfig = %main::myconfig;
1610 my $locale = $main::locale;
1612 $main::auth->assert('config');
1614 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1615 AM->units_in_use(\%myconfig, $form, $units);
1616 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1618 my @languages = AM->language(\%myconfig, $form, 1);
1620 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1623 foreach (@unit_list) {
1624 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1625 $_->{"UNITLANGUAGES"} = [];
1626 foreach my $lang (@languages) {
1627 push(@{ $_->{"UNITLANGUAGES"} },
1629 "unit" => $_->{"name"},
1630 "language_id" => $lang->{"id"},
1631 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1632 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1638 $units = AM->retrieve_units(\%myconfig, $form);
1639 my $ddbox = AM->unit_select_data($units, undef, 1);
1641 $form->{"title"} = $locale->text("Add and edit units");
1643 print($form->parse_html_template("am/edit_units",
1644 { "UNITS" => \@unit_list,
1645 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1646 "LANGUAGES" => \@languages,
1649 $main::lxdebug->leave_sub();
1653 $main::lxdebug->enter_sub();
1655 my $form = $main::form;
1656 my %myconfig = %main::myconfig;
1657 my $locale = $main::locale;
1659 $main::auth->assert('config');
1661 $form->isblank("new_name", $locale->text("The name is missing."));
1662 my $units = AM->retrieve_units(\%myconfig, $form);
1663 my $all_units = AM->retrieve_units(\%myconfig, $form);
1664 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1666 my ($base_unit, $factor);
1667 if ($form->{"new_base_unit"}) {
1668 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1670 $form->isblank("new_factor", $locale->text("The factor is missing."));
1671 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1672 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1673 $base_unit = $form->{"new_base_unit"};
1677 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1678 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1679 push(@languages, { "id" => $lang->{"id"},
1680 "localized" => $form->{"new_localized_$lang->{id}"},
1681 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1685 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1687 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1691 $main::lxdebug->leave_sub();
1694 sub set_unit_languages {
1695 $main::lxdebug->enter_sub();
1697 my $form = $main::form;
1699 $main::auth->assert('config');
1701 my ($unit, $languages, $idx) = @_;
1703 $unit->{"LANGUAGES"} = [];
1705 foreach my $lang (@{$languages}) {
1706 push(@{ $unit->{"LANGUAGES"} },
1707 { "id" => $lang->{"id"},
1708 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1709 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1713 $main::lxdebug->leave_sub();
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 $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1726 AM->units_in_use(\%myconfig, $form, $old_units);
1728 my @languages = AM->language(\%myconfig, $form, 1);
1731 my @delete_units = ();
1732 foreach my $i (1..($form->{"rowcount"} * 1)) {
1733 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1735 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1738 if ($form->{"unchangeable_$i"}) {
1739 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1740 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1741 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1745 if ($old_unit->{"in_use"}) {
1746 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1749 if ($form->{"delete_$i"}) {
1750 push(@delete_units, $old_unit->{"name"});
1754 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1756 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1757 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1758 $new_units->{$form->{"name_$i"}} = \%h;
1759 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1760 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1763 foreach my $unit (values(%{$new_units})) {
1764 next unless ($unit->{"old_name"});
1765 if ($unit->{"base_unit"}) {
1766 $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"}))
1767 unless (defined($new_units->{$unit->{"base_unit"}}));
1768 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1769 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1771 $unit->{"base_unit"} = undef;
1772 $unit->{"factor"} = undef;
1776 foreach my $unit (values(%{$new_units})) {
1777 next if ($unit->{"unchanged_unit"});
1779 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1780 my $new_unit = $unit;
1781 while ($new_unit->{"base_unit"}) {
1782 $new_unit->{"seen"} = 1;
1783 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1784 if ($new_unit->{"seen"}) {
1785 $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, " .
1786 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1791 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1793 $form->{"saved_message"} = $locale->text("The units have been saved.");
1797 $main::lxdebug->leave_sub();
1800 sub show_history_search {
1801 $main::lxdebug->enter_sub();
1803 my $form = $main::form;
1804 my $locale = $main::locale;
1806 $main::auth->assert('config');
1808 $form->{title} = $locale->text("History Search");
1811 print $form->parse_html_template("common/search_history");
1813 $main::lxdebug->leave_sub();
1816 sub show_am_history {
1817 $main::lxdebug->enter_sub();
1819 my $form = $main::form;
1820 my %myconfig = %main::myconfig;
1821 my $locale = $main::locale;
1823 $main::auth->assert('config');
1825 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1826 $form->{order} ||= 'h.itime--1';
1828 my %search = ( "Artikelnummer" => "parts",
1829 "Kundennummer" => "customer",
1830 "Lieferantennummer" => "vendor",
1831 "Projektnummer" => "project",
1832 "Buchungsnummer" => "oe",
1833 "Eingangsrechnungnummer" => "ap",
1834 "Ausgangsrechnungnummer" => "ar",
1835 "Mahnungsnummer" => "dunning"
1837 my %searchNo = ( "Artikelnummer" => "partnumber",
1838 "Kundennummer" => "customernumber",
1839 "Lieferantennummer" => "vendornumber",
1840 "Projektnummer" => "projectnumber",
1841 "Buchungsnummer" => "ordnumber",
1842 "Eingangsrechnungnummer" => "invnumber",
1843 "Ausgangsrechnungnummer" => "invnumber",
1844 "Mahnungsnummer" => "dunning_id"
1847 my $dbh = $form->dbconnect(\%myconfig);
1850 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1851 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1852 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1853 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1854 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1855 } elsif ($form->{mitarbeiter}) {
1856 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1859 my $query = qq|SELECT trans_id AS id FROM history_erp | .
1860 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
1861 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
1863 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
1864 my $daten .= shift @ids;
1865 $daten .= join '', map { " OR trans_id = $_" } @ids;
1867 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1868 $sort =~ s/.*\.(.*)$/$1/;
1870 $form->{title} = $locale->text("History Search");
1873 print $form->parse_html_template("common/show_history",
1874 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1875 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1878 uc($sort) . "BY" => $sortby,
1879 'callback' => $callback,
1883 $main::lxdebug->leave_sub();
1887 $main::lxdebug->enter_sub();
1889 my $form = $main::form;
1890 my $locale = $main::locale;
1892 $main::auth->assert('config');
1894 $form->{title} = $locale->text('Add');
1896 $form->{callback} ||= "am.pl?action=add_tax";
1898 _get_taxaccount_selection();
1902 my $parameters_ref = {
1903 # ChartTypeIsAccount => $ChartTypeIsAccount,
1906 # Ausgabe des Templates
1907 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1909 $main::lxdebug->leave_sub();
1913 $main::lxdebug->enter_sub();
1915 my $form = $main::form;
1916 my %myconfig = %main::myconfig;
1917 my $locale = $main::locale;
1919 $main::auth->assert('config');
1921 $form->{title} = $locale->text('Edit');
1923 AM->get_tax(\%myconfig, \%$form);
1924 _get_taxaccount_selection();
1926 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1930 my $parameters_ref = {
1933 # Ausgabe des Templates
1934 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1936 $main::lxdebug->leave_sub();
1940 $main::lxdebug->enter_sub();
1942 my $form = $main::form;
1943 my %myconfig = %main::myconfig;
1944 my $locale = $main::locale;
1946 $main::auth->assert('config');
1948 AM->taxes(\%myconfig, \%$form);
1950 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1952 $form->{callback} = build_std_url('action=list_tax');
1954 $form->{title} = $locale->text('Tax-O-Matic');
1958 my $parameters_ref = {
1961 # Ausgabe des Templates
1962 print($form->parse_html_template('am/list_tax', $parameters_ref));
1964 $main::lxdebug->leave_sub();
1967 sub _get_taxaccount_selection{
1968 $main::lxdebug->enter_sub();
1970 my $form = $main::form;
1971 my %myconfig = %main::myconfig;
1973 $main::auth->assert('config');
1975 AM->get_tax_accounts(\%myconfig, \%$form);
1977 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1979 $main::lxdebug->leave_sub();
1983 $main::lxdebug->enter_sub();
1985 my $form = $main::form;
1986 my %myconfig = %main::myconfig;
1987 my $locale = $main::locale;
1989 $main::auth->assert('config');
1991 $form->isblank("rate", $locale->text('Taxrate missing!'));
1992 $form->isblank("taxdescription", $locale->text('Taxdescription missing!'));
1993 $form->isblank("taxkey", $locale->text('Taxkey missing!'));
1995 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1997 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1998 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
2001 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
2002 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
2005 AM->save_tax(\%myconfig, \%$form);
2006 $form->redirect($locale->text('Tax saved!'));
2008 $main::lxdebug->leave_sub();
2012 $main::lxdebug->enter_sub();
2014 my $form = $main::form;
2015 my %myconfig = %main::myconfig;
2016 my $locale = $main::locale;
2018 $main::auth->assert('config');
2020 AM->delete_tax(\%myconfig, \%$form);
2021 $form->redirect($locale->text('Tax deleted!'));
2023 $main::lxdebug->leave_sub();
2026 sub add_price_factor {
2027 $main::lxdebug->enter_sub();
2029 my $form = $main::form;
2030 my $locale = $main::locale;
2032 $main::auth->assert('config');
2034 $form->{title} = $locale->text('Add Price Factor');
2035 $form->{callback} ||= build_std_url('action=add_price_factor');
2036 $form->{fokus} = 'description';
2039 print $form->parse_html_template('am/edit_price_factor');
2041 $main::lxdebug->leave_sub();
2044 sub edit_price_factor {
2045 $main::lxdebug->enter_sub();
2047 my $form = $main::form;
2048 my %myconfig = %main::myconfig;
2049 my $locale = $main::locale;
2051 $main::auth->assert('config');
2053 $form->{title} = $locale->text('Edit Price Factor');
2054 $form->{callback} ||= build_std_url('action=add_price_factor');
2055 $form->{fokus} = 'description';
2057 AM->get_price_factor(\%myconfig, $form);
2059 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
2062 print $form->parse_html_template('am/edit_price_factor');
2064 $main::lxdebug->leave_sub();
2067 sub list_price_factors {
2068 $main::lxdebug->enter_sub();
2070 my $form = $main::form;
2071 my %myconfig = %main::myconfig;
2072 my $locale = $main::locale;
2074 $main::auth->assert('config');
2076 AM->get_all_price_factors(\%myconfig, \%$form);
2078 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
2079 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
2082 $form->{callback} = build_std_url('action=list_price_factors');
2083 $form->{title} = $locale->text('Price Factors');
2084 $form->{url_base} = build_std_url('callback');
2087 print $form->parse_html_template('am/list_price_factors');
2089 $main::lxdebug->leave_sub();
2092 sub save_price_factor {
2093 $main::lxdebug->enter_sub();
2095 my $form = $main::form;
2096 my %myconfig = %main::myconfig;
2097 my $locale = $main::locale;
2099 $main::auth->assert('config');
2101 $form->isblank("description", $locale->text('Description missing!'));
2102 $form->isblank("factor", $locale->text('Factor missing!'));
2104 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
2106 AM->save_price_factor(\%myconfig, $form);
2108 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
2110 $form->redirect($locale->text('Price factor saved!'));
2112 $main::lxdebug->leave_sub();
2115 sub delete_price_factor {
2116 $main::lxdebug->enter_sub();
2118 my $form = $main::form;
2119 my %myconfig = %main::myconfig;
2120 my $locale = $main::locale;
2122 $main::auth->assert('config');
2124 AM->delete_price_factor(\%myconfig, \%$form);
2126 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
2128 $form->redirect($locale->text('Price factor deleted!'));
2130 $main::lxdebug->leave_sub();
2134 $main::lxdebug->enter_sub();
2136 my $form = $main::form;
2137 my $locale = $main::locale;
2139 $main::auth->assert('config');
2141 $form->{title} = $locale->text('Add Warehouse');
2142 $form->{callback} ||= build_std_url('action=add_warehouse');
2143 $form->{fokus} = 'description';
2146 print $form->parse_html_template('am/edit_warehouse');
2148 $main::lxdebug->leave_sub();
2151 sub edit_warehouse {
2152 $main::lxdebug->enter_sub();
2154 my $form = $main::form;
2155 my %myconfig = %main::myconfig;
2156 my $locale = $main::locale;
2158 $main::auth->assert('config');
2160 AM->get_warehouse(\%myconfig, $form);
2162 $form->get_lists('employees' => 'EMPLOYEES');
2164 $form->{title} = $locale->text('Edit Warehouse');
2165 $form->{callback} ||= build_std_url('action=list_warehouses');
2166 $form->{fokus} = 'description';
2169 print $form->parse_html_template('am/edit_warehouse');
2171 $main::lxdebug->leave_sub();
2174 sub list_warehouses {
2175 $main::lxdebug->enter_sub();
2177 my $form = $main::form;
2178 my %myconfig = %main::myconfig;
2179 my $locale = $main::locale;
2181 $main::auth->assert('config');
2183 AM->get_all_warehouses(\%myconfig, $form);
2185 $form->{callback} = build_std_url('action=list_warehouses');
2186 $form->{title} = $locale->text('Warehouses');
2187 $form->{url_base} = build_std_url('callback');
2190 print $form->parse_html_template('am/list_warehouses');
2192 $main::lxdebug->leave_sub();
2195 sub save_warehouse {
2196 $main::lxdebug->enter_sub();
2198 my $form = $main::form;
2199 my %myconfig = %main::myconfig;
2200 my $locale = $main::locale;
2202 $main::auth->assert('config');
2204 $form->isblank("description", $locale->text('Description missing!'));
2206 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
2208 AM->save_warehouse(\%myconfig, $form);
2210 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
2212 $form->redirect($locale->text('Warehouse saved.'));
2214 $main::lxdebug->leave_sub();
2217 sub delete_warehouse {
2218 $main::lxdebug->enter_sub();
2220 my $form = $main::form;
2221 my %myconfig = %main::myconfig;
2222 my $locale = $main::locale;
2224 $main::auth->assert('config');
2226 if (!$form->{confirmed}) {
2227 $form->{title} = $locale->text('Confirmation');
2230 print $form->parse_html_template('am/confirm_delete_warehouse');
2234 if (AM->delete_warehouse(\%myconfig, $form)) {
2235 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
2236 $form->redirect($locale->text('Warehouse deleted.'));
2239 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
2242 $main::lxdebug->leave_sub();
2246 $main::lxdebug->enter_sub();
2248 my $form = $main::form;
2249 my %myconfig = %main::myconfig;
2250 my $locale = $main::locale;
2252 $main::auth->assert('config');
2254 AM->save_bins(\%myconfig, $form);
2256 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
2258 $form->redirect($locale->text('Bins saved.'));
2260 $main::lxdebug->leave_sub();