X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=bin%2Fmozilla%2Foe.pl;h=41b290a3b7502678027414f35c588d56afec3b9b;hb=018e340ac9f0fc9c4b0bd180bd195e7c0fbd3c0e;hp=d9ccd05a886d95c3bdd6442fe0f0d3062ae1b6bd;hpb=d319704a66e9be64da837ccea10af6774c2b0838;p=kivitendo-erp.git diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index d9ccd05a8..41b290a3b 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -31,73 +31,100 @@ # 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 { - $lxdebug->enter_sub(); - - 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'; - } - - $form->{callback} = - "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&password=$form->{password}" - unless $form->{callback}; - - &order_links; - &prepare_order; - &display_form; - - $lxdebug->leave_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'); + +# $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 edit { +sub set_headings { $lxdebug->enter_sub(); + 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'; } + $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}" + unless $form->{callback}; + &order_links; &prepare_order; &display_form; @@ -105,792 +132,358 @@ sub edit { $lxdebug->leave_sub(); } -sub order_links { +sub edit { $lxdebug->enter_sub(); - # get customer/vendor - $form->all_vc(\%myconfig, $form->{vc}, - ($form->{vc} eq 'customer') ? "AR" : "AP"); + check_oe_access(); - # retrieve order/quotation - $form->{webdav} = $webdav; + # show history button + $form->{javascript} = qq||; + #/show hhistory button - # set jscalendar - $form->{jscalendar} = $jscalendar; + $form->{simple_save} = 0; - OE->retrieve(\%myconfig, \%$form); + set_headings("edit"); - $taxincluded = $form->{taxincluded}; - $form->{shipto} = 1 if $form->{id}; + # editing without stuff to edit? try adding it first + if ($form->{rowcount} && !$form->{print_and_save}) { + map { $id++ if $form->{"multi_id_$_"} } (1 .. $form->{rowcount}); + if (!$id) { - if ($form->{"all_$form->{vc}"}) { - unless ($form->{"$form->{vc}_id"}) { - $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id}; + # reset rowcount + undef $form->{rowcount}; + &add; + $lxdebug->leave_sub(); + return; } + } elsif (!$form->{id}) { + &add; + $lxdebug->leave_sub(); + return; } - $cp_id = $form->{cp_id}; - $intnotes = $form->{intnotes}; - - # 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; - - $form->{intnotes} = $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}"} .= "$_->{name}--$_->{id}\n" } - (@{ $form->{"all_$form->{vc}"} }); + if ($form->{print_and_save}) { + $form->{action} = "print"; + $form->{resubmit} = 1; + $language_id = $form->{language_id}; + $printer_id = $form->{printer_id}; } - # currencies - @curr = split /:/, $form->{currencies}; - chomp $curr[0]; - $form->{defaultcurrency} = $curr[0]; - $form->{currency} = $form->{defaultcurrency} unless $form->{currency}; - - map { $form->{selectcurrency} .= "$_\n" } @curr; + set_headings("edit"); - $form->{taxincluded} = $taxincluded if ($form->{id}); - - # departments - if (@{ $form->{all_departments} }) { - $form->{selectdepartment} = "\n"; - $form->{department} = "$form->{department}--$form->{department_id}"; + &order_links; - map { - $form->{selectdepartment} .= - "$_->{description}--$_->{id}\n" - } (@{ $form->{all_departments} }); + $form->{rowcount} = 0; + foreach $ref (@{ $form->{form_details} }) { + $form->{rowcount}++; + map { $form->{"${_}_$form->{rowcount}"} = $ref->{$_} } keys %{$ref}; } - $form->{employee} = "$form->{employee}--$form->{employee_id}"; + &prepare_order; - # sales staff - if (@{ $form->{all_employees} }) { - $form->{selectemployee} = ""; - map { $form->{selectemployee} .= "$_->{name}--$_->{id}\n" } - (@{ $form->{all_employees} }); + if ($form->{print_and_save}) { + $form->{language_id} = $language_id; + $form->{printer_id} = $printer_id; } - # forex - $form->{forex} = $form->{exchangerate}; + &display_form; $lxdebug->leave_sub(); } -sub prepare_order { +sub order_links { $lxdebug->enter_sub(); - $form->{format} = "html"; - $form->{media} = "screen"; - $form->{formname} = $form->{type}; - - if ($form->{id}) { - - map { $form->{$_} =~ s/\"/"/g } - qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact); - - foreach $ref (@{ $form->{form_details} }) { - $i++; - map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref}; - $form->{"discount_$i"} = - $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100); - ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); - $dec = length $dec; - $decimalplaces = ($dec > 2) ? $dec : 2; + check_oe_access(); - $form->{"sellprice_$i"} = - $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, - $decimalplaces); - $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); - - map { $form->{"${_}_$i"} =~ s/\"/"/g } - qw(partnumber description unit); - $form->{rowcount} = $i; - } - } + # get customer/vendor + $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP"); - $lxdebug->leave_sub(); -} + # retrieve order/quotation + $form->{webdav} = $webdav; + $form->{jsscript} = 1; -sub form_header { - $lxdebug->enter_sub(); + my $editing = $form->{id}; - $checkedopen = ($form->{closed}) ? "" : "checked"; - $checkedclosed = ($form->{closed}) ? "checked" : ""; + OE->retrieve(\%myconfig, \%$form); - # use JavaScript Calendar or not - $form->{jsscript} = $form->{jscalendar}; - $jsscript = ""; + # 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 ''; - 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->{"$form->{vc}_id"} ||= $form->{"all_$form->{vc}"}->[0]->{id} if $form->{"all_$form->{vc}"}; - } else { + $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes)); + $form->{shipto} = 1 if $form->{id}; - # without JavaScript Calendar - $button1 = qq| - {transdate}>|; - $button2 = qq| - {reqdate}>|; - } + # 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)/; - if ($form->{id}) { - $openclosed = qq| - - - - - | - . $locale->text('Open') - . qq| - | - . $locale->text('Closed') - . qq| - - - - -|; - } + $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}"; - # 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}/; + # 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"}|; } - #build contacts - if ($form->{all_contacts}) { - - $form->{selectcontact} = ""; - foreach $item (@{ $form->{all_contacts} }) { - if ($form->{cp_id} == $item->{cp_id}) { - $form->{selectcontact} .= - "$item->{cp_name}--$item->{cp_id}"; - } else { - $form->{selectcontact} .= "$item->{cp_name}--$item->{cp_id}"; - } - } - } + $form->{"old$form->{vc}"} = $form->{$form->{vc}}; + $form->{"old$form->{vc}"} .= qq|--$form->{"$form->{vc}_id"}| unless ($form->{"old$form->{vc}"} =~ m/--\d+$/); - $form->{exchangerate} = - $form->format_amount(\%myconfig, $form->{exchangerate}); + $lxdebug->leave_sub(); +} - $form->{creditlimit} = - $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); - $form->{creditremaining} = - $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); +sub prepare_order { + $lxdebug->enter_sub(); - $contact = - ($form->{selectcontact}) - ? qq|$form->{selectcontact}\n| - : qq||; + check_oe_access(); - $exchangerate = qq| -{forex}> -|; + $form->{formname} ||= $form->{type}; - 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}>|; - } + for my $i (1 .. $form->{rowcount}) { + $form->{"reqdate_$i"} ||= $form->{"deliverydate_$i"}; + $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * ($form->{id} ? 100 : 1)); + $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}); + $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); } - $vclabel = ucfirst $form->{vc}; - $vclabel = $locale->text($vclabel); - - $terms = qq| - - | . $locale->text('Terms: Net') . qq| - {terms}> | - . $locale->text('days') - . qq| - -|; - - if ($form->{business}) { - $business = qq| - - | . $locale->text('Business') . qq| - $form->{business} - | . $locale->text('Trade Discount') . qq| - | - . $form->format_amount(\%myconfig, $form->{tradediscount} * 100) - . qq| % - -|; - } + $lxdebug->leave_sub(); +} - 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 +sub form_header { + $lxdebug->enter_sub(); + my @custom_hiddens; - - - | . $locale->text('Required by') . qq| - $button2 - -|; + check_oe_access(); - $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; + # Container for template variables. Unfortunately this has to be visible in form_footer too, so not my. + our %TMPL_VAR = (); - $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| - - - -|; + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); - $terms = ""; - } + $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id}; + $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id}; - $ordnumber .= qq| - - | . $locale->text('Quotation Date') . qq| - $button1 - - - $reqlabel - $button2 - -|; + # 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, "ordnumber" if $form->{type} =~ /_quotation$/; + push @custom_hiddens, "customer_klass" if $form->{vc} eq 'customer'; - $vc = - ($form->{"select$form->{vc}"}) - ? qq|{vc}>$form->{"select$form->{vc}"}\n{vc}"}">| - : qq|{vc} value="$form->{$form->{vc}}" size=35>|; + $credittext = $locale->text('Credit Limit exceeded!!!'); - $department = qq| - - | . $locale->text('Department') . qq| - $form->{selectdepartment} - - - -| if $form->{selectdepartment}; + 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)"; - $employee = qq| - -|; + if ($form->{id}) { + my $follow_ups = FU->follow_ups('trans_id' => $form->{id}); - if ($form->{type} eq 'sales_order') { - if ($form->{selectemployee}) { - $employee = qq| - - | . $locale->text('Salesperson') . qq| - $form->{selectemployee} - - - -|; + if (scalar @{ $follow_ups }) { + $TMPL_VAR{num_follow_ups} = scalar @{ $follow_ups }; + $TMPL_VAR{num_due_follow_ups} = sum map { $_->{due} * 1 } @{ $follow_ups }; } - } else { - $employee = qq| - - | . $locale->text('Employee') . qq| - $form->{selectemployee} - - - -|; } - $form->header; - - print qq| - - -{script}> - -{id}> - -{type}> -{formname}> -{media}> -{format}> - - - - - -{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()"; - + $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; -{discount}> -{creditlimit}> -{creditremaining}> + $form->{javascript} .= qq||; + $form->{javascript} .= qq||; + $form->{javascript} .= qq||; -{tradediscount}> -{business}> - + $form->header; - - - $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 - - - - - - - -$jsscript + $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(); } sub form_footer { $lxdebug->enter_sub(); - $form->{invtotal} = $form->{invsubtotal}; + check_oe_access(); - 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->{invtotal} = $form->{invsubtotal}; - $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + $rows = max 2, $form->numtextrows($form->{notes}, 25, 8); + $introws = max 2, $form->numtextrows($form->{intnotes}, 35, 8); + $rows = max $rows, $introws; - $taxincluded = ""; - if ($form->{taxaccounts}) { - $taxincluded = qq| - {taxincluded}> | - . $locale->text('Tax Included') - . qq| -|; - } + $TMPL_VAR{notes} = qq|| . H($form->{notes}) . qq||; + $TMPL_VAR{intnotes} = qq|| . H($form->{intnotes}) . 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->{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}_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); - $subtotal = qq| - - | . $locale->text('Subtotal') . qq| - $form->{invsubtotal} - -|; - - } - - if ($form->{taxincluded}) { + } else { 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| + $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"} + 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}> - - - - -|; + 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}"), + }); - if ($webdav) { - $webdav_list = qq| + $lxdebug->leave_sub(); +} - - Dokumente im Webdav-Repository - - - Dateiname - Webdavlink -|; - foreach $file (keys %{ $form->{WEBDAV} }) { - $webdav_list .= qq| - - $file - $form->{WEBDAV}{$file} - -|; - } - $webdav_list .= qq| - - - - - -|; +sub update { + $lxdebug->enter_sub(); + + my ($recursive_call) = shift; - 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} =~ /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 - -|; - } - } - - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print qq| - -{rowcount}> - - - -{path}> -{login}> -{password}> - - - - -