X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Foe.pl;h=ba4b7b45631be9d0e01c211fa12249ecb84bf8b6;hb=937e37ad007405c6a3a389ee18006379ffecc073;hp=d05745b8ee5e8873ba5d01efa5532ec554ca9f58;hpb=b3721e4e65d62ea30b68b00ac77b4495b1f17337;p=kivitendo-erp.git diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index d05745b8e..ba4b7b456 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,622 @@ # Quotation module #====================================================================== + +use Carp; +use POSIX qw(strftime); + +use SL::DO; +use SL::FU; use SL::OE; use SL::IR; use SL::IS; +use SL::MoreCommon qw(ary_diff); use SL::PE; +use SL::ReportGenerator; +use List::MoreUtils qw(any none); +use List::Util qw(min max reduce sum); +use Data::Dumper; + +use SL::DB::Customer; -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"; + +use strict; + +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'; } + $main::lxdebug->leave_sub(); +} + +sub add { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + + 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; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } -sub order_links { - $lxdebug->enter_sub(); +sub edit { + $main::lxdebug->enter_sub(); - # get customer/vendor - $form->all_vc(\%myconfig, $form->{vc}, - ($form->{vc} eq 'customer') ? "AR" : "AP"); + my $form = $main::form; - # retrieve order/quotation - $form->{webdav} = $webdav; + check_oe_access(); + $form->{taxincluded_changed_by_user} = 1; - # set jscalendar - $form->{jscalendar} = $jscalendar; + # show history button + $form->{javascript} = qq||; + #/show hhistory button - OE->retrieve(\%myconfig, \%$form); + $form->{simple_save} = 0; - # 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("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}) { + my $id; + 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; + $main::lxdebug->leave_sub(); + return; } + } elsif (!$form->{id}) { + &add; + $main::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}"} .= "