X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Foe.pl;h=3867c1b411b9362cc8daa399365dac805573d6dd;hb=2bc081d8f636bf558b7f3eb8bb9e4e99d45e6ca1;hp=f9907cbf2855d00e5eec31d3a090d045f69360c9;hpb=b59ec96925334124e8e126e467181b766b7c701f;p=kivitendo-erp.git diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index f9907cbf2..3867c1b41 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,979 +31,578 @@ # Quotation module #====================================================================== +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 "bin/mozilla/io.pl"; +require "bin/mozilla/arap.pl"; +require "bin/mozilla/reportgenerator.pl"; + +use strict; -require "$form->{path}/io.pl"; -require "$form->{path}/arap.pl"; +our %TMPL_VAR; 1; # end of main -sub add { - $lxdebug->enter_sub(); +# 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'); - if ($form->{type} eq 'purchase_order') { - $form->{title} = $locale->text('Add Purchase Order'); - $form->{vc} = 'vendor'; - } - if ($form->{type} eq 'sales_order') { - $form->{title} = $locale->text('Add Sales Order'); - $form->{vc} = 'customer'; - } - if ($form->{type} eq 'request_quotation') { - $form->{title} = $locale->text('Add Request for Quotation'); - $form->{vc} = 'vendor'; - } - if ($form->{type} eq 'sales_quotation') { - $form->{title} = $locale->text('Add Quotation'); - $form->{vc} = 'customer'; - } +# $locale->text('Workflow purchase_order'); +# $locale->text('Workflow sales_order'); +# $locale->text('Workflow request_quotation'); +# $locale->text('Workflow sales_quotation'); - $form->{callback} = - "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&password=$form->{password}" - unless $form->{callback}; +my $oe_access_map = { + 'sales_order' => 'sales_order_edit', + 'purchase_order' => 'purchase_order_edit', + 'request_quotation' => 'request_quotation_edit', + 'sales_quotation' => 'sales_quotation_edit', +}; - &order_links; - &prepare_order; - &display_form; +sub check_oe_access { + my $form = $main::form; - $lxdebug->leave_sub(); + my $right = $oe_access_map->{$form->{type}}; + $right ||= 'DOES_NOT_EXIST'; + + $main::auth->assert($right); } -sub edit { - $lxdebug->enter_sub(); +sub set_headings { + $main::lxdebug->enter_sub(); - # editing without stuff to edit? try adding it first - if ($form->{rowcount}) { - map {$id++ if $form->{"id_$_"}} (1 .. $form->{rowcount}); - if (!$id) { - # reset rowcount - undef $form->{rowcount}; - &add; - return; - } - } else { - if (!$form->{id}) { - &add; - return; - } - } + my $form = $main::form; + my $locale = $main::locale; + + check_oe_access(); + + my ($action) = @_; if ($form->{type} eq 'purchase_order') { - $form->{title} = $locale->text('Edit Purchase Order'); + $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('Edit Sales Order'); + $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('Edit Request for Quotation'); + $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('Edit Quotation'); + $form->{title} = $action eq "edit" ? + $locale->text('Edit Quotation') : + $locale->text('Add Quotation'); $form->{heading} = $locale->text('Quotation'); $form->{vc} = 'customer'; } - &order_links; - &prepare_order; - &display_form; - - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } -sub order_links { - $lxdebug->enter_sub(); - - # get customer/vendor - $form->all_vc(\%myconfig, $form->{vc}, - ($form->{vc} eq 'customer') ? "AR" : "AP"); - - # retrieve order/quotation - $form->{webdav} = $webdav; - +sub add { + $main::lxdebug->enter_sub(); - # set jscalendar - $form->{jscalendar} = $jscalendar; + my $form = $main::form; - OE->retrieve(\%myconfig, \%$form); + check_oe_access(); - # 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!')); - } + set_headings("add"); - $taxincluded = $form->{taxincluded}; - $form->{shipto} = 1 if $form->{id}; + $form->{callback} = + "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}" + unless $form->{callback}; - if ($form->{"all_$form->{vc}"}) { - unless ($form->{"$form->{vc}_id"}) { - $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id}; - } - } + &order_links; + &prepare_order; + &display_form; - $cp_id = $form->{cp_id}; - $intnotes = $form->{intnotes}; + $main::lxdebug->leave_sub(); +} - # 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; +sub edit { + $main::lxdebug->enter_sub(); - $form->{intnotes} = $intnotes; - ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} }; - $form->{"old$form->{vc}"} = - qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|; + my $form = $main::form; - # 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}"} .= "$_->{name}--$_->{id}\n" } - (@{ $form->{"all_$form->{vc}"} }); - } + check_oe_access(); - # currencies - @curr = split /:/, $form->{currencies}; - chomp $curr[0]; - $form->{defaultcurrency} = $curr[0]; - $form->{currency} = $form->{defaultcurrency} unless $form->{currency}; + # show history button + $form->{javascript} = qq||; + #/show hhistory button - map { $form->{selectcurrency} .= "$_\n" } @curr; + $form->{simple_save} = 0; - $form->{taxincluded} = $taxincluded if ($form->{id}); + set_headings("edit"); - # departments - if (@{ $form->{all_departments} }) { - $form->{selectdepartment} = "\n"; - $form->{department} = "$form->{department}--$form->{department_id}"; + # 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) { - map { - $form->{selectdepartment} .= - "$_->{description}--$_->{id}\n" - } (@{ $form->{all_departments} }); + # reset rowcount + undef $form->{rowcount}; + &add; + $main::lxdebug->leave_sub(); + return; + } + } elsif (!$form->{id}) { + &add; + $main::lxdebug->leave_sub(); + return; } - $form->{employee} = "$form->{employee}--$form->{employee_id}"; - - # sales staff - if (@{ $form->{all_employees} }) { - $form->{selectemployee} = ""; - map { $form->{selectemployee} .= "$_->{name}--$_->{id}\n" } - (@{ $form->{all_employees} }); + my ($language_id, $printer_id); + if ($form->{print_and_save}) { + $form->{action} = "print"; + $form->{resubmit} = 1; + $language_id = $form->{language_id}; + $printer_id = $form->{printer_id}; } - # forex - $form->{forex} = $form->{exchangerate}; + set_headings("edit"); - $lxdebug->leave_sub(); -} + &order_links; -sub prepare_order { - $lxdebug->enter_sub(); - $form->{format} = "pdf"; - $form->{media} = "screen"; - $form->{formname} = $form->{type}; + $form->{rowcount} = 0; + foreach my $ref (@{ $form->{form_details} }) { + $form->{rowcount}++; + map { $form->{"${_}_$form->{rowcount}"} = $ref->{$_} } keys %{$ref}; + } - map { $form->{$_} =~ s/\"/"/g } - qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact); + &prepare_order; - foreach $ref (@{ $form->{form_details} }) { - $form->{rowcount} = ++$i; + if ($form->{print_and_save}) { + $form->{language_id} = $language_id; + $form->{printer_id} = $printer_id; + } - 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"}; - - $form->{"sellprice_$i"} = - $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, - $decimalplaces); - - (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/); - $dec_qty = length $dec_qty; - $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty); - - map { $form->{"${_}_$i"} =~ s/\"/"/g } - qw(partnumber description unit); - } + &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } -sub form_header { - $lxdebug->enter_sub(); - - $checkedopen = ($form->{closed}) ? "" : "checked"; - $checkedclosed = ($form->{closed}) ? "checked" : ""; +sub order_links { + $main::lxdebug->enter_sub(); - # 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"); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - } else { + check_oe_access(); - # without JavaScript Calendar - $button1 = qq| - {transdate}>|; - $button2 = qq| - {reqdate}>|; - } + # get customer/vendor + $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP"); - if ($form->{id}) { - $openclosed = qq| - - - - - | - . $locale->text('Open') . qq| - | - . $locale->text('Closed') . qq| - - - - -|; - } + # retrieve order/quotation + $form->{webdav} = $main::webdav; + $form->{jsscript} = 1; - # 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}/; - } + my $editing = $form->{id}; - #build contacts - if ($form->{all_contacts}) { + OE->retrieve(\%myconfig, \%$form); - $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}"; - } - } - } + # 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) + $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 ''; - $form->{exchangerate} = - $form->format_amount(\%myconfig, $form->{exchangerate}); + $form->{"$form->{vc}_id"} ||= $form->{"all_$form->{vc}"}->[0]->{id} if $form->{"all_$form->{vc}"}; - $form->{creditlimit} = - $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); - $form->{creditremaining} = - $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); + $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes)); + $form->{shipto} = 1 if $form->{id}; - $contact = - ($form->{selectcontact}) - ? qq|$form->{selectcontact}\n| - : qq||; + # get customer / vendor + IR->get_vendor(\%myconfig, \%$form) if $form->{type} =~ /(purchase_order|request_quotation)/; + IS->get_customer(\%myconfig, \%$form) if $form->{type} =~ /sales_(order|quotation)/; - $exchangerate = qq| -{forex}> -|; + $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}"; - 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}>|; - } + # 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"}|; } - $vclabel = ucfirst $form->{vc}; - $vclabel = $locale->text($vclabel); - - $terms = qq| - - | . $locale->text('Terms: Net') . qq| - {terms}> | - . $locale->text('days') . qq| - -|; + $form->{"old$form->{vc}"} = $form->{$form->{vc}}; - if ($form->{business}) { - $business = qq| - - | . $locale->text('Business') . qq| - $form->{business} - | . $locale->text('Trade Discount') . qq| - | - . $form->format_amount(\%myconfig, $form->{tradediscount} * 100) - . qq| % - -|; + if ($form->{"old$form->{vc}"} !~ m/--\d+$/ && $form->{"$form->{vc}_id"}) { + $form->{"old$form->{vc}"} .= qq|--$form->{"$form->{vc}_id"}| } - 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 - - - - | . $locale->text('Required by') . qq| - $button2 - -|; + $main::lxdebug->leave_sub(); +} - $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; - - $creditremaining = qq| - - - - - - | . $locale->text('Credit Limit') . qq| - $form->{creditlimit} - - | . $locale->text('Remaining') . qq| - $form->{creditremaining} - - - - -|; - } else { - $reqlabel = - ($form->{type} eq 'sales_quotation') - ? $locale->text('Valid until') - : $locale->text('Required by'); - if ($form->{type} eq 'sales_quotation') { - $ordnumber = qq| - - | - . $locale->text('Quotation Number') . qq| - - - -|; - } else { - $ordnumber = qq| - - | . $locale->text('RFQ Number') . qq| - - - -|; +sub prepare_order { + $main::lxdebug->enter_sub(); - $terms = ""; - } + my $form = $main::form; + my %myconfig = %main::myconfig; - $ordnumber .= qq| - - | . $locale->text('Quotation Date') . qq| - $button1 - - - $reqlabel - $button2 - -|; + check_oe_access(); - } - - $vc = - ($form->{"select$form->{vc}"}) - ? qq|{vc}>$form->{"select$form->{vc}"}\n{vc}"}">| - : qq|{vc} value="$form->{$form->{vc}}" size=35>|; + $form->{formname} ||= $form->{type}; - $department = qq| - - | . $locale->text('Department') . qq| - $form->{selectdepartment} - - - -| if $form->{selectdepartment}; - - $employee = qq| - -|; + # 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}; - 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} - - - -|; + 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->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}); + $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); } - $form->header; - - print qq| - + $main::lxdebug->leave_sub(); +} -{script}> +sub form_header { + $main::lxdebug->enter_sub(); + my @custom_hiddens; -{id}> + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + my $cgi = $main::cgi; -{type}> -{formname}> -{media}> -{format}> + check_oe_access(); - - - + # Container for template variables. Unfortunately this has to be + # visible in form_footer too, so package local level and not my here. + %TMPL_VAR = (); -{vc}> + $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}; -{discount}> -{creditlimit}> -{creditremaining}> + # 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 + 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}; + $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 + 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, "customer_klass" if $form->{vc} eq 'customer'; + + my $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)"; -{tradediscount}> -{business}> - + if ($form->{id}) { + my $follow_ups = FU->follow_ups('trans_id' => $form->{id}); - - - $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 (scalar @{ $follow_ups }) { + $TMPL_VAR{num_follow_ups} = scalar @{ $follow_ups }; + $TMPL_VAR{num_due_follow_ups} = sum map { $_->{due} * 1 } @{ $follow_ups }; + } + } -$jsscript + my $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')" + : ""; - + $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||; - - - - - - + $form->header; - - + $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$/), + ); - -|; + print $form->parse_html_template("oe/form_header", { %TMPL_VAR }); - foreach $item (split / /, $form->{taxaccounts}) { - print qq| -{"${item}_rate"}> - -|; - } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub form_footer { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $form->{invtotal} = $form->{invsubtotal}; + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - 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}|; + check_oe_access(); - $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + $form->{invtotal} = $form->{invsubtotal}; - $taxincluded = ""; - if ($form->{taxaccounts}) { - $taxincluded = qq| - {taxincluded}> | - . $locale->text('Tax Included') . qq| -|; - } + 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|| . H($form->{notes}) . qq||; + $TMPL_VAR{intnotes} = qq|| . H($form->{intnotes}) . qq||; 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); - - $tax .= qq| - - $form->{"${item}_description"} - $form->{"${item}_total"} - -|; + $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->{invsubtotal} = - $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); +# $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); # template does this - $subtotal = qq| - - | . $locale->text('Subtotal') . qq| - $form->{invsubtotal} - -|; - - } - - if ($form->{taxincluded}) { - foreach $item (split / /, $form->{taxaccounts}) { + } else { + 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); - $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->{"${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| + + Enthaltene $form->{"${item}_description"} | . $form->{"${item}_rate"} * 100 .qq|% + $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| + print $form->parse_html_template("oe/form_footer", { + %TMPL_VAR, + webdav => $main::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$/), + }); + + $main::lxdebug->leave_sub(); +} -{rowcount}> +sub update { + $main::lxdebug->enter_sub(); - + my ($recursive_call) = shift; -{path}> -{login}> -{password}> + my $form = $main::form; + my %myconfig = %main::myconfig; - + check_oe_access(); - -