Move code of incoterm into the Incoterm Trait.

This commit is contained in:
Laurent Destailleur 2020-09-16 02:50:18 +02:00
parent b7d56cbfbf
commit e5191cad24
14 changed files with 165 additions and 140 deletions

View File

@ -18,7 +18,8 @@ Following changes may create regressions for some external modules, but were nec
* The hidden option HOLIDAY_MORE_PUBLIC_HOLIDAYS has been removed. Use instead the dictionary table if you need to define custom
days of holiday.
* Property num_paiement has been renamed num_payment everywhere for better code consistency.
* If you build a class that implement CommonObject to use the incoterm properties or method (->fk_incoterm, ->label_incoterm, ->location_incoterm),
you must now also include declaration of the Trait CommonIncoterm in your class. All incoterm functions were moved into this Trait.
***** ChangeLog for 12.0.2 compared to 12.0.1 *****
FIX: computation of the bottom margin of <body> returns NaN because body is not loaded yet

View File

@ -41,12 +41,15 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
/**
* Class to manage proposals
*/
class Propal extends CommonObject
{
use CommonIncoterm;
/**
* @var string ID to identify managed object
*/

View File

@ -37,6 +37,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
/**
* Class to manage customers orders
*/

View File

@ -0,0 +1,141 @@
<?php
/* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/class/commonincoterm.class.php
* \ingroup core
* \brief File of the superclass of object classes that support incoterm (customer and supplier)
*/
/**
* Superclass for incoterm classes
*/
trait CommonIncoterm
{
/**
* @var int ID incoterm.
* @see setIncoterms()
*/
public $fk_incoterms;
/**
* @var string Label of incoterm. Used for tooltip.
* @see SetIncoterms()
*/
public $label_incoterms;
/**
* @var string Location of incoterm.
* @see display_incoterms()
*/
public $location_incoterms;
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return incoterms informations
* TODO Use a cache for label get
*
* @return string incoterms info
*/
public function display_incoterms()
{
// phpcs:enable
$out = '';
$this->label_incoterms = '';
if (!empty($this->fk_incoterms))
{
$sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms;
$result = $this->db->query($sql);
if ($result)
{
$res = $this->db->fetch_object($result);
$out .= $res->code;
}
}
$out .= (($out && $this->location_incoterms) ? ' - ' : '').$this->location_incoterms;
return $out;
}
/**
* Return incoterms informations for pdf display
*
* @return string incoterms info
*/
public function getIncotermsForPDF()
{
$sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms;
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
if ($num > 0)
{
$res = $this->db->fetch_object($resql);
return 'Incoterm : '.$res->code.' - '.$this->location_incoterms;
} else {
return '';
}
} else {
$this->errors[] = $this->db->lasterror();
return false;
}
}
/**
* Define incoterms values of current object
*
* @param int $id_incoterm Id of incoterm to set or '' to remove
* @param string $location location of incoterm
* @return int <0 if KO, >0 if OK
*/
public function setIncoterms($id_incoterm, $location)
{
if ($this->id && $this->table_element)
{
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
$sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null");
$sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null");
$sql .= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$this->fk_incoterms = $id_incoterm;
$this->location_incoterms = $location;
$sql = 'SELECT libelle FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms;
$res = $this->db->query($sql);
if ($res)
{
$obj = $this->db->fetch_object($res);
$this->label_incoterms = $obj->libelle;
}
return 1;
} else {
$this->errors[] = $this->db->lasterror();
return -1;
}
} else {
return -1;
}
}
}

View File

@ -24,12 +24,15 @@
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
/**
* Superclass for invoices classes
*/
abstract class CommonInvoice extends CommonObject
{
use CommonIncoterm;
/**
* Standard invoice
*/

View File

@ -393,24 +393,6 @@ abstract class CommonObject
*/
public $comments = array();
/**
* @var int
* @see setIncoterms()
*/
public $fk_incoterms;
/**
* @var string
* @see SetIncoterms()
*/
public $label_incoterms;
/**
* @var string
* @see display_incoterms()
*/
public $location_incoterms;
/**
* @var string The name
*/
@ -3882,98 +3864,6 @@ abstract class CommonObject
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return incoterms informations
* TODO Use a cache for label get
*
* @return string incoterms info
*/
public function display_incoterms()
{
// phpcs:enable
$out = '';
$this->label_incoterms = '';
if (!empty($this->fk_incoterms))
{
$sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms;
$result = $this->db->query($sql);
if ($result)
{
$res = $this->db->fetch_object($result);
$out .= $res->code;
}
}
$out .= (($out && $this->location_incoterms) ? ' - ' : '').$this->location_incoterms;
return $out;
}
/**
* Return incoterms informations for pdf display
*
* @return string incoterms info
*/
public function getIncotermsForPDF()
{
$sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms;
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
if ($num > 0)
{
$res = $this->db->fetch_object($resql);
return 'Incoterm : '.$res->code.' - '.$this->location_incoterms;
} else {
return '';
}
} else {
$this->errors[] = $this->db->lasterror();
return false;
}
}
/**
* Define incoterms values of current object
*
* @param int $id_incoterm Id of incoterm to set or '' to remove
* @param string $location location of incoterm
* @return int <0 if KO, >0 if OK
*/
public function setIncoterms($id_incoterm, $location)
{
if ($this->id && $this->table_element)
{
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
$sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null");
$sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null");
$sql .= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$this->fk_incoterms = $id_incoterm;
$this->location_incoterms = $location;
$sql = 'SELECT libelle FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms;
$res = $this->db->query($sql);
if ($res)
{
$obj = $this->db->fetch_object($res);
$this->label_incoterms = $obj->libelle;
}
return 1;
} else {
$this->errors[] = $this->db->lasterror();
return -1;
}
} else return -1;
}
// --------------------
// TODO: All functions here must be redesigned and moved as they are not business functions but output functions
// --------------------

View File

@ -23,13 +23,14 @@
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
/**
* Superclass for orders classes
*/
abstract class CommonOrder extends CommonObject
{
use CommonIncoterm;
}
/**

View File

@ -64,7 +64,7 @@ $domData .= ' data-qty="'.$line->qty.'"';
$domData .= ' data-product_type="'.$line->product_type.'"';
$sign = 1;
if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && $object->type == $object::TYPE_CREDIT_NOTE) {
if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && in_array($object->element, array('facture', 'invoice_supplier')) && $object->type == $object::TYPE_CREDIT_NOTE) {
$sign = -1;
}

View File

@ -36,6 +36,7 @@
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php";
require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
@ -46,6 +47,8 @@ if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/exped
*/
class Expedition extends CommonObject
{
use CommonIncoterm;
/**
* @var string ID to identify managed object
*/

View File

@ -156,11 +156,6 @@ class CommandeFournisseur extends CommonOrder
public $user_approve_id;
public $user_approve_id2; // Used when SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED is set
//Incoterms
public $fk_incoterms;
public $location_incoterms;
public $label_incoterms; //Used into tooltip
public $extraparams = array();
/**

View File

@ -190,14 +190,6 @@ class FactureFournisseur extends CommonInvoice
*/
public $fournisseur;
/**
* @var int ID Incorterms
*/
public $fk_incoterms;
public $location_incoterms;
public $label_incoterms; //Used into tooltip
public $extraparams = array();
// Multicurrency

View File

@ -34,6 +34,7 @@
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php";
require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
@ -43,6 +44,8 @@ if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/
*/
class Reception extends CommonObject
{
use CommonIncoterm;
public $element = "reception";
public $fk_element = "fk_reception";
public $table_element = "reception";

View File

@ -38,6 +38,7 @@
* \brief File for third party class
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
/**
@ -45,6 +46,8 @@ require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
*/
class Societe extends CommonObject
{
use CommonIncoterm;
/**
* @var string ID to identify managed object
*/
@ -692,20 +695,6 @@ class Societe extends CommonObject
*/
public $logo_squarred_mini;
/**
* @var int ID Incoterms
*/
public $fk_incoterms;
/**
* @var string Incoterms Location
*/
public $location_incoterms;
/**
* @var string Incoterm label
*/
public $label_incoterms; //Used into tooltip
// Multicurrency
/**

View File

@ -41,12 +41,15 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
/**
* Class to manage price ask supplier
*/
class SupplierProposal extends CommonObject
{
use CommonIncoterm;
/**
* @var string ID to identify managed object
*/