X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fis.pl;h=f44c5809cb008b3fea0c37b6275a18610e7bfce3;hb=6d169764351ba6f5bbf2a90f9d7a260617ab4070;hp=314f68bc1e28f290ded0330d3d195ed099842d68;hpb=6dce043fdd2d1f8104dbfb11b55823aab499fe01;p=kivitendo-erp.git diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 314f68bc1..f44c5809c 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -31,877 +31,462 @@ # #====================================================================== +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; + +my $edit; +my $print_post; 1; # end of main sub add { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->assert('invoice_edit'); - $form->{title} = $locale->text('Add Sales Invoice'); + return $main::lxdebug->leave_sub() if (load_draft_maybe()); - $form->{callback} = - "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}" - unless $form->{callback}; + if ($form->{type} eq "credit_note") { + $form->{title} = $locale->text('Add Credit Note'); - $form{jsscript} = "date"; + 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; - $form->{format} ="pdf"; - &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub edit { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; - $form->{title} = $locale->text('Edit Sales Invoice'); + $main::auth->assert('invoice_edit'); - if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR") - { - $form->error("Access Denied"); + # 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->{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; + $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes id shipto_id)); - # currencies - @curr = split /:/, $form->{currencies}; - chomp $curr[0]; - $form->{defaultcurrency} = $curr[0]; + IS->get_customer(\%myconfig, \%$form); - map { $form->{selectcurrency} .= "\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(); - $form->{type} = "invoice"; - $form->{formname} = "invoice"; - $form->{media} = "screen"; + my $form = $main::form; + my %myconfig = %main::myconfig; - if ($form->{id}) { + $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"; + } - map { $form->{$_} =~ s/\"/"/g } - qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes); + if ($form->{id}) { - # # get pricegroups for parts - # IS->get_pricegroups_for_parts(\%myconfig, \%$form); + 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; - $form->{"sellprice_$i"} = - $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, - $decimalplaces); + $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; - (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/); - $dec_qty = length $dec_qty; + $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); + (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/); + $dec_qty = length $dec_qty; - $form->{"qty_$i"} = - $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty); + $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty); - map { $form->{"${_}_$i"} =~ s/\"/"/g } - qw(partnumber description unit partnotes); - $form->{rowcount} = $i; + $form->{rowcount} = $i; } + + # get pricegroups for parts + IS->get_pricegroups_for_parts(\%myconfig, \%$form); + set_pricegroup($_) for 1 .. $form->{rowcount}; } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub form_header { - $lxdebug->enter_sub(); + $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'); + + our %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} =~ /-/; - # 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->{fokus} = "invoice.customer"; - #build contacts - if ($form->{all_contacts}) { + my $follow_up_vc = $form->{customer}; + $follow_up_vc =~ s/--\d*\s*$//; + $TMPL_VAR{customer_name} = $follow_up_vc; - $form->{selectcontact} = ""; - foreach $item (@{ $form->{all_contacts} }) { - if ($form->{cp_id} == $item->{cp_id}) { - $form->{selectcontact} .= - "|; - foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) { - $form->{"lizenzen_$i"} .= - qq||; + foreach my $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) { + $form->{"lizenzen_$i"} .= qq||; } - $form->{"lizenzen_$i"} .= - qq||; + $form->{"lizenzen_$i"} .= qq||; } } @@ -1007,27 +577,78 @@ sub update { && ($form->{"description_$i"} eq "")) { $form->{rowcount}--; $form->{"discount_$i"} = ""; - &display_form; - } else { + display_form(); + } else { $form->{"id_$i"} = 0; - $form->{"unit_$i"} = $locale->text('ea'); + new_item(); + } + } + } + $main::lxdebug->leave_sub(); +} + +sub post_payment { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('invoice_edit'); - &new_item; + our $invdate; + + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); + for my $i (1 .. $form->{paidaccounts}) { + if ($form->{"paid_$i"}) { + my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); + + $form->isblank("datepaid_$i", $locale->text('Payment date missing!')); + $form->error($locale->text('Cannot post payment for a closed period!')) + if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig)); + + if ($form->{currency} ne $form->{defaultcurrency}) { + $form->{"exchangerate_$i"} = $form->{exchangerate} + if ($invdate == $datepaid); + $form->isblank("exchangerate_$i", + $locale->text('Exchangerate for payment missing!')); } } } - $lxdebug->leave_sub(); + + ($form->{AR}) = split /--/, $form->{AR}; + ($form->{AR_paid}) = split /--/, $form->{AR_paid}; + relink_accounts(); + $form->redirect($locale->text('Payment posted!')) + if (IS->post_payment(\%myconfig, \%$form)); + $form->error($locale->text('Cannot post payment!')); + + + $main::lxdebug->leave_sub(); } sub post { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('invoice_edit'); + + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); $form->isblank("invdate", $locale->text('Invoice Date missing!')); $form->isblank("customer", $locale->text('Customer missing!')); + $form->error($locale->text('Cannot post invoice for a closed period!')) + if ($form->date_closed($form->{"invdate"}, \%myconfig)); + + $form->{invnumber} =~ s/^\s*//g; + $form->{invnumber} =~ s/\s*$//g; # if oldcustomer ne customer redo form - if (&check_name(customer)) { + if (&check_name('customer')) { &update; exit; } @@ -1035,10 +656,11 @@ sub post { $form->{print_and_post} = 0; } + remove_emptied_rows(); &validate_items; - $closedto = $form->datetonum($form->{closedto}, \%myconfig); - $invdate = $form->datetonum($form->{invdate}, \%myconfig); + my $closedto = $form->datetonum($form->{closedto}, \%myconfig); + my $invdate = $form->datetonum($form->{invdate}, \%myconfig); $form->error($locale->text('Cannot post invoice for a closed period!')) if ($invdate <= $closedto); @@ -1046,14 +668,14 @@ sub post { $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); - for $i (1 .. $form->{paidaccounts}) { - if ($form->{"paid_$i"}) { - $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); + for my $i (1 .. $form->{paidaccounts}) { + if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { + my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); $form->isblank("datepaid_$i", $locale->text('Payment date missing!')); $form->error($locale->text('Cannot post payment for a closed period!')) - if ($datepaid <= $closedto); + if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig)); if ($form->{currency} ne $form->{defaultcurrency}) { $form->{"exchangerate_$i"} = $form->{exchangerate} @@ -1064,59 +686,137 @@ sub post { } } - ($form->{AR}) = split /--/, $form->{AR}; - ($form->{AR_paid}) = split /--/, $form->{AR_paid}; + ($form->{AR}) = split /--/, $form->{AR}; + ($form->{AR_paid}) = split /--/, $form->{AR_paid}; + $form->{storno} ||= 0; $form->{label} = $locale->text('Invoice'); $form->{id} = 0 if $form->{postasnew}; # get new invnumber in sequence if no invnumber is given or if posasnew was requested - if (!$form->{invnumber} || $form->{postasnew}) { - $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber") - } - if ($print_post) { - if (!(IS->post_invoice(\%myconfig, \%$form))) { - $form->error($locale->text('Cannot post invoice!')); + if ($form->{postasnew}) { + if ($form->{type} eq "credit_note") { + undef($form->{cnnumber}); + } else { + undef($form->{invnumber}); } - } else { - $form->redirect( - $form->{label} . " $form->{invnumber} " . $locale->text('posted!')) - if (IS->post_invoice(\%myconfig, \%$form)); - $form->error($locale->text('Cannot post invoice!')); } - $lxdebug->leave_sub(); + relink_accounts(); + $form->error($locale->text('Cannot post invoice!')) + unless IS->post_invoice(\%myconfig, \%$form); + remove_draft() if $form->{remove_draft}; + + if(!exists $form->{addition}) { + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{addition} = $print_post ? "PRINTED AND POSTED" : + $form->{storno} ? "STORNO" : + "POSTED"; + $form->save_history($form->dbconnect(\%myconfig)); + } + + $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!')) + unless $print_post; + + $main::lxdebug->leave_sub(); } sub print_and_post { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; - $old_form = new Form; + $main::auth->assert('invoice_edit'); + + my $old_form = new Form; $print_post = 1; $form->{print_and_post} = 1; &post(); &edit(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub use_as_template { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('invoice_edit'); + + map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno); + $form->{paidaccounts} = 1; + $form->{rowcount}--; + $form->{invdate} = $form->current_date(\%myconfig); + &display_form; + + $main::lxdebug->leave_sub(); +} + +sub storno { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('invoice_edit'); + + if ($form->{storno}) { + $form->error($locale->text('Cannot storno storno invoice!')); + } + + if (IS->has_storno(\%myconfig, $form, "ar")) { + $form->error($locale->text("Invoice has already been storno'd!")); + } + + map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password stylesheet type))); } keys(%{ $form })); + + invoice_links(); + prepare_invoice(); + relink_accounts(); + + # Payments must not be recorded for the new storno invoice. + $form->{paidaccounts} = 0; + map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form }; + + $form->{storno_id} = $form->{id}; + $form->{storno} = 1; + $form->{id} = ""; + $form->{invnumber} = "Storno zu " . $form->{invnumber}; + $form->{rowcount}++; + + post(); + $main::lxdebug->leave_sub(); +} + sub preview { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + + $main::auth->assert('invoice_edit'); $form->{preview} = 1; - $old_form = new Form; + my $old_form = new Form; for (keys %$form) { $old_form->{$_} = $form->{$_} } - $old_form->{rowcount}++; &print_form($old_form); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub delete { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->assert('invoice_edit'); + if ($form->{second_run}) { $form->{print_and_post} = 0; } @@ -1125,19 +825,20 @@ sub delete { print qq| -
{script}> + |; # delete action variable map { delete $form->{$_} } qw(action header); - foreach $key (keys %$form) { + foreach my $key (keys %$form) { + next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key})); $form->{$key} =~ s/\"/"/g; - print qq|\n|; + print qq|\n|; } print qq| -

| . $locale->text('Confirm!') . qq|

+

| . $locale->text('Confirm!') . qq|

| . $locale->text('Are you sure you want to delete Invoice Number') @@ -1145,20 +846,119 @@ sub delete {

-

|; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); +} + +sub credit_note { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('invoice_edit'); + + $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig); + $form->{duedate} = + $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1); + + $form->{id} = ''; + $form->{rowcount}--; + $form->{shipto} = 1; + + + $form->{title} = $locale->text('Add Credit Note'); + $form->{script} = 'is.pl'; + our $script = "is"; + our $buysell = 'buy'; + + + # bo creates the id, reset it + map { delete $form->{$_} } + qw(id invnumber subject message cc bcc printed emailed queued); + $form->{ $form->{vc} } =~ s/--.*//g; + $form->{type} = "credit_note"; + + + map { $form->{"select$_"} = "" } ($form->{vc}, 'currency'); + +# map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } +# qw(creditlimit creditremaining); + + my $currency = $form->{currency}; + &invoice_links; + + $form->{currency} = $currency; + $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, $buysell); + $form->{exchangerate} = $form->{forex} || ''; + + $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal}); + + # bei Gutschriften werden Zahlungseingänge aus Rechnung nicht übernommen + for my $i (1 .. $form->{paidaccounts}) { + delete $form->{"paid_$i"}; + delete $form->{"source_$i"}; + delete $form->{"memo_$i"}; + delete $form->{"datepaid_$i"}; + delete $form->{"AR_paid_$i"}; + }; + $form->{paidaccounts} = 1; + + &prepare_invoice; + + + &display_form; + + $main::lxdebug->leave_sub(); } sub yes { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $form->redirect($locale->text('Invoice deleted!')) - if (IS->delete_invoice(\%myconfig, \%$form, $spool)); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('invoice_edit'); + + if (IS->delete_invoice(\%myconfig, \%$form, $main::spool)) { + # saving the history + if(!exists $form->{addition}) { + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{addition} = "DELETED"; + $form->save_history($form->dbconnect(\%myconfig)); + } + # /saving the history + $form->redirect($locale->text('Invoice deleted!')); + } $form->error($locale->text('Cannot delete invoice!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); +} + +sub e_mail { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + + $main::auth->assert('invoice_edit'); + + if (!$form->{id}) { + $print_post = 1; + + my $saved_form = save_form(); + + post(); + + restore_form($saved_form, 0, qw(id invnumber)); + } + + edit_e_mail(); + + $main::lxdebug->leave_sub(); }