X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fis.pl;h=2cdf21e63680a5332923bfc419983962d76c286d;hb=0e6197ea79295e1a1232617ee4ed4ae99d8a0640;hp=4e6a066dbe5c4690375c13161416b374c53719a3;hpb=c103dedd31b5aeb5899c191f2950d2db95e12a79;p=kivitendo-erp.git diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 4e6a066db..2cdf21e63 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -31,862 +31,463 @@ # #====================================================================== +use SL::FU; use SL::IS; use SL::PE; +use SL::OE; +use Data::Dumper; +use List::Util qw(max sum); -require "$form->{path}/io.pl"; -require "$form->{path}/arap.pl"; +require "bin/mozilla/io.pl"; +require "bin/mozilla/invoice_io.pl"; +require "bin/mozilla/arap.pl"; +require "bin/mozilla/drafts.pl"; + +use strict; 1; # end of main sub add { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; - $form->{title} = $locale->text('Add Sales Invoice'); + $main::auth->assert('invoice_edit'); - $form->{callback} = - "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}" - unless $form->{callback}; + return $main::lxdebug->leave_sub() if (load_draft_maybe()); - $form{jsscript} = "date"; + if ($form->{type} eq "credit_note") { + $form->{title} = $locale->text('Add Credit Note'); + + if ($form->{storno}) { + $form->{title} = $locale->text('Add Storno Credit Note'); + } + } else { + $form->{title} = $locale->text('Add Sales Invoice'); - if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR") - { - $form->error("Access Denied"); } + + $form->{callback} = "$form->{script}?action=add&type=$form->{type}" unless $form->{callback}; + + $form->{jsscript} = "date"; + &invoice_links; &prepare_invoice; &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub edit { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $form->{title} = $locale->text('Edit Sales Invoice'); + my $form = $main::form; + my $locale = $main::locale; - if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR") - { - $form->error("Access Denied"); + $main::auth->assert('invoice_edit'); + + # show history button + $form->{javascript} = qq||; + #/show hhistory button + + if ($form->{type} eq "credit_note") { + $form->{title} = $locale->text('Edit Credit Note'); + $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno}; + } else { + $form->{title} = $locale->text('Edit Sales Invoice'); + $form->{title} = $locale->text('Edit Storno Invoice') if $form->{storno}; } + my ($language_id, $printer_id); + if ($form->{print_and_post}) { + $form->{action} = "print"; + $form->{resubmit} = 1; + $language_id = $form->{language_id}; + $printer_id = $form->{printer_id}; + } &invoice_links; &prepare_invoice; + if ($form->{print_and_post}) { + $form->{language_id} = $language_id; + $form->{printer_id} = $printer_id; + } + &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub invoice_links { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('invoice_edit'); $form->{vc} = 'customer'; # create links - $form->{webdav} = $webdav; - $form->{lizenzen} = $lizenzen; + $form->{webdav} = $main::webdav; + $form->{lizenzen} = $main::lizenzen; $form->create_links("AR", \%myconfig, "customer"); if ($form->{all_customer}) { unless ($form->{customer_id}) { $form->{customer_id} = $form->{all_customer}->[0]->{id}; + $form->{salesman_id} = $form->{all_customer}->[0]->{salesman_id}; } } - $cp_id = $form->{cp_id}; - IS->get_customer(\%myconfig, \%$form); - IS->retrieve_invoice(\%myconfig, \%$form); - $form->{cp_id} = $cp_id; + my $editing = $form->{id}; - # currencies - @curr = split /:/, $form->{currencies}; - chomp $curr[0]; - $form->{defaultcurrency} = $curr[0]; + $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes id shipto_id)); + + IS->get_customer(\%myconfig, \%$form); - map { $form->{selectcurrency} .= "$_\n" } @curr; + #quote all_customer Bug 133 + foreach my $ref (@{ $form->{all_customer} }) { + $ref->{name} = $form->quote($ref->{name}); + } - $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}"; + # Load data for a specific order and update form fields + my $order_data = OE->get_order_data_by_ordnumber(%$form) if $form->{ordnumber}; - if ($form->{all_customer}) { - $form->{customer} = "$form->{customer}--$form->{customer_id}"; - map { $form->{selectcustomer} .= "$_->{name}--$_->{id}\n" } - (@{ $form->{all_customer} }); + # Copy the fields we need to %form + for my $key (qw(payment_id salesman_id orddate taxzone_id quonumber)) { + $form->{$key} = $order_data->{$key}; } - # departments - if ($form->{all_departments}) { - $form->{selectdepartment} = "\n"; - $form->{department} = "$form->{department}--$form->{department_id}"; + $form->restore_vars(qw(id)); + + IS->retrieve_invoice(\%myconfig, \%$form); + $form->restore_vars(qw(payment_id language_id taxzone_id intnotes cp_id shipto_id)); + $form->restore_vars(qw(taxincluded)) if $form->{id}; + $form->restore_vars(qw(salesman_id)) if $editing; + - map { - $form->{selectdepartment} .= - "$_->{description}--$_->{id}\n" - } (@{ $form->{all_departments} }); + # build vendor/customer drop down comatibility... don't ask + if (@{ $form->{"all_customer"} }) { + $form->{"selectcustomer"} = 1; + $form->{customer} = qq|$form->{customer}--$form->{"customer_id"}|; } - $form->{employee} = "$form->{employee}--$form->{employee_id}"; + $form->{"oldcustomer"} = $form->{customer}; - # sales staff - if ($form->{all_employees}) { - $form->{selectemployee} = ""; - map { $form->{selectemployee} .= "$_->{name}--$_->{id}\n" } - (@{ $form->{all_employees} }); + if ($form->{"oldcustomer"} !~ m/--\d+$/ && $form->{"customer_id"}) { + $form->{"oldcustomer"} .= qq|--$form->{"customer_id"}| } + +# $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}"; +# $form->{selectcustomer} = 1; + + $form->{employee} = "$form->{employee}--$form->{employee_id}"; + # forex $form->{forex} = $form->{exchangerate}; - $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; + my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; - foreach $key (keys %{ $form->{AR_links} }) { - foreach $ref (@{ $form->{AR_links}{$key} }) { - $form->{"select$key"} .= "$ref->{accno}--$ref->{description}\n"; + foreach my $key (keys %{ $form->{AR_links} }) { + foreach my $ref (@{ $form->{AR_links}{$key} }) { + $form->{"select$key"} .= "$ref->{accno}--$ref->{description}\n"; } if ($key eq "AR_paid") { - for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) { - $form->{"AR_paid_$i"} = - "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; + next unless $form->{acc_trans}{$key}; + for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) { + $form->{"AR_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; # reverse paid - $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1; - $form->{"datepaid_$i"} = - $form->{acc_trans}{$key}->[$i - 1]->{transdate}; - $form->{"forex_$i"} = $form->{"exchangerate_$i"} = - $form->{acc_trans}{$key}->[$i - 1]->{exchangerate}; - $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source}; - $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo}; + $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1; + $form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{transdate}; + $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{exchangerate}; + $form->{"forex_$i"} = $form->{"exchangerate_$i"}; + $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source}; + $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo}; $form->{paidaccounts} = $i; } } else { - $form->{$key} = - "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}"; + $form->{$key} = "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}"; } - } $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts}); $form->{AR} = $form->{AR_1} unless $form->{id}; - $form->{locked} = - ($form->datetonum($form->{invdate}, \%myconfig) <= - $form->datetonum($form->{closedto}, \%myconfig)); + $form->{locked} = ($form->datetonum($form->{invdate}, \%myconfig) + <= $form->datetonum($form->{closedto}, \%myconfig)); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub prepare_invoice { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; - $form->{type} = "invoice"; - $form->{formname} = "invoice"; - $form->{format} = "html"; - $form->{media} = "screen"; + $main::auth->assert('invoice_edit'); + + if ($form->{type} eq "credit_note") { + $form->{type} = "credit_note"; + $form->{formname} = "credit_note"; + } else { + $form->{type} = "invoice"; + $form->{formname} = "invoice"; + } if ($form->{id}) { - map { $form->{$_} =~ s/\"/"/g } - qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes); + my $i = 0; - foreach $ref (@{ $form->{invoice_details} }) { + foreach my $ref (@{ $form->{invoice_details} }) { $i++; - map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref}; - $form->{"discount_$i"} = - $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100); - ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); - $dec = length $dec; - $decimalplaces = ($dec > 2) ? $dec : 2; + map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref}; - $form->{"sellprice_$i"} = - $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, - $decimalplaces); - $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); + $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100); + my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); + $dec = length $dec; + my $decimalplaces = ($dec > 2) ? $dec : 2; - map { $form->{"${_}_$i"} =~ s/\"/"/g } - qw(partnumber description unit partnotes); - $form->{rowcount} = $i; - } - } - $lxdebug->leave_sub(); -} + $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); + (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/); + $dec_qty = length $dec_qty; -sub form_header { - $lxdebug->enter_sub(); + $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces); - # set option selected - foreach $item (qw(AR customer currency department employee contact)) { - $form->{"select$item"} =~ s/ selected//; - $form->{"select$item"} =~ - s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; - } + $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty); - #build contacts - if ($form->{all_contacts}) { + $form->{rowcount} = $i; - $form->{selectcontact} = ""; - foreach $item (@{ $form->{all_contacts} }) { - if ($form->{cp_id} == $item->{cp_id}) { - $form->{selectcontact} .= - "$item->{cp_name}--$item->{cp_id}"; - } else { - $form->{selectcontact} .= "$item->{cp_name}--$item->{cp_id}"; - } } + + # get pricegroups for parts + IS->get_pricegroups_for_parts(\%myconfig, \%$form); + set_pricegroup($_) for 1 .. $form->{rowcount}; } + $main::lxdebug->leave_sub(); +} - #else {$form->{all_contacts} = 0;} +sub form_header { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + my $cgi = $main::cgi; + + $main::auth->assert('invoice_edit'); + + my %TMPL_VAR = (); + my @custom_hiddens; + + $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id}; + $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id}; + + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); + + my $set_duedate_url = "$form->{script}?action=set_duedate"; + + push @ { $form->{AJAX} }, new CGI::Ajax( 'set_duedate' => $set_duedate_url ); + + my @old_project_ids = ($form->{"globalproject_id"}); + map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"}; + + $form->get_lists("contacts" => "ALL_CONTACTS", + "shipto" => "ALL_SHIPTO", + "projects" => { "key" => "ALL_PROJECTS", + "all" => 0, + "old_id" => \@old_project_ids }, + "employees" => "ALL_EMPLOYEES", + "salesmen" => "ALL_SALESMEN", + "taxzones" => "ALL_TAXZONES", + "currencies" => "ALL_CURRENCIES", + "customers" => "ALL_CUSTOMERS", + "departments" => "all_departments", + "price_factors" => "ALL_PRICE_FACTORS"); + + $TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} }; + $TMPL_VAR{shipto_labels} = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) }; + $TMPL_VAR{contact_labels} = sub { join(', ', $_[0]->{"cp_name"}, $_[0]->{"cp_givenname"}) . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") }; + $TMPL_VAR{department_labels} = sub { "$_[0]->{description}--$_[0]->{id}" }; + + # customer + $TMPL_VAR{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" }; + $TMPL_VAR{vclimit} = $myconfig{vclimit}; + $TMPL_VAR{vc_select} = "customer_or_vendor_selection_window('customer', '', 0, 0)"; + push @custom_hiddens, "customer_id"; + push @custom_hiddens, "oldcustomer"; + push @custom_hiddens, "selectcustomer"; + + # currencies and exchangerate + my @values = map { $_ } @{ $form->{ALL_CURRENCIES} }; + my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} }; + $form->{currency} = $form->{defaultcurrency} unless $form->{currency}; + $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency}; + $TMPL_VAR{currencies} = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"}, + '-values' => \@values, '-labels' => \%labels)) if scalar @values; + push @custom_hiddens, "forex"; + push @custom_hiddens, "exchangerate" if $form->{forex}; + + $TMPL_VAR{creditwarning} = ($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}; + $TMPL_VAR{is_credit_remaining_negativ} = $form->{creditremaining} =~ /-/; - $form->{exchangerate} = - $form->format_amount(\%myconfig, $form->{exchangerate}); + $form->{fokus} = "invoice.customer"; - $form->{creditlimit} = - $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); - $form->{creditremaining} = - $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); + my $follow_up_vc = $form->{customer}; + $follow_up_vc =~ s/--\d*\s*$//; + $TMPL_VAR{customer_name} = $follow_up_vc; - $exchangerate = ""; - if ($form->{currency} ne $form->{defaultcurrency}) { - if ($form->{forex}) { - $exchangerate .= - qq|| - . $locale->text('Exchangerate') - . qq|$form->{exchangerate}{exchangerate}>|; - } else { - $exchangerate .= - qq|| - . $locale->text('Exchangerate') - . qq|{exchangerate}>|; - } +# set option selected + foreach my $item (qw(AR)) { + $form->{"select$item"} =~ s/ selected//; + $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; } - $exchangerate .= qq| -{forex}> -|; - $customer = - ($form->{selectcustomer}) - ? qq|$form->{selectcustomer}\n| - : qq||; - - #sk - $contact = - ($form->{selectcontact}) - ? qq|$form->{selectcontact}\n| - : qq||; - - $department = qq| - - | . $locale->text('Department') . qq| - $form->{selectdepartment} - - - -| if $form->{selectdepartment}; - - $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; - - if ($form->{business}) { - $business = qq| - - | . $locale->text('Business') . qq| - $form->{business} - | . $locale->text('Trade Discount') . qq| - | - . $form->format_amount(\%myconfig, $form->{tradediscount} * 100) - . qq| % - -|; - } + $TMPL_VAR{is_type_credit_note} = $form->{type} eq "credit_note"; + $TMPL_VAR{is_format_html} = $form->{format} eq 'html'; + $TMPL_VAR{dateformat} = $myconfig{dateformat}; + $TMPL_VAR{numberformat} = $myconfig{numberformat}; - $form->{fokus} = "invoice.customer"; + # hiddens + $TMPL_VAR{HIDDENS} = [qw( + id action type media format queued printed emailed title vc discount + title creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id + max_dunning_level dunning_amount + shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax + shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus + convert_from_do_ids convert_from_oe_ids + ), @custom_hiddens, + map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}]; - # use JavaScript Calendar or not - $form->{jsscript} = $jscalendar; - $jsscript = ""; - if ($form->{jsscript}) { - - # with JavaScript Calendar - $button1 = qq| - {invdate}> - text('button') . qq|> - |; - $button2 = qq| - {duedate}> - text('button') . qq|> - |; - - #write Trigger - $jsscript = - Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1", - "duedate", "BL", "trigger2"); - } else { + $form->{jsscript} = 1; + $form->header(); - # without JavaScript Calendar - $button1 = - qq|{invdate}>|; - $button2 = - qq|{duedate}>|; - } - if ($form->{resubmit}) { - $onload = "document.invoice.submit()"; - } else { - $onload = "fokus()"; - } - $form->header; + print $form->parse_html_template("is/form_header", \%TMPL_VAR); - print qq| - - -{script}> - - -{id}> -{action}> - -{type}> -{media}> -{format}> - - - - - - -{vc}> - -{discount}> -{creditlimit}> -{creditremaining}> - -{tradediscount}> -{business}> - -{closedto}> -{locked}> - -{shipped}> - - - - - $form->{title} - - - - - - - - - - | . $locale->text('Customer') . qq| - $customer - {customer_id}> - - | - . $locale->text('Contact Person') . qq| - $contact - - - - - - - | . $locale->text('Credit Limit') . qq| - $form->{creditlimit} - - | . $locale->text('Remaining') . qq| - $form->{creditremaining} - - - - - $business - - | . $locale->text('Record in') . qq| - $form->{selectAR} - - - $department - - | . $locale->text('Currency') . qq| - $form->{selectcurrency} - - {defaultcurrency}> - {fxgain_accno}> - {fxloss_accno}> - $exchangerate - - - | . $locale->text('Shipping Point') . qq| - - - - | . $locale->text('Ship via') . qq| - - - - - - - - | . $locale->text('Salesperson') . qq| - $form->{selectemployee} - - - - - | . $locale->text('Invoice Number') . qq| - - - - | . $locale->text('Invoice Date') . qq| - $button1 - - - | . $locale->text('Due Date') . qq| - $button2 - - - | . $locale->text('Order Number') . qq| - - - - | . $locale->text('Quotation Number') . qq| - - - - | . $locale->text('Customer Order Number') . qq| - - - - - - - - - - - - - -$jsscript - - - - - - - - - - - - - - - - - - - - - -|; - - foreach $item (split / /, $form->{taxaccounts}) { - print qq| - - - -|; - } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub form_footer { - $lxdebug->enter_sub(); - - $form->{invtotal} = $form->{invsubtotal}; + $main::lxdebug->enter_sub(); - if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) { - $rows = 2; - } - if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) { - $introws = 2; - } - $rows = ($rows > $introws) ? $rows : $introws; - $notes = - qq|$form->{notes}|; - $intnotes = - qq|$form->{intnotes}|; - - $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; - - $taxincluded = ""; - if ($form->{taxaccounts}) { - $taxincluded = qq| - {taxincluded}> | - . $locale->text('Tax Included') . qq||; - } + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - if (!$form->{taxincluded}) { + $main::auth->assert('invoice_edit'); - foreach $item (split / /, $form->{taxaccounts}) { - if ($form->{"${item}_base"}) { - $form->{"${item}_total"} = - $form->round_amount( - $form->{"${item}_base"} * $form->{"${item}_rate"}, - 2); - $form->{invtotal} += $form->{"${item}_total"}; - $form->{"${item}_total"} = - $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2); - - $tax .= qq| - - $form->{"${item}_description"} - $form->{"${item}_total"} - -|; - } - } + $form->{invtotal} = $form->{invsubtotal}; + $form->{oldinvtotal} = $form->{invtotal}; - $form->{invsubtotal} = - $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); + # note rows + $form->{rows} = max 2, + $form->numtextrows($form->{notes}, 26, 8), + $form->numtextrows($form->{intnotes}, 35, 8); - $subtotal = qq| - - | . $locale->text('Subtotal') . qq| - $form->{invsubtotal} - -|; - } + # tax, total and subtotal calculations + my ($tax, $subtotal); + $form->{taxaccounts_array} = [ split / /, $form->{taxaccounts} ]; - if ($form->{taxincluded}) { - foreach $item (split / /, $form->{taxaccounts}) { - if ($form->{"${item}_base"}) { - $form->{"${item}_total"} = - $form->round_amount( - ($form->{"${item}_base"} * $form->{"${item}_rate"} / - (1 + $form->{"${item}_rate"}) - ), - 2); - $form->{"${item}_netto"} = - $form->round_amount( - ($form->{"${item}_base"} - $form->{"${item}_total"}), - 2); - $form->{"${item}_total"} = - $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2); - $form->{"${item}_netto"} = - $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2); - - $tax .= qq| - - Enthaltene $form->{"${item}_description"} - $form->{"${item}_total"} - - - Nettobetrag - $form->{"${item}_netto"} - -|; + foreach my $item (@{ $form->{taxaccounts_array} }) { + if ($form->{"${item}_base"}) { + if ($form->{taxincluded}) { + $form->{"${item}_total"} = $form->round_amount( ($form->{"${item}_base"} * $form->{"${item}_rate"} + / (1 + $form->{"${item}_rate"})), 2); + $form->{"${item}_netto"} = $form->round_amount( ($form->{"${item}_base"} - $form->{"${item}_total"}), 2); + } else { + $form->{"${item}_total"} = $form->round_amount( $form->{"${item}_base"} * $form->{"${item}_rate"}, 2); + $form->{invtotal} += $form->{"${item}_total"}; } } - } - $form->{oldinvtotal} = $form->{invtotal}; - $form->{invtotal} = - $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0); - - print qq| - - - - - - - - | . $locale->text('Notes') . qq| - | . $locale->text('Internal Notes') . qq| - - - $notes - $intnotes - - - - - $taxincluded - - $subtotal - $tax - - | . $locale->text('Total') . qq| - $form->{invtotal} - - - - - - - -|; - if ($webdav) { - $webdav_list = qq| - - - - - Dokumente im Webdav-Repository - - - Dateiname - Webdavlink -|; - foreach $file (keys %{ $form->{WEBDAV} }) { - $webdav_list .= qq| - - $file - $form->{WEBDAV}{$file} - -|; - } - $webdav_list .= qq| - - -|; - - print $webdav_list; - } - print qq| - - - - - | - . $locale->text('Incoming Payments') . qq| - -|; - - if ($form->{currency} eq $form->{defaultcurrency}) { - @column_index = qw(datepaid source memo paid AR_paid); - } else { - @column_index = qw(datepaid source memo paid exchangerate AR_paid); + # follow ups + if ($form->{id}) { + $form->{follow_ups} = FU->follow_ups('trans_id' => $form->{id}) || []; + $form->{follow_ups_unfinished} = ( sum map { $_->{due} * 1 } @{ $form->{follow_ups} } ) || 0; } - $column_data{datepaid} = "" . $locale->text('Date') . ""; - $column_data{paid} = "" . $locale->text('Amount') . ""; - $column_data{exchangerate} = "" . $locale->text('Exch') . ""; - $column_data{AR_paid} = "" . $locale->text('Account') . ""; - $column_data{source} = "" . $locale->text('Source') . ""; - $column_data{memo} = "" . $locale->text('Memo') . ""; - - print " - -"; - map { print "$column_data{$_}\n" } @column_index; - print " - -"; - + # payments + my $totalpaid = 0; $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); - for $i (1 .. $form->{paidaccounts}) { - - print " - \n"; + $form->{paid_indices} = [ 1 .. $form->{paidaccounts} ]; + for my $i (1 .. $form->{paidaccounts}) { $form->{"selectAR_paid_$i"} = $form->{selectAR_paid}; - $form->{"selectAR_paid_$i"} =~ - s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/; - - # format amounts + $form->{"selectAR_paid_$i"} =~ s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/; $totalpaid += $form->{"paid_$i"}; - $form->{"paid_$i"} = - $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2); - $form->{"exchangerate_$i"} = - $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); - - $exchangerate = qq| |; - if ($form->{currency} ne $form->{defaultcurrency}) { - if ($form->{"forex_$i"}) { - $exchangerate = - qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; - } else { - $exchangerate = - qq|{"exchangerate_$i"}>|; - } - } - - $exchangerate .= qq| -{"forex_$i"}> -|; - - $column_data{"paid_$i"} = - qq|{"paid_$i"}>|; - $column_data{"exchangerate_$i"} = qq|$exchangerate|; - $column_data{"AR_paid_$i"} = - qq|$form->{"selectAR_paid_$i"}|; - $column_data{"datepaid_$i"} = - qq|{"datepaid_$i"}>|; - $column_data{"source_$i"} = - qq||; - $column_data{"memo_$i"} = - qq||; - - map { print qq|$column_data{"${_}_$i"}\n| } @column_index; - print " - \n"; } - print qq| -{paidaccounts}> - -{oldinvtotal}> - -{print_and_post}> -{second_run}> - - - - - - - - -|; - - &print_options; - - print qq| - - - -|; - - $invdate = $form->datetonum($form->{invdate}, \%myconfig); - $closedto = $form->datetonum($form->{closedto}, \%myconfig); - - if ($form->{id}) { - print qq| - - - - -|; - - if (!$form->{revtrans}) { - if (!$form->{locked}) { - print qq| - - -|; - } - } - - if ($invdate > $closedto) { - print qq| - - -|; - } - - } else { - if ($invdate > $closedto) { - print qq| - - - - - |; - } - } + print $form->parse_html_template('is/form_footer', { + is_type_credit_note => ($form->{type} eq "credit_note"), + totalpaid => $totalpaid, + paid_missing => $form->{invtotal} - $totalpaid, + print_options => print_options(inline => 1), + show_storno => $form->{id} && !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar") && !$totalpaid, + show_delete => ($form->current_date(\%myconfig) eq $form->{gldate}), + }); +##print $form->parse_html_template('is/_payments'); # parser +##print $form->parse_html_template('webdav/_list'); # parser + + $main::lxdebug->leave_sub(); +} - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } +sub mark_as_paid { + $main::lxdebug->enter_sub(); - print qq| + my $form = $main::form; + my %myconfig = %main::myconfig; -{rowcount}> + $main::auth->assert('invoice_edit'); - + &mark_as_paid_common(\%myconfig,"ar"); -{path}> -{login}> -{password}> + $main::lxdebug->leave_sub(); +} - +sub update { + $main::lxdebug->enter_sub(); - + my $form = $main::form; + my %myconfig = %main::myconfig; -