|
#=====================================================================
|
|
# LX-Office ERP
|
|
# Copyright (C) 2004
|
|
# Based on SQL-Ledger Version 2.1.9
|
|
# Web http://www.lx-office.org
|
|
#
|
|
#=====================================================================
|
|
# SQL-Ledger, Accounting
|
|
# Copyright (c) 1998-2003
|
|
#
|
|
# Author: Dieter Simader
|
|
# Email: dsimader@sql-ledger.org
|
|
# Web: http://www.sql-ledger.org
|
|
#
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# 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., 51 Franklin Street, Fifth Floor, Boston,
|
|
# MA 02110-1335, USA.
|
|
#======================================================================
|
|
#
|
|
# Order entry module
|
|
# Quotation module
|
|
#======================================================================
|
|
|
|
|
|
use Carp;
|
|
use POSIX qw(strftime);
|
|
|
|
use SL::DB::Order;
|
|
use SL::DB::OrderItem;
|
|
use SL::DO;
|
|
use SL::FU;
|
|
use SL::OE;
|
|
use SL::IR;
|
|
use SL::IS;
|
|
use SL::Helper::UserPreferences::DisplayPreferences;
|
|
use SL::MoreCommon qw(ary_diff restore_form save_form);
|
|
use SL::Presenter::ItemsList;
|
|
use SL::ReportGenerator;
|
|
use SL::YAML;
|
|
use List::MoreUtils qw(uniq any none);
|
|
use List::Util qw(min max reduce sum);
|
|
use Data::Dumper;
|
|
|
|
use SL::Controller::Order;
|
|
use SL::DB::Customer;
|
|
use SL::DB::TaxZone;
|
|
use SL::DB::PaymentTerm;
|
|
use SL::DB::ValidityToken;
|
|
use SL::DB::Vendor;
|
|
|
|
require "bin/mozilla/common.pl";
|
|
require "bin/mozilla/io.pl";
|
|
require "bin/mozilla/reportgenerator.pl";
|
|
|
|
use strict;
|
|
|
|
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');
|
|
|
|
# $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_intake' => 'sales_order_edit',
|
|
'sales_order' => 'sales_order_edit',
|
|
'purchase_order' => 'purchase_order_edit',
|
|
'purchase_order_confirmation' => 'purchase_order_edit',
|
|
'request_quotation' => 'request_quotation_edit',
|
|
'sales_quotation' => 'sales_quotation_edit',
|
|
'purchase_quotation_intake' => 'request_quotation_edit',
|
|
};
|
|
|
|
my $oe_view_access_map = {
|
|
'sales_order_intake' => 'sales_order_edit | sales_order_view',
|
|
'sales_order' => 'sales_order_edit | sales_order_view',
|
|
'purchase_order' => 'purchase_order_edit | purchase_order_view',
|
|
'purchase_order_confirmation' => 'purchase_order_edit | purchase_order_view',
|
|
'request_quotation' => 'request_quotation_edit | request_quotation_view',
|
|
'sales_quotation' => 'sales_quotation_edit | sales_quotation_view',
|
|
'purchase_quotation_intake' => 'request_quotation_edit | request_quotation_view',
|
|
};
|
|
|
|
sub check_oe_access {
|
|
my (%params) = @_;
|
|
my $form = $main::form;
|
|
|
|
my $right = ($params{with_view}) ? $oe_view_access_map->{$form->{type}} : $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;
|
|
|
|
$::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} = $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} = $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} = $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} = $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};
|
|
|
|
$form->{show_details} = $::myconfig{show_form_details};
|
|
|
|
order_links(is_new => 1);
|
|
&prepare_order;
|
|
&display_form;
|
|
|
|
$main::lxdebug->leave_sub();
|
|
}
|
|
|
|
sub edit {
|
|
$main::lxdebug->enter_sub();
|
|
|
|
my $form = $main::form;
|
|
|
|
check_oe_access();
|
|
|
|
$form->{show_details} = $::myconfig{show_form_details};
|
|
$form->{taxincluded_changed_by_user} = 1;
|
|
|
|
# show history button
|
|
$form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
|
|
#/show hhistory button
|
|
|
|
$form->{simple_save} = 0;
|
|
|
|
set_headings("edit");
|
|