X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=bin%2Fmozilla%2Fir.pl;h=e5b698db83cfb9b08f0fff5336e10ce0a6487736;hb=e9e216f571e214e1d19c43a2b47f04525f4aaddf;hp=264100e743b151ccd980ae0ee008b301bca22668;hpb=0bb0eb67db98f28ec8faf8dfe8c233268332f842;p=kivitendo-erp.git diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 264100e74..e5b698db8 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -32,10 +32,13 @@ #====================================================================== use SL::IR; +use SL::IS; use SL::PE; -require "$form->{path}/io.pl"; -require "$form->{path}/arap.pl"; +require "bin/mozilla/io.pl"; +require "bin/mozilla/arap.pl"; +require "bin/mozilla/common.pl"; +require "bin/mozilla/drafts.pl"; 1; @@ -44,6 +47,8 @@ require "$form->{path}/arap.pl"; sub add { $lxdebug->enter_sub(); + return $lxdebug->leave_sub() if (load_draft_maybe()); + $form->{title} = $locale->text('Add Vendor Invoice'); &invoice_links; @@ -55,7 +60,11 @@ sub add { sub edit { $lxdebug->enter_sub(); - + + # show history button + $form->{javascript} = qq||; + #/show hhistory button + $form->{title} = $locale->text('Edit Vendor Invoice'); &invoice_links; @@ -76,28 +85,47 @@ sub invoice_links { $form->create_links("AP", \%myconfig, "vendor"); + #quote all_vendor Bug 133 + foreach $ref (@{ $form->{all_vendor} }) { + $ref->{name} = $form->quote($ref->{name}); + } + if ($form->{all_vendor}) { unless ($form->{vendor_id}) { $form->{vendor_id} = $form->{all_vendor}->[0]->{id}; } } + if ($form->{payment_id}) { + $payment_id = $form->{payment_id}; + } + if ($form->{language_id}) { + $language_id = $form->{language_id}; + } + if ($form->{taxzone_id}) { + $taxzone_id = $form->{taxzone_id}; + } $cp_id = $form->{cp_id}; IR->get_vendor(\%myconfig, \%$form); IR->retrieve_invoice(\%myconfig, \%$form); $form->{cp_id} = $cp_id; - - # currencies - @curr = split /:/, $form->{currencies}; - chomp $curr[0]; - $form->{defaultcurrency} = $curr[0]; + + if ($payment_id) { + $form->{payment_id} = $payment_id; + } + if ($language_id) { + $form->{language_id} = $language_id; + } + if ($taxzone_id) { + $form->{taxzone_id} = $taxzone_id; + } map { $form->{selectcurrency} .= "$_\n" } @curr; $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}"; # vendors - if ($form->{all_vendor}) { + if (@{ $form->{all_vendor} }) { $form->{vendor} = "$form->{vendor}--$form->{vendor_id}"; map { $form->{selectvendor} .= "$_->{name}--$_->{id}\n" } (@{ $form->{all_vendor} }); @@ -165,6 +193,7 @@ sub prepare_invoice { map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber); + my $i = 0; foreach $ref (@{ $form->{invoice_details} }) { $i++; map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref}; @@ -194,12 +223,21 @@ sub form_header { $lxdebug->enter_sub(); # set option selected - foreach $item (qw(AP vendor currency department contact)) { + foreach $item (qw(AP vendor currency department)) { $form->{"select$item"} =~ s/ selected//; $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; } + $form->{radier} = + ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0; + + #quote selectvendor Bug 133 + $form->{"selectvendor"} = $form->quote($form->{"selectvendor"}); + + #substitute \n and \r to \s (bug 543) + $form->{"selectvendor"} =~ s/[\n\r]/ /g; + $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); @@ -208,20 +246,6 @@ sub form_header { $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); - #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}"; - } - } - } - $exchangerate = ""; if ($form->{currency} ne $form->{defaultcurrency}) { if ($form->{forex}) { @@ -242,21 +266,123 @@ sub form_header { {forex}> |; - $vendor = - ($form->{selectvendor}) - ? qq|$form->{selectvendor}\n| - : qq||; + 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", + "projects" => { "key" => "ALL_PROJECTS", + "all" => 0, + "old_id" => \@old_project_ids }, + "taxzones" => "ALL_TAXZONES", + "employees" => "ALL_SALESMEN", + "currencies" => "ALL_CURRENCIES", + "vendors" => "ALL_VENDORS"); + + my %labels; + my @values = (undef); + foreach my $item (@{ $form->{"ALL_CONTACTS"} }) { + push(@values, $item->{"cp_id"}); + $labels{$item->{"cp_id"}} = $item->{"cp_name"} . + ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : ""); + } + my $contact = + NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, + '-labels' => \%labels, '-default' => $form->{"cp_id"})); + + %labels = (); + @values = (""); + foreach my $item (@{ $form->{"ALL_PROJECTS"} }) { + push(@values, $item->{"id"}); + $labels{$item->{"id"}} = $item->{"projectnumber"}; + } + my $globalprojectnumber = + NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values, + '-labels' => \%labels, + '-default' => $form->{"globalproject_id"})); + + %labels = (); + @values = (); + my $i = 0; + foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) { + push(@values, $item); + $labels{$item} = $item; + } + + $form->{currency} = $form->{defaultcurrency} unless $form->{currency}; + my $currencies = qq| + + | . $locale->text('Currency') . qq| + | . + NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"}, + '-values' => \@values, '-labels' => \%labels)) . qq| + + |; + + %labels = (); + @values = (); + my $i = 0; + foreach my $item (@{ $form->{"ALL_SALESMEN"} }) { + push(@values, $item->{"id"}); + $labels{$item->{"id"}} = $item->{"name"}; + } + my $employees = qq| + + | . $locale->text('Employee') . qq| + | . + NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"}, + '-values' => \@values, '-labels' => \%labels)) . qq| + + |; + + %labels = (); + @values = (); + my $i = 0; + foreach my $item (@{ $form->{"ALL_VENDORS"} }) { + push(@values, $item->{name}.qq|--|.$item->{"id"}); + $labels{$item->{"id"}} = $item->{"name"}.qq|--|.$item->{"id"}; + } + my $vendors = qq| + | . $locale->text('Vendor') . qq| + | . + NTI($cgi->popup_menu('-name' => 'vendor', '-default' => $form->{"vendor"}, + '-onChange' => 'document.getElementById(\'update_button\').click();', + '-values' => \@values, '-labels' => \%labels)) . qq| + |; + + %labels = (); + @values = (); + foreach my $item (@{ $form->{"ALL_TAXZONES"} }) { + push(@values, $item->{"id"}); + $labels{$item->{"id"}} = $item->{"description"}; + } - $contact = - ($form->{selectcontact}) - ? qq|$form->{selectcontact}\n| - : qq||; + if (!$form->{"id"}) { + $taxzone = qq| + + | . $locale->text('Steuersatz') . qq| + | . + NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"}, + '-values' => \@values, '-labels' => \%labels)) . qq| + + |; + + } else { + $taxzone = qq| + + | . $locale->text('Steuersatz') . qq| + + + | . H($labels{$form->{"taxzone_id"}}) . qq| + + |; + } $department = qq| | . $locale->text('Department') . qq| - $form->{selectdepartment} - + $form->{selectdepartment} + | if $form->{selectdepartment}; @@ -270,12 +396,12 @@ sub form_header { # with JavaScript Calendar $button1 = qq| - {invdate}> + text('button') . qq|> |; $button2 = qq| - {duedate}> + text('button') . qq|> |; @@ -288,15 +414,25 @@ sub form_header { # without JavaScript Calendar $button1 = - qq|{invdate}>|; + qq||; $button2 = - qq|{duedate}>|; + qq||; } - $form->header; + $form->{"javascript"} .= qq||; + $form->{"javascript"} .= qq||; + $jsscript .= + $form->write_trigger(\%myconfig, 2, + "orddate", "BL", "trigger_orddate", + "quodate", "BL", "trigger_quodate"); + + $form->header; + $onload = qq|focus()|; + $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|; + $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|; print qq| - + {script}> @@ -313,7 +449,10 @@ sub form_header { {locked}> {shipped}> +{storno}> +{storno_id}> +| . ($form->{saved_message} ? qq|$form->{saved_message}| : "") . qq| @@ -327,20 +466,18 @@ sub form_header { - | . $locale->text('Vendor') . qq| - $vendor - + $vendors | . $locale->text('Contact Person') . qq| $contact - {vendor_id}> - - + + + - + | . $locale->text('Credit Limit') . qq| @@ -350,23 +487,24 @@ sub form_header { $form->{creditremaining} - + - | . $locale->text('Record in') . qq| - $form->{selectAP} - + | . $locale->text('Record in') . qq| + $form->{selectAP} + + $taxzone $department - | . $locale->text('Currency') . qq| - $form->{selectcurrency} + $currencies $exchangerate - + $employees + | . $locale->text('Invoice Number') . qq| @@ -383,7 +521,21 @@ sub form_header { - + + | . $locale->text('Order Date') . qq| + + + + + | . $locale->text('Quotation Date') . qq| + + + + + | . $locale->text('Project Number') . qq| + $globalprojectnumber + + @@ -392,8 +544,6 @@ sub form_header { $jsscript - -{defaultcurrency}> {fxgain_accno}> {fxloss_accno}> @@ -454,7 +604,8 @@ sub form_footer { $tax .= qq| - $form->{"${item}_description"} + $form->{"${item}_description"} | + . $form->{"${item}_rate"} * 100 .qq|% $form->{"${item}_total"} |; @@ -495,7 +646,8 @@ sub form_footer { $tax .= qq| - Enthaltene $form->{"${item}_description"} + Enthaltene $form->{"${item}_description"} | + . $form->{"${item}_rate"} * 100 .qq|% $form->{"${item}_total"} @@ -535,7 +687,7 @@ sub form_footer { $subtotal $tax - 0 + | . $locale->text('Total') . qq| $form->{invtotal} @@ -606,6 +758,7 @@ sub form_footer { |; + my @triggers = (); $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); for $i (1 .. $form->{paidaccounts}) { @@ -618,8 +771,10 @@ sub form_footer { s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/; # format amounts - $form->{"paid_$i"} = - $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2); + if ($form->{"paid_$i"}) { + $form->{"paid_$i"} = + $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2); + } $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); @@ -638,12 +793,13 @@ sub form_footer { |; $column_data{"paid_$i"} = - qq|{"paid_$i"}>|; + qq||; $column_data{"exchangerate_$i"} = qq|$exchangerate|; $column_data{"AP_paid_$i"} = qq|$form->{"selectAP_paid_$i"}|; $column_data{"datepaid_$i"} = - qq|{"datepaid_$i"}>|; + qq| + |; $column_data{"source_$i"} = qq|{"source_$i"}>|; $column_data{"memo_$i"} = @@ -654,6 +810,7 @@ sub form_footer { print qq| |; + push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i"); } print qq| @@ -674,55 +831,51 @@ sub form_footer { $closedto = $form->datetonum($form->{closedto}, \%myconfig); if ($form->{id}) { - print qq| -|; + my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap"); - if (!$form->{revtrans}) { - if (!$form->{locked}) { - print qq| - - + print qq| |; - } - } - - if ($invdate > $closedto) { - print qq| - - + print qq| +| if ($show_storno); + if ($form->{radier}) { + print qq| + |; - } - - } else { - if ($invdate > $closedto) { - print qq| - |; - } } + print qq| +|; - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; } - print qq| + print qq||; -{rowcount}> + if (!$form->{id} && ($invdate > $closedto)) { + print qq| | . + NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), + '-class' => 'submit')); + } - + print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers); + $form->hide_form(qw(rowcount callback draft_id draft_description login password)); -{path}> -{login}> -{password}> + # button for saving history + if($form->{id} ne "") { + print qq| + |; + } + # /button for saving history - +print qq| @@ -739,8 +892,6 @@ sub update { &check_name(vendor); - &check_project; - $form->{exchangerate} = $exchangerate if ( $form->{forex} = ( @@ -767,7 +918,7 @@ sub update { } $i = $form->{rowcount}; - $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; + $exchangerate = ($form->{exchangerate} * 1) ? $form->{exchangerate} * 1 : 1; if ( ($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") @@ -775,7 +926,7 @@ sub update { $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid}); &check_form; - } else { + } else { IR->retrieve_item(\%myconfig, \%$form); @@ -851,12 +1002,106 @@ sub update { $lxdebug->leave_sub(); } +sub storno { + $lxdebug->enter_sub(); + + if ($form->{storno}) { + $form->error($locale->text('Cannot storno storno invoice!')); + } + + if (IS->has_storno(\%myconfig, $form, "ap")) { + $form->error($locale->text("Invoice has already been storno'd!")); + } + + my $employee_id = $form->{employee_id}; + 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 }; + + # saving the history + if(!exists $form->{addition} && $form->{id} ne "") { + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{addition} = "CANCELED"; + $form->save_history($form->dbconnect(\%myconfig)); + } + # /saving the history + + $form->{storno_id} = $form->{id}; + $form->{storno} = 1; + $form->{id} = ""; + $form->{invnumber} = "Storno zu " . $form->{invnumber}; + $form->{rowcount}++; + $form->{employee_id} = $employee_id; + post(); + $lxdebug->leave_sub(); + +} + +sub use_as_template { + $lxdebug->enter_sub(); + + 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; + + $lxdebug->leave_sub(); +} + +sub post_payment { + $lxdebug->enter_sub(); + for $i (1 .. $form->{paidaccounts}) { + if ($form->{"paid_$i"}) { + $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->{currency} ne $form->{defaultcurrency}) { + $form->{"exchangerate_$i"} = $form->{exchangerate} + if ($invdate == $datepaid); + $form->isblank("exchangerate_$i", + $locale->text('Exchangerate for payment missing!')); + } + } + } + + ($form->{AP}) = split /--/, $form->{AP}; + ($form->{AP_paid}) = split /--/, $form->{AP_paid}; + if (IR->post_payment(\%myconfig, \%$form)){ + + if(!exists $form->{addition} && $form->{id} ne "") { + # saving the history + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{addition} = "PAYMENT POSTED"; + $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED"); + $form->save_history($form->dbconnect(\%myconfig)); + # /saving the history + $form->redirect($locale->text(' Payment posted!')); + } + } + $form->error($locale->text('Cannot post payment!')); + + + $lxdebug->leave_sub(); +} + sub post { $lxdebug->enter_sub(); $form->isblank("invdate", $locale->text('Invoice Date missing!')); $form->isblank("vendor", $locale->text('Vendor missing!')); + $form->{invnumber} =~ s/^\s*//g; + $form->{invnumber} =~ s/\s*$//g; + # if the vendor changed get new values if (&check_name(vendor)) { &update; @@ -875,7 +1120,7 @@ sub post { if ($form->{currency} ne $form->{defaultcurrency}); for $i (1 .. $form->{paidaccounts}) { - if ($form->{"paid_$i"}) { + if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); $form->isblank("datepaid_$i", $locale->text('Payment date missing!')); @@ -897,10 +1142,22 @@ sub post { $form->{id} = 0 if $form->{postasnew}; - $form->redirect( $locale->text('Invoice') + + relink_accounts(); + if (IR->post_invoice(\%myconfig, \%$form)){ + # saving the history + if(!exists $form->{addition} && $form->{id} ne "") { + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{addition} = "POSTED"; + #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber}; + $form->save_history($form->dbconnect(\%myconfig)); + } + # /saving the history + remove_draft() if $form->{remove_draft}; + $form->redirect( $locale->text('Invoice') . " $form->{invnumber} " - . $locale->text('posted!')) - if (IR->post_invoice(\%myconfig, \%$form)); + . $locale->text('posted!')); + } $form->error($locale->text('Cannot post invoice!')); $lxdebug->leave_sub(); @@ -910,7 +1167,6 @@ sub delete { $lxdebug->enter_sub(); $form->header; - print qq| @@ -942,9 +1198,16 @@ sub delete { sub yes { $lxdebug->enter_sub(); - - $form->redirect($locale->text('Invoice deleted!')) - if (IR->delete_invoice(\%myconfig, \%$form)); + if (IR->delete_invoice(\%myconfig, \%$form)) { + # 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();
$form->{saved_message}