1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
32 #======================================================================
37 use SL::Auth::PasswordPolicy;
48 require "bin/mozilla/common.pl";
56 sub add { call_sub("add_$main::form->{type}"); }
57 sub delete { call_sub("delete_$main::form->{type}"); }
58 sub save { call_sub("save_$main::form->{type}"); }
59 sub edit { call_sub("edit_$main::form->{type}"); }
60 sub continue { call_sub($main::form->{"nextsub"}); }
61 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
64 $main::lxdebug->enter_sub();
66 my $form = $main::form;
67 my %myconfig = %main::myconfig;
69 $main::auth->assert('config');
71 $form->{title} = "Add";
72 $form->{charttype} = "A";
73 AM->get_account(\%myconfig, \%$form);
75 $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
80 $main::lxdebug->leave_sub();
84 $main::lxdebug->enter_sub();
86 my $form = $main::form;
87 my %myconfig = %main::myconfig;
89 $main::auth->assert('config');
91 $form->{title} = "Edit";
92 AM->get_account(\%myconfig, \%$form);
94 foreach my $item (split(/:/, $form->{link})) {
95 $form->{$item} = "checked";
101 $main::lxdebug->leave_sub();
105 $main::lxdebug->enter_sub();
107 my $form = $main::form;
108 my %myconfig = %main::myconfig;
109 my $locale = $main::locale;
111 $main::auth->assert('config');
113 if ( $form->{action} eq 'edit_account') {
114 $form->{account_exists} = '1';
117 $form->{title} = $locale->text("$form->{title} Account");
119 $form->{"$form->{charttype}_checked"} = "checked";
120 $form->{"$form->{category}_checked"} = "checked";
122 $form->{select_tax} = "";
124 my @tax_report_pos = USTVA->report_variables({
125 myconfig => \%myconfig,
128 attribute => 'position',
132 if (@{ $form->{TAXKEY} }) {
133 foreach my $item (@{ $form->{TAXKEY} }) {
134 $item->{rate} = $item->{rate} * 100 . '%';
137 # Fill in empty row for new Taxkey
138 my $newtaxkey_ref = {
143 taxdescription => '',
150 push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
153 foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
155 # Fill in a runningnumber
156 $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
158 # Fill in the Taxkeys as select options
159 foreach my $item (@{ $form->{TAXKEY} }) {
160 if ($item->{id} == $taxkey_used->{tax_id}) {
161 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
162 qq|<option value="$item->{id}" selected="selected">|
163 . sprintf("%.2d", $item->{taxkey})
164 . qq|. $item->{taxdescription} ($item->{rate}) |
165 . $locale->text('Tax-o-matic Account')
166 . qq|: $item->{chart_accno}\n|;
169 $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
170 qq|<option value="$item->{id}">|
171 . sprintf("%.2d", $item->{taxkey})
172 . qq|. $item->{taxdescription} ($item->{rate}) |
173 . $locale->text('Tax-o-matic Account')
174 . qq|: $item->{chart_accno}\n|;
179 # Fill in the USTVA Numbers as select options
180 foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
182 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
184 elsif ( $item eq $taxkey_used->{pos_ustva} ) {
185 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
188 $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
197 # Newaccount Folgekonto
198 if (@{ $form->{NEWACCOUNT} || [] }) {
199 if (!$form->{new_chart_valid}) {
200 $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
202 foreach my $item (@{ $form->{NEWACCOUNT} }) {
203 if ($item->{id} == $form->{new_chart_id}) {
204 $form->{selectnewaccount} .=
205 qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
206 } elsif (!$form->{new_chart_valid}) {
207 $form->{selectnewaccount} .=
208 qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
214 my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
217 2 => "sonstige Erlöse",
218 3 => "Privatanteile",
220 5 => "Ausserordentliche Erträge",
221 6 => "Vereinnahmte Umsatzst.",
222 7 => "Umsatzsteuererstattungen",
223 8 => "Wareneingänge",
224 9 => "Löhne und Gehälter",
225 10 => "Gesetzl. sozialer Aufw.",
227 12 => "Gas, Strom, Wasser",
228 13 => "Instandhaltung",
229 14 => "Steuern, Versich., Beiträge",
231 16 => "Kfz-Versicherungen",
232 17 => "Sonst. Fahrzeugkosten",
233 18 => "Werbe- und Reisekosten",
234 19 => "Instandhaltung u. Werkzeuge",
235 20 => "Fachzeitschriften, Bücher",
236 21 => "Miete für Einrichtungen",
237 22 => "Rechts- und Beratungskosten",
238 23 => "Bürobedarf, Porto, Telefon",
239 24 => "Sonstige Aufwendungen",
240 25 => "Abschreibungen auf Anlagever.",
241 26 => "Abschreibungen auf GWG",
243 28 => "Umsatzsteuerzahlungen",
245 30 => "Ausserordentlicher Aufwand",
246 31 => "Betriebliche Steuern");
247 foreach my $item (sort({ $a <=> $b } keys(%eur))) {
248 my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
249 if ($item == $form->{pos_eur}) {
250 $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
252 $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
257 my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
261 2 => 'Best.Verdg.FE/UE',
262 3 => 'Aktiv.Eigenleistung',
263 4 => 'Mat./Wareneinkauf',
264 5 => 'So.betr.Erlöse',
265 10 => 'Personalkosten',
267 12 => 'Betriebl.Steuern',
268 13 => 'Vers./Beiträge',
269 14 => 'Kfz.Kosten o.St.',
270 15 => 'Werbe-Reisek.',
271 16 => 'Kosten Warenabgabe',
272 17 => 'Abschreibungen',
273 18 => 'Rep./instandhlt.',
274 19 => 'Übrige Steuern',
275 20 => 'Sonst.Kosten',
277 31 => 'Sonst.neutr.Aufw.',
279 33 => 'Sonst.neutr.Ertrag',
280 34 => 'Verr.kalk.Kosten',
281 35 => 'Steuern Eink.u.Ertr.');
282 foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
283 my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
284 if ($item == $form->{pos_bwa}) {
285 $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
287 $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
292 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
293 my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
294 foreach my $item ((1, 2, 3, 4)) {
295 if ($item == $form->{pos_bilanz}) {
296 $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
298 $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
303 # this is for our parser only! Do not remove.
304 # type=submit $locale->text('Add Account')
305 # type=submit $locale->text('Edit Account')
307 $form->{type} = "account";
309 # preselections category
311 my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
314 'A' => $locale->text('Asset'),
315 'L' => $locale->text('Liability'),
316 'Q' => $locale->text('Equity'),
317 'I' => $locale->text('Revenue'),
318 'E' => $locale->text('Expense'),
319 'C' => $locale->text('Costs'),
321 foreach my $item ( sort({ $a <=> $b } keys %category) ) {
322 if ($item eq $form->{category}) {
323 $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
325 $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
330 # preselection chart type
331 my @all_charttypes = ({'name' => $locale->text('Account'), 'value' => 'A'},
332 {'name' => $locale->text('Heading'), 'value' => 'H'},
334 my $selected_charttype = $form->{charttype};
337 # account where AR_tax or AP_tax is set are not orphaned if they are used as
338 # tax-o-matic account
339 if ( $form->{id} && !$form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
340 if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
341 $form->{orphaned} = 0;
345 my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
346 my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
350 my $parameters_ref = {
351 ChartTypeIsAccount => $ChartTypeIsAccount,
352 AccountIsPosted => $AccountIsPosted,
353 select_category => $select_category,
354 all_charttypes => \@all_charttypes,
355 selected_charttype => $selected_charttype,
356 select_bwa => $select_bwa,
357 select_bilanz => $select_bilanz,
358 select_eur => $select_eur,
361 # Ausgabe des Templates
362 print($form->parse_html_template('am/edit_accounts', $parameters_ref));
365 $main::lxdebug->leave_sub();
369 $::lxdebug->enter_sub;
370 $::auth->assert('config');
372 print $::form->parse_html_template('am/form_footer', {
373 show_save => !$::form->{id}
374 || ($::form->{id} && $::form->{orphaned})
375 || ($::form->{type} eq "account" && !$::form->{new_chart_valid}),
376 show_delete => $::form->{id} && $::form->{orphaned},
377 show_save_as_new => $::form->{id} && $::form->{type} eq "account",
380 $::lxdebug->leave_sub;
384 $main::lxdebug->enter_sub();
386 my $form = $main::form;
387 my %myconfig = %main::myconfig;
388 my $locale = $main::locale;
390 $main::auth->assert('config');
392 $form->isblank("accno", $locale->text('Account Number missing!'));
393 $form->isblank("description", $locale->text('Account Description missing!'));
395 if ($form->{charttype} eq 'A'){
396 $form->isblank("category", $locale->text('Account Type missing!'));
399 $form->redirect($locale->text('Account saved!'))
400 if (AM->save_account(\%myconfig, \%$form));
401 $form->error($locale->text('Cannot save account!'));
403 $main::lxdebug->leave_sub();
406 sub save_as_new_account {
407 $main::lxdebug->enter_sub();
409 my $form = $main::form;
410 my %myconfig = %main::myconfig;
411 my $locale = $main::locale;
413 $main::auth->assert('config');
415 $form->isblank("accno", $locale->text('Account Number missing!'));
416 $form->isblank("description", $locale->text('Account Description missing!'));
418 if ($form->{charttype} eq 'A'){
419 $form->isblank("category", $locale->text('Account Type missing!'));
422 for my $taxkey (0 .. 9) {
423 if ($form->{"taxkey_id_$taxkey"}) {
424 $form->{"taxkey_id_$taxkey"} = "NEW";
429 if ($form->{"original_accno"} &&
430 ($form->{"accno"} eq $form->{"original_accno"})) {
431 $form->error($locale->text('Account Number already used!'));
433 $form->redirect($locale->text('Account saved!'))
434 if (AM->save_account(\%myconfig, \%$form));
435 $form->error($locale->text('Cannot save account!'));
437 $main::lxdebug->leave_sub();
441 $main::lxdebug->enter_sub();
443 my $form = $main::form;
444 my %myconfig = %main::myconfig;
445 my $locale = $main::locale;
447 $main::auth->assert('config');
449 $form->{callback} = build_std_url('action=list_account');
450 my $link_edit_account = build_std_url('action=edit_account', 'callback');
452 CA->all_accounts(\%myconfig, \%$form);
454 foreach my $ca (@{ $form->{CA} }) {
459 if ($ca->{amount} > 0) {
460 $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
462 if ($ca->{amount} < 0) {
463 $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
465 $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:'';
466 $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
469 $form->use_stylesheet("list_accounts.css");
470 $form->{title} = $locale->text('Chart of Accounts');
475 my $parameters_ref = {
476 # hidden_variables => $_hidden_variables_ref,
479 # Ausgabe des Templates
480 print($form->parse_html_template('am/list_accounts', $parameters_ref));
482 $main::lxdebug->leave_sub();
487 sub list_account_details {
488 # Ajax Funktion aus list_account_details
489 $main::lxdebug->enter_sub();
491 my $form = $main::form;
492 my %myconfig = %main::myconfig;
493 my $locale = $main::locale;
495 $main::auth->assert('config');
497 my $chart_id = $form->{args};
499 CA->all_accounts(\%myconfig, \%$form, $chart_id);
501 foreach my $ca (@{ $form->{CA} }) {
503 $ca->{debit} = " ";
504 $ca->{credit} = " ";
506 if ($ca->{amount} > 0) {
508 $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
510 if ($ca->{amount} < 0) {
512 $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
515 my @links = split( q{:}, $ca->{link});
519 foreach my $link (@links){
520 $link = ( $link eq 'AR') ? $locale->text('Account Link AR')
521 : ( $link eq 'AP') ? $locale->text('Account Link AP')
522 : ( $link eq 'IC') ? $locale->text('Account Link IC')
523 : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount')
524 : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid')
525 : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax')
526 : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount')
527 : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid')
528 : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax')
529 : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale')
530 : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs')
531 : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart')
532 : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income')
533 : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense')
534 : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
535 : $locale->text('Unknown Link') . ': ' . $link;
536 $ca->{link} .= ($link ne '') ? "[$link] ":'';
539 $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
540 : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
541 : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
542 : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
543 : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
544 : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
545 : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
546 : $locale->text('Unknown Category') . ': ' . $ca->{category};
549 $form->{title} = $locale->text('Chart of Accounts');
551 print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
553 $main::lxdebug->leave_sub();
558 $main::lxdebug->enter_sub();
560 my $form = $main::form;
561 my %myconfig = %main::myconfig;
562 my $locale = $main::locale;
564 $main::auth->assert('config');
566 $form->{title} = $locale->text('Delete Account');
569 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
571 if ($form->{id} == $form->{$id}) {
572 $form->error($locale->text('Cannot delete default account!'));
576 $form->redirect($locale->text('Account deleted!'))
577 if (AM->delete_account(\%myconfig, \%$form));
578 $form->error($locale->text('Cannot delete account!'));
580 $main::lxdebug->leave_sub();
584 $main::lxdebug->enter_sub();
586 my $form = $main::form;
588 $main::auth->assert('config');
590 $form->{title} = "Add";
592 $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
597 $main::lxdebug->leave_sub();
601 $main::lxdebug->enter_sub();
603 my $form = $main::form;
604 my %myconfig = %main::myconfig;
606 $main::auth->assert('config');
608 $form->{title} = "Edit";
610 AM->get_lead(\%myconfig, \%$form);
614 $form->{orphaned} = 1;
617 $main::lxdebug->leave_sub();
621 $main::lxdebug->enter_sub();
623 my $form = $main::form;
624 my %myconfig = %main::myconfig;
625 my $locale = $main::locale;
627 $main::auth->assert('config');
629 AM->lead(\%myconfig, \%$form);
631 $form->{callback} = "am.pl?action=list_lead";
633 my $callback = $form->escape($form->{callback});
635 $form->{title} = $locale->text('Lead');
637 my @column_index = qw(description cost profit);
639 $column_header{description} =
640 qq|<th class=listheading width=100%>|
641 . $locale->text('Description')
651 <th class=listtop>$form->{title}</th>
654 <tr class=listheading>
657 map { print "$column_header{$_}\n" } @column_index;
663 my ($i, %column_data);
664 foreach my $ref (@{ $form->{ALL} }) {
670 <tr valign=top class=listrow$i>
673 # $lead = $ref->{lead};
675 $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
677 map { print "$column_data{$_}\n" } @column_index;
686 <td><hr size=3 noshade></td>
691 <form method=post action=am.pl>
693 <input name=callback type=hidden value="$form->{callback}">
695 <input type=hidden name=type value=lead>
697 <input class=submit type=submit name=action value="|
698 . $locale->text('Add') . qq|">
706 $main::lxdebug->leave_sub();
710 $main::lxdebug->enter_sub();
712 my $form = $main::form;
713 my $locale = $main::locale;
715 $main::auth->assert('config');
717 $form->{title} = $locale->text("$form->{title} Lead");
719 # $locale->text('Add Lead')
720 # $locale->text('Edit Lead')
722 $form->{description} =~ s/\"/"/g;
725 qq|<input name=description size=50 value="$form->{lead}">|;
732 <form method=post action=am.pl>
734 <input type=hidden name=id value=$form->{id}>
735 <input type=hidden name=type value=lead>
739 <th class=listtop colspan=2>$form->{title}</th>
743 <th align=right>| . $locale->text('Description') . qq|</th>
744 <td>$description</td>
746 <td colspan=2><hr size=3 noshade></td>
751 $main::lxdebug->leave_sub();
755 $main::lxdebug->enter_sub();
757 my $form = $main::form;
758 my %myconfig = %main::myconfig;
759 my $locale = $main::locale;
761 $main::auth->assert('config');
763 $form->isblank("description", $locale->text('Description missing!'));
764 AM->save_lead(\%myconfig, \%$form);
765 $form->redirect($locale->text('lead saved!'));
767 $main::lxdebug->leave_sub();
771 $main::lxdebug->enter_sub();
773 my $form = $main::form;
774 my %myconfig = %main::myconfig;
775 my $locale = $main::locale;
777 $main::auth->assert('config');
779 AM->delete_lead(\%myconfig, \%$form);
780 $form->redirect($locale->text('lead deleted!'));
782 $main::lxdebug->leave_sub();
786 $main::lxdebug->enter_sub();
788 my $form = $main::form;
790 $main::auth->assert('config');
792 $form->{title} = "Add";
794 $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
799 $main::lxdebug->leave_sub();
803 $main::lxdebug->enter_sub();
805 my $form = $main::form;
806 my %myconfig = %main::myconfig;
808 $main::auth->assert('config');
810 $form->{title} = "Edit";
812 AM->get_language(\%myconfig, \%$form);
816 $form->{orphaned} = 1;
819 $main::lxdebug->leave_sub();
823 $::lxdebug->enter_sub;
824 $::auth->assert('config');
826 AM->language(\%::myconfig, $::form);
828 $::form->{callback} = "am.pl?action=list_language";
829 $::form->{title} = $::locale->text('Languages');
833 print $::form->parse_html_template('am/language_list');
835 $::lxdebug->leave_sub;
838 sub language_header {
839 $::lxdebug->enter_sub;
840 $::auth->assert('config');
842 # $locale->text('Add Language')
843 # $locale->text('Edit Language')
844 $::form->{title} = $::locale->text("$::form->{title} Language");
848 print $::form->parse_html_template('am/language_header', {
849 numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00' ],
850 dateformats => [ qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
853 $::lxdebug->leave_sub;
857 $main::lxdebug->enter_sub();
859 my $form = $main::form;
860 my %myconfig = %main::myconfig;
861 my $locale = $main::locale;
863 $main::auth->assert('config');
865 $form->isblank("description", $locale->text('Language missing!'));
866 $form->isblank("template_code", $locale->text('Template Code missing!'));
867 $form->isblank("article_code", $locale->text('Article Code missing!'));
868 AM->save_language(\%myconfig, \%$form);
869 $form->redirect($locale->text('Language saved!'));
871 $main::lxdebug->leave_sub();
874 sub delete_language {
875 $main::lxdebug->enter_sub();
877 my $form = $main::form;
878 my %myconfig = %main::myconfig;
879 my $locale = $main::locale;
881 $main::auth->assert('config');
883 AM->delete_language(\%myconfig, \%$form);
884 $form->redirect($locale->text('Language deleted!'));
886 $main::lxdebug->leave_sub();
890 sub add_buchungsgruppe {
891 $main::lxdebug->enter_sub();
893 my $form = $main::form;
894 my %myconfig = %main::myconfig;
895 my $locale = $main::locale;
897 $main::auth->assert('config');
899 # $locale->text("Add Buchungsgruppe")
900 # $locale->text("Edit Buchungsgruppe")
901 $form->{title} = "Add";
903 $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
905 AM->get_buchungsgruppe(\%myconfig, \%$form);
906 $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
907 for (my $i = 0; 4 > $i; $i++) {
908 map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
912 &buchungsgruppe_header;
915 $main::lxdebug->leave_sub();
918 sub edit_buchungsgruppe {
919 $main::lxdebug->enter_sub();
921 my $form = $main::form;
922 my %myconfig = %main::myconfig;
924 $main::auth->assert('config');
926 $form->{title} = "Edit";
928 AM->get_buchungsgruppe(\%myconfig, \%$form);
930 &buchungsgruppe_header;
934 $main::lxdebug->leave_sub();
937 sub list_buchungsgruppe {
938 $main::lxdebug->enter_sub();
940 my $form = $main::form;
941 my %myconfig = %main::myconfig;
942 my $locale = $main::locale;
944 $main::auth->assert('config');
946 AM->buchungsgruppe(\%myconfig, \%$form);
948 $form->{callback} = "am.pl?action=list_buchungsgruppe";
950 my $callback = $form->escape($form->{callback});
952 $form->{title} = $locale->text('Buchungsgruppen');
954 my @column_index = qw(up down description inventory_accno
955 income_accno_0 expense_accno_0
956 income_accno_1 expense_accno_1
957 income_accno_2 expense_accno_2
958 income_accno_3 expense_accno_3 );
961 qq|<th class="listheading" width="16">|
962 . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
964 $column_header{down} =
965 qq|<th class="listheading" width="16">|
966 . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
968 $column_header{description} =
969 qq|<th class="listheading" width="40%">|
970 . $locale->text('Description')
972 $column_header{inventory_accno} =
973 qq|<th class=listheading>|
974 . $locale->text('Bestandskonto')
976 $column_header{income_accno_0} =
977 qq|<th class=listheading>|
978 . $locale->text('National Revenues')
980 $column_header{expense_accno_0} =
981 qq|<th class=listheading>|
982 . $locale->text('National Expenses')
984 $column_header{income_accno_1} =
985 qq|<th class=listheading>|
986 . $locale->text('Revenues EU with UStId')
988 $column_header{expense_accno_1} =
989 qq|<th class=listheading>|
990 . $locale->text('Expenses EU with UStId')
992 $column_header{income_accno_2} =
993 qq|<th class=listheading>|
994 . $locale->text('Revenues EU without UStId')
996 $column_header{expense_accno_2} =
997 qq|<th class=listheading>|
998 . $locale->text('Expenses EU without UStId')
1000 $column_header{income_accno_3} =
1001 qq|<th class=listheading>|
1002 . $locale->text('Foreign Revenues')
1004 $column_header{expense_accno_3} =
1005 qq|<th class=listheading>|
1006 . $locale->text('Foreign Expenses')
1015 <th class=listtop>$form->{title}</th>
1017 <tr height="5"></tr>
1021 <tr class=listheading>
1024 map { print "$column_header{$_}\n" } @column_index;
1030 my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
1033 my ($i, %column_data);
1034 foreach my $ref (@{ $form->{ALL} }) {
1040 <tr valign=top class=listrow$i>
1044 my $pref = $form->{ALL}->[$row - 1];
1046 qq|<td align="center" valign="center" width="16">| .
1047 qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
1048 qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
1051 $column_data{up} = qq|<td width="16"> </td>|;
1054 if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
1055 $column_data{down} = qq|<td width="16"> </td>|;
1057 my $nref = $form->{ALL}->[$row + 1];
1058 $column_data{down} =
1059 qq|<td align="center" valign="center" width="16">| .
1060 qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
1061 qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
1065 $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
1066 $column_data{inventory_accno} = qq|<td align=right>$ref->{inventory_accno}</td>|;
1067 $column_data{income_accno_0} =
1068 qq|<td align=right>$ref->{income_accno_0}</td>|;
1069 $column_data{expense_accno_0} = qq|<td align=right>$ref->{expense_accno_0}</td>|;
1070 $column_data{income_accno_1} =
1071 qq|<td align=right>$ref->{income_accno_1}</td>|;
1072 $column_data{expense_accno_1} = qq|<td align=right>$ref->{expense_accno_1}</td>|;
1073 $column_data{income_accno_2} =
1074 qq|<td align=right>$ref->{income_accno_2}</td>|;
1075 $column_data{expense_accno_2} = qq|<td align=right>$ref->{expense_accno_2}</td>|;
1076 $column_data{income_accno_3} =
1077 qq|<td align=right>$ref->{income_accno_3}</td>|;
1078 $column_data{expense_accno_3} = qq|<td align=right>$ref->{expense_accno_3}</td>|;
1080 map { print "$column_data{$_}\n" } @column_index;
1094 <td><hr size=3 noshade></td>
1099 <form method=post action=am.pl>
1101 <input name=callback type=hidden value="$form->{callback}">
1103 <input type=hidden name=type value=buchungsgruppe>
1105 <input class=submit type=submit name=action value="|
1106 . $locale->text('Add') . qq|">
1114 $main::lxdebug->leave_sub();
1117 sub buchungsgruppe_header {
1118 $main::lxdebug->enter_sub();
1120 my $form = $main::form;
1121 my $locale = $main::locale;
1123 $main::auth->assert('config');
1125 $form->{title} = $locale->text("$form->{title} Buchungsgruppe");
1127 # $locale->text('Add Accounting Group')
1128 # $locale->text('Edit Accounting Group')
1130 my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
1131 my %acc_type_map = (
1132 "IC" => $acc_inventory,
1133 "IC_income" => $acc_income,
1134 "IC_sale" => $acc_income,
1135 "IC_expense" => $acc_expense,
1136 "IC_cogs" => $acc_expense,
1139 foreach my $key (keys(%acc_type_map)) {
1140 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1141 $acc_type_map{$key}->{$ref->{"id"}} = $ref;
1145 foreach my $type (qw(IC IC_income IC_expense)) {
1146 $form->{"select$type"} =
1148 map({ "<option value=$_->{id} $_->{selected}>" .
1149 "$_->{accno}--" . H($_->{description}) . "</option>" }
1150 sort({ $a->{"accno"} cmp $b->{"accno"} }
1151 values(%{$acc_type_map{$type}}))));
1155 $form->{selectIC} =~ s/selected//g;
1156 $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/ value=$form->{inventory_accno_id} selected/;
1157 $form->{selectIC_income} =~ s/selected//g;
1158 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/ value=$form->{income_accno_id_0} selected/;
1159 $form->{selectIC_expense} =~ s/selected//g;
1160 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/ value=$form->{expense_accno_id_0} selected/;
1164 if ( $::instance_conf->get_inventory_system eq 'perpetual' ) { # was !$::lx_office_conf{system}->{eur}) { }
1167 <th align=right>| . $locale->text('Inventory') . qq|</th>
1168 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
1169 <input name=selectIC type=hidden value="$form->{selectIC}">
1171 } elsif ( $::instance_conf->get_inventory_system eq 'periodic' ) {
1172 # don't allow choice of inventory accno and don't show that line
1174 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
1178 $linkaccounts .= qq|
1180 <th align=right>| . $locale->text('National Revenues') . qq|</th>
1181 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
1184 <th align=right>| . $locale->text('National Expenses') . qq|</th>
1185 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
1188 $form->{selectIC_income} =~ s/selected//g;
1189 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/ value=$form->{income_accno_id_1} selected/;
1190 $form->{selectIC_expense} =~ s/selected//g;
1191 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/ value=$form->{expense_accno_id_1} selected/;
1193 $linkaccounts .= qq| <tr>
1194 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
1195 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
1198 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
1199 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
1203 $form->{selectIC_income} =~ s/selected//g;
1204 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/ value=$form->{income_accno_id_2} selected/;
1205 $form->{selectIC_expense} =~ s/selected//g;
1206 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/ value=$form->{expense_accno_id_2} selected/;
1209 $linkaccounts .= qq| <tr>
1210 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
1211 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
1214 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
1215 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
1219 $form->{selectIC_income} =~ s/selected//g;
1220 $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/ value=$form->{income_accno_id_3} selected/;
1221 $form->{selectIC_expense} =~ s/selected//g;
1222 $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/ value=$form->{expense_accno_id_3} selected/;
1225 $linkaccounts .= qq| <tr>
1226 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
1227 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
1230 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
1231 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
1241 <form method=post action=am.pl>
1243 <input type=hidden name=id value=$form->{id}>
1244 <input type=hidden name=type value=buchungsgruppe>
1248 <th class=listtop colspan=2>$form->{title}</th>
1250 <tr height="5"></tr>
1252 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
1253 <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1256 <td colspan=2><hr size=3 noshade></td>
1261 $main::lxdebug->leave_sub();
1264 sub save_buchungsgruppe {
1265 $main::lxdebug->enter_sub();
1267 my $form = $main::form;
1268 my %myconfig = %main::myconfig;
1269 my $locale = $main::locale;
1271 $main::auth->assert('config');
1273 $form->isblank("description", $locale->text('Description missing!'));
1275 AM->save_buchungsgruppe(\%myconfig, \%$form);
1276 $form->redirect($locale->text('Accounting Group saved!'));
1278 $main::lxdebug->leave_sub();
1281 sub delete_buchungsgruppe {
1282 $main::lxdebug->enter_sub();
1284 my $form = $main::form;
1285 my %myconfig = %main::myconfig;
1286 my $locale = $main::locale;
1288 $main::auth->assert('config');
1290 AM->delete_buchungsgruppe(\%myconfig, \%$form);
1291 $form->redirect($locale->text('Accounting Group deleted!'));
1293 $main::lxdebug->leave_sub();
1296 sub swap_buchungsgruppen {
1297 $main::lxdebug->enter_sub();
1299 my $form = $main::form;
1300 my %myconfig = %main::myconfig;
1302 $main::auth->assert('config');
1304 AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
1305 list_buchungsgruppe();
1307 $main::lxdebug->leave_sub();
1311 $main::lxdebug->enter_sub();
1313 my $form = $main::form;
1314 my %myconfig = %main::myconfig;
1315 my $locale = $main::locale;
1317 # get defaults for account numbers and last numbers
1318 AM->defaultaccounts(\%myconfig, \%$form);
1319 $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
1321 map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
1324 my $all_languages = SL::DB::Manager::Language->get_all;
1326 # EÜR = cash, Bilanzierung = accrual
1328 foreach my $key (keys %{ $form->{IC} }) {
1329 foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
1330 my $array = "ACCNOS_" . uc($key);
1331 $form->{$array} ||= [];
1333 my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
1334 push @{ $form->{$array} }, {
1337 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
1342 $form->{title} = $locale->text('Ranges of numbers and default accounts');
1345 print $form->parse_html_template('am/edit_defaults',
1346 { ALL_LANGUAGES => $all_languages, });
1348 $main::lxdebug->leave_sub();
1352 $main::lxdebug->enter_sub();
1354 my $form = $main::form;
1355 my $locale = $main::locale;
1357 AM->save_defaults();
1359 $form->redirect($locale->text('Defaults saved.'));
1361 $main::lxdebug->leave_sub();
1364 sub _build_cfg_options {
1365 my $form = $main::form;
1366 my %myconfig = %main::myconfig;
1369 my $array = uc($idx) . 'S';
1371 $form->{$array} = [];
1372 foreach my $item (@_) {
1373 push @{ $form->{$array} }, {
1376 'selected' => $item eq $myconfig{$idx},
1382 $main::lxdebug->enter_sub();
1384 my $form = $main::form;
1385 my %myconfig = %main::myconfig;
1386 my $locale = $main::locale;
1388 _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
1389 _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
1392 if ($::lx_office_conf{print_templates}->{opendocument}
1393 && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
1394 && $::lx_office_conf{applications}->{xvfb} && (-x $::lx_office_conf{applications}->{xvfb})) {
1395 push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
1396 "value" => "opendocument_pdf" });
1398 if ($::lx_office_conf{print_templates}->{latex}) {
1399 push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
1401 push(@formats, { "name" => "HTML", "value" => "html" });
1402 if ($::lx_office_conf{print_templates}->{latex}) {
1403 push(@formats, { "name" => $locale->text("Postscript"),
1404 "value" => "postscript" });
1406 if ($::lx_office_conf{print_templates}->{opendocument}) {
1407 push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
1408 "value" => "opendocument" });
1411 if (!$myconfig{"template_format"}) {
1412 $myconfig{"template_format"} = "pdf";
1414 $form->{TEMPLATE_FORMATS} = [];
1415 foreach my $item (@formats) {
1416 push @{ $form->{TEMPLATE_FORMATS} }, {
1417 'name' => $item->{name},
1418 'value' => $item->{value},
1419 'selected' => $item->{value} eq $myconfig{template_format},
1423 if (!$myconfig{"default_media"}) {
1424 $myconfig{"default_media"} = "screen";
1427 my %selected = ($myconfig{"default_media"} => "selected");
1429 { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
1430 { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
1431 { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
1434 $form->{PRINTERS} = [ SL::Printer->all_printers(%::myconfig) ];
1436 my %countrycodes = User->country_codes;
1438 $form->{COUNTRYCODES} = [];
1439 foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
1440 push @{ $form->{COUNTRYCODES} }, {
1441 'name' => $countrycodes{$countrycode},
1442 'value' => $countrycode,
1443 'selected' => $countrycode eq $myconfig{countrycode},
1447 $form->{STYLESHEETS} = [];
1448 foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
1449 push @{ $form->{STYLESHEETS} }, {
1452 'selected' => $item eq $myconfig{stylesheet},
1456 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
1457 $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
1458 $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
1460 $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
1463 print $form->parse_html_template('am/config');
1465 $main::lxdebug->leave_sub();
1468 sub save_preferences {
1469 $main::lxdebug->enter_sub();
1471 my $form = $main::form;
1472 my %myconfig = %main::myconfig;
1473 my $locale = $main::locale;
1475 $form->{stylesheet} = $form->{usestylesheet};
1477 TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
1479 if (AM->save_preferences(\%myconfig, $form)) {
1480 if ($::auth->can_change_password()
1481 && defined $form->{new_password}
1482 && ($form->{new_password} ne '********')) {
1483 my $verifier = SL::Auth::PasswordPolicy->new;
1484 my $result = $verifier->verify($form->{new_password});
1486 if ($result != SL::Auth::PasswordPolicy->OK()) {
1487 $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
1490 $::auth->change_password($form->{login}, $form->{new_password});
1492 $form->{password} = $form->{new_password};
1493 $::auth->set_session_value('password', $form->{password});
1494 $::auth->create_or_refresh_session();
1497 $form->redirect($locale->text('Preferences saved!'));
1500 $form->error($locale->text('Cannot save preferences!'));
1502 $main::lxdebug->leave_sub();
1506 $main::lxdebug->enter_sub();
1508 my $form = $main::form;
1509 my %myconfig = %main::myconfig;
1510 my $locale = $main::locale;
1512 $main::auth->assert('config');
1514 $form->{title} = $locale->text('Audit Control');
1516 AM->closedto(\%myconfig, \%$form);
1523 <form method=post action=am.pl>
1526 <tr><th class=listtop>$form->{title}</th></tr>
1527 <tr height="5"></tr>
1532 <th>| . $locale->text('Close Books up to') . qq|</th>
1533 <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
1543 <input type=hidden name=nextsub value=doclose>
1545 <input type=submit class=submit name=action value="|
1546 . $locale->text('Continue') . qq|">
1554 $main::lxdebug->leave_sub();
1558 $main::lxdebug->enter_sub();
1560 my $form = $main::form;
1561 my %myconfig = %main::myconfig;
1562 my $locale = $main::locale;
1564 $main::auth->assert('config');
1566 AM->closebooks(\%myconfig, \%$form);
1568 if ($form->{closedto}) {
1570 $locale->text('Books closed up to') . " "
1571 . $locale->date(\%myconfig, $form->{closedto}, 1));
1573 $form->redirect($locale->text('Books are open'));
1576 $main::lxdebug->leave_sub();
1580 $main::lxdebug->enter_sub();
1582 my $form = $main::form;
1583 my %myconfig = %main::myconfig;
1584 my $locale = $main::locale;
1586 $main::auth->assert('config');
1588 my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1589 AM->units_in_use(\%myconfig, $form, $units);
1590 map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
1592 my @languages = AM->language(\%myconfig, $form, 1);
1594 my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
1597 foreach (@unit_list) {
1598 $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
1599 $_->{"UNITLANGUAGES"} = [];
1600 foreach my $lang (@languages) {
1601 push(@{ $_->{"UNITLANGUAGES"} },
1603 "unit" => $_->{"name"},
1604 "language_id" => $lang->{"id"},
1605 "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
1606 "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
1612 $units = AM->retrieve_units(\%myconfig, $form);
1613 my $ddbox = AM->unit_select_data($units, undef, 1);
1615 $form->{"title"} = $locale->text("Add and edit units");
1617 print($form->parse_html_template("am/edit_units",
1618 { "UNITS" => \@unit_list,
1619 "NEW_BASE_UNIT_DDBOX" => $ddbox,
1620 "LANGUAGES" => \@languages,
1623 $main::lxdebug->leave_sub();
1627 $main::lxdebug->enter_sub();
1629 my $form = $main::form;
1630 my %myconfig = %main::myconfig;
1631 my $locale = $main::locale;
1633 $main::auth->assert('config');
1635 $form->isblank("new_name", $locale->text("The name is missing."));
1636 my $units = AM->retrieve_units(\%myconfig, $form);
1637 my $all_units = AM->retrieve_units(\%myconfig, $form);
1638 $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
1640 my ($base_unit, $factor);
1641 if ($form->{"new_base_unit"}) {
1642 $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
1644 $form->isblank("new_factor", $locale->text("The factor is missing."));
1645 $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
1646 $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
1647 $base_unit = $form->{"new_base_unit"};
1651 foreach my $lang (AM->language(\%myconfig, $form, 1)) {
1652 next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
1653 push(@languages, { "id" => $lang->{"id"},
1654 "localized" => $form->{"new_localized_$lang->{id}"},
1655 "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
1659 AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
1661 $form->{"saved_message"} = $locale->text("The unit has been saved.");
1665 $main::lxdebug->leave_sub();
1668 sub set_unit_languages {
1669 $main::lxdebug->enter_sub();
1671 my $form = $main::form;
1673 $main::auth->assert('config');
1675 my ($unit, $languages, $idx) = @_;
1677 $unit->{"LANGUAGES"} = [];
1679 foreach my $lang (@{$languages}) {
1680 push(@{ $unit->{"LANGUAGES"} },
1681 { "id" => $lang->{"id"},
1682 "localized" => $form->{"localized_${idx}_$lang->{id}"},
1683 "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
1687 $main::lxdebug->leave_sub();
1691 $main::lxdebug->enter_sub();
1693 my $form = $main::form;
1694 my %myconfig = %main::myconfig;
1695 my $locale = $main::locale;
1697 $main::auth->assert('config');
1699 my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
1700 AM->units_in_use(\%myconfig, $form, $old_units);
1702 my @languages = AM->language(\%myconfig, $form, 1);
1705 my @delete_units = ();
1706 foreach my $i (1..($form->{"rowcount"} * 1)) {
1707 my $old_unit = $old_units->{$form->{"old_name_$i"}};
1709 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
1712 if ($form->{"unchangeable_$i"}) {
1713 $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
1714 $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
1715 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1719 if ($old_unit->{"in_use"}) {
1720 $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
1723 if ($form->{"delete_$i"}) {
1724 push(@delete_units, $old_unit->{"name"});
1728 $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
1730 $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
1731 my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
1732 $new_units->{$form->{"name_$i"}} = \%h;
1733 $new_units->{$form->{"name_$i"}}->{"row"} = $i;
1734 set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
1737 foreach my $unit (values(%{$new_units})) {
1738 next unless ($unit->{"old_name"});
1739 if ($unit->{"base_unit"}) {
1740 $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"}))
1741 unless (defined($new_units->{$unit->{"base_unit"}}));
1742 $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
1743 $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
1745 $unit->{"base_unit"} = undef;
1746 $unit->{"factor"} = undef;
1750 foreach my $unit (values(%{$new_units})) {
1751 next if ($unit->{"unchanged_unit"});
1753 map({ $_->{"seen"} = 0; } values(%{$new_units}));
1754 my $new_unit = $unit;
1755 while ($new_unit->{"base_unit"}) {
1756 $new_unit->{"seen"} = 1;
1757 $new_unit = $new_units->{$new_unit->{"base_unit"}};
1758 if ($new_unit->{"seen"}) {
1759 $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, " .
1760 "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
1765 AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
1767 $form->{"saved_message"} = $locale->text("The units have been saved.");
1771 $main::lxdebug->leave_sub();
1774 sub show_history_search {
1775 $main::lxdebug->enter_sub();
1777 my $form = $main::form;
1778 my $locale = $main::locale;
1780 $main::auth->assert('config');
1782 $form->{title} = $locale->text("History Search");
1785 print $form->parse_html_template("common/search_history");
1787 $main::lxdebug->leave_sub();
1790 sub show_am_history {
1791 $main::lxdebug->enter_sub();
1793 my $form = $main::form;
1794 my %myconfig = %main::myconfig;
1795 my $locale = $main::locale;
1797 $main::auth->assert('config');
1799 my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
1800 $form->{order} ||= 'h.itime--1';
1802 my %search = ( "Artikelnummer" => "parts",
1803 "Kundennummer" => "customer",
1804 "Lieferantennummer" => "vendor",
1805 "Projektnummer" => "project",
1806 "Buchungsnummer" => "oe",
1807 "Eingangsrechnungnummer" => "ap",
1808 "Ausgangsrechnungnummer" => "ar",
1809 "Mahnungsnummer" => "dunning"
1811 my %searchNo = ( "Artikelnummer" => "partnumber",
1812 "Kundennummer" => "customernumber",
1813 "Lieferantennummer" => "vendornumber",
1814 "Projektnummer" => "projectnumber",
1815 "Buchungsnummer" => "ordnumber",
1816 "Eingangsrechnungnummer" => "invnumber",
1817 "Ausgangsrechnungnummer" => "invnumber",
1818 "Mahnungsnummer" => "dunning_id"
1821 my $dbh = $form->dbconnect(\%myconfig);
1824 $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
1825 $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
1826 $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
1827 if ($form->{mitarbeiter} =~ m/^\d+$/) {
1828 $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
1829 } elsif ($form->{mitarbeiter}) {
1830 $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
1833 my $query = qq|SELECT trans_id AS id FROM history_erp | .
1834 ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
1835 : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
1837 my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
1838 my $daten .= shift @ids;
1839 $daten .= join '', map { " OR trans_id = $_" } @ids;
1841 my ($sort, $sortby) = split(/\-\-/, $form->{order});
1842 $sort =~ s/.*\.(.*)$/$1/;
1844 $form->{title} = $locale->text("History Search");
1847 print $form->parse_html_template("common/show_history",
1848 { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
1849 "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
1852 uc($sort) . "BY" => $sortby,
1853 'callback' => $callback,
1857 $main::lxdebug->leave_sub();
1861 $main::lxdebug->enter_sub();
1863 my $form = $main::form;
1864 my $locale = $main::locale;
1866 $main::auth->assert('config');
1868 $form->{title} = $locale->text('Add');
1870 $form->{callback} ||= "am.pl?action=add_tax";
1872 _get_taxaccount_selection();
1876 my $parameters_ref = {
1877 # ChartTypeIsAccount => $ChartTypeIsAccount,
1880 # Ausgabe des Templates
1881 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1883 $main::lxdebug->leave_sub();
1887 $main::lxdebug->enter_sub();
1889 my $form = $main::form;
1890 my %myconfig = %main::myconfig;
1891 my $locale = $main::locale;
1893 $main::auth->assert('config');
1895 $form->{title} = $locale->text('Edit');
1897 AM->get_tax(\%myconfig, \%$form);
1898 _get_taxaccount_selection();
1900 $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
1904 my $parameters_ref = {
1907 # Ausgabe des Templates
1908 print($form->parse_html_template('am/edit_tax', $parameters_ref));
1910 $main::lxdebug->leave_sub();
1914 $main::lxdebug->enter_sub();
1916 my $form = $main::form;
1917 my %myconfig = %main::myconfig;
1918 my $locale = $main::locale;
1920 $main::auth->assert('config');
1922 AM->taxes(\%myconfig, \%$form);
1924 map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
1926 $form->{callback} = build_std_url('action=list_tax');
1928 $form->{title} = $locale->text('Tax-O-Matic');
1932 my $parameters_ref = {
1935 # Ausgabe des Templates
1936 print($form->parse_html_template('am/list_tax', $parameters_ref));
1938 $main::lxdebug->leave_sub();
1941 sub _get_taxaccount_selection{
1942 $main::lxdebug->enter_sub();
1944 my $form = $main::form;
1945 my %myconfig = %main::myconfig;
1947 $main::auth->assert('config');
1949 AM->get_tax_accounts(\%myconfig, \%$form);
1951 map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
1953 $main::lxdebug->leave_sub();
1957 $main::lxdebug->enter_sub();
1959 my $form = $main::form;
1960 my %myconfig = %main::myconfig;
1961 my $locale = $main::locale;
1963 $main::auth->assert('config');
1965 $form->isblank("rate", $locale->text('Taxrate missing!'));
1966 $form->isblank("taxdescription", $locale->text('Taxdescription missing!'));
1967 $form->isblank("taxkey", $locale->text('Taxkey missing!'));
1969 $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
1971 if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
1972 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1975 if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
1976 $form->error($locale->text('Tax Percent is a number between 0 and 100'));
1979 AM->save_tax(\%myconfig, \%$form);
1980 $form->redirect($locale->text('Tax saved!'));
1982 $main::lxdebug->leave_sub();
1986 $main::lxdebug->enter_sub();
1988 my $form = $main::form;
1989 my %myconfig = %main::myconfig;
1990 my $locale = $main::locale;
1992 $main::auth->assert('config');
1994 AM->delete_tax(\%myconfig, \%$form);
1995 $form->redirect($locale->text('Tax deleted!'));
1997 $main::lxdebug->leave_sub();
2000 sub add_price_factor {
2001 $main::lxdebug->enter_sub();
2003 my $form = $main::form;
2004 my $locale = $main::locale;
2006 $main::auth->assert('config');
2008 $form->{title} = $locale->text('Add Price Factor');
2009 $form->{callback} ||= build_std_url('action=add_price_factor');
2010 $form->{fokus} = 'description';
2013 print $form->parse_html_template('am/edit_price_factor');
2015 $main::lxdebug->leave_sub();
2018 sub edit_price_factor {
2019 $main::lxdebug->enter_sub();
2021 my $form = $main::form;
2022 my %myconfig = %main::myconfig;
2023 my $locale = $main::locale;
2025 $main::auth->assert('config');
2027 $form->{title} = $locale->text('Edit Price Factor');
2028 $form->{callback} ||= build_std_url('action=add_price_factor');
2029 $form->{fokus} = 'description';
2031 AM->get_price_factor(\%myconfig, $form);
2033 $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
2036 print $form->parse_html_template('am/edit_price_factor');
2038 $main::lxdebug->leave_sub();
2041 sub list_price_factors {
2042 $main::lxdebug->enter_sub();
2044 my $form = $main::form;
2045 my %myconfig = %main::myconfig;
2046 my $locale = $main::locale;
2048 $main::auth->assert('config');
2050 AM->get_all_price_factors(\%myconfig, \%$form);
2052 foreach my $current (@{ $form->{PRICE_FACTORS} }) {
2053 $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
2056 $form->{callback} = build_std_url('action=list_price_factors');
2057 $form->{title} = $locale->text('Price Factors');
2058 $form->{url_base} = build_std_url('callback');
2061 print $form->parse_html_template('am/list_price_factors');
2063 $main::lxdebug->leave_sub();
2066 sub save_price_factor {
2067 $main::lxdebug->enter_sub();
2069 my $form = $main::form;
2070 my %myconfig = %main::myconfig;
2071 my $locale = $main::locale;
2073 $main::auth->assert('config');
2075 $form->isblank("description", $locale->text('Description missing!'));
2076 $form->isblank("factor", $locale->text('Factor missing!'));
2078 $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
2080 AM->save_price_factor(\%myconfig, $form);
2082 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
2084 $form->redirect($locale->text('Price factor saved!'));
2086 $main::lxdebug->leave_sub();
2089 sub delete_price_factor {
2090 $main::lxdebug->enter_sub();
2092 my $form = $main::form;
2093 my %myconfig = %main::myconfig;
2094 my $locale = $main::locale;
2096 $main::auth->assert('config');
2098 AM->delete_price_factor(\%myconfig, \%$form);
2100 $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
2102 $form->redirect($locale->text('Price factor deleted!'));
2104 $main::lxdebug->leave_sub();
2108 $main::lxdebug->enter_sub();
2110 my $form = $main::form;
2111 my $locale = $main::locale;
2113 $main::auth->assert('config');
2115 $form->{title} = $locale->text('Add Warehouse');
2116 $form->{callback} ||= build_std_url('action=add_warehouse');
2117 $form->{fokus} = 'description';
2120 print $form->parse_html_template('am/edit_warehouse');
2122 $main::lxdebug->leave_sub();
2125 sub edit_warehouse {
2126 $main::lxdebug->enter_sub();
2128 my $form = $main::form;
2129 my %myconfig = %main::myconfig;
2130 my $locale = $main::locale;
2132 $main::auth->assert('config');
2134 AM->get_warehouse(\%myconfig, $form);
2136 $form->get_lists('employees' => 'EMPLOYEES');
2138 $form->{title} = $locale->text('Edit Warehouse');
2139 $form->{callback} ||= build_std_url('action=list_warehouses');
2140 $form->{fokus} = 'description';
2143 print $form->parse_html_template('am/edit_warehouse');
2145 $main::lxdebug->leave_sub();
2148 sub list_warehouses {
2149 $main::lxdebug->enter_sub();
2151 my $form = $main::form;
2152 my %myconfig = %main::myconfig;
2153 my $locale = $main::locale;
2155 $main::auth->assert('config');
2157 AM->get_all_warehouses(\%myconfig, $form);
2159 $form->{callback} = build_std_url('action=list_warehouses');
2160 $form->{title} = $locale->text('Warehouses');
2161 $form->{url_base} = build_std_url('callback');
2164 print $form->parse_html_template('am/list_warehouses');
2166 $main::lxdebug->leave_sub();
2169 sub save_warehouse {
2170 $main::lxdebug->enter_sub();
2172 my $form = $main::form;
2173 my %myconfig = %main::myconfig;
2174 my $locale = $main::locale;
2176 $main::auth->assert('config');
2178 $form->isblank("description", $locale->text('Description missing!'));
2180 $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
2182 AM->save_warehouse(\%myconfig, $form);
2184 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
2186 $form->redirect($locale->text('Warehouse saved.'));
2188 $main::lxdebug->leave_sub();
2191 sub delete_warehouse {
2192 $main::lxdebug->enter_sub();
2194 my $form = $main::form;
2195 my %myconfig = %main::myconfig;
2196 my $locale = $main::locale;
2198 $main::auth->assert('config');
2200 if (!$form->{confirmed}) {
2201 $form->{title} = $locale->text('Confirmation');
2204 print $form->parse_html_template('am/confirm_delete_warehouse');
2208 if (AM->delete_warehouse(\%myconfig, $form)) {
2209 $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
2210 $form->redirect($locale->text('Warehouse deleted.'));
2213 $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
2216 $main::lxdebug->leave_sub();
2220 $main::lxdebug->enter_sub();
2222 my $form = $main::form;
2223 my %myconfig = %main::myconfig;
2224 my $locale = $main::locale;
2226 $main::auth->assert('config');
2228 AM->save_bins(\%myconfig, $form);
2230 $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
2232 $form->redirect($locale->text('Bins saved.'));
2234 $main::lxdebug->leave_sub();