X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Foe.pl;h=8f42a067b7d48b73a3420dc453bdfe86e068f5d3;hb=3b9c2119792ae678e9368a0141d7f8646fd6ef42;hp=de1722e60db0e26cc8a8ec7f41f4d11a3f6e8bee;hpb=8c7e44938a661e035f62840e1e177353240ace5d;p=kivitendo-erp.git
diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl
index de1722e60..8f42a067b 100644
--- a/bin/mozilla/oe.pl
+++ b/bin/mozilla/oe.pl
@@ -31,19 +31,32 @@
# Quotation module
#======================================================================
+
+use Carp;
use POSIX qw(strftime);
+use SL::DO;
+use SL::FU;
use SL::OE;
use SL::IR;
use SL::IS;
+use SL::MoreCommon qw(ary_diff);
use SL::PE;
use SL::ReportGenerator;
-use List::Util qw(max reduce);
+use List::MoreUtils qw(any none);
+use List::Util qw(min max reduce sum);
+use Data::Dumper;
+
+use SL::DB::Customer;
require "bin/mozilla/io.pl";
require "bin/mozilla/arap.pl";
require "bin/mozilla/reportgenerator.pl";
+use strict;
+
+our %TMPL_VAR;
+
1;
# end of main
@@ -67,14 +80,19 @@ my $oe_access_map = {
};
sub check_oe_access {
+ my $form = $main::form;
+
my $right = $oe_access_map->{$form->{type}};
$right ||= 'DOES_NOT_EXIST';
- $auth->assert($right);
+ $main::auth->assert($right);
}
sub set_headings {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my $locale = $main::locale;
check_oe_access();
@@ -109,11 +127,13 @@ sub set_headings {
$form->{vc} = 'customer';
}
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub add {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
check_oe_access();
@@ -127,14 +147,18 @@ sub add {
&prepare_order;
&display_form;
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub edit {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
check_oe_access();
+ $form->{taxincluded_changed_by_user} = 1;
+
# show history button
$form->{javascript} = qq||;
#/show hhistory button
@@ -145,23 +169,26 @@ sub edit {
# editing without stuff to edit? try adding it first
if ($form->{rowcount} && !$form->{print_and_save}) {
+ my $id;
map { $id++ if $form->{"multi_id_$_"} } (1 .. $form->{rowcount});
if (!$id) {
# reset rowcount
undef $form->{rowcount};
&add;
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
return;
}
} elsif (!$form->{id}) {
&add;
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
return;
}
+ my ($language_id, $printer_id);
if ($form->{print_and_save}) {
- $form->{action} = "print";
+ $form->{action} = "dispatcher";
+ $form->{action_print} = "1";
$form->{resubmit} = 1;
$language_id = $form->{language_id};
$printer_id = $form->{printer_id};
@@ -170,18 +197,31 @@ sub edit {
set_headings("edit");
&order_links;
+
+ $form->{rowcount} = 0;
+ foreach my $ref (@{ $form->{form_details} }) {
+ $form->{rowcount}++;
+ map { $form->{"${_}_$form->{rowcount}"} = $ref->{$_} } keys %{$ref};
+ }
+
&prepare_order;
+
if ($form->{print_and_save}) {
$form->{language_id} = $language_id;
$form->{printer_id} = $printer_id;
}
+
&display_form;
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub order_links {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
check_oe_access();
@@ -189,217 +229,135 @@ sub order_links {
$form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
# retrieve order/quotation
- $form->{webdav} = $webdav;
- $form->{jsscript} = 1;
+ $form->{webdav} = $::instance_conf->get_webdav;
my $editing = $form->{id};
OE->retrieve(\%myconfig, \%$form);
- 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};
- }
-
- $salesman_id = $form->{salesman_id} if ($editing);
-
-
# if multiple rowcounts (== collective order) then check if the
# there were more than one customer (in that case OE::retrieve removes
# the content from the field)
- if ( $form->{rowcount}
- && $form->{type} eq 'sales_order'
- && defined $form->{customer}
- && $form->{customer} eq '') {
-
- # $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
- $form->error(
- $locale->text(
- 'Collective Orders only work for orders from one customer!')
- );
- }
+ $form->error($locale->text('Collective Orders only work for orders from one customer!'))
+ if $form->{rowcount} && $form->{type} eq 'sales_order'
+ && defined $form->{customer} && $form->{customer} eq '';
- $taxincluded = $form->{taxincluded};
- $form->{shipto} = 1 if $form->{id};
-
- if ($form->{"all_$form->{vc}"}) {
- unless ($form->{"$form->{vc}_id"}) {
- $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
- }
- }
+ $form->{"$form->{vc}_id"} ||= $form->{"all_$form->{vc}"}->[0]->{id} if $form->{"all_$form->{vc}"};
- $cp_id = $form->{cp_id};
- $intnotes = $form->{intnotes};
+ $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes shipto_id currency));
+ $form->{shipto} = 1 if $form->{id} || $form->{convert_from_oe_ids};
# get customer / vendor
- if ($form->{type} =~ /(purchase_order|request_quotation)/) {
- IR->get_vendor(\%myconfig, \%$form);
+ IR->get_vendor(\%myconfig, \%$form) if $form->{type} =~ /(purchase_order|request_quotation)/;
+ IS->get_customer(\%myconfig, \%$form) if $form->{type} =~ /sales_(order|quotation)/;
- #quote all_vendor Bug 133
- foreach $ref (@{ $form->{all_vendor} }) {
- $ref->{name} = $form->quote($ref->{name});
- }
+ $form->restore_vars(qw(payment_id language_id taxzone_id intnotes cp_id shipto_id));
+ $form->restore_vars(qw(currency)) if $form->{id};
+ $form->restore_vars(qw(taxincluded)) if $form->{id};
+ $form->restore_vars(qw(salesman_id)) if $editing;
+ $form->{forex} = $form->{exchangerate};
+ $form->{employee} = "$form->{employee}--$form->{employee_id}";
+ # build vendor/customer drop down comatibility... don't ask
+ if (@{ $form->{"all_$form->{vc}"} || [] }) {
+ $form->{"select$form->{vc}"} = 1;
+ $form->{$form->{vc}} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
}
- if ($form->{type} =~ /sales_(order|quotation)/) {
- IS->get_customer(\%myconfig, \%$form);
-
- #quote all_vendor Bug 133
- foreach $ref (@{ $form->{all_customer} }) {
- $ref->{name} = $form->quote($ref->{name});
- }
- }
- $form->{cp_id} = $cp_id;
+ $form->{"old$form->{vc}"} = $form->{$form->{vc}};
- if ($payment_id) {
- $form->{payment_id} = $payment_id;
- }
- if ($language_id) {
- $form->{language_id} = $language_id;
+ if ($form->{"old$form->{vc}"} !~ m/--\d+$/ && $form->{"$form->{vc}_id"}) {
+ $form->{"old$form->{vc}"} .= qq|--$form->{"$form->{vc}_id"}|
}
- if ($taxzone_id) {
- $form->{taxzone_id} = $taxzone_id;
- }
- $form->{intnotes} = $intnotes if $intnotes;
- ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
- $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
-
- # build the popup menus
- if (@{ $form->{"all_$form->{vc}"} }) {
- $form->{ $form->{vc} } =
- qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
- map { $form->{"select$form->{vc}"} .=
-"\n" }
- (@{ $form->{"all_$form->{vc}"} });
- }
-
- $form->{taxincluded} = $taxincluded if ($form->{id});
-
- # departments
- if (@{ $form->{all_departments} }) {
- $form->{selectdepartment} = "\n"
- } @{ $form->{all_departments} };
- }
-
- $form->{employee} = "$form->{employee}--$form->{employee_id}";
-
- # forex
- $form->{forex} = $form->{exchangerate};
-
- $form->{salesman_id} = $salesman_id if ($editing);
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub prepare_order {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
check_oe_access();
- $form->{formname} = $form->{type} unless $form->{formname};
+ $form->{formname} ||= $form->{type};
+
+ # format discounts if values come from db. either as single id, or as a collective order
+ my $format_discounts = $form->{id} || $form->{convert_from_oe_ids};
- my $i = 0;
- foreach $ref (@{ $form->{form_details} }) {
- $form->{rowcount} = ++$i;
- map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
- }
for my $i (1 .. $form->{rowcount}) {
- $form->{"reqdate_$i"} = $form->{"deliverydate_$i"} unless $form->{"reqdate_$i"};
- $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * ($form->{id} ? 100 : 1));
+ $form->{"reqdate_$i"} ||= $form->{"deliverydate_$i"};
+ $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * ($format_discounts ? 100 : 1));
$form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
+ $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"});
$form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
- map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit);
}
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub form_header {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
my @custom_hiddens;
- check_oe_access();
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+ my $cgi = $::request->{cgi};
- # Container for template variables. Unfortunately this has to be visible in form_footer too, so not my.
- our %TMPL_VAR = ();
+ check_oe_access();
- $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
- $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
+ # Container for template variables. Unfortunately this has to be
+ # visible in form_footer too, so package local level and not my here.
+ %TMPL_VAR = ();
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
$form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
$form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
- map { $form->{$_} = H($form->{$_}) }
- qw(shippingpoint shipvia notes intnotes shiptoname
- shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
- shiptophone shiptofax shiptodepartment_1 shiptodepartment_2);
-
- # use JavaScript Calendar or not
- $form->{jsscript} = 1;
- $TMPL_VAR{button1} = qq|
-
- text('button') . qq|> |
- |;
- $TMPL_VAR{button2} = qq|
-
- text('button') . qq|> |
- |;
- #write Trigger
- $TMPL_VAR{jsscript} = Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1", "reqdate", "BL", "trigger2");
-
# openclosed checkboxes
my @tmp;
push @tmp, sprintf qq||,
- $form->{"delivered"} ? "checked" : "", $locale->text('Delivered') if $form->{"type"} =~ /_order$/;
+ $form->{"delivered"} ? "checked" : "", $locale->text('Delivery Order created') if $form->{"type"} =~ /_order$/;
push @tmp, sprintf qq||,
$form->{"closed"} ? "checked" : "", $locale->text('Closed') if $form->{id};
$TMPL_VAR{openclosed} = sprintf qq|%s |
\n|, 2 * scalar @tmp, join "\n", @tmp if @tmp;
- # set option selected
- foreach $item ($form->{vc}, 'currency', 'department', ($form->{vc} eq "customer" ? 'customer' : 'vendor')) {
- $form->{"select$item"} =~ s/ selected//;
- $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
- }
-
- #quote select[customer|vendor] Bug 133
- $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
-
- #substitute \n and \r to \s (bug 543)
- $form->{"select$form->{vc}"} =~ s/[\n\r]/ /g;
-
+ # project ids
my @old_project_ids = ($form->{"globalproject_id"}, grep { $_ } map { $form->{"project_id_$_"} } 1..$form->{"rowcount"});
my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
- $form->get_lists("contacts" => "ALL_CONTACTS",
- "shipto" => "ALL_SHIPTO",
- "projects" => { "key" => "ALL_PROJECTS",
+ $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
"all" => 0,
"old_id" => \@old_project_ids },
- "employees" => "ALL_EMPLOYEES",
- "salesmen" => "ALL_SALESMEN",
"taxzones" => "ALL_TAXZONES",
"payments" => "ALL_PAYMENTS",
"currencies" => "ALL_CURRENCIES",
+ "departments" => "ALL_DEPARTMENTS",
$vc => { key => "ALL_" . uc($vc),
limit => $myconfig{vclimit} + 1 },
"price_factors" => "ALL_PRICE_FACTORS");
# label subs
+ my $employee_list_query_gen = sub { $::form->{$_[0]} ? [ or => [ id => $::form->{$_[0]}, deleted => 0 ] ] : [ deleted => 0 ] };
+ $TMPL_VAR{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all(query => $employee_list_query_gen->('employee_id'));
+ $TMPL_VAR{ALL_SALESMEN} = SL::DB::Manager::Employee->get_all(query => $employee_list_query_gen->('salesman_id'));
+ $TMPL_VAR{ALL_SHIPTO} = SL::DB::Manager::Shipto->get_all(query => [
+ or => [ trans_id => $::form->{"$::form->{vc}_id"} * 1, and => [ shipto_id => $::form->{shipto_id} * 1, trans_id => undef ] ]
+ ]);
+ $TMPL_VAR{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all(query => [
+ or => [
+ cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
+ and => [
+ cp_cv_id => undef,
+ cp_id => $::form->{cp_id} * 1
+ ]
+ ]
+ ]);
$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 { $_[0]->{"cp_name"} . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
+ $TMPL_VAR{department_labels} = sub { "$_[0]->{description}--$_[0]->{id}" };
# vendor/customer
$TMPL_VAR{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
@@ -410,36 +368,66 @@ sub form_header {
push @custom_hiddens, "select$form->{vc}";
# currencies and exchangerate
- @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
- %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
+ 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} && $form->{exchangerate};
+ $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;
+ '-values' => \@values, '-labels' => \%labels,
+ '-onchange' => "document.getElementById('update_button').click();"
+ )) if scalar @values;
push @custom_hiddens, "forex";
push @custom_hiddens, "exchangerate" if $form->{forex};
# credit remaining
- $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
+ my $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
$TMPL_VAR{is_credit_remaining_negativ} = ($form->{creditremaining} =~ /-/) ? "0" : "1";
-
+
# business
$TMPL_VAR{business_label} = ($form->{vc} eq "customer" ? $locale->text('Customer type') : $locale->text('Vendor type'));
- push @custom_hiddens, "ordnumber" if $form->{type} =~ /_quotation$/;
push @custom_hiddens, "customer_klass" if $form->{vc} eq 'customer';
- $credittext = $locale->text('Credit Limit exceeded!!!');
+ my $credittext = $locale->text('Credit Limit exceeded!!!');
- $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? "window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()"
- : ($form->{resubmit}) ? "document.oe.submit()"
- : ($creditwarning) ? "alert('$credittext')"
- : "focus()";
+ my $follow_up_vc = $form->{ $form->{vc} eq 'customer' ? 'customer' : 'vendor' };
+ $follow_up_vc =~ s/--\d*\s*$//;
+ $TMPL_VAR{follow_up_trans_info} = ($form->{type} =~ /_quotation$/ ? $form->{quonumber} : $form->{ordnumber}) . " ($follow_up_vc)";
+
+ if ($form->{id}) {
+ my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
+
+ if (scalar @{ $follow_ups }) {
+ $TMPL_VAR{num_follow_ups} = scalar @{ $follow_ups };
+ $TMPL_VAR{num_due_follow_ups} = sum map { $_->{due} * 1 } @{ $follow_ups };
+ }
+ }
+
+ my $dispatch_to_popup = '';
+ if ($form->{resubmit} && ($form->{format} eq "html")) {
+ $dispatch_to_popup = "window.open('about:blank','Beleg'); document.oe.target = 'Beleg';";
+ $dispatch_to_popup .= "document.do.submit();";
+ } elsif ($form->{resubmit}) {
+ # emulate click for resubmitting actions
+ $dispatch_to_popup = "document.oe.${_}.click(); " for grep { /^action_/ } keys %$form;
+ } elsif ($creditwarning) {
+ $::request->{layout}->add_javascripts_inline("alert('$credittext');");
+ }
+
+ $::request->{layout}->add_javascripts_inline("\$(function(){$dispatch_to_popup})");
+ $TMPL_VAR{dateformat} = $myconfig{dateformat};
+ $TMPL_VAR{numberformat} = $myconfig{numberformat};
+
+ if ($form->{type} eq 'sales_order') {
+ if (!$form->{periodic_invoices_config}) {
+ $form->{periodic_invoices_status} = $locale->text('not configured');
+
+ } else {
+ my $config = YAML::Load($form->{periodic_invoices_config});
+ $form->{periodic_invoices_status} = $config->{active} ? $locale->text('active') : $locale->text('inactive');
+ }
+ }
- $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
- $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
- $TMPL_VAR{onload} = $onload;
-
$form->{javascript} .= qq||;
$form->{javascript} .= qq||;
$form->{javascript} .= qq||;
@@ -451,8 +439,8 @@ sub form_header {
title creditlimit creditremaining tradediscount business
max_dunning_level dunning_amount shiptoname shiptostreet shiptozipcode
shiptocity shiptocountry shiptocontact shiptophone shiptofax
- shiptodepartment_1 shiptodepartment_2 shiptoemail
- message email subject cc bcc taxpart taxservice taxaccounts),
+ shiptodepartment_1 shiptodepartment_2 shiptoemail shiptocp_gender
+ message email subject cc bcc taxpart taxservice taxaccounts cursor_fokus),
@custom_hiddens,
map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} ]; # deleted: discount
@@ -466,44 +454,53 @@ sub form_header {
is_pur_ord => scalar ($form->{type} =~ /purchase_order$/),
);
- print $form->parse_html_template("oe/orders_header", { %TMPL_VAR });
+ print $form->parse_html_template("oe/form_header", { %TMPL_VAR });
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub form_footer {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
check_oe_access();
$form->{invtotal} = $form->{invsubtotal};
- $rows = max 2, $form->numtextrows($form->{notes}, 25, 8);
- $introws = max 2, $form->numtextrows($form->{intnotes}, 35, 8);
+ my $rows = max 2, $form->numtextrows($form->{notes}, 25, 8);
+ my $introws = max 2, $form->numtextrows($form->{intnotes}, 35, 8);
$rows = max $rows, $introws;
- $TMPL_VAR{notes} = qq||;
- $TMPL_VAR{intnotes} = qq||;
+ $TMPL_VAR{notes} = qq||;
+ $TMPL_VAR{intnotes} = qq||;
+
+ if( $form->{customer_id} && !$form->{taxincluded_changed_by_user} ) {
+ my $customer = SL::DB::Customer->new(id => $form->{customer_id})->load();
+ $form->{taxincluded} = defined($customer->taxincluded_checked) ? $customer->taxincluded_checked : $myconfig{taxincluded_checked};
+ }
if (!$form->{taxincluded}) {
- foreach $item (split / /, $form->{taxaccounts}) {
+ foreach my $item (split / /, $form->{taxaccounts}) {
if ($form->{"${item}_base"}) {
$form->{invtotal} += $form->{"${item}_total"} = $form->round_amount( $form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
$form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
$TMPL_VAR{tax} .= qq|
-
- $form->{"${item}_description"} | . $form->{"${item}_rate"} * 100 .qq|% |
- $form->{"${item}_total"} |
-
|;
+
+ $form->{"${item}_description"} | . $form->{"${item}_rate"} * 100 .qq|% |
+ $form->{"${item}_total"} |
+
|;
}
}
- $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
+# $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); # template does this
} else {
- foreach $item (split / /, $form->{taxaccounts}) {
+ foreach my $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);
@@ -511,98 +508,127 @@ sub form_footer {
$form->{"${item}_netto"} = $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
$TMPL_VAR{tax} .= qq|
-
- Enthaltene $form->{"${item}_description"} | . $form->{"${item}_rate"} * 100 .qq|% |
- $form->{"${item}_total"} |
-
-
- Nettobetrag |
- $form->{"${item}_netto"} |
-
|;
+
+ Enthaltene $form->{"${item}_description"} | . $form->{"${item}_rate"} * 100 .qq|% |
+ $form->{"${item}_total"} |
+
+
+ Nettobetrag |
+ $form->{"${item}_netto"} |
+
|;
}
}
}
$form->{oldinvtotal} = $form->{invtotal};
- print $form->parse_html_template("oe/orders_footer", {
+ print $form->parse_html_template("oe/form_footer", {
%TMPL_VAR,
- webdav => $webdav,
+ webdav => $::instance_conf->get_webdav,
print_options => print_options(inline => 1),
label_edit => $locale->text("Edit the $form->{type}"),
label_workflow => $locale->text("Workflow $form->{type}"),
+ is_sales => scalar ($form->{type} =~ /^sales_/), # these vars are exported, so that the template
+ is_order => scalar ($form->{type} =~ /_order$/), # may determine what to show
+ is_sales_quo => scalar ($form->{type} =~ /sales_quotation$/),
+ is_req_quo => scalar ($form->{type} =~ /request_quotation$/),
+ is_sales_ord => scalar ($form->{type} =~ /sales_order$/),
+ is_pur_ord => scalar ($form->{type} =~ /purchase_order$/),
});
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub update {
- $lxdebug->enter_sub();
-
- my ($recursive_call) = shift;
+ $main::lxdebug->enter_sub();
+
+ my ($recursive_call) = @_;
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
check_oe_access();
set_headings($form->{"id"} ? "edit" : "add");
- map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
$form->{update} = 1;
-
- $payment_id = $form->{payment_id} if $form->{payment_id};
-
+
&check_name($form->{vc});
-
- $form->{payment_id} = $payment_id if $form->{payment_id} eq "";
-
- $buysell = 'buy';
+
+ if (!$form->{forex}) { # read exchangerate from input field (not hidden)
+ map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate) unless $recursive_call;
+ }
+ my $buysell = 'buy';
$buysell = 'sell' if ($form->{vc} eq 'vendor');
- $form->{exchangerate} = $exchangerate if
- $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
+ $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
+ $form->{exchangerate} = $form->{forex} if $form->{forex};
- $exchangerate = $form->{exchangerate} || 1;
+ my $exchangerate = $form->{exchangerate} || 1;
##################### process items ######################################
# for pricegroups
- $i = $form->{rowcount};
+ my $i = $form->{rowcount};
if ( ($form->{"partnumber_$i"} eq "")
&& ($form->{"description_$i"} eq "")
&& ($form->{"partsgroup_$i"} eq "")) {
$form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
- &check_form;
+ &check_form;
} else {
+ my $mode;
if ($form->{type} =~ /^sales/) {
IS->retrieve_item(\%myconfig, \%$form);
+ $mode = 'IS';
} else {
IR->retrieve_item(\%myconfig, \%$form);
+ $mode = 'IR';
}
my $rows = scalar @{ $form->{item_list} };
- $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
+ # hier ist das problem fuer bug 817 $form->{discount} wird nicht durchgeschliffen
+ # ferner fallunterscheidung fuer verkauf oder einkauf s.a. bug 736 jb 04.05.2009
+ # select discount as vendor_discount from vendor ||
+ # select discount as customer_discount from customer
+ $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"$form->{vc}_discount"} * 100);
+
+ $form->{"lastcost_$i"} = $form->parse_amount(\%myconfig, $form->{"lastcost_$i"});
if ($rows) {
- $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
+
+ $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
+ if( !$form->{"qty_$i"} ) {
+ $form->{"qty_$i"} = 1;
+ }
if ($rows > 1) {
- &select_item;
- exit;
+ select_item(mode => $mode);
+ ::end_of_request();
} else {
- $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
- $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
+ my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
+ # hier werden parts (Artikeleigenschaften) aus item_list (retrieve_item aus IS.pm)
+ # (item wahrscheinlich synonym für parts) entsprechend in die form geschrieben ...
+
+ # Wäre dieses Mapping nicht besser in retrieve_items aufgehoben?
+ #(Eine Funktion bekommt Daten -> ARBEIT -> Rückgabe DATEN)
+ # Das quot sieht doch auch nach Ãberarbeitung aus ... (hmm retrieve_items gibt es in IS und IR)
map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
+
+ # ... deswegen muss die prüfung, ob es sich um einen nicht rabattierfähigen artikel handelt später erfolgen (Bug 1136)
+ $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
$form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
$form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
- $decimalplaces = max 2, length $1;
+ my $dec_qty = length $1;
+ my $decimalplaces = max 2, $dec_qty;
if ($sellprice) {
$form->{"sellprice_$i"} = $sellprice;
@@ -611,7 +637,7 @@ sub update {
$form->{"sellprice_$i"} /= $exchangerate; # if there is an exchange rate adjust sellprice
}
- $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
+ my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{taxaccounts} if !$form->{taxincluded};
@@ -619,6 +645,7 @@ sub update {
$form->{creditremaining} -= $amount;
$form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
+ $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces);
$form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
# get pricegroups for parts
@@ -650,276 +677,74 @@ sub update {
##################### process items ######################################
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub search {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
check_oe_access();
if ($form->{type} eq 'purchase_order') {
- $form->{title} = $locale->text('Purchase Orders');
- $form->{vc} = 'vendor';
- $ordlabel = $locale->text('Order Number');
- $ordnumber = 'ordnumber';
- $employee = $locale->text('Employee');
- }
-
- if ($form->{type} eq 'request_quotation') {
- $form->{title} = $locale->text('Request for Quotations');
- $form->{vc} = 'vendor';
- $ordlabel = $locale->text('RFQ Number');
- $ordnumber = 'quonumber';
- $employee = $locale->text('Employee');
- }
+ $form->{vc} = 'vendor';
+ $form->{ordnrname} = 'ordnumber';
+ $form->{title} = $locale->text('Purchase Orders');
+ $form->{ordlabel} = $locale->text('Order Number');
+
+ } elsif ($form->{type} eq 'request_quotation') {
+ $form->{vc} = 'vendor';
+ $form->{ordnrname} = 'quonumber';
+ $form->{title} = $locale->text('Request for Quotations');
+ $form->{ordlabel} = $locale->text('RFQ Number');
+
+ } elsif ($form->{type} eq 'sales_order') {
+ $form->{vc} = 'customer';
+ $form->{ordnrname} = 'ordnumber';
+ $form->{title} = $locale->text('Sales Orders');
+ $form->{ordlabel} = $locale->text('Order Number');
+
+ } elsif ($form->{type} eq 'sales_quotation') {
+ $form->{vc} = 'customer';
+ $form->{ordnrname} = 'quonumber';
+ $form->{title} = $locale->text('Quotations');
+ $form->{ordlabel} = $locale->text('Quotation Number');
- if ($form->{type} eq 'sales_order') {
- $form->{title} = $locale->text('Sales Orders');
- $form->{vc} = 'customer';
- $ordlabel = $locale->text('Order Number');
- $ordnumber = 'ordnumber';
- $employee = $locale->text('Employee');
- }
-
- if ($form->{type} eq 'sales_quotation') {
- $form->{title} = $locale->text('Quotations');
- $form->{vc} = 'customer';
- $ordlabel = $locale->text('Quotation Number');
- $ordnumber = 'quonumber';
- $employee = $locale->text('Employee');
- }
-
- # setup vendor / customer selection
- $form->all_vc(\%myconfig, $form->{vc},
- ($form->{vc} eq 'customer') ? "AR" : "AP");
-
- # departments
- if (@{ $form->{all_departments} }) {
- $form->{selectdepartment} = "\n"
- } (@{ $form->{all_departments} });
- }
-
- $department = qq|
-
- | . $locale->text('Department') . qq| |
- |
-
-| if $form->{selectdepartment};
-
- my $delivered;
- if (($form->{"type"} eq "sales_order") ||
- ($form->{"type"} eq "purchase_order")) {
- $delivered = qq|
-
-
- |
-
- |
-
-|;
+ } else {
+ $form->show_generic_error($locale->text('oe.pl::search called with unknown type'), back_button => 1);
}
- # use JavaScript Calendar or not
- $form->{jsscript} = 1;
- $jsscript = "";
-
- $button1 = qq|
-
- text('button') . qq|> |
- |;
- $button2 = qq|
-
- text('button') . qq|> |
- |;
-
- #write Trigger
- $jsscript =
- Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
- "transdateto", "BL", "trigger4");
-
- my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
-
- $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
- "all" => 1 },
- "employees" => "ALL_EMPLOYEES",
- "salesmen" => "ALL_SALESMEN",
- $vc => "ALL_" . uc($vc)
- );
-
- my %labels = ();
- my @values = ("");
- foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
- push(@values, $item->{"id"});
- $labels{$item->{"id"}} = $item->{"projectnumber"};
- }
- my $projectnumber =
- NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
- '-labels' => \%labels));
-
- #employees
- %labels = ();
- @values = ("");
- foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
- push(@values, $item->{"id"});
- $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
- }
-
- #salesmen
- my %labels_salesmen = ();
- my @values_salesmen = ('');
- foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
- push(@values_salesmen, $item->{"id"});
- $labels_salesmen{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
- }
-
- my $employee_block = qq|
-
- | . $locale->text('Employee') . qq| |
- | . NTI($cgi->popup_menu('-name' => 'employee_id', '-values' => \@values, '-labels' => \%labels)) . qq| |
-
-
- | . $locale->text('Salesman') . qq| |
- | .
- NTI($cgi->popup_menu('-name' => 'salesman_id',
- '-values' => \@values_salesmen,
- '-labels' => \%labels_salesmen)) . qq|
- |
-
|;
-
- %labels = ();
- @values = ("");
-
- foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
- push(@values, $item->{name}.qq|--|.$item->{"id"});
- $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
- }
-
- my $vc_label = $form->{vc} eq "customer" ? $locale->text('Customer') : $locale->text('Vendor');
- $vc =
- $myconfig{vclimit} <= scalar(@values)
- ? qq|{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
- : NTI($cgi->popup_menu('-name' => "$form->{vc}",
- '-default' => $form->{"old$form->{vc}"},
- '-onChange' => 'document.getElementById(\'update_button\').click();',
- '-values' => \@values,
- '-labels' => \%labels));
- $form->header;
-
- print qq|
-
-
-
+ $form->header();
-
-