X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/4dbb09950c9f5596646537c12d991c99086fe7c1..fbcd5580:/bin/mozilla/oe.pl diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index 91e178dc5..17d9fb500 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -24,7 +24,8 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. #====================================================================== # # Order entry module @@ -32,1410 +33,1150 @@ #====================================================================== +use Carp; +use POSIX qw(strftime); + +use SL::DB::Order; +use SL::DO; +use SL::FU; use SL::OE; use SL::IR; use SL::IS; -use SL::PE; +use SL::MoreCommon qw(ary_diff restore_form save_form); +use SL::ReportGenerator; +use List::MoreUtils qw(uniq any none); +use List::Util qw(min max reduce sum); +use Data::Dumper; + +use SL::DB::Customer; +use SL::DB::TaxZone; +use SL::DB::PaymentTerm; + +require "bin/mozilla/common.pl"; +require "bin/mozilla/io.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 +# 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'); -sub add { - $lxdebug->enter_sub(); +# $locale->text('Workflow purchase_order'); +# $locale->text('Workflow sales_order'); +# $locale->text('Workflow request_quotation'); +# $locale->text('Workflow 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'; - } +my $oe_access_map = { + 'sales_order' => 'sales_order_edit', + 'purchase_order' => 'purchase_order_edit', + 'request_quotation' => 'request_quotation_edit', + 'sales_quotation' => 'sales_quotation_edit', +}; - $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; +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 check_oe_conversion_to_sales_invoice_allowed { + return 1 if $::form->{type} !~ m/^sales/; + return 1 if ($::form->{type} =~ m/quotation/) && $::instance_conf->get_allow_sales_invoice_from_sales_quotation; + return 1 if ($::form->{type} =~ m/order/) && $::instance_conf->get_allow_sales_invoice_from_sales_order; -sub edit { - $lxdebug->enter_sub(); + $::form->show_generic_error($::locale->text("You do not have the permissions to access this function.")); + + return 0; +} + +sub set_headings { + $main::lxdebug->enter_sub(); + + 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'; + $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'; + $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'; + $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'; + $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}; + + $form->{show_details} = $::myconfig{show_form_details}; + &order_links; &prepare_order; &display_form; - - $lxdebug->leave_sub(); + + $main::lxdebug->leave_sub(); } +sub edit { + $main::lxdebug->enter_sub(); + my $form = $main::form; -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; - - # set jscalendar - $form->{jscalendar} = $jscalendar; - - OE->retrieve(\%myconfig, \%$form); + check_oe_access(); + + $form->{show_details} = $::myconfig{show_form_details}; + $form->{taxincluded_changed_by_user} = 1; + + # show history button + $form->{javascript} = qq||; + #/show hhistory button + + $form->{simple_save} = 0; + + set_headings("edit"); - $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}; + # 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) { + + # 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}"} .= "