X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fap.pl;h=7b16657e578c9f11824bc7592df27be8345b46d3;hb=094307a8ce3e7680a5b14ef17b5c1094a2555009;hp=3bbe8dcb9a696d82b372804dc476dbb0bd9b5bc0;hpb=4486e3bc8eb00c37cf8029e663eb94b4b9c5346a;p=kivitendo-erp.git diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index 3bbe8dcb9..7b16657e5 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -97,7 +97,7 @@ sub add { AP->get_transdate(\%myconfig, $form); $form->{initial_transdate} = $form->{transdate}; - &create_links; + create_links(dont_save => 1); $form->{transdate} = $form->{initial_transdate}; &display_form; @@ -113,7 +113,7 @@ sub edit { $form->{title} = "Edit"; - &create_links; + create_links(); &display_form; $main::lxdebug->leave_sub(); @@ -135,18 +135,23 @@ sub display_form { sub create_links { $main::lxdebug->enter_sub(); + my %params = @_; + my $form = $main::form; my %myconfig = %main::myconfig; $main::auth->assert('general_ledger'); $form->create_links("AP", \%myconfig, "vendor"); - my $taxincluded = $form->{taxincluded}; - my $duedate = $form->{duedate}; + my %saved; + if (!$params{dont_save}) { + %saved = map { ($_ => $form->{$_}) } qw(direct_debit taxincluded); + $saved{duedate} = $form->{duedate} if $form->{duedate}; + } IR->get_vendor(\%myconfig, \%$form); - $form->{taxincluded} = $taxincluded; - $form->{duedate} = $duedate if $duedate; + + $form->{$_} = $saved{$_} for keys %saved; $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}"; $form->{rowcount} = 1; @@ -192,115 +197,54 @@ sub form_header { $main::auth->assert('general_ledger'); - my $title = $form->{title}; - $form->{title} = $locale->text("$title Accounts Payables Transaction"); - - $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + $form->{title_} = $form->{title}; + $form->{title} = $form->{title} eq 'Add' ? $locale->text('Add Accounts Payables Transaction') : $locale->text('Edit Accounts Payables Transaction'); # type=submit $locale->text('Add Accounts Payables Transaction') # type=submit $locale->text('Edit Accounts Payables Transaction') - $form->{javascript} = qq||; - # show history button - $form->{javascript} .= qq||; - #/show hhistory button - # set option selected foreach my $item (qw(vendor currency department)) { my $to_replace = H($form->{$item}); $form->{"select$item"} =~ s/ selected//; $form->{"select$item"} =~ s/>\Q${to_replace}\E/ selected>${to_replace}/; } - my $readonly = ($form->{id}) ? "readonly" : ""; + my $readonly = $form->{id} ? "readonly" : ""; $form->{radier} = ($::instance_conf->get_ap_changeable == 2) ? ($form->current_date(\%myconfig) eq $form->{gldate}) : ($::instance_conf->get_ap_changeable == 1); - $readonly = ($form->{radier}) ? "" : $readonly; + $readonly = $form->{radier} ? "" : $readonly; - $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'sell'); - $form->{exchangerate} = $form->{forex} if $form->{forex}; + $form->{readonly} = $readonly; + + $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'sell'); + if ( $form->{forex} ) { + $form->{exchangerate} = $form->{forex}; + } # format amounts $form->{exchangerate} = $form->{exchangerate} ? $form->format_amount(\%myconfig, $form->{exchangerate}) : ''; $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); - my $exchangerate = qq| -{forex}> -|; - if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) { - if ($form->{forex}) { - $exchangerate .= qq| - - | . $locale->text('Exchangerate') . qq| - {exchangerate}>$form->{exchangerate} - -|; - } else { - $exchangerate .= qq| - | . $locale->text('Exchangerate') . qq| - {exchangerate}> -|; - } - } - - my $taxincluded = ""; - - $taxincluded = qq| - - {taxincluded}> - | - . $locale->text('Tax Included') . qq| - -|; - my $rows; if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) { $rows = 2; } - my $notes = - qq||; - my $intnotes = qq||; - - my $department; - $department = qq| - - | . $locale->text('Department') . qq| - - - - -| if $form->{selectdepartment}; - - my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; - - my $vendor = - ($form->{selectvendor}) - ? qq|| - : qq||; + $form->{textarea_rows} = $rows; + + $form->{creditremaining_plus} = ($form->{creditremaining} =~ /-/) ? "0" : "1"; my @old_project_ids = (); - map({ push(@old_project_ids, $form->{"project_id_$_"}) - if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"})); + map( + { + if ($form->{"project_id_$_"}) { + push(@old_project_ids, $form->{"project_id_$_"}); + } + } + (1..$form->{"rowcount"}) + ); $form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 0, @@ -310,84 +254,46 @@ sub form_header { "taxcharts" => { "key" => "ALL_TAXCHARTS", "module" => "AP" },); - map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; } - @{ $form->{ALL_CHARTS} }); + map( + { $_->{link_split} = [ split(/:/, $_->{link}) ]; } + @{ $form->{ALL_CHARTS} } + ); my %project_labels = (); - my @project_values = (""); foreach my $item (@{ $form->{"ALL_PROJECTS"} }) { - push(@project_values, $item->{"id"}); - $project_labels{$item->{"id"}} = $item->{"projectnumber"}; + $project_labels{$item->{id}} = $item->{projectnumber}; } - my (%AP_amount_labels, @AP_amount_values); - my (%AP_labels, @AP_values); - my (%AP_paid_labels, @AP_paid_values); my %charts; my $taxchart_init; foreach my $item (@{ $form->{ALL_CHARTS} }) { - if (grep({ $_ eq "AP_amount" } @{ $item->{link_split} })) { - $taxchart_init = $item->{tax_id} if ($taxchart_init eq ""); - my $key = "$item->{accno}--$item->{tax_id}"; - push(@AP_amount_values, $key); - $AP_amount_labels{$key} = - "$item->{accno}--$item->{description}"; - - } elsif (grep({ $_ eq "AP" } @{ $item->{link_split} })) { - push(@AP_values, $item->{accno}); - $AP_labels{$item->{accno}} = "$item->{accno}--$item->{description}"; - - } elsif (grep({ $_ eq "AP_paid" } @{ $item->{link_split} })) { - push(@AP_paid_values, $item->{accno}); - $AP_paid_labels{$item->{accno}} = - "$item->{accno}--$item->{description}"; + if ( grep({ $_ eq 'AP_amount' } @{ $item->{link_split} }) ) { + if ( $taxchart_init eq '' ) { + $taxchart_init = $item->{tax_id}; + } + + push(@{ $form->{ALL_CHARTS_AP_amount} }, $item); + } + elsif ( grep({ $_ eq 'AP' } @{ $item->{link_split} }) ) { + push(@{ $form->{ALL_CHARTS_AP} }, $item); + } + elsif ( grep({ $_ eq 'AP_paid' } @{ $item->{link_split} }) ) { + push(@{ $form->{ALL_CHARTS_AP_paid} }, $item); } $charts{$item->{accno}} = $item; } - my %taxchart_labels = (); - my @taxchart_values = (); my %taxcharts = (); foreach my $item (@{ $form->{ALL_TAXCHARTS} }) { - my $key = "$item->{id}--$item->{rate}"; - $taxchart_init = $key if ($taxchart_init eq $item->{id}); - push(@taxchart_values, $key); - $taxchart_labels{$key} = - "$item->{taxdescription} " . ($item->{rate} * 100) . ' %'; - $taxcharts{$item->{id}} = $item; - } + my $key = $item->{id} .'--'. $item->{rate}; - # use JavaScript Calendar or not - $form->{jsscript} = 1; - my $jsscript = ""; - my ($button1, $button2); - if ($form->{jsscript}) { - - # with JavaScript Calendar - $button1 = qq| - - text('button') . qq|> - |; - $button2 = qq| - - text('button') . qq|> - |; - - #write Trigger - $jsscript = - Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1", - "duedate", "BL", "trigger2"); - } else { + if ( $taxchart_init eq $item->{id} ) { + $taxchart_init = $key; + } - # without JavaScript Calendar - $button1 = - qq||; - $button2 = - qq||; + $taxcharts{$item->{id}} = $item; } my $follow_up_vc = $form->{vendor}; @@ -398,128 +304,12 @@ sub form_header { $form->{javascript} .= qq||; $form->{javascript} .= qq||; - my $globalprojectnumber = - NTI($cgi->popup_menu('-name' => "globalproject_id", - '-values' => \@project_values, - '-labels' => \%project_labels, - '-default' => $form->{"globalproject_id"} )); - - $form->header; - print qq| -
{script}> - -{id}> -{sort}> -{closedto}> -{locked}> - - - - - - - -| . ($form->{saved_message} ? qq|

$form->{saved_message}

| : "") . qq| - - - - - - - - - - - - -$jsscript - {rowcount}> - - - - - - - - - - - - -
$form->{title}
- - - - - -
- - - - - - - - - - - - - - - - - {defaultcurrency}> - {fxgain_accno}> - {fxloss_accno}> - $exchangerate - - $department - $taxincluded -
| . $locale->text('Vendor') . qq|$vendor
- - - - - - - {creditlimit}> - {creditremaining}> - -
| . $locale->text('Credit Limit') . qq|$form->{creditlimit}| . $locale->text('Remaining') . qq|$form->{creditremaining}
-
| . $locale->text('Currency') . qq|
-
- - - - - - - - - - - - $button1 - - - - $button2 - - - - - -
| . $locale->text('Invoice Number') . qq|
| . $locale->text('Order Number') . qq|
| . $locale->text('Invoice Date') . qq|
| . $locale->text('Due Date') . qq|
| . $locale->text('Project Number') . qq|$globalprojectnumber
-
-
- - - - - - - - -|; - - my $amount = $locale->text('Amount'); - my $project = $locale->text('Project'); + $form->header(); for my $i (1 .. $form->{rowcount}) { # format amounts - $form->{"amount_$i"} = - $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2); + $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2); $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2); my $selected_accno_full; @@ -540,147 +330,61 @@ $jsscript $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"}); - my $selectAP_amount = - NTI($cgi->popup_menu('-name' => "AP_amount_$i", - '-id' => "AP_amount_$i", - '-style' => 'width:400px', - '-onChange' => "setTaxkey(this, $i)", - '-values' => \@AP_amount_values, - '-labels' => \%AP_amount_labels, - '-default' => $selected_accno_full)) - . $cgi->hidden('-name' => "previous_AP_amount_$i", - '-default' => $selected_accno_full); - - my $tax = qq||; - - my $projectnumber = - NTI($cgi->popup_menu('-name' => "project_id_$i", - '-values' => \@project_values, - '-labels' => \%project_labels, - '-default' => ($i==$form->{rowcount})? $form->{globalproject_id} : $form->{"project_id_$i"} )); - - print qq| - - - - - $tax - - -|; - $amount = ""; - $project = ""; + $form->{'selected_accno_full_'. $i} = $selected_accno_full; + + $form->{'selected_taxchart_'. $i} = $selected_taxchart; } - my $taxlabel = - ($form->{taxincluded}) - ? $locale->text('Tax Included') - : $locale->text('Tax'); + $form->{AP_amount_value_title_sub} = sub { + my $item = shift; + return [ + $item->{accno} .'--'. $item->{tax_id}, + $item->{accno} .'--'. $item->{description}, + ]; + }; + + $form->{taxchart_value_title_sub} = sub { + my $item = shift; + return [ + $item->{id} .'--'. $item->{rate}, + $item->{taxdescription} .' '. ($item->{rate} * 100) .' %', + ]; + }; + + $form->{AP_paid_value_title_sub} = sub { + my $item = shift; + return [ + $item->{accno}, + $item->{accno} .'--'. $item->{description} + ]; + }; + + $form->{APselected_value_title_sub} = sub { + my $item = shift; + return [ + $item->{accno}, + $item->{accno} .'--'. $item->{description} + ]; + }; $form->{invtotal_unformatted} = $form->{invtotal}; $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2); - my $APselected = - NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected", - '-style' => 'width:400px', - '-values' => \@AP_values, '-labels' => \%AP_labels, - '-default' => $form->{APselected})); - print qq| - - - - - - - - {oldinvtotal}> - {oldtotalpaid}> - - - - - - - -
| . $locale->text('Account') . qq|| . $locale->text('Amount') . qq|| . $locale->text('Tax') . qq|| . $locale->text('Taxkey') . qq|| . $locale->text('Project') . qq|
| . - NTI($cgi->popup_menu('-name' => "taxchart_$i", - '-id' => "taxchart_$i", - '-style' => 'width:200px', - '-values' => \@taxchart_values, - '-labels' => \%taxchart_labels, - '-default' => $selected_taxchart)) - . qq|
$selectAP_amount{"amount_$i"}>$form->{"tax_$i"}$projectnumber
-
-
${APselected}$form->{invtotal}
-
- - - - - - - - -
| . $locale->text('Notes') . qq|$notes| . $locale->text('Notes for vendor') . qq|$intnotes
-
- - - - -|; + $form->{totalpaid} = 0; - my @column_index; - if ($form->{defaultcurrency} && ($form->{currency} eq $form->{defaultcurrency})) { - @column_index = qw(datepaid source memo paid AP_paid paid_project_id); - } else { - @column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id); + if ( $form->{'paid_'. $form->{paidaccounts}} ) { + $form->{paidaccounts}++; } - my %column_data; - $column_data{datepaid} = ""; - $column_data{paid} = ""; - $column_data{exchangerate} = ""; - $column_data{AP_paid} = ""; - $column_data{source} = ""; - $column_data{memo} = ""; - $column_data{paid_project_id} = ""; - - print " - -"; - map { print "$column_data{$_}\n" } @column_index; - print " - -"; - - my @triggers = (); - $form->{totalpaid} = 0; + # default account for current assets (i.e. 1801 - SKR04) + $form->{accno_arap} = IS->get_standard_accno_current_assets(\%myconfig, \%$form); - $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); for my $i (1 .. $form->{paidaccounts}) { - print " - -"; - - my $selectAP_paid = - NTI($cgi->popup_menu('-name' => "AP_paid_$i", - '-id' => "AP_paid_$i", - '-values' => \@AP_paid_values, - '-labels' => \%AP_paid_labels, - '-default' => $form->{"AP_paid_$i"})); - $form->{totalpaid} += $form->{"paid_$i"}; # format amounts if ($form->{"paid_$i"}) { - $form->{"paid_$i"} = - $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2); + $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2); } if ($form->{"exchangerate_$i"} == 0) { $form->{"exchangerate_$i"} = ""; @@ -689,8 +393,6 @@ $jsscript $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); } - print qq|{"acc_trans_id_$i"}>\n|; - print qq|{"gldate_$i"}>\n|; my $changeable = 1; if (SL::DB::Default->get->payments_changeable == 0) { # never @@ -701,127 +403,14 @@ $jsscript $changeable = (($form->{"gldate_$i"} eq '') || $form->current_date(\%myconfig) eq $form->{"gldate_$i"}); } - $exchangerate = qq| |; - if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) { - if ($form->{"forex_$i"}) { - $exchangerate = - qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; - } else { - if ($changeable) { - $exchangerate = - qq|{"exchangerate_$i"}>|; - } else { - $exchangerate = - qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; - } - } - } - - $exchangerate .= qq| -{"forex_$i"}> -|; - - my $datepaid; - if ($changeable) { - $datepaid = qq||; - } else { - $datepaid = qq||. - qq|{"datepaid_$i"}>|; - } - - my $paid; - if ($changeable) { - $paid = qq||; - } else { - $paid = qq||. - qq|{"paid_$i"}>|; - } - - my $source; - if ($changeable) { - $source = qq||; - } else { - $source = qq||. - qq|{"source_$i"}>|; - } - - my $memo; - if ($changeable) { - $memo = qq||; - } else { - $memo = qq||. - qq|{"memo_$i"}>|; - } - - my $AP_paid; - if ($changeable) { - $AP_paid = qq||; - } else { - $AP_paid = qq||. - qq|{"AP_paid_$i"}>|; - } + $form->{'paidaccount_changeable_'. $i} = $changeable; - my $paid_project_id; - if ($changeable) { - $paid_project_id = - qq||; - } else { - my $projectnumber = $project_labels{$form->{"paid_project_id_$i"}}; - $paid_project_id = qq||. - qq|{"paid_project_id_$i"}>|; - } - - $column_data{"paid_$i"} = $paid; - $column_data{"AP_paid_$i"} = $AP_paid; - $column_data{"exchangerate_$i"} = qq||; - $column_data{"datepaid_$i"} = $datepaid; - $column_data{"source_$i"} = $source; - $column_data{"memo_$i"} = $memo; - $column_data{"paid_project_id_$i"} = $paid_project_id; - - map { print qq|$column_data{"${_}_$i"}\n| } @column_index; - - print " - -"; - if ($changeable) { - push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i"); - } + $form->{'labelpaid_project_id_'. $i} = $project_labels{$form->{'paid_project_id_'. $i}}; } - my $paid_missing = $form->{invtotal_unformatted} - $form->{totalpaid}; + $form->{paid_missing} = $form->{invtotal_unformatted} - $form->{totalpaid}; - print qq| - - - - - - - - - - - - -| . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) . - qq| - {paidaccounts}> - -
| . $locale->text('Payments') . qq|
" . $locale->text('Date') . "" . $locale->text('Amount') . "" . $locale->text('Exch') . "" . $locale->text('Account') . "" . $locale->text('Source') . "" . $locale->text('Memo') . "" . $locale->text('Project Number') . "
- $form->{"datepaid_$i"}$form->{"paid_$i"}$form->{"source_$i"}$form->{"memo_$i"}${selectAP_paid}$form->{"AP_paid_$i"}| - . NTI($cgi->popup_menu('-name' => "paid_project_id_$i", - '-values' => \@project_values, - '-labels' => \%project_labels, - '-default' => $form->{"paid_project_id_$i"} )) - . qq|$projectnumber$exchangerate
| . $locale->text('Total') . qq|| . H($form->format_amount(\%myconfig, $form->{totalpaid}, 2)) . qq|
| . $locale->text('Missing amount') . qq|| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|
-

-|; + print $form->parse_html_template('ap/form_header'); $main::lxdebug->leave_sub(); } @@ -1021,10 +610,11 @@ sub post { my ($inline) = @_; - # check if there is a vendor, invoice and due date + # check if there is a vendor, invoice, due date and invnumber $form->isblank("transdate", $locale->text("Invoice Date missing!")); $form->isblank("duedate", $locale->text("Due Date missing!")); $form->isblank("vendor", $locale->text('Vendor missing!')); + $form->isblank("invnumber", $locale->text('Invoice Number missing!')); if ($myconfig{mandatory_departments} && !$form->{department}) { $form->{saved_message} = $::locale->text('You have to specify a department.'); @@ -1034,6 +624,9 @@ sub post { my $closedto = $form->datetonum($form->{closedto}, \%myconfig); my $transdate = $form->datetonum($form->{transdate}, \%myconfig); + + $form->error($locale->text('Cannot post transaction above the maximum future booking date!')) + if ($form->date_max_future($form->{"transdate"}, \%myconfig)); $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig)); my $zero_amount_posting = 1; @@ -1207,7 +800,7 @@ sub yes { sub search { $main::lxdebug->enter_sub(); - $main::auth->assert('general_ledger | vendor_invoice_edit'); + $main::auth->assert('vendor_invoice_edit'); my $form = $main::form; my %myconfig = %main::myconfig; @@ -1217,15 +810,12 @@ sub search { $form->all_vc(\%myconfig, "vendor", "AP"); $form->{title} = $locale->text('AP Transactions'); - $::request->{layout}->focus('#vendor'); - $form->{jsscript} = 1; $form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 }, "departments" => "ALL_DEPARTMENTS", "vendors" => "ALL_VC"); # constants and subs for template - $form->{jsscript} = 1; $form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" }; $form->header; @@ -1262,7 +852,7 @@ sub ap_transactions { my %myconfig = %main::myconfig; my $locale = $main::locale; - $main::auth->assert('general_ledger | vendor_invoice_edit'); + $main::auth->assert('vendor_invoice_edit'); ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});