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 $select_charttype = q{};
334 'A' => $locale->text('Account'),
335 'H' => $locale->text('Heading'),
338 foreach my $item ( sort({ $a <=> $b } keys %charttype) ) {
339 if ($item eq $form->{charttype}) {
340 $select_charttype .= qq|<option value="$item" selected="selected">$charttype{$item}\n|;
343 $select_charttype .= qq|<option value="$item">$charttype{$item}\n|;
348 my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
349 my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
353 my $parameters_ref = {
354 ChartTypeIsAccount => $ChartTypeIsAccount,
355 AccountIsPosted => $AccountIsPosted,
356 select_category => $select_category,
357 select_charttype => $select_charttype,
358 select_bwa => $select_bwa,
359 select_bilanz => $select_bilanz,
360 select_eur => $select_eur,
363 # Ausgabe des Templates
364 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
367 $main::lxdebug->leave_sub();
371 $main::lxdebug->enter_sub();
373 my $form = $main::form;
374 my $locale = $main::locale;
376 $main::auth->assert('config');
380 <input name=callback type=hidden value="| . H($form->{callback}) . qq|">
383 if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) {
385 <input type=submit class=submit name=action value="|
386 . $locale->text('Save') . qq|">
390 if ($form->{id} && $form->{orphaned}) {
391 print qq|<input type=submit class=submit name=action value="|
392 . $locale->text('Delete') . qq|">|;
395 if ($form->{id} && $form->{type} eq "account") {
397 <input class=submit type=submit name=action value="|
398 . $locale->text('Save as new') . qq|">|;
408 $main::lxdebug->leave_sub();
412 $main::lxdebug->enter_sub();
414 my $form = $main::form;
415 my %myconfig = %main::myconfig;
416 my $locale = $main::locale;
418 $main::auth->assert('config');
420 $form->isblank("accno", $locale->text('Account Number missing!'));
421 $form->isblank("description", $locale->text('Account Description missing!'));
423 if ($form->{charttype} eq 'A'){
424 $form->isblank("category", $locale->text('Account Type missing!'));
427 $form->redirect($locale->text('Account saved!'))
428 if (AM->save_account(\%myconfig, \%$form));
429 $form->error($locale->text('Cannot save account!'));
431 $main::lxdebug->leave_sub();
434 sub save_as_new_account {
435 $main::lxdebug->enter_sub();
437 my $form = $main::form;
438 my %myconfig = %main::myconfig;
439 my $locale = $main::locale;
441 $main::auth->assert('config');
443 $form->isblank("accno", $locale->text('Account Number missing!'));
444 $form->isblank("description", $locale->text('Account Description missing!'));
446 if ($form->{charttype} eq 'A'){
447 $form->isblank("category", $locale->text('Account Type missing!'));
450 for my $taxkey (0 .. 9) {
451 if ($form->{"taxkey_id_$taxkey"}) {
452 $form->{"taxkey_id_$taxkey"} = "NEW";
457 if ($form->{"original_accno"} &&
458 ($form->{"accno"} eq $form->{"original_accno"})) {
459 $form->error($locale->text('Account Number already used!'));
461 $form->redirect($locale->text('Account saved!'))
462 if (AM->save_account(\%myconfig, \%$form));
463 $form->error($locale->text('Cannot save account!'));
465 $main::lxdebug->leave_sub();
469 $main::lxdebug->enter_sub();
471 my $form = $main::form;
472 my %myconfig = %main::myconfig;
473 my $locale = $main::locale;
475 $main::auth->assert('config');
477 $form->{callback} = build_std_url('action=list_account');
478 my $link_edit_account = build_std_url('action=edit_account', 'callback');
480 CA->all_accounts(\%myconfig, \%$form);
482 foreach my $ca (@{ $form->{CA} }) {
487 if ($ca->{amount} > 0) {
488 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
490 if ($ca->{amount} < 0) {
491 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
493 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
494 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
497 $form->use_stylesheet("list_accounts.css");
498 $form->{title} = $locale->text('Chart of Accounts');
503 my $parameters_ref = {
504 # hidden_variables => $_hidden_variables_ref,
507 # Ausgabe des Templates
508 print($form->parse_html_template('am/list_accounts', $parameters_ref));
510 $main::lxdebug->leave_sub();
515 sub list_account_details {
516 # Ajax Funktion aus list_account_details
517 $main::lxdebug->enter_sub();
519 my $form = $main::form;
520 my %myconfig = %main::myconfig;
521 my $locale = $main::locale;
523 $main::auth->assert('config');
525 my $chart_id = $form->{args};
527 CA->all_accounts(\%myconfig, \%$form, $chart_id);
529 foreach my $ca (@{ $form->{CA} }) {
531 $ca->{debit} = " ";
532 $ca->{credit} = " ";
534 if ($ca->{amount} > 0) {
536 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
538 if ($ca->{amount} < 0) {
540 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
543 my @links = split( q{:}, $ca->{link});
547 foreach my $link (@links){
548 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
549 : ( $link eq 'AP') ? $locale->text('Account Link AP')
550 : ( $link eq 'IC') ? $locale->text('Account Link IC')
551 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
552 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
553 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
554 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
555 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
556 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
557 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
558 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
559 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
560 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
561 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
562 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
563 # : ( $link eq 'CT_tax' ) ? $locale->text('Account Link CT_tax')
564 : $locale->text('Unknown Link') . ': ' . $link;
565 $ca->{link} .= ($link ne '') ? "[$link] ":'';
568 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
569 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
570 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
571 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
572 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
573 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
574 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
575 : $locale->text('Unknown Category') . ': ' . $ca->{category};
578 $form->{title} = $locale->text('Chart of Accounts');
580 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
582 $main::lxdebug->leave_sub();
587 $main::lxdebug->enter_sub();
589 my $form = $main::form;
590 my %myconfig = %main::myconfig;
591 my $locale = $main::locale;
593 $main::auth->assert('config');
595 $form->{title} = $locale->text('Delete Account');
598 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
600 if ($form->{id} == $form->{$id}) {
601 $form->error($locale->text('Cannot delete default account!'));
605 $form->redirect($locale->text('Account deleted!'))
606 if (AM->delete_account(\%myconfig, \%$form));
607 $form->error($locale->text('Cannot delete account!'));
609 $main::lxdebug->leave_sub();
613 $main::lxdebug->enter_sub();
615 my $form = $main::form;
617 $main::auth->assert('config');
619 $form->{title} = "Add";
621 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
626 $main::lxdebug->leave_sub();
630 $main::lxdebug->enter_sub();
632 my $form = $main::form;
633 my %myconfig = %main::myconfig;
635 $main::auth->assert('config');
637 $form->{title} = "Edit";
639 AM->get_lead(\%myconfig, \%$form);
643 $form->{orphaned} = 1;
646 $main::lxdebug->leave_sub();
650 $main::lxdebug->enter_sub();
652 my $form = $main::form;
653 my %myconfig = %main::myconfig;
654 my $locale = $main::locale;
656 $main::auth->assert('config');
658 AM->lead(\%myconfig, \%$form);
660 $form->{callback} = "am.pl?action=list_lead";
662 my $callback = $form->escape($form->{callback});
664 $form->{title} = $locale->text('Lead');
666 my @column_index = qw(description cost profit);
668 $column_header{description} =
669 qq|<th class=listheading width=100%>|
670 . $locale->text('Description')
680 <th class=listtop>$form->{title}</th>
683 <tr class=listheading>
686 map { print "$column_header{$_}\n" } @column_index;
692 my ($i, %column_data);
693 foreach my $ref (@{ $form->{ALL} }) {
699 <tr valign=top class=listrow$i>
702 # $lead = $ref->{lead};
704 $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
706 map { print "$column_data{$_}\n" } @column_index;
715 <td><hr size=3 noshade></td>
720 <form method=post action=am.pl>
722 <input name=callback type=hidden value="$form->{callback}">
724 <input type=hidden name=type value=lead>
726 <input class=submit type=submit name=action value="|
727 . $locale->text('Add') . qq|">
735 $main::lxdebug->leave_sub();
739 $main::lxdebug->enter_sub();
741 my $form = $main::form;
742 my $locale = $main::locale;
744 $main::auth->assert('config');
746 $form->{title} = $locale->text("$form->{title} Lead");
748 # $locale->text('Add Lead')
749 # $locale->text('Edit Lead')
751 $form->{description} =~ s/\"/"/g;
754 qq|<input name=description size=50 value="$form->{lead}">|;
761 <form method=post action=am.pl>
763 <input type=hidden name=id value=$form->{id}>
764 <input type=hidden name=type value=lead>
768 <th class=listtop colspan=2>$form->{title}</th>
772 <th align=right>| . $locale->text('Description') . qq|</th>
773 <td>$description</td>
775 <td colspan=2><hr size=3 noshade></td>
780 $main::lxdebug->leave_sub();
784 $main::lxdebug->enter_sub();
786 my $form = $main::form;
787 my %myconfig = %main::myconfig;
788 my $locale = $main::locale;
790 $main::auth->assert('config');
792 $form->isblank("description", $locale->text('Description missing!'));
793 AM->save_lead(\%myconfig, \%$form);
794 $form->redirect($locale->text('lead saved!'));
796 $main::lxdebug->leave_sub();
800 $main::lxdebug->enter_sub();
802 my $form = $main::form;
803 my %myconfig = %main::myconfig;
804 my $locale = $main::locale;
806 $main::auth->assert('config');
808 AM->delete_lead(\%myconfig, \%$form);
809 $form->redirect($locale->text('lead deleted!'));
811 $main::lxdebug->leave_sub();
815 $main::lxdebug->enter_sub();
817 my $form = $main::form;
819 $main::auth->assert('config');
821 $form->{title} = "Add";
823 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
828 $main::lxdebug->leave_sub();
832 $main::lxdebug->enter_sub();
834 my $form = $main::form;
835 my %myconfig = %main::myconfig;
837 $main::auth->assert('config');
839 $form->{title} = "Edit";
841 AM->get_language(\%myconfig, \%$form);
845 $form->{orphaned} = 1;
848 $main::lxdebug->leave_sub();
852 $main::lxdebug->enter_sub();
854 my $form = $main::form;
855 my %myconfig = %main::myconfig;
856 my $locale = $main::locale;
858 $main::auth->assert('config');
860 AM->language(\%myconfig, \%$form);
862 $form->{callback} = "am.pl?action=list_language";
864 my $callback = $form->escape($form->{callback});
866 $form->{title} = $locale->text('Languages');
868 my @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
870 $column_header{description} =
871 qq|<th class=listheading width=60%>|
872 . $locale->text('Description')
874 $column_header{template_code} =
875 qq|<th class=listheading width=10%>|
876 . $locale->text('Template Code')
878 $column_header{article_code} =
879 qq|<th class=listheading>|
880 . $locale->text('Article Code')
882 $column_header{output_numberformat} =
883 qq|<th class=listheading>|
884 . $locale->text('Number Format')
886 $column_header{output_dateformat} =
887 qq|<th class=listheading>|
888 . $locale->text('Date Format')
890 $column_header{output_longdates} =
891 qq|<th class=listheading>|
892 . $locale->text('Long Dates')
902 <th class=listtop>$form->{title}</th>
908 <tr class=listheading>
911 map { print "$column_header{$_}\n" } @column_index;
917 my ($i, %column_data);
918 foreach my $ref (@{ $form->{ALL} }) {
924 <tr valign=top class=listrow$i>
928 $column_data{description} =
929 qq|<td><a href="am.pl?action=edit_language&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
930 $column_data{template_code} = qq|<td align=right>$ref->{template_code}</td>|;
931 $column_data{article_code} =
932 qq|<td align=right>$ref->{article_code}</td>|;
933 $column_data{output_numberformat} =
935 ($ref->{output_numberformat} ? $ref->{output_numberformat} :
936 $locale->text("use program settings")) .
938 $column_data{output_dateformat} =
940 ($ref->{output_dateformat} ? $ref->{output_dateformat} :
941 $locale->text("use program settings")) .
943 $column_data{output_longdates} =
945 ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
948 map { print "$column_data{$_}\n" } @column_index;
960 <td><hr size=3 noshade></td>
965 <form method=post action=am.pl>
967 <input name=callback type=hidden value="$form->{callback}">
969 <input type=hidden name=type value=language>
971 <input class=submit type=submit name=action value="|
972 . $locale->text('Add') . qq|">
980 $main::lxdebug->leave_sub();
983 sub language_header {
984 $main::lxdebug->enter_sub();
986 my $form = $main::form;
987 my $locale = $main::locale;
989 $main::auth->assert('config');
991 $form->{title} = $locale->text("$form->{title} Language");
993 # $locale->text('Add Language')
994 # $locale->text('Edit Language')
996 $form->{description} =~ s/\"/"/g;
997 $form->{template_code} =~ s/\"/"/g;
998 $form->{article_code} =~ s/\"/"/g;
1004 qq|<option value="">| . $locale->text("use program settings") .
1006 foreach my $item (('1,000.00', '1000.00', '1.000,00', '1000,00')) {
1008 ($item eq $form->{output_numberformat})
1009 ? "<option selected>$item"
1015 qq|<option value="">| . $locale->text("use program settings") .
1017 foreach my $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
1019 ($item eq $form->{output_dateformat})
1020 ? "<option selected>$item"
1028 <form method=post action=am.pl>
1030 <input type=hidden name=id value=$form->{id}>
1031 <input type=hidden name=type value=language>
1035 <th class=listtop colspan=2>$form->{title}</th>
1037 <tr height="5"></tr>
1039 <th align=right>| . $locale->text('Language') . qq|</th>
1040 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1043 <th align=right>| . $locale->text('Template Code') . qq|</th>
1044 <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
1047 <th align=right>| . $locale->text('Article Code') . qq|</th>
1048 <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
1051 <th align=right>| . $locale->text('Number Format') . qq|</th>
1052 <td><select name="output_numberformat">$numberformat</select></td>
1055 <th align=right>| . $locale->text('Date Format') . qq|</th>
1056 <td><select name="output_dateformat">$dateformat</select></td>
1059 <th align=right>| . $locale->text('Long Dates') . qq|</th>
1060 <td><input type="radio" name="output_longdates" value="1"| .
1061 ($form->{output_longdates} ? " checked" : "") .
1062 qq|>| . $locale->text("Yes") .
1063 qq|<input type="radio" name="output_longdates" value="0"| .
1064 ($form->{output_longdates} ? "" : " checked") .
1065 qq|>| . $locale->text("No") .
1068 <td colspan=2><hr size=3 noshade></td>
1073 $main::lxdebug->leave_sub();
1077 $main::lxdebug->enter_sub();
1079 my $form = $main::form;
1080 my %myconfig = %main::myconfig;
1081 my $locale = $main::locale;
1083 $main::auth->assert('config');
1085 $form->isblank("description", $locale->text('Language missing!'));
1086 $form->isblank("template_code", $locale->text('Template Code missing!'));
1087 $form->isblank("article_code", $locale->text('Article Code missing!'));
1088 AM->save_language(\%myconfig, \%$form);
1089 $form->redirect($locale->text('Language saved!'));
1091 $main::lxdebug->leave_sub();
1094 sub delete_language {
1095 $main::lxdebug->enter_sub();
1097 my $form = $main::form;
1098 my %myconfig = %main::myconfig;
1099 my $locale = $main::locale;
1101 $main::auth->assert('config');
1103 AM->delete_language(\%myconfig, \%$form);
1104 $form->redirect($locale->text('Language deleted!'));
1106 $main::lxdebug->leave_sub();
1110 sub add_buchungsgruppe {
1111 $main::lxdebug->enter_sub();
1113 my $form = $main::form;
1114 my %myconfig = %main::myconfig;
1115 my $locale = $main::locale;
1117 $main::auth->assert('config');
1119 # $locale->text("Add Buchungsgruppe")
1120 # $locale->text("Edit Buchungsgruppe")
1121 $form->{title} = "Add";
1123 $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
1125 AM->get_buchungsgruppe(\%myconfig, \%$form);
1126 $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
1127 for (my $i = 0; 4 > $i; $i++) {
1128 map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
1129 qw(income expense));
1132 &buchungsgruppe_header;
1135 $main::lxdebug->leave_sub();
1138 sub edit_buchungsgruppe {
1139 $main::lxdebug->enter_sub();
1141 my $form = $main::form;
1142 my %myconfig = %main::myconfig;
1144 $main::auth->assert('config');
1146 $form->{title} = "Edit";
1148 AM->get_buchungsgruppe(\%myconfig, \%$form);
1150 &buchungsgruppe_header;
1154 $main::lxdebug->leave_sub();
1157 sub list_buchungsgruppe {
1158 $main::lxdebug->enter_sub();
1160 my $form = $main::form;
1161 my %myconfig = %main::myconfig;
1162 my $locale = $main::locale;
1164 $main::auth->assert('config');
1166 AM->buchungsgruppe(\%myconfig, \%$form);
1168 $form->{callback} = "am.pl?action=list_buchungsgruppe";
1170 my $callback = $form->escape($form->{callback});
1172 $form->{title} = $locale->text('Buchungsgruppen');
1174 my @column_index = qw(up down description inventory_accno
1175 income_accno_0 expense_accno_0
1176 income_accno_1 expense_accno_1
1177 income_accno_2 expense_accno_2
1178 income_accno_3 expense_accno_3 );
1180 $column_header{up} =
1181 qq|<th class="listheading" width="16">|
1182 . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
1184 $column_header{down} =
1185 qq|<th class="listheading" width="16">|
1186 . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
1188 $column_header{description} =
1189 qq|<th class="listheading" width="40%">|
1190 . $locale->text('Description')
1192 $column_header{inventory_accno} =
1193 qq|<th class=listheading>|
1194 . $locale->text('Bestandskonto')
1196 $column_header{income_accno_0} =
1197 qq|<th class=listheading>|
1198 . $locale->text('National Revenues')
1200 $column_header{expense_accno_0} =
1201 qq|<th class=listheading>|
1202 . $locale->text('National Expenses')
1204 $column_header{income_accno_1} =
1205 qq|<th class=listheading>|
1206 . $locale->text('Revenues EU with UStId')
1208 $column_header{expense_accno_1} =
1209 qq|<th class=listheading>|
1210 . $locale->text('Expenses EU with UStId')
1212 $column_header{income_accno_2} =
1213 qq|<th class=listheading>|
1214 . $locale->text('Revenues EU without UStId')
1216 $column_header{expense_accno_2} =
1217 qq|<th class=listheading>|
1218 . $locale->text('Expenses EU without UStId')
1220 $column_header{income_accno_3} =
1221 qq|<th class=listheading>|
1222 . $locale->text('Foreign Revenues')
1224 $column_header{expense_accno_3} =
1225 qq|<th class=listheading>|
1226 . $locale->text('Foreign Expenses')
1235 <th class=listtop>$form->{title}</th>
1237 <tr height="5"></tr>
1241 <tr class=listheading>
1244 map { print "$column_header{$_}\n" } @column_index;
1250 my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
1253 my ($i, %column_data);
1254 foreach my $ref (@{ $form->{ALL} }) {
1260 <tr valign=top class=listrow$i>
1264 my $pref = $form->{ALL}->[$row - 1];
1266 qq|<td align="center" valign="center" width="16">| .
1267 qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
1268 qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
1271 $column_data{up} = qq|<td width="16"> </td>|;
1274 if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
1275 $column_data{down} = qq|<td width="16"> </td>|;
1277 my $nref = $form->{ALL}->[$row + 1];
1278 $column_data{down} =
1279 qq|<td align="center" valign="center" width="16">| .
1280 qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
1281 qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
1285 $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
1286 $column_data{inventory_accno} = qq|<td align=right>$ref->{inventory_accno}</td>|;
1287 $column_data{income_accno_0} =
1288 qq|<td align=right>$ref->{income_accno_0}</td>|;
1289 $column_data{expense_accno_0} = qq|<td align=right>$ref->{expense_accno_0}</td>|;
1290 $column_data{income_accno_1} =
1291 qq|<td align=right>$ref->{income_accno_1}</td>|;
1292 $column_data{expense_accno_1} = qq|<td align=right>$ref->{expense_accno_1}</td>|;
1293 $column_data{income_accno_2} =
1294 qq|<td align=right>$ref->{income_accno_2}</td>|;
1295 $column_data{expense_accno_2} = qq|<td align=right>$ref->{expense_accno_2}</td>|;
1296 $column_data{income_accno_3} =
1297 qq|<td align=right>$ref->{income_accno_3}</td>|;
1298 $column_data{expense_accno_3} = qq|<td align=right>$ref->{expense_accno_3}</td>|;
1300 map { print "$column_data{$_}\n" } @column_index;
1314 <td><hr size=3 noshade></td>
1319 <form method=post action=am.pl>
1321 <input name=callback type=hidden value="$form->{callback}">
1323 <input type=hidden name=type value=buchungsgruppe>
1325 <input class=submit type=submit name=action value="|
1326 . $locale->text('Add') . qq|">
1334 $main::lxdebug->leave_sub();
1337 sub buchungsgruppe_header {
1338 $main::lxdebug->enter_sub();
1340 my $form = $main::form;
1341 my $locale = $main::locale;
1343 $main::auth->assert('config');
1345 $form->{title} = $locale->text("$form->{title} Buchungsgruppe");
1347 # $locale->text('Add Accounting Group')
1348 # $locale->text('Edit Accounting Group')
1350 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
1351 my %acc_type_map = (
1352 "IC" => $acc_inventory,
1353 "IC_income" => $acc_income,
1354 "IC_sale" => $acc_income,
1355 "IC_expense" => $acc_expense,
1356 "IC_cogs" => $acc_expense,
1359 foreach my $key (keys(%acc_type_map)) {
1360 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1361 $acc_type_map{$key}->{$ref->{"id"}} = $ref;
1365 foreach my $type (qw(IC IC_income IC_expense)) {
1366 $form->{"select$type"} =
1368 map({ "<option value=$_->{id} $_->{selected}>" .
1369 "$_->{accno}--" . H($_->{description}) . "</option>" }
1370 sort({ $a->{"accno"} cmp $b->{"accno"} }
1371 values(%{$acc_type_map{$type}}))));
1375 $form->{selectIC} =~ s/selected//g;
1376 $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/ value=$form->{inventory_accno_id} selected/;
1377 $form->{selectIC_income} =~ s/selected//g;
1378 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/ value=$form->{income_accno_id_0} selected/;
1379 $form->{selectIC_expense} =~ s/selected//g;
1380 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/ value=$form->{expense_accno_id_0} selected/;
1384 if ( $::instance_conf->get_inventory_system eq 'perpetual' ) { # was !$::lx_office_conf{system}->{eur}) {
1387 <th align=right>| . $locale->text('Inventory') . qq|</th>
1388 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
1389 <input name=selectIC type=hidden value="$form->{selectIC}">
1391 } elsif ( $::instance_conf->get_inventory_system eq 'periodic' ) {
1392 # don't allow choice of inventory accno and don't show that line
1394 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
1398 $linkaccounts .= qq|
1400 <th align=right>| . $locale->text('National Revenues') . qq|</th>
1401 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
1404 <th align=right>| . $locale->text('National Expenses') . qq|</th>
1405 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
1408 $form->{selectIC_income} =~ s/selected//g;
1409 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/ value=$form->{income_accno_id_1} selected/;
1410 $form->{selectIC_expense} =~ s/selected//g;
1411 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/ value=$form->{expense_accno_id_1} selected/;
1413 $linkaccounts .= qq| <tr>
1414 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
1415 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
1418 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
1419 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
1423 $form->{selectIC_income} =~ s/selected//g;
1424 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/ value=$form->{income_accno_id_2} selected/;
1425 $form->{selectIC_expense} =~ s/selected//g;
1426 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/ value=$form->{expense_accno_id_2} selected/;
1429 $linkaccounts .= qq| <tr>
1430 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
1431 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
1434 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
1435 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
1439 $form->{selectIC_income} =~ s/selected//g;
1440 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/ value=$form->{income_accno_id_3} selected/;
1441 $form->{selectIC_expense} =~ s/selected//g;
1442 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/ value=$form->{expense_accno_id_3} selected/;
1445 $linkaccounts .= qq| <tr>
1446 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
1447 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
1450 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
1451 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
1461 <form method=post action=am.pl>
1463 <input type=hidden name=id value=$form->{id}>
1464 <input type=hidden name=type value=buchungsgruppe>
1468 <th class=listtop colspan=2>$form->{title}</th>
1470 <tr height="5"></tr>
1472 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
1473 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1476 <td colspan=2><hr size=3 noshade></td>
1481 $main::lxdebug->leave_sub();
1484 sub save_buchungsgruppe {
1485 $main::lxdebug->enter_sub();
1487 my $form = $main::form;
1488 my %myconfig = %main::myconfig;
1489 my $locale = $main::locale;
1491 $main::auth->assert('config');
1493 $form->isblank("description", $locale->text('Description missing!'));
1495 AM->save_buchungsgruppe(\%myconfig, \%$form);
1496 $form->redirect($locale->text('Accounting Group saved!'));
1498 $main::lxdebug->leave_sub();
1501 sub delete_buchungsgruppe {
1502 $main::lxdebug->enter_sub();
1504 my $form = $main::form;
1505 my %myconfig = %main::myconfig;
1506 my $locale = $main::locale;
1508 $main::auth->assert('config');
1510 AM->delete_buchungsgruppe(\%myconfig, \%$form);
1511 $form->redirect($locale->text('Accounting Group deleted!'));
1513 $main::lxdebug->leave_sub();
1516 sub swap_buchungsgruppen {
1517 $main::lxdebug->enter_sub();
1519 my $form = $main::form;
1520 my %myconfig = %main::myconfig;
1522 $main::auth->assert('config');
1524 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
1525 list_buchungsgruppe();
1527 $main::lxdebug->leave_sub();
1531 $main::lxdebug->enter_sub();
1533 my $form = $main::form;
1534 my %myconfig = %main::myconfig;
1535 my $locale = $main::locale;
1537 # get defaults for account numbers and last numbers
1538 AM->defaultaccounts(\%myconfig, \%$form);
1539 $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
1541 map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
1544 my $all_languages = SL::DB::Manager::Language->get_all;
1546 # EÜR = cash, Bilanzierung = accrual
1548 foreach my $key (keys %{ $form->{IC} }) {
1549 foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
1550 my $array = "ACCNOS_" . uc($key);
1551 $form->{$array} ||= [];
1553 my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
1554 push @{ $form->{$array} }, {
1557 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
1562 $form->{title} = $locale->text('Ranges of numbers and default accounts');
1565 print $form->parse_html_template('am/edit_defaults',
1566 { ALL_LANGUAGES => $all_languages, });
1568 $main::lxdebug->leave_sub();
1572 $main::lxdebug->enter_sub();
1574 my $form = $main::form;
1575 my $locale = $main::locale;
1577 AM->save_defaults();
1579 $form->redirect($locale->text('Defaults saved.'));
1581 $main::lxdebug->leave_sub();
1584 sub _build_cfg_options {
1585 my $form = $main::form;
1586 my %myconfig = %main::myconfig;
1589 my $array = uc($idx) . 'S';
1591 $form->{$array} = [];
1592 foreach my $item (@_) {
1593 push @{ $form->{$array} }, {
1596 'selected' => $item eq $myconfig{$idx},
1602 $main::lxdebug->enter_sub();
1604 my $form = $main::form;
1605 my %myconfig = %main::myconfig;
1606 my $locale = $main::locale;
1608 _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
1609 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
1612 if ($::lx_office_conf{print_templates}->{opendocument}
1613 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
1614 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
1615 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
1616 "value" => "opendocument_pdf" });
1618 if ($::lx_office_conf{print_templates}->{latex}) {
1619 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
1621 push(@formats, { "name" => "HTML", "value" => "html" });
1622 if ($::lx_office_conf{print_templates}->{latex}) {
1623 push(@formats, { "name" => $locale->text("Postscript"),
1624 "value" => "postscript" });
1626 if ($::lx_office_conf{print_templates}->{opendocument}) {
1627 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
1628 "value" => "opendocument" });
1631 if (!$myconfig{"template_format"}) {
1632 $myconfig{"template_format"} = "pdf";
1634 $form->{TEMPLATE_FORMATS} = [];
1635 foreach my $item (@formats) {
1636 push @{ $form->{TEMPLATE_FORMATS} }, {
1637 'name' => $item->{name},
1638 'value' => $item->{value},
1639 'selected' => $item->{value} eq $myconfig{template_format},
1643 if (!$myconfig{"default_media"}) {
1644 $myconfig{"default_media"} = "screen";
1647 my %selected = ($myconfig{"default_media"} => "selected");
1649 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
1650 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
1651 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
1654 $form->{PRINTERS} = [ SL::Printer->all_printers(%::myconfig) ];
1656 my %countrycodes = User->country_codes;
1658 $form->{COUNTRYCODES} = [];
1659 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
1660 push @{ $form->{COUNTRYCODES} }, {
1661 'name' => $countrycodes{$countrycode},
1662 'value' => $countrycode,
1663 'selected' => $countrycode eq $myconfig{countrycode},
1667 $form->{STYLESHEETS} = [];
1668 foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
1669 push @{ $form->{STYLESHEETS} }, {
1672 'selected' => $item eq $myconfig{stylesheet},
1676 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
1677 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
1678 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
1680 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
1683 print $form->parse_html_template('am/config');
1685 $main::lxdebug->leave_sub();
1688 sub save_preferences {
1689 $main::lxdebug->enter_sub();
1691 my $form = $main::form;
1692 my %myconfig = %main::myconfig;
1693 my $locale = $main::locale;
1695 $form->{stylesheet} = $form->{usestylesheet};
1697 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
1699 if (AM->save_preferences(\%myconfig, $form)) {
1700 if ($::auth->can_change_password()
1701 && defined $form->{new_password}
1702 && ($form->{new_password} ne '********')) {
1703 my $verifier = SL::Auth::PasswordPolicy->new;
1704 my $result = $verifier->verify($form->{new_password});
1706 if ($result != SL::Auth::PasswordPolicy->OK()) {
1707 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
1710 $::auth->change_password($form->{login}, $form->{new_password});
1712 $form->{password} = $form->{new_password};
1713 $::auth->set_session_value('password', $form->{password});
1714 $::auth->create_or_refresh_session();
1717 $form->redirect($locale->text('Preferences saved!'));
1720 $form->error($locale->text('Cannot save preferences!'));
1722 $main::lxdebug->leave_sub();
1726 $main::lxdebug->enter_sub();
1728 my $form = $main::form;
1729 my %myconfig = %main::myconfig;
1730 my $locale = $main::locale;
1732 $main::auth->assert('config');
1734 $form->{title} = $locale->text('Audit Control');
1736 AM->closedto(\%myconfig, \%$form);
1743 <form method=post action=am.pl>
1746 <tr><th class=listtop>$form->{title}</th></tr>
1747 <tr height="5"></tr>
1752 <th>| . $locale->text('Close Books up to') . qq|</th>
1753 <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
1763 <input type=hidden name=nextsub value=doclose>
1765 <input type=submit class=submit name=action value="|
1766 . $locale->text('Continue') . qq|">
1774 $main::lxdebug->leave_sub();
1778 $main::lxdebug->enter_sub();
1780 my $form = $main::form;
1781 my %myconfig = %main::myconfig;
1782 my $locale = $main::locale;
1784 $main::auth->assert('config');
1786 AM->closebooks(\%myconfig, \%$form);
1788 if ($form->{closedto}) {
1790 $locale->text('Books closed up to') . " "
1791 . $locale->date(\%myconfig, $form->{closedto}, 1));
1793 $form->redirect($locale->text('Books are open'));
1796 $main::lxdebug->leave_sub();
1800 $main::lxdebug->enter_sub();
1802 my $form = $main::form;
1803 my %myconfig = %main::myconfig;
1804 my $locale = $main::locale;
1806 $main::auth->assert('config');
1808 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1809 AM->units_in_use(\%myconfig, $form, $units);
1810 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1812 my @languages = AM->language(\%myconfig, $form, 1);
1814 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1817 foreach (@unit_list) {
1818 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1819 $_->{"UNITLANGUAGES"} = [];
1820 foreach my $lang (@languages) {
1821 push(@{ $_->{"UNITLANGUAGES"} },
1823 "unit" => $_->{"name"},
1824 "language_id" => $lang->{"id"},
1825 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1826 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1832 $units = AM->retrieve_units(\%myconfig, $form);
1833 my $ddbox = AM->unit_select_data($units, undef, 1);
1835 $form->{"title"} = $locale->text("Add and edit units");
1837 print($form->parse_html_template("am/edit_units",
1838 { "UNITS" => \@unit_list,
1839 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1840 "LANGUAGES" => \@languages,
1843 $main::lxdebug->leave_sub();
1847 $main::lxdebug->enter_sub();
1849 my $form = $main::form;
1850 my %myconfig = %main::myconfig;
1851 my $locale = $main::locale;
1853 $main::auth->assert('config');
1855 $form->isblank("new_name", $locale->text("The name is missing."));
1856 my $units = AM->retrieve_units(\%myconfig, $form);
1857 my $all_units = AM->retrieve_units(\%myconfig, $form);
1858 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1860 my ($base_unit, $factor);
1861 if ($form->{"new_base_unit"}) {
1862 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1864 $form->isblank("new_factor", $locale->text("The factor is missing."));
1865 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1866 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1867 $base_unit = $form->{"new_base_unit"};
1871 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1872 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1873 push(@languages, { "id" => $lang->{"id"},
1874 "localized" => $form->{"new_localized_$lang->{id}"},
1875 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1879 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1881 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1885 $main::lxdebug->leave_sub();
1888 sub set_unit_languages {
1889 $main::lxdebug->enter_sub();
1891 my $form = $main::form;
1893 $main::auth->assert('config');
1895 my ($unit, $languages, $idx) = @_;
1897 $unit->{"LANGUAGES"} = [];
1899 foreach my $lang (@{$languages}) {
1900 push(@{ $unit->{"LANGUAGES"} },
1901 { "id" => $lang->{"id"},
1902 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1903 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1907 $main::lxdebug->leave_sub();
1911 $main::lxdebug->enter_sub();
1913 my $form = $main::form;
1914 my %myconfig = %main::myconfig;
1915 my $locale = $main::locale;
1917 $main::auth->assert('config');
1919 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1920 AM->units_in_use(\%myconfig, $form, $old_units);
1922 my @languages = AM->language(\%myconfig, $form, 1);
1925 my @delete_units = ();
1926 foreach my $i (1..($form->{"rowcount"} * 1)) {
1927 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1929 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1932 if ($form->{"unchangeable_$i"}) {
1933 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1934 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1935 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1939 if ($old_unit->{"in_use"}) {
1940 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1943 if ($form->{"delete_$i"}) {
1944 push(@delete_units, $old_unit->{"name"});
1948 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1950 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1951 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1952 $new_units->{$form->{"name_$i"}} = \%h;
1953 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1954 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1957 foreach my $unit (values(%{$new_units})) {
1958 next unless ($unit->{"old_name"});
1959 if ($unit->{"base_unit"}) {
1960 $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"}))
1961 unless (defined($new_units->{$unit->{"base_unit"}}));
1962 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1963 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1965 $unit->{"base_unit"} = undef;
1966 $unit->{"factor"} = undef;
1970 foreach my $unit (values(%{$new_units})) {
1971 next if ($unit->{"unchanged_unit"});
1973 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1974 my $new_unit = $unit;
1975 while ($new_unit->{"base_unit"}) {
1976 $new_unit->{"seen"} = 1;
1977 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1978 if ($new_unit->{"seen"}) {
1979 $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, " .
1980 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1985 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1987 $form->{"saved_message"} = $locale->text("The units have been saved.");
1991 $main::lxdebug->leave_sub();
1994 sub show_history_search {
1995 $main::lxdebug->enter_sub();
1997 my $form = $main::form;
1998 my $locale = $main::locale;
2000 $main::auth->assert('config');
2002 $form->{title} = $locale->text("History Search");
2005 print $form->parse_html_template("common/search_history");
2007 $main::lxdebug->leave_sub();
2010 sub show_am_history {
2011 $main::lxdebug->enter_sub();
2013 my $form = $main::form;
2014 my %myconfig = %main::myconfig;
2015 my $locale = $main::locale;
2017 $main::auth->assert('config');
2019 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
2020 $form->{order} ||= 'h.itime--1';
2022 my %search = ( "Artikelnummer" => "parts",
2023 "Kundennummer" => "customer",
2024 "Lieferantennummer" => "vendor",
2025 "Projektnummer" => "project",
2026 "Buchungsnummer" => "oe",
2027 "Eingangsrechnungnummer" => "ap",
2028 "Ausgangsrechnungnummer" => "ar",
2029 "Mahnungsnummer" => "dunning"
2031 my %searchNo = ( "Artikelnummer" => "partnumber",
2032 "Kundennummer" => "customernumber",
2033 "Lieferantennummer" => "vendornumber",
2034 "Projektnummer" => "projectnumber",
2035 "Buchungsnummer" => "ordnumber",
2036 "Eingangsrechnungnummer" => "invnumber",
2037 "Ausgangsrechnungnummer" => "invnumber",
2038 "Mahnungsnummer" => "dunning_id"
2041 my $dbh = $form->dbconnect(\%myconfig);
2044 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
2045 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
2046 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
2047 if ($form->{mitarbeiter} =~ m/^\d+$/) {
2048 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
2049 } elsif ($form->{mitarbeiter}) {
2050 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
2053 my $query = qq|SELECT trans_id AS id FROM history_erp | .
2054 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
2055 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
2057 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
2058 my $daten .= shift @ids;
2059 $daten .= join '', map { " OR trans_id = $_" } @ids;
2061 my ($sort, $sortby) = split(/\-\-/, $form->{order});
2062 $sort =~ s/.*\.(.*)$/$1/;
2064 $form->{title} = $locale->text("History Search");
2067 print $form->parse_html_template("common/show_history",
2068 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
2069 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
2072 uc($sort) . "BY" => $sortby,
2073 'callback' => $callback,
2077 $main::lxdebug->leave_sub();
2081 $main::lxdebug->enter_sub();
2083 my $form = $main::form;
2084 my $locale = $main::locale;
2086 $main::auth->assert('config');
2088 $form->{title} = $locale->text('Add');
2090 $form->{callback} ||= "am.pl?action=add_tax";
2092 _get_taxaccount_selection();
2096 my $parameters_ref = {
2097 # ChartTypeIsAccount => $ChartTypeIsAccount,
2100 # Ausgabe des Templates
2101 print($form->parse_html_template('am/edit_tax', $parameters_ref));
2103 $main::lxdebug->leave_sub();
2107 $main::lxdebug->enter_sub();
2109 my $form = $main::form;
2110 my %myconfig = %main::myconfig;
2111 my $locale = $main::locale;
2113 $main::auth->assert('config');
2115 $form->{title} = $locale->text('Edit');
2117 AM->get_tax(\%myconfig, \%$form);
2118 _get_taxaccount_selection();
2120 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
2124 my $parameters_ref = {
2127 # Ausgabe des Templates
2128 print($form->parse_html_template('am/edit_tax', $parameters_ref));
2130 $main::lxdebug->leave_sub();
2134 $main::lxdebug->enter_sub();
2136 my $form = $main::form;
2137 my %myconfig = %main::myconfig;
2138 my $locale = $main::locale;
2140 $main::auth->assert('config');
2142 AM->taxes(\%myconfig, \%$form);
2144 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
2146 $form->{callback} = build_std_url('action=list_tax');
2148 $form->{title} = $locale->text('Tax-O-Matic');
2152 my $parameters_ref = {
2155 # Ausgabe des Templates
2156 print($form->parse_html_template('am/list_tax', $parameters_ref));
2158 $main::lxdebug->leave_sub();
2161 sub _get_taxaccount_selection{
2162 $main::lxdebug->enter_sub();
2164 my $form = $main::form;
2165 my %myconfig = %main::myconfig;
2167 $main::auth->assert('config');
2169 AM->get_tax_accounts(\%myconfig, \%$form);
2171 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
2173 $main::lxdebug->leave_sub();
2177 $main::lxdebug->enter_sub();
2179 my $form = $main::form;
2180 my %myconfig = %main::myconfig;
2181 my $locale = $main::locale;
2183 $main::auth->assert('config');
2185 $form->isblank("rate", $locale->text('Taxrate missing!'));
2186 $form->isblank("taxdescription", $locale->text('Taxdescription missing!'));
2187 $form->isblank("taxkey", $locale->text('Taxkey missing!'));
2189 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
2191 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
2192 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
2195 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
2196 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
2199 AM->save_tax(\%myconfig, \%$form);
2200 $form->redirect($locale->text('Tax saved!'));
2202 $main::lxdebug->leave_sub();
2206 $main::lxdebug->enter_sub();
2208 my $form = $main::form;
2209 my %myconfig = %main::myconfig;
2210 my $locale = $main::locale;
2212 $main::auth->assert('config');
2214 AM->delete_tax(\%myconfig, \%$form);
2215 $form->redirect($locale->text('Tax deleted!'));
2217 $main::lxdebug->leave_sub();
2220 sub add_price_factor {
2221 $main::lxdebug->enter_sub();
2223 my $form = $main::form;
2224 my $locale = $main::locale;
2226 $main::auth->assert('config');
2228 $form->{title} = $locale->text('Add Price Factor');
2229 $form->{callback} ||= build_std_url('action=add_price_factor');
2230 $form->{fokus} = 'description';
2233 print $form->parse_html_template('am/edit_price_factor');
2235 $main::lxdebug->leave_sub();
2238 sub edit_price_factor {
2239 $main::lxdebug->enter_sub();
2241 my $form = $main::form;
2242 my %myconfig = %main::myconfig;
2243 my $locale = $main::locale;
2245 $main::auth->assert('config');
2247 $form->{title} = $locale->text('Edit Price Factor');
2248 $form->{callback} ||= build_std_url('action=add_price_factor');
2249 $form->{fokus} = 'description';
2251 AM->get_price_factor(\%myconfig, $form);
2253 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
2256 print $form->parse_html_template('am/edit_price_factor');
2258 $main::lxdebug->leave_sub();
2261 sub list_price_factors {
2262 $main::lxdebug->enter_sub();
2264 my $form = $main::form;
2265 my %myconfig = %main::myconfig;
2266 my $locale = $main::locale;
2268 $main::auth->assert('config');
2270 AM->get_all_price_factors(\%myconfig, \%$form);
2272 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
2273 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
2276 $form->{callback} = build_std_url('action=list_price_factors');
2277 $form->{title} = $locale->text('Price Factors');
2278 $form->{url_base} = build_std_url('callback');
2281 print $form->parse_html_template('am/list_price_factors');
2283 $main::lxdebug->leave_sub();
2286 sub save_price_factor {
2287 $main::lxdebug->enter_sub();
2289 my $form = $main::form;
2290 my %myconfig = %main::myconfig;
2291 my $locale = $main::locale;
2293 $main::auth->assert('config');
2295 $form->isblank("description", $locale->text('Description missing!'));
2296 $form->isblank("factor", $locale->text('Factor missing!'));
2298 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
2300 AM->save_price_factor(\%myconfig, $form);
2302 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
2304 $form->redirect($locale->text('Price factor saved!'));
2306 $main::lxdebug->leave_sub();
2309 sub delete_price_factor {
2310 $main::lxdebug->enter_sub();
2312 my $form = $main::form;
2313 my %myconfig = %main::myconfig;
2314 my $locale = $main::locale;
2316 $main::auth->assert('config');
2318 AM->delete_price_factor(\%myconfig, \%$form);
2320 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
2322 $form->redirect($locale->text('Price factor deleted!'));
2324 $main::lxdebug->leave_sub();
2328 $main::lxdebug->enter_sub();
2330 my $form = $main::form;
2331 my $locale = $main::locale;
2333 $main::auth->assert('config');
2335 $form->{title} = $locale->text('Add Warehouse');
2336 $form->{callback} ||= build_std_url('action=add_warehouse');
2337 $form->{fokus} = 'description';
2340 print $form->parse_html_template('am/edit_warehouse');
2342 $main::lxdebug->leave_sub();
2345 sub edit_warehouse {
2346 $main::lxdebug->enter_sub();
2348 my $form = $main::form;
2349 my %myconfig = %main::myconfig;
2350 my $locale = $main::locale;
2352 $main::auth->assert('config');
2354 AM->get_warehouse(\%myconfig, $form);
2356 $form->get_lists('employees' => 'EMPLOYEES');
2358 $form->{title} = $locale->text('Edit Warehouse');
2359 $form->{callback} ||= build_std_url('action=list_warehouses');
2360 $form->{fokus} = 'description';
2363 print $form->parse_html_template('am/edit_warehouse');
2365 $main::lxdebug->leave_sub();
2368 sub list_warehouses {
2369 $main::lxdebug->enter_sub();
2371 my $form = $main::form;
2372 my %myconfig = %main::myconfig;
2373 my $locale = $main::locale;
2375 $main::auth->assert('config');
2377 AM->get_all_warehouses(\%myconfig, $form);
2379 $form->{callback} = build_std_url('action=list_warehouses');
2380 $form->{title} = $locale->text('Warehouses');
2381 $form->{url_base} = build_std_url('callback');
2384 print $form->parse_html_template('am/list_warehouses');
2386 $main::lxdebug->leave_sub();
2389 sub save_warehouse {
2390 $main::lxdebug->enter_sub();
2392 my $form = $main::form;
2393 my %myconfig = %main::myconfig;
2394 my $locale = $main::locale;
2396 $main::auth->assert('config');
2398 $form->isblank("description", $locale->text('Description missing!'));
2400 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
2402 AM->save_warehouse(\%myconfig, $form);
2404 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
2406 $form->redirect($locale->text('Warehouse saved.'));
2408 $main::lxdebug->leave_sub();
2411 sub delete_warehouse {
2412 $main::lxdebug->enter_sub();
2414 my $form = $main::form;
2415 my %myconfig = %main::myconfig;
2416 my $locale = $main::locale;
2418 $main::auth->assert('config');
2420 if (!$form->{confirmed}) {
2421 $form->{title} = $locale->text('Confirmation');
2424 print $form->parse_html_template('am/confirm_delete_warehouse');
2428 if (AM->delete_warehouse(\%myconfig, $form)) {
2429 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
2430 $form->redirect($locale->text('Warehouse deleted.'));
2433 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
2436 $main::lxdebug->leave_sub();
2440 $main::lxdebug->enter_sub();
2442 my $form = $main::form;
2443 my %myconfig = %main::myconfig;
2444 my $locale = $main::locale;
2446 $main::auth->assert('config');
2448 AM->save_bins(\%myconfig, $form);
2450 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
2452 $form->redirect($locale->text('Bins saved.'));
2454 $main::lxdebug->leave_sub();