X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=bin%2Fmozilla%2Foe.pl;h=cb7402aa338238d42fd7ed387858d88595d613fc;hb=1163cee7d5cfe9355a9d231ac544ce0943623d77;hp=7aa3f2eb28a1da3334ba1ffb9aa6fe15bd872072;hpb=972f67f3fe4d62126a9a5958918175b5f0b08ee6;p=kivitendo-erp.git diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index 7aa3f2eb2..cb7402aa3 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -1,4 +1,4 @@ -# #===================================================================== +#===================================================================== # LX-Office ERP # Copyright (C) 2004 # Based on SQL-Ledger Version 2.1.9 @@ -30,42 +30,101 @@ # Order entry module # Quotation module #====================================================================== -use Data::Dumper; +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 sum); +use Data::Dumper; -require "$form->{path}/io.pl"; -require "$form->{path}/arap.pl"; +require "bin/mozilla/io.pl"; +require "bin/mozilla/arap.pl"; +require "bin/mozilla/reportgenerator.pl"; 1; # end of main -sub add { +# For locales.pl: +# $locale->text('Edit the purchase_order'); +# $locale->text('Edit the sales_order'); +# $locale->text('Edit the request_quotation'); +# $locale->text('Edit the sales_quotation'); + +# $locale->text('Workflow purchase_order'); +# $locale->text('Workflow sales_order'); +# $locale->text('Workflow request_quotation'); +# $locale->text('Workflow sales_quotation'); + +my $oe_access_map = { + 'sales_order' => 'sales_order_edit', + 'purchase_order' => 'purchase_order_edit', + 'request_quotation' => 'request_quotation_edit', + 'sales_quotation' => 'sales_quotation_edit', +}; + +sub check_oe_access { + my $right = $oe_access_map->{$form->{type}}; + $right ||= 'DOES_NOT_EXIST'; + + $auth->assert($right); +} + +sub set_headings { $lxdebug->enter_sub(); + check_oe_access(); + + my ($action) = @_; + if ($form->{type} eq 'purchase_order') { - $form->{title} = $locale->text('Add Purchase Order'); - $form->{vc} = 'vendor'; + $form->{title} = $action eq "edit" ? + $locale->text('Edit Purchase Order') : + $locale->text('Add Purchase Order'); + $form->{heading} = $locale->text('Purchase Order'); + $form->{vc} = 'vendor'; } if ($form->{type} eq 'sales_order') { - $form->{title} = $locale->text('Add Sales Order'); - $form->{vc} = 'customer'; + $form->{title} = $action eq "edit" ? + $locale->text('Edit Sales Order') : + $locale->text('Add Sales Order'); + $form->{heading} = $locale->text('Sales Order'); + $form->{vc} = 'customer'; } if ($form->{type} eq 'request_quotation') { - $form->{title} = $locale->text('Add Request for Quotation'); - $form->{vc} = 'vendor'; + $form->{title} = $action eq "edit" ? + $locale->text('Edit Request for Quotation') : + $locale->text('Add Request for Quotation'); + $form->{heading} = $locale->text('Request for Quotation'); + $form->{vc} = 'vendor'; } if ($form->{type} eq 'sales_quotation') { - $form->{title} = $locale->text('Add Quotation'); - $form->{vc} = 'customer'; + $form->{title} = $action eq "edit" ? + $locale->text('Edit Quotation') : + $locale->text('Add Quotation'); + $form->{heading} = $locale->text('Quotation'); + $form->{vc} = 'customer'; } + $lxdebug->leave_sub(); +} + +sub add { + $lxdebug->enter_sub(); + + check_oe_access(); + + set_headings("add"); + $form->{callback} = - "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&password=$form->{password}" + "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}" unless $form->{callback}; &order_links; @@ -78,46 +137,57 @@ sub add { sub edit { $lxdebug->enter_sub(); + check_oe_access(); + + # show history button + $form->{javascript} = qq||; + #/show hhistory button + + $form->{simple_save} = 0; + + set_headings("edit"); + # editing without stuff to edit? try adding it first - if ($form->{rowcount}) { - map { $id++ if $form->{"id_$_"} } (1 .. $form->{rowcount}); + if ($form->{rowcount} && !$form->{print_and_save}) { + map { $id++ if $form->{"multi_id_$_"} } (1 .. $form->{rowcount}); if (!$id) { # reset rowcount undef $form->{rowcount}; &add; + $lxdebug->leave_sub(); return; } - } else { - if (!$form->{id}) { - &add; - return; - } + } elsif (!$form->{id}) { + &add; + $lxdebug->leave_sub(); + return; } - if ($form->{type} eq 'purchase_order') { - $form->{title} = $locale->text('Edit Purchase Order'); - $form->{heading} = $locale->text('Purchase Order'); - $form->{vc} = 'vendor'; - } - if ($form->{type} eq 'sales_order') { - $form->{title} = $locale->text('Edit Sales Order'); - $form->{heading} = $locale->text('Sales Order'); - $form->{vc} = 'customer'; - } - if ($form->{type} eq 'request_quotation') { - $form->{title} = $locale->text('Edit Request for Quotation'); - $form->{heading} = $locale->text('Request for Quotation'); - $form->{vc} = 'vendor'; - } - if ($form->{type} eq 'sales_quotation') { - $form->{title} = $locale->text('Edit Quotation'); - $form->{heading} = $locale->text('Quotation'); - $form->{vc} = 'customer'; + if ($form->{print_and_save}) { + $form->{action} = "print"; + $form->{resubmit} = 1; + $language_id = $form->{language_id}; + $printer_id = $form->{printer_id}; } + set_headings("edit"); + &order_links; + + $form->{rowcount} = 0; + foreach $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(); @@ -126,156 +196,71 @@ sub edit { sub order_links { $lxdebug->enter_sub(); + check_oe_access(); + # get customer/vendor - $form->all_vc(\%myconfig, $form->{vc}, - ($form->{vc} eq 'customer') ? "AR" : "AP"); + $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP"); # retrieve order/quotation - $form->{webdav} = $webdav; + $form->{webdav} = $webdav; + $form->{jsscript} = 1; - # set jscalendar - $form->{jscalendar} = $jscalendar; + my $editing = $form->{id}; OE->retrieve(\%myconfig, \%$form); # 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)); + $form->{shipto} = 1 if $form->{id}; # get customer / vendor - if ($form->{type} =~ /(purchase_order|request_quotation|receive_order)/) { - IR->get_vendor(\%myconfig, \%$form); - - #quote all_vendor Bug 133 - foreach $ref (@{ $form->{all_vendor} }) { - $ref->{name} = $form->quote($ref->{name}); - } - - } - if ($form->{type} =~ /(sales|ship)_(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; + IR->get_vendor(\%myconfig, \%$form) if $form->{type} =~ /(purchase_order|request_quotation)/; + IS->get_customer(\%myconfig, \%$form) if $form->{type} =~ /sales_(order|quotation)/; - $form->{intnotes} = $intnotes; - ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} }; - $form->{"old$form->{vc}"} = - qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|; + $form->restore_vars(qw(payment_id language_id taxzone_id intnotes cp_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 the popup menus + # build vendor/customer drop down comatibility... don't ask if (@{ $form->{"all_$form->{vc}"} }) { - $form->{ $form->{vc} } = - qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|; - map { $form->{"select$form->{vc}"} .= "$_->{name}--$_->{id}\n" } - (@{ $form->{"all_$form->{vc}"} }); - } - - # currencies - @curr = split /:/, $form->{currencies}; - chomp $curr[0]; - $form->{defaultcurrency} = $curr[0]; - $form->{currency} = $form->{defaultcurrency} unless $form->{currency}; - - map { $form->{selectcurrency} .= "$_\n" } @curr; - - $form->{taxincluded} = $taxincluded if ($form->{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->{"select$form->{vc}"} = 1; + $form->{$form->{vc}} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|; } - $form->{employee} = "$form->{employee}--$form->{employee_id}"; + $form->{"old$form->{vc}"} = $form->{$form->{vc}}; - # sales staff - if (@{ $form->{all_employees} }) { - $form->{selectemployee} = ""; - map { $form->{selectemployee} .= "$_->{name}--$_->{id}\n" } - (@{ $form->{all_employees} }); + if ($form->{"old$form->{vc}"} !~ m/--\d+$/ && $form->{"$form->{vc}_id"}) { + $form->{"old$form->{vc}"} .= qq|--$form->{"$form->{vc}_id"}| } - # forex - $form->{forex} = $form->{exchangerate}; - $lxdebug->leave_sub(); } sub prepare_order { $lxdebug->enter_sub(); - $form->{format} = "pdf"; - $form->{media} = "screen"; - $form->{formname} = $form->{type}; - - map { $form->{$_} =~ s/\"/"/g } - qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact); - - foreach $ref (@{ $form->{form_details} }) { - $form->{rowcount} = ++$i; - - map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref}; - } - for my $i (1 .. $form->{rowcount}) { - if ($form->{id}) { - $form->{"discount_$i"} = - $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100); - } else { - $form->{"discount_$i"} = - $form->format_amount(\%myconfig, $form->{"discount_$i"}); - } - ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); - $dec = length $dec; - $decimalplaces = ($dec > 2) ? $dec : 2; - # copy reqdate from deliverydate for invoice -> order conversion - $form->{"reqdate_$i"} = $form->{"deliverydate_$i"} - unless $form->{"reqdate_$i"}; + check_oe_access(); - $form->{"sellprice_$i"} = - $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, - $decimalplaces); + $form->{formname} ||= $form->{type}; - (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/); - $dec_qty = length $dec_qty; - $form->{"qty_$i"} = - $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty); + # 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}; - map { $form->{"${_}_$i"} =~ s/\"/"/g } - qw(partnumber description unit); + for my $i (1 .. $form->{rowcount}) { + $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->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); } $lxdebug->leave_sub(); @@ -283,752 +268,299 @@ sub prepare_order { sub form_header { $lxdebug->enter_sub(); + my @custom_hiddens; - $checkedopen = ($form->{closed}) ? "" : "checked"; - $checkedclosed = ($form->{closed}) ? "checked" : ""; + check_oe_access(); - # use JavaScript Calendar or not - $form->{jsscript} = $form->{jscalendar}; - $jsscript = ""; - - if ($form->{jsscript}) { - - # with JavaScript Calendar - $button1 = qq| - {transdate}> - text('button') . qq|> - |; - $button2 = qq| - {reqdate}> - text('button') . qq|> - |; - - #write Trigger - $jsscript = - Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1", - "reqdate", "BL", "trigger2"); + # Container for template variables. Unfortunately this has to be visible in form_footer too, so not my. + our %TMPL_VAR = (); - } else { + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); - # without JavaScript Calendar - $button1 = qq| - {transdate}>|; - $button2 = qq| - {reqdate}>|; - } + $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id}; + $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id}; + + # use JavaScript Calendar or not + $form->{jsscript} = 1; + + # openclosed checkboxes + my @tmp; + push @tmp, sprintf qq|%s|, + $form->{"delivered"} ? "checked" : "", $locale->text('Delivered') if $form->{"type"} =~ /_order$/; + push @tmp, sprintf qq|%s|, + $form->{"closed"} ? "checked" : "", $locale->text('Closed') if $form->{id}; + $TMPL_VAR{openclosed} = sprintf qq|%s\n|, 2 * scalar @tmp, join "\n", @tmp if @tmp; + + # 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", + "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 + $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}" }; + + # vendor/customer + $TMPL_VAR{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" }; + $TMPL_VAR{vclimit} = $myconfig{vclimit}; + $TMPL_VAR{vc_select} = "customer_or_vendor_selection_window('$form->{vc}', '', @{[ $form->{vc} eq 'vendor' ? 1 : 0 ]}, 0)"; + push @custom_hiddens, "$form->{vc}_id"; + push @custom_hiddens, "old$form->{vc}"; + push @custom_hiddens, "select$form->{vc}"; + + # currencies and exchangerate + @values = map { $_ } @{ $form->{ALL_CURRENCIES} }; + %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}; + + # credit remaining + $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, "customer_klass" if $form->{vc} eq 'customer'; + + $credittext = $locale->text('Credit Limit exceeded!!!'); + + 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}) { - $openclosed = qq| - - - - - | - . $locale->text('Open') . qq| - | - . $locale->text('Closed') . qq| - - - - -|; - } + my $follow_ups = FU->follow_ups('trans_id' => $form->{id}); - # set option selected - foreach $item ($form->{vc}, currency, department, employee, contact) { - $form->{"select$item"} =~ s/ selected//; - $form->{"select$item"} =~ - s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; + if (scalar @{ $follow_ups }) { + $TMPL_VAR{num_follow_ups} = scalar @{ $follow_ups }; + $TMPL_VAR{num_due_follow_ups} = sum map { $_->{due} * 1 } @{ $follow_ups }; + } } - #quote select[customer|vendor] Bug 133 - $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"}); + $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()"; - #build contacts - if ($form->{all_contacts}) { + $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->{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}"; - } - } - } + $form->{javascript} .= qq||; + $form->{javascript} .= qq||; + $form->{javascript} .= qq||; - $form->{exchangerate} = - $form->format_amount(\%myconfig, $form->{exchangerate}); + $form->header; - $form->{creditlimit} = - $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); - $form->{creditremaining} = - $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); + $TMPL_VAR{HIDDENS} = [ map { name => $_, value => $form->{$_} }, + qw(id action type vc formname media format proforma queued printed emailed + 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 cursor_fokus), + @custom_hiddens, + map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} ]; # deleted: discount + + %TMPL_VAR = ( + %TMPL_VAR, + 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$/), + ); - $contact = - ($form->{selectcontact}) - ? qq|$form->{selectcontact}\n| - : qq||; + print $form->parse_html_template("oe/form_header", { %TMPL_VAR }); - $exchangerate = qq| -{forex}> -|; + $lxdebug->leave_sub(); +} - 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}>|; - } - } +sub form_footer { + $lxdebug->enter_sub(); - $vclabel = ucfirst $form->{vc}; - $vclabel = $locale->text($vclabel); + check_oe_access(); - $terms = qq| - - | . $locale->text('Terms: Net') . qq| - {terms}> | - . $locale->text('days') . qq| - -|; + $form->{invtotal} = $form->{invsubtotal}; - if ($form->{business}) { - $business = qq| - - | . $locale->text('Business') . qq| - $form->{business} - | . $locale->text('Trade Discount') . qq| - | - . $form->format_amount(\%myconfig, $form->{tradediscount} * 100) - . qq| % - -|; - } + $rows = max 2, $form->numtextrows($form->{notes}, 25, 8); + $introws = max 2, $form->numtextrows($form->{intnotes}, 35, 8); + $rows = max $rows, $introws; - if ($form->{type} !~ /_quotation$/) { - $ordnumber = qq| - - | . $locale->text('Order Number') . qq| - - - - | - . $locale->text('Quotation Number') . qq| - - - - | - . $locale->text('Customer Order Number') . qq| - - - - | . $locale->text('Order Date') . qq| - $button1 + $TMPL_VAR{notes} = qq|| . H($form->{notes}) . qq||; + $TMPL_VAR{intnotes} = qq|| . H($form->{intnotes}) . qq||; - - - | . $locale->text('Required by') . qq| - $button2 - -|; + if (!$form->{taxincluded}) { - $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; + foreach $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); - $creditremaining = qq| + $TMPL_VAR{tax} .= qq| - - - - - | . $locale->text('Credit Limit') . qq| - $form->{creditlimit} - - | . $locale->text('Remaining') . qq| - $form->{creditremaining} - - - - -|; + $form->{"${item}_description"} | . $form->{"${item}_rate"} * 100 .qq|% + $form->{"${item}_total"} + |; + } + } + +# $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); # template does this + } else { - $reqlabel = - ($form->{type} eq 'sales_quotation') - ? $locale->text('Valid until') - : $locale->text('Required by'); - if ($form->{type} eq 'sales_quotation') { - $ordnumber = qq| + 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); + + $TMPL_VAR{tax} .= qq| - | - . $locale->text('Quotation Number') . qq| - - + Enthaltene $form->{"${item}_description"} | . $form->{"${item}_rate"} * 100 .qq|% + $form->{"${item}_total"} -|; - } else { - $ordnumber = qq| - | . $locale->text('RFQ Number') . qq| - - - -|; - - $terms = ""; + Nettobetrag + $form->{"${item}_netto"} + |; + } } + } - $ordnumber .= qq| - - | . $locale->text('Quotation Date') . qq| - $button1 - - - $reqlabel - $button2 - -|; + $form->{oldinvtotal} = $form->{invtotal}; - } + print $form->parse_html_template("oe/form_footer", { + %TMPL_VAR, + webdav => $webdav, + print_options => print_options(inline => 1), + label_edit => $locale->text("Edit the $form->{type}"), + label_workflow => $locale->text("Workflow $form->{type}"), + }); - $vc = - ($form->{"select$form->{vc}"}) - ? qq|{vc}>$form->{"select$form->{vc}"}\n{vc}"}">| - : qq|{vc} value="$form->{$form->{vc}}" size=35>|; + $lxdebug->leave_sub(); +} - $department = qq| - - | . $locale->text('Department') . qq| - $form->{selectdepartment} - - - -| if $form->{selectdepartment}; +sub update { + $lxdebug->enter_sub(); - $employee = qq| - -|; + my ($recursive_call) = shift; - if ($form->{type} eq 'sales_order') { - if ($form->{selectemployee}) { - $employee = qq| - {customer_klass}> - - | . $locale->text('Salesperson') . qq| - $form->{selectemployee} - - - -|; - } - } else { - $employee = qq| - {customer_klass}> - - | . $locale->text('Employee') . qq| - $form->{selectemployee} - - - -|; - } + check_oe_access(); - $form->header; +# $main::lxdebug->message(0, Dumper($form)); - print qq| - + set_headings($form->{"id"} ? "edit" : "add"); -{script}> + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate) unless $recursive_call; + $form->{update} = 1; -{id}> + $payment_id = $form->{payment_id} if $form->{payment_id}; -{type}> -{formname}> -{media}> -{format}> + &check_name($form->{vc}); - - - + $form->{payment_id} = $payment_id if $form->{payment_id} eq ""; -{vc}> + $buysell = 'buy'; + $buysell = 'sell' if ($form->{vc} eq 'vendor'); + $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell); + $form->{exchangerate} = $form->{forex} if $form->{forex}; - + $exchangerate = $form->{exchangerate} || 1; -{discount}> -{creditlimit}> -{creditremaining}> +##################### process items ###################################### + # for pricegroups + $i = $form->{rowcount}; + if ( ($form->{"partnumber_$i"} eq "") + && ($form->{"description_$i"} eq "") + && ($form->{"partsgroup_$i"} eq "")) { -{tradediscount}> -{business}> - + $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid}); - - - $form->{title} - - - - - - - - - - $vclabel - $vc - {vc}_id value=$form->{"$form->{vc}_id"}> - {vc}"}"> - | - . $locale->text('Contact Person') . qq| - $contact - - $creditremaining - $business - $department - - | . $locale->text('Currency') . qq| - $form->{selectcurrency} - - {defaultcurrency}> - $exchangerate - - - | . $locale->text('Shipping Point') . qq| - - - - | . $locale->text('Ship via') . qq| - - - - - - - $openclosed - $employee - $ordnumber - $terms - - - - - - + &check_form; + } else { -$jsscript + if ($form->{type} =~ /^sales/) { + IS->retrieve_item(\%myconfig, \%$form); + } else { + IR->retrieve_item(\%myconfig, \%$form); + } - + my $rows = scalar @{ $form->{item_list} }; - - - - - - - - - + # 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); - - - - - - + if ($rows) { + $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"}); - - + if ($rows > 1) { - -|; + &select_item; + exit; - foreach $item (split / /, $form->{taxaccounts}) { - print qq| -{"${item}_rate"}> - -|; - } - $lxdebug->leave_sub(); -} + } else { -sub form_footer { - $lxdebug->enter_sub(); + $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 ... - $form->{invtotal} = $form->{invsubtotal}; + # 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 ""; - if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) { - $rows = 2; - } - if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) { - $introws = 2; - } - $rows = ($rows > $introws) ? $rows : $introws; - $notes = - qq|$form->{notes}|; - $intnotes = - qq|$form->{intnotes}|; + $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor}; - $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/; + $decimalplaces = max 2, length $1; - $taxincluded = ""; - if ($form->{taxaccounts}) { - $taxincluded = qq| - {taxincluded}> | - . $locale->text('Tax Included') . qq| -|; - } + if ($sellprice) { + $form->{"sellprice_$i"} = $sellprice; + } else { + $form->{"sellprice_$i"} *= (1 - $form->{tradediscount}); + $form->{"sellprice_$i"} /= $exchangerate; # if there is an exchange rate adjust sellprice + } - if (!$form->{taxincluded}) { - - foreach $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); - - $tax .= qq| - - $form->{"${item}_description"} - $form->{"${item}_total"} - -|; - } - } - - $form->{invsubtotal} = - $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); - - $subtotal = qq| - - | . $locale->text('Subtotal') . qq| - $form->{invsubtotal} - -|; - - } - - 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"} - -|; - } - } - - } - - $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} - - - - - - - -{oldinvtotal}> - - - - -|; - - 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| - - - - - -|; - - print $webdav_list; - } - print qq| -{jscalendar}> -|; - print qq| - - -|; - &print_options; - - print qq| - - - - -Bearbeiten des $form->{heading} - - - - - -|; - - if ($form->{id}) { - print qq| -Workflow $form->{heading} - -|; - if ($form->{type} =~ /sales_quotation$/) { - print qq| -|; - } - if ($form->{type} =~ /request_quotation$/) { - print qq| -|; - } - print qq| - -|; - - if ($form->{type} =~ /sales_order$/) { - print qq| -$form->{heading} als neue Vorlage verwenden für - - -|; - - } elsif ($form->{type} =~ /purchase_order$/) { - print qq| -$form->{heading} als neue Vorlage verwenden für - - -|; - - } else { - print qq| -$form->{heading} als neue Vorlage verwenden für - -|; - } - } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount}) { - print qq| -Workflow $form->{heading} - - -|; - } - - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print qq| - -{rowcount}> - - - -{path}> -{login}> -{password}> - - - - -