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 : $locale->text('Unknown Link') . ': ' . $link;
564 $ca->{link} .= ($link ne '') ? "[$link] ":'';
567 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
568 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
569 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
570 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
571 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
572 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
573 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
574 : $locale->text('Unknown Category') . ': ' . $ca->{category};
577 $form->{title} = $locale->text('Chart of Accounts');
579 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
581 $main::lxdebug->leave_sub();
586 $main::lxdebug->enter_sub();
588 my $form = $main::form;
589 my %myconfig = %main::myconfig;
590 my $locale = $main::locale;
592 $main::auth->assert('config');
594 $form->{title} = $locale->text('Delete Account');
597 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
599 if ($form->{id} == $form->{$id}) {
600 $form->error($locale->text('Cannot delete default account!'));
604 $form->redirect($locale->text('Account deleted!'))
605 if (AM->delete_account(\%myconfig, \%$form));
606 $form->error($locale->text('Cannot delete account!'));
608 $main::lxdebug->leave_sub();
612 $main::lxdebug->enter_sub();
614 my $form = $main::form;
616 $main::auth->assert('config');
618 $form->{title} = "Add";
620 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
625 $main::lxdebug->leave_sub();
629 $main::lxdebug->enter_sub();
631 my $form = $main::form;
632 my %myconfig = %main::myconfig;
634 $main::auth->assert('config');
636 $form->{title} = "Edit";
638 AM->get_lead(\%myconfig, \%$form);
642 $form->{orphaned} = 1;
645 $main::lxdebug->leave_sub();
649 $main::lxdebug->enter_sub();
651 my $form = $main::form;
652 my %myconfig = %main::myconfig;
653 my $locale = $main::locale;
655 $main::auth->assert('config');
657 AM->lead(\%myconfig, \%$form);
659 $form->{callback} = "am.pl?action=list_lead";
661 my $callback = $form->escape($form->{callback});
663 $form->{title} = $locale->text('Lead');
665 my @column_index = qw(description cost profit);
667 $column_header{description} =
668 qq|<th class=listheading width=100%>|
669 . $locale->text('Description')
679 <th class=listtop>$form->{title}</th>
682 <tr class=listheading>
685 map { print "$column_header{$_}\n" } @column_index;
691 my ($i, %column_data);
692 foreach my $ref (@{ $form->{ALL} }) {
698 <tr valign=top class=listrow$i>
701 # $lead = $ref->{lead};
703 $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
705 map { print "$column_data{$_}\n" } @column_index;
714 <td><hr size=3 noshade></td>
719 <form method=post action=am.pl>
721 <input name=callback type=hidden value="$form->{callback}">
723 <input type=hidden name=type value=lead>
725 <input class=submit type=submit name=action value="|
726 . $locale->text('Add') . qq|">
734 $main::lxdebug->leave_sub();
738 $main::lxdebug->enter_sub();
740 my $form = $main::form;
741 my $locale = $main::locale;
743 $main::auth->assert('config');
745 $form->{title} = $locale->text("$form->{title} Lead");
747 # $locale->text('Add Lead')
748 # $locale->text('Edit Lead')
750 $form->{description} =~ s/\"/"/g;
753 qq|<input name=description size=50 value="$form->{lead}">|;
760 <form method=post action=am.pl>
762 <input type=hidden name=id value=$form->{id}>
763 <input type=hidden name=type value=lead>
767 <th class=listtop colspan=2>$form->{title}</th>
771 <th align=right>| . $locale->text('Description') . qq|</th>
772 <td>$description</td>
774 <td colspan=2><hr size=3 noshade></td>
779 $main::lxdebug->leave_sub();
783 $main::lxdebug->enter_sub();
785 my $form = $main::form;
786 my %myconfig = %main::myconfig;
787 my $locale = $main::locale;
789 $main::auth->assert('config');
791 $form->isblank("description", $locale->text('Description missing!'));
792 AM->save_lead(\%myconfig, \%$form);
793 $form->redirect($locale->text('lead saved!'));
795 $main::lxdebug->leave_sub();
799 $main::lxdebug->enter_sub();
801 my $form = $main::form;
802 my %myconfig = %main::myconfig;
803 my $locale = $main::locale;
805 $main::auth->assert('config');
807 AM->delete_lead(\%myconfig, \%$form);
808 $form->redirect($locale->text('lead deleted!'));
810 $main::lxdebug->leave_sub();
814 $main::lxdebug->enter_sub();
816 my $form = $main::form;
818 $main::auth->assert('config');
820 $form->{title} = "Add";
822 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
827 $main::lxdebug->leave_sub();
831 $main::lxdebug->enter_sub();
833 my $form = $main::form;
834 my %myconfig = %main::myconfig;
836 $main::auth->assert('config');
838 $form->{title} = "Edit";
840 AM->get_language(\%myconfig, \%$form);
844 $form->{orphaned} = 1;
847 $main::lxdebug->leave_sub();
851 $main::lxdebug->enter_sub();
853 my $form = $main::form;
854 my %myconfig = %main::myconfig;
855 my $locale = $main::locale;
857 $main::auth->assert('config');
859 AM->language(\%myconfig, \%$form);
861 $form->{callback} = "am.pl?action=list_language";
863 my $callback = $form->escape($form->{callback});
865 $form->{title} = $locale->text('Languages');
867 my @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
869 $column_header{description} =
870 qq|<th class=listheading width=60%>|
871 . $locale->text('Description')
873 $column_header{template_code} =
874 qq|<th class=listheading width=10%>|
875 . $locale->text('Template Code')
877 $column_header{article_code} =
878 qq|<th class=listheading>|
879 . $locale->text('Article Code')
881 $column_header{output_numberformat} =
882 qq|<th class=listheading>|
883 . $locale->text('Number Format')
885 $column_header{output_dateformat} =
886 qq|<th class=listheading>|
887 . $locale->text('Date Format')
889 $column_header{output_longdates} =
890 qq|<th class=listheading>|
891 . $locale->text('Long Dates')
901 <th class=listtop>$form->{title}</th>
907 <tr class=listheading>
910 map { print "$column_header{$_}\n" } @column_index;
916 my ($i, %column_data);
917 foreach my $ref (@{ $form->{ALL} }) {
923 <tr valign=top class=listrow$i>
927 $column_data{description} =
928 qq|<td><a href="am.pl?action=edit_language&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
929 $column_data{template_code} = qq|<td align=right>$ref->{template_code}</td>|;
930 $column_data{article_code} =
931 qq|<td align=right>$ref->{article_code}</td>|;
932 $column_data{output_numberformat} =
934 ($ref->{output_numberformat} ? $ref->{output_numberformat} :
935 $locale->text("use program settings")) .
937 $column_data{output_dateformat} =
939 ($ref->{output_dateformat} ? $ref->{output_dateformat} :
940 $locale->text("use program settings")) .
942 $column_data{output_longdates} =
944 ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
947 map { print "$column_data{$_}\n" } @column_index;
959 <td><hr size=3 noshade></td>
964 <form method=post action=am.pl>
966 <input name=callback type=hidden value="$form->{callback}">
968 <input type=hidden name=type value=language>
970 <input class=submit type=submit name=action value="|
971 . $locale->text('Add') . qq|">
979 $main::lxdebug->leave_sub();
982 sub language_header {
983 $main::lxdebug->enter_sub();
985 my $form = $main::form;
986 my $locale = $main::locale;
988 $main::auth->assert('config');
990 $form->{title} = $locale->text("$form->{title} Language");
992 # $locale->text('Add Language')
993 # $locale->text('Edit Language')
995 $form->{description} =~ s/\"/"/g;
996 $form->{template_code} =~ s/\"/"/g;
997 $form->{article_code} =~ s/\"/"/g;
1003 qq|<option value="">| . $locale->text("use program settings") .
1005 foreach my $item (('1,000.00', '1000.00', '1.000,00', '1000,00')) {
1007 ($item eq $form->{output_numberformat})
1008 ? "<option selected>$item"
1014 qq|<option value="">| . $locale->text("use program settings") .
1016 foreach my $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
1018 ($item eq $form->{output_dateformat})
1019 ? "<option selected>$item"
1027 <form method=post action=am.pl>
1029 <input type=hidden name=id value=$form->{id}>
1030 <input type=hidden name=type value=language>
1034 <th class=listtop colspan=2>$form->{title}</th>
1036 <tr height="5"></tr>
1038 <th align=right>| . $locale->text('Language') . qq|</th>
1039 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1042 <th align=right>| . $locale->text('Template Code') . qq|</th>
1043 <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
1046 <th align=right>| . $locale->text('Article Code') . qq|</th>
1047 <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
1050 <th align=right>| . $locale->text('Number Format') . qq|</th>
1051 <td><select name="output_numberformat">$numberformat</select></td>
1054 <th align=right>| . $locale->text('Date Format') . qq|</th>
1055 <td><select name="output_dateformat">$dateformat</select></td>
1058 <th align=right>| . $locale->text('Long Dates') . qq|</th>
1059 <td><input type="radio" name="output_longdates" value="1"| .
1060 ($form->{output_longdates} ? " checked" : "") .
1061 qq|>| . $locale->text("Yes") .
1062 qq|<input type="radio" name="output_longdates" value="0"| .
1063 ($form->{output_longdates} ? "" : " checked") .
1064 qq|>| . $locale->text("No") .
1067 <td colspan=2><hr size=3 noshade></td>
1072 $main::lxdebug->leave_sub();
1076 $main::lxdebug->enter_sub();
1078 my $form = $main::form;
1079 my %myconfig = %main::myconfig;
1080 my $locale = $main::locale;
1082 $main::auth->assert('config');
1084 $form->isblank("description", $locale->text('Language missing!'));
1085 $form->isblank("template_code", $locale->text('Template Code missing!'));
1086 $form->isblank("article_code", $locale->text('Article Code missing!'));
1087 AM->save_language(\%myconfig, \%$form);
1088 $form->redirect($locale->text('Language saved!'));
1090 $main::lxdebug->leave_sub();
1093 sub delete_language {
1094 $main::lxdebug->enter_sub();
1096 my $form = $main::form;
1097 my %myconfig = %main::myconfig;
1098 my $locale = $main::locale;
1100 $main::auth->assert('config');
1102 AM->delete_language(\%myconfig, \%$form);
1103 $form->redirect($locale->text('Language deleted!'));
1105 $main::lxdebug->leave_sub();
1109 sub add_buchungsgruppe {
1110 $main::lxdebug->enter_sub();
1112 my $form = $main::form;
1113 my %myconfig = %main::myconfig;
1114 my $locale = $main::locale;
1116 $main::auth->assert('config');
1118 # $locale->text("Add Buchungsgruppe")
1119 # $locale->text("Edit Buchungsgruppe")
1120 $form->{title} = "Add";
1122 $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
1124 AM->get_buchungsgruppe(\%myconfig, \%$form);
1125 $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
1126 for (my $i = 0; 4 > $i; $i++) {
1127 map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
1128 qw(income expense));
1131 &buchungsgruppe_header;
1134 $main::lxdebug->leave_sub();
1137 sub edit_buchungsgruppe {
1138 $main::lxdebug->enter_sub();
1140 my $form = $main::form;
1141 my %myconfig = %main::myconfig;
1143 $main::auth->assert('config');
1145 $form->{title} = "Edit";
1147 AM->get_buchungsgruppe(\%myconfig, \%$form);
1149 &buchungsgruppe_header;
1153 $main::lxdebug->leave_sub();
1156 sub list_buchungsgruppe {
1157 $main::lxdebug->enter_sub();
1159 my $form = $main::form;
1160 my %myconfig = %main::myconfig;
1161 my $locale = $main::locale;
1163 $main::auth->assert('config');
1165 AM->buchungsgruppe(\%myconfig, \%$form);
1167 $form->{callback} = "am.pl?action=list_buchungsgruppe";
1169 my $callback = $form->escape($form->{callback});
1171 $form->{title} = $locale->text('Buchungsgruppen');
1173 my @column_index = qw(up down description inventory_accno
1174 income_accno_0 expense_accno_0
1175 income_accno_1 expense_accno_1
1176 income_accno_2 expense_accno_2
1177 income_accno_3 expense_accno_3 );
1179 $column_header{up} =
1180 qq|<th class="listheading" width="16">|
1181 . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
1183 $column_header{down} =
1184 qq|<th class="listheading" width="16">|
1185 . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
1187 $column_header{description} =
1188 qq|<th class="listheading" width="40%">|
1189 . $locale->text('Description')
1191 $column_header{inventory_accno} =
1192 qq|<th class=listheading>|
1193 . $locale->text('Bestandskonto')
1195 $column_header{income_accno_0} =
1196 qq|<th class=listheading>|
1197 . $locale->text('National Revenues')
1199 $column_header{expense_accno_0} =
1200 qq|<th class=listheading>|
1201 . $locale->text('National Expenses')
1203 $column_header{income_accno_1} =
1204 qq|<th class=listheading>|
1205 . $locale->text('Revenues EU with UStId')
1207 $column_header{expense_accno_1} =
1208 qq|<th class=listheading>|
1209 . $locale->text('Expenses EU with UStId')
1211 $column_header{income_accno_2} =
1212 qq|<th class=listheading>|
1213 . $locale->text('Revenues EU without UStId')
1215 $column_header{expense_accno_2} =
1216 qq|<th class=listheading>|
1217 . $locale->text('Expenses EU without UStId')
1219 $column_header{income_accno_3} =
1220 qq|<th class=listheading>|
1221 . $locale->text('Foreign Revenues')
1223 $column_header{expense_accno_3} =
1224 qq|<th class=listheading>|
1225 . $locale->text('Foreign Expenses')
1234 <th class=listtop>$form->{title}</th>
1236 <tr height="5"></tr>
1240 <tr class=listheading>
1243 map { print "$column_header{$_}\n" } @column_index;
1249 my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
1252 my ($i, %column_data);
1253 foreach my $ref (@{ $form->{ALL} }) {
1259 <tr valign=top class=listrow$i>
1263 my $pref = $form->{ALL}->[$row - 1];
1265 qq|<td align="center" valign="center" width="16">| .
1266 qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
1267 qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
1270 $column_data{up} = qq|<td width="16"> </td>|;
1273 if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
1274 $column_data{down} = qq|<td width="16"> </td>|;
1276 my $nref = $form->{ALL}->[$row + 1];
1277 $column_data{down} =
1278 qq|<td align="center" valign="center" width="16">| .
1279 qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
1280 qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
1284 $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
1285 $column_data{inventory_accno} = qq|<td align=right>$ref->{inventory_accno}</td>|;
1286 $column_data{income_accno_0} =
1287 qq|<td align=right>$ref->{income_accno_0}</td>|;
1288 $column_data{expense_accno_0} = qq|<td align=right>$ref->{expense_accno_0}</td>|;
1289 $column_data{income_accno_1} =
1290 qq|<td align=right>$ref->{income_accno_1}</td>|;
1291 $column_data{expense_accno_1} = qq|<td align=right>$ref->{expense_accno_1}</td>|;
1292 $column_data{income_accno_2} =
1293 qq|<td align=right>$ref->{income_accno_2}</td>|;
1294 $column_data{expense_accno_2} = qq|<td align=right>$ref->{expense_accno_2}</td>|;
1295 $column_data{income_accno_3} =
1296 qq|<td align=right>$ref->{income_accno_3}</td>|;
1297 $column_data{expense_accno_3} = qq|<td align=right>$ref->{expense_accno_3}</td>|;
1299 map { print "$column_data{$_}\n" } @column_index;
1313 <td><hr size=3 noshade></td>
1318 <form method=post action=am.pl>
1320 <input name=callback type=hidden value="$form->{callback}">
1322 <input type=hidden name=type value=buchungsgruppe>
1324 <input class=submit type=submit name=action value="|
1325 . $locale->text('Add') . qq|">
1333 $main::lxdebug->leave_sub();
1336 sub buchungsgruppe_header {
1337 $main::lxdebug->enter_sub();
1339 my $form = $main::form;
1340 my $locale = $main::locale;
1342 $main::auth->assert('config');
1344 $form->{title} = $locale->text("$form->{title} Buchungsgruppe");
1346 # $locale->text('Add Accounting Group')
1347 # $locale->text('Edit Accounting Group')
1349 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
1350 my %acc_type_map = (
1351 "IC" => $acc_inventory,
1352 "IC_income" => $acc_income,
1353 "IC_sale" => $acc_income,
1354 "IC_expense" => $acc_expense,
1355 "IC_cogs" => $acc_expense,
1358 foreach my $key (keys(%acc_type_map)) {
1359 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1360 $acc_type_map{$key}->{$ref->{"id"}} = $ref;
1364 foreach my $type (qw(IC IC_income IC_expense)) {
1365 $form->{"select$type"} =
1367 map({ "<option value=$_->{id} $_->{selected}>" .
1368 "$_->{accno}--" . H($_->{description}) . "</option>" }
1369 sort({ $a->{"accno"} cmp $b->{"accno"} }
1370 values(%{$acc_type_map{$type}}))));
1374 $form->{selectIC} =~ s/selected//g;
1375 $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/ value=$form->{inventory_accno_id} selected/;
1376 $form->{selectIC_income} =~ s/selected//g;
1377 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/ value=$form->{income_accno_id_0} selected/;
1378 $form->{selectIC_expense} =~ s/selected//g;
1379 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/ value=$form->{expense_accno_id_0} selected/;
1383 if ( $::instance_conf->get_inventory_system eq 'perpetual' ) { # was !$::lx_office_conf{system}->{eur}) {
1386 <th align=right>| . $locale->text('Inventory') . qq|</th>
1387 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
1388 <input name=selectIC type=hidden value="$form->{selectIC}">
1390 } elsif ( $::instance_conf->get_inventory_system eq 'periodic' ) {
1391 # don't allow choice of inventory accno and don't show that line
1393 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
1397 $linkaccounts .= qq|
1399 <th align=right>| . $locale->text('National Revenues') . qq|</th>
1400 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
1403 <th align=right>| . $locale->text('National Expenses') . qq|</th>
1404 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
1407 $form->{selectIC_income} =~ s/selected//g;
1408 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/ value=$form->{income_accno_id_1} selected/;
1409 $form->{selectIC_expense} =~ s/selected//g;
1410 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/ value=$form->{expense_accno_id_1} selected/;
1412 $linkaccounts .= qq| <tr>
1413 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
1414 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
1417 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
1418 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
1422 $form->{selectIC_income} =~ s/selected//g;
1423 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/ value=$form->{income_accno_id_2} selected/;
1424 $form->{selectIC_expense} =~ s/selected//g;
1425 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/ value=$form->{expense_accno_id_2} selected/;
1428 $linkaccounts .= qq| <tr>
1429 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
1430 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
1433 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
1434 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
1438 $form->{selectIC_income} =~ s/selected//g;
1439 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/ value=$form->{income_accno_id_3} selected/;
1440 $form->{selectIC_expense} =~ s/selected//g;
1441 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/ value=$form->{expense_accno_id_3} selected/;
1444 $linkaccounts .= qq| <tr>
1445 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
1446 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
1449 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
1450 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
1460 <form method=post action=am.pl>
1462 <input type=hidden name=id value=$form->{id}>
1463 <input type=hidden name=type value=buchungsgruppe>
1467 <th class=listtop colspan=2>$form->{title}</th>
1469 <tr height="5"></tr>
1471 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
1472 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1475 <td colspan=2><hr size=3 noshade></td>
1480 $main::lxdebug->leave_sub();
1483 sub save_buchungsgruppe {
1484 $main::lxdebug->enter_sub();
1486 my $form = $main::form;
1487 my %myconfig = %main::myconfig;
1488 my $locale = $main::locale;
1490 $main::auth->assert('config');
1492 $form->isblank("description", $locale->text('Description missing!'));
1494 AM->save_buchungsgruppe(\%myconfig, \%$form);
1495 $form->redirect($locale->text('Accounting Group saved!'));
1497 $main::lxdebug->leave_sub();
1500 sub delete_buchungsgruppe {
1501 $main::lxdebug->enter_sub();
1503 my $form = $main::form;
1504 my %myconfig = %main::myconfig;
1505 my $locale = $main::locale;
1507 $main::auth->assert('config');
1509 AM->delete_buchungsgruppe(\%myconfig, \%$form);
1510 $form->redirect($locale->text('Accounting Group deleted!'));
1512 $main::lxdebug->leave_sub();
1515 sub swap_buchungsgruppen {
1516 $main::lxdebug->enter_sub();
1518 my $form = $main::form;
1519 my %myconfig = %main::myconfig;
1521 $main::auth->assert('config');
1523 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
1524 list_buchungsgruppe();
1526 $main::lxdebug->leave_sub();
1530 $main::lxdebug->enter_sub();
1532 my $form = $main::form;
1533 my %myconfig = %main::myconfig;
1534 my $locale = $main::locale;
1536 # get defaults for account numbers and last numbers
1537 AM->defaultaccounts(\%myconfig, \%$form);
1538 $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
1540 map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
1543 my $all_languages = SL::DB::Manager::Language->get_all;
1545 # EÜR = cash, Bilanzierung = accrual
1547 foreach my $key (keys %{ $form->{IC} }) {
1548 foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
1549 my $array = "ACCNOS_" . uc($key);
1550 $form->{$array} ||= [];
1552 my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
1553 push @{ $form->{$array} }, {
1556 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
1561 $form->{title} = $locale->text('Ranges of numbers and default accounts');
1564 print $form->parse_html_template('am/edit_defaults',
1565 { ALL_LANGUAGES => $all_languages, });
1567 $main::lxdebug->leave_sub();
1571 $main::lxdebug->enter_sub();
1573 my $form = $main::form;
1574 my $locale = $main::locale;
1576 AM->save_defaults();
1578 $form->redirect($locale->text('Defaults saved.'));
1580 $main::lxdebug->leave_sub();
1583 sub _build_cfg_options {
1584 my $form = $main::form;
1585 my %myconfig = %main::myconfig;
1588 my $array = uc($idx) . 'S';
1590 $form->{$array} = [];
1591 foreach my $item (@_) {
1592 push @{ $form->{$array} }, {
1595 'selected' => $item eq $myconfig{$idx},
1601 $main::lxdebug->enter_sub();
1603 my $form = $main::form;
1604 my %myconfig = %main::myconfig;
1605 my $locale = $main::locale;
1607 _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
1608 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
1611 if ($::lx_office_conf{print_templates}->{opendocument}
1612 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
1613 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
1614 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
1615 "value" => "opendocument_pdf" });
1617 if ($::lx_office_conf{print_templates}->{latex}) {
1618 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
1620 push(@formats, { "name" => "HTML", "value" => "html" });
1621 if ($::lx_office_conf{print_templates}->{latex}) {
1622 push(@formats, { "name" => $locale->text("Postscript"),
1623 "value" => "postscript" });
1625 if ($::lx_office_conf{print_templates}->{opendocument}) {
1626 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
1627 "value" => "opendocument" });
1630 if (!$myconfig{"template_format"}) {
1631 $myconfig{"template_format"} = "pdf";
1633 $form->{TEMPLATE_FORMATS} = [];
1634 foreach my $item (@formats) {
1635 push @{ $form->{TEMPLATE_FORMATS} }, {
1636 'name' => $item->{name},
1637 'value' => $item->{value},
1638 'selected' => $item->{value} eq $myconfig{template_format},
1642 if (!$myconfig{"default_media"}) {
1643 $myconfig{"default_media"} = "screen";
1646 my %selected = ($myconfig{"default_media"} => "selected");
1648 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
1649 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
1650 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
1653 $form->{PRINTERS} = [ SL::Printer->all_printers(%::myconfig) ];
1655 my %countrycodes = User->country_codes;
1657 $form->{COUNTRYCODES} = [];
1658 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
1659 push @{ $form->{COUNTRYCODES} }, {
1660 'name' => $countrycodes{$countrycode},
1661 'value' => $countrycode,
1662 'selected' => $countrycode eq $myconfig{countrycode},
1666 $form->{STYLESHEETS} = [];
1667 foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
1668 push @{ $form->{STYLESHEETS} }, {
1671 'selected' => $item eq $myconfig{stylesheet},
1675 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
1676 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
1677 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
1679 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
1682 print $form->parse_html_template('am/config');
1684 $main::lxdebug->leave_sub();
1687 sub save_preferences {
1688 $main::lxdebug->enter_sub();
1690 my $form = $main::form;
1691 my %myconfig = %main::myconfig;
1692 my $locale = $main::locale;
1694 $form->{stylesheet} = $form->{usestylesheet};
1696 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
1698 if (AM->save_preferences(\%myconfig, $form)) {
1699 if ($::auth->can_change_password()
1700 && defined $form->{new_password}
1701 && ($form->{new_password} ne '********')) {
1702 my $verifier = SL::Auth::PasswordPolicy->new;
1703 my $result = $verifier->verify($form->{new_password});
1705 if ($result != SL::Auth::PasswordPolicy->OK()) {
1706 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
1709 $::auth->change_password($form->{login}, $form->{new_password});
1711 $form->{password} = $form->{new_password};
1712 $::auth->set_session_value('password', $form->{password});
1713 $::auth->create_or_refresh_session();
1716 $form->redirect($locale->text('Preferences saved!'));
1719 $form->error($locale->text('Cannot save preferences!'));
1721 $main::lxdebug->leave_sub();
1725 $main::lxdebug->enter_sub();
1727 my $form = $main::form;
1728 my %myconfig = %main::myconfig;
1729 my $locale = $main::locale;
1731 $main::auth->assert('config');
1733 $form->{title} = $locale->text('Audit Control');
1735 AM->closedto(\%myconfig, \%$form);
1742 <form method=post action=am.pl>
1745 <tr><th class=listtop>$form->{title}</th></tr>
1746 <tr height="5"></tr>
1751 <th>| . $locale->text('Close Books up to') . qq|</th>
1752 <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
1762 <input type=hidden name=nextsub value=doclose>
1764 <input type=submit class=submit name=action value="|
1765 . $locale->text('Continue') . qq|">
1773 $main::lxdebug->leave_sub();
1777 $main::lxdebug->enter_sub();
1779 my $form = $main::form;
1780 my %myconfig = %main::myconfig;
1781 my $locale = $main::locale;
1783 $main::auth->assert('config');
1785 AM->closebooks(\%myconfig, \%$form);
1787 if ($form->{closedto}) {
1789 $locale->text('Books closed up to') . " "
1790 . $locale->date(\%myconfig, $form->{closedto}, 1));
1792 $form->redirect($locale->text('Books are open'));
1795 $main::lxdebug->leave_sub();
1799 $main::lxdebug->enter_sub();
1801 my $form = $main::form;
1802 my %myconfig = %main::myconfig;
1803 my $locale = $main::locale;
1805 $main::auth->assert('config');
1807 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1808 AM->units_in_use(\%myconfig, $form, $units);
1809 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1811 my @languages = AM->language(\%myconfig, $form, 1);
1813 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1816 foreach (@unit_list) {
1817 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1818 $_->{"UNITLANGUAGES"} = [];
1819 foreach my $lang (@languages) {
1820 push(@{ $_->{"UNITLANGUAGES"} },
1822 "unit" => $_->{"name"},
1823 "language_id" => $lang->{"id"},
1824 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1825 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1831 $units = AM->retrieve_units(\%myconfig, $form);
1832 my $ddbox = AM->unit_select_data($units, undef, 1);
1834 $form->{"title"} = $locale->text("Add and edit units");
1836 print($form->parse_html_template("am/edit_units",
1837 { "UNITS" => \@unit_list,
1838 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1839 "LANGUAGES" => \@languages,
1842 $main::lxdebug->leave_sub();
1846 $main::lxdebug->enter_sub();
1848 my $form = $main::form;
1849 my %myconfig = %main::myconfig;
1850 my $locale = $main::locale;
1852 $main::auth->assert('config');
1854 $form->isblank("new_name", $locale->text("The name is missing."));
1855 my $units = AM->retrieve_units(\%myconfig, $form);
1856 my $all_units = AM->retrieve_units(\%myconfig, $form);
1857 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1859 my ($base_unit, $factor);
1860 if ($form->{"new_base_unit"}) {
1861 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1863 $form->isblank("new_factor", $locale->text("The factor is missing."));
1864 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1865 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1866 $base_unit = $form->{"new_base_unit"};
1870 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1871 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1872 push(@languages, { "id" => $lang->{"id"},
1873 "localized" => $form->{"new_localized_$lang->{id}"},
1874 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1878 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1880 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1884 $main::lxdebug->leave_sub();
1887 sub set_unit_languages {
1888 $main::lxdebug->enter_sub();
1890 my $form = $main::form;
1892 $main::auth->assert('config');
1894 my ($unit, $languages, $idx) = @_;
1896 $unit->{"LANGUAGES"} = [];
1898 foreach my $lang (@{$languages}) {
1899 push(@{ $unit->{"LANGUAGES"} },
1900 { "id" => $lang->{"id"},
1901 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1902 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1906 $main::lxdebug->leave_sub();
1910 $main::lxdebug->enter_sub();
1912 my $form = $main::form;
1913 my %myconfig = %main::myconfig;
1914 my $locale = $main::locale;
1916 $main::auth->assert('config');
1918 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1919 AM->units_in_use(\%myconfig, $form, $old_units);
1921 my @languages = AM->language(\%myconfig, $form, 1);
1924 my @delete_units = ();
1925 foreach my $i (1..($form->{"rowcount"} * 1)) {
1926 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1928 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1931 if ($form->{"unchangeable_$i"}) {
1932 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1933 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1934 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1938 if ($old_unit->{"in_use"}) {
1939 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1942 if ($form->{"delete_$i"}) {
1943 push(@delete_units, $old_unit->{"name"});
1947 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1949 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1950 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1951 $new_units->{$form->{"name_$i"}} = \%h;
1952 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1953 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1956 foreach my $unit (values(%{$new_units})) {
1957 next unless ($unit->{"old_name"});
1958 if ($unit->{"base_unit"}) {
1959 $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"}))
1960 unless (defined($new_units->{$unit->{"base_unit"}}));
1961 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1962 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1964 $unit->{"base_unit"} = undef;
1965 $unit->{"factor"} = undef;
1969 foreach my $unit (values(%{$new_units})) {
1970 next if ($unit->{"unchanged_unit"});
1972 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1973 my $new_unit = $unit;
1974 while ($new_unit->{"base_unit"}) {
1975 $new_unit->{"seen"} = 1;
1976 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1977 if ($new_unit->{"seen"}) {
1978 $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, " .
1979 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1984 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1986 $form->{"saved_message"} = $locale->text("The units have been saved.");
1990 $main::lxdebug->leave_sub();
1993 sub show_history_search {
1994 $main::lxdebug->enter_sub();
1996 my $form = $main::form;
1997 my $locale = $main::locale;
1999 $main::auth->assert('config');
2001 $form->{title} = $locale->text("History Search");
2004 print $form->parse_html_template("common/search_history");
2006 $main::lxdebug->leave_sub();
2009 sub show_am_history {
2010 $main::lxdebug->enter_sub();
2012 my $form = $main::form;
2013 my %myconfig = %main::myconfig;
2014 my $locale = $main::locale;
2016 $main::auth->assert('config');
2018 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
2019 $form->{order} ||= 'h.itime--1';
2021 my %search = ( "Artikelnummer" => "parts",
2022 "Kundennummer" => "customer",
2023 "Lieferantennummer" => "vendor",
2024 "Projektnummer" => "project",
2025 "Buchungsnummer" => "oe",
2026 "Eingangsrechnungnummer" => "ap",
2027 "Ausgangsrechnungnummer" => "ar",
2028 "Mahnungsnummer" => "dunning"
2030 my %searchNo = ( "Artikelnummer" => "partnumber",
2031 "Kundennummer" => "customernumber",
2032 "Lieferantennummer" => "vendornumber",
2033 "Projektnummer" => "projectnumber",
2034 "Buchungsnummer" => "ordnumber",
2035 "Eingangsrechnungnummer" => "invnumber",
2036 "Ausgangsrechnungnummer" => "invnumber",
2037 "Mahnungsnummer" => "dunning_id"
2040 my $dbh = $form->dbconnect(\%myconfig);
2043 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
2044 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
2045 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
2046 if ($form->{mitarbeiter} =~ m/^\d+$/) {
2047 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
2048 } elsif ($form->{mitarbeiter}) {
2049 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
2052 my $query = qq|SELECT trans_id AS id FROM history_erp | .
2053 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
2054 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
2056 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
2057 my $daten .= shift @ids;
2058 $daten .= join '', map { " OR trans_id = $_" } @ids;
2060 my ($sort, $sortby) = split(/\-\-/, $form->{order});
2061 $sort =~ s/.*\.(.*)$/$1/;
2063 $form->{title} = $locale->text("History Search");
2066 print $form->parse_html_template("common/show_history",
2067 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
2068 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
2071 uc($sort) . "BY" => $sortby,
2072 'callback' => $callback,
2076 $main::lxdebug->leave_sub();
2080 $main::lxdebug->enter_sub();
2082 my $form = $main::form;
2083 my $locale = $main::locale;
2085 $main::auth->assert('config');
2087 $form->{title} = $locale->text('Add');
2089 $form->{callback} ||= "am.pl?action=add_tax";
2091 _get_taxaccount_selection();
2095 my $parameters_ref = {
2096 # ChartTypeIsAccount => $ChartTypeIsAccount,
2099 # Ausgabe des Templates
2100 print($form->parse_html_template('am/edit_tax', $parameters_ref));
2102 $main::lxdebug->leave_sub();
2106 $main::lxdebug->enter_sub();
2108 my $form = $main::form;
2109 my %myconfig = %main::myconfig;
2110 my $locale = $main::locale;
2112 $main::auth->assert('config');
2114 $form->{title} = $locale->text('Edit');
2116 AM->get_tax(\%myconfig, \%$form);
2117 _get_taxaccount_selection();
2119 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
2123 my $parameters_ref = {
2126 # Ausgabe des Templates
2127 print($form->parse_html_template('am/edit_tax', $parameters_ref));
2129 $main::lxdebug->leave_sub();
2133 $main::lxdebug->enter_sub();
2135 my $form = $main::form;
2136 my %myconfig = %main::myconfig;
2137 my $locale = $main::locale;
2139 $main::auth->assert('config');
2141 AM->taxes(\%myconfig, \%$form);
2143 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
2145 $form->{callback} = build_std_url('action=list_tax');
2147 $form->{title} = $locale->text('Tax-O-Matic');
2151 my $parameters_ref = {
2154 # Ausgabe des Templates
2155 print($form->parse_html_template('am/list_tax', $parameters_ref));
2157 $main::lxdebug->leave_sub();
2160 sub _get_taxaccount_selection{
2161 $main::lxdebug->enter_sub();
2163 my $form = $main::form;
2164 my %myconfig = %main::myconfig;
2166 $main::auth->assert('config');
2168 AM->get_tax_accounts(\%myconfig, \%$form);
2170 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
2172 $main::lxdebug->leave_sub();
2176 $main::lxdebug->enter_sub();
2178 my $form = $main::form;
2179 my %myconfig = %main::myconfig;
2180 my $locale = $main::locale;
2182 $main::auth->assert('config');
2184 $form->isblank("rate", $locale->text('Taxrate missing!'));
2185 $form->isblank("taxdescription", $locale->text('Taxdescription missing!'));
2186 $form->isblank("taxkey", $locale->text('Taxkey missing!'));
2188 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
2190 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
2191 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
2194 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
2195 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
2198 AM->save_tax(\%myconfig, \%$form);
2199 $form->redirect($locale->text('Tax saved!'));
2201 $main::lxdebug->leave_sub();
2205 $main::lxdebug->enter_sub();
2207 my $form = $main::form;
2208 my %myconfig = %main::myconfig;
2209 my $locale = $main::locale;
2211 $main::auth->assert('config');
2213 AM->delete_tax(\%myconfig, \%$form);
2214 $form->redirect($locale->text('Tax deleted!'));
2216 $main::lxdebug->leave_sub();
2219 sub add_price_factor {
2220 $main::lxdebug->enter_sub();
2222 my $form = $main::form;
2223 my $locale = $main::locale;
2225 $main::auth->assert('config');
2227 $form->{title} = $locale->text('Add Price Factor');
2228 $form->{callback} ||= build_std_url('action=add_price_factor');
2229 $form->{fokus} = 'description';
2232 print $form->parse_html_template('am/edit_price_factor');
2234 $main::lxdebug->leave_sub();
2237 sub edit_price_factor {
2238 $main::lxdebug->enter_sub();
2240 my $form = $main::form;
2241 my %myconfig = %main::myconfig;
2242 my $locale = $main::locale;
2244 $main::auth->assert('config');
2246 $form->{title} = $locale->text('Edit Price Factor');
2247 $form->{callback} ||= build_std_url('action=add_price_factor');
2248 $form->{fokus} = 'description';
2250 AM->get_price_factor(\%myconfig, $form);
2252 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
2255 print $form->parse_html_template('am/edit_price_factor');
2257 $main::lxdebug->leave_sub();
2260 sub list_price_factors {
2261 $main::lxdebug->enter_sub();
2263 my $form = $main::form;
2264 my %myconfig = %main::myconfig;
2265 my $locale = $main::locale;
2267 $main::auth->assert('config');
2269 AM->get_all_price_factors(\%myconfig, \%$form);
2271 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
2272 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
2275 $form->{callback} = build_std_url('action=list_price_factors');
2276 $form->{title} = $locale->text('Price Factors');
2277 $form->{url_base} = build_std_url('callback');
2280 print $form->parse_html_template('am/list_price_factors');
2282 $main::lxdebug->leave_sub();
2285 sub save_price_factor {
2286 $main::lxdebug->enter_sub();
2288 my $form = $main::form;
2289 my %myconfig = %main::myconfig;
2290 my $locale = $main::locale;
2292 $main::auth->assert('config');
2294 $form->isblank("description", $locale->text('Description missing!'));
2295 $form->isblank("factor", $locale->text('Factor missing!'));
2297 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
2299 AM->save_price_factor(\%myconfig, $form);
2301 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
2303 $form->redirect($locale->text('Price factor saved!'));
2305 $main::lxdebug->leave_sub();
2308 sub delete_price_factor {
2309 $main::lxdebug->enter_sub();
2311 my $form = $main::form;
2312 my %myconfig = %main::myconfig;
2313 my $locale = $main::locale;
2315 $main::auth->assert('config');
2317 AM->delete_price_factor(\%myconfig, \%$form);
2319 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
2321 $form->redirect($locale->text('Price factor deleted!'));
2323 $main::lxdebug->leave_sub();
2327 $main::lxdebug->enter_sub();
2329 my $form = $main::form;
2330 my $locale = $main::locale;
2332 $main::auth->assert('config');
2334 $form->{title} = $locale->text('Add Warehouse');
2335 $form->{callback} ||= build_std_url('action=add_warehouse');
2336 $form->{fokus} = 'description';
2339 print $form->parse_html_template('am/edit_warehouse');
2341 $main::lxdebug->leave_sub();
2344 sub edit_warehouse {
2345 $main::lxdebug->enter_sub();
2347 my $form = $main::form;
2348 my %myconfig = %main::myconfig;
2349 my $locale = $main::locale;
2351 $main::auth->assert('config');
2353 AM->get_warehouse(\%myconfig, $form);
2355 $form->get_lists('employees' => 'EMPLOYEES');
2357 $form->{title} = $locale->text('Edit Warehouse');
2358 $form->{callback} ||= build_std_url('action=list_warehouses');
2359 $form->{fokus} = 'description';
2362 print $form->parse_html_template('am/edit_warehouse');
2364 $main::lxdebug->leave_sub();
2367 sub list_warehouses {
2368 $main::lxdebug->enter_sub();
2370 my $form = $main::form;
2371 my %myconfig = %main::myconfig;
2372 my $locale = $main::locale;
2374 $main::auth->assert('config');
2376 AM->get_all_warehouses(\%myconfig, $form);
2378 $form->{callback} = build_std_url('action=list_warehouses');
2379 $form->{title} = $locale->text('Warehouses');
2380 $form->{url_base} = build_std_url('callback');
2383 print $form->parse_html_template('am/list_warehouses');
2385 $main::lxdebug->leave_sub();
2388 sub save_warehouse {
2389 $main::lxdebug->enter_sub();
2391 my $form = $main::form;
2392 my %myconfig = %main::myconfig;
2393 my $locale = $main::locale;
2395 $main::auth->assert('config');
2397 $form->isblank("description", $locale->text('Description missing!'));
2399 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
2401 AM->save_warehouse(\%myconfig, $form);
2403 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
2405 $form->redirect($locale->text('Warehouse saved.'));
2407 $main::lxdebug->leave_sub();
2410 sub delete_warehouse {
2411 $main::lxdebug->enter_sub();
2413 my $form = $main::form;
2414 my %myconfig = %main::myconfig;
2415 my $locale = $main::locale;
2417 $main::auth->assert('config');
2419 if (!$form->{confirmed}) {
2420 $form->{title} = $locale->text('Confirmation');
2423 print $form->parse_html_template('am/confirm_delete_warehouse');
2427 if (AM->delete_warehouse(\%myconfig, $form)) {
2428 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
2429 $form->redirect($locale->text('Warehouse deleted.'));
2432 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
2435 $main::lxdebug->leave_sub();
2439 $main::lxdebug->enter_sub();
2441 my $form = $main::form;
2442 my %myconfig = %main::myconfig;
2443 my $locale = $main::locale;
2445 $main::auth->assert('config');
2447 AM->save_bins(\%myconfig, $form);
2449 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
2451 $form->redirect($locale->text('Bins saved.'));
2453 $main::lxdebug->leave_sub();