|
#=====================================================================
|
|
# 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.
|
|
#======================================================================
|
|
#
|
|
# Delivery orders
|
|
#======================================================================
|
|
|
|
use Carp;
|
|
use List::MoreUtils qw(uniq);
|
|
use List::Util qw(max sum);
|
|
use POSIX qw(strftime);
|
|
|
|
use SL::Controller::DeliveryOrder;
|
|
use SL::DB::DeliveryOrder;
|
|
use SL::DB::DeliveryOrderItem;
|
|
use SL::DB::DeliveryOrder::TypeData qw(:types validate_type);
|
|
use SL::DB::ValidityToken;
|
|
use SL::Helper::UserPreferences::DisplayPreferences;
|
|
use SL::DO;
|
|
use SL::IR;
|
|
use SL::IS;
|
|
use SL::MoreCommon qw(ary_diff restore_form save_form);
|
|
use SL::Presenter::ItemsList;
|
|
use SL::ReportGenerator;
|
|
use SL::WH;
|
|
use SL::YAML;
|
|
use Sort::Naturally ();
|
|
require "bin/mozilla/common.pl";
|
|
require "bin/mozilla/io.pl";
|
|
require "bin/mozilla/reportgenerator.pl";
|
|
|
|
use SL::Helper::Flash qw(flash flash_later render_flash);
|
|
|
|
use strict;
|
|
|
|
1;
|
|
|
|
# end of main
|
|
|
|
sub check_do_access_for_edit {
|
|
validate_type($::form->{type});
|
|
|
|
my $right = SL::DB::DeliveryOrder::TypeData::get3($::form->{type}, "rights", "edit");
|
|
$main::auth->assert($right);
|
|
}
|
|
|
|
sub check_do_access {
|
|
validate_type($::form->{type});
|
|
|
|
my $right = SL::DB::DeliveryOrder::TypeData::get3($::form->{type}, "rights", "view");
|
|
$main::auth->assert($right);
|
|
}
|
|
|
|
sub set_headings {
|
|
$main::lxdebug->enter_sub();
|
|
|
|
check_do_access();
|
|
|
|
my ($action) = @_;
|
|
|
|
my $form = $main::form;
|
|
my $locale = $main::locale;
|
|
|
|
if ($form->{type} eq 'purchase_delivery_order') {
|
|
$form->{vc} = 'vendor';
|
|
$form->{title} = $action eq "edit" ? $locale->text('Edit Purchase Delivery Order') : $locale->text('Add Purchase Delivery Order');
|
|
} else {
|
|
$form->{vc} = 'customer';
|
|
$form->{title} = $action eq "edit" ? $locale->text('Edit Sales Delivery Order') : $locale->text('Add Sales Delivery Order');
|
|
}
|
|
|
|
$form->{heading} = $locale->text('Delivery Order');
|
|
|
|
$main::lxdebug->leave_sub();
|
|
}
|
|
|
|
sub add {
|
|
$main::lxdebug->enter_sub();
|
|
|
|
check_do_access_for_edit();
|
|
|
|
if (($::form->{type} =~ /purchase/) && !$::instance_conf->get_allow_new_purchase_invoice) {
|
|
$::form->show_generic_error($::locale->text("You do not have the permissions to access this function."));
|
|
}
|
|
|
|
my $form = $main::form;
|
|
|
|
set_headings("add");
|
|
|
|
$form->{show_details} = $::myconfig{show_form_details};
|
|
$form->{callback} = build_std_url('action=add', 'type', 'vc') unless ($form->{callback});
|
|
|
|
if (!$form->{form_validity_token}) {
|
|
$form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_DELIVERY_ORDER_SAVE())->token;
|
|
}
|
|
|
|
order_links(is_new => 1);
|
|
prepare_order();
|
|
display_form();
|
|
|
|
$main::lxdebug->leave_sub();
|
|
}
|
|
|
|
sub add_from_reclamation {
|
|
|
|
require SL::DB::Reclamation;
|
|
my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load;
|
|
my ($delivery_order, $error) = $reclamation->convert_to_delivery_order();
|
|
if($error) {
|
|
croak("Error while converting: " . $error);
|
|
}
|
|
|
|
# edit new saved delivery order
|
|
$::form->{id} = $delivery_order->id;
|
|
edit();
|
|
}
|
|
|
|
sub edit {
|
|
$main::lxdebug->enter_sub();
|
|
|
|
check_do_access();
|
|
|
|
my $form = $main::form;
|
|
|
|
$form->{show_details} = $::myconfig{show_form_details};
|
|
|
|
# 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");
|
|
|
|
# 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) {
|
|
|
|
# reset rowcount
|
|
undef $form->{rowcount};
|
|
add();
|
|
$main::lxdebug->leave_sub();
|
|
return;
|
|
# }
|
|
} elsif (!$form->{id}) {
|
|
add();
|
|
$main::lxdebug->leave_sub();
|
|
return;
|
|
}
|
|
|
|
my ($language_id, $printer_id);
|
|
if ($form->{print_and_save}) {
|
|
$form->{action} = "dispatcher";
|
|
$form->{action_print} = "1";
|
|
$form->{resubmit} = 1;
|
|
$language_id = $form->{language_id};
|
|
$printer_id = $form->{printer_id};
|
|
}
|
|
|
|
set_headings("edit");
|
|
|
|
order_links();
|
|
prepare_order();
|
|
|
|
if ($form->{print_and_save}) {
|
|
$form->{language_id} = $language_id;
|
|
$form->{printer_id} = $printer_id;
|
|
}
|
|
|
|
display_form();
|
|
|
|
$main::lxdebug->leave_sub();
|
|
}
|
|
|
|
sub order_links {
|
|
$main::lxdebug->enter_sub();
|
|
|
|
check_do_access();
|
|
|
|
my %params = @_;
|
|
my $form = $main::form;
|
|
my %myconfig = %main::myconfig;
|
|
|
|
# retrieve order/quotation
|
|
my $editing = $form->{id};
|
|
|
|
DO->retrieve('vc' => $form->{vc},
|
|
'ids' => $form->{id});
|
|
|
|
$form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes delivery_term_id currency));
|
|
|
|
# get customer / vendor
|
|
if ($form->{vc} eq 'vendor') {
|
|
IR->get_vendor(\%myconfig, \%$form);
|
|
$form->{discount} = $form->{vendor_discount};
|
|
} else {
|
|
IS->get_customer(\%myconfig, \%$form);
|
|
$form->{discount} = $form->{customer_discount};
|
|
$form->{billing_address_id} = $form->{default_billing_address_id} if $params{is_new};
|
|
}
|
|
|
|
$form->restore_vars(qw(payment_id language_id taxzone_id intnotes cp_id delivery_term_id));
|
|
$form->restore_vars(qw(currency)) if ($form->{id} || $form->{convert_from_oe_ids});
|
|
$form->restore_vars(qw(taxincluded)) if $form->{id};
|
|
$form->restore_vars(qw(salesman_id)) if $editing;
|
|
|