X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=bin%2Fmozilla%2Fir.pl;h=284b2fe5d4fe2f105105d107371fa457d99877b5;hb=2fda509c7dc417aad28ed072e91e8ffe2396314d;hp=caa8a0e6d511c2dbd70931afccb2d7adbbb583b9;hpb=07d71c33315605fcfc450d3b9abf0fd10e92bed5;p=kivitendo-erp.git diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index caa8a0e6d..284b2fe5d 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; @@ -43,7 +46,9 @@ require "$form->{path}/arap.pl"; sub add { $lxdebug->enter_sub(); -print STDERR "ir.pl-add\n"; + + return $lxdebug->leave_sub() if (load_draft_maybe()); + $form->{title} = $locale->text('Add Vendor Invoice'); &invoice_links; @@ -55,7 +60,11 @@ print STDERR "ir.pl-add\n"; sub edit { $lxdebug->enter_sub(); - + + # show history button + $form->{javascript} = qq||; + #/show hhistory button + $form->{title} = $locale->text('Edit Vendor Invoice'); &invoice_links; @@ -67,7 +76,7 @@ sub edit { sub invoice_links { $lxdebug->enter_sub(); -print STDERR "ir.pl-invoice_links\n"; + # create links $form->{webdav} = $webdav; @@ -76,28 +85,47 @@ print STDERR "ir.pl-invoice_links\n"; $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} }); @@ -160,11 +188,12 @@ print STDERR "ir.pl-invoice_links\n"; sub prepare_invoice { $lxdebug->enter_sub(); -print STDERR "ir.pl-prepare_invoice\n"; + if ($form->{id}) { map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber); + my $i = 0; foreach $ref (@{ $form->{invoice_details} }) { $i++; map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref}; @@ -176,8 +205,12 @@ print STDERR "ir.pl-prepare_invoice\n"; $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"} * -1)); + $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty); $form->{rowcount} = $i; } @@ -188,14 +221,23 @@ print STDERR "ir.pl-prepare_invoice\n"; sub form_header { $lxdebug->enter_sub(); -print STDERR "ir.pl-form_header\n"; + # set option selected - foreach $item (qw(AP vendor currency department contact)) { + foreach $item (qw(AP vendor currency department employee)) { $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}); @@ -204,34 +246,18 @@ print STDERR "ir.pl-form_header\n"; $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}) { $exchangerate .= qq| | - . $locale->text('Exchangerate') - . qq| + . $locale->text('Exchangerate') . qq| $form->{exchangerate}{exchangerate}> |; } else { $exchangerate .= qq| | - . $locale->text('Exchangerate') - . qq| + . $locale->text('Exchangerate') . qq| {exchangerate}> |; } @@ -240,21 +266,123 @@ print STDERR "ir.pl-form_header\n"; {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', '-default' => $form->{"employee"}, + '-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"}; + } + + 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| + + |; - $contact = - ($form->{selectcontact}) - ? qq|$form->{selectcontact}\n| - : 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}; @@ -268,16 +396,14 @@ print STDERR "ir.pl-form_header\n"; # with JavaScript Calendar $button1 = qq| - {invdate}> + text('button') - . qq|> + . $locale->text('button') . qq|> |; $button2 = qq| - {duedate}> + text('button') - . qq|> + . $locale->text('button') . qq|> |; #write Trigger @@ -288,15 +414,25 @@ print STDERR "ir.pl-form_header\n"; # 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 @@ print STDERR "ir.pl-form_header\n"; {locked}> {shipped}> +{storno}> +{storno_id}> +| . ($form->{saved_message} ? qq|$form->{saved_message}| : "") . qq| @@ -327,21 +466,18 @@ print STDERR "ir.pl-form_header\n"; - | . $locale->text('Vendor') . qq| - $vendor - + $vendors | - . $locale->text('Contact Person') - . qq| + . $locale->text('Contact Person') . qq| $contact - {vendor_id}> - - + + + - + | . $locale->text('Credit Limit') . qq| @@ -351,23 +487,24 @@ print STDERR "ir.pl-form_header\n"; $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| @@ -384,7 +521,21 @@ print STDERR "ir.pl-form_header\n"; - + + | . $locale->text('Order Date') . qq| + + + + + | . $locale->text('Quotation Date') . qq| + + + + + | . $locale->text('Project Number') . qq| + $globalprojectnumber + + @@ -393,8 +544,6 @@ print STDERR "ir.pl-form_header\n"; $jsscript - -{defaultcurrency}> {fxgain_accno}> {fxloss_accno}> @@ -417,7 +566,7 @@ $jsscript sub form_footer { $lxdebug->enter_sub(); -print STDERR "ir.pl-form_footer\n"; + $form->{invtotal} = $form->{invsubtotal}; if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) { @@ -455,7 +604,8 @@ print STDERR "ir.pl-form_footer\n"; $tax .= qq| - $form->{"${item}_description"} + $form->{"${item}_description"} | + . $form->{"${item}_rate"} * 100 .qq|% $form->{"${item}_total"} |; @@ -496,7 +646,8 @@ print STDERR "ir.pl-form_footer\n"; $tax .= qq| - Enthaltene $form->{"${item}_description"} + Enthaltene $form->{"${item}_description"} | + . $form->{"${item}_rate"} * 100 .qq|% $form->{"${item}_total"} @@ -536,7 +687,7 @@ print STDERR "ir.pl-form_footer\n"; $subtotal $tax - 0 + | . $locale->text('Total') . qq| $form->{invtotal} @@ -607,6 +758,7 @@ print STDERR "ir.pl-form_footer\n"; |; + my @triggers = (); $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); for $i (1 .. $form->{paidaccounts}) { @@ -619,8 +771,10 @@ print STDERR "ir.pl-form_footer\n"; 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"}); @@ -639,12 +793,13 @@ print STDERR "ir.pl-form_footer\n"; |; $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"} = @@ -655,6 +810,7 @@ print STDERR "ir.pl-form_footer\n"; print qq| |; + push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i"); } print qq| @@ -675,55 +831,51 @@ print STDERR "ir.pl-form_footer\n"; $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| @@ -740,8 +892,6 @@ sub update { &check_name(vendor); - &check_project; - $form->{exchangerate} = $exchangerate if ( $form->{forex} = ( @@ -768,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 "") @@ -776,7 +926,7 @@ sub update { $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid}); &check_form; - } else { + } else { IR->retrieve_item(\%myconfig, \%$form); @@ -823,7 +973,7 @@ sub update { $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); $form->{"qty_$i"} = - $form->format_amount(\%myconfig, $form->{"qty_$i"}); + $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty); } &display_form; @@ -852,6 +1002,91 @@ 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!")); + } + + invoice_links(); + prepare_invoice(); + relink_accounts(); + + # 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}++; + &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(); @@ -876,7 +1111,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!')); @@ -898,10 +1133,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(); @@ -911,7 +1158,6 @@ sub delete { $lxdebug->enter_sub(); $form->header; - print qq| @@ -943,9 +1189,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}