X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fam.pl;h=d9d484269d0e26c55810f58f36cf99e8eb39c74c;hb=5400d2499ba3e626958171eb33c6e8bab6f98370;hp=b41b0ec9927034a13f40834c928a2aa1bbf8b69b;hpb=4dbb09950c9f5596646537c12d991c99086fe7c1;p=kivitendo-erp.git diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index b41b0ec99..d9d484269 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -31,50 +31,65 @@ # #====================================================================== - +use SL::Auth; use SL::AM; use SL::CA; use SL::Form; use SL::User; +use SL::USTVA; +use SL::Iconv; +use SL::TODO; +use CGI::Ajax; +use CGI; +use Data::Dumper; -1; -# end of main +require "bin/mozilla/common.pl"; +use strict; +1; -sub add { &{ "add_$form->{type}" } }; -sub edit { &{ "edit_$form->{type}" } }; -sub save { &{ "save_$form->{type}" } }; -sub delete { &{ "delete_$form->{type}" } }; +# end of main +sub add { call_sub("add_$main::form->{type}"); } +sub delete { call_sub("delete_$main::form->{type}"); } +sub save { call_sub("save_$main::form->{type}"); } +sub edit { call_sub("edit_$main::form->{type}"); } +sub continue { call_sub($main::form->{"nextsub"}); } +sub save_as_new { call_sub("save_as_new_$main::form->{type}"); } +sub add_account { + $main::lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; -sub add_account { - $lxdebug->enter_sub(); + $main::auth->assert('config'); - - $form->{title} = "Add"; + $form->{title} = "Add"; $form->{charttype} = "A"; AM->get_account(\%myconfig, \%$form); - - $form->{callback} = "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; + + $form->{callback} = "am.pl?action=list_account" unless $form->{callback}; &account_header; &form_footer; - - $lxdebug->leave_sub(); -} + $main::lxdebug->leave_sub(); +} sub edit_account { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('config'); - $form->{title} = "Edit"; AM->get_account(\%myconfig, \%$form); - + foreach my $item (split(/:/, $form->{link})) { $form->{$item} = "checked"; } @@ -82,684 +97,550 @@ sub edit_account { &account_header; &form_footer; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } - sub account_header { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); + + if ( $form->{action} eq 'edit_account') { + $form->{account_exists} = '1'; + } $form->{title} = $locale->text("$form->{title} Account"); - - $checked{$form->{charttype}} = "checked"; - $checked{"$form->{category}_"} = "checked"; - $checked{CT_tax} = ($form->{CT_tax}) ? "" : "checked"; - - $form->{description} =~ s/\"/"/g; - - if (@{ $form->{TAXKEY} }) { - $form->{selecttaxkey} = "|; } + foreach my $item (@{ $form->{NEWACCOUNT} }) { + if ($item->{id} == $form->{new_chart_id}) { + $form->{selectnewaccount} .= + qq||; + } elsif (!$form->{new_chart_valid}) { + $form->{selectnewaccount} .= + qq||; + } - + } } - - - $bwa = qq| - - |.$locale->text('BWA').qq| - - - |; - $form->{selectbilanz} = "\n|; + my %eur = ( + 1 => "Umsatzerlöse", + 2 => "sonstige Erlöse", + 3 => "Privatanteile", + 4 => "Zinserträge", + 5 => "Ausserordentliche Erträge", + 6 => "Vereinnahmte Umsatzst.", + 7 => "Umsatzsteuererstattungen", + 8 => "Wareneingänge", + 9 => "Löhne und Gehälter", + 10 => "Gesetzl. sozialer Aufw.", + 11 => "Mieten", + 12 => "Gas, Strom, Wasser", + 13 => "Instandhaltung", + 14 => "Steuern, Versich., Beiträge", + 15 => "Kfz-Steuern", + 16 => "Kfz-Versicherungen", + 17 => "Sonst. Fahrzeugkosten", + 18 => "Werbe- und Reisekosten", + 19 => "Instandhaltung u. Werkzeuge", + 20 => "Fachzeitschriften, Bücher", + 21 => "Miete für Einrichtungen", + 22 => "Rechts- und Beratungskosten", + 23 => "Bürobedarf, Porto, Telefon", + 24 => "Sonstige Aufwendungen", + 25 => "Abschreibungen auf Anlagever.", + 26 => "Abschreibungen auf GWG", + 27 => "Vorsteuer", + 28 => "Umsatzsteuerzahlungen", + 29 => "Zinsaufwand", + 30 => "Ausserordentlicher Aufwand", + 31 => "Betriebliche Steuern"); + foreach my $item (sort({ $a <=> $b } keys(%eur))) { + my $text = H(SL::Iconv::convert("ISO-8859-15", $main::dbcharset, $eur{$item})); + if ($item == $form->{pos_eur}) { + $select_eur .= qq|\n|; } else { - $form->{selectbilanz} .= "\n|; } - } - - - $bilanz = qq| - - |.$locale->text('Bilanz').qq| - - - |; -# this is for our parser only! -# type=submit $locale->text('Add Account') -# type=submit $locale->text('Edit Account') - - $form->header; - - print qq| - - -
{script}> - -{id}> - -{inventory_accno_id}> -{income_accno_id}> -{expense_accno_id}> -{fxgain_accno_id}> -{fxloss_accno_id}> + my $select_bwa = q|\n|; + + my %bwapos = ( + 1 => 'Umsatzerlöse', + 2 => 'Best.Verdg.FE/UE', + 3 => 'Aktiv.Eigenleistung', + 4 => 'Mat./Wareneinkauf', + 5 => 'So.betr.Erlöse', + 10 => 'Personalkosten', + 11 => 'Raumkosten', + 12 => 'Betriebl.Steuern', + 13 => 'Vers./Beiträge', + 14 => 'Kfz.Kosten o.St.', + 15 => 'Werbe-Reisek.', + 16 => 'Kosten Warenabgabe', + 17 => 'Abschreibungen', + 18 => 'Rep./instandhlt.', + 19 => 'Übrige Steuern', + 20 => 'Sonst.Kosten', + 30 => 'Zinsauwand', + 31 => 'Sonst.neutr.Aufw.', + 32 => 'Zinserträge', + 33 => 'Sonst.neutr.Ertrag', + 34 => 'Verr.kalk.Kosten', + 35 => 'Steuern Eink.u.Ertr.'); + foreach my $item (sort({ $a <=> $b } keys %bwapos)) { + my $text = H(SL::Iconv::convert("ISO-8859-15", $main::dbcharset, $bwapos{$item})); + if ($item == $form->{pos_bwa}) { + $select_bwa .= qq|\n|; + my %category = ( + 'A' => $locale->text('Asset'), + 'L' => $locale->text('Liability'), + 'Q' => $locale->text('Equity'), + 'I' => $locale->text('Revenue'), + 'E' => $locale->text('Expense'), + 'C' => $locale->text('Costs'), + ); + foreach my $item ( sort({ $a <=> $b } keys %category) ) { + if ($item eq $form->{category}) { + $select_category .= qq|
- - -|; + my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":""; - $lxdebug->leave_sub(); -} + $form->header(); - -sub save_account { - $lxdebug->enter_sub(); + my $parameters_ref = { + ChartTypeIsAccount => $ChartTypeIsAccount, + select_category => $select_category, + select_charttype => $select_charttype, + select_bwa => $select_bwa, + select_bilanz => $select_bilanz, + select_eur => $select_eur, + }; + # Ausgabe des Templates + print($form->parse_html_template('am/edit_accounts', $parameters_ref)); - $form->isblank("accno", $locale->text('Account Number missing!')); - $form->isblank("category", $locale->text('Account Type missing!')); - - $form->redirect($locale->text('Account saved!')) if (AM->save_account(\%myconfig, \%$form)); - $form->error($locale->text('Cannot save account!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub form_footer { + $main::lxdebug->enter_sub(); -sub list_account { - $lxdebug->enter_sub(); - - - CA->all_accounts(\%myconfig, \%$form); - - $form->{title} = $locale->text('Chart of Accounts'); - - # construct callback - $callback = "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&password=$form->{password}"; - - @column_index = qw(accno gifi_accno description debit credit link); - - $column_header{accno} = qq||.$locale->text('Account').qq||; - $column_header{gifi_accno} = qq||.$locale->text('GIFI').qq||; - $column_header{description} = qq||.$locale->text('Description').qq||; - $column_header{debit} = qq||.$locale->text('Debit').qq||; - $column_header{credit} = qq||.$locale->text('Credit').qq||; - $column_header{link} = qq||.$locale->text('Link').qq||; - + my $form = $main::form; + my $locale = $main::locale; - $form->header; - $colspan = $#column_index + 1; + $main::auth->assert('config'); print qq| - - - - - - - -|; + - map { print "$column_header{$_}\n" } @column_index; - - print qq| - +
|; + if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) { + print qq| + |; +} - # escape callback - $callback = $form->escape($callback); - - foreach $ca (@{ $form->{CA} }) { - - $ca->{debit} = " "; - $ca->{credit} = " "; - - if ($ca->{amount} > 0) { - $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2, " "); - } - if ($ca->{amount} < 0) { - $ca->{debit} = $form->format_amount(\%myconfig, -$ca->{amount}, 2, " "); - } - - $ca->{link} =~ s/:/
/og; - - if ($ca->{charttype} eq "H") { - print qq||; - - $column_data{accno} = qq||; - $column_data{gifi_accno} = qq||; - $column_data{description} = qq||; - $column_data{debit} = qq||; - $column_data{credit} = qq| |; - $column_data{link} = qq||; - - } else { - $i++; $i %= 2; - print qq| -|; - $column_data{accno} = qq||; - $column_data{gifi_accno} = qq||; - $column_data{description} = qq||; - $column_data{debit} = qq||; - $column_data{credit} = qq||; - $column_data{link} = qq||; - - } + if ($form->{id} && $form->{orphaned}) { + print qq||; + } - map { print "$column_data{$_}\n" } @column_index; - - print "\n"; + if ($form->{id} && $form->{type} eq "account") { + print qq| + |; } - + print qq| - -
$form->{title}
{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{accno}{script}?action=edit_gifi&accno=$ca->{gifi_accno}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{gifi_accno} $ca->{description}    
{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{accno}{script}?action=edit_gifi&accno=$ca->{gifi_accno}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{gifi_accno} $ca->{description} $ca->{debit}$ca->{credit}$ca->{link} 

+ |; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub save_account { + $main::lxdebug->enter_sub(); -sub delete_account { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); - $form->{title} = $locale->text('Delete Account'); + $form->isblank("accno", $locale->text('Account Number missing!')); + $form->isblank("description", $locale->text('Account Description missing!')); - foreach $id (qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)) { - if ($form->{id} == $form->{$id}) { - $form->error($locale->text('Cannot delete default account!')); - } + if ($form->{charttype} eq 'A'){ + $form->isblank("category", $locale->text('Account Type missing!')); } - $form->redirect($locale->text('Account deleted!')) if (AM->delete_account(\%myconfig, \%$form)); - $form->error($locale->text('Cannot delete account!')); + $form->redirect($locale->text('Account saved!')) + if (AM->save_account(\%myconfig, \%$form)); + $form->error($locale->text('Cannot save account!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub save_as_new_account { + $main::lxdebug->enter_sub(); -sub list_gifi { - $lxdebug->enter_sub(); - - - @{ $form->{fields} } = (accno, description); - $form->{table} = "gifi"; - $form->{sortorder} = "accno"; - - AM->gifi_accounts(\%myconfig, \%$form); - - $form->{title} = $locale->text('GIFI'); - - # construct callback - $callback = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&password=$form->{password}"; - - @column_index = qw(accno description); - - $column_header{accno} = qq||.$locale->text('GIFI').qq||; - $column_header{description} = qq||.$locale->text('Description').qq||; - - - $form->header; - $colspan = $#column_index + 1; + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - print qq| - + $main::auth->assert('config'); - - - - - - -|; + $form->isblank("accno", $locale->text('Account Number missing!')); + $form->isblank("description", $locale->text('Account Description missing!')); - map { print "$column_header{$_}\n" } @column_index; - - print qq| - -|; + if ($form->{charttype} eq 'A'){ + $form->isblank("category", $locale->text('Account Type missing!')); + } - # escape callback - $callback = $form->escape($callback); - - foreach $ca (@{ $form->{ALL} }) { - - $i++; $i %= 2; - - print qq| -|; - - $column_data{accno} = qq||; - $column_data{description} = qq||; - - map { print "$column_data{$_}\n" } @column_index; - - print "\n"; + for my $taxkey (0 .. 9) { + if ($form->{"taxkey_id_$taxkey"}) { + $form->{"taxkey_id_$taxkey"} = "NEW"; + } } - - print qq| - - - -
$form->{title}
{script}?action=edit_gifi&coa=1&accno=$ca->{accno}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{accno}$ca->{description} 

- - -|; + $form->{id} = 0; + if ($form->{"original_accno"} && + ($form->{"accno"} eq $form->{"original_accno"})) { + $form->error($locale->text('Account Number already used!')); + } + $form->redirect($locale->text('Account saved!')) + if (AM->save_account(\%myconfig, \%$form)); + $form->error($locale->text('Cannot save account!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub list_account { + $main::lxdebug->enter_sub(); -sub add_gifi { - $lxdebug->enter_sub(); - - $form->{title} = "Add"; - - # construct callback - $form->{callback} = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&password=$form->{password}"; + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - $form->{coa} = 1; - - &gifi_header; - &gifi_footer; - - $lxdebug->leave_sub(); -} + $main::auth->assert('config'); + $form->{callback} = build_std_url('action=list_account'); + my $link_edit_account = build_std_url('action=edit_account', 'callback'); -sub edit_gifi { - $lxdebug->enter_sub(); + CA->all_accounts(\%myconfig, \%$form); - - $form->{title} = "Edit"; + foreach my $ca (@{ $form->{CA} }) { - AM->get_gifi(\%myconfig, \%$form); - - &gifi_header; - &gifi_footer; - - $lxdebug->leave_sub(); -} + $ca->{debit} = ""; + $ca->{credit} = ""; + if ($ca->{amount} > 0) { + $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2); + } + if ($ca->{amount} < 0) { + $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2); + } + $ca->{heading} = ( $ca->{charttype} eq 'H' ) ? 1:''; + $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id}); + } -sub gifi_header { - $lxdebug->enter_sub(); + # Ajax + my $pjx = new CGI::Ajax('list_account_details' => build_std_url('action=list_account_details')); + # Eneable AJAX debuging + #$pjx->DEBUG(1); + #$pjx->JSDEBUG(1); - $form->{title} = $locale->text("$form->{title} GIFI"); - -# $locale->text('Add GIFI') -# $locale->text('Edit GIFI') + push(@ { $form->{AJAX} }, $pjx); - $form->{description} =~ s/\"/"/g; + $form->{stylesheets} = "list_accounts.css"; + $form->{title} = $locale->text('Chart of Accounts'); $form->header; - print qq| - -
{script}> + my $parameters_ref = { + # hidden_variables => $_hidden_variables_ref, + }; -{accno}> - + # Ausgabe des Templates + print($form->parse_html_template('am/list_accounts', $parameters_ref)); - - - - - - - - - - - -
$form->{title}
- - - - - - - - - -
|.$locale->text('GIFI').qq|{accno}>
|.$locale->text('Description').qq|
-

-|; + $main::lxdebug->leave_sub(); - $lxdebug->leave_sub(); } -sub gifi_footer { - $lxdebug->enter_sub(); +sub list_account_details { +# Ajax Funktion aus list_account_details + $main::lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - print qq| + $main::auth->assert('config'); - + my $chart_id = $form->{args}; -{path}> -{login}> -{password}> + CA->all_accounts(\%myconfig, \%$form, $chart_id); -
|; + foreach my $ca (@{ $form->{CA} }) { - if ($form->{coa}) { - print qq| - -|; + $ca->{debit} = " "; + $ca->{credit} = " "; - if ($form->{accno} && $form->{orphaned}) { - print qq||; + if ($ca->{amount} > 0) { + $ca->{credit} = + $form->format_amount(\%myconfig, $ca->{amount}, 2, " "); + } + if ($ca->{amount} < 0) { + $ca->{debit} = + $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " "); } - } - - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print qq| -
- - - -|; - $lxdebug->leave_sub(); -} + my @links = split( q{:}, $ca->{link}); + + $ca->{link} = q{}; + + foreach my $link (@links){ + $link = ( $link eq 'AR') ? $locale->text('Account Link AR') + : ( $link eq 'AP') ? $locale->text('Account Link AP') + : ( $link eq 'IC') ? $locale->text('Account Link IC') + : ( $link eq 'AR_amount' ) ? $locale->text('Account Link AR_amount') + : ( $link eq 'AR_paid' ) ? $locale->text('Account Link AR_paid') + : ( $link eq 'AR_tax' ) ? $locale->text('Account Link AR_tax') + : ( $link eq 'AP_amount' ) ? $locale->text('Account Link AP_amount') + : ( $link eq 'AP_paid' ) ? $locale->text('Account Link AP_paid') + : ( $link eq 'AP_tax' ) ? $locale->text('Account Link AP_tax') + : ( $link eq 'IC_sale' ) ? $locale->text('Account Link IC_sale') + : ( $link eq 'IC_cogs' ) ? $locale->text('Account Link IC_cogs') + : ( $link eq 'IC_taxpart' ) ? $locale->text('Account Link IC_taxpart') + : ( $link eq 'IC_income' ) ? $locale->text('Account Link IC_income') + : ( $link eq 'IC_expense' ) ? $locale->text('Account Link IC_expense') + : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice') +# : ( $link eq 'CT_tax' ) ? $locale->text('Account Link CT_tax') + : $locale->text('Unknown Link') . ': ' . $link; + $ca->{link} .= ($link ne '') ? "[$link] ":''; + } + $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A') + : ($ca->{category} eq 'E') ? $locale->text('Account Category E') + : ($ca->{category} eq 'L') ? $locale->text('Account Category L') + : ($ca->{category} eq 'I') ? $locale->text('Account Category I') + : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q') + : ($ca->{category} eq 'C') ? $locale->text('Account Category C') + : ($ca->{category} eq 'G') ? $locale->text('Account Category G') + : $locale->text('Unknown Category') . ': ' . $ca->{category}; + } -sub save_gifi { - $lxdebug->enter_sub(); + $form->{title} = $locale->text('Chart of Accounts'); + $form->header(); + print $form->parse_html_template('am/list_account_details'); - $form->isblank("accno", $locale->text('GIFI missing!')); - AM->save_gifi(\%myconfig, \%$form); - $form->redirect($locale->text('GIFI saved!')); + $main::lxdebug->leave_sub(); - $lxdebug->leave_sub(); } +sub delete_account { + $main::lxdebug->enter_sub(); -sub copy_to_coa { - $lxdebug->enter_sub(); - - - $form->isblank("accno", $locale->text('GIFI missing!')); - - AM->save_gifi(\%myconfig, \%$form); - - delete $form->{id}; - $form->{gifi_accno} = $form->{accno}; - $form->{title} = "Add"; - $form->{charttype} = "A"; - - &account_header; - &form_footer; - - $lxdebug->leave_sub(); -} + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); -sub delete_gifi { - $lxdebug->enter_sub(); + $form->{title} = $locale->text('Delete Account'); + foreach my $id ( + qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id) + ) { + if ($form->{id} == $form->{$id}) { + $form->error($locale->text('Cannot delete default account!')); + } + } - AM->delete_gifi(\%myconfig, \%$form); - $form->redirect($locale->text('GIFI deleted!')); + $form->redirect($locale->text('Account deleted!')) + if (AM->delete_account(\%myconfig, \%$form)); + $form->error($locale->text('Cannot delete account!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } - sub add_department { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + my $form = $main::form; + + $main::auth->assert('config'); $form->{title} = "Add"; - $form->{role} = "P"; - - $form->{callback} = "$form->{script}?action=add_department&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; + $form->{role} = "P"; + + $form->{callback} = "am.pl?action=add_department" unless $form->{callback}; &department_header; &form_footer; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } - sub edit_department { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + $main::auth->assert('config'); $form->{title} = "Edit"; @@ -768,27 +649,40 @@ sub edit_department { &department_header; &form_footer; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } - sub list_department { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); AM->departments(\%myconfig, \%$form); - $form->{callback} = "$form->{script}?action=list_department&path=$form->{path}&login=$form->{login}&password=$form->{password}"; + $form->{callback} = "am.pl?action=list_department"; - $callback = $form->escape($form->{callback}); - - $form->{title} = $locale->text('Departments'); + my $callback = $form->escape($form->{callback}); - @column_index = qw(description cost profit); + $form->{title} = $locale->text('Departments'); - $column_header{description} = qq||.$locale->text('Description').qq||; - $column_header{cost} = qq||.$locale->text('Cost Center').qq||; - $column_header{profit} = qq||.$locale->text('Profit Center').qq||; + my @column_index = qw(description cost profit); + my %column_header; + $column_header{description} = + qq|| + . $locale->text('Description') + . qq||; + $column_header{cost} = + qq|| + . $locale->text('Cost Center') + . qq||; + $column_header{profit} = + qq|| + . $locale->text('Profit Center') + . qq||; $form->header; @@ -812,25 +706,28 @@ sub list_department { |; - foreach $ref (@{ $form->{ALL} }) { - - $i++; $i %= 2; - + my ($i, %column_data); + foreach my $ref (@{ $form->{ALL} }) { + + $i++; + $i %= 2; + print qq| |; - $costcenter = ($ref->{role} eq "C") ? "X" : ""; - $profitcenter = ($ref->{role} eq "P") ? "X" : ""; - - $column_data{description} = qq|{script}?action=edit_department&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}|; - $column_data{cost} = qq|$costcenter|; - $column_data{profit} = qq|$profitcenter|; + my $costcenter = ($ref->{role} eq "C") ? "X" : ""; + my $profitcenter = ($ref->{role} eq "P") ? "X" : ""; - map { print "$column_data{$_}\n" } @column_index; + $column_data{description} = + qq|$ref->{description}|; + $column_data{cost} = qq|$costcenter|; + $column_data{profit} = qq|$profitcenter|; - print qq| - + map { print "$column_data{$_}\n" } @column_index; + + print qq| + |; } @@ -844,60 +741,57 @@ sub list_department {
-
{script}> + -{path}> -{login}> -{password}> + -|; +
- if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } + + +|; - print qq| - - - - -|; - - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } - sub department_header { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; + $main::auth->assert('config'); $form->{title} = $locale->text("$form->{title} Department"); -# $locale->text('Add Department') -# $locale->text('Edit Department') + # $locale->text('Add Department') + # $locale->text('Edit Department') $form->{description} =~ s/\"/"/g; + my ($rows, $description); if (($rows = $form->numtextrows($form->{description}, 60)) > 1) { - $description = qq||; + $description = + qq||; } else { - $description = qq||; + $description = + qq||; } - $costcenter = "checked" if $form->{role} eq "C"; - $profitcenter = "checked" if $form->{role} eq "P"; - + my $costcenter = "checked" if $form->{role} eq "C"; + my $profitcenter = "checked" if $form->{role} eq "P"; + $form->header; print qq| -
{script}> + {id}> @@ -908,13 +802,15 @@ sub department_header { - |.$locale->text('Description').qq| + | . $locale->text('Description') . qq| $description - |.$locale->text('Cost Center').qq| - |.$locale->text('Profit Center').qq| + | + . $locale->text('Cost Center') . qq| + | + . $locale->text('Profit Center') . qq|
@@ -922,82 +818,100 @@ sub department_header { |; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } - sub save_department { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); $form->isblank("description", $locale->text('Description missing!')); AM->save_department(\%myconfig, \%$form); $form->redirect($locale->text('Department saved!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } - sub delete_department { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); AM->delete_department(\%myconfig, \%$form); $form->redirect($locale->text('Department deleted!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub add_lead { + $main::lxdebug->enter_sub(); -sub add_business { - $lxdebug->enter_sub(); + my $form = $main::form; + $main::auth->assert('config'); $form->{title} = "Add"; - - $form->{callback} = "$form->{script}?action=add_business&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; - &business_header; + $form->{callback} = "am.pl?action=add_lead" unless $form->{callback}; + + &lead_header; &form_footer; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub edit_lead { + $main::lxdebug->enter_sub(); -sub edit_business { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + $main::auth->assert('config'); $form->{title} = "Edit"; - AM->get_business(\%myconfig, \%$form); + AM->get_lead(\%myconfig, \%$form); - &business_header; + &lead_header; $form->{orphaned} = 1; &form_footer; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub list_lead { + $main::lxdebug->enter_sub(); -sub list_business { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); - AM->business(\%myconfig, \%$form); + AM->lead(\%myconfig, \%$form); - $form->{callback} = "$form->{script}?action=list_business&path=$form->{path}&login=$form->{login}&password=$form->{password}"; + $form->{callback} = "am.pl?action=list_lead"; - $callback = $form->escape($form->{callback}); - - $form->{title} = $locale->text('Type of Business'); + my $callback = $form->escape($form->{callback}); - @column_index = qw(description discount customernumberinit); + $form->{title} = $locale->text('Lead'); - $column_header{description} = qq||.$locale->text('Description').qq||; - $column_header{discount} = qq||.$locale->text('Discount').qq| %|; - $column_header{customernumberinit} = qq||.$locale->text('Customernumberinit').qq||; + my @column_index = qw(description cost profit); + my %column_header; + $column_header{description} = + qq|| + . $locale->text('Description') + . qq||; $form->header; @@ -1009,99 +923,88 @@ sub list_business { $form->{title} - - - - + |; map { print "$column_header{$_}\n" } @column_index; print qq| - + |; - foreach $ref (@{ $form->{ALL} }) { - - $i++; $i %= 2; - + my ($i, %column_data); + foreach my $ref (@{ $form->{ALL} }) { + + $i++; + $i %= 2; + print qq| - + |; - $discount = $form->format_amount(\%myconfig, $ref->{discount} * 100, 1, " "); - $description = ($ref->{salesman}) ? "$ref->{description}" : "$ref->{description}"; - $column_data{description} = qq||; - $column_data{discount} = qq||; - $column_data{customernumberinit} = qq||; - - map { print "$column_data{$_}\n" } @column_index; +# $lead = $ref->{lead}; + + $column_data{description} = qq||; + + map { print "$column_data{$_}\n" } @column_index; - print qq| - + print qq| + |; } print qq| -
{script}?action=edit_business&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$description$discount$ref->{customernumberinit}$ref->{lead}
- -

-{script}> + - - -{path}> -{login}> -{password}> + -|; + - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print qq| -
- + - + |; - - $lxdebug->leave_sub(); + + $main::lxdebug->leave_sub(); } +sub lead_header { + $main::lxdebug->enter_sub(); -sub business_header { - $lxdebug->enter_sub(); + my $form = $main::form; + my $locale = $main::locale; + $main::auth->assert('config'); - $form->{title} = $locale->text("$form->{title} Business"); - $form->{salesman} = "checked" if $form->{salesman}; -# $locale->text('Add Business') -# $locale->text('Edit Business') + $form->{title} = $locale->text("$form->{title} Lead"); + + # $locale->text('Add Lead') + # $locale->text('Edit Lead') $form->{description} =~ s/\"/"/g; - $form->{discount} = $form->format_amount(\%myconfig, $form->{discount} * 100); + + my $description = + qq||; $form->header; print qq| -
{script}> + {id}> - + @@ -1109,102 +1012,119 @@ sub business_header { - - - - - - - - - - + + - - - - - +
|.$locale->text('Type of Business').qq|
|.$locale->text('Discount').qq| %{discount}>
|.$locale->text('Customernumberinit').qq|{customernumberinit}>| . $locale->text('Description') . qq|$description
|.$locale->text('Salesman').qq|{salesman}>


|; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub save_lead { + $main::lxdebug->enter_sub(); -sub save_business { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); $form->isblank("description", $locale->text('Description missing!')); - AM->save_business(\%myconfig, \%$form); - $form->redirect($locale->text('Business saved!')); + AM->save_lead(\%myconfig, \%$form); + $form->redirect($locale->text('lead saved!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub delete_lead { + $main::lxdebug->enter_sub(); -sub delete_business { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); - AM->delete_business(\%myconfig, \%$form); - $form->redirect($locale->text('Business deleted!')); + AM->delete_lead(\%myconfig, \%$form); + $form->redirect($locale->text('lead deleted!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub add_business { + $main::lxdebug->enter_sub(); + my $form = $main::form; -sub add_sic { - $lxdebug->enter_sub(); - + $main::auth->assert('config'); $form->{title} = "Add"; - - $form->{callback} = "$form->{script}?action=add_sic&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; - &sic_header; + $form->{callback} = "am.pl?action=add_business" unless $form->{callback}; + + &business_header; &form_footer; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub edit_business { + $main::lxdebug->enter_sub(); -sub edit_sic { - $lxdebug->enter_sub(); - + my $form = $main::form; + my %myconfig = %main::myconfig; $form->{title} = "Edit"; - AM->get_sic(\%myconfig, \%$form); + AM->get_business(\%myconfig, \%$form); - &sic_header; + &business_header; $form->{orphaned} = 1; &form_footer; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub list_business { + $main::lxdebug->enter_sub(); -sub list_sic { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); - AM->sic(\%myconfig, \%$form); + AM->business(\%myconfig, \%$form); - $form->{callback} = "$form->{script}?action=list_sic&path=$form->{path}&login=$form->{login}&password=$form->{password}"; + $form->{callback} = "am.pl?action=list_business"; - $callback = $form->escape($form->{callback}); - - $form->{title} = $locale->text('Standard Industrial Codes'); + my $callback = $form->escape($form->{callback}); - @column_index = qw(code description); + $form->{title} = $locale->text('Type of Business'); - $column_header{code} = qq||.$locale->text('Code').qq||; - $column_header{description} = qq||.$locale->text('Description').qq||; + my @column_index = qw(description discount customernumberinit); + push @column_index, 'salesman' if $::vertreter; + my %column_header; + $column_header{description} = + qq|| + . $locale->text('Description') + . qq||; + $column_header{discount} = + qq|| + . $locale->text('Discount') + . qq| %|; + $column_header{customernumberinit} = + qq|| + . $locale->text('Customernumberinit') + . qq||; + $column_header{salesman} = + qq|| + . $locale->text('Representative') + . qq||; $form->header; @@ -1228,31 +1148,28 @@ sub list_sic { |; - foreach $ref (@{ $form->{ALL} }) { - - $i++; $i %= 2; - - if ($ref->{sictype} eq 'H') { - print qq| - -|; - $column_data{code} = qq|
{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{code}|; - $column_data{description} = qq|$ref->{description}|; - - } else { - print qq| + my ($i, %column_data); + foreach my $ref (@{ $form->{ALL} }) { + + $i++; + $i %= 2; + + print qq| |; - $column_data{code} = qq|{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{code}|; - $column_data{description} = qq|$ref->{description}|; + my $discount = $form->format_amount(\%myconfig, $ref->{discount} * 100); + my $description = $ref->{description}; + $column_data{description} = qq|$description|; + $column_data{discount} = qq|$discount|; + $column_data{customernumberinit} = + qq|$ref->{customernumberinit}|; + $column_data{salesman} = '' . ($ref->{salesman} ? $::locale->text('Yes') : $::locale->text('No')) . ''; - } - - map { print "$column_data{$_}\n" } @column_index; + map { print "$column_data{$_}\n" } @column_index; - print qq| - + print qq| + |; } @@ -1266,57 +1183,63 @@ sub list_sic {
-{script}> + - - -{path}> -{login}> -{password}> - -|; + - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } + - print qq| - + - + |; - - $lxdebug->leave_sub(); + + $main::lxdebug->leave_sub(); } +sub business_header { + $main::lxdebug->enter_sub(); -sub sic_header { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); - $form->{title} = $locale->text("$form->{title} SIC"); + $form->{title} = $locale->text("$form->{title} Business"); -# $locale->text('Add SIC') -# $locale->text('Edit SIC') + # $locale->text('Add Business') + # $locale->text('Edit Business') - $form->{code} =~ s/\"/"/g; $form->{description} =~ s/\"/"/g; + $form->{discount} = + $form->format_amount(\%myconfig, $form->{discount} * 100); - $checked = ($form->{sictype} eq 'H') ? "checked" : ""; + my $salesman_code; + if ($::vertreter) { + $salesman_code = qq| + + | . $locale->text('Representative') . qq| + | . $::cgi->checkbox(-name => "salesman", -value => 1, -label => '', 'checked' => $form->{salesman} ? 1 : 0) . qq| + +|; + } else { + $salesman_code = $::cgi->hidden(-name => 'salesman', -value => $form->{salesman} ? 1 : 0); + } $form->header; print qq| -
{script}> + - -{code}> +{id}> + @@ -1324,615 +1247,868 @@ sub sic_header { - - - + + - - + + + - - + + - +$salesman_code +
|.$locale->text('Code').qq|{code}>
| . $locale->text('Type of Business') . qq|
|.$locale->text('Heading').qq|
| . $locale->text('Discount') . qq| %{discount}>
|.$locale->text('Description').qq|| . $locale->text('Customernumberinit') . qq|{customernumberinit}>


|; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub save_business { + $main::lxdebug->enter_sub(); -sub save_sic { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); - $form->isblank("code", $locale->text('Code missing!')); $form->isblank("description", $locale->text('Description missing!')); - AM->save_sic(\%myconfig, \%$form); - $form->redirect($locale->text('SIC saved!')); + $form->{discount} = $form->parse_amount(\%myconfig, $form->{discount}) / 100; + AM->save_business(\%myconfig, \%$form); + $form->redirect($locale->text('Business saved!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub delete_business { + $main::lxdebug->enter_sub(); -sub delete_sic { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); - AM->delete_sic(\%myconfig, \%$form); - $form->redirect($locale->text('SIC deleted!')); + AM->delete_business(\%myconfig, \%$form); + $form->redirect($locale->text('Business deleted!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub add_language { + $main::lxdebug->enter_sub(); + my $form = $main::form; -sub display_stylesheet { - $lxdebug->enter_sub(); - - - $form->{file} = "css/$myconfig{stylesheet}"; - &display_form; - - $lxdebug->leave_sub(); -} - + $main::auth->assert('config'); -sub display_form { - $lxdebug->enter_sub(); + $form->{title} = "Add"; + $form->{callback} = "am.pl?action=add_language" unless $form->{callback}; - $form->{file} =~ s/^(.:)*?\/|\.\.\///g; - $form->{file} =~ s/^\/*//g; - $form->{file} =~ s/$userspath//; + &language_header; + &form_footer; - $form->error("$!: $form->{file}") unless -f $form->{file}; + $main::lxdebug->leave_sub(); +} - AM->load_template(\%$form); +sub edit_language { + $main::lxdebug->enter_sub(); - $form->{title} = $form->{file}; + my $form = $main::form; + my %myconfig = %main::myconfig; - # if it is anything but html - if ($form->{file} !~ /\.html$/) { - $form->{body} = "
\n$form->{body}\n
"; - } - - $form->header; + $main::auth->assert('config'); - print qq| - + $form->{title} = "Edit"; -$form->{body} + AM->get_language(\%myconfig, \%$form); -{script}> + &language_header; -{file}> - + $form->{orphaned} = 1; + &form_footer; -{path}> -{login}> -{password}> + $main::lxdebug->leave_sub(); +} -|; +sub list_language { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + AM->language(\%myconfig, \%$form); + + $form->{callback} = "am.pl?action=list_language"; + + my $callback = $form->escape($form->{callback}); + + $form->{title} = $locale->text('Languages'); + + my @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates); + my %column_header; + $column_header{description} = + qq|| + . $locale->text('Description') + . qq||; + $column_header{template_code} = + qq|| + . $locale->text('Template Code') + . qq||; + $column_header{article_code} = + qq|| + . $locale->text('Article Code') + . qq||; + $column_header{output_numberformat} = + qq|| + . $locale->text('Number Format') + . qq||; + $column_header{output_dateformat} = + qq|| + . $locale->text('Date Format') + . qq||; + $column_header{output_longdates} = + qq|| + . $locale->text('Long Dates') + . qq||; - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } + $form->header; print qq| -
+ - - + + + + + + + + + + + +
$form->{title}
+ + |; - $lxdebug->leave_sub(); -} - - -sub edit_template { - $lxdebug->enter_sub(); - - - AM->load_template(\%$form); - - $form->{title} = $locale->text('Edit Template'); - # convert   to &nbsp; - $form->{body} =~ s/ /&nbsp;/gi; - + map { print "$column_header{$_}\n" } @column_index; - $form->header; - print qq| - + +|; -{script}> + my ($i, %column_data); + foreach my $ref (@{ $form->{ALL} }) { -{file}> - + $i++; + $i %= 2; -{path}> -{login}> -{password}> + print qq| + +|; - - + $column_data{description} = + qq||; + $column_data{template_code} = qq||; + $column_data{article_code} = + qq||; + $column_data{output_numberformat} = + ""; + $column_data{output_dateformat} = + ""; + $column_data{output_longdates} = + ""; -
-|; + map { print "$column_data{$_}\n" } @column_index; - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; + print qq| + +|; } - print q| - + print qq| +
$ref->{description}$ref->{template_code}$ref->{article_code}" . + ($ref->{output_numberformat} ? $ref->{output_numberformat} : + $locale->text("use program settings")) . + "" . + ($ref->{output_dateformat} ? $ref->{output_dateformat} : + $locale->text("use program settings")) . + "" . + ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) . + "
+

+
+
- - -|; + - $lxdebug->leave_sub(); -} + + -sub save_template { - $lxdebug->enter_sub(); +
+ + +|; - AM->save_template(\%$form); - $form->redirect($locale->text('Template saved!')); - - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub language_header { + $main::lxdebug->enter_sub(); -sub config { - $lxdebug->enter_sub(); + my $form = $main::form; + my $locale = $main::locale; + $main::auth->assert('config'); - # get defaults for account numbers and last numbers - AM->defaultaccounts(\%myconfig, \%$form); + $form->{title} = $locale->text("$form->{title} Language"); - foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) { - $dateformat .= ($item eq $myconfig{dateformat}) ? "|; + foreach my $item (('1,000.00', '1000.00', '1.000,00', '1000,00')) { + $numberformat .= + ($item eq $form->{output_numberformat}) + ? ""; } - $countrycodes = "|; + foreach my $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) { + $dateformat .= + ($item eq $form->{output_dateformat}) + ? ""; } - opendir CSS, "css/."; - @all = grep /.*\.css$/, readdir CSS; - closedir CSS; - - foreach $item (@all) { - if ($item eq $myconfig{stylesheet}) { - $selectstylesheet .= qq|" } + sort({ $a->{"accno"} cmp $b->{"accno"} } + values(%{$acc_type_map{$type}})))); + } + + if ($form->{id}) { + $form->{selectIC} =~ s/selected//g; + $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/ value=$form->{inventory_accno_id} selected/; + $form->{selectIC_income} =~ s/selected//g; + $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/ value=$form->{income_accno_id_0} selected/; + $form->{selectIC_expense} =~ s/selected//g; + $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/ value=$form->{expense_accno_id_0} selected/; + } + + my $linkaccounts; + if (!$main::eur) { + $linkaccounts = qq| + + | . $locale->text('Inventory') . qq| + + + |; + } else { + $linkaccounts = qq| + {inventory_accno_id}>|; + } + + + $linkaccounts .= qq| + + | . $locale->text('National Revenues') . qq| + + + + | . $locale->text('National Expenses') . qq| + + |; + if ($form->{id}) { + $form->{selectIC_income} =~ s/selected//g; + $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/ value=$form->{income_accno_id_1} selected/; + $form->{selectIC_expense} =~ s/selected//g; + $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/ value=$form->{expense_accno_id_1} selected/; + } + $linkaccounts .= qq| + | . $locale->text('Revenues EU with UStId') . qq| + + + + | . $locale->text('Expenses EU with UStId') . qq| + + |; + + if ($form->{id}) { + $form->{selectIC_income} =~ s/selected//g; + $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/ value=$form->{income_accno_id_2} selected/; + $form->{selectIC_expense} =~ s/selected//g; + $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/ value=$form->{expense_accno_id_2} selected/; + } + + $linkaccounts .= qq| + | . $locale->text('Revenues EU without UStId') . qq| + + + + | . $locale->text('Expenses EU without UStId') . qq| + + |; + + if ($form->{id}) { + $form->{selectIC_income} =~ s/selected//g; + $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/ value=$form->{income_accno_id_3} selected/; + $form->{selectIC_expense} =~ s/selected//g; + $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/ value=$form->{expense_accno_id_3} selected/; + } + + $linkaccounts .= qq| + | . $locale->text('Foreign Revenues') . qq| + + + + | . $locale->text('Foreign Expenses') . qq| + + +|; + + + $form->header; + + print qq| + + +
+ +{id}> + + + + + + + + + + + + $linkaccounts + + +
$form->{title}
| . $locale->text('Buchungsgruppe') . qq|

+|; + + $main::lxdebug->leave_sub(); } +sub save_buchungsgruppe { + $main::lxdebug->enter_sub(); -sub add_warehouse { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); - $form->{title} = "Add"; - - $form->{callback} = "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; + $form->isblank("description", $locale->text('Description missing!')); - &warehouse_header; - &form_footer; + AM->save_buchungsgruppe(\%myconfig, \%$form); + $form->redirect($locale->text('Accounting Group saved!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub delete_buchungsgruppe { + $main::lxdebug->enter_sub(); -sub edit_warehouse { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); - $form->{title} = "Edit"; + AM->delete_buchungsgruppe(\%myconfig, \%$form); + $form->redirect($locale->text('Accounting Group deleted!')); + + $main::lxdebug->leave_sub(); +} + +sub swap_buchungsgruppen { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('config'); - AM->get_warehouse(\%myconfig, \%$form); + AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen"); + list_buchungsgruppe(); - &warehouse_header; + $main::lxdebug->leave_sub(); +} + +sub add_payment { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('config'); + + $form->{title} = "Add"; + + $form->{callback} = "am.pl?action=add_payment" unless $form->{callback}; + + $form->{terms_netto} = 0; + $form->{terms_skonto} = 0; + $form->{percent_skonto} = 0; + my @languages = AM->language(\%myconfig, $form, 1); + map({ $_->{"language"} = $_->{"description"}; + $_->{"language_id"} = $_->{"id"}; } @languages); + $form->{"TRANSLATION"} = \@languages; + &payment_header; &form_footer; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub edit_payment { + $main::lxdebug->enter_sub(); -sub list_warehouse { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + $main::auth->assert('config'); - AM->warehouses(\%myconfig, \%$form); + $form->{title} = "Edit"; + + AM->get_payment(\%myconfig, $form); + $form->{percent_skonto} = + $form->format_amount(\%myconfig, $form->{percent_skonto} * 100); - $form->{callback} = "$form->{script}?action=list_warehouse&path=$form->{path}&login=$form->{login}&password=$form->{password}"; + &payment_header; - $callback = $form->escape($form->{callback}); - - $form->{title} = $locale->text('Warehouses'); + $form->{orphaned} = 1; + &form_footer; - @column_index = qw(description); + $main::lxdebug->leave_sub(); +} - $column_header{description} = qq||.$locale->text('Description').qq||; +sub list_payment { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + AM->payment(\%myconfig, \%$form); + + $form->{callback} = build_std_url("action=list_payment"); + + my $callback = $form->escape($form->{callback}); + + $form->{title} = $locale->text('Payment Terms'); + + my @column_index = qw(up down description description_long terms_netto + terms_skonto percent_skonto); + my %column_header; + $column_header{up} = + qq|| + . qq|| . $locale->text(| + . qq||; + $column_header{down} = + qq|| + . qq|| . $locale->text(| + . qq||; + $column_header{description} = + qq|| + . $locale->text('Description') + . qq||; + $column_header{description_long} = + qq|| + . $locale->text('Long Description') + . qq||; + $column_header{terms_netto} = + qq|| + . $locale->text('Netto Terms') + . qq||; + $column_header{terms_skonto} = + qq|| + . $locale->text('Skonto Terms') + . qq||; + $column_header{percent_skonto} = + qq|| + . $locale->text('Skonto') + . qq| %|; $form->header; @@ -1956,21 +2132,61 @@ sub list_warehouse { |; - foreach $ref (@{ $form->{ALL} }) { - - $i++; $i %= 2; - + my $swap_link = build_std_url("action=swap_payment_terms"); + + my $row = 0; + my ($i, %column_data); + foreach my $ref (@{ $form->{ALL} }) { + + $i++; + $i %= 2; + print qq| |; - $column_data{description} = qq|
{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}|; + if ($row) { + my $pref = $form->{ALL}->[$row - 1]; + $column_data{up} = + qq|| . + qq|| . + qq|| . $locale->text(| . + qq||; + } else { + $column_data{up} = qq| |; + } + + if ($row == (scalar(@{ $form->{ALL} }) - 1)) { + $column_data{down} = qq| |; + } else { + my $nref = $form->{ALL}->[$row + 1]; + $column_data{down} = + qq|| . + qq|| . + qq|| . $locale->text(| . + qq||; + } - map { print "$column_data{$_}\n" } @column_index; + $column_data{description} = + qq|{id}", "callback=$callback") . + qq|">| . H($ref->{description}) . qq||; + $column_data{description_long} = + qq|| . H($ref->{description_long}) . qq||; + $column_data{terms_netto} = + qq|$ref->{terms_netto}|; + $column_data{terms_skonto} = + qq|$ref->{terms_skonto}|; + $column_data{percent_skonto} = + qq|| . + $form->format_amount(\%myconfig, $ref->{percent_skonto} * 100) . + qq|%|; + map { print "$column_data{$_}\n" } @column_index; - print qq| - + print qq| + |; + $row++; } print qq| @@ -1983,61 +2199,50 @@ sub list_warehouse {
-{script}> + - - -{path}> -{login}> -{password}> + -|; + - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print qq|
- + - + |; - - $lxdebug->leave_sub(); + + $main::lxdebug->leave_sub(); } +sub payment_header { + $main::lxdebug->enter_sub(); -sub warehouse_header { - $lxdebug->enter_sub(); + my $form = $main::form; + my $locale = $main::locale; + $main::auth->assert('config'); - $form->{title} = $locale->text("$form->{title} Warehouse"); + $form->{title} = $locale->text("$form->{title} Payment Terms"); -# $locale->text('Add Warehouse') -# $locale->text('Edit Warehouse') + # $locale->text('Add Payment Terms') + # $locale->text('Edit Payment Terms') $form->{description} =~ s/\"/"/g; - if (($rows = $form->numtextrows($form->{description}, 60)) > 1) { - $description = qq||; - } else { - $description = qq||; - } - + $form->header; print qq| -
{script}> + {id}> - + @@ -2045,50 +2250,1099 @@ sub warehouse_header { - - + + + + + + +|; + + foreach my $language (@{ $form->{"TRANSLATION"} }) { + print qq| - + + -
|.$locale->text('Description').qq|$description| . $locale->text('Description') . qq|
| . $locale->text('Long Description') . qq|

| . + sprintf($locale->text('Translation (%s)'), + $language->{"language"}) + . qq|
|; + } + + print qq| + + | . $locale->text('Netto Terms') . qq| + + + + | . $locale->text('Skonto Terms') . qq| + + + + | . $locale->text('Skonto') . qq| % + + +
+ + - $lxdebug->leave_sub(); +

| . $locale->text("You can use the following strings in the long " . + "description and all translations. They will be " . + "replaced by their actual values by Lx-Office " . + "before they're output.") +. qq|

+ +|; + + $main::lxdebug->leave_sub(); } +sub save_payment { + $main::lxdebug->enter_sub(); -sub save_warehouse { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('config'); $form->isblank("description", $locale->text('Description missing!')); - AM->save_warehouse(\%myconfig, \%$form); - $form->redirect($locale->text('Warehouse saved!')); + $form->{"percent_skonto"} = + $form->parse_amount(\%myconfig, $form->{percent_skonto}) / 100; + AM->save_payment(\%myconfig, \%$form); + $form->redirect($locale->text('Payment Terms saved!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub delete_payment { + $main::lxdebug->enter_sub(); -sub delete_warehouse { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + AM->delete_payment(\%myconfig, \%$form); + $form->redirect($locale->text('Payment terms deleted!')); + + $main::lxdebug->leave_sub(); +} + +sub swap_payment_terms { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('config'); + + AM->swap_sortkeys(\%myconfig, $form, "payment_terms"); + list_payment(); + + $main::lxdebug->leave_sub(); +} + +sub edit_defaults { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + # get defaults for account numbers and last numbers + AM->defaultaccounts(\%myconfig, \%$form); + $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g'); + + map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} }; + + foreach my $key (keys %{ $form->{IC} }) { + foreach my $accno (sort keys %{ $form->{IC}->{$key} }) { + my $array = "ACCNOS_" . uc($key); + $form->{$array} ||= []; + + my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description}; + push @{ $form->{$array} }, { + 'name' => $value, + 'value' => $value, + 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key}, + }; + } + } + + $form->{title} = $locale->text('Ranges of numbers and default accounts'); + + $form->header(); + print $form->parse_html_template('am/edit_defaults'); + + $main::lxdebug->leave_sub(); +} +sub save_defaults { + $main::lxdebug->enter_sub(); - AM->delete_warehouse(\%myconfig, \%$form); - $form->redirect($locale->text('Warehouse deleted!')); + my $form = $main::form; + my $locale = $main::locale; - $lxdebug->leave_sub(); + AM->save_defaults(); + + $form->redirect($locale->text('Defaults saved.')); + + $main::lxdebug->leave_sub(); +} + +sub _build_cfg_options { + my $form = $main::form; + my %myconfig = %main::myconfig; + + my $idx = shift; + my $array = uc($idx) . 'S'; + + $form->{$array} = []; + foreach my $item (@_) { + push @{ $form->{$array} }, { + 'name' => $item, + 'value' => $item, + 'selected' => $item eq $myconfig{$idx}, + }; + } +} + +sub config { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)); + _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00')); + + my @formats = (); + if ($main::opendocument_templates && $main::openofficeorg_writer_bin && + $main::xvfb_bin && (-x $main::openofficeorg_writer_bin) && (-x $main::xvfb_bin)) { + push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"), + "value" => "opendocument_pdf" }); + } + if ($main::latex_templates) { + push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" }); + } + push(@formats, { "name" => "HTML", "value" => "html" }); + if ($main::latex_templates) { + push(@formats, { "name" => $locale->text("Postscript"), + "value" => "postscript" }); + } + if ($main::opendocument_templates) { + push(@formats, { "name" => $locale->text("OpenDocument/OASIS"), + "value" => "opendocument" }); + } + + if (!$myconfig{"template_format"}) { + $myconfig{"template_format"} = "pdf"; + } + $form->{TEMPLATE_FORMATS} = []; + foreach my $item (@formats) { + push @{ $form->{TEMPLATE_FORMATS} }, { + 'name' => $item->{name}, + 'value' => $item->{value}, + 'selected' => $item->{value} eq $myconfig{template_format}, + }; + } + + if (!$myconfig{"default_media"}) { + $myconfig{"default_media"} = "screen"; + } + + my %selected = ($myconfig{"default_media"} => "selected"); + $form->{MEDIA} = [ + { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, }, + { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, }, + { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, }, + ]; + + $form->{PRINTERS} = []; + foreach my $printer (SL::Printer->all_printers(%::myconfig)) { + push @{ $form->{PRINTERS} }, { + 'name' => $printer->{printer_description}, + 'value' => $printer->{id}, + 'selected' => $printer->{id} == $myconfig{default_printer_id}, + }; + } + + my %countrycodes = User->country_codes; + + $form->{COUNTRYCODES} = []; + foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) { + push @{ $form->{COUNTRYCODES} }, { + 'name' => $countrycodes{$countrycode}, + 'value' => $countrycode, + 'selected' => $countrycode eq $myconfig{countrycode}, + }; + } + + $form->{STYLESHEETS} = []; + foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) { + push @{ $form->{STYLESHEETS} }, { + 'name' => $item, + 'value' => $item, + 'selected' => $item eq $myconfig{stylesheet}, + }; + } + + $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details})); + $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password(); + $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) }; + + $form->{title} = $locale->text('Edit Preferences for #1', $form->{login}); + + $form->header(); + print $form->parse_html_template('am/config'); + + $main::lxdebug->leave_sub(); } +sub save_preferences { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $form->{stylesheet} = $form->{usestylesheet}; -sub continue { - $lxdebug->enter_sub(); + TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } }); - - &{ $form->{nextsub} }; + $form->redirect($locale->text('Preferences saved!')) if (AM->save_preferences(\%myconfig, \%$form, 0)); + $form->error($locale->text('Cannot save preferences!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub audit_control { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + $form->{title} = $locale->text('Audit Control'); + + AM->closedto(\%myconfig, \%$form); + + $form->header; + + print qq| + + + + + + + + + + +
$form->{title}
+ + + + + +
| . $locale->text('Close Books up to') . qq|{closedto}>
+
+
+ +
+ + + + +
+ + + +|; + + $main::lxdebug->leave_sub(); +} + +sub doclose { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + AM->closebooks(\%myconfig, \%$form); + + if ($form->{closedto}) { + $form->redirect( + $locale->text('Books closed up to') . " " + . $locale->date(\%myconfig, $form->{closedto}, 1)); + } else { + $form->redirect($locale->text('Books are open')); + } + + $main::lxdebug->leave_sub(); +} + +sub edit_units { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + my $units = AM->retrieve_units(\%myconfig, $form, "resolved_"); + AM->units_in_use(\%myconfig, $form, $units); + map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units})); + + my @languages = AM->language(\%myconfig, $form, 1); + + my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units})); + + my $i = 1; + foreach (@unit_list) { + $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"}); + $_->{"UNITLANGUAGES"} = []; + foreach my $lang (@languages) { + push(@{ $_->{"UNITLANGUAGES"} }, + { "idx" => $i, + "unit" => $_->{"name"}, + "language_id" => $lang->{"id"}, + "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"}, + "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"}, + }); + } + $i++; + } + + $units = AM->retrieve_units(\%myconfig, $form); + my $ddbox = AM->unit_select_data($units, undef, 1); + + my $updownlink = build_std_url("action=swap_units"); + + $form->{"title"} = $locale->text("Add and edit units"); + $form->header(); + print($form->parse_html_template("am/edit_units", + { "UNITS" => \@unit_list, + "NEW_BASE_UNIT_DDBOX" => $ddbox, + "LANGUAGES" => \@languages, + "updownlink" => $updownlink })); + + $main::lxdebug->leave_sub(); +} + +sub add_unit { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + $form->isblank("new_name", $locale->text("The name is missing.")); + my $units = AM->retrieve_units(\%myconfig, $form); + my $all_units = AM->retrieve_units(\%myconfig, $form); + $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}}); + + my ($base_unit, $factor); + if ($form->{"new_base_unit"}) { + $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}})); + + $form->isblank("new_factor", $locale->text("The factor is missing.")); + $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"}); + $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor); + $base_unit = $form->{"new_base_unit"}; + } + + my @languages; + foreach my $lang (AM->language(\%myconfig, $form, 1)) { + next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"}); + push(@languages, { "id" => $lang->{"id"}, + "localized" => $form->{"new_localized_$lang->{id}"}, + "localized_plural" => $form->{"new_localized_plural_$lang->{id}"}, + }); + } + + AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages); + + $form->{"saved_message"} = $locale->text("The unit has been saved."); + + edit_units(); + + $main::lxdebug->leave_sub(); +} + +sub set_unit_languages { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + + $main::auth->assert('config'); + + my ($unit, $languages, $idx) = @_; + + $unit->{"LANGUAGES"} = []; + + foreach my $lang (@{$languages}) { + push(@{ $unit->{"LANGUAGES"} }, + { "id" => $lang->{"id"}, + "localized" => $form->{"localized_${idx}_$lang->{id}"}, + "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"}, + }); + } + + $main::lxdebug->leave_sub(); +} + +sub save_unit { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_"); + AM->units_in_use(\%myconfig, $form, $old_units); + + my @languages = AM->language(\%myconfig, $form, 1); + + my $new_units = {}; + my @delete_units = (); + foreach my $i (1..($form->{"rowcount"} * 1)) { + my $old_unit = $old_units->{$form->{"old_name_$i"}}; + if (!$old_unit) { + $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i)); + } + + if ($form->{"unchangeable_$i"}) { + $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}}; + $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1; + set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i); + next; + } + + if ($old_unit->{"in_use"}) { + $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i)); + } + + if ($form->{"delete_$i"}) { + push(@delete_units, $old_unit->{"name"}); + next; + } + + $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i)); + + $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}}); + my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name)); + $new_units->{$form->{"name_$i"}} = \%h; + $new_units->{$form->{"name_$i"}}->{"row"} = $i; + set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i); + } + + foreach my $unit (values(%{$new_units})) { + next unless ($unit->{"old_name"}); + if ($unit->{"base_unit"}) { + $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"})) + unless (defined($new_units->{$unit->{"base_unit"}})); + $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"}); + $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0); + } else { + $unit->{"base_unit"} = undef; + $unit->{"factor"} = undef; + } + } + + foreach my $unit (values(%{$new_units})) { + next if ($unit->{"unchanged_unit"}); + + map({ $_->{"seen"} = 0; } values(%{$new_units})); + my $new_unit = $unit; + while ($new_unit->{"base_unit"}) { + $new_unit->{"seen"} = 1; + $new_unit = $new_units->{$new_unit->{"base_unit"}}; + if ($new_unit->{"seen"}) { + $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, " . + "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"})); + } + } + } + + AM->save_units(\%myconfig, $form, $new_units, \@delete_units); + + $form->{"saved_message"} = $locale->text("The units have been saved."); + + edit_units(); + + $main::lxdebug->leave_sub(); +} + +sub show_history_search { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->assert('config'); + + $form->{title} = $locale->text("History Search"); + $form->header(); + + print $form->parse_html_template("common/search_history"); + + $main::lxdebug->leave_sub(); +} + +sub show_am_history { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search)); + $form->{order} ||= 'h.itime--1'; + + my %search = ( "Artikelnummer" => "parts", + "Kundennummer" => "customer", + "Lieferantennummer" => "vendor", + "Projektnummer" => "project", + "Buchungsnummer" => "oe", + "Eingangsrechnungnummer" => "ap", + "Ausgangsrechnungnummer" => "ar", + "Mahnungsnummer" => "dunning" + ); + my %searchNo = ( "Artikelnummer" => "partnumber", + "Kundennummer" => "customernumber", + "Lieferantennummer" => "vendornumber", + "Projektnummer" => "projectnummer", + "Buchungsnummer" => "ordnumber", + "Eingangsrechnungnummer" => "invnumber", + "Ausgangsrechnungnummer" => "invnumber", + "Mahnungsnummer" => "dunning_id" + ); + + my $dbh = $form->dbconnect(\%myconfig); + + my $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen}; + $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate}; + $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate}; + if ($form->{mitarbeiter} =~ m/^\d+$/) { + $restriction .= qq| AND employee_id = | . $form->{mitarbeiter}; + } elsif ($form->{mitarbeiter}) { + $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|; + } + + my $query = qq|SELECT trans_id AS id FROM history_erp | . + ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'| + : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|); + + my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query); + my $daten .= shift @ids; + $daten .= join '', map { " OR trans_id = $_" } @ids; + + my ($sort, $sortby) = split(/\-\-/, $form->{order}); + $sort =~ s/.*\.(.*)$/$1/; + + $form->{title} = $locale->text("History Search"); + $form->header(); + + print $form->parse_html_template("common/show_history", + { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}), + "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"), + "NONEWWINDOW" => 1, + uc($sort) => 1, + uc($sort) . "BY" => $sortby, + 'callback' => $callback, + }); + $dbh->disconnect(); + + $main::lxdebug->leave_sub(); +} + +sub swap_units { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('config'); + + my $dir = $form->{"dir"} eq "down" ? "down" : "up"; + AM->swap_units(\%myconfig, $form, $dir, $form->{"name"}); + + edit_units(); + + $main::lxdebug->leave_sub(); +} + +sub add_tax { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->assert('config'); + + $form->{title} = $locale->text('Add'); + + $form->{callback} ||= "am.pl?action=add_tax"; + + _get_taxaccount_selection(); + + $form->header(); + + my $parameters_ref = { +# ChartTypeIsAccount => $ChartTypeIsAccount, + }; + + # Ausgabe des Templates + print($form->parse_html_template('am/edit_tax', $parameters_ref)); + + $main::lxdebug->leave_sub(); +} + +sub edit_tax { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + $form->{title} = $locale->text('Edit'); + + AM->get_tax(\%myconfig, \%$form); + _get_taxaccount_selection(); + + $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2); + + $form->header(); + + my $parameters_ref = { + }; + + # Ausgabe des Templates + print($form->parse_html_template('am/edit_tax', $parameters_ref)); + + $main::lxdebug->leave_sub(); +} + +sub list_tax { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + AM->taxes(\%myconfig, \%$form); + + map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} }; + + $form->{callback} = build_std_url('action=list_tax'); + + $form->{title} = $locale->text('Tax-O-Matic'); + + $form->header(); + + my $parameters_ref = { + }; + + # Ausgabe des Templates + print($form->parse_html_template('am/list_tax', $parameters_ref)); + + $main::lxdebug->leave_sub(); +} + +sub _get_taxaccount_selection{ + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('config'); + + AM->get_tax_accounts(\%myconfig, \%$form); + + map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} }; + + $main::lxdebug->leave_sub(); +} + +sub save_tax { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + $form->isblank("rate", $locale->text('Taxrate missing!')); + $form->isblank("taxdescription", $locale->text('Taxdescription missing!')); + $form->isblank("taxkey", $locale->text('Taxkey missing!')); + + $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate}); + + if ( $form->{rate} < 0 || $form->{rate} >= 100 ) { + $form->error($locale->text('Tax Percent is a number between 0 and 100')); + } + + if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) { + $form->error($locale->text('Tax Percent is a number between 0 and 100')); + } + + AM->save_tax(\%myconfig, \%$form); + $form->redirect($locale->text('Tax saved!')); + + $main::lxdebug->leave_sub(); +} + +sub delete_tax { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + AM->delete_tax(\%myconfig, \%$form); + $form->redirect($locale->text('Tax deleted!')); + + $main::lxdebug->leave_sub(); +} + +sub add_price_factor { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->assert('config'); + + $form->{title} = $locale->text('Add Price Factor'); + $form->{callback} ||= build_std_url('action=add_price_factor'); + $form->{fokus} = 'description'; + + $form->header(); + print $form->parse_html_template('am/edit_price_factor'); + + $main::lxdebug->leave_sub(); +} + +sub edit_price_factor { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + $form->{title} = $locale->text('Edit Price Factor'); + $form->{callback} ||= build_std_url('action=add_price_factor'); + $form->{fokus} = 'description'; + + AM->get_price_factor(\%myconfig, $form); + + $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1); + + $form->header(); + print $form->parse_html_template('am/edit_price_factor'); + + $main::lxdebug->leave_sub(); +} + +sub list_price_factors { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + AM->get_all_price_factors(\%myconfig, \%$form); + + my $previous; + foreach my $current (@{ $form->{PRICE_FACTORS} }) { + if ($previous) { + $previous->{next_id} = $current->{id}; + $current->{previous_id} = $previous->{id}; + } + + $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1); + + $previous = $current; + } + + $form->{callback} = build_std_url('action=list_price_factors'); + $form->{title} = $locale->text('Price Factors'); + $form->{url_base} = build_std_url('callback'); + + $form->header(); + print $form->parse_html_template('am/list_price_factors'); + + $main::lxdebug->leave_sub(); +} + +sub save_price_factor { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + $form->isblank("description", $locale->text('Description missing!')); + $form->isblank("factor", $locale->text('Factor missing!')); + + $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor}); + + AM->save_price_factor(\%myconfig, $form); + + $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback}); + + $form->redirect($locale->text('Price factor saved!')); + + $main::lxdebug->leave_sub(); +} + +sub delete_price_factor { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + AM->delete_price_factor(\%myconfig, \%$form); + + $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback}); + + $form->redirect($locale->text('Price factor deleted!')); + + $main::lxdebug->leave_sub(); +} + +sub swap_price_factors { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('config'); + + AM->swap_sortkeys(\%myconfig, $form, 'price_factors'); + list_price_factors(); + + $main::lxdebug->leave_sub(); +} + +sub add_warehouse { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->assert('config'); + + $form->{title} = $locale->text('Add Warehouse'); + $form->{callback} ||= build_std_url('action=add_warehouse'); + $form->{fokus} = 'description'; + + $form->header(); + print $form->parse_html_template('am/edit_warehouse'); + + $main::lxdebug->leave_sub(); +} + +sub edit_warehouse { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + AM->get_warehouse(\%myconfig, $form); + + $form->get_lists('employees' => 'EMPLOYEES'); + + $form->{title} = $locale->text('Edit Warehouse'); + $form->{callback} ||= build_std_url('action=list_warehouses'); + $form->{fokus} = 'description'; + + $form->header(); + print $form->parse_html_template('am/edit_warehouse'); + + $main::lxdebug->leave_sub(); +} + +sub list_warehouses { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + AM->get_all_warehouses(\%myconfig, $form); + + my $previous; + foreach my $current (@{ $form->{WAREHOUSES} }) { + if ($previous) { + $previous->{next_id} = $current->{id}; + $current->{previous_id} = $previous->{id}; + } + + $previous = $current; + } + + $form->{callback} = build_std_url('action=list_warehouses'); + $form->{title} = $locale->text('Warehouses'); + $form->{url_base} = build_std_url('callback'); + + $form->header(); + print $form->parse_html_template('am/list_warehouses'); + + $main::lxdebug->leave_sub(); +} + +sub save_warehouse { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + $form->isblank("description", $locale->text('Description missing!')); + + $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins}); + + AM->save_warehouse(\%myconfig, $form); + + $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback}); + + $form->redirect($locale->text('Warehouse saved.')); + + $main::lxdebug->leave_sub(); +} + +sub swap_warehouses { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('config'); + + AM->swap_sortkeys(\%myconfig, $form, 'warehouse'); + list_warehouses(); + + $main::lxdebug->leave_sub(); +} + +sub delete_warehouse { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + if (!$form->{confirmed}) { + $form->{title} = $locale->text('Confirmation'); + + $form->header(); + print $form->parse_html_template('am/confirm_delete_warehouse'); + ::end_of_request(); + } + + if (AM->delete_warehouse(\%myconfig, $form)) { + $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback}); + $form->redirect($locale->text('Warehouse deleted.')); + + } else { + $form->error($locale->text('The warehouse could not be deleted because it has already been used.')); + } + + $main::lxdebug->leave_sub(); +} + +sub save_bin { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); + + AM->save_bins(\%myconfig, $form); + + $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback}); + + $form->redirect($locale->text('Bins saved.')); + + $main::lxdebug->leave_sub(); +}