X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fis.pl;h=b858db1cd927c7d0646dfd7a9350bebf3efa84fc;hb=e7fdb1da83751073b7bcc5488772c7e844789062;hp=a043e07bb655b4bbb147502769149a3a7ecf48c6;hpb=4dbb09950c9f5596646537c12d991c99086fe7c1;p=kivitendo-erp.git diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index a043e07bb..b858db1cd 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -31,775 +31,486 @@ # #====================================================================== - +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 { + $main::lxdebug->enter_sub(); + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->assert('invoice_edit'); + + return $main::lxdebug->leave_sub() if (load_draft_maybe()); + + 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'); + + } -sub add { - $lxdebug->enter_sub(); - $form->{title} = $locale->text('Add Sales Invoice'); + $form->{callback} = "$form->{script}?action=add&type=$form->{type}" unless $form->{callback}; - $form->{callback} = "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}" unless $form->{callback}; + $form->{jsscript} = "date"; - $form{jsscript} = "date"; - - if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR") { - $form->error("Access Denied") - } - &invoice_links; &prepare_invoice; &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } - sub edit { - $lxdebug->enter_sub(); - - $form->{title} = $locale->text('Edit Sales Invoice'); - - if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR") { - $form->error("Access Denied") - } - + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->assert('invoice_edit'); + + # show history button + $form->{javascript} = qq||; + #/show hhistory button + + 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; + 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}; + } + &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} = $::lx_office_conf{features}->{webdav}; $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}; + + my $editing = $form->{id}; + + $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes id shipto_id)); + IS->get_customer(\%myconfig, \%$form); - - IS->retrieve_invoice(\%myconfig, \%$form); - $form->{cp_id} = $cp_id; - # currencies - @curr = split /:/, $form->{currencies}; - chomp $curr[0]; - $form->{defaultcurrency} = $curr[0]; + #quote all_customer Bug 133 + foreach my $ref (@{ $form->{all_customer} }) { + $ref->{name} = $form->quote($ref->{name}); + } + + $form->restore_vars(qw(id)); - map { $form->{selectcurrency} .= "$_\n" } @curr; + 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; - $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}"; - if ($form->{all_customer}) { - $form->{customer} = "$form->{customer}--$form->{customer_id}"; - map { $form->{selectcustomer} .= "$_->{name}--$_->{id}\n" } (@{ $form->{all_customer} }); + # build vendor/customer drop down comatibility... don't ask + if (@{ $form->{"all_customer"} }) { + $form->{"selectcustomer"} = 1; + $form->{customer} = qq|$form->{customer}--$form->{"customer_id"}|; } - - # departments - if ($form->{all_departments}) { - $form->{selectdepartment} = "\n"; - $form->{department} = "$form->{department}--$form->{department_id}"; - map { $form->{selectdepartment} .= "$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} }); + $form->{"oldcustomer"} = $form->{customer}; + + 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}"; - # sales staff - if ($form->{all_employees}) { - $form->{selectemployee} = ""; - map { $form->{selectemployee} .= "$_->{name}--$_->{id}\n" } (@{ $form->{all_employees} }); - } - + # forex $form->{forex} = $form->{exchangerate}; - $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"; + my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; + + 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}"; - # 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->{paidaccounts} = $i; + 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}"; + + $form->{"acc_trans_id_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{acc_trans_id}; + # reverse paid + $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1; + $form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{transdate}; + $form->{"gldate_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{gldate}; + $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->{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(); - - $form->{type} = "invoice"; - $form->{formname} = "invoice"; - $form->{format} = "html"; - $form->{media} = "screen"; + $main::lxdebug->enter_sub(); - if ($form->{id}) { + my $form = $main::form; + my %myconfig = %main::myconfig; - map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes); + $main::auth->assert('invoice_edit'); - foreach $ref (@{ $form->{invoice_details} } ) { - $i++; - map { $form->{"${_}_$i"} = $ref->{$_} } keys %{ $ref }; - $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100); + if ($form->{type} eq "credit_note") { + $form->{type} = "credit_note"; + $form->{formname} = "credit_note"; + } else { + $form->{type} = "invoice"; + $form->{formname} = "invoice"; + } - ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); - $dec = length $dec; - $decimalplaces = ($dec > 2) ? $dec : 2; + if ($form->{id}) { - $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); - $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); + my $i = 0; - map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit partnotes); - $form->{rowcount} = $i; - } - } - $lxdebug->leave_sub(); -} + foreach my $ref (@{ $form->{invoice_details} }) { + $i++; + map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref}; + $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; -sub form_header { - $lxdebug->enter_sub(); + $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); + (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/); + $dec_qty = length $dec_qty; - # 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}/; - } - - #build contacts - if ($form->{all_contacts}) { - - $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}"; - } - } - } - #else {$form->{all_contacts} = 0;} + $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces); - $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); + $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty); - $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); - $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); + $form->{"sellprice_pg_$i"} = join ('--', $form->{"sellprice_$i"}, $form->{"pricegroup_id_$i"}); + $form->{rowcount} = $i; - $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}>|; } - } - $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| % - -|; - } - $form->{fokus} = "invoice.customer"; - - # 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 - { - # without JavaScript Calendar - $button1 = qq|{invdate}>|; - $button2 = qq|{duedate}>|; - } - - $form->header; - - print qq| - - -{script}> - - -{id}> - -{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 - - - - - - - - - - - - - - - - - - - - - -|; + # get pricegroups for parts + IS->get_pricegroups_for_parts(\%myconfig, \%$form); - foreach $item (split / /, $form->{taxaccounts}) { - print qq| - - - -|; + # Problem: set_pricegroup resets the sellprice of old invoices to the price + # currently defined in the pricegroup, which is a problem if the price has + # changed, as the old invoice gets the new price + # set_pricegroup must never be called, when an old invoice is initially loaded + + # set_pricegroup($_) for 1 .. $form->{rowcount}; } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub form_header { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + my $cgi = $::request->{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 @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}; + $form->{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency}; + $TMPL_VAR{currencies} = NTI($::request->{cgi}->popup_menu('-name' => 'currency', '-default' => $form->{"currency"}, + '-values' => \@values, '-labels' => \%labels, + '-onchange' => "document.getElementById('update_button').click();" + )) 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->{fokus} = "invoice.customer"; -sub form_footer { - $lxdebug->enter_sub(); - - $form->{invtotal} = $form->{invsubtotal}; + my $follow_up_vc = $form->{customer}; + $follow_up_vc =~ s/--\d*\s*$//; + $TMPL_VAR{customer_name} = $follow_up_vc; - if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) { - $rows = 2; - } - if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) { - $introws = 2; +# 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}/; } - $rows = ($rows > $introws) ? $rows : $introws; - $notes = qq|$form->{notes}|; - $intnotes = qq|$form->{intnotes}|; - $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + $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}; - $taxincluded = ""; - if ($form->{taxaccounts}) { - $taxincluded = qq| - {taxincluded}> |.$locale->text('Tax Included').qq||; - } + # 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 shiptocp_gender 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}]; - if (!$form->{taxincluded}) { + $form->{jsscript} = 1; + $form->header(); - 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); + print $form->parse_html_template("is/form_header", \%TMPL_VAR); - $tax .= qq| - - $form->{"${item}_description"} - $form->{"${item}_total"} - -|; - } - } + $main::lxdebug->leave_sub(); +} - $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); +sub form_footer { + $main::lxdebug->enter_sub(); - $subtotal = qq| - - |.$locale->text('Subtotal').qq| - $form->{invsubtotal} - -|; + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - } - - 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"} - -|; - } - } - - - } - + $main::auth->assert('invoice_edit'); + $form->{invtotal} = $form->{invsubtotal}; $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| - - -|; + # note rows + $form->{rows} = max 2, + $form->numtextrows($form->{notes}, 26, 8), + $form->numtextrows($form->{intnotes}, 35, 8); -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); - } - - $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 " - -"; - - $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); - for $i (1 .. $form->{paidaccounts}) { - - print " - \n"; - - $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"}/; + # tax, total and subtotal calculations + my ($tax, $subtotal); + $form->{taxaccounts_array} = [ split / /, $form->{taxaccounts} ]; - # format amounts - $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"}|; + 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 { - $exchangerate = qq|{"exchangerate_$i"}>|; + $form->{"${item}_total"} = $form->round_amount( $form->{"${item}_base"} * $form->{"${item}_rate"}, 2); + $form->{invtotal} += $form->{"${item}_total"}; } } - - $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_options; - - - - print qq| - - - -|; - - - $invdate = $form->datetonum($form->{invdate}, \%myconfig); - $closedto = $form->datetonum($form->{closedto}, \%myconfig); + # follow ups if ($form->{id}) { - print qq| - - - - -|; + $form->{follow_ups} = FU->follow_ups('trans_id' => $form->{id}) || []; + $form->{follow_ups_unfinished} = ( sum map { $_->{due} * 1 } @{ $form->{follow_ups} } ) || 0; + } - if (!$form->{revtrans}) { - if (!$form->{locked}) { - print qq| - - -|; - } + # payments + my $totalpaid = 0; + $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); + $form->{paid_indices} = [ 1 .. $form->{paidaccounts} ]; + + # Standard Konto für Umlaufvermögen + my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form); + + for my $i (1 .. $form->{paidaccounts}) { + $form->{"changeable_$i"} = 1; + if ($::lx_office_conf{features}->{payments_changeable} == 0) { + # never + $form->{"changeable_$i"} = ($form->{"acc_trans_id_$i"})? 0 : 1; + } elsif ($::lx_office_conf{features}->{payments_changeable} == 2) { + # on the same day + $form->{"changeable_$i"} = (($form->{"gldate_$i"} eq '') || + ($form->current_date(\%myconfig) eq $form->{"gldate_$i"})); } - if ($invdate > $closedto) { - print qq| - - -|; + $form->{"selectAR_paid_$i"} = $form->{selectAR_paid}; + if (!$form->{"AR_paid_$i"}) { + $form->{"selectAR_paid_$i"} =~ s/option>$accno_arap--(.*?)$accno_arap--$1; + } else { + $form->{"selectAR_paid_$i"} =~ s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/; } - } else { - if ($invdate > $closedto) { - print qq| - - - - |; - } + $totalpaid += $form->{"paid_$i"}; } - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - 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(); +} -{rowcount}> +sub mark_as_paid { + $main::lxdebug->enter_sub(); - + my $form = $main::form; + my %myconfig = %main::myconfig; -{path}> -{login}> -{password}> + $main::auth->assert('invoice_edit'); - + &mark_as_paid_common(\%myconfig,"ar"); - + $main::lxdebug->leave_sub(); +} -