X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Foe.pl;h=1fc3fe3d653fd939046486a0930875c7e7903392;hb=4f63ea874f629459e1a73643595ab5e23e38e7f0;hp=baa041f364d9288bd5da8c5070f8d38153c946d3;hpb=72539cb39a3d19f930a8e0e41e46bf41afe9a8f1;p=kivitendo-erp.git diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index baa041f36..1fc3fe3d6 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 @@ -31,40 +31,98 @@ # Quotation module #====================================================================== +use POSIX qw(strftime); + +use SL::DO; +use SL::FU; use SL::OE; use SL::IR; use SL::IS; use SL::PE; +use SL::ReportGenerator; +use List::Util qw(max reduce sum); -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; @@ -77,46 +135,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(); @@ -125,144 +194,68 @@ 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); - } - if ($form->{type} =~ /(sales|ship)_(order|quotation)/) { - IS->get_customer(\%myconfig, \%$form); - } - $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->{employee} = "$form->{employee}--$form->{employee_id}"; - - # sales staff - if (@{ $form->{all_employees} }) { - $form->{selectemployee} = ""; - map { $form->{selectemployee} .= "$_->{name}--$_->{id}\n" } - (@{ $form->{all_employees} }); + $form->{"select$form->{vc}"} = 1; + $form->{$form->{vc}} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|; } - # forex - $form->{forex} = $form->{exchangerate}; + $form->{"old$form->{vc}"} = $form->{$form->{vc}}; + $form->{"old$form->{vc}"} .= qq|--$form->{"$form->{vc}_id"}| unless ($form->{"old$form->{vc}"} =~ m/--\d+$/); $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(); @@ -270,749 +263,285 @@ 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 = ""; + # Container for template variables. Unfortunately this has to be visible in form_footer too, so not my. + our %TMPL_VAR = (); - 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"); + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); - } else { + $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id}; + $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id}; - # without JavaScript Calendar - $button1 = qq| - {transdate}>|; - $button2 = qq| - {reqdate}>|; - } + # 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/--.*?//; + $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 }; + } } - #build contacts - if ($form->{all_contacts}) { + $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()"; - $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}"; - } - } - } + $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->{exchangerate} = - $form->format_amount(\%myconfig, $form->{exchangerate}); + $form->{javascript} .= qq||; + $form->{javascript} .= qq||; + $form->{javascript} .= qq||; - $form->{creditlimit} = - $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); - $form->{creditremaining} = - $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); + $form->header; - $contact = - ($form->{selectcontact}) - ? qq|$form->{selectcontact}\n| - : qq||; + $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$/), + ); - $exchangerate = qq| -{forex}> -|; + print $form->parse_html_template("oe/form_header", { %TMPL_VAR }); - 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}>|; - } - } + $lxdebug->leave_sub(); +} - $vclabel = ucfirst $form->{vc}; - $vclabel = $locale->text($vclabel); +sub form_footer { + $lxdebug->enter_sub(); - $terms = qq| - - | . $locale->text('Terms: Net') . qq| - {terms}> | - . $locale->text('days') . qq| - -|; + check_oe_access(); - if ($form->{business}) { - $business = qq| - - | . $locale->text('Business') . qq| - $form->{business} - | . $locale->text('Trade Discount') . qq| - | - . $form->format_amount(\%myconfig, $form->{tradediscount} * 100) - . qq| % - -|; - } + $form->{invtotal} = $form->{invsubtotal}; - 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 + $rows = max 2, $form->numtextrows($form->{notes}, 25, 8); + $introws = max 2, $form->numtextrows($form->{intnotes}, 35, 8); + $rows = max $rows, $introws; - - - | . $locale->text('Required by') . qq| - $button2 - -|; + $TMPL_VAR{notes} = qq|| . H($form->{notes}) . qq||; + $TMPL_VAR{intnotes} = qq|| . H($form->{intnotes}) . qq||; + + 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; + set_headings($form->{"id"} ? "edit" : "add"); - print qq| - + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate) unless $recursive_call; + $form->{update} = 1; -{script}> + $payment_id = $form->{payment_id} if $form->{payment_id}; -{id}> + &check_name($form->{vc}); -{type}> -{formname}> -{media}> -{format}> + $form->{payment_id} = $payment_id if $form->{payment_id} eq ""; - - - + $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}; -{vc}> + $exchangerate = $form->{exchangerate} || 1; - +##################### process items ###################################### + # for pricegroups + $i = $form->{rowcount}; + if ( ($form->{"partnumber_$i"} eq "") + && ($form->{"description_$i"} eq "") + && ($form->{"partsgroup_$i"} eq "")) { -{discount}> -{creditlimit}> -{creditremaining}> + $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid}); + &check_form; -{tradediscount}> -{business}> - + } else { - - - $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 - - - - - - + if ($form->{type} =~ /^sales/) { + IS->retrieve_item(\%myconfig, \%$form); + } else { + IR->retrieve_item(\%myconfig, \%$form); + } -$jsscript + my $rows = scalar @{ $form->{item_list} }; - - - - - - - - - - - - - - - - - - - - - - - -|; + $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100); - foreach $item (split / /, $form->{taxaccounts}) { - print qq| -{"${item}_rate"}> - -|; - } - $lxdebug->leave_sub(); -} + if ($rows) { + $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"}); -sub form_footer { - $lxdebug->enter_sub(); + if ($rows > 1) { - $form->{invtotal} = $form->{invsubtotal}; + &select_item; + exit; - 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}|; + } else { - $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"}); + $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"}; + map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit); + map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] }; + $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne ""; - $taxincluded = ""; - if ($form->{taxaccounts}) { - $taxincluded = qq| - {taxincluded}> | - . $locale->text('Tax Included') . qq| -|; - } - - 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}> - - - - -