2004-10-20 23:06:45 +02:00
< ? php
2015-05-23 18:52:31 +02:00
/* Copyright ( C ) 2002 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2021-07-16 00:05:00 +02:00
* Copyright ( C ) 2004 - 2021 Laurent Destailleur < eldy @ users . sourceforge . net >
2015-05-23 18:52:31 +02:00
* Copyright ( C ) 2004 Eric Seigne < eric . seigne @ ryxeo . com >
* Copyright ( C ) 2003 Brian Fraval < brian @ fraval . org >
* Copyright ( C ) 2006 Andre Cianfarani < acianfa @ free . fr >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2017 Regis Houssin < regis . houssin @ inodbox . com >
2015-05-23 18:52:31 +02:00
* Copyright ( C ) 2008 Patrick Raguin < patrick . raguin @ auguria . net >
2018-12-01 10:38:40 +01:00
* Copyright ( C ) 2010 - 2018 Juanjo Menent < jmenent @ 2 byte . es >
2015-05-23 18:52:31 +02:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2021-10-08 06:29:22 +02:00
* Copyright ( C ) 2013 - 2021 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2015-05-23 18:52:31 +02:00
* Copyright ( C ) 2013 Peter Fontaine < contact @ peterfontaine . fr >
* Copyright ( C ) 2014 - 2015 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2017-09-20 13:30:59 +02:00
* Copyright ( C ) 2017 Rui Strecht < rui . strecht @ aliartalentos . com >
2018-11-01 11:50:55 +01:00
* Copyright ( C ) 2018 Philippe Grand < philippe . grand @ atoo - net . com >
2020-04-14 07:01:53 +02:00
* Copyright ( C ) 2019 - 2020 Josep Lluís Amador < joseplluis @ lliuretic . cat >
2021-03-20 11:38:53 +01:00
* Copyright ( C ) 2019 - 2021 Frédéric France < frederic . france @ netlogic . fr >
2020-04-27 17:35:14 +02:00
* Copyright ( C ) 2020 Open - Dsi < support @ open - dsi . fr >
2005-10-05 15:05:30 +02:00
*
2002-04-30 12:51:35 +02:00
* 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2002-04-30 12:51:35 +02:00
* ( 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2002-04-30 12:51:35 +02:00
*/
2004-12-31 18:29:28 +01:00
/**
2010-07-21 14:35:56 +02:00
* \file htdocs / societe / class / societe . class . php
2008-10-25 23:18:53 +02:00
* \ingroup societe
2009-05-05 03:16:04 +02:00
* \brief File for third party class
2008-07-19 18:53:56 +02:00
*/
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
2020-09-16 02:50:18 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonincoterm.class.php' ;
2016-02-16 20:44:23 +01:00
require_once DOL_DOCUMENT_ROOT . '/multicurrency/class/multicurrency.class.php' ;
2004-08-28 14:19:06 +02:00
2022-02-28 19:45:53 +01:00
2005-01-17 13:34:00 +01:00
/**
2012-03-11 21:45:17 +01:00
* Class to manage third parties objects ( customers , suppliers , prospects ... )
2008-07-19 18:53:56 +02:00
*/
2008-02-24 15:41:07 +01:00
class Societe extends CommonObject
2006-03-16 02:03:55 +01:00
{
2020-09-16 02:50:18 +02:00
use CommonIncoterm ;
2018-08-23 18:52:47 +02:00
/**
* @ var string ID to identify managed object
*/
2019-11-13 18:32:11 +01:00
public $element = 'societe' ;
2018-08-31 11:29:30 +02:00
2018-08-22 19:56:24 +02:00
/**
* @ var string Name of table without prefix where object is stored
*/
2017-10-13 13:28:26 +02:00
public $table_element = 'societe' ;
2018-08-31 11:29:30 +02:00
2018-09-01 15:27:55 +02:00
/**
2020-12-05 23:53:55 +01:00
* @ var string Field with ID of parent key if this field has a parent or for child tables
2018-09-01 15:27:55 +02:00
*/
2019-11-13 18:32:11 +01:00
public $fk_element = 'fk_soc' ;
2018-09-01 15:27:55 +02:00
2020-10-31 14:32:18 +01:00
/**
* @ var string Fields for combobox
*/
2019-11-13 18:32:11 +01:00
public $fieldsforcombobox = 'nom,name_alias' ;
2019-06-22 20:17:40 +02:00
/**
* @ var array List of child tables . To test if we can delete object .
*/
2019-12-08 14:26:59 +01:00
protected $childtables = array (
2022-03-26 08:32:20 +01:00
'supplier_proposal' => array ( 'name' => 'SupplierProposal' ),
'propal' => array ( 'name' => 'Proposal' ),
'commande' => array ( 'name' => 'Order' ),
'facture' => array ( 'name' => 'Invoice' ),
'facture_rec' => array ( 'name' => 'RecurringInvoiceTemplate' ),
'contrat' => array ( 'name' => 'Contract' ),
'fichinter' => array ( 'name' => 'Fichinter' ),
'facture_fourn' => array ( 'name' => 'SupplierInvoice' ),
'commande_fournisseur' => array ( 'name' => 'SupplierOrder' ),
'projet' => array ( 'name' => 'Project' ),
'expedition' => array ( 'name' => 'Shipment' ),
'prelevement_lignes' => array ( 'name' => 'DirectDebitRecord' ),
2019-12-08 14:26:59 +01:00
);
2019-06-22 20:17:40 +02:00
/**
2020-06-01 10:43:57 +02:00
* @ var array List of child tables . To know object to delete on cascade .
2021-06-10 12:59:04 +02:00
* if name like with @ ClassName : FilePathClass : ParentFkFieldName ' it will call method deleteByParentField ( with parentId as parameters ) and FieldName to fetch and delete child object
2019-06-22 20:17:40 +02:00
*/
2019-12-08 14:26:59 +01:00
protected $childtablesoncascade = array (
2022-03-26 08:32:20 +01:00
'societe_prices' ,
'societe_address' ,
'product_fournisseur_price' ,
'product_customer_price_log' ,
'product_customer_price' ,
'@Contact:/contact/class/contact.class.php:fk_soc' ,
'adherent' ,
'societe_account' ,
'societe_rib' ,
'societe_remise' ,
'societe_remise_except' ,
'societe_commerciaux' ,
'categorie' ,
'notify' ,
'notify_def' ,
'actioncomm' ,
2019-12-08 14:26:59 +01:00
);
2019-06-22 20:17:40 +02:00
2019-10-30 10:10:22 +01:00
/**
* @ var string String with name of icon for myobject . Must be the part after the 'object_' into object_myobject . png
*/
2017-11-02 15:03:09 +01:00
public $picto = 'company' ;
2014-05-03 13:19:03 +02:00
2017-09-10 19:28:20 +02:00
/**
2017-10-13 13:28:26 +02:00
* 0 = No test on entity , 1 = Test with field entity , 2 = Test with link by societe
* @ var int
*/
2017-10-25 22:02:07 +02:00
public $ismultientitymanaged = 1 ;
2018-10-06 12:18:03 +02:00
2017-12-18 15:39:40 +01:00
/**
* 0 = Default , 1 = View may be restricted to sales representative only if no permission to see all or to company of external user if external user
* @ var integer
*/
public $restrictiononfksoc = 1 ;
2017-10-25 22:02:07 +02:00
2021-02-05 17:29:11 +01:00
/**
* 'type' field format ( 'integer' , 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]' , 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]' , 'varchar(x)' , 'double(24,8)' , 'real' , 'price' , 'text' , 'text:none' , 'html' , 'date' , 'datetime' , 'timestamp' , 'duration' , 'mail' , 'phone' , 'url' , 'password' )
* Note : Filter can be a string like " (t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL) "
* 'label' the translation key .
* 'picto' is code of a picto to show before value in forms
* 'enabled' is a condition when the field must be managed ( Example : 1 or ' $conf -> global -> MY_SETUP_PARAM )
* 'position' is the sort order of field .
* 'notnull' is set to 1 if not null in database . Set to - 1 if we must set data to null if empty ( '' or 0 ) .
* 'visible' says if field is visible in list ( Examples : 0 = Not visible , 1 = Visible on list and create / update / view forms , 2 = Visible on list only , 3 = Visible on create / update / view form only ( not list ), 4 = Visible on list and update / view form only ( not create ) . 5 = Visible on list and view only ( not create / not update ) . Using a negative value means field is not shown by default on list but can be selected for viewing )
* 'noteditable' says if field is not editable ( 1 or 0 )
* 'default' is a default value for creation ( can still be overwrote by the Setup of Default Values if field is editable in creation form ) . Note : If default is set to '(PROV)' and field is 'ref' , the default value will be set to '(PROVid)' where id is rowid when a new record is created .
* 'index' if we want an index in database .
* 'foreignkey' => 'tablename.field' if the field is a foreign key ( it is recommanded to name the field fk_ ... ) .
* 'searchall' is 1 if we want to search in this field when making a search from the quick search button .
* 'isameasure' must be set to 1 if you want to have a total on list for this field . Field type must be summable like integer or double ( 24 , 8 ) .
* 'css' and 'cssview' and 'csslist' is the CSS style to use on field . 'css' is used in creation and update . 'cssview' is used in view mode . 'csslist' is used for columns in lists . For example : 'maxwidth200' , 'wordbreak' , 'tdoverflowmax200'
* 'help' is a 'TranslationString' to use to show a tooltip on field . You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click .
* 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
* 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute . In most cases , this is never set into the definition of $fields into class , but is set dynamically by some part of code .
2021-04-29 12:10:55 +02:00
* 'arrayofkeyval' to set list of value if type is a list of predefined values . For example : array ( " 0 " => " Draft " , " 1 " => " Active " , " -1 " => " Cancel " )
2021-02-05 17:29:11 +01:00
* 'autofocusoncreate' to have field having the focus on a create form . Only 1 field should have this property set to 1.
* 'comment' is not used . You can store here any text of your choice . It is not used by application .
*
* Note : To have value dynamic , you can set value to 0 in definition and edit the value on the fly into the constructor .
*/
2017-10-25 22:02:07 +02:00
/**
* @ var array Array with all fields and their property . Do not use it as a static var . It may be modified by constructor .
*/
2019-11-13 18:32:11 +01:00
public $fields = array (
2020-02-08 11:32:38 +01:00
'rowid' => array ( 'type' => 'integer' , 'label' => 'TechnicalID' , 'enabled' => 1 , 'visible' =>- 1 , 'notnull' => 1 , 'position' => 10 ),
'parent' => array ( 'type' => 'integer' , 'label' => 'Parent' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 20 ),
'tms' => array ( 'type' => 'timestamp' , 'label' => 'DateModification' , 'enabled' => 1 , 'visible' =>- 1 , 'notnull' => 1 , 'position' => 25 ),
'datec' => array ( 'type' => 'datetime' , 'label' => 'DateCreation' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 30 ),
2020-02-11 16:42:48 +01:00
'nom' => array ( 'type' => 'varchar(128)' , 'label' => 'Nom' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 35 , 'showoncombobox' => 1 ),
2021-06-05 15:14:10 +02:00
'name_alias' => array ( 'type' => 'varchar(128)' , 'label' => 'Name alias' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 36 , 'showoncombobox' => 2 ),
2020-02-08 11:32:38 +01:00
'entity' => array ( 'type' => 'integer' , 'label' => 'Entity' , 'default' => 1 , 'enabled' => 1 , 'visible' =>- 2 , 'notnull' => 1 , 'position' => 40 , 'index' => 1 ),
2020-04-13 01:10:35 +02:00
'ref_ext' => array ( 'type' => 'varchar(255)' , 'label' => 'RefExt' , 'enabled' => 1 , 'visible' => 0 , 'position' => 45 ),
'code_client' => array ( 'type' => 'varchar(24)' , 'label' => 'CustomerCode' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 55 ),
'code_fournisseur' => array ( 'type' => 'varchar(24)' , 'label' => 'SupplierCode' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 60 ),
'code_compta' => array ( 'type' => 'varchar(24)' , 'label' => 'CodeCompta' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 65 ),
'code_compta_fournisseur' => array ( 'type' => 'varchar(24)' , 'label' => 'CodeComptaSupplier' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 70 ),
2020-02-08 11:32:38 +01:00
'address' => array ( 'type' => 'varchar(255)' , 'label' => 'Address' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 75 ),
'zip' => array ( 'type' => 'varchar(25)' , 'label' => 'Zip' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 80 ),
'town' => array ( 'type' => 'varchar(50)' , 'label' => 'Town' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 85 ),
2020-04-13 01:10:35 +02:00
'fk_departement' => array ( 'type' => 'integer' , 'label' => 'State' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 90 ),
'fk_pays' => array ( 'type' => 'integer:Ccountry:core/class/ccountry.class.php' , 'label' => 'Country' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 95 ),
2020-02-08 11:32:38 +01:00
'phone' => array ( 'type' => 'varchar(20)' , 'label' => 'Phone' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 100 ),
'fax' => array ( 'type' => 'varchar(20)' , 'label' => 'Fax' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 105 ),
'url' => array ( 'type' => 'varchar(255)' , 'label' => 'Url' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 110 ),
'email' => array ( 'type' => 'varchar(128)' , 'label' => 'Email' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 115 ),
'socialnetworks' => array ( 'type' => 'text' , 'label' => 'Socialnetworks' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 120 ),
2020-10-06 09:31:54 +02:00
'fk_effectif' => array ( 'type' => 'integer' , 'label' => 'Workforce' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 170 ),
2021-02-05 17:29:11 +01:00
'fk_typent' => array ( 'type' => 'integer' , 'label' => 'TypeOfCompany' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 175 , 'csslist' => 'minwidth200' ),
2020-04-13 01:10:35 +02:00
'fk_forme_juridique' => array ( 'type' => 'integer' , 'label' => 'JuridicalStatus' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 180 ),
'fk_currency' => array ( 'type' => 'varchar(3)' , 'label' => 'Currency' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 185 ),
2020-02-08 11:32:38 +01:00
'siren' => array ( 'type' => 'varchar(128)' , 'label' => 'Idprof1' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 190 ),
'siret' => array ( 'type' => 'varchar(128)' , 'label' => 'Idprof2' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 195 ),
'ape' => array ( 'type' => 'varchar(128)' , 'label' => 'Idprof3' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 200 ),
'idprof4' => array ( 'type' => 'varchar(128)' , 'label' => 'Idprof4' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 205 ),
'idprof5' => array ( 'type' => 'varchar(128)' , 'label' => 'Idprof5' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 206 ),
'idprof6' => array ( 'type' => 'varchar(128)' , 'label' => 'Idprof6' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 207 ),
'tva_intra' => array ( 'type' => 'varchar(20)' , 'label' => 'Tva intra' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 210 ),
'capital' => array ( 'type' => 'double(24,8)' , 'label' => 'Capital' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 215 ),
2020-10-06 09:31:54 +02:00
'fk_stcomm' => array ( 'type' => 'integer' , 'label' => 'CommercialStatus' , 'enabled' => 1 , 'visible' =>- 1 , 'notnull' => 1 , 'position' => 220 ),
2022-04-06 21:08:23 +02:00
'note_public' => array ( 'type' => 'text' , 'label' => 'NotePublic' , 'enabled' => 1 , 'visible' => 0 , 'position' => 225 ),
'note_private' => array ( 'type' => 'text' , 'label' => 'NotePrivate' , 'enabled' => 1 , 'visible' => 0 , 'position' => 230 ),
2020-02-08 11:32:38 +01:00
'prefix_comm' => array ( 'type' => 'varchar(5)' , 'label' => 'Prefix comm' , 'enabled' => '$conf->global->SOCIETE_USEPREFIX' , 'visible' =>- 1 , 'position' => 235 ),
'client' => array ( 'type' => 'tinyint(4)' , 'label' => 'Client' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 240 ),
'fournisseur' => array ( 'type' => 'tinyint(4)' , 'label' => 'Fournisseur' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 245 ),
'supplier_account' => array ( 'type' => 'varchar(32)' , 'label' => 'Supplier account' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 250 ),
'fk_prospectlevel' => array ( 'type' => 'varchar(12)' , 'label' => 'ProspectLevel' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 255 ),
'customer_bad' => array ( 'type' => 'tinyint(4)' , 'label' => 'Customer bad' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 260 ),
'customer_rate' => array ( 'type' => 'double' , 'label' => 'Customer rate' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 265 ),
'supplier_rate' => array ( 'type' => 'double' , 'label' => 'Supplier rate' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 270 ),
'fk_user_creat' => array ( 'type' => 'integer:User:user/class/user.class.php' , 'label' => 'UserAuthor' , 'enabled' => 1 , 'visible' =>- 2 , 'position' => 275 ),
'fk_user_modif' => array ( 'type' => 'integer:User:user/class/user.class.php' , 'label' => 'UserModif' , 'enabled' => 1 , 'visible' =>- 2 , 'notnull' =>- 1 , 'position' => 280 ),
//'remise_client' =>array('type'=>'double', 'label'=>'CustomerDiscount', 'enabled'=>1, 'visible'=>-1, 'position'=>285, 'isameasure'=>1),
//'remise_supplier' =>array('type'=>'double', 'label'=>'SupplierDiscount', 'enabled'=>1, 'visible'=>-1, 'position'=>290, 'isameasure'=>1),
'mode_reglement' => array ( 'type' => 'tinyint(4)' , 'label' => 'Mode reglement' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 295 ),
'cond_reglement' => array ( 'type' => 'tinyint(4)' , 'label' => 'Cond reglement' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 300 ),
2021-10-28 16:53:28 +02:00
'deposit_percent' => array ( 'type' => 'varchar(63)' , 'label' => 'DepositPercent' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 301 ),
2020-02-08 11:32:38 +01:00
'mode_reglement_supplier' => array ( 'type' => 'integer' , 'label' => 'Mode reglement supplier' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 305 ),
2021-12-09 17:19:31 +01:00
'cond_reglement_supplier' => array ( 'type' => 'integer' , 'label' => 'Cond reglement supplier' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 308 ),
2020-02-08 11:34:25 +01:00
'outstanding_limit' => array ( 'type' => 'double(24,8)' , 'label' => 'OutstandingBill' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 310 , 'isameasure' => 1 ),
2020-02-08 11:32:38 +01:00
'order_min_amount' => array ( 'type' => 'double(24,8)' , 'label' => 'Order min amount' , 'enabled' => '!empty($conf->commande->enabled) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)' , 'visible' =>- 1 , 'position' => 315 , 'isameasure' => 1 ),
'supplier_order_min_amount' => array ( 'type' => 'double(24,8)' , 'label' => 'Supplier order min amount' , 'enabled' => '!empty($conf->commande->enabled) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)' , 'visible' =>- 1 , 'position' => 320 , 'isameasure' => 1 ),
'fk_shipping_method' => array ( 'type' => 'integer' , 'label' => 'Fk shipping method' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 330 ),
'tva_assuj' => array ( 'type' => 'tinyint(4)' , 'label' => 'Tva assuj' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 335 ),
'localtax1_assuj' => array ( 'type' => 'tinyint(4)' , 'label' => 'Localtax1 assuj' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 340 ),
'localtax1_value' => array ( 'type' => 'double(6,3)' , 'label' => 'Localtax1 value' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 345 ),
'localtax2_assuj' => array ( 'type' => 'tinyint(4)' , 'label' => 'Localtax2 assuj' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 350 ),
'localtax2_value' => array ( 'type' => 'double(6,3)' , 'label' => 'Localtax2 value' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 355 ),
'barcode' => array ( 'type' => 'varchar(255)' , 'label' => 'Barcode' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 360 ),
'price_level' => array ( 'type' => 'integer' , 'label' => 'Price level' , 'enabled' => '$conf->global->PRODUIT_MULTIPRICES || $conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES' , 'visible' =>- 1 , 'position' => 365 ),
'default_lang' => array ( 'type' => 'varchar(6)' , 'label' => 'Default lang' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 370 ),
'canvas' => array ( 'type' => 'varchar(32)' , 'label' => 'Canvas' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 375 ),
'fk_barcode_type' => array ( 'type' => 'integer' , 'label' => 'Fk barcode type' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 405 ),
'webservices_url' => array ( 'type' => 'varchar(255)' , 'label' => 'Webservices url' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 410 ),
'webservices_key' => array ( 'type' => 'varchar(128)' , 'label' => 'Webservices key' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 415 ),
'fk_incoterms' => array ( 'type' => 'integer' , 'label' => 'Fk incoterms' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 425 ),
'location_incoterms' => array ( 'type' => 'varchar(255)' , 'label' => 'Location incoterms' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 430 ),
'model_pdf' => array ( 'type' => 'varchar(255)' , 'label' => 'Model pdf' , 'enabled' => 1 , 'visible' => 0 , 'position' => 435 ),
'fk_multicurrency' => array ( 'type' => 'integer' , 'label' => 'Fk multicurrency' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 440 ),
'multicurrency_code' => array ( 'type' => 'varchar(255)' , 'label' => 'Multicurrency code' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 445 ),
2021-04-14 12:02:56 +02:00
'fk_account' => array ( 'type' => 'integer' , 'label' => 'AccountingAccount' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 450 ),
'fk_warehouse' => array ( 'type' => 'integer' , 'label' => 'Warehouse' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 455 ),
2020-02-08 11:32:38 +01:00
'logo' => array ( 'type' => 'varchar(255)' , 'label' => 'Logo' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 400 ),
'logo_squarred' => array ( 'type' => 'varchar(255)' , 'label' => 'Logo squarred' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 401 ),
'status' => array ( 'type' => 'tinyint(4)' , 'label' => 'Status' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 500 ),
'import_key' => array ( 'type' => 'varchar(14)' , 'label' => 'ImportId' , 'enabled' => 1 , 'visible' =>- 2 , 'position' => 1000 ),
2017-10-25 22:02:07 +02:00
);
2018-08-31 18:27:16 +02:00
/**
* @ var int Entity
*/
2017-10-13 13:28:26 +02:00
public $entity ;
2014-05-03 13:19:03 +02:00
2017-10-13 13:28:26 +02:00
/**
* Thirdparty name
* @ var string
* @ deprecated Use $name instead
2018-10-12 19:08:06 +02:00
* @ see $name
2017-10-13 13:28:26 +02:00
*/
public $nom ;
2014-07-20 15:34:33 +02:00
2018-09-20 17:26:39 +02:00
/**
2019-12-08 14:26:59 +01:00
* @ var string Thirdparty name
2018-09-20 17:26:39 +02:00
*/
public $name ;
2015-02-27 15:08:08 +01:00
/**
2015-06-16 12:04:11 +02:00
* Alias names ( commercial , trademark or alias names )
2015-02-27 15:08:08 +01:00
* @ var string
*/
2015-06-16 12:04:11 +02:00
public $name_alias ;
2015-02-27 15:08:08 +01:00
2020-10-31 14:32:18 +01:00
/**
* @ var int Physical thirdparty not a company
*/
2017-10-13 13:28:26 +02:00
public $particulier ;
2018-10-05 16:04:10 +02:00
/**
* @ var string Address
*/
2017-10-13 13:28:26 +02:00
public $address ;
2018-10-05 16:04:10 +02:00
2020-10-31 14:32:18 +01:00
/**
* @ var string Zip code of thirdparty
*/
2017-10-13 13:28:26 +02:00
public $zip ;
2019-12-08 14:26:59 +01:00
2020-10-31 14:32:18 +01:00
/**
* @ var string Town of thirdparty
*/
2017-10-13 13:28:26 +02:00
public $town ;
/**
* Thirdparty status : 0 = activity ceased , 1 = in activity
* @ var int
*/
2019-11-13 18:32:11 +01:00
public $status = 1 ;
2017-10-13 13:28:26 +02:00
/**
* Id of department
* @ var int
*/
2018-04-21 15:08:46 +02:00
public $state_id ;
2019-12-08 14:26:59 +01:00
2020-10-31 14:32:18 +01:00
/**
* @ var string State code
*/
2018-04-21 15:08:46 +02:00
public $state_code ;
2019-12-08 14:26:59 +01:00
2020-10-31 14:32:18 +01:00
/**
* @ var string State name
*/
2018-04-21 15:08:46 +02:00
public $state ;
2017-10-13 13:28:26 +02:00
2018-02-06 13:01:54 +01:00
/**
* Id of region
* @ var int
*/
2018-04-21 15:08:46 +02:00
public $region_code ;
2019-12-08 14:26:59 +01:00
2020-10-31 14:32:18 +01:00
/**
* @ var string Region name
*/
2018-04-21 15:08:46 +02:00
public $region ;
2018-02-06 13:01:54 +01:00
2017-10-13 13:28:26 +02:00
/**
2019-12-08 14:26:59 +01:00
* @ var string State code
2017-10-13 13:28:26 +02:00
* @ deprecated Use state_code instead
2018-10-12 19:08:06 +02:00
* @ see $state_code
2017-10-13 13:28:26 +02:00
*/
2018-04-21 15:08:46 +02:00
public $departement_code ;
2017-10-13 13:28:26 +02:00
/**
* @ var string
* @ deprecated Use state instead
2018-10-12 19:08:06 +02:00
* @ see $state
2017-10-13 13:28:26 +02:00
*/
2018-04-21 15:08:46 +02:00
public $departement ;
2017-10-13 13:28:26 +02:00
/**
* @ var string
* @ deprecated Use country instead
2018-10-12 19:08:06 +02:00
* @ see $country
2017-10-13 13:28:26 +02:00
*/
2018-04-21 15:08:46 +02:00
public $pays ;
2010-09-02 22:06:52 +02:00
2014-05-05 12:53:46 +02:00
/**
* Phone number
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $phone ;
2014-05-05 12:53:46 +02:00
/**
* Fax number
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $fax ;
2014-05-05 12:53:46 +02:00
/**
* Email
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $email ;
2019-09-12 18:04:24 +02:00
2020-10-31 14:32:18 +01:00
/**
* @ var array array of socialnetworks
*/
public $socialnetworks ;
2019-09-12 18:04:24 +02:00
2014-05-05 12:53:46 +02:00
/**
* Skype username
* @ var string
2019-09-12 18:04:24 +02:00
* @ deprecated
2014-05-05 12:53:46 +02:00
*/
2018-04-21 15:08:46 +02:00
public $skype ;
2019-09-12 18:04:24 +02:00
2018-09-26 16:55:46 +02:00
/**
* Twitter username
* @ var string
2019-09-12 18:04:24 +02:00
* @ deprecated
2018-09-26 16:55:46 +02:00
*/
public $twitter ;
2019-12-08 14:26:59 +01:00
2018-09-26 16:55:46 +02:00
/**
* Facebook username
* @ var string
2019-09-12 18:04:24 +02:00
* @ deprecated
2018-09-26 16:55:46 +02:00
*/
public $facebook ;
2019-12-08 14:26:59 +01:00
2020-10-31 14:32:18 +01:00
/**
* LinkedIn username
* @ var string
2019-09-12 18:04:24 +02:00
* @ deprecated
2020-10-31 14:32:18 +01:00
*/
2019-12-08 14:26:59 +01:00
public $linkedin ;
2014-05-05 12:53:46 +02:00
/**
* Webpage
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $url ;
2011-12-07 15:06:29 +01:00
2017-10-13 13:28:26 +02:00
/**
* Barcode value
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $barcode ;
2017-10-13 13:28:26 +02:00
// 6 professional id (usage depends on country)
/**
* Professional ID 1 ( Ex : Siren in France )
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $idprof1 ;
2017-10-13 13:28:26 +02:00
2022-05-21 22:52:27 +02:00
/**
* @ var string Professional ID 1
* @ deprecated
* @ see $idprof1
*/
public $siren ;
2017-10-13 13:28:26 +02:00
/**
* Professional ID 2 ( Ex : Siret in France )
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $idprof2 ;
2017-10-13 13:28:26 +02:00
2022-05-21 23:02:15 +02:00
/**
* @ var string Professional ID 2
* @ deprecated
* @ see $idprof2
*/
public $siret ;
2017-10-13 13:28:26 +02:00
/**
* Professional ID 3 ( Ex : Ape in France )
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $idprof3 ;
2017-10-13 13:28:26 +02:00
2022-05-21 23:04:25 +02:00
/**
* @ var string Professional ID 3
* @ deprecated
* @ see $idprof3
*/
public $ape ;
2017-10-13 13:28:26 +02:00
/**
* Professional ID 4 ( Ex : RCS in France )
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $idprof4 ;
2017-10-13 13:28:26 +02:00
/**
* Professional ID 5
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $idprof5 ;
2017-10-13 13:28:26 +02:00
/**
* Professional ID 6
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $idprof6 ;
2017-10-13 13:28:26 +02:00
2020-10-31 14:32:18 +01:00
/**
* @ var string Prefix comm
*/
2018-04-21 15:08:46 +02:00
public $prefix_comm ;
2017-10-13 13:28:26 +02:00
2019-12-08 14:26:59 +01:00
/**
* @ var int Vat concerned
*/
2019-11-13 18:32:11 +01:00
public $tva_assuj = 1 ;
2019-12-08 14:26:59 +01:00
2017-10-13 13:28:26 +02:00
/**
* Intracommunitary VAT ID
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $tva_intra ;
2017-10-13 13:28:26 +02:00
// Local taxes
2018-04-21 15:08:46 +02:00
public $localtax1_assuj ;
public $localtax1_value ;
public $localtax2_assuj ;
public $localtax2_value ;
2020-10-31 14:32:18 +01:00
/**
* @ var string Manager
*/
2018-04-21 15:08:46 +02:00
public $managers ;
2019-12-08 14:26:59 +01:00
2020-10-31 14:32:18 +01:00
/**
* @ var float Capital
*/
2018-04-21 15:08:46 +02:00
public $capital ;
2019-12-08 14:26:59 +01:00
/**
* @ var int Type thirdparty
*/
2019-11-13 18:32:11 +01:00
public $typent_id = 0 ;
2018-04-21 15:08:46 +02:00
public $typent_code ;
public $effectif ;
2019-11-13 18:32:11 +01:00
public $effectif_id = 0 ;
2018-04-21 15:08:46 +02:00
public $forme_juridique_code ;
2019-11-13 18:32:11 +01:00
public $forme_juridique = 0 ;
2018-04-21 15:08:46 +02:00
public $remise_percent ;
public $remise_supplier_percent ;
2021-05-12 14:19:12 +02:00
2021-09-29 12:05:38 +02:00
public $mode_reglement_id ;
public $cond_reglement_id ;
public $deposit_percent ;
2018-04-21 15:08:46 +02:00
public $mode_reglement_supplier_id ;
public $cond_reglement_supplier_id ;
2020-10-31 14:32:18 +01:00
public $transport_mode_supplier_id ;
2018-10-12 09:34:54 +02:00
/**
2020-10-31 14:32:18 +01:00
* @ var int ID
*/
2018-04-21 15:08:46 +02:00
public $fk_prospectlevel ;
2018-10-12 09:34:54 +02:00
2019-12-08 14:26:59 +01:00
/**
* @ var string second name
*/
2018-04-21 15:08:46 +02:00
public $name_bis ;
2014-05-05 12:53:46 +02:00
//Log data
/**
* Date of last update
2022-05-18 11:23:21 +02:00
* @ var integer | string
2014-05-05 12:53:46 +02:00
*/
2018-04-21 15:08:46 +02:00
public $date_modification ;
2019-12-08 14:26:59 +01:00
2014-05-05 12:53:46 +02:00
/**
* User that made last update
2022-05-18 11:23:21 +02:00
* @ var User
2014-05-05 12:53:46 +02:00
*/
2018-04-21 15:08:46 +02:00
public $user_modification ;
2019-11-02 10:39:05 +01:00
2014-05-05 12:53:46 +02:00
/**
2022-05-18 11:23:21 +02:00
* Date of creation
* @ var integer | string
2014-05-05 12:53:46 +02:00
*/
2018-04-21 15:08:46 +02:00
public $date_creation ;
2019-11-02 10:39:05 +01:00
2014-05-05 12:53:46 +02:00
/**
* User that created the thirdparty
2017-10-13 13:28:26 +02:00
* @ var User
2014-05-05 12:53:46 +02:00
*/
2018-04-21 15:08:46 +02:00
public $user_creation ;
2014-05-05 12:53:46 +02:00
2017-10-13 13:28:26 +02:00
/**
* 0 = no customer , 1 = customer , 2 = prospect , 3 = customer and prospect
* @ var int
*/
2019-11-13 18:32:11 +01:00
public $client = 0 ;
2019-12-08 14:26:59 +01:00
2017-10-13 13:28:26 +02:00
/**
* 0 = no prospect , 1 = prospect
* @ var int
*/
2019-11-13 18:32:11 +01:00
public $prospect = 0 ;
2019-12-08 14:26:59 +01:00
2017-10-13 13:28:26 +02:00
/**
* 0 = no supplier , 1 = supplier
* @ var int
*/
2018-04-21 15:08:46 +02:00
public $fournisseur ;
2015-02-09 17:55:43 +01:00
2017-10-13 13:28:26 +02:00
/**
* Client code . E . g : CU2014 - 003
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $code_client ;
2016-07-07 12:19:20 +02:00
2017-10-13 13:28:26 +02:00
/**
* Supplier code . E . g : SU2014 - 003
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $code_fournisseur ;
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
/**
* Accounting code for client
* @ var string
*/
2022-01-13 19:41:52 +01:00
public $code_compta_client ;
2011-12-07 15:06:29 +01:00
2020-10-31 14:32:18 +01:00
/**
2022-01-13 19:41:52 +01:00
* Duplicate of code_compta_client ( for backward compatibility )
2020-10-31 14:32:18 +01:00
* @ var string
*/
2022-01-13 19:41:52 +01:00
public $code_compta ;
2018-09-30 10:52:40 +02:00
2017-10-13 13:28:26 +02:00
/**
2021-10-08 06:50:22 +02:00
* Accounting code for customer
* @ var string
*/
public $accountancy_code_customer ;
/**
* Accounting code for supplier
2017-10-13 13:28:26 +02:00
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $code_compta_fournisseur ;
2016-07-07 12:19:20 +02:00
2021-10-08 06:50:22 +02:00
/**
* Accounting code for supplier
* @ var string
*/
public $accountancy_code_supplier ;
2022-01-13 19:41:52 +01:00
/**
* Accounting code for product ( for level 3 of suggestion of prouct accounting account )
* @ var string
*/
public $code_compta_product ;
2017-10-13 13:28:26 +02:00
/**
* @ var string
* @ deprecated Note is split in public and private notes
2018-10-12 19:08:06 +02:00
* @ see $note_public , $note_private
2017-10-13 13:28:26 +02:00
*/
2018-04-21 15:08:46 +02:00
public $note ;
2016-07-07 12:19:20 +02:00
2017-10-13 13:28:26 +02:00
/**
* Private note
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $note_private ;
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
/**
* Public note
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $note_public ;
2010-09-02 22:06:52 +02:00
2019-11-02 14:25:52 +01:00
/**
* Status prospect id
* @ var int
*/
2018-04-21 15:08:46 +02:00
public $stcomm_id ;
2019-12-08 14:26:59 +01:00
2020-04-27 17:35:14 +02:00
/**
* Status prospect picto
* @ var string
*/
public $stcomm_picto ;
2019-11-02 14:25:52 +01:00
/**
* Status prospect label
* @ var int
*/
public $status_prospect_label ;
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
/**
* Assigned price level
* @ var int
*/
2018-04-21 15:08:46 +02:00
public $price_level ;
2019-12-08 14:26:59 +01:00
/**
* @ var string outstanding limit
*/
2018-04-21 15:08:46 +02:00
public $outstanding_limit ;
2018-02-20 19:38:18 +01:00
2018-01-20 16:40:56 +01:00
/**
2019-12-08 14:26:59 +01:00
* @ var string Min order amount
2018-01-20 16:40:56 +01:00
*/
2018-04-21 15:08:46 +02:00
public $order_min_amount ;
2019-12-08 14:26:59 +01:00
2020-10-31 14:32:18 +01:00
/**
* @ var string Supplier min order amount
*/
2018-04-21 15:08:46 +02:00
public $supplier_order_min_amount ;
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
/**
* Id of sales representative to link ( used for thirdparty creation ) . Not filled by a fetch , because we can have several sales representatives .
* @ var int
*/
2018-04-21 15:08:46 +02:00
public $commercial_id ;
2019-12-08 14:26:59 +01:00
2017-10-13 13:28:26 +02:00
/**
* Id of parent thirdparty ( if one )
* @ var int
*/
2018-04-21 15:08:46 +02:00
public $parent ;
2019-12-08 14:26:59 +01:00
2017-10-13 13:28:26 +02:00
/**
* Default language code of thirdparty ( en_US , ... )
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $default_lang ;
2010-09-02 22:06:52 +02:00
2018-08-31 18:47:25 +02:00
/**
* @ var string Ref
*/
2018-04-21 15:08:46 +02:00
public $ref ;
2018-08-31 18:47:25 +02:00
2019-12-08 14:26:59 +01:00
/**
* @ var string Internal ref
2020-03-06 14:38:06 +01:00
* @ deprecated
2019-12-08 14:26:59 +01:00
*/
2018-04-21 15:08:46 +02:00
public $ref_int ;
2019-12-08 14:26:59 +01:00
2017-10-13 13:28:26 +02:00
/**
* External user reference .
2020-03-06 14:38:06 +01:00
* This is to allow external systems to store their id and make self - developed synchronizing functions easier to build .
2017-10-13 13:28:26 +02:00
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $ref_ext ;
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
/**
* Import key .
* Set when the thirdparty has been created through an import process . This is to relate those created thirdparties
* to an import process
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $import_key ;
2013-12-20 17:03:24 +01:00
2017-10-13 13:28:26 +02:00
/**
* Supplier WebServices URL
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $webservices_url ;
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
/**
* Supplier WebServices Key
* @ var string
*/
2018-04-21 15:08:46 +02:00
public $webservices_key ;
2010-09-02 22:06:52 +02:00
2020-10-31 14:32:18 +01:00
/**
* @ var string Logo
*/
2018-04-21 15:08:46 +02:00
public $logo ;
2019-12-08 14:26:59 +01:00
2020-10-31 14:32:18 +01:00
/**
* @ var string logo small
*/
2018-04-21 15:08:46 +02:00
public $logo_small ;
2019-12-08 14:26:59 +01:00
2020-10-31 14:32:18 +01:00
/**
* @ var string Logo mini
*/
2018-04-21 15:08:46 +02:00
public $logo_mini ;
2017-10-13 13:28:26 +02:00
2020-10-31 14:32:18 +01:00
/**
* @ var string Logo squarred
*/
2019-10-11 11:27:05 +02:00
public $logo_squarred ;
2019-12-08 14:26:59 +01:00
2020-10-31 14:32:18 +01:00
/**
* @ var string Logo squarred small
*/
2019-10-11 11:27:05 +02:00
public $logo_squarred_small ;
2017-10-13 13:28:26 +02:00
2020-10-31 14:32:18 +01:00
/**
* @ var string Logo squarred mini
*/
2019-12-08 14:26:59 +01:00
public $logo_squarred_mini ;
2017-10-13 13:28:26 +02:00
2020-12-04 04:13:42 +01:00
/**
* @ var string Accountancy account for sales
*/
public $accountancy_code_sell ;
/**
* @ var string Accountancy account for bought
*/
public $accountancy_code_buy ;
2017-10-13 13:28:26 +02:00
// Multicurrency
2018-10-12 09:34:54 +02:00
/**
2020-10-31 14:32:18 +01:00
* @ var int ID
*/
2018-04-21 15:08:46 +02:00
public $fk_multicurrency ;
2018-10-12 09:34:54 +02:00
2021-01-17 02:09:21 +01:00
// Warehouse
/**
* @ var int ID
*/
public $fk_warehouse ;
2020-10-31 14:32:18 +01:00
/**
* @ var string Multicurrency code
*/
2018-04-21 15:08:46 +02:00
public $multicurrency_code ;
2017-10-13 13:28:26 +02:00
2020-03-22 19:11:21 +01:00
2021-06-09 23:48:28 +02:00
// Fields loaded by fetchPartnerships()
public $partnerships = array ();
2023-01-18 00:13:21 +01:00
const STATUS_CEASED = 0 ;
const STATUS_INACTIVITY = 1 ;
2021-06-09 23:48:28 +02:00
2020-05-26 23:22:14 +02:00
/**
2020-05-27 23:08:33 +02:00
* @ var Account | string Default BAN account
2020-05-26 23:22:14 +02:00
*/
public $bank_account ;
2020-09-16 10:51:19 +02:00
/**
* Third party is no customer
*/
const NO_CUSTOMER = 0 ;
/**
* Third party is a customer
*/
const CUSTOMER = 1 ;
/**
* Third party is a prospect
*/
const PROSPECT = 2 ;
/**
* Third party is a customer and a prospect
*/
const CUSTOMER_AND_PROSPECT = 3 ;
/**
* Third party is no supplier
*/
const NO_SUPPLIER = 0 ;
/**
* Third party is a supplier
*/
const SUPPLIER = 1 ;
2020-05-26 23:22:14 +02:00
2017-10-13 13:28:26 +02:00
/**
* Constructor
*
* @ param DoliDB $db Database handler
*/
public function __construct ( $db )
{
2020-07-13 17:48:21 +02:00
global $conf ;
2017-10-13 13:28:26 +02:00
$this -> db = $db ;
$this -> client = 0 ;
$this -> prospect = 0 ;
$this -> fournisseur = 0 ;
2019-11-13 18:32:11 +01:00
$this -> typent_id = 0 ;
$this -> effectif_id = 0 ;
$this -> forme_juridique_code = 0 ;
2017-10-13 13:28:26 +02:00
$this -> tva_assuj = 1 ;
$this -> status = 1 ;
2020-07-13 17:48:21 +02:00
2020-10-31 14:32:18 +01:00
if ( ! empty ( $conf -> global -> COMPANY_SHOW_ADDRESS_SELECTLIST )) {
2020-07-13 17:48:21 +02:00
$this -> fields [ 'address' ][ 'showoncombobox' ] = $conf -> global -> COMPANY_SHOW_ADDRESS_SELECTLIST ;
$this -> fields [ 'zip' ][ 'showoncombobox' ] = $conf -> global -> COMPANY_SHOW_ADDRESS_SELECTLIST ;
$this -> fields [ 'town' ][ 'showoncombobox' ] = $conf -> global -> COMPANY_SHOW_ADDRESS_SELECTLIST ;
//$this->fields['fk_pays']['showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
}
2017-10-13 13:28:26 +02:00
}
2010-09-02 22:06:52 +02:00
2017-09-02 12:36:22 +02:00
2017-10-13 13:28:26 +02:00
/**
* Create third party in database .
* $this -> code_client = - 1 and $this -> code_fournisseur = - 1 means automatic assignement .
*
* @ param User $user Object of user that ask creation
2020-09-25 17:11:54 +02:00
* @ return int >= 0 if OK , < 0 if KO
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function create ( User $user )
2017-10-13 13:28:26 +02:00
{
2019-11-13 18:32:11 +01:00
global $langs , $conf , $mysoc ;
2010-09-02 22:06:52 +02:00
2019-11-13 18:32:11 +01:00
$error = 0 ;
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
// Clean parameters
2020-12-28 21:08:56 +01:00
if ( empty ( $this -> status )) {
$this -> status = 0 ;
}
2019-11-13 18:32:11 +01:00
$this -> name = $this -> name ? trim ( $this -> name ) : trim ( $this -> nom );
2020-10-28 20:53:29 +01:00
$this -> setUpperOrLowerCase ();
2019-11-13 18:32:11 +01:00
$this -> nom = $this -> name ; // For backward compatibility
2020-12-28 21:08:56 +01:00
if ( empty ( $this -> client )) {
$this -> client = 0 ;
}
if ( empty ( $this -> fournisseur )) {
$this -> fournisseur = 0 ;
}
2017-10-13 13:28:26 +02:00
$this -> import_key = trim ( $this -> import_key );
2010-09-02 22:06:52 +02:00
2021-10-08 06:50:22 +02:00
$this -> accountancy_code_customer = trim ( $this -> code_compta );
$this -> accountancy_code_supplier = trim ( $this -> code_compta_fournisseur );
2020-12-04 04:13:42 +01:00
$this -> accountancy_code_buy = trim ( $this -> accountancy_code_buy );
2021-10-25 22:07:31 +02:00
$this -> accountancy_code_sell = trim ( $this -> accountancy_code_sell );
2020-12-04 04:13:42 +01:00
2020-12-28 21:08:56 +01:00
if ( ! empty ( $this -> multicurrency_code )) {
$this -> fk_multicurrency = MultiCurrency :: getIdFromCode ( $this -> db , $this -> multicurrency_code );
}
if ( empty ( $this -> fk_multicurrency )) {
2016-01-18 19:45:27 +01:00
$this -> multicurrency_code = '' ;
$this -> fk_multicurrency = 0 ;
}
2017-10-13 13:28:26 +02:00
dol_syslog ( get_class ( $this ) . " ::create " . $this -> name );
2014-07-04 14:25:08 +02:00
2019-11-13 18:32:11 +01:00
$now = dol_now ();
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
$this -> db -> begin ();
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
2020-12-28 21:08:56 +01:00
if ( $this -> code_client == - 1 || $this -> code_client === 'auto' ) {
$this -> get_codeclient ( $this , 0 );
}
if ( $this -> code_fournisseur == - 1 || $this -> code_fournisseur === 'auto' ) {
$this -> get_codefournisseur ( $this , 1 );
}
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
// Check more parameters (including mandatory setup
// If error, this->errors[] is filled
$result = $this -> verify ();
2012-08-20 01:29:13 +02:00
2020-12-28 21:08:56 +01:00
if ( $result >= 0 ) {
2019-11-13 18:32:11 +01:00
$this -> entity = (( isset ( $this -> entity ) && is_numeric ( $this -> entity )) ? $this -> entity : $conf -> entity );
2018-01-11 10:20:49 +01:00
2020-12-04 04:13:42 +01:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " societe ( " ;
$sql .= " nom " ;
$sql .= " , name_alias " ;
$sql .= " , entity " ;
$sql .= " , datec " ;
$sql .= " , fk_user_creat " ;
2022-02-11 11:40:45 +01:00
$sql .= " , fk_typent " ;
2020-12-04 04:13:42 +01:00
$sql .= " , canvas " ;
$sql .= " , status " ;
$sql .= " , ref_ext " ;
$sql .= " , fk_stcomm " ;
$sql .= " , fk_incoterms " ;
$sql .= " , location_incoterms " ;
$sql .= " , import_key " ;
$sql .= " , fk_multicurrency " ;
$sql .= " , multicurrency_code " ;
2021-04-14 04:45:17 +02:00
if ( empty ( $conf -> global -> MAIN_COMPANY_PERENTITY_SHARED )) {
$sql .= " , accountancy_code_buy " ;
$sql .= " , accountancy_code_sell " ;
}
2021-08-28 03:09:18 +02:00
$sql .= " ) VALUES (' " . $this -> db -> escape ( $this -> name ) . " ', ' " . $this -> db -> escape ( $this -> name_alias ) . " ', " . (( int ) $this -> entity ) . " , ' " . $this -> db -> idate ( $now ) . " ' " ;
2022-01-05 10:47:59 +01:00
$sql .= " , " . ( ! empty ( $user -> id ) ? (( int ) $user -> id ) : " null " );
2021-03-28 19:19:40 +02:00
$sql .= " , " . ( ! empty ( $this -> typent_id ) ? (( int ) $this -> typent_id ) : " null " );
2019-11-13 18:32:11 +01:00
$sql .= " , " . ( ! empty ( $this -> canvas ) ? " ' " . $this -> db -> escape ( $this -> canvas ) . " ' " : " null " );
2021-07-05 18:46:27 +02:00
$sql .= " , " . (( int ) $this -> status );
2019-11-13 18:32:11 +01:00
$sql .= " , " . ( ! empty ( $this -> ref_ext ) ? " ' " . $this -> db -> escape ( $this -> ref_ext ) . " ' " : " null " );
$sql .= " , 0 " ;
$sql .= " , " . ( int ) $this -> fk_incoterms ;
$sql .= " , ' " . $this -> db -> escape ( $this -> location_incoterms ) . " ' " ;
$sql .= " , " . ( ! empty ( $this -> import_key ) ? " ' " . $this -> db -> escape ( $this -> import_key ) . " ' " : " null " );
$sql .= " , " . ( int ) $this -> fk_multicurrency ;
2020-12-04 04:13:42 +01:00
$sql .= " , ' " . $this -> db -> escape ( $this -> multicurrency_code ) . " ' " ;
2021-04-14 04:45:17 +02:00
if ( empty ( $conf -> global -> MAIN_COMPANY_PERENTITY_SHARED )) {
2021-10-25 22:07:31 +02:00
$sql .= " , ' " . $this -> db -> escape ( $this -> accountancy_code_buy ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> accountancy_code_sell ) . " ' " ;
2021-04-14 04:45:17 +02:00
}
2020-12-04 04:13:42 +01:00
$sql .= " ) " ;
2014-10-31 17:46:11 +01:00
2017-10-13 13:28:26 +02:00
dol_syslog ( get_class ( $this ) . " ::create " , LOG_DEBUG );
2019-11-13 18:32:11 +01:00
$result = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $result ) {
2017-10-13 13:28:26 +02:00
$this -> id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . " societe " );
2015-03-05 11:38:16 +01:00
2019-01-27 11:55:16 +01:00
$ret = $this -> update ( $this -> id , $user , 0 , 1 , 1 , 'add' );
2014-10-31 17:46:11 +01:00
2021-04-14 04:45:17 +02:00
// update accountancy for this entity
if ( ! $error && ! empty ( $conf -> global -> MAIN_COMPANY_PERENTITY_SHARED )) {
2021-10-25 22:07:31 +02:00
$this -> db -> query ( " DELETE FROM " . MAIN_DB_PREFIX . " societe_perentity WHERE fk_soc = " . (( int ) $this -> id ) . " AND entity = " . (( int ) $conf -> entity ));
2021-04-14 04:45:17 +02:00
2021-10-25 22:07:31 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " societe_perentity ( " ;
2021-04-14 04:45:17 +02:00
$sql .= " fk_soc " ;
$sql .= " , entity " ;
2021-10-08 06:29:22 +02:00
$sql .= " , accountancy_code_customer " ;
$sql .= " , accountancy_code_supplier " ;
2021-04-14 04:45:17 +02:00
$sql .= " , accountancy_code_buy " ;
$sql .= " , accountancy_code_sell " ;
$sql .= " ) VALUES ( " ;
$sql .= $this -> id ;
2022-05-16 13:57:11 +02:00
$sql .= " , " . (( int ) $conf -> entity );
2021-10-25 22:07:31 +02:00
$sql .= " , ' " . $this -> db -> escape ( $this -> accountancy_code_customer ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> accountancy_code_supplier ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> accountancy_code_buy ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> accountancy_code_sell ) . " ' " ;
2021-04-14 04:45:17 +02:00
$sql .= " ) " ;
$result = $this -> db -> query ( $sql );
if ( ! $result ) {
$error ++ ;
$this -> error = 'ErrorFailedToUpdateAccountancyForEntity' ;
}
}
2017-10-13 13:28:26 +02:00
// Ajout du commercial affecte
2020-12-28 21:08:56 +01:00
if ( $this -> commercial_id != '' && $this -> commercial_id != - 1 ) {
2017-10-13 13:28:26 +02:00
$this -> add_commercial ( $user , $this -> commercial_id );
2021-02-26 21:17:52 +01:00
} elseif ( empty ( $user -> rights -> societe -> client -> voir )) {
// si un commercial cree un client il lui est affecte automatiquement
2017-10-13 13:28:26 +02:00
$this -> add_commercial ( $user , $user -> id );
}
2015-02-09 17:55:43 +01:00
2020-12-28 21:08:56 +01:00
if ( $ret >= 0 ) {
2017-10-13 13:28:26 +02:00
// Call trigger
2019-11-13 18:32:11 +01:00
$result = $this -> call_trigger ( 'COMPANY_CREATE' , $user );
2020-12-28 21:08:56 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2017-10-13 13:28:26 +02:00
// End call triggers
2020-12-28 21:08:56 +01:00
} else {
$error ++ ;
}
2010-09-02 22:06:52 +02:00
2020-12-28 21:08:56 +01:00
if ( ! $error ) {
2017-10-13 13:28:26 +02:00
dol_syslog ( get_class ( $this ) . " ::Create success id= " . $this -> id );
$this -> db -> commit ();
return $this -> id ;
2020-05-21 15:05:19 +02:00
} else {
2020-12-29 04:44:48 +01:00
dol_syslog ( get_class ( $this ) . " ::Create echec update " . $this -> error . ( empty ( $this -> errors ) ? '' : ' ' . join ( ',' , $this -> errors )), LOG_ERR );
2017-10-13 13:28:26 +02:00
$this -> db -> rollback ();
return - 4 ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-12-28 21:08:56 +01:00
if ( $this -> db -> lasterrno () == 'DB_ERROR_RECORD_ALREADY_EXISTS' ) {
2019-11-13 18:32:11 +01:00
$this -> error = $langs -> trans ( " ErrorCompanyNameAlreadyExists " , $this -> name ); // duplicate on a field (code or profid or ...)
$result = - 1 ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 18:32:11 +01:00
$this -> error = $this -> db -> lasterror ();
$result = - 2 ;
2017-10-13 13:28:26 +02:00
}
$this -> db -> rollback ();
return $result ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
$this -> db -> rollback ();
2019-01-27 11:55:16 +01:00
dol_syslog ( get_class ( $this ) . " ::Create fails verify " . join ( ',' , $this -> errors ), LOG_WARNING );
2017-10-13 13:28:26 +02:00
return - 3 ;
}
}
2010-09-02 22:06:52 +02:00
2014-10-31 17:46:11 +01:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Create a contact / address from thirdparty
*
* @ param User $user Object user
2021-01-07 17:23:02 +01:00
* @ param int $no_email 1 = Do not send mailing , 0 = Ok to recieve mailling
2021-01-06 09:11:04 +01:00
* @ param array $tags Array of tag to affect to contact
2017-10-13 13:28:26 +02:00
* @ return int < 0 if KO , > 0 if OK
*/
2021-03-28 19:19:40 +02:00
public function create_individual ( User $user , $no_email = 0 , $tags = array ())
2017-10-13 13:28:26 +02:00
{
2021-01-07 17:23:02 +01:00
global $conf ;
$error = 0 ;
$this -> db -> begin ();
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
2019-11-13 18:32:11 +01:00
$contact = new Contact ( $this -> db );
2017-10-13 13:28:26 +02:00
$contact -> name = $this -> name_bis ;
$contact -> firstname = $this -> firstname ;
$contact -> civility_id = $this -> civility_id ;
2019-11-13 18:32:11 +01:00
$contact -> socid = $this -> id ; // fk_soc
2020-03-12 12:45:44 +01:00
$contact -> statut = 1 ; // deprecated
2020-02-08 11:32:38 +01:00
$contact -> status = 1 ;
2017-10-13 13:28:26 +02:00
$contact -> priv = 0 ;
$contact -> country_id = $this -> country_id ;
$contact -> state_id = $this -> state_id ;
$contact -> address = $this -> address ;
$contact -> email = $this -> email ;
$contact -> zip = $this -> zip ;
$contact -> town = $this -> town ;
2021-02-17 15:26:56 +01:00
$this -> setUpperOrLowerCase ();
2017-10-13 13:28:26 +02:00
$contact -> phone_pro = $this -> phone ;
2021-01-06 09:11:04 +01:00
$contactId = $contact -> create ( $user );
if ( $contactId < 0 ) {
2021-01-07 17:23:02 +01:00
$error ++ ;
2017-10-13 13:28:26 +02:00
$this -> error = $contact -> error ;
$this -> errors = $contact -> errors ;
2019-11-13 18:32:11 +01:00
dol_syslog ( get_class ( $this ) . " ::create_individual ERROR: " . $this -> error , LOG_ERR );
2017-10-13 13:28:26 +02:00
}
2013-09-17 10:33:47 +02:00
2021-01-07 17:23:02 +01:00
if ( empty ( $error ) && is_array ( $tags ) && ! empty ( $tags )) {
2021-01-06 09:11:04 +01:00
$result = $contact -> setCategories ( $tags );
2021-01-07 17:23:02 +01:00
if ( $result < 0 ) {
$error ++ ;
$this -> error = $contact -> error ;
$this -> errors = array_merge ( $this -> errors , $contact -> errors );
2021-10-25 22:07:31 +02:00
dol_syslog ( get_class ( $this ) . " ::create_individual Affect Tag ERROR: " . $this -> error , LOG_ERR );
2021-01-07 17:23:02 +01:00
$contactId = $result ;
}
}
if ( empty ( $error ) && ! empty ( $conf -> mailing -> enabled ) && ! empty ( $contact -> email ) && isset ( $no_email )) {
$result = $contact -> setNoEmail ( $no_email );
if ( $result < 0 ) {
2021-01-06 09:11:04 +01:00
$this -> error = $contact -> error ;
$this -> errors = array_merge ( $this -> errors , $contact -> errors );
2021-10-25 22:07:31 +02:00
dol_syslog ( get_class ( $this ) . " ::create_individual set mailing status ERROR: " . $this -> error , LOG_ERR );
2021-01-06 09:11:04 +01:00
$contactId = $result ;
}
2017-10-13 13:28:26 +02:00
}
2013-09-17 10:33:47 +02:00
2022-06-07 18:44:00 +02:00
if ( empty ( $error )) {
2021-01-07 17:23:02 +01:00
dol_syslog ( get_class ( $this ) . " ::create_individual success " );
$this -> db -> commit ();
} else {
$this -> db -> rollback ();
}
2021-01-06 09:11:04 +01:00
return $contactId ;
2017-10-13 13:28:26 +02:00
}
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
/**
* Check properties of third party are ok ( like name , third party codes , ... )
* Used before an add or update .
*
* @ return int 0 if OK , < 0 if KO
*/
2020-10-31 14:32:18 +01:00
public function verify ()
2017-10-13 13:28:26 +02:00
{
global $conf , $langs , $mysoc ;
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
$error = 0 ;
2019-11-13 18:32:11 +01:00
$this -> errors = array ();
2015-03-05 11:38:16 +01:00
2017-10-13 13:28:26 +02:00
$result = 0 ;
2019-11-13 18:32:11 +01:00
$this -> name = trim ( $this -> name );
$this -> nom = $this -> name ; // For backward compatibility
2016-01-18 19:45:27 +01:00
2020-12-28 21:08:56 +01:00
if ( ! $this -> name ) {
2017-10-13 13:28:26 +02:00
$this -> errors [] = 'ErrorBadThirdPartyName' ;
$result = - 2 ;
}
2013-03-09 16:19:15 +01:00
2020-12-28 21:08:56 +01:00
if ( $this -> client ) {
2017-10-13 13:28:26 +02:00
$rescode = $this -> check_codeclient ();
2020-12-28 21:08:56 +01:00
if ( $rescode != 0 && $rescode != - 5 ) {
2020-12-29 04:32:13 +01:00
if ( $rescode == - 1 ) {
2017-10-13 13:28:26 +02:00
$this -> errors [] = 'ErrorBadCustomerCodeSyntax' ;
2020-12-29 04:32:13 +01:00
} elseif ( $rescode == - 2 ) {
2017-10-13 13:28:26 +02:00
$this -> errors [] = 'ErrorCustomerCodeRequired' ;
2020-12-29 04:32:13 +01:00
} elseif ( $rescode == - 3 ) {
2017-10-13 13:28:26 +02:00
$this -> errors [] = 'ErrorCustomerCodeAlreadyUsed' ;
2020-12-29 04:32:13 +01:00
} elseif ( $rescode == - 4 ) {
2017-10-13 13:28:26 +02:00
$this -> errors [] = 'ErrorPrefixRequired' ;
2020-09-25 17:11:54 +02:00
} else {
$this -> errors [] = 'ErrorUnknownOnCustomerCodeCheck' ;
2017-10-13 13:28:26 +02:00
}
2020-09-25 17:11:54 +02:00
2017-10-13 13:28:26 +02:00
$result = - 3 ;
}
}
2010-09-02 22:06:52 +02:00
2020-12-28 21:08:56 +01:00
if ( $this -> fournisseur ) {
2017-10-13 13:28:26 +02:00
$rescode = $this -> check_codefournisseur ();
2020-12-28 21:08:56 +01:00
if ( $rescode != 0 && $rescode != - 5 ) {
2020-12-29 04:32:13 +01:00
if ( $rescode == - 1 ) {
2017-10-13 13:28:26 +02:00
$this -> errors [] = 'ErrorBadSupplierCodeSyntax' ;
2020-12-29 04:32:13 +01:00
} elseif ( $rescode == - 2 ) {
2017-10-13 13:28:26 +02:00
$this -> errors [] = 'ErrorSupplierCodeRequired' ;
2020-12-29 04:32:13 +01:00
} elseif ( $rescode == - 3 ) {
2017-10-13 13:28:26 +02:00
$this -> errors [] = 'ErrorSupplierCodeAlreadyUsed' ;
2020-12-29 04:32:13 +01:00
} elseif ( $rescode == - 4 ) {
2020-04-14 07:01:53 +02:00
$this -> errors [] = 'ErrorPrefixRequired' ;
2020-09-25 17:11:54 +02:00
} else {
$this -> errors [] = 'ErrorUnknownOnSupplierCodeCheck' ;
2017-10-13 13:28:26 +02:00
}
$result = - 3 ;
}
}
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
// Check for duplicate or mandatory fields defined into setup
2019-11-13 18:32:11 +01:00
$array_to_check = array ( 'IDPROF1' , 'IDPROF2' , 'IDPROF3' , 'IDPROF4' , 'IDPROF5' , 'IDPROF6' , 'EMAIL' );
2020-12-28 21:08:56 +01:00
foreach ( $array_to_check as $key ) {
2019-11-13 18:32:11 +01:00
$keymin = strtolower ( $key );
$i = ( int ) preg_replace ( '/[^0-9]/' , '' , $key );
$vallabel = $this -> $keymin ;
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( $i > 0 ) {
if ( $this -> isACompany ()) {
2019-11-06 00:27:36 +01:00
// Check for mandatory prof id (but only if country is same than ours)
2020-12-28 21:08:56 +01:00
if ( $mysoc -> country_id > 0 && $this -> country_id == $mysoc -> country_id ) {
2019-11-13 18:32:11 +01:00
$idprof_mandatory = 'SOCIETE_' . $key . '_MANDATORY' ;
2020-12-28 21:08:56 +01:00
if ( ! $vallabel && ! empty ( $conf -> global -> $idprof_mandatory )) {
2017-10-13 13:28:26 +02:00
$langs -> load ( " errors " );
$error ++ ;
$this -> errors [] = $langs -> trans ( " ErrorProdIdIsMandatory " , $langs -> transcountry ( 'ProfId' . $i , $this -> country_code )) . ' (' . $langs -> trans ( " ForbiddenBySetupRules " ) . ')' ;
}
}
}
2019-11-06 00:27:36 +01:00
2020-01-22 16:29:04 +01:00
// Check for unicity on profid
2020-12-28 21:08:56 +01:00
if ( ! $error && $vallabel && $this -> id_prof_verifiable ( $i )) {
if ( $this -> id_prof_exists ( $keymin , $vallabel , ( $this -> id > 0 ? $this -> id : 0 ))) {
2019-11-06 00:27:36 +01:00
$langs -> load ( " errors " );
$error ++ ;
$this -> errors [] = $langs -> transcountry ( 'ProfId' . $i , $this -> country_code ) . " " . $langs -> trans ( " ErrorProdIdAlreadyExist " , $vallabel ) . ' (' . $langs -> trans ( " ForbiddenBySetupRules " ) . ')' ;
}
}
2020-05-21 15:05:19 +02:00
} else {
2018-01-10 12:27:11 +01:00
//var_dump($conf->global->SOCIETE_EMAIL_UNIQUE);
2017-10-13 13:28:26 +02:00
//var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
2020-12-28 21:08:56 +01:00
if ( $key == 'EMAIL' ) {
2019-11-06 00:27:36 +01:00
// Check for mandatory
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_EMAIL_MANDATORY ) && ! isValidEMail ( $this -> email )) {
2019-11-06 00:27:36 +01:00
$langs -> load ( " errors " );
$error ++ ;
$this -> errors [] = $langs -> trans ( " ErrorBadEMail " , $this -> email ) . ' (' . $langs -> trans ( " ForbiddenBySetupRules " ) . ')' ;
}
2017-10-13 13:28:26 +02:00
// Check for unicity
2020-12-28 21:08:56 +01:00
if ( ! $error && $vallabel && ! empty ( $conf -> global -> SOCIETE_EMAIL_UNIQUE )) {
if ( $this -> id_prof_exists ( $keymin , $vallabel , ( $this -> id > 0 ? $this -> id : 0 ))) {
2017-10-13 13:28:26 +02:00
$langs -> load ( " errors " );
$error ++ ; $this -> errors [] = $langs -> trans ( 'Email' ) . " " . $langs -> trans ( " ErrorProdIdAlreadyExist " , $vallabel ) . ' (' . $langs -> trans ( " ForbiddenBySetupRules " ) . ')' ;
}
}
}
}
}
2020-12-28 21:08:56 +01:00
if ( $error ) {
$result = - 4 ;
}
2017-10-13 13:28:26 +02:00
return $result ;
}
/**
* Update parameters of third party
*
2017-11-03 11:42:40 +01:00
* @ param int $id Id of company ( deprecated , use 0 here and call update on an object loaded by a fetch )
2019-10-21 02:18:39 +02:00
* @ param User $user User who requests the update
2017-11-29 16:23:11 +01:00
* @ param int $call_trigger 0 = no , 1 = yes
2017-10-13 13:28:26 +02:00
* @ param int $allowmodcodeclient Inclut modif code client et code compta
* @ param int $allowmodcodefournisseur Inclut modif code fournisseur et code compta fournisseur
2018-01-31 18:01:56 +01:00
* @ param string $action 'add' or 'update' or 'merge'
2017-10-13 13:28:26 +02:00
* @ param int $nosyncmember Do not synchronize info of linked member
* @ return int < 0 if KO , >= 0 if OK
*/
2020-10-31 14:32:18 +01:00
public function update ( $id , $user = '' , $call_trigger = 1 , $allowmodcodeclient = 0 , $allowmodcodefournisseur = 0 , $action = 'update' , $nosyncmember = 1 )
2017-10-13 13:28:26 +02:00
{
2019-11-13 18:32:11 +01:00
global $langs , $conf , $hookmanager ;
2018-08-12 16:29:26 +02:00
2017-10-13 13:28:26 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2020-12-28 21:08:56 +01:00
if ( empty ( $id )) {
$id = $this -> id ;
}
2017-11-03 11:42:40 +01:00
2019-11-13 18:32:11 +01:00
$error = 0 ;
2017-10-13 13:28:26 +02:00
dol_syslog ( get_class ( $this ) . " ::Update id= " . $id . " call_trigger= " . $call_trigger . " allowmodcodeclient= " . $allowmodcodeclient . " allowmodcodefournisseur= " . $allowmodcodefournisseur );
2019-11-13 18:32:11 +01:00
$now = dol_now ();
2017-10-13 13:28:26 +02:00
// Clean parameters
2019-11-13 18:32:11 +01:00
$this -> id = $id ;
$this -> entity = (( isset ( $this -> entity ) && is_numeric ( $this -> entity )) ? $this -> entity : $conf -> entity );
$this -> name = $this -> name ? trim ( $this -> name ) : trim ( $this -> nom );
$this -> nom = $this -> name ; // For backward compatibility
$this -> name_alias = trim ( $this -> name_alias );
2017-10-13 13:28:26 +02:00
$this -> ref_ext = trim ( $this -> ref_ext );
2019-11-13 18:32:11 +01:00
$this -> address = $this -> address ? trim ( $this -> address ) : trim ( $this -> address );
$this -> zip = $this -> zip ? trim ( $this -> zip ) : trim ( $this -> zip );
2020-10-31 14:32:18 +01:00
$this -> town = $this -> town ? trim ( $this -> town ) : trim ( $this -> town );
2020-10-28 20:53:29 +01:00
$this -> setUpperOrLowerCase ();
2019-11-13 18:32:11 +01:00
$this -> state_id = trim ( $this -> state_id );
$this -> country_id = ( $this -> country_id > 0 ) ? $this -> country_id : 0 ;
2017-10-13 13:28:26 +02:00
$this -> phone = trim ( $this -> phone );
2019-01-27 11:55:16 +01:00
$this -> phone = preg_replace ( " / \ s/ " , " " , $this -> phone );
$this -> phone = preg_replace ( " / \ ./ " , " " , $this -> phone );
2017-10-13 13:28:26 +02:00
$this -> fax = trim ( $this -> fax );
2019-01-27 11:55:16 +01:00
$this -> fax = preg_replace ( " / \ s/ " , " " , $this -> fax );
$this -> fax = preg_replace ( " / \ ./ " , " " , $this -> fax );
2019-11-13 18:32:11 +01:00
$this -> email = trim ( $this -> email );
$this -> url = $this -> url ? clean_url ( $this -> url , 0 ) : '' ;
2018-04-01 13:45:39 +02:00
$this -> note_private = trim ( $this -> note_private );
$this -> note_public = trim ( $this -> note_public );
2017-10-13 13:28:26 +02:00
$this -> idprof1 = trim ( $this -> idprof1 );
$this -> idprof2 = trim ( $this -> idprof2 );
$this -> idprof3 = trim ( $this -> idprof3 );
$this -> idprof4 = trim ( $this -> idprof4 );
2019-11-13 18:32:11 +01:00
$this -> idprof5 = ( ! empty ( $this -> idprof5 ) ? trim ( $this -> idprof5 ) : '' );
$this -> idprof6 = ( ! empty ( $this -> idprof6 ) ? trim ( $this -> idprof6 ) : '' );
$this -> prefix_comm = trim ( $this -> prefix_comm );
2017-10-13 13:28:26 +02:00
$this -> outstanding_limit = price2num ( $this -> outstanding_limit );
2018-01-20 16:40:56 +01:00
$this -> order_min_amount = price2num ( $this -> order_min_amount );
$this -> supplier_order_min_amount = price2num ( $this -> supplier_order_min_amount );
2017-10-13 13:28:26 +02:00
$this -> tva_assuj = trim ( $this -> tva_assuj );
2019-01-27 11:55:16 +01:00
$this -> tva_intra = dol_sanitizeFileName ( $this -> tva_intra , '' );
2020-12-28 21:08:56 +01:00
if ( empty ( $this -> status )) {
$this -> status = 0 ;
}
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( ! empty ( $this -> multicurrency_code )) {
$this -> fk_multicurrency = MultiCurrency :: getIdFromCode ( $this -> db , $this -> multicurrency_code );
}
if ( empty ( $this -> fk_multicurrency )) {
2017-10-13 13:28:26 +02:00
$this -> multicurrency_code = '' ;
$this -> fk_multicurrency = 0 ;
}
// Local taxes
2019-11-13 18:32:11 +01:00
$this -> localtax1_assuj = trim ( $this -> localtax1_assuj );
$this -> localtax2_assuj = trim ( $this -> localtax2_assuj );
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$this -> localtax1_value = trim ( $this -> localtax1_value );
$this -> localtax2_value = trim ( $this -> localtax2_value );
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( $this -> capital != '' ) {
$this -> capital = price2num ( trim ( $this -> capital ));
}
if ( ! is_numeric ( $this -> capital )) {
$this -> capital = '' ; // '' = undef
}
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$this -> effectif_id = trim ( $this -> effectif_id );
$this -> forme_juridique_code = trim ( $this -> forme_juridique_code );
2017-10-13 13:28:26 +02:00
//Gencod
2019-11-13 18:32:11 +01:00
$this -> barcode = trim ( $this -> barcode );
2017-10-13 13:28:26 +02:00
// For automatic creation
2020-12-28 21:08:56 +01:00
if ( $this -> code_client == - 1 || $this -> code_client === 'auto' ) {
$this -> get_codeclient ( $this , 0 );
}
if ( $this -> code_fournisseur == - 1 || $this -> code_fournisseur === 'auto' ) {
$this -> get_codefournisseur ( $this , 1 );
}
2017-10-13 13:28:26 +02:00
2021-07-14 17:19:43 +02:00
$this -> code_compta_client = trim ( empty ( $this -> code_compta ) ? $this -> code_compta_client : $this -> code_compta );
2021-10-25 22:07:31 +02:00
$this -> code_compta = $this -> code_compta_client ; // for backward compatibility
2019-11-13 18:32:11 +01:00
$this -> code_compta_fournisseur = trim ( $this -> code_compta_fournisseur );
2017-10-13 13:28:26 +02:00
// Check parameters. More tests are done later in the ->verify()
2020-12-28 21:08:56 +01:00
if ( ! is_numeric ( $this -> client ) && ! is_numeric ( $this -> fournisseur )) {
2017-10-13 13:28:26 +02:00
$langs -> load ( " errors " );
$this -> error = $langs -> trans ( " BadValueForParameterClientOrSupplier " );
return - 1 ;
}
2019-11-13 18:32:11 +01:00
$customer = false ;
2020-12-28 21:08:56 +01:00
if ( ! empty ( $allowmodcodeclient ) && ! empty ( $this -> client )) {
2021-07-14 17:19:43 +02:00
// If $allowmodcodeclient is set and value is not set, we generate it
if ( empty ( $this -> code_compta_client )) {
2019-11-13 18:32:11 +01:00
$ret = $this -> get_codecompta ( 'customer' );
2020-12-28 21:08:56 +01:00
if ( $ret < 0 ) {
return - 1 ;
}
2017-10-13 13:28:26 +02:00
}
2019-11-13 18:32:11 +01:00
$customer = true ;
2017-10-13 13:28:26 +02:00
}
2019-11-13 18:32:11 +01:00
$supplier = false ;
2020-12-28 21:08:56 +01:00
if ( ! empty ( $allowmodcodefournisseur ) && ! empty ( $this -> fournisseur )) {
2021-07-14 17:19:43 +02:00
// If $allowmodcodefournisseur is set and value is not set, we generate it
if ( empty ( $this -> code_compta_fournisseur )) {
2019-11-13 18:32:11 +01:00
$ret = $this -> get_codecompta ( 'supplier' );
2020-12-28 21:08:56 +01:00
if ( $ret < 0 ) {
return - 1 ;
}
2017-10-13 13:28:26 +02:00
}
2019-11-13 18:32:11 +01:00
$supplier = true ;
2017-10-13 13:28:26 +02:00
}
//Web services
2019-11-13 18:32:11 +01:00
$this -> webservices_url = $this -> webservices_url ? clean_url ( $this -> webservices_url , 0 ) : '' ;
2017-10-13 13:28:26 +02:00
$this -> webservices_key = trim ( $this -> webservices_key );
2020-12-04 04:13:42 +01:00
$this -> accountancy_code_buy = trim ( $this -> accountancy_code_buy );
2021-10-25 22:07:31 +02:00
$this -> accountancy_code_sell = trim ( $this -> accountancy_code_sell );
2020-12-04 04:13:42 +01:00
2017-10-13 13:28:26 +02:00
//Incoterms
$this -> fk_incoterms = ( int ) $this -> fk_incoterms ;
$this -> location_incoterms = trim ( $this -> location_incoterms );
$this -> db -> begin ();
// Check name is required and codes are ok or unique.
// If error, this->errors[] is filled
$result = 0 ;
2020-12-28 21:08:56 +01:00
if ( $action != 'add' && $action != 'merge' ) {
2018-01-31 18:01:56 +01:00
// We don't check when update called during a create because verify was already done.
// For a merge, we suppose source data is clean and a customer code of a deleted thirdparty must be accepted into a target thirdparty with empty code without duplicate error
$result = $this -> verify ();
2018-11-08 17:15:35 +01:00
// If there is only one error and error is ErrorBadCustomerCodeSyntax and we don't change customer code, we allow the update
// So we can update record that were using and old numbering rule.
2020-12-28 21:08:56 +01:00
if ( is_array ( $this -> errors )) {
if ( in_array ( 'ErrorBadCustomerCodeSyntax' , $this -> errors ) && is_object ( $this -> oldcopy ) && $this -> oldcopy -> code_client == $this -> code_client ) {
if (( $key = array_search ( 'ErrorBadCustomerCodeSyntax' , $this -> errors )) !== false ) {
unset ( $this -> errors [ $key ]); // Remove error message
}
2018-11-08 17:15:35 +01:00
}
2020-12-28 21:08:56 +01:00
if ( in_array ( 'ErrorBadSupplierCodeSyntax' , $this -> errors ) && is_object ( $this -> oldcopy ) && $this -> oldcopy -> code_fournisseur == $this -> code_fournisseur ) {
if (( $key = array_search ( 'ErrorBadSupplierCodeSyntax' , $this -> errors )) !== false ) {
unset ( $this -> errors [ $key ]); // Remove error message
}
2018-11-08 17:15:35 +01:00
}
2020-12-28 21:08:56 +01:00
if ( empty ( $this -> errors )) { // If there is no more error, we can make like if there is no error at all
2018-11-08 17:15:35 +01:00
$result = 0 ;
}
}
2018-01-31 18:01:56 +01:00
}
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( $result >= 0 ) {
2017-10-13 13:28:26 +02:00
dol_syslog ( get_class ( $this ) . " ::update verify ok or not done " );
$sql = " UPDATE " . MAIN_DB_PREFIX . " societe SET " ;
2019-11-13 18:32:11 +01:00
$sql .= " entity = " . $this -> db -> escape ( $this -> entity );
$sql .= " ,nom = ' " . $this -> db -> escape ( $this -> name ) . " ' " ; // Required
$sql .= " ,name_alias = ' " . $this -> db -> escape ( $this -> name_alias ) . " ' " ;
$sql .= " ,ref_ext = " . ( ! empty ( $this -> ref_ext ) ? " ' " . $this -> db -> escape ( $this -> ref_ext ) . " ' " : " null " );
$sql .= " ,address = ' " . $this -> db -> escape ( $this -> address ) . " ' " ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$sql .= " ,zip = " . ( ! empty ( $this -> zip ) ? " ' " . $this -> db -> escape ( $this -> zip ) . " ' " : " null " );
$sql .= " ,town = " . ( ! empty ( $this -> town ) ? " ' " . $this -> db -> escape ( $this -> town ) . " ' " : " null " );
2017-10-13 13:28:26 +02:00
2021-07-05 18:46:27 +02:00
$sql .= " ,fk_departement = " . (( ! empty ( $this -> state_id ) && $this -> state_id > 0 ) ? (( int ) $this -> state_id ) : 'null' );
$sql .= " ,fk_pays = " . (( ! empty ( $this -> country_id ) && $this -> country_id > 0 ) ? (( int ) $this -> country_id ) : 'null' );
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$sql .= " ,phone = " . ( ! empty ( $this -> phone ) ? " ' " . $this -> db -> escape ( $this -> phone ) . " ' " : " null " );
$sql .= " ,fax = " . ( ! empty ( $this -> fax ) ? " ' " . $this -> db -> escape ( $this -> fax ) . " ' " : " null " );
2020-10-31 14:32:18 +01:00
$sql .= " ,email = " . ( ! empty ( $this -> email ) ? " ' " . $this -> db -> escape ( $this -> email ) . " ' " : " null " );
2021-07-05 18:46:27 +02:00
$sql .= " ,socialnetworks = ' " . $this -> db -> escape ( json_encode ( $this -> socialnetworks )) . " ' " ;
2019-11-13 18:32:11 +01:00
$sql .= " ,url = " . ( ! empty ( $this -> url ) ? " ' " . $this -> db -> escape ( $this -> url ) . " ' " : " null " );
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$sql .= " ,parent = " . ( $this -> parent > 0 ? $this -> parent : " null " );
2018-06-19 19:34:23 +02:00
2019-11-13 18:32:11 +01:00
$sql .= " ,note_private = " . ( ! empty ( $this -> note_private ) ? " ' " . $this -> db -> escape ( $this -> note_private ) . " ' " : " null " );
$sql .= " ,note_public = " . ( ! empty ( $this -> note_public ) ? " ' " . $this -> db -> escape ( $this -> note_public ) . " ' " : " null " );
2017-10-16 17:16:44 +02:00
2019-11-13 18:32:11 +01:00
$sql .= " ,siren = ' " . $this -> db -> escape ( $this -> idprof1 ) . " ' " ;
$sql .= " ,siret = ' " . $this -> db -> escape ( $this -> idprof2 ) . " ' " ;
$sql .= " ,ape = ' " . $this -> db -> escape ( $this -> idprof3 ) . " ' " ;
$sql .= " ,idprof4 = ' " . $this -> db -> escape ( $this -> idprof4 ) . " ' " ;
$sql .= " ,idprof5 = ' " . $this -> db -> escape ( $this -> idprof5 ) . " ' " ;
$sql .= " ,idprof6 = ' " . $this -> db -> escape ( $this -> idprof6 ) . " ' " ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$sql .= " ,tva_assuj = " . ( $this -> tva_assuj != '' ? " ' " . $this -> db -> escape ( $this -> tva_assuj ) . " ' " : " null " );
$sql .= " ,tva_intra = ' " . $this -> db -> escape ( $this -> tva_intra ) . " ' " ;
2021-06-09 15:36:47 +02:00
$sql .= " ,status = " . (( int ) $this -> status );
2017-10-13 13:28:26 +02:00
// Local taxes
2019-11-13 18:32:11 +01:00
$sql .= " ,localtax1_assuj = " . ( $this -> localtax1_assuj != '' ? " ' " . $this -> db -> escape ( $this -> localtax1_assuj ) . " ' " : " null " );
$sql .= " ,localtax2_assuj = " . ( $this -> localtax2_assuj != '' ? " ' " . $this -> db -> escape ( $this -> localtax2_assuj ) . " ' " : " null " );
2020-12-28 21:08:56 +01:00
if ( $this -> localtax1_assuj == 1 ) {
if ( $this -> localtax1_value != '' ) {
2019-11-13 18:32:11 +01:00
$sql .= " ,localtax1_value = " . $this -> localtax1_value ;
2020-12-28 21:08:56 +01:00
} else {
$sql .= " ,localtax1_value =0.000 " ;
}
} else {
$sql .= " ,localtax1_value =0.000 " ;
}
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( $this -> localtax2_assuj == 1 ) {
if ( $this -> localtax2_value != '' ) {
2019-11-13 18:32:11 +01:00
$sql .= " ,localtax2_value = " . $this -> localtax2_value ;
2020-12-28 21:08:56 +01:00
} else {
$sql .= " ,localtax2_value =0.000 " ;
}
} else {
$sql .= " ,localtax2_value =0.000 " ;
}
2017-10-13 13:28:26 +02:00
$sql .= " ,capital = " . ( $this -> capital == '' ? " null " : $this -> capital );
2019-11-13 18:32:11 +01:00
$sql .= " ,prefix_comm = " . ( ! empty ( $this -> prefix_comm ) ? " ' " . $this -> db -> escape ( $this -> prefix_comm ) . " ' " : " null " );
2017-10-13 13:28:26 +02:00
2022-03-30 10:14:28 +02:00
$sql .= " ,fk_effectif = " . ( $this -> effectif_id > 0 ? (( int ) $this -> effectif_id ) : " null " );
2020-12-28 21:08:56 +01:00
if ( isset ( $this -> stcomm_id )) {
2022-10-26 12:15:30 +02:00
$sql .= " ,fk_stcomm= " . ( int ) $this -> stcomm_id ;
2022-03-30 10:14:28 +02:00
}
if ( isset ( $this -> typent_id )) {
$sql .= " ,fk_typent = " . ( $this -> typent_id > 0 ? (( int ) $this -> typent_id ) : " 0 " );
2017-10-13 13:28:26 +02:00
}
2019-11-13 18:32:11 +01:00
$sql .= " ,fk_forme_juridique = " . ( ! empty ( $this -> forme_juridique_code ) ? " ' " . $this -> db -> escape ( $this -> forme_juridique_code ) . " ' " : " null " );
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$sql .= " ,mode_reglement = " . ( ! empty ( $this -> mode_reglement_id ) ? " ' " . $this -> db -> escape ( $this -> mode_reglement_id ) . " ' " : " null " );
$sql .= " ,cond_reglement = " . ( ! empty ( $this -> cond_reglement_id ) ? " ' " . $this -> db -> escape ( $this -> cond_reglement_id ) . " ' " : " null " );
2021-10-28 16:53:28 +02:00
$sql .= " ,deposit_percent = " . ( ! empty ( $this -> deposit_percent ) ? " ' " . $this -> db -> escape ( $this -> deposit_percent ) . " ' " : " null " );
2020-10-31 18:51:30 +01:00
$sql .= " ,transport_mode = " . ( ! empty ( $this -> transport_mode_id ) ? " ' " . $this -> db -> escape ( $this -> transport_mode_id ) . " ' " : " null " );
2020-10-31 14:32:18 +01:00
$sql .= " ,mode_reglement_supplier = " . ( ! empty ( $this -> mode_reglement_supplier_id ) ? " ' " . $this -> db -> escape ( $this -> mode_reglement_supplier_id ) . " ' " : " null " );
2019-11-13 18:32:11 +01:00
$sql .= " ,cond_reglement_supplier = " . ( ! empty ( $this -> cond_reglement_supplier_id ) ? " ' " . $this -> db -> escape ( $this -> cond_reglement_supplier_id ) . " ' " : " null " );
2020-10-31 18:51:30 +01:00
$sql .= " ,transport_mode_supplier = " . ( ! empty ( $this -> transport_mode_supplier_id ) ? " ' " . $this -> db -> escape ( $this -> transport_mode_supplier_id ) . " ' " : " null " );
2019-11-13 18:32:11 +01:00
$sql .= " ,fk_shipping_method = " . ( ! empty ( $this -> shipping_method_id ) ? " ' " . $this -> db -> escape ( $this -> shipping_method_id ) . " ' " : " null " );
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$sql .= " ,client = " . ( ! empty ( $this -> client ) ? $this -> client : 0 );
$sql .= " ,fournisseur = " . ( ! empty ( $this -> fournisseur ) ? $this -> fournisseur : 0 );
$sql .= " ,barcode = " . ( ! empty ( $this -> barcode ) ? " ' " . $this -> db -> escape ( $this -> barcode ) . " ' " : " null " );
$sql .= " ,default_lang = " . ( ! empty ( $this -> default_lang ) ? " ' " . $this -> db -> escape ( $this -> default_lang ) . " ' " : " null " );
$sql .= " ,logo = " . ( ! empty ( $this -> logo ) ? " ' " . $this -> db -> escape ( $this -> logo ) . " ' " : " null " );
$sql .= " ,logo_squarred = " . ( ! empty ( $this -> logo_squarred ) ? " ' " . $this -> db -> escape ( $this -> logo_squarred ) . " ' " : " null " );
$sql .= " ,outstanding_limit= " . ( $this -> outstanding_limit != '' ? $this -> outstanding_limit : 'null' );
$sql .= " ,order_min_amount= " . ( $this -> order_min_amount != '' ? $this -> order_min_amount : 'null' );
$sql .= " ,supplier_order_min_amount= " . ( $this -> supplier_order_min_amount != '' ? $this -> supplier_order_min_amount : 'null' );
2017-10-13 13:28:26 +02:00
$sql .= " ,fk_prospectlevel=' " . $this -> db -> escape ( $this -> fk_prospectlevel ) . " ' " ;
2021-04-14 04:45:17 +02:00
if ( empty ( $conf -> global -> MAIN_COMPANY_PERENTITY_SHARED )) {
2021-10-25 22:07:31 +02:00
$sql .= " , accountancy_code_buy = ' " . $this -> db -> escape ( $this -> accountancy_code_buy ) . " ' " ;
$sql .= " , accountancy_code_sell= ' " . $this -> db -> escape ( $this -> accountancy_code_sell ) . " ' " ;
2021-10-07 06:18:39 +02:00
if ( $customer ) {
$sql .= " , code_compta = " . ( ! empty ( $this -> code_compta_client ) ? " ' " . $this -> db -> escape ( $this -> code_compta_client ) . " ' " : " null " );
}
if ( $supplier ) {
$sql .= " , code_compta_fournisseur = " . (( $this -> code_compta_fournisseur != " " ) ? " ' " . $this -> db -> escape ( $this -> code_compta_fournisseur ) . " ' " : " null " );
}
2021-04-14 04:45:17 +02:00
}
2019-11-13 18:32:11 +01:00
$sql .= " ,webservices_url = " . ( ! empty ( $this -> webservices_url ) ? " ' " . $this -> db -> escape ( $this -> webservices_url ) . " ' " : " null " );
$sql .= " ,webservices_key = " . ( ! empty ( $this -> webservices_key ) ? " ' " . $this -> db -> escape ( $this -> webservices_key ) . " ' " : " null " );
2017-10-13 13:28:26 +02:00
//Incoterms
2021-06-09 15:36:47 +02:00
$sql .= " , fk_incoterms = " . (( int ) $this -> fk_incoterms );
2019-11-13 18:32:11 +01:00
$sql .= " , location_incoterms = " . ( ! empty ( $this -> location_incoterms ) ? " ' " . $this -> db -> escape ( $this -> location_incoterms ) . " ' " : " null " );
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( $customer ) {
2019-11-13 18:32:11 +01:00
$sql .= " , code_client = " . ( ! empty ( $this -> code_client ) ? " ' " . $this -> db -> escape ( $this -> code_client ) . " ' " : " null " );
2017-10-13 13:28:26 +02:00
}
2020-12-28 21:08:56 +01:00
if ( $supplier ) {
2019-11-13 18:32:11 +01:00
$sql .= " , code_fournisseur = " . ( ! empty ( $this -> code_fournisseur ) ? " ' " . $this -> db -> escape ( $this -> code_fournisseur ) . " ' " : " null " );
2017-10-13 13:28:26 +02:00
}
2019-11-13 18:32:11 +01:00
$sql .= " , fk_user_modif = " . ( $user -> id > 0 ? $user -> id : " null " );
2017-10-13 13:28:26 +02:00
$sql .= " , fk_multicurrency = " . ( int ) $this -> fk_multicurrency ;
2018-03-15 01:33:46 +01:00
$sql .= " , multicurrency_code = ' " . $this -> db -> escape ( $this -> multicurrency_code ) . " ' " ;
2020-07-27 15:27:49 +02:00
$sql .= " , model_pdf = ' " . $this -> db -> escape ( $this -> model_pdf ) . " ' " ;
2019-11-13 18:32:11 +01:00
$sql .= " WHERE rowid = " . ( int ) $id ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
if ( is_object ( $this -> oldcopy )) { // If we have information on old values
if ( $this -> oldcopy -> country_id != $this -> country_id ) {
2018-10-21 11:44:21 +02:00
unset ( $this -> country_code );
unset ( $this -> country );
}
2020-12-28 21:08:56 +01:00
if ( $this -> oldcopy -> state_id != $this -> state_id ) {
2018-10-21 11:44:21 +02:00
unset ( $this -> state_code );
unset ( $this -> state );
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 18:32:11 +01:00
unset ( $this -> country_code ); // We clean this, in the doubt, because it may have been changed after an update of country_id
2018-10-21 11:44:21 +02:00
unset ( $this -> country );
unset ( $this -> state_code );
unset ( $this -> state );
}
2017-10-13 13:28:26 +02:00
$nbrowsaffected = $this -> db -> affected_rows ( $resql );
2020-12-28 21:08:56 +01:00
if ( ! $error && $nbrowsaffected ) {
2017-10-13 13:28:26 +02:00
// Update information on linked member if it is an update
2020-12-28 21:08:56 +01:00
if ( ! $nosyncmember && ! empty ( $conf -> adherent -> enabled )) {
2017-10-13 13:28:26 +02:00
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php' ;
dol_syslog ( get_class ( $this ) . " ::update update linked member " );
2019-11-13 18:32:11 +01:00
$lmember = new Adherent ( $this -> db );
$result = $lmember -> fetch ( 0 , 0 , $this -> id );
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( $result > 0 ) {
2019-11-13 18:32:11 +01:00
$lmember -> company = $this -> name ;
2017-10-13 13:28:26 +02:00
//$lmember->firstname=$this->firstname?$this->firstname:$lmember->firstname; // We keep firstname and lastname of member unchanged
//$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname; // We keep firstname and lastname of member unchanged
2019-11-13 18:32:11 +01:00
$lmember -> address = $this -> address ;
$lmember -> zip = $this -> zip ;
$lmember -> town = $this -> town ;
$lmember -> email = $this -> email ;
$lmember -> socialnetworks = $this -> socialnetworks ;
$lmember -> phone = $this -> phone ;
$lmember -> state_id = $this -> state_id ;
$lmember -> country_id = $this -> country_id ;
$result = $lmember -> update ( $user , 0 , 1 , 1 , 1 ); // Use nosync to 1 to avoid cyclic updates
2020-12-28 21:08:56 +01:00
if ( $result < 0 ) {
2019-09-02 16:01:51 +02:00
$this -> error = $lmember -> error ;
$this -> errors = array_merge ( $this -> errors , $lmember -> errors );
2019-01-27 11:55:16 +01:00
dol_syslog ( get_class ( $this ) . " ::update " . $this -> error , LOG_ERR );
2017-10-13 13:28:26 +02:00
$error ++ ;
}
2020-12-28 21:08:56 +01:00
} elseif ( $result < 0 ) {
2019-11-13 18:32:11 +01:00
$this -> error = $lmember -> error ;
2017-10-13 13:28:26 +02:00
$error ++ ;
}
}
}
2019-11-13 18:32:11 +01:00
$action = 'update' ;
2017-10-13 13:28:26 +02:00
2021-04-14 04:45:17 +02:00
// update accountancy for this entity
if ( ! $error && ! empty ( $conf -> global -> MAIN_COMPANY_PERENTITY_SHARED )) {
2021-10-25 22:07:31 +02:00
$this -> db -> query ( " DELETE FROM " . MAIN_DB_PREFIX . " societe_perentity WHERE fk_soc = " . (( int ) $this -> id ) . " AND entity = " . (( int ) $conf -> entity ));
2021-04-14 04:45:17 +02:00
2021-10-25 22:07:31 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " societe_perentity ( " ;
2021-04-14 04:45:17 +02:00
$sql .= " fk_soc " ;
$sql .= " , entity " ;
2021-10-07 06:18:39 +02:00
$sql .= " , accountancy_code_customer " ;
$sql .= " , accountancy_code_supplier " ;
2021-04-14 04:45:17 +02:00
$sql .= " , accountancy_code_buy " ;
$sql .= " , accountancy_code_sell " ;
$sql .= " ) VALUES ( " ;
$sql .= $this -> id ;
2021-10-25 22:07:31 +02:00
$sql .= " , " . $conf -> entity ;
$sql .= " , ' " . $this -> db -> escape ( $this -> code_compta_client ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> code_compta_fournisseur ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> accountancy_code_buy ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> accountancy_code_sell ) . " ' " ;
2021-04-14 04:45:17 +02:00
$sql .= " ) " ;
$result = $this -> db -> query ( $sql );
if ( ! $result ) {
$error ++ ;
$this -> error = 'ErrorFailedToUpdateAccountancyForEntity' ;
}
}
2018-04-10 12:03:01 +02:00
// Actions on extra fields
2020-12-28 21:08:56 +01:00
if ( ! $error ) {
2019-11-13 18:32:11 +01:00
$result = $this -> insertExtraFields ();
2020-12-28 21:08:56 +01:00
if ( $result < 0 ) {
2018-04-10 12:03:01 +02:00
$error ++ ;
2017-10-13 13:28:26 +02:00
}
}
2020-04-01 16:21:03 +02:00
// Actions on extra languages
2020-12-28 21:08:56 +01:00
if ( ! $error && empty ( $conf -> global -> MAIN_EXTRALANGUAGES_DISABLED )) { // For avoid conflicts if trigger used
2020-04-01 16:21:03 +02:00
$result = $this -> insertExtraLanguages ();
2020-12-28 21:08:56 +01:00
if ( $result < 0 ) {
2020-04-01 16:21:03 +02:00
$error ++ ;
}
}
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( ! $error && $call_trigger ) {
2017-10-13 13:28:26 +02:00
// Call trigger
2019-11-13 18:32:11 +01:00
$result = $this -> call_trigger ( 'COMPANY_MODIFY' , $user );
2020-12-28 21:08:56 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2017-10-13 13:28:26 +02:00
// End call triggers
}
2020-12-28 21:08:56 +01:00
if ( ! $error ) {
2017-10-13 13:28:26 +02:00
dol_syslog ( get_class ( $this ) . " ::Update success " );
$this -> db -> commit ();
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
$this -> db -> rollback ();
return - 1 ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-12-28 21:08:56 +01:00
if ( $this -> db -> errno () == 'DB_ERROR_RECORD_ALREADY_EXISTS' ) {
2017-10-13 13:28:26 +02:00
// Doublon
$this -> error = $langs -> trans ( " ErrorDuplicateField " );
$result = - 1 ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
$this -> error = $this -> db -> lasterror ();
$result = - 2 ;
}
$this -> db -> rollback ();
return $result ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
$this -> db -> rollback ();
2019-01-27 11:55:16 +01:00
dol_syslog ( get_class ( $this ) . " ::Update fails verify " . join ( ',' , $this -> errors ), LOG_WARNING );
2017-10-13 13:28:26 +02:00
return - 3 ;
}
}
/**
* Load a third party from database into memory
*
* @ param int $rowid Id of third party to load
* @ param string $ref Reference of third party , name ( Warning , this can return several records )
* @ param string $ref_ext External reference of third party ( Warning , this information is a free field not provided by Dolibarr )
2020-08-28 22:44:58 +02:00
* @ param string $barcode Barcode of third party to load
2017-10-13 13:28:26 +02:00
* @ param string $idprof1 Prof id 1 of third party ( Warning , this can return several records )
* @ param string $idprof2 Prof id 2 of third party ( Warning , this can return several records )
* @ param string $idprof3 Prof id 3 of third party ( Warning , this can return several records )
* @ param string $idprof4 Prof id 4 of third party ( Warning , this can return several records )
* @ param string $idprof5 Prof id 5 of third party ( Warning , this can return several records )
* @ param string $idprof6 Prof id 6 of third party ( Warning , this can return several records )
2018-02-23 19:55:15 +01:00
* @ param string $email Email of third party ( Warning , this can return several records )
* @ param string $ref_alias Name_alias of third party ( Warning , this can return several records )
2017-10-13 13:28:26 +02:00
* @ return int > 0 if OK , < 0 if KO or if two records found for same ref or idprof , 0 if not found .
*/
2020-08-28 22:44:58 +02:00
public function fetch ( $rowid , $ref = '' , $ref_ext = '' , $barcode = '' , $idprof1 = '' , $idprof2 = '' , $idprof3 = '' , $idprof4 = '' , $idprof5 = '' , $idprof6 = '' , $email = '' , $ref_alias = '' )
2017-10-13 13:28:26 +02:00
{
global $langs ;
global $conf ;
2020-12-28 21:08:56 +01:00
if ( empty ( $rowid ) && empty ( $ref ) && empty ( $ref_ext ) && empty ( $barcode ) && empty ( $idprof1 ) && empty ( $idprof2 ) && empty ( $idprof3 ) && empty ( $idprof4 ) && empty ( $idprof5 ) && empty ( $idprof6 ) && empty ( $email )) {
return - 1 ;
}
2017-10-13 13:28:26 +02:00
2020-09-08 04:21:35 +02:00
$sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.address, s.datec as date_creation, s.prefix_comm' ;
2021-01-17 02:09:21 +01:00
$sql .= ', s.status, s.fk_warehouse' ;
2017-10-13 13:28:26 +02:00
$sql .= ', s.price_level' ;
$sql .= ', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif' ;
2019-09-11 22:27:09 +02:00
$sql .= ', s.phone, s.fax, s.email' ;
2019-10-01 20:14:06 +02:00
$sql .= ', s.socialnetworks' ;
2019-09-11 22:27:09 +02:00
$sql .= ', s.url, s.zip, s.town, s.note_private, s.note_public, s.model_pdf, s.client, s.fournisseur' ;
2017-10-13 13:28:26 +02:00
$sql .= ', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6' ;
$sql .= ', s.capital, s.tva_intra' ;
$sql .= ', s.fk_typent as typent_id' ;
$sql .= ', s.fk_effectif as effectif_id' ;
$sql .= ', s.fk_forme_juridique as forme_juridique_code' ;
2021-05-12 14:19:12 +02:00
$sql .= ', s.webservices_url, s.webservices_key, s.model_pdf' ;
2021-04-14 04:45:17 +02:00
if ( empty ( $conf -> global -> MAIN_COMPANY_PERENTITY_SHARED )) {
2021-10-07 06:18:39 +02:00
$sql .= ', s.code_compta, s.code_compta_fournisseur, s.accountancy_code_buy, s.accountancy_code_sell' ;
2021-04-14 04:45:17 +02:00
} else {
2021-10-07 06:18:39 +02:00
$sql .= ', spe.accountancy_code_customer as code_compta, spe.accountancy_code_supplier as code_compta_fournisseur, spe.accountancy_code_buy, spe.accountancy_code_sell' ;
2021-04-14 04:45:17 +02:00
}
2021-10-07 06:18:39 +02:00
$sql .= ', s.code_client, s.code_fournisseur, s.parent, s.barcode' ;
2021-09-29 12:05:38 +02:00
$sql .= ', s.fk_departement as state_id, s.fk_pays as country_id, s.fk_stcomm, s.mode_reglement, s.cond_reglement, s.deposit_percent, s.transport_mode' ;
2020-10-30 05:45:36 +01:00
$sql .= ', s.fk_account, s.tva_assuj' ;
2020-10-30 14:33:16 +01:00
$sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.transport_mode_supplier' ;
2020-10-30 05:45:36 +01:00
$sql .= ', s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred' ;
2017-10-13 13:28:26 +02:00
$sql .= ', s.fk_shipping_method' ;
$sql .= ', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms' ;
2018-01-20 21:57:36 +01:00
$sql .= ', s.order_min_amount, s.supplier_order_min_amount' ;
2017-10-13 13:28:26 +02:00
$sql .= ', s.fk_multicurrency, s.multicurrency_code' ;
$sql .= ', fj.libelle as forme_juridique' ;
$sql .= ', e.libelle as effectif' ;
$sql .= ', c.code as country_code, c.label as country' ;
2021-02-26 13:15:02 +01:00
$sql .= ', d.code_departement as state_code, d.nom as state' ;
$sql .= ', r.rowid as region_id, r.code_region as region_code' ;
2020-04-27 17:35:14 +02:00
$sql .= ', st.libelle as stcomm, st.picto as stcomm_picto' ;
2017-10-13 13:28:26 +02:00
$sql .= ', te.code as typent_code' ;
2019-06-25 13:00:02 +02:00
$sql .= ', i.libelle as label_incoterms' ;
2021-05-12 14:19:12 +02:00
if ( empty ( $conf -> multicompany -> enabled )) {
$sql .= ', s.remise_client, s.remise_supplier' ;
} else {
$sql .= ', sr.remise_client, sr2.remise_supplier' ;
}
2017-10-13 13:28:26 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe as s' ;
2021-04-14 04:45:17 +02:00
if ( ! empty ( $conf -> global -> MAIN_COMPANY_PERENTITY_SHARED )) {
2021-10-25 22:07:31 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . (( int ) $conf -> entity );
2021-04-14 04:45:17 +02:00
}
2017-10-13 13:28:26 +02:00
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_effectif as e ON s.fk_effectif = e.id' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as c ON s.fk_pays = c.rowid' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_stcomm as st ON s.fk_stcomm = st.id' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_departements as d ON s.fk_departement = d.rowid' ;
2021-02-26 23:29:13 +01:00
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_regions as r ON d.fk_region = r.code_region ' ;
2017-10-13 13:28:26 +02:00
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_typent as te ON s.fk_typent = te.id' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_incoterms as i ON s.fk_incoterms = i.rowid' ;
2021-05-12 14:19:12 +02:00
// With default setup, llx_societe_remise is a history table in default setup and current value is in llx_societe.
// We use it for real value when multicompany is on. A better place would be into llx_societe_perentity.
if ( ! empty ( $conf -> multicompany -> enabled )) {
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe_remise as sr ON sr.rowid = (SELECT MAX(rowid) FROM ' . MAIN_DB_PREFIX . 'societe_remise WHERE fk_soc = s.rowid AND entity IN (' . getEntity ( 'discount' ) . '))' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe_remise_supplier as sr2 ON sr2.rowid = (SELECT MAX(rowid) FROM ' . MAIN_DB_PREFIX . 'societe_remise_supplier WHERE fk_soc = s.rowid AND entity IN (' . getEntity ( 'discount' ) . '))' ;
}
2018-01-30 15:48:09 +01:00
$sql .= ' WHERE s.entity IN (' . getEntity ( $this -> element ) . ')' ;
2020-12-28 21:08:56 +01:00
if ( $rowid ) {
2021-03-29 15:32:09 +02:00
$sql .= ' AND s.rowid = ' . (( int ) $rowid );
2020-12-28 21:08:56 +01:00
}
if ( $ref ) {
$sql .= " AND s.nom = ' " . $this -> db -> escape ( $ref ) . " ' " ;
}
if ( $ref_alias ) {
$sql .= " AND s.name_alias = ' " . $this -> db -> escape ( $ref_alias ) . " ' " ;
}
if ( $ref_ext ) {
$sql .= " AND s.ref_ext = ' " . $this -> db -> escape ( $ref_ext ) . " ' " ;
}
if ( $barcode ) {
$sql .= " AND s.barcode = ' " . $this -> db -> escape ( $barcode ) . " ' " ;
}
if ( $idprof1 ) {
$sql .= " AND s.siren = ' " . $this -> db -> escape ( $idprof1 ) . " ' " ;
}
if ( $idprof2 ) {
$sql .= " AND s.siret = ' " . $this -> db -> escape ( $idprof2 ) . " ' " ;
}
if ( $idprof3 ) {
$sql .= " AND s.ape = ' " . $this -> db -> escape ( $idprof3 ) . " ' " ;
}
if ( $idprof4 ) {
$sql .= " AND s.idprof4 = ' " . $this -> db -> escape ( $idprof4 ) . " ' " ;
}
if ( $idprof5 ) {
$sql .= " AND s.idprof5 = ' " . $this -> db -> escape ( $idprof5 ) . " ' " ;
}
if ( $idprof6 ) {
$sql .= " AND s.idprof6 = ' " . $this -> db -> escape ( $idprof6 ) . " ' " ;
}
if ( $email ) {
$sql .= " AND s.email = ' " . $this -> db -> escape ( $email ) . " ' " ;
}
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2019-11-13 18:32:11 +01:00
$num = $this -> db -> num_rows ( $resql );
2020-12-28 21:08:56 +01:00
if ( $num > 1 ) {
2019-11-13 18:32:11 +01:00
$this -> error = 'Fetch found several records. Rename one of thirdparties to avoid duplicate.' ;
2017-10-13 13:28:26 +02:00
dol_syslog ( $this -> error , LOG_ERR );
$result = - 2 ;
2020-12-28 21:08:56 +01:00
} elseif ( $num ) { // $num = 1
2017-10-13 13:28:26 +02:00
$obj = $this -> db -> fetch_object ( $resql );
$this -> id = $obj -> rowid ;
$this -> entity = $obj -> entity ;
2019-11-13 18:32:11 +01:00
$this -> canvas = $obj -> canvas ;
2017-10-13 13:28:26 +02:00
$this -> ref = $obj -> rowid ;
2019-11-13 18:32:11 +01:00
$this -> name = $obj -> name ;
$this -> nom = $obj -> name ; // deprecated
2017-10-13 13:28:26 +02:00
$this -> name_alias = $obj -> name_alias ;
$this -> ref_ext = $obj -> ref_ext ;
$this -> date_creation = $this -> db -> jdate ( $obj -> date_creation );
$this -> date_modification = $this -> db -> jdate ( $obj -> date_modification );
$this -> user_creation = $obj -> fk_user_creat ;
$this -> user_modification = $obj -> fk_user_modif ;
2019-11-13 18:32:11 +01:00
$this -> address = $obj -> address ;
2017-10-13 13:28:26 +02:00
$this -> zip = $obj -> zip ;
$this -> town = $obj -> town ;
$this -> country_id = $obj -> country_id ;
2019-11-13 18:32:11 +01:00
$this -> country_code = $obj -> country_id ? $obj -> country_code : '' ;
2021-09-15 19:02:17 +02:00
$this -> country = $obj -> country_id ? (( $langs -> transnoentities ( 'Country' . $obj -> country_code ) != 'Country' . $obj -> country_code ) ? $langs -> transnoentities ( 'Country' . $obj -> country_code ) : $obj -> country ) : '' ;
2017-10-13 13:28:26 +02:00
2019-04-05 20:06:13 +02:00
$this -> state_id = $obj -> state_id ;
2017-10-13 13:28:26 +02:00
$this -> state_code = $obj -> state_code ;
2021-02-26 13:15:02 +01:00
$this -> region_id = $obj -> region_id ;
2021-10-25 22:07:31 +02:00
$this -> region_code = $obj -> region_code ;
2019-11-13 18:32:11 +01:00
$this -> state = ( $obj -> state != '-' ? $obj -> state : '' );
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$transcode = $langs -> trans ( 'StatusProspect' . $obj -> fk_stcomm );
$label = ( $transcode != 'StatusProspect' . $obj -> fk_stcomm ? $transcode : $obj -> stcomm );
$this -> stcomm_id = $obj -> fk_stcomm ; // id status prospect
$this -> status_prospect_label = $label ; // label status prospect
2020-10-31 14:32:18 +01:00
$this -> stcomm_picto = $obj -> stcomm_picto ; // picto statut commercial
2017-10-13 13:28:26 +02:00
2020-10-31 14:32:18 +01:00
$this -> email = $obj -> email ;
2019-10-01 20:14:06 +02:00
$this -> socialnetworks = ( array ) json_decode ( $obj -> socialnetworks , true );
2019-09-11 22:27:09 +02:00
2017-10-13 13:28:26 +02:00
$this -> url = $obj -> url ;
$this -> phone = $obj -> phone ;
$this -> fax = $obj -> fax ;
2019-11-13 18:32:11 +01:00
$this -> parent = $obj -> parent ;
2017-10-13 13:28:26 +02:00
$this -> idprof1 = $obj -> idprof1 ;
$this -> idprof2 = $obj -> idprof2 ;
$this -> idprof3 = $obj -> idprof3 ;
$this -> idprof4 = $obj -> idprof4 ;
$this -> idprof5 = $obj -> idprof5 ;
$this -> idprof6 = $obj -> idprof6 ;
2019-11-13 18:32:11 +01:00
$this -> capital = $obj -> capital ;
2017-10-13 13:28:26 +02:00
$this -> code_client = $obj -> code_client ;
$this -> code_fournisseur = $obj -> code_fournisseur ;
2022-01-13 19:41:52 +01:00
$this -> code_compta = $obj -> code_compta ; // For backward compatibility
$this -> code_compta_client = $obj -> code_compta ;
2017-10-13 13:28:26 +02:00
$this -> code_compta_fournisseur = $obj -> code_compta_fournisseur ;
$this -> barcode = $obj -> barcode ;
$this -> tva_assuj = $obj -> tva_assuj ;
$this -> tva_intra = $obj -> tva_intra ;
$this -> status = $obj -> status ;
// Local Taxes
$this -> localtax1_assuj = $obj -> localtax1_assuj ;
$this -> localtax2_assuj = $obj -> localtax2_assuj ;
$this -> localtax1_value = $obj -> localtax1_value ;
$this -> localtax2_value = $obj -> localtax2_value ;
$this -> typent_id = $obj -> typent_id ;
$this -> typent_code = $obj -> typent_code ;
$this -> effectif_id = $obj -> effectif_id ;
2019-11-13 18:32:11 +01:00
$this -> effectif = $obj -> effectif_id ? $obj -> effectif : '' ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$this -> forme_juridique_code = $obj -> forme_juridique_code ;
2019-12-18 15:20:36 +01:00
$this -> forme_juridique = $obj -> forme_juridique_code ? $obj -> forme_juridique : '' ;
2017-10-13 13:28:26 +02:00
$this -> fk_prospectlevel = $obj -> fk_prospectlevel ;
$this -> prefix_comm = $obj -> prefix_comm ;
2020-12-29 14:47:16 +01:00
$this -> remise_percent = $obj -> remise_client ? price2num ( $obj -> remise_client ) : 0 ; // 0.000000 must be 0
2019-11-13 18:32:11 +01:00
$this -> remise_supplier_percent = $obj -> remise_supplier ;
2021-05-12 14:19:12 +02:00
2017-10-13 13:28:26 +02:00
$this -> mode_reglement_id = $obj -> mode_reglement ;
$this -> cond_reglement_id = $obj -> cond_reglement ;
2021-09-29 12:05:38 +02:00
$this -> deposit_percent = $obj -> deposit_percent ;
2019-07-22 06:56:55 +02:00
$this -> transport_mode_id = $obj -> transport_mode ;
2017-10-13 13:28:26 +02:00
$this -> mode_reglement_supplier_id = $obj -> mode_reglement_supplier ;
$this -> cond_reglement_supplier_id = $obj -> cond_reglement_supplier ;
2020-10-31 14:32:18 +01:00
$this -> transport_mode_supplier_id = $obj -> transport_mode_supplier ;
$this -> shipping_method_id = ( $obj -> fk_shipping_method > 0 ) ? $obj -> fk_shipping_method : null ;
$this -> fk_account = $obj -> fk_account ;
2017-10-13 13:28:26 +02:00
2020-10-31 14:32:18 +01:00
$this -> client = $obj -> client ;
$this -> fournisseur = $obj -> fournisseur ;
2017-10-13 13:28:26 +02:00
$this -> note = $obj -> note_private ; // TODO Deprecated for backward comtability
$this -> note_private = $obj -> note_private ;
$this -> note_public = $obj -> note_public ;
2020-08-18 14:48:38 +02:00
$this -> model_pdf = $obj -> model_pdf ;
2020-11-09 15:18:56 +01:00
$this -> modelpdf = $obj -> model_pdf ; // deprecated
2017-10-13 13:28:26 +02:00
$this -> default_lang = $obj -> default_lang ;
$this -> logo = $obj -> logo ;
2019-10-11 11:27:05 +02:00
$this -> logo_squarred = $obj -> logo_squarred ;
2017-10-13 13:28:26 +02:00
$this -> webservices_url = $obj -> webservices_url ;
$this -> webservices_key = $obj -> webservices_key ;
2020-12-04 04:13:42 +01:00
$this -> accountancy_code_buy = $obj -> accountancy_code_buy ;
$this -> accountancy_code_sell = $obj -> accountancy_code_sell ;
2017-10-13 13:28:26 +02:00
$this -> outstanding_limit = $obj -> outstanding_limit ;
2018-01-20 21:57:36 +01:00
$this -> order_min_amount = $obj -> order_min_amount ;
2019-11-13 18:32:11 +01:00
$this -> supplier_order_min_amount = $obj -> supplier_order_min_amount ;
2017-10-13 13:28:26 +02:00
// multiprix
$this -> price_level = $obj -> price_level ;
2021-01-17 02:26:09 +01:00
2021-01-17 02:09:21 +01:00
// warehouse
$this -> fk_warehouse = $obj -> fk_warehouse ;
2017-10-13 13:28:26 +02:00
$this -> import_key = $obj -> import_key ;
//Incoterms
$this -> fk_incoterms = $obj -> fk_incoterms ;
$this -> location_incoterms = $obj -> location_incoterms ;
2019-06-25 13:00:02 +02:00
$this -> label_incoterms = $obj -> label_incoterms ;
2017-10-13 13:28:26 +02:00
// multicurrency
$this -> fk_multicurrency = $obj -> fk_multicurrency ;
$this -> multicurrency_code = $obj -> multicurrency_code ;
2020-07-27 15:27:49 +02:00
$this -> model_pdf = $obj -> model_pdf ;
2017-10-13 13:28:26 +02:00
$result = 1 ;
2018-02-20 19:38:18 +01:00
// fetch optionals attributes and labels
$this -> fetch_optionals ();
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
$result = 0 ;
}
$this -> db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 18:32:11 +01:00
$this -> error = $this -> db -> lasterror ();
2021-03-11 19:09:42 +01:00
$this -> errors [] = $this -> db -> lasterror ();
2017-10-13 13:28:26 +02:00
$result = - 3 ;
}
// Use first price level if level not defined for third party
2020-12-28 21:08:56 +01:00
if (( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) && empty ( $this -> price_level )) {
$this -> price_level = 1 ;
}
2017-10-13 13:28:26 +02:00
return $result ;
}
/**
* Delete a third party from database and all its dependencies ( contacts , rib ... )
*
* @ param int $id Id of third party to delete
2019-01-17 15:57:17 +01:00
* @ param User $fuser User who ask to delete thirdparty
2017-10-13 13:28:26 +02:00
* @ param int $call_trigger 0 = No , 1 = yes
* @ return int < 0 if KO , 0 if nothing done , > 0 if OK
*/
2020-10-31 14:32:18 +01:00
public function delete ( $id , User $fuser = null , $call_trigger = 1 )
2017-10-13 13:28:26 +02:00
{
global $langs , $conf , $user ;
2020-12-28 21:08:56 +01:00
if ( empty ( $fuser )) {
$fuser = $user ;
}
2017-10-13 13:28:26 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2019-11-13 18:32:11 +01:00
$entity = isset ( $this -> entity ) ? $this -> entity : $conf -> entity ;
2017-10-13 13:28:26 +02:00
dol_syslog ( get_class ( $this ) . " ::delete " , LOG_DEBUG );
$error = 0 ;
// Test if child exists
$objectisused = $this -> isObjectUsed ( $id );
2020-12-28 21:08:56 +01:00
if ( empty ( $objectisused )) {
2017-10-13 13:28:26 +02:00
$this -> db -> begin ();
// User is mandatory for trigger call
2020-12-28 21:08:56 +01:00
if ( ! $error && $call_trigger ) {
2017-10-13 13:28:26 +02:00
// Call trigger
2019-11-13 18:32:11 +01:00
$result = $this -> call_trigger ( 'COMPANY_DELETE' , $fuser );
2020-12-28 21:08:56 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2017-10-13 13:28:26 +02:00
// End call triggers
}
2020-12-28 21:08:56 +01:00
if ( ! $error ) {
2017-10-13 13:28:26 +02:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
$static_cat = new Categorie ( $this -> db );
$toute_categs = array ();
// Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
2020-12-28 21:08:56 +01:00
if ( $this -> client || $this -> prospect ) {
2019-01-27 11:55:16 +01:00
$toute_categs [ 'customer' ] = $static_cat -> containing ( $this -> id , Categorie :: TYPE_CUSTOMER );
2017-10-13 13:28:26 +02:00
}
2020-12-28 21:08:56 +01:00
if ( $this -> fournisseur ) {
2019-01-27 11:55:16 +01:00
$toute_categs [ 'supplier' ] = $static_cat -> containing ( $this -> id , Categorie :: TYPE_SUPPLIER );
2017-10-13 13:28:26 +02:00
}
// Remove each "Categorie"
2020-12-28 21:08:56 +01:00
foreach ( $toute_categs as $type => $categs_type ) {
foreach ( $categs_type as $cat ) {
2017-10-13 13:28:26 +02:00
$cat -> del_type ( $this , $type );
}
}
}
2020-12-28 21:08:56 +01:00
if ( ! $error ) {
foreach ( $this -> childtablesoncascade as $tabletodelete ) {
2020-10-31 14:32:18 +01:00
$deleteFromObject = explode ( ':' , $tabletodelete );
if ( count ( $deleteFromObject ) >= 2 ) {
$className = str_replace ( '@' , '' , $deleteFromObject [ 0 ]);
$filepath = $deleteFromObject [ 1 ];
$columnName = $deleteFromObject [ 2 ];
2020-06-01 10:43:57 +02:00
if ( dol_include_once ( $filepath )) {
2020-06-06 21:32:25 +02:00
$child_object = new $className ( $this -> db );
$result = $child_object -> deleteByParentField ( $id , $columnName );
if ( $result < 0 ) {
$error ++ ;
$this -> errors [] = $child_object -> error ;
2020-06-06 21:45:53 +02:00
break ;
2020-05-26 21:27:46 +02:00
}
2020-06-01 10:43:57 +02:00
} else {
$error ++ ;
2020-10-31 14:32:18 +01:00
$this -> errors [] = 'Cannot include child class file ' . $filepath ;
2020-06-06 21:45:53 +02:00
break ;
2020-06-01 10:43:57 +02:00
}
} else {
2020-10-31 14:32:18 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . $tabletodelete ;
2021-03-30 19:12:07 +02:00
$sql .= " WHERE fk_soc = " . (( int ) $id );
2020-06-01 10:43:57 +02:00
if ( ! $this -> db -> query ( $sql )) {
$error ++ ;
$this -> errors [] = $this -> db -> lasterror ();
2020-06-06 21:45:53 +02:00
break ;
2020-05-26 21:27:46 +02:00
}
2017-10-13 13:28:26 +02:00
}
}
}
// Removed extrafields
2020-12-28 21:08:56 +01:00
if ( ! $error ) {
2019-11-13 18:32:11 +01:00
$result = $this -> deleteExtraFields ();
2020-12-28 21:08:56 +01:00
if ( $result < 0 ) {
2017-10-13 13:28:26 +02:00
$error ++ ;
dol_syslog ( get_class ( $this ) . " ::delete error -3 " . $this -> error , LOG_ERR );
}
}
2018-11-01 15:41:58 +01:00
// Remove links to subsidiaries companies
2020-12-28 21:08:56 +01:00
if ( ! $error ) {
2018-11-01 15:41:58 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " societe " ;
2019-11-13 18:32:11 +01:00
$sql .= " SET parent = NULL " ;
2021-03-30 19:12:07 +02:00
$sql .= " WHERE parent = " . (( int ) $id );
2020-12-28 21:08:56 +01:00
if ( ! $this -> db -> query ( $sql )) {
2018-11-01 15:41:58 +01:00
$error ++ ;
$this -> errors [] = $this -> db -> lasterror ();
}
}
2017-10-13 13:28:26 +02:00
// Remove third party
2020-12-28 21:08:56 +01:00
if ( ! $error ) {
2021-10-08 06:50:22 +02:00
if ( ! empty ( $conf -> global -> MAIN_COMPANY_PERENTITY_SHARED )) {
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " societe_perentity " ;
$sql .= " WHERE fk_soc = " . (( int ) $id );
if ( ! $this -> db -> query ( $sql )) {
$error ++ ;
$this -> errors [] = $this -> db -> lasterror ();
}
}
2017-10-13 13:28:26 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " societe " ;
2021-03-14 11:48:39 +01:00
$sql .= " WHERE rowid = " . (( int ) $id );
2020-12-28 21:08:56 +01:00
if ( ! $this -> db -> query ( $sql )) {
2017-10-13 13:28:26 +02:00
$error ++ ;
$this -> errors [] = $this -> db -> lasterror ();
}
}
2020-12-28 21:08:56 +01:00
if ( ! $error ) {
2017-10-13 13:28:26 +02:00
$this -> db -> commit ();
// Delete directory
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> societe -> multidir_output [ $entity ])) {
2019-11-13 18:32:11 +01:00
$docdir = $conf -> societe -> multidir_output [ $entity ] . " / " . $id ;
2020-12-28 21:08:56 +01:00
if ( dol_is_dir ( $docdir )) {
2017-10-13 13:28:26 +02:00
dol_delete_dir_recursive ( $docdir );
}
}
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
dol_syslog ( $this -> error , LOG_ERR );
$this -> db -> rollback ();
return - 1 ;
}
2020-12-28 21:08:56 +01:00
} else {
dol_syslog ( " Can't remove thirdparty with id " . $id . " . There is " . $objectisused . " childs " , LOG_WARNING );
}
2017-10-13 13:28:26 +02:00
return 0 ;
}
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Define third party as a customer
*
* @ return int < 0 if KO , > 0 if OK
*/
2020-10-31 14:32:18 +01:00
public function set_as_client ()
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2020-12-28 21:08:56 +01:00
if ( $this -> id ) {
2019-11-13 18:32:11 +01:00
$newclient = 1 ;
2020-12-28 21:08:56 +01:00
if ( $this -> client == 2 || $this -> client == 3 ) {
$newclient = 3 ; //If prospect, we keep prospect tag
}
2017-10-13 13:28:26 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " societe " ;
2021-03-30 03:37:54 +02:00
$sql .= " SET client = " . (( int ) $newclient );
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2017-10-13 13:28:26 +02:00
$this -> client = $newclient ;
return 1 ;
2020-12-28 21:08:56 +01:00
} else {
return - 1 ;
}
2017-10-13 13:28:26 +02:00
}
return 0 ;
}
2019-10-21 02:18:39 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
2019-10-21 02:18:39 +02:00
* Defines the company as a customer
2017-10-13 13:28:26 +02:00
*
2019-10-21 02:18:39 +02:00
* @ param float $remise Value in % of the discount
* @ param string $note Note / Reason for changing the discount
* @ param User $user User who sets the discount
2017-10-13 13:28:26 +02:00
* @ return int < 0 if KO , > 0 if OK
*/
2020-10-31 14:32:18 +01:00
public function set_remise_client ( $remise , $note , User $user )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $conf , $langs ;
2019-10-21 02:18:39 +02:00
// Parameter cleaning
2019-11-13 18:32:11 +01:00
$note = trim ( $note );
2020-12-28 21:08:56 +01:00
if ( ! $note ) {
2019-11-13 18:32:11 +01:00
$this -> error = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " NoteReason " ));
2017-10-13 13:28:26 +02:00
return - 2 ;
}
dol_syslog ( get_class ( $this ) . " ::set_remise_client " . $remise . " , " . $note . " , " . $user -> id );
2020-12-28 21:08:56 +01:00
if ( $this -> id ) {
2017-10-13 13:28:26 +02:00
$this -> db -> begin ();
2019-11-13 18:32:11 +01:00
$now = dol_now ();
2017-10-13 13:28:26 +02:00
2019-10-21 02:18:39 +02:00
// Position current discount
2017-10-13 13:28:26 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " societe " ;
2019-11-13 18:32:11 +01:00
$sql .= " SET remise_client = ' " . $this -> db -> escape ( $remise ) . " ' " ;
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( ! $resql ) {
2017-10-13 13:28:26 +02:00
$this -> db -> rollback ();
2019-11-13 18:32:11 +01:00
$this -> error = $this -> db -> error ();
2017-10-13 13:28:26 +02:00
return - 1 ;
}
2019-10-21 02:18:39 +02:00
// Writes trace in discount history
2017-10-13 13:28:26 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " societe_remise " ;
2019-11-13 18:32:11 +01:00
$sql .= " (entity, datec, fk_soc, remise_client, note, fk_user_author) " ;
2021-06-14 13:51:09 +02:00
$sql .= " VALUES ( " . $conf -> entity . " , ' " . $this -> db -> idate ( $now ) . " ', " . (( int ) $this -> id ) . " , ' " . $this -> db -> escape ( $remise ) . " ', " ;
2019-11-13 18:32:11 +01:00
$sql .= " ' " . $this -> db -> escape ( $note ) . " ', " ;
2021-06-14 13:51:09 +02:00
$sql .= " " . (( int ) $user -> id );
2019-11-13 18:32:11 +01:00
$sql .= " ) " ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( ! $resql ) {
2017-10-13 13:28:26 +02:00
$this -> db -> rollback ();
2019-11-13 18:32:11 +01:00
$this -> error = $this -> db -> lasterror ();
2017-10-13 13:28:26 +02:00
return - 1 ;
}
$this -> db -> commit ();
return 1 ;
}
}
2018-03-08 22:26:42 +01:00
2019-10-21 02:18:39 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2018-02-27 16:30:39 +01:00
/**
2019-10-21 02:18:39 +02:00
* Defines the company as a customer
2018-02-27 16:30:39 +01:00
*
2019-10-21 02:18:39 +02:00
* @ param float $remise Value in % of the discount
* @ param string $note Note / Reason for changing the discount
* @ param User $user User who sets the discount
2018-02-27 16:30:39 +01:00
* @ return int < 0 if KO , > 0 if OK
*/
2020-10-31 14:32:18 +01:00
public function set_remise_supplier ( $remise , $note , User $user )
2018-02-27 16:30:39 +01:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2018-02-27 16:30:39 +01:00
global $conf , $langs ;
2018-03-08 22:26:42 +01:00
2019-10-21 02:18:39 +02:00
// Parameter cleaning
2019-11-13 18:32:11 +01:00
$note = trim ( $note );
2020-12-28 21:08:56 +01:00
if ( ! $note ) {
2019-11-13 18:32:11 +01:00
$this -> error = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " NoteReason " ));
2018-02-27 16:30:39 +01:00
return - 2 ;
}
2018-03-08 22:26:42 +01:00
2018-02-27 16:30:39 +01:00
dol_syslog ( get_class ( $this ) . " ::set_remise_supplier " . $remise . " , " . $note . " , " . $user -> id );
2018-03-08 22:26:42 +01:00
2020-12-28 21:08:56 +01:00
if ( $this -> id ) {
2018-02-27 16:30:39 +01:00
$this -> db -> begin ();
2018-03-08 22:26:42 +01:00
2019-11-13 18:32:11 +01:00
$now = dol_now ();
2018-03-08 22:26:42 +01:00
2019-10-21 02:18:39 +02:00
// Position current discount
2018-02-27 16:30:39 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " societe " ;
2019-11-13 18:32:11 +01:00
$sql .= " SET remise_supplier = ' " . $this -> db -> escape ( $remise ) . " ' " ;
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( ! $resql ) {
2018-02-27 16:30:39 +01:00
$this -> db -> rollback ();
2019-11-13 18:32:11 +01:00
$this -> error = $this -> db -> error ();
2018-02-27 16:30:39 +01:00
return - 1 ;
}
2018-03-08 22:26:42 +01:00
2019-10-21 02:18:39 +02:00
// Writes trace in discount history
2018-02-27 16:30:39 +01:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " societe_remise_supplier " ;
2019-11-13 18:32:11 +01:00
$sql .= " (entity, datec, fk_soc, remise_supplier, note, fk_user_author) " ;
2021-06-14 13:51:09 +02:00
$sql .= " VALUES ( " . $conf -> entity . " , ' " . $this -> db -> idate ( $now ) . " ', " . (( int ) $this -> id ) . " , ' " . $this -> db -> escape ( $remise ) . " ', " ;
2019-11-13 18:32:11 +01:00
$sql .= " ' " . $this -> db -> escape ( $note ) . " ', " ;
2021-06-14 13:51:09 +02:00
$sql .= " " . (( int ) $user -> id );
2019-11-13 18:32:11 +01:00
$sql .= " ) " ;
2018-03-08 22:26:42 +01:00
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( ! $resql ) {
2018-02-27 16:30:39 +01:00
$this -> db -> rollback ();
2019-11-13 18:32:11 +01:00
$this -> error = $this -> db -> lasterror ();
2018-02-27 16:30:39 +01:00
return - 1 ;
}
2018-03-08 22:26:42 +01:00
2018-02-27 16:30:39 +01:00
$this -> db -> commit ();
return 1 ;
}
}
2017-10-13 13:28:26 +02:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Add a discount for third party
*
2018-02-14 18:02:40 +01:00
* @ param float $remise Amount of discount
* @ param User $user User adding discount
* @ param string $desc Reason of discount
2020-03-26 02:01:30 +01:00
* @ param string $vatrate VAT rate ( may contain the vat code too ) . Exemple : '1.23' , '1.23 (ABC)' , ...
2018-02-14 18:02:40 +01:00
* @ param int $discount_type 0 => customer discount , 1 => supplier discount
2020-03-26 02:01:30 +01:00
* @ return int < 0 if KO , id of discount record if OK
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function set_remise_except ( $remise , User $user , $desc , $vatrate = '' , $discount_type = 0 )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $langs ;
// Clean parameters
$remise = price2num ( $remise );
$desc = trim ( $desc );
// Check parameters
2022-08-12 15:54:50 +02:00
if ( ! ( $remise > 0 )) {
2019-11-13 18:32:11 +01:00
$this -> error = $langs -> trans ( " ErrorWrongValueForParameter " , " 1 " );
2017-10-13 13:28:26 +02:00
return - 1 ;
}
2020-12-28 21:08:56 +01:00
if ( ! $desc ) {
2019-11-13 18:32:11 +01:00
$this -> error = $langs -> trans ( " ErrorWrongValueForParameter " , " 3 " );
2017-10-13 13:28:26 +02:00
return - 2 ;
}
2020-12-28 21:08:56 +01:00
if ( $this -> id > 0 ) {
2020-03-26 02:01:30 +01:00
// Clean vat code
$reg = array ();
$vat_src_code = '' ;
2020-12-28 21:08:56 +01:00
if ( preg_match ( '/\((.*)\)/' , $vatrate , $reg )) {
2020-03-26 02:01:30 +01:00
$vat_src_code = $reg [ 1 ];
$vatrate = preg_replace ( '/\s*\(.*\)/' , '' , $vatrate ); // Remove code into vatrate.
}
2017-10-13 13:28:26 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php' ;
$discount = new DiscountAbsolute ( $this -> db );
2019-11-13 18:32:11 +01:00
$discount -> fk_soc = $this -> id ;
2018-10-19 14:27:15 +02:00
2019-11-13 18:32:11 +01:00
$discount -> discount_type = $discount_type ;
2018-10-19 14:27:15 +02:00
2019-11-13 18:32:11 +01:00
$discount -> amount_ht = $discount -> multicurrency_amount_ht = price2num ( $remise , 'MT' );
2020-03-26 02:01:30 +01:00
$discount -> amount_tva = $discount -> multicurrency_amount_tva = price2num ( $remise * $vatrate / 100 , 'MT' );
2019-11-13 18:32:11 +01:00
$discount -> amount_ttc = $discount -> multicurrency_amount_ttc = price2num ( $discount -> amount_ht + $discount -> amount_tva , 'MT' );
2018-10-19 14:27:15 +02:00
2020-11-27 14:24:15 +01:00
$discount -> tva_tx = price2num ( $vatrate );
2020-03-26 02:01:30 +01:00
$discount -> vat_src_code = $vat_src_code ;
2019-11-13 18:32:11 +01:00
$discount -> description = $desc ;
2018-02-14 18:02:40 +01:00
2019-11-13 18:32:11 +01:00
$result = $discount -> create ( $user );
2020-12-28 21:08:56 +01:00
if ( $result > 0 ) {
2017-10-13 13:28:26 +02:00
return $result ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 18:32:11 +01:00
$this -> error = $discount -> error ;
2017-10-13 13:28:26 +02:00
return - 3 ;
}
2020-12-28 21:08:56 +01:00
} else {
return 0 ;
}
2017-10-13 13:28:26 +02:00
}
/**
2019-10-21 02:18:39 +02:00
* Returns amount of included taxes of the current discounts / credits available from the company
2017-10-13 13:28:26 +02:00
*
2019-10-21 02:18:39 +02:00
* @ param User $user Filter on a user author of discounts
* @ param string $filter Other filter
2018-02-14 18:02:40 +01:00
* @ param integer $maxvalue Filter on max value for discount
* @ param int $discount_type 0 => customer discount , 1 => supplier discount
2017-10-13 13:28:26 +02:00
* @ return int < 0 if KO , Credit note amount otherwise
*/
2020-10-31 14:32:18 +01:00
public function getAvailableDiscounts ( $user = '' , $filter = '' , $maxvalue = 0 , $discount_type = 0 )
2017-10-13 13:28:26 +02:00
{
require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php' ;
2019-11-13 18:32:11 +01:00
$discountstatic = new DiscountAbsolute ( $this -> db );
$result = $discountstatic -> getAvailableDiscounts ( $this , $user , $filter , $maxvalue , $discount_type );
2020-12-28 21:08:56 +01:00
if ( $result >= 0 ) {
2017-10-13 13:28:26 +02:00
return $result ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 18:32:11 +01:00
$this -> error = $discountstatic -> error ;
2017-10-13 13:28:26 +02:00
return - 1 ;
}
}
/**
* Return array of sales representatives
*
2022-02-18 15:11:54 +01:00
* @ param User $user Object user ( not used )
2020-07-01 09:16:44 +02:00
* @ param int $mode 0 = Array with properties , 1 = Array of id .
* @ param string $sortfield List of sort fields , separated by comma . Example : 't1.fielda,t2.fieldb'
* @ param string $sortorder Sort order , separated by comma . Example : 'ASC,DESC' ;
* @ return array Array of sales representatives of third party
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function getSalesRepresentatives ( User $user , $mode = 0 , $sortfield = null , $sortorder = null )
2017-10-13 13:28:26 +02:00
{
global $conf ;
2019-11-13 18:32:11 +01:00
$reparray = array ();
2017-10-13 13:28:26 +02:00
2021-01-20 18:45:44 +01:00
$sql = " SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.office_phone, u.job, u.email, u.statut as status, u.entity, u.photo, u.gender " ;
2021-06-24 20:11:40 +02:00
$sql .= " , u.office_fax, u.user_mobile, u.personal_mobile " ;
2019-11-13 18:32:11 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_commerciaux as sc, " . MAIN_DB_PREFIX . " user as u " ;
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && ! empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE )) {
2019-11-13 18:32:11 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " usergroup_user as ug " ;
$sql .= " WHERE ((ug.fk_user = sc.fk_user " ;
$sql .= " AND ug.entity = " . $conf -> entity . " ) " ;
$sql .= " OR u.admin = 1) " ;
2020-12-28 21:08:56 +01:00
} else {
$sql .= " WHERE entity in (0, " . $conf -> entity . " ) " ;
}
2017-10-13 13:28:26 +02:00
2021-08-23 17:41:11 +02:00
$sql .= " AND u.rowid = sc.fk_user AND sc.fk_soc = " . (( int ) $this -> id );
2020-07-01 09:16:44 +02:00
if ( empty ( $sortfield ) && empty ( $sortorder )) {
$sortfield = 'u.lastname,u.firstname' ;
$sortorder = 'ASC,ASC' ;
}
$sql .= $this -> db -> order ( $sortfield , $sortorder );
2017-10-13 13:28:26 +02:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2017-10-13 13:28:26 +02:00
$num = $this -> db -> num_rows ( $resql );
2019-11-13 18:32:11 +01:00
$i = 0 ;
2020-12-28 21:08:56 +01:00
while ( $i < $num ) {
2017-10-13 13:28:26 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2018-03-22 16:05:50 +01:00
2020-12-28 21:08:56 +01:00
if ( empty ( $mode )) {
2019-11-13 18:32:11 +01:00
$reparray [ $i ][ 'id' ] = $obj -> rowid ;
$reparray [ $i ][ 'lastname' ] = $obj -> lastname ;
$reparray [ $i ][ 'firstname' ] = $obj -> firstname ;
$reparray [ $i ][ 'email' ] = $obj -> email ;
$reparray [ $i ][ 'phone' ] = $obj -> office_phone ;
2021-06-24 20:11:40 +02:00
$reparray [ $i ][ 'office_phone' ] = $obj -> office_phone ;
$reparray [ $i ][ 'office_fax' ] = $obj -> office_fax ;
$reparray [ $i ][ 'user_mobile' ] = $obj -> user_mobile ;
$reparray [ $i ][ 'personal_mobile' ] = $obj -> personal_mobile ;
2019-11-13 18:32:11 +01:00
$reparray [ $i ][ 'job' ] = $obj -> job ;
2020-03-12 12:45:44 +01:00
$reparray [ $i ][ 'statut' ] = $obj -> status ; // deprecated
2020-02-08 11:32:38 +01:00
$reparray [ $i ][ 'status' ] = $obj -> status ;
2019-11-13 18:32:11 +01:00
$reparray [ $i ][ 'entity' ] = $obj -> entity ;
$reparray [ $i ][ 'login' ] = $obj -> login ;
$reparray [ $i ][ 'photo' ] = $obj -> photo ;
2021-01-20 18:45:44 +01:00
$reparray [ $i ][ 'gender' ] = $obj -> gender ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 18:32:11 +01:00
$reparray [] = $obj -> rowid ;
2018-03-22 16:05:50 +01:00
}
2017-10-13 13:28:26 +02:00
$i ++ ;
}
return $reparray ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
dol_print_error ( $this -> db );
return - 1 ;
}
}
/**
* Set the price level
*
* @ param int $price_level Level of price
* @ param User $user Use making change
* @ return int < 0 if KO , > 0 if OK
*/
2021-04-01 10:05:37 +02:00
public function setPriceLevel ( $price_level , User $user )
2017-10-13 13:28:26 +02:00
{
2020-12-28 21:08:56 +01:00
if ( $this -> id ) {
2019-11-13 18:32:11 +01:00
$now = dol_now ();
2017-10-13 13:28:26 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " societe " ;
2021-03-29 22:51:36 +02:00
$sql .= " SET price_level = " . (( int ) $price_level );
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( ! $this -> db -> query ( $sql )) {
2017-10-13 13:28:26 +02:00
dol_print_error ( $this -> db );
return - 1 ;
}
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " societe_prices " ;
$sql .= " (datec, fk_soc, price_level, fk_user_author) " ;
2021-08-28 03:09:18 +02:00
$sql .= " VALUES (' " . $this -> db -> idate ( $now ) . " ', " . (( int ) $this -> id ) . " , " . (( int ) $price_level ) . " , " . (( int ) $user -> id ) . " ) " ;
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( ! $this -> db -> query ( $sql )) {
2017-10-13 13:28:26 +02:00
dol_print_error ( $this -> db );
return - 1 ;
}
return 1 ;
}
return - 1 ;
}
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Add link to sales representative
*
* @ param User $user Object user
* @ param int $commid Id of user
2019-03-15 19:34:04 +01:00
* @ return int <= 0 if KO , > 0 if OK
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function add_commercial ( User $user , $commid )
2017-10-13 13:28:26 +02:00
{
2019-03-15 19:34:04 +01:00
// phpcs:enable
2019-11-13 18:32:11 +01:00
$error = 0 ;
2018-08-13 17:26:32 +02:00
2020-12-28 21:08:56 +01:00
if ( $this -> id > 0 && $commid > 0 ) {
2020-10-31 14:32:18 +01:00
$this -> db -> begin ();
2020-12-28 21:08:56 +01:00
if ( ! $error ) {
2020-10-31 14:32:18 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " societe_commerciaux " ;
2021-08-27 18:18:50 +02:00
$sql .= " WHERE fk_soc = " . (( int ) $this -> id ) . " AND fk_user = " . (( int ) $commid );
2020-10-31 14:32:18 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( ! $resql ) {
2020-10-31 14:32:18 +01:00
dol_syslog ( get_class ( $this ) . " ::add_commercial Error " . $this -> db -> lasterror ());
$error ++ ;
}
}
2020-12-28 21:08:56 +01:00
if ( ! $error ) {
2020-10-31 14:32:18 +01:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " societe_commerciaux " ;
$sql .= " (fk_soc, fk_user) " ;
2021-08-27 18:18:50 +02:00
$sql .= " VALUES ( " . (( int ) $this -> id ) . " , " . (( int ) $commid ) . " ) " ;
2020-10-31 14:32:18 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( ! $resql ) {
2020-10-31 14:32:18 +01:00
dol_syslog ( get_class ( $this ) . " ::add_commercial Error " . $this -> db -> lasterror ());
$error ++ ;
}
}
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( ! $error ) {
2021-08-27 18:18:50 +02:00
$this -> context = array ( 'commercial_modified' => $commid );
2018-08-13 17:26:32 +02:00
2019-11-13 18:32:11 +01:00
$result = $this -> call_trigger ( 'COMPANY_LINK_SALE_REPRESENTATIVE' , $user );
2020-12-28 21:08:56 +01:00
if ( $result < 0 ) {
2020-10-31 14:32:18 +01:00
$error ++ ;
}
2019-03-15 19:34:04 +01:00
}
2019-03-12 10:48:08 +01:00
2020-12-28 21:08:56 +01:00
if ( ! $error ) {
2020-10-31 14:32:18 +01:00
$this -> db -> commit ();
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
$this -> db -> rollback ();
return - 1 ;
2019-03-15 19:34:04 +01:00
}
2017-10-13 13:28:26 +02:00
}
2019-03-15 19:34:04 +01:00
return 0 ;
2017-10-13 13:28:26 +02:00
}
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Add link to sales representative
*
* @ param User $user Object user
* @ param int $commid Id of user
* @ return void
*/
2020-10-31 14:32:18 +01:00
public function del_commercial ( User $user , $commid )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2019-11-13 18:32:11 +01:00
$error = 0 ;
$this -> context = array ( 'commercial_modified' => $commid );
2018-08-13 17:26:32 +02:00
2019-11-13 18:32:11 +01:00
$result = $this -> call_trigger ( 'COMPANY_UNLINK_SALE_REPRESENTATIVE' , $user );
2020-12-28 21:08:56 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2018-08-13 17:26:32 +02:00
2020-12-28 21:08:56 +01:00
if ( $this -> id > 0 && $commid > 0 ) {
2017-10-13 13:28:26 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " societe_commerciaux " ;
2021-08-27 18:18:50 +02:00
$sql .= " WHERE fk_soc = " . (( int ) $this -> id ) . " AND fk_user = " . (( int ) $commid );
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( ! $this -> db -> query ( $sql )) {
2017-10-13 13:28:26 +02:00
dol_syslog ( get_class ( $this ) . " ::del_commercial Erreur " );
}
}
}
/**
* Return a link on thirdparty ( with picto )
*
* @ param int $withpicto Add picto into link ( 0 = No picto , 1 = Include picto with link , 2 = Picto only )
* @ param string $option Target of link ( '' , 'customer' , 'prospect' , 'supplier' , 'project' )
* @ param int $maxlen Max length of name
* @ param int $notooltip 1 = Disable tooltip
* @ param int $save_lastsearch_value - 1 = Auto , 0 = No save of lastsearch_values when clicking , 1 = Save lastsearch_values whenclicking
2022-01-06 10:54:19 +01:00
* @ param int $noaliasinname 1 = Do not add alias into the link ref
2022-02-04 14:44:47 +01:00
* @ param string $target add attribute target
2017-10-13 13:28:26 +02:00
* @ return string String with URL
*/
2022-02-15 09:32:27 +01:00
public function getNomUrl ( $withpicto = 0 , $option = '' , $maxlen = 0 , $notooltip = 0 , $save_lastsearch_value = - 1 , $noaliasinname = 0 , $target = '' )
2017-10-13 13:28:26 +02:00
{
global $conf , $langs , $hookmanager ;
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> dol_no_mouse_hover )) {
$notooltip = 1 ; // Force disable tooltips
}
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$name = $this -> name ? $this -> name : $this -> nom ;
2018-04-21 15:08:46 +02:00
2020-10-31 14:32:18 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD )) {
2020-12-28 21:08:56 +01:00
if ( empty ( $option ) && $this -> client > 0 ) {
$option = 'customer' ;
}
if ( empty ( $option ) && $this -> fournisseur > 0 ) {
$option = 'supplier' ;
}
2020-10-31 14:32:18 +01:00
}
2018-04-13 15:48:58 +02:00
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_ADD_REF_IN_LIST ) && ( ! empty ( $withpicto ))) {
2018-10-12 19:08:06 +02:00
$code = '' ;
2020-11-02 11:41:07 +01:00
if (( $this -> client ) && ( ! empty ( $this -> code_client )) && ( $conf -> global -> SOCIETE_ADD_REF_IN_LIST == 1 || $conf -> global -> SOCIETE_ADD_REF_IN_LIST == 2 )) {
2019-11-13 18:32:11 +01:00
$code = $this -> code_client . ' - ' ;
2018-10-12 19:08:06 +02:00
}
2017-10-13 13:28:26 +02:00
2020-11-02 11:41:07 +01:00
if (( $this -> fournisseur ) && ( ! empty ( $this -> code_fournisseur )) && ( $conf -> global -> SOCIETE_ADD_REF_IN_LIST == 1 || $conf -> global -> SOCIETE_ADD_REF_IN_LIST == 3 )) {
2019-11-13 18:32:11 +01:00
$code .= $this -> code_fournisseur . ' - ' ;
2018-10-12 19:08:06 +02:00
}
2017-10-13 13:28:26 +02:00
2020-10-14 14:02:07 +02:00
if ( $code ) {
if ( $conf -> global -> SOCIETE_ADD_REF_IN_LIST == 1 ) {
$name = $code . ' ' . $name ;
} else {
$name = $code ;
}
2018-10-12 19:08:06 +02:00
}
2017-10-13 13:28:26 +02:00
}
2022-01-06 10:54:19 +01:00
if ( ! empty ( $this -> name_alias ) && empty ( $noaliasinname )) {
2020-12-28 21:08:56 +01:00
$name .= ' (' . $this -> name_alias . ')' ;
}
2017-10-13 13:28:26 +02:00
2022-02-28 19:45:53 +01:00
$result = '' ; $label = '' ; $label2 = '' ;
2019-11-13 18:32:11 +01:00
$linkstart = '' ; $linkend = '' ;
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( ! empty ( $this -> logo ) && class_exists ( 'Form' )) {
2022-01-05 10:43:05 +01:00
$label .= '<div class="photointooltip floatright">' ;
$label .= Form :: showphoto ( 'societe' , $this , 0 , 40 , 0 , 'photoref' , 'mini' , 0 ); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
$label .= '</div>' ;
//$label .= '<div style="clear: both;"></div>';
2020-12-28 21:08:56 +01:00
} elseif ( ! empty ( $this -> logo_squarred ) && class_exists ( 'Form' )) {
2019-10-11 11:27:05 +02:00
/* $label .= '<div class="photointooltip">' ;
2017-10-22 21:15:08 +02:00
$label .= Form :: showphoto ( 'societe' , $this , 0 , 40 , 0 , 'photowithmargin' , 'mini' , 0 ); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
2019-10-11 11:27:05 +02:00
$label .= '</div><div style="clear: both;"></div>' ; */
2017-10-13 13:28:26 +02:00
}
2019-11-13 18:32:11 +01:00
$label .= '<div class="centpercent">' ;
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( $option == 'customer' || $option == 'compta' || $option == 'category' ) {
2020-11-02 11:41:07 +01:00
$label .= img_picto ( '' , $this -> picto ) . ' <u class="paddingrightonly">' . $langs -> trans ( " Customer " ) . '</u>' ;
2020-10-31 14:32:18 +01:00
$linkstart = '<a href="' . DOL_URL_ROOT . '/comm/card.php?socid=' . $this -> id ;
2020-12-28 21:08:56 +01:00
} elseif ( $option == 'prospect' && empty ( $conf -> global -> SOCIETE_DISABLE_PROSPECTS )) {
2020-11-02 11:41:07 +01:00
$label .= img_picto ( '' , $this -> picto ) . ' <u class="paddingrightonly">' . $langs -> trans ( " Prospect " ) . '</u>' ;
2017-10-13 13:28:26 +02:00
$linkstart = '<a href="' . DOL_URL_ROOT . '/comm/card.php?socid=' . $this -> id ;
2020-12-28 21:08:56 +01:00
} elseif ( $option == 'supplier' || $option == 'category_supplier' ) {
2020-11-02 11:41:07 +01:00
$label .= img_picto ( '' , $this -> picto ) . ' <u class="paddingrightonly">' . $langs -> trans ( " Supplier " ) . '</u>' ;
2017-10-13 13:28:26 +02:00
$linkstart = '<a href="' . DOL_URL_ROOT . '/fourn/card.php?socid=' . $this -> id ;
2020-12-28 21:08:56 +01:00
} elseif ( $option == 'agenda' ) {
2020-11-02 11:41:07 +01:00
$label .= img_picto ( '' , $this -> picto ) . ' <u class="paddingrightonly">' . $langs -> trans ( " ThirdParty " ) . '</u>' ;
2017-10-13 13:28:26 +02:00
$linkstart = '<a href="' . DOL_URL_ROOT . '/societe/agenda.php?socid=' . $this -> id ;
2020-12-28 21:08:56 +01:00
} elseif ( $option == 'project' ) {
2020-11-02 11:41:07 +01:00
$label .= img_picto ( '' , $this -> picto ) . ' <u class="paddingrightonly">' . $langs -> trans ( " ThirdParty " ) . '</u>' ;
2017-10-13 13:28:26 +02:00
$linkstart = '<a href="' . DOL_URL_ROOT . '/societe/project.php?socid=' . $this -> id ;
2020-12-28 21:08:56 +01:00
} elseif ( $option == 'margin' ) {
2020-11-02 11:41:07 +01:00
$label .= img_picto ( '' , $this -> picto ) . ' <u class="paddingrightonly">' . $langs -> trans ( " ThirdParty " ) . '</u>' ;
2017-10-13 13:28:26 +02:00
$linkstart = '<a href="' . DOL_URL_ROOT . '/margin/tabs/thirdpartyMargins.php?socid=' . $this -> id . '&type=1' ;
2020-12-28 21:08:56 +01:00
} elseif ( $option == 'contact' ) {
2020-11-02 11:41:07 +01:00
$label .= img_picto ( '' , $this -> picto ) . ' <u class="paddingrightonly">' . $langs -> trans ( " ThirdParty " ) . '</u>' ;
2017-10-13 13:28:26 +02:00
$linkstart = '<a href="' . DOL_URL_ROOT . '/societe/contact.php?socid=' . $this -> id ;
2020-12-28 21:08:56 +01:00
} elseif ( $option == 'ban' ) {
2020-11-02 11:41:07 +01:00
$label .= img_picto ( '' , $this -> picto ) . ' <u class="paddingrightonly">' . $langs -> trans ( " ThirdParty " ) . '</u>' ;
2018-03-08 22:26:42 +01:00
$linkstart = '<a href="' . DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $this -> id ;
2017-10-13 13:28:26 +02:00
}
// By default
2020-12-28 21:08:56 +01:00
if ( empty ( $linkstart )) {
2020-11-02 11:41:07 +01:00
$label .= img_picto ( '' , $this -> picto ) . ' <u class="paddingrightonly">' . $langs -> trans ( " ThirdParty " ) . '</u>' ;
2017-10-13 13:28:26 +02:00
$linkstart = '<a href="' . DOL_URL_ROOT . '/societe/card.php?socid=' . $this -> id ;
}
2020-11-02 11:41:07 +01:00
if ( isset ( $this -> status )) {
$label .= ' ' . $this -> getLibStatut ( 5 );
}
2017-10-13 13:28:26 +02:00
2021-09-29 16:42:52 +02:00
$label .= '<br><b>' . $langs -> trans ( 'Name' ) . ':</b> ' . dol_escape_htmltag ( $this -> name );
if ( ! empty ( $this -> name_alias )) {
$label .= ' (' . dol_escape_htmltag ( $this -> name_alias ) . ')' ;
}
if ( $this -> email ) {
$label .= '<br>' . img_picto ( '' , 'email' , 'class="pictofixedwidth"' ) . $this -> email ;
2019-08-07 13:49:14 +02:00
}
2021-05-17 10:14:14 +02:00
if ( ! empty ( $this -> phone ) || ! empty ( $this -> fax )) {
$phonelist = array ();
if ( $this -> phone ) {
$phonelist [] = dol_print_phone ( $this -> phone , $this -> country_code , $this -> id , 0 , '' , ' ' , 'phone' );
}
if ( $this -> fax ) {
$phonelist [] = dol_print_phone ( $this -> fax , $this -> country_code , $this -> id , 0 , '' , ' ' , 'fax' );
}
2021-09-20 13:01:53 +02:00
$label .= '<br>' . implode ( ' ' , $phonelist );
2021-05-15 02:29:15 +02:00
}
2022-02-28 19:45:53 +01:00
2021-05-15 02:29:15 +02:00
if ( ! empty ( $this -> address )) {
2022-02-28 19:45:53 +01:00
$label2 .= '<br><b>' . $langs -> trans ( " Address " ) . ':</b> ' . dol_format_address ( $this , 1 , ' ' , $langs ); // Address + country
2021-05-17 10:16:33 +02:00
} elseif ( ! empty ( $this -> country_code )) {
2022-02-28 19:45:53 +01:00
$label2 .= '<br><b>' . $langs -> trans ( 'Country' ) . ':</b> ' . $this -> country_code ;
2020-12-28 21:08:56 +01:00
}
if ( ! empty ( $this -> tva_intra ) || ( ! empty ( $conf -> global -> SOCIETE_SHOW_FIELD_IN_TOOLTIP ) && strpos ( $conf -> global -> SOCIETE_SHOW_FIELD_IN_TOOLTIP , 'vatnumber' ) !== false )) {
2022-02-28 19:45:53 +01:00
$label2 .= '<br><b>' . $langs -> trans ( 'VATIntra' ) . ':</b> ' . dol_escape_htmltag ( $this -> tva_intra );
2020-12-28 21:08:56 +01:00
}
2022-11-17 02:23:13 +01:00
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_SHOW_FIELD_IN_TOOLTIP )) {
2022-11-17 02:23:13 +01:00
if ( strpos ( $conf -> global -> SOCIETE_SHOW_FIELD_IN_TOOLTIP , 'profid1' ) !== false && $langs -> trans ( 'ProfId1' . $this -> country_code ) != '-' ) {
2022-02-28 19:45:53 +01:00
$label2 .= '<br><b>' . $langs -> trans ( 'ProfId1' . $this -> country_code ) . ':</b> ' . $this -> idprof1 ;
2020-12-28 21:08:56 +01:00
}
2022-11-17 02:23:13 +01:00
if ( strpos ( $conf -> global -> SOCIETE_SHOW_FIELD_IN_TOOLTIP , 'profid2' ) !== false && $langs -> trans ( 'ProfId2' . $this -> country_code ) != '-' ) {
2022-02-28 19:45:53 +01:00
$label2 .= '<br><b>' . $langs -> trans ( 'ProfId2' . $this -> country_code ) . ':</b> ' . $this -> idprof2 ;
2020-12-28 21:08:56 +01:00
}
2022-11-17 02:23:13 +01:00
if ( strpos ( $conf -> global -> SOCIETE_SHOW_FIELD_IN_TOOLTIP , 'profid3' ) !== false && $langs -> trans ( 'ProfId3' . $this -> country_code ) != '-' ) {
2022-02-28 19:45:53 +01:00
$label2 .= '<br><b>' . $langs -> trans ( 'ProfId3' . $this -> country_code ) . ':</b> ' . $this -> idprof3 ;
2020-12-28 21:08:56 +01:00
}
2022-11-17 02:23:13 +01:00
if ( strpos ( $conf -> global -> SOCIETE_SHOW_FIELD_IN_TOOLTIP , 'profid4' ) !== false && $langs -> trans ( 'ProfId4' . $this -> country_code ) != '-' ) {
2022-02-28 19:45:53 +01:00
$label2 .= '<br><b>' . $langs -> trans ( 'ProfId4' . $this -> country_code ) . ':</b> ' . $this -> idprof4 ;
2020-12-28 21:08:56 +01:00
}
2022-11-17 02:23:13 +01:00
if ( strpos ( $conf -> global -> SOCIETE_SHOW_FIELD_IN_TOOLTIP , 'profid5' ) !== false && $langs -> trans ( 'ProfId5' . $this -> country_code ) != '-' ) {
2022-02-28 19:45:53 +01:00
$label2 .= '<br><b>' . $langs -> trans ( 'ProfId5' . $this -> country_code ) . ':</b> ' . $this -> idprof5 ;
2020-12-28 21:08:56 +01:00
}
2022-11-17 02:23:13 +01:00
if ( strpos ( $conf -> global -> SOCIETE_SHOW_FIELD_IN_TOOLTIP , 'profid6' ) !== false && $langs -> trans ( 'ProfId6' . $this -> country_code ) != '-' ) {
2022-02-28 19:45:53 +01:00
$label2 .= '<br><b>' . $langs -> trans ( 'ProfId6' . $this -> country_code ) . ':</b> ' . $this -> idprof6 ;
2020-12-28 21:08:56 +01:00
}
}
if ( ! empty ( $this -> code_client ) && ( $this -> client == 1 || $this -> client == 3 )) {
2022-02-28 19:45:53 +01:00
$label2 .= '<br><b>' . $langs -> trans ( 'CustomerCode' ) . ':</b> ' . $this -> code_client ;
2020-12-28 21:08:56 +01:00
}
if ( ! empty ( $this -> code_fournisseur ) && $this -> fournisseur ) {
2022-02-28 19:45:53 +01:00
$label2 .= '<br><b>' . $langs -> trans ( 'SupplierCode' ) . ':</b> ' . $this -> code_fournisseur ;
2020-12-28 21:08:56 +01:00
}
if ( ! empty ( $conf -> accounting -> enabled ) && ( $this -> client == 1 || $this -> client == 3 )) {
2022-02-28 19:45:53 +01:00
$label2 .= '<br><b>' . $langs -> trans ( 'CustomerAccountancyCode' ) . ':</b> ' . ( $this -> code_compta ? $this -> code_compta : $this -> code_compta_client );
2020-12-28 21:08:56 +01:00
}
if ( ! empty ( $conf -> accounting -> enabled ) && $this -> fournisseur ) {
2022-02-28 19:45:53 +01:00
$label2 .= '<br><b>' . $langs -> trans ( 'SupplierAccountancyCode' ) . ':</b> ' . $this -> code_compta_fournisseur ;
2020-12-28 21:08:56 +01:00
}
2022-02-28 19:45:53 +01:00
$label .= ( $label2 ? '<br>' . $label2 : '' ) . '</div>' ;
2017-10-13 13:28:26 +02:00
// Add type of canvas
2019-11-13 18:32:11 +01:00
$linkstart .= ( ! empty ( $this -> canvas ) ? '&canvas=' . $this -> canvas : '' );
2017-10-13 13:28:26 +02:00
// Add param to save lastsearch_values or not
2019-11-13 18:32:11 +01:00
$add_save_lastsearch_values = ( $save_lastsearch_value == 1 ? 1 : 0 );
2020-12-28 21:08:56 +01:00
if ( $save_lastsearch_value == - 1 && preg_match ( '/list\.php/' , $_SERVER [ " PHP_SELF " ])) {
$add_save_lastsearch_values = 1 ;
}
if ( $add_save_lastsearch_values ) {
$linkstart .= '&save_lastsearch_values=1' ;
}
2019-11-13 18:32:11 +01:00
$linkstart .= '"' ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$linkclose = '' ;
2020-12-28 21:08:56 +01:00
if ( empty ( $notooltip )) {
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
2019-11-13 18:32:11 +01:00
$label = $langs -> trans ( " ShowCompany " );
$linkclose .= ' alt="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
2017-10-13 13:28:26 +02:00
}
2019-11-13 18:32:11 +01:00
$linkclose .= ' title="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
$linkclose .= ' class="classfortooltip refurl"' ;
2022-03-07 17:11:32 +01:00
$target_value = array ( '_self' , '_blank' , '_parent' , '_top' );
2022-02-04 14:48:25 +01:00
if ( in_array ( $target , $target_value )) {
2022-03-07 17:11:32 +01:00
$linkclose .= ' target="' . dol_escape_htmltag ( $target ) . '"' ;
2022-02-04 14:44:47 +01:00
}
2017-10-13 13:28:26 +02:00
}
2019-11-13 18:32:11 +01:00
$linkstart .= $linkclose . '>' ;
$linkend = '</a>' ;
2017-10-13 13:28:26 +02:00
global $user ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && $user -> socid > 0 && $this -> id != $user -> socid ) {
2019-11-13 18:32:11 +01:00
$linkstart = '' ;
$linkend = '' ;
2017-10-13 13:28:26 +02:00
}
2019-11-13 18:32:11 +01:00
$result .= $linkstart ;
2020-12-28 21:08:56 +01:00
if ( $withpicto ) {
$result .= img_object (( $notooltip ? '' : $label ), ( $this -> picto ? $this -> picto : 'generic' ), ( $notooltip ? (( $withpicto != 2 ) ? 'class="paddingright"' : '' ) : 'class="' . (( $withpicto != 2 ) ? 'paddingright ' : '' ) . 'classfortooltip"' ), 0 , 0 , $notooltip ? 0 : 1 );
}
if ( $withpicto != 2 ) {
$result .= dol_escape_htmltag ( $maxlen ? dol_trunc ( $name , $maxlen ) : $name );
}
2019-11-13 18:32:11 +01:00
$result .= $linkend ;
2017-10-13 13:28:26 +02:00
2018-03-15 20:46:55 +01:00
global $action ;
2018-03-15 22:22:42 +01:00
$hookmanager -> initHooks ( array ( 'thirdpartydao' ));
2020-09-03 10:45:03 +02:00
$parameters = array (
'id' => $this -> id ,
2021-11-22 19:57:26 +01:00
'getnomurl' => & $result ,
2020-09-03 10:45:03 +02:00
'withpicto ' => $withpicto ,
'option' => $option ,
'maxlen' => $maxlen ,
'notooltip' => $notooltip ,
'save_lastsearch_value' => $save_lastsearch_value
);
2019-11-13 18:32:11 +01:00
$reshook = $hookmanager -> executeHooks ( 'getNomUrl' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
2020-12-28 21:08:56 +01:00
if ( $reshook > 0 ) {
$result = $hookmanager -> resPrint ;
} else {
$result .= $hookmanager -> resPrint ;
}
2018-03-15 20:46:55 +01:00
2017-10-13 13:28:26 +02:00
return $result ;
}
2021-02-05 17:29:11 +01:00
/**
* Return link ( s ) on type of thirdparty ( with picto )
*
2022-06-29 21:55:31 +02:00
* @ param int $withpicto Add picto into link ( 0 = No picto , 1 = Include picto with link , 2 = Picto only )
* @ param string $option '' = All
* @ param int $notooltip 1 = Disable tooltip
* @ param string $tag Tag 'a' or 'span'
* @ return string String with URL
2021-02-05 17:29:11 +01:00
*/
2022-06-29 21:55:31 +02:00
public function getTypeUrl ( $withpicto = 0 , $option = '' , $notooltip = 0 , $tag = 'a' )
2021-02-05 17:29:11 +01:00
{
global $conf , $langs ;
$s = '' ;
if ( empty ( $option ) || preg_match ( '/prospect/' , $option )) {
2021-02-26 21:17:52 +01:00
if (( $this -> client == 2 || $this -> client == 3 ) && empty ( $conf -> global -> SOCIETE_DISABLE_PROSPECTS )) {
2022-06-29 21:55:31 +02:00
$s .= '<' . $tag . ' class="customer-back opacitymedium" title="' . $langs -> trans ( " Prospect " ) . '" href="' . DOL_URL_ROOT . '/comm/card.php?socid=' . $this -> id . '">' . dol_substr ( $langs -> trans ( " Prospect " ), 0 , 1 ) . '</' . $tag . '>' ;
2021-02-05 17:29:11 +01:00
}
}
if ( empty ( $option ) || preg_match ( '/customer/' , $option )) {
2021-02-26 21:17:52 +01:00
if (( $this -> client == 1 || $this -> client == 3 ) && empty ( $conf -> global -> SOCIETE_DISABLE_CUSTOMERS )) {
2022-06-29 21:55:31 +02:00
$s .= '<' . $tag . ' class="customer-back" title="' . $langs -> trans ( " Customer " ) . '" href="' . DOL_URL_ROOT . '/comm/card.php?socid=' . $this -> id . '">' . dol_substr ( $langs -> trans ( " Customer " ), 0 , 1 ) . '</' . $tag . '>' ;
2021-02-05 17:29:11 +01:00
}
}
if ( empty ( $option ) || preg_match ( '/supplier/' , $option )) {
2021-04-12 06:04:08 +02:00
if ((( ! empty ( $conf -> fournisseur -> enabled ) && empty ( $conf -> global -> MAIN_USE_NEW_SUPPLIERMOD )) || ! empty ( $conf -> supplier_order -> enabled ) || ! empty ( $conf -> supplier_invoice -> enabled )) && $this -> fournisseur ) {
2022-06-29 21:55:31 +02:00
$s .= '<' . $tag . ' class="vendor-back" title="' . $langs -> trans ( " Supplier " ) . '" href="' . DOL_URL_ROOT . '/fourn/card.php?socid=' . $this -> id . '">' . dol_substr ( $langs -> trans ( " Supplier " ), 0 , 1 ) . '</' . $tag . '>' ;
2021-02-05 17:29:11 +01:00
}
}
return $s ;
}
2017-10-13 13:28:26 +02:00
/**
* Return label of status ( activity , closed )
*
2019-10-31 23:29:17 +01:00
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto , 6 = Long label + Picto
* @ return string Label of status
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function getLibStatut ( $mode = 0 )
2017-10-13 13:28:26 +02:00
{
2019-01-27 11:55:16 +01:00
return $this -> LibStatut ( $this -> status , $mode );
2017-10-13 13:28:26 +02:00
}
2019-10-21 02:18:39 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
2019-10-21 02:18:39 +02:00
* Return the label of a given status
2017-10-13 13:28:26 +02:00
*
2019-10-24 16:38:06 +02:00
* @ param int $status Status id
2017-11-18 01:48:16 +01:00
* @ param int $mode 0 = Long label , 1 = Short label , 2 = Picto + Short label , 3 = Picto , 4 = Picto + Long label , 5 = Short label + Picto , 6 = Long label + Picto
2019-10-21 02:18:39 +02:00
* @ return string Status label
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function LibStatut ( $status , $mode = 0 )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $langs ;
$langs -> load ( 'companies' );
2019-10-24 16:38:06 +02:00
$statusType = 'status4' ;
2020-12-28 21:08:56 +01:00
if ( $status == 0 ) {
$statusType = 'status6' ;
}
2019-10-24 16:38:06 +02:00
2020-12-28 21:08:56 +01:00
if ( empty ( $this -> labelStatus ) || empty ( $this -> labelStatusShort )) {
2021-10-16 19:37:57 +02:00
$this -> labelStatus [ 0 ] = $langs -> transnoentitiesnoconv ( " ActivityCeased " );
$this -> labelStatus [ 1 ] = $langs -> transnoentitiesnoconv ( " InActivity " );
$this -> labelStatusShort [ 0 ] = $langs -> transnoentitiesnoconv ( " ActivityCeased " );
$this -> labelStatusShort [ 1 ] = $langs -> transnoentitiesnoconv ( " InActivity " );
2017-10-13 13:28:26 +02:00
}
2019-10-24 16:38:06 +02:00
2019-11-01 12:52:03 +01:00
return dolGetStatus ( $this -> labelStatus [ $status ], $this -> labelStatusShort [ $status ], '' , $statusType , $mode );
2020-10-31 14:32:18 +01:00
}
2017-10-13 13:28:26 +02:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Return list of contacts emails existing for third party
*
* @ param int $addthirdparty 1 = Add also a record for thirdparty email
* @ return array Array of contacts emails
*/
2020-10-31 14:32:18 +01:00
public function thirdparty_and_contact_email_array ( $addthirdparty = 0 )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $langs ;
2019-01-27 11:55:16 +01:00
$contact_emails = $this -> contact_property_array ( 'email' , 1 );
2020-12-28 21:08:56 +01:00
if ( $this -> email && $addthirdparty ) {
if ( empty ( $this -> name )) {
$this -> name = $this -> nom ;
}
2019-11-13 18:32:11 +01:00
$contact_emails [ 'thirdparty' ] = $langs -> transnoentitiesnoconv ( " ThirdParty " ) . ': ' . dol_trunc ( $this -> name , 16 ) . " < " . $this -> email . " > " ;
2017-10-13 13:28:26 +02:00
}
//var_dump($contact_emails)
return $contact_emails ;
}
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Return list of contacts mobile phone existing for third party
*
* @ return array Array of contacts emails
*/
2020-10-31 14:32:18 +01:00
public function thirdparty_and_contact_phone_array ()
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $langs ;
$contact_phone = $this -> contact_property_array ( 'mobile' );
2020-12-28 21:08:56 +01:00
if ( ! empty ( $this -> phone )) { // If a phone of thirdparty is defined, we add it ot mobile of contacts
if ( empty ( $this -> name )) {
$this -> name = $this -> nom ;
}
2017-10-13 13:28:26 +02:00
// TODO: Tester si tel non deja present dans tableau contact
2019-11-13 18:32:11 +01:00
$contact_phone [ 'thirdparty' ] = $langs -> transnoentitiesnoconv ( " ThirdParty " ) . ': ' . dol_trunc ( $this -> name , 16 ) . " < " . $this -> phone . " > " ;
2017-10-13 13:28:26 +02:00
}
return $contact_phone ;
}
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Return list of contacts emails or mobile existing for third party
*
* @ param string $mode 'email' or 'mobile'
* @ param int $hidedisabled 1 = Hide contact if disabled
2017-11-03 16:29:23 +01:00
* @ return array Array of contacts emails or mobile . Example : array ( id => 'Name <email>' )
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function contact_property_array ( $mode = 'email' , $hidedisabled = 0 )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $langs ;
$contact_property = array ();
2020-02-08 11:32:38 +01:00
$sql = " SELECT rowid, email, statut as status, phone_mobile, lastname, poste, firstname " ;
2019-11-13 18:32:11 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " socpeople " ;
2021-08-27 18:18:50 +02:00
$sql .= " WHERE fk_soc = " . (( int ) $this -> id );
2019-11-13 18:32:11 +01:00
$sql .= " ORDER BY lastname, firstname " ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2017-10-13 13:28:26 +02:00
$nump = $this -> db -> num_rows ( $resql );
2020-12-28 21:08:56 +01:00
if ( $nump ) {
2019-11-13 18:32:11 +01:00
$sepa = " ( " ; $sepb = " ) " ;
2020-12-28 21:08:56 +01:00
if ( $mode == 'email' ) {
2017-11-03 16:29:23 +01:00
//$sepa="<"; $sepb=">";
2019-11-13 18:32:11 +01:00
$sepa = " < " ; $sepb = " > " ;
2017-10-13 13:28:26 +02:00
}
$i = 0 ;
2020-12-28 21:08:56 +01:00
while ( $i < $nump ) {
2017-10-13 13:28:26 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2020-12-28 21:08:56 +01:00
if ( $mode == 'email' ) {
$property = $obj -> email ;
} elseif ( $mode == 'mobile' ) {
$property = $obj -> phone_mobile ;
} else {
$property = $obj -> $mode ;
}
2017-10-13 13:28:26 +02:00
// Show all contact. If hidedisabled is 1, showonly contacts with status = 1
2020-12-28 21:08:56 +01:00
if ( $obj -> status == 1 || empty ( $hidedisabled )) {
if ( empty ( $property )) {
if ( $mode == 'email' ) {
$property = $langs -> transnoentitiesnoconv ( " NoEMail " );
} elseif ( $mode == 'mobile' ) {
$property = $langs -> transnoentitiesnoconv ( " NoMobilePhone " );
}
2017-10-13 13:28:26 +02:00
}
2020-12-28 21:08:56 +01:00
if ( ! empty ( $obj -> poste )) {
2019-11-13 18:32:11 +01:00
$contact_property [ $obj -> rowid ] = trim ( dolGetFirstLastname ( $obj -> firstname , $obj -> lastname )) . ( $obj -> poste ? " - " . $obj -> poste : " " ) . (( $mode != 'poste' && $property ) ? " " . $sepa . $property . $sepb : '' );
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 18:32:11 +01:00
$contact_property [ $obj -> rowid ] = trim ( dolGetFirstLastname ( $obj -> firstname , $obj -> lastname )) . (( $mode != 'poste' && $property ) ? " " . $sepa . $property . $sepb : '' );
2017-10-13 13:28:26 +02:00
}
}
$i ++ ;
}
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
dol_print_error ( $this -> db );
}
return $contact_property ;
}
2019-10-21 02:18:39 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
2019-10-21 02:18:39 +02:00
* Returns the contact list of this company
2017-10-13 13:28:26 +02:00
*
2019-10-21 02:18:39 +02:00
* @ return array array of contacts
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function contact_array ()
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
$contacts = array ();
2021-08-27 18:18:50 +02:00
$sql = " SELECT rowid, lastname, firstname FROM " . MAIN_DB_PREFIX . " socpeople WHERE fk_soc = " . (( int ) $this -> id );
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2017-10-13 13:28:26 +02:00
$nump = $this -> db -> num_rows ( $resql );
2020-12-28 21:08:56 +01:00
if ( $nump ) {
2017-10-13 13:28:26 +02:00
$i = 0 ;
2020-12-28 21:08:56 +01:00
while ( $i < $nump ) {
2017-10-13 13:28:26 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2019-01-27 11:55:16 +01:00
$contacts [ $obj -> rowid ] = dolGetFirstLastname ( $obj -> firstname , $obj -> lastname );
2017-10-13 13:28:26 +02:00
$i ++ ;
}
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
dol_print_error ( $this -> db );
}
return $contacts ;
}
2019-10-21 02:18:39 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
2019-10-21 02:18:39 +02:00
* Returns the contact list of this company
2017-10-13 13:28:26 +02:00
*
2019-10-21 02:18:39 +02:00
* @ return array $contacts array of contacts
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function contact_array_objects ()
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2019-11-13 18:32:11 +01:00
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
2017-10-13 13:28:26 +02:00
$contacts = array ();
2021-08-27 18:18:50 +02:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " socpeople WHERE fk_soc = " . (( int ) $this -> id );
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2017-10-13 13:28:26 +02:00
$nump = $this -> db -> num_rows ( $resql );
2020-12-28 21:08:56 +01:00
if ( $nump ) {
2017-10-13 13:28:26 +02:00
$i = 0 ;
2020-12-28 21:08:56 +01:00
while ( $i < $nump ) {
2017-10-13 13:28:26 +02:00
$obj = $this -> db -> fetch_object ( $resql );
$contact = new Contact ( $this -> db );
$contact -> fetch ( $obj -> rowid );
$contacts [] = $contact ;
$i ++ ;
}
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
dol_print_error ( $this -> db );
}
return $contacts ;
}
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Return property of contact from its id
*
* @ param int $rowid id of contact
* @ param string $mode 'email' or 'mobile'
* @ return string Email of contact with format : " Full name <email> "
*/
2020-10-31 14:32:18 +01:00
public function contact_get_property ( $rowid , $mode )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2019-11-13 18:32:11 +01:00
$contact_property = '' ;
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( empty ( $rowid )) {
return '' ;
}
2017-10-13 13:28:26 +02:00
$sql = " SELECT rowid, email, phone_mobile, lastname, firstname " ;
2019-11-13 18:32:11 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " socpeople " ;
2020-09-20 03:32:43 +02:00
$sql .= " WHERE rowid = " . (( int ) $rowid );
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2017-10-13 13:28:26 +02:00
$nump = $this -> db -> num_rows ( $resql );
2020-12-28 21:08:56 +01:00
if ( $nump ) {
2017-10-13 13:28:26 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2020-12-28 21:08:56 +01:00
if ( $mode == 'email' ) {
$contact_property = dol_string_nospecial ( dolGetFirstLastname ( $obj -> firstname , $obj -> lastname ), ' ' , array ( " , " )) . " < " . $obj -> email . " > " ;
} elseif ( $mode == 'mobile' ) {
$contact_property = $obj -> phone_mobile ;
}
2017-10-13 13:28:26 +02:00
}
return $contact_property ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
dol_print_error ( $this -> db );
}
}
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Return bank number property of thirdparty ( label or rum )
*
* @ param string $mode 'label' or 'rum' or 'format'
2020-08-03 14:11:15 +02:00
* @ return string Bank label or RUM or '' if no bank account found
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function display_rib ( $mode = 'label' )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2019-11-13 18:32:11 +01:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php' ;
2017-10-13 13:28:26 +02:00
$bac = new CompanyBankAccount ( $this -> db );
2019-01-27 11:55:16 +01:00
$bac -> fetch ( 0 , $this -> id );
2017-10-13 13:28:26 +02:00
2020-08-03 14:11:15 +02:00
if ( $bac -> id > 0 ) { // If a bank account has been found for company $this->id
2020-08-03 14:44:01 +02:00
if ( $mode == 'label' ) {
2020-08-03 14:11:15 +02:00
return $bac -> getRibLabel ( true );
2020-08-03 14:44:01 +02:00
} elseif ( $mode == 'rum' ) {
if ( empty ( $bac -> rum )) {
2020-08-03 14:11:15 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php' ;
$prelevement = new BonPrelevement ( $this -> db );
$bac -> fetch_thirdparty ();
$bac -> rum = $prelevement -> buildRumNumber ( $bac -> thirdparty -> code_client , $bac -> datec , $bac -> id );
}
return $bac -> rum ;
2020-08-03 14:44:01 +02:00
} elseif ( $mode == 'format' ) {
2020-08-03 14:11:15 +02:00
return $bac -> frstrecur ;
} else {
return 'BadParameterToFunctionDisplayRib' ;
2017-10-13 13:28:26 +02:00
}
2020-08-03 14:11:15 +02:00
} else {
return '' ;
2017-10-13 13:28:26 +02:00
}
}
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Return Array of RIB
*
* @ return array | int 0 if KO , Array of CompanyBanckAccount if OK
*/
2020-10-31 14:32:18 +01:00
public function get_all_rib ()
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2019-11-13 18:32:11 +01:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php' ;
2021-08-23 17:41:11 +02:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " societe_rib WHERE type='ban' AND fk_soc = " . (( int ) $this -> id );
2017-10-13 13:28:26 +02:00
$result = $this -> db -> query ( $sql );
if ( ! $result ) {
$this -> error ++ ;
$this -> errors [] = $this -> db -> lasterror ;
return 0 ;
} else {
$num_rows = $this -> db -> num_rows ( $result );
$rib_array = array ();
if ( $num_rows ) {
while ( $obj = $this -> db -> fetch_object ( $result )) {
$rib = new CompanyBankAccount ( $this -> db );
$rib -> fetch ( $obj -> rowid );
$rib_array [] = $rib ;
}
}
return $rib_array ;
}
}
2019-10-21 02:18:39 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
2019-10-21 02:18:39 +02:00
* Assigns a customer code from the code control module .
2017-10-13 13:28:26 +02:00
* Return value is stored into this -> code_client
*
* @ param Societe $objsoc Object thirdparty
* @ param int $type Should be 0 to say customer
* @ return void
*/
2020-10-31 14:32:18 +01:00
public function get_codeclient ( $objsoc = 0 , $type = 0 )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $conf ;
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_CODECLIENT_ADDON )) {
2019-11-13 18:32:11 +01:00
$module = $conf -> global -> SOCIETE_CODECLIENT_ADDON ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$dirsociete = array_merge ( array ( '/core/modules/societe/' ), $conf -> modules_parts [ 'societe' ]);
2020-12-28 21:08:56 +01:00
foreach ( $dirsociete as $dirroot ) {
2019-11-13 18:32:11 +01:00
$res = dol_include_once ( $dirroot . $module . '.php' );
2020-12-28 21:08:56 +01:00
if ( $res ) {
break ;
}
2017-10-13 13:28:26 +02:00
}
$mod = new $module ();
2019-01-27 11:55:16 +01:00
$this -> code_client = $mod -> getNextValue ( $objsoc , $type );
2017-10-13 13:28:26 +02:00
$this -> prefixCustomerIsRequired = $mod -> prefixIsRequired ;
dol_syslog ( get_class ( $this ) . " ::get_codeclient code_client= " . $this -> code_client . " module= " . $module );
}
}
2019-10-21 02:18:39 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
2019-10-21 02:18:39 +02:00
* Assigns a vendor code from the code control module .
2017-10-13 13:28:26 +02:00
* Return value is stored into this -> code_fournisseur
*
* @ param Societe $objsoc Object thirdparty
* @ param int $type Should be 1 to say supplier
* @ return void
*/
2020-10-31 14:32:18 +01:00
public function get_codefournisseur ( $objsoc = 0 , $type = 1 )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $conf ;
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_CODECLIENT_ADDON )) {
2019-11-13 18:32:11 +01:00
$module = $conf -> global -> SOCIETE_CODECLIENT_ADDON ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$dirsociete = array_merge ( array ( '/core/modules/societe/' ), $conf -> modules_parts [ 'societe' ]);
2020-12-28 21:08:56 +01:00
foreach ( $dirsociete as $dirroot ) {
2019-11-13 18:32:11 +01:00
$res = dol_include_once ( $dirroot . $module . '.php' );
2020-12-28 21:08:56 +01:00
if ( $res ) {
break ;
}
2017-10-13 13:28:26 +02:00
}
$mod = new $module ();
2019-01-27 11:55:16 +01:00
$this -> code_fournisseur = $mod -> getNextValue ( $objsoc , $type );
2017-10-13 13:28:26 +02:00
dol_syslog ( get_class ( $this ) . " ::get_codefournisseur code_fournisseur= " . $this -> code_fournisseur . " module= " . $module );
}
}
2019-10-21 02:18:39 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
2019-10-21 02:18:39 +02:00
* Check if a client code is editable based on the parameters of the
* code control module .
2017-10-13 13:28:26 +02:00
*
* @ return int 0 = No , 1 = Yes
*/
2020-10-31 14:32:18 +01:00
public function codeclient_modifiable ()
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $conf ;
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_CODECLIENT_ADDON )) {
2019-11-13 18:32:11 +01:00
$module = $conf -> global -> SOCIETE_CODECLIENT_ADDON ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$dirsociete = array_merge ( array ( '/core/modules/societe/' ), $conf -> modules_parts [ 'societe' ]);
2020-12-28 21:08:56 +01:00
foreach ( $dirsociete as $dirroot ) {
2019-11-13 18:32:11 +01:00
$res = dol_include_once ( $dirroot . $module . '.php' );
2020-12-28 21:08:56 +01:00
if ( $res ) {
break ;
}
2017-10-13 13:28:26 +02:00
}
$mod = new $module ();
dol_syslog ( get_class ( $this ) . " ::codeclient_modifiable code_client= " . $this -> code_client . " module= " . $module );
2020-12-28 21:08:56 +01:00
if ( $mod -> code_modifiable_null && ! $this -> code_client ) {
return 1 ;
}
if ( $mod -> code_modifiable_invalide && $this -> check_codeclient () < 0 ) {
return 1 ;
}
if ( $mod -> code_modifiable ) {
return 1 ; // A mettre en dernier
}
2017-10-13 13:28:26 +02:00
return 0 ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
return 0 ;
}
}
2019-10-21 02:18:39 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
2019-10-21 02:18:39 +02:00
* Check if a vendor code is editable in the code control module configuration
2017-10-13 13:28:26 +02:00
*
* @ return int 0 = No , 1 = Yes
*/
2020-10-31 14:32:18 +01:00
public function codefournisseur_modifiable ()
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $conf ;
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_CODECLIENT_ADDON )) {
2019-11-13 18:32:11 +01:00
$module = $conf -> global -> SOCIETE_CODECLIENT_ADDON ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$dirsociete = array_merge ( array ( '/core/modules/societe/' ), $conf -> modules_parts [ 'societe' ]);
2020-12-28 21:08:56 +01:00
foreach ( $dirsociete as $dirroot ) {
2019-11-13 18:32:11 +01:00
$res = dol_include_once ( $dirroot . $module . '.php' );
2020-12-28 21:08:56 +01:00
if ( $res ) {
break ;
}
2017-10-13 13:28:26 +02:00
}
$mod = new $module ();
dol_syslog ( get_class ( $this ) . " ::codefournisseur_modifiable code_founisseur= " . $this -> code_fournisseur . " module= " . $module );
2020-12-28 21:08:56 +01:00
if ( $mod -> code_modifiable_null && ! $this -> code_fournisseur ) {
return 1 ;
}
if ( $mod -> code_modifiable_invalide && $this -> check_codefournisseur () < 0 ) {
return 1 ;
}
if ( $mod -> code_modifiable ) {
return 1 ; // A mettre en dernier
}
2017-10-13 13:28:26 +02:00
return 0 ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
return 0 ;
}
}
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Check customer code
*
* @ return int 0 if OK
* - 1 ErrorBadCustomerCodeSyntax
* - 2 ErrorCustomerCodeRequired
* - 3 ErrorCustomerCodeAlreadyUsed
* - 4 ErrorPrefixRequired
2020-12-20 13:54:02 +01:00
* - 5 NotConfigured - Setup empty so any value may be ok or not
* - 6 Other ( see this -> error )
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function check_codeclient ()
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $conf ;
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_CODECLIENT_ADDON )) {
2019-11-13 18:32:11 +01:00
$module = $conf -> global -> SOCIETE_CODECLIENT_ADDON ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$dirsociete = array_merge ( array ( '/core/modules/societe/' ), $conf -> modules_parts [ 'societe' ]);
2020-12-28 21:08:56 +01:00
foreach ( $dirsociete as $dirroot ) {
2019-11-13 18:32:11 +01:00
$res = dol_include_once ( $dirroot . $module . '.php' );
2020-12-28 21:08:56 +01:00
if ( $res ) {
break ;
}
2017-10-13 13:28:26 +02:00
}
$mod = new $module ();
2020-12-28 21:08:56 +01:00
dol_syslog ( get_class ( $this ) . " ::check_codeclient code_client= " . $this -> code_client . " module= " . $module );
$result = $mod -> verif ( $this -> db , $this -> code_client , $this , 0 );
if ( $result ) { // If error
$this -> error = $mod -> error ;
$this -> errors = $mod -> errors ;
}
2017-10-13 13:28:26 +02:00
return $result ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
return 0 ;
}
}
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Check supplier code
*
* @ return int 0 if OK
* - 1 ErrorBadCustomerCodeSyntax
* - 2 ErrorCustomerCodeRequired
* - 3 ErrorCustomerCodeAlreadyUsed
* - 4 ErrorPrefixRequired
2020-12-29 04:30:37 +01:00
* - 5 NotConfigured - Setup empty so any value may be ok or not
* - 6 Other ( see this -> error )
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function check_codefournisseur ()
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $conf ;
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_CODECLIENT_ADDON )) {
2019-11-13 18:32:11 +01:00
$module = $conf -> global -> SOCIETE_CODECLIENT_ADDON ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$dirsociete = array_merge ( array ( '/core/modules/societe/' ), $conf -> modules_parts [ 'societe' ]);
2020-12-28 21:08:56 +01:00
foreach ( $dirsociete as $dirroot ) {
2019-11-13 18:32:11 +01:00
$res = dol_include_once ( $dirroot . $module . '.php' );
2020-12-28 21:08:56 +01:00
if ( $res ) {
break ;
}
2017-10-13 13:28:26 +02:00
}
$mod = new $module ();
dol_syslog ( get_class ( $this ) . " ::check_codefournisseur code_fournisseur= " . $this -> code_fournisseur . " module= " . $module );
$result = $mod -> verif ( $this -> db , $this -> code_fournisseur , $this , 1 );
2020-09-25 17:11:54 +02:00
if ( $result ) { // If error
$this -> error = $mod -> error ;
$this -> errors = $mod -> errors ;
}
2017-10-13 13:28:26 +02:00
return $result ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
return 0 ;
}
}
2019-10-21 02:18:39 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
2020-06-17 15:42:55 +02:00
* Assigns a accounting code from the accounting code module .
* Computed value is stored into this -> code_compta or this -> code_compta_fournisseur according to $type .
* May be identical to the one entered or generated automatically . Currently , only the automatic generation is implemented .
2017-10-13 13:28:26 +02:00
*
* @ param string $type Type of thirdparty ( 'customer' or 'supplier' )
2020-06-17 15:42:55 +02:00
* @ return int 0 if OK , < 0 if $type is not valid
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function get_codecompta ( $type )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $conf ;
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_CODECOMPTA_ADDON )) {
2019-11-13 18:32:11 +01:00
$res = false ;
$dirsociete = array_merge ( array ( '/core/modules/societe/' ), $conf -> modules_parts [ 'societe' ]);
2020-12-28 21:08:56 +01:00
foreach ( $dirsociete as $dirroot ) {
2019-11-13 18:32:11 +01:00
$res = dol_include_once ( $dirroot . $conf -> global -> SOCIETE_CODECOMPTA_ADDON . '.php' );
2020-12-28 21:08:56 +01:00
if ( $res ) {
break ;
}
2017-10-13 13:28:26 +02:00
}
2020-12-28 21:08:56 +01:00
if ( $res ) {
2017-10-13 13:28:26 +02:00
$classname = $conf -> global -> SOCIETE_CODECOMPTA_ADDON ;
$mod = new $classname ;
2019-10-21 02:18:39 +02:00
// Set code count in $mod->code
2017-10-13 13:28:26 +02:00
$result = $mod -> get_code ( $this -> db , $this , $type );
2020-12-28 21:08:56 +01:00
if ( $type == 'customer' ) {
2021-07-14 17:19:43 +02:00
$this -> code_compta_client = $mod -> code ;
2021-10-25 22:07:31 +02:00
$this -> code_compta = $this -> code_compta_client ; // For backward compatibility
2020-12-28 21:08:56 +01:00
} elseif ( $type == 'supplier' ) {
$this -> code_compta_fournisseur = $mod -> code ;
}
2017-10-13 13:28:26 +02:00
return $result ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
$this -> error = 'ErrorAccountancyCodeNotDefined' ;
return - 1 ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-12-28 21:08:56 +01:00
if ( $type == 'customer' ) {
2021-07-14 17:19:43 +02:00
$this -> code_compta_client = '' ;
2020-12-28 21:08:56 +01:00
$this -> code_compta = '' ;
} elseif ( $type == 'supplier' ) {
$this -> code_compta_fournisseur = '' ;
}
2017-10-13 13:28:26 +02:00
return 0 ;
}
}
/**
2021-10-08 06:29:22 +02:00
* Define parent company of current company
2017-10-13 13:28:26 +02:00
*
* @ param int $id Id of thirdparty to set or '' to remove
* @ return int < 0 if KO , > 0 if OK
*/
2021-05-25 12:02:33 +02:00
public function setParent ( $id )
2017-10-13 13:28:26 +02:00
{
2021-05-25 12:03:38 +02:00
dol_syslog ( get_class ( $this ) . '::setParent' , LOG_DEBUG );
2020-12-28 21:08:56 +01:00
if ( $this -> id ) {
2021-05-20 14:53:50 +02:00
// Check if the id we want to add as parent has not already one parent that is the current id we try to update
2021-05-25 12:02:33 +02:00
if ( $id > 0 ) {
2021-10-25 22:07:31 +02:00
$sameparent = $this -> validateFamilyTree ( $id , $this -> id , 0 );
2021-05-25 12:02:33 +02:00
if ( $sameparent < 0 ) {
return - 1 ;
}
if ( $sameparent == 1 ) {
setEventMessages ( 'ParentCompanyToAddIsAlreadyAChildOfModifiedCompany' , null , 'warnings' );
2021-05-20 14:38:24 +02:00
return - 1 ;
}
}
2021-05-25 12:02:33 +02:00
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'societe SET parent = ' . ( $id > 0 ? $id : 'null' ) . ' WHERE rowid = ' . (( int ) $this -> id );
2021-10-25 22:07:31 +02:00
$resql = $this -> db -> query ( $sql );
2021-05-25 12:02:33 +02:00
if ( $resql ) {
$this -> parent = $id ;
return 1 ;
} else {
return - 1 ;
}
2021-05-20 14:38:24 +02:00
} else {
return - 1 ;
}
2021-05-19 18:47:07 +02:00
}
/**
2021-05-20 14:50:02 +02:00
* Check if a thirdparty $idchild is or not inside the parents ( or grand parents ) of another thirdparty id $idparent .
2021-05-19 18:47:07 +02:00
*
* @ param int $idparent Id of thirdparty to check
* @ param int $idchild Id of thirdparty to compare to
2021-05-20 14:50:02 +02:00
* @ param int $counter Counter to protect against infinite loops
* @ return int < 0 if KO , 0 if OK or 1 if at some level a parent company was the child to compare to
2021-05-19 18:47:07 +02:00
*/
2021-05-20 15:30:33 +02:00
public function validateFamilyTree ( $idparent , $idchild , $counter = 0 )
2021-05-19 18:47:07 +02:00
{
2021-05-20 14:50:02 +02:00
if ( $counter > 100 ) {
dol_syslog ( " Too high level of parent - child for company. May be an infinite loop ? " , LOG_WARNING );
}
2021-05-20 15:25:56 +02:00
2021-05-25 12:02:33 +02:00
$sql = 'SELECT s.parent' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe as s' ;
2021-08-28 03:09:18 +02:00
$sql .= ' WHERE rowid = ' . (( int ) $idparent );
2021-10-25 22:07:31 +02:00
$resql = $this -> db -> query ( $sql );
2021-05-20 14:38:24 +02:00
if ( $resql ) {
2021-05-19 18:47:07 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2021-10-25 22:07:31 +02:00
if ( $obj -> parent == '' ) {
2021-05-20 14:38:24 +02:00
return 0 ;
2021-10-25 22:07:31 +02:00
} elseif ( $obj -> parent == $idchild ) {
2017-10-13 13:28:26 +02:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2021-10-25 22:07:31 +02:00
$sameparent = $this -> validateFamilyTree ( $obj -> parent , $idchild , ( $counter + 1 ));
2017-10-13 13:28:26 +02:00
}
2021-05-19 18:47:07 +02:00
return $sameparent ;
2020-12-28 21:08:56 +01:00
} else {
return - 1 ;
}
2017-10-13 13:28:26 +02:00
}
2022-02-02 16:45:12 +01:00
/**
* Get parents for company
*
* @ param int $company_id ID of company to search parent
* @ param array $parents List of companies ID found
* @ return array
*/
public function getParentsForCompany ( $company_id , $parents = [])
{
global $langs ;
if ( $company_id > 0 ) {
$sql = " SELECT parent FROM " . MAIN_DB_PREFIX . " societe WHERE rowid = $company_id " ;
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
if ( $obj = $this -> db -> fetch_object ( $resql )) {
$parent = $obj -> parent ;
if ( $parent > 0 && ! in_array ( $parent , $parents )) {
$parents [] = $parent ;
return $this -> getParentsForCompany ( $parent , $parents );
} else {
return $parents ;
}
}
$this -> db -> free ( $resql );
} else {
setEventMessage ( $langs -> trans ( 'GetCompanyParentsError' , $this -> db -> lasterror ()), 'errors' );
}
}
}
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
2020-12-01 15:50:59 +01:00
* Returns if a profid sould be verified to be unique
2017-10-13 13:28:26 +02:00
*
2020-12-01 15:50:59 +01:00
* @ param int $idprof 1 , 2 , 3 , 4 , 5 , 6 ( Example : 1 = siren , 2 = siret , 3 = naf , 4 = rcs / rm , 5 = eori , 6 = idprof6 )
* @ return boolean true if the ID must be unique
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function id_prof_verifiable ( $idprof )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $conf ;
2020-12-28 21:08:56 +01:00
switch ( $idprof ) {
2017-10-13 13:28:26 +02:00
case 1 :
2020-12-01 15:50:59 +01:00
$ret = ( empty ( $conf -> global -> SOCIETE_IDPROF1_UNIQUE ) ? false : true );
2017-10-13 13:28:26 +02:00
break ;
case 2 :
2020-12-01 15:50:59 +01:00
$ret = ( empty ( $conf -> global -> SOCIETE_IDPROF2_UNIQUE ) ? false : true );
2017-10-13 13:28:26 +02:00
break ;
case 3 :
2020-12-01 15:50:59 +01:00
$ret = ( empty ( $conf -> global -> SOCIETE_IDPROF3_UNIQUE ) ? false : true );
2017-10-13 13:28:26 +02:00
break ;
case 4 :
2020-12-01 15:50:59 +01:00
$ret = ( empty ( $conf -> global -> SOCIETE_IDPROF4_UNIQUE ) ? false : true );
2017-10-13 13:28:26 +02:00
break ;
case 5 :
2020-12-01 15:50:59 +01:00
$ret = ( empty ( $conf -> global -> SOCIETE_IDPROF5_UNIQUE ) ? false : true );
2017-10-13 13:28:26 +02:00
break ;
case 6 :
2020-12-01 15:50:59 +01:00
$ret = ( empty ( $conf -> global -> SOCIETE_IDPROF6_UNIQUE ) ? false : true );
2017-10-13 13:28:26 +02:00
break ;
default :
2019-11-13 18:32:11 +01:00
$ret = false ;
2017-10-13 13:28:26 +02:00
}
return $ret ;
}
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Verify if a profid exists into database for others thirds
*
* @ param string $idprof 'idprof1' , 'idprof2' , 'idprof3' , 'idprof4' , 'idprof5' , 'idprof6' , 'email' ( Example : idprof1 = siren , idprof2 = siret , idprof3 = naf , idprof4 = rcs / rm )
* @ param string $value Value of profid
* @ param int $socid Id of thirdparty to exclude ( if update )
* @ return boolean True if exists , False if not
*/
2020-10-31 14:32:18 +01:00
public function id_prof_exists ( $idprof , $value , $socid = 0 )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
$field = $idprof ;
2020-12-28 21:08:56 +01:00
switch ( $idprof ) { // For backward compatibility
2017-10-13 13:28:26 +02:00
case '1' :
case 'idprof1' :
2019-11-13 18:32:11 +01:00
$field = " siren " ;
2017-10-13 13:28:26 +02:00
break ;
case '2' :
case 'idprof2' :
2019-11-13 18:32:11 +01:00
$field = " siret " ;
2017-10-13 13:28:26 +02:00
break ;
case '3' :
case 'idprof3' :
2019-11-13 18:32:11 +01:00
$field = " ape " ;
2017-10-13 13:28:26 +02:00
break ;
case '4' :
case 'idprof4' :
2019-11-13 18:32:11 +01:00
$field = " idprof4 " ;
2017-10-13 13:28:26 +02:00
break ;
case '5' :
2019-11-13 18:32:11 +01:00
$field = " idprof5 " ;
2017-10-13 13:28:26 +02:00
break ;
case '6' :
2019-11-13 18:32:11 +01:00
$field = " idprof6 " ;
2017-10-13 13:28:26 +02:00
break ;
2020-12-28 21:08:56 +01:00
}
2017-10-13 13:28:26 +02:00
//Verify duplicate entries
2020-09-20 03:32:43 +02:00
$sql = " SELECT COUNT(*) as idprof FROM " . MAIN_DB_PREFIX . " societe WHERE " . $field . " = ' " . $this -> db -> escape ( $value ) . " ' AND entity IN ( " . getEntity ( 'societe' ) . " ) " ;
2020-12-28 21:08:56 +01:00
if ( $socid ) {
$sql .= " AND rowid <> " . $socid ;
}
2017-10-13 13:28:26 +02:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2017-10-13 13:28:26 +02:00
$obj = $this -> db -> fetch_object ( $resql );
$count = $obj -> idprof ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
$count = 0 ;
print $this -> db -> error ();
}
$this -> db -> free ( $resql );
2020-12-28 21:08:56 +01:00
if ( $count > 0 ) {
return true ;
} else {
return false ;
}
2017-10-13 13:28:26 +02:00
}
2019-10-21 02:18:39 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
2019-10-21 02:18:39 +02:00
* Check the validity of a professional identifier according to the country of the company ( siren , siret , ... )
2017-10-13 13:28:26 +02:00
*
* @ param int $idprof 1 , 2 , 3 , 4 ( Exemple : 1 = siren , 2 = siret , 3 = naf , 4 = rcs / rm )
* @ param Societe $soc Objet societe
* @ return int <= 0 if KO , > 0 if OK
* TODO better to have this in a lib than into a business class
*/
2020-10-31 14:32:18 +01:00
public function id_prof_check ( $idprof , $soc )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $conf ;
2019-11-13 18:32:11 +01:00
$ok = 1 ;
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLEPROFIDRULES )) {
return 1 ;
}
2017-10-13 13:28:26 +02:00
2019-10-21 02:18:39 +02:00
// Check SIREN if country FR
2020-12-28 21:08:56 +01:00
if ( $idprof == 1 && $soc -> country_code == 'FR' ) {
2019-11-13 18:32:11 +01:00
$chaine = trim ( $this -> idprof1 );
$chaine = preg_replace ( '/(\s)/' , '' , $chaine );
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( ! is_numeric ( $chaine )) {
return - 1 ;
}
if ( dol_strlen ( $chaine ) != 9 ) {
return - 1 ;
}
2017-10-13 13:28:26 +02:00
2018-03-15 12:00:32 +01:00
// on prend chaque chiffre un par un
// si son index (position dans la chaîne en commence à 0 au premier caractère) est impair
// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
// on ajoute cette valeur à la somme totale
2020-12-02 15:47:56 +01:00
$sum = 0 ;
2020-12-28 21:08:56 +01:00
for ( $index = 0 ; $index < 9 ; $index ++ ) {
2019-07-20 16:00:16 +02:00
$number = ( int ) $chaine [ $index ];
2020-12-28 21:08:56 +01:00
if (( $index % 2 ) != 0 ) {
if (( $number *= 2 ) > 9 ) {
$number -= 9 ;
}
}
2018-03-15 12:00:32 +01:00
$sum += $number ;
2017-10-13 13:28:26 +02:00
}
2018-03-15 12:00:32 +01:00
// le numéro est valide si la somme des chiffres est multiple de 10
2020-12-28 21:08:56 +01:00
if (( $sum % 10 ) != 0 ) {
return - 1 ;
}
2017-10-13 13:28:26 +02:00
}
// Verifie SIRET si pays FR
2020-12-28 21:08:56 +01:00
if ( $idprof == 2 && $soc -> country_code == 'FR' ) {
2019-11-13 18:32:11 +01:00
$chaine = trim ( $this -> idprof2 );
$chaine = preg_replace ( '/(\s)/' , '' , $chaine );
2017-10-13 13:28:26 +02:00
2020-12-28 21:08:56 +01:00
if ( ! is_numeric ( $chaine )) {
return - 1 ;
}
if ( dol_strlen ( $chaine ) != 14 ) {
return - 1 ;
}
2018-03-15 20:46:55 +01:00
2018-03-15 09:50:33 +01:00
// on prend chaque chiffre un par un
// si son index (position dans la chaîne en commence à 0 au premier caractère) est pair
// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
// on ajoute cette valeur à la somme totale
2020-12-02 15:47:56 +01:00
$sum = 0 ;
2020-12-28 21:08:56 +01:00
for ( $index = 0 ; $index < 14 ; $index ++ ) {
2018-03-15 09:50:33 +01:00
$number = ( int ) $chaine [ $index ];
2020-12-28 21:08:56 +01:00
if (( $index % 2 ) == 0 ) {
if (( $number *= 2 ) > 9 ) {
$number -= 9 ;
}
}
2018-03-15 09:50:33 +01:00
$sum += $number ;
}
2018-03-15 20:46:55 +01:00
2018-03-15 09:50:33 +01:00
// le numéro est valide si la somme des chiffres est multiple de 10
2020-12-28 21:08:56 +01:00
if (( $sum % 10 ) != 0 ) {
return - 1 ;
}
2017-10-13 13:28:26 +02:00
}
//Verify CIF/NIF/NIE if pays ES
//Returns: 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad
2020-12-28 21:08:56 +01:00
if ( $idprof == 1 && $soc -> country_code == 'ES' ) {
2019-11-13 18:32:11 +01:00
$string = trim ( $this -> idprof1 );
$string = preg_replace ( '/(\s)/' , '' , $string );
2017-10-13 13:28:26 +02:00
$string = strtoupper ( $string );
//Check format
2020-12-28 21:08:56 +01:00
if ( ! preg_match ( '/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/' , $string )) {
return 0 ;
}
2017-10-13 13:28:26 +02:00
2019-07-20 16:00:16 +02:00
$num = array ();
2020-12-28 21:08:56 +01:00
for ( $i = 0 ; $i < 9 ; $i ++ ) {
2019-07-20 16:00:16 +02:00
$num [ $i ] = substr ( $string , $i , 1 );
}
2017-10-13 13:28:26 +02:00
//Check NIF
2020-12-28 21:08:56 +01:00
if ( preg_match ( '/(^[0-9]{8}[A-Z]{1}$)/' , $string )) {
if ( $num [ 8 ] == substr ( 'TRWAGMYFPDXBNJZSQVHLCKE' , substr ( $string , 0 , 8 ) % 23 , 1 )) {
2019-10-27 17:01:23 +01:00
return 1 ;
2020-12-28 21:08:56 +01:00
} else {
return - 1 ;
}
}
2017-10-13 13:28:26 +02:00
//algorithm checking type code CIF
$sum = $num [ 2 ] + $num [ 4 ] + $num [ 6 ];
2020-12-28 21:08:56 +01:00
for ( $i = 1 ; $i < 8 ; $i += 2 ) {
$sum += intval ( substr (( 2 * $num [ $i ]), 0 , 1 )) + intval ( substr (( 2 * $num [ $i ]), 1 , 1 ));
}
2017-10-13 13:28:26 +02:00
$n = 10 - substr ( $sum , strlen ( $sum ) - 1 , 1 );
//Chek special NIF
2020-12-28 21:08:56 +01:00
if ( preg_match ( '/^[KLM]{1}/' , $string )) {
if ( $num [ 8 ] == chr ( 64 + $n ) || $num [ 8 ] == substr ( 'TRWAGMYFPDXBNJZSQVHLCKE' , substr ( $string , 1 , 8 ) % 23 , 1 )) {
2019-10-27 17:01:23 +01:00
return 1 ;
2020-12-28 21:08:56 +01:00
} else {
return - 1 ;
}
}
2017-10-13 13:28:26 +02:00
//Check CIF
2020-12-28 21:08:56 +01:00
if ( preg_match ( '/^[ABCDEFGHJNPQRSUVW]{1}/' , $string )) {
if ( $num [ 8 ] == chr ( 64 + $n ) || $num [ 8 ] == substr ( $n , strlen ( $n ) - 1 , 1 )) {
2019-10-27 17:01:23 +01:00
return 2 ;
2020-12-28 21:08:56 +01:00
} else {
return - 2 ;
}
}
2017-10-13 13:28:26 +02:00
//Check NIE T
2020-12-28 21:08:56 +01:00
if ( preg_match ( '/^[T]{1}/' , $string )) {
if ( $num [ 8 ] == preg_match ( '/^[T]{1}[A-Z0-9]{8}$/' , $string )) {
2019-10-27 17:01:23 +01:00
return 3 ;
2020-12-28 21:08:56 +01:00
} else {
return - 3 ;
}
}
2017-10-13 13:28:26 +02:00
//Check NIE XYZ
2020-12-28 21:08:56 +01:00
if ( preg_match ( '/^[XYZ]{1}/' , $string )) {
if ( $num [ 8 ] == substr ( 'TRWAGMYFPDXBNJZSQVHLCKE' , substr ( str_replace ( array ( 'X' , 'Y' , 'Z' ), array ( '0' , '1' , '2' ), $string ), 0 , 8 ) % 23 , 1 )) {
2019-10-27 17:01:23 +01:00
return 3 ;
2020-12-28 21:08:56 +01:00
} else {
return - 3 ;
}
}
2017-10-13 13:28:26 +02:00
//Can not be verified
return - 4 ;
}
2010-09-02 22:06:52 +02:00
2018-02-28 13:26:05 +01:00
//Verify NIF if country is PT
//Returns: 1 if NIF ok, -1 if NIF bad, 0 if unexpected bad
2020-12-28 21:08:56 +01:00
if ( $idprof == 1 && $soc -> country_code == 'PT' ) {
2019-11-13 18:32:11 +01:00
$string = trim ( $this -> idprof1 );
$string = preg_replace ( '/(\s)/' , '' , $string );
2018-02-28 13:26:05 +01:00
//Check NIF
if ( preg_match ( '/(^[0-9]{9}$)/' , $string )) {
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2018-02-28 13:26:05 +01:00
return - 1 ;
}
}
2017-10-13 13:28:26 +02:00
return $ok ;
}
2010-09-02 22:06:52 +02:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Return an url to check online a professional id or empty string
*
* @ param int $idprof 1 , 2 , 3 , 4 ( Example : 1 = siren , 2 = siret , 3 = naf , 4 = rcs / rm )
* @ param Societe $thirdparty Object thirdparty
* @ return string Url or empty string if no URL known
* TODO better in a lib than into business class
*/
2020-10-31 14:32:18 +01:00
public function id_prof_url ( $idprof , $thirdparty )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2019-11-13 18:32:11 +01:00
global $conf , $langs , $hookmanager ;
2010-09-02 22:06:52 +02:00
2019-11-13 18:32:11 +01:00
$url = '' ;
2017-10-13 13:28:26 +02:00
$action = '' ;
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
$hookmanager -> initHooks ( array ( 'idprofurl' ));
2019-11-13 18:32:11 +01:00
$parameters = array ( 'idprof' => $idprof , 'company' => $thirdparty );
$reshook = $hookmanager -> executeHooks ( 'getIdProfUrl' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
2018-02-28 13:51:29 +01:00
if ( empty ( $reshook )) {
2019-11-13 18:32:11 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLEPROFIDRULES )) {
2018-02-28 13:51:29 +01:00
return '' ;
}
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
// TODO Move links to validate professional ID into a dictionary table "country" + "link"
2020-10-31 14:32:18 +01:00
$strippedIdProf1 = str_replace ( ' ' , '' , $thirdparty -> idprof1 );
2018-02-28 13:51:29 +01:00
if ( $idprof == 1 && $thirdparty -> country_code == 'FR' ) {
2021-09-09 16:38:45 +02:00
$url = 'https://annuaire-entreprises.data.gouv.fr/entreprise/' . $strippedIdProf1 ; // See also http://avis-situation-sirene.insee.fr/
2018-02-28 13:51:29 +01:00
}
if ( $idprof == 1 && ( $thirdparty -> country_code == 'GB' || $thirdparty -> country_code == 'UK' )) {
2019-11-13 18:32:11 +01:00
$url = 'https://beta.companieshouse.gov.uk/company/' . $strippedIdProf1 ;
2018-02-28 13:51:29 +01:00
}
if ( $idprof == 1 && $thirdparty -> country_code == 'ES' ) {
2019-11-13 18:32:11 +01:00
$url = 'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/' . $strippedIdProf1 ;
2018-02-28 13:51:29 +01:00
}
if ( $idprof == 1 && $thirdparty -> country_code == 'IN' ) {
2019-11-13 18:32:11 +01:00
$url = 'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber=' . $strippedIdProf1 . ';&searchBy=TIN&backPage=searchByTin_Inter.jsp' ;
2018-02-28 13:51:29 +01:00
}
if ( $idprof == 1 && $thirdparty -> country_code == 'PT' ) {
2019-11-13 18:32:11 +01:00
$url = 'http://www.nif.pt/' . $strippedIdProf1 ;
2018-02-28 13:51:29 +01:00
}
2010-09-02 22:06:52 +02:00
2018-02-28 13:51:29 +01:00
if ( $url ) {
2021-11-22 02:35:55 +01:00
return '<a target="_blank" rel="noopener noreferrer" href="' . $url . '">' . $langs -> trans ( " Check " ) . '</a>' ;
2018-02-28 13:51:29 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
return $hookmanager -> resPrint ;
}
2017-06-07 16:44:04 +02:00
2017-10-13 13:28:26 +02:00
return '' ;
}
2010-09-02 22:06:52 +02:00
2019-10-21 02:18:39 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
2019-10-21 02:18:39 +02:00
* Indicates if the company has projects
2017-10-13 13:28:26 +02:00
*
2019-10-21 02:18:39 +02:00
* @ return bool true if the company has projects , false otherwise
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function has_projects ()
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2021-09-30 15:59:47 +02:00
$sql = " SELECT COUNT(*) as numproj FROM " . MAIN_DB_PREFIX . " projet WHERE fk_soc = " . (( int ) $this -> id );
2017-10-13 13:28:26 +02:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2017-10-13 13:28:26 +02:00
$obj = $this -> db -> fetch_object ( $resql );
$count = $obj -> numproj ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
$count = 0 ;
print $this -> db -> error ();
}
$this -> db -> free ( $resql );
return ( $count > 0 );
}
2017-06-07 16:44:04 +02:00
2010-11-11 02:26:41 +01:00
2017-10-13 13:28:26 +02:00
/**
* Load information for tab info
*
* @ param int $id Id of thirdparty to load
* @ return void
*/
2020-10-31 14:32:18 +01:00
public function info ( $id )
2017-10-13 13:28:26 +02:00
{
2022-06-28 13:09:53 +02:00
$sql = " SELECT s.rowid, s.nom as name, s.datec, tms as datem, " ;
2019-11-13 18:32:11 +01:00
$sql .= " fk_user_creat, fk_user_modif " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
2021-03-14 11:48:39 +01:00
$sql .= " WHERE s.rowid = " . (( int ) $id );
2017-06-07 16:44:04 +02:00
2019-11-13 18:32:11 +01:00
$result = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $result ) {
if ( $this -> db -> num_rows ( $result )) {
2017-10-13 13:28:26 +02:00
$obj = $this -> db -> fetch_object ( $result );
2011-03-05 17:27:26 +01:00
2017-10-13 13:28:26 +02:00
$this -> id = $obj -> rowid ;
2013-07-10 14:03:25 +02:00
2022-06-28 13:09:53 +02:00
$this -> user_creation_id = $obj -> fk_user_creat ;
$this -> user_modification_id = $obj -> fk_user_modif ;
$this -> date_creation = $this -> db -> jdate ( $obj -> datec );
$this -> date_modification = empty ( $obj -> datem ) ? '' : $this -> db -> jdate ( $obj -> datem );
2010-09-02 22:06:52 +02:00
2019-11-13 18:32:11 +01:00
$this -> ref = $obj -> name ;
2017-10-13 13:28:26 +02:00
}
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
$this -> db -> free ( $result );
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
dol_print_error ( $this -> db );
}
}
2015-06-21 17:05:49 +02:00
2017-10-13 13:28:26 +02:00
/**
* Return if third party is a company ( Business ) or an end user ( Consumer )
*
* @ return boolean true = is a company , false = a and user
*/
2020-10-31 14:32:18 +01:00
public function isACompany ()
2017-10-13 13:28:26 +02:00
{
global $conf ;
2015-06-21 17:05:49 +02:00
2017-10-13 13:28:26 +02:00
// Define if third party is treated as company (or not) when nature is unknown
2019-11-13 18:32:11 +01:00
$isacompany = empty ( $conf -> global -> MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES ) ? 0 : 1 ; // 0 by default
if ( ! empty ( $this -> tva_intra )) {
2019-11-06 00:27:36 +01:00
$isacompany = 1 ;
2020-05-21 15:05:19 +02:00
} elseif ( ! empty ( $this -> idprof1 ) || ! empty ( $this -> idprof2 ) || ! empty ( $this -> idprof3 ) || ! empty ( $this -> idprof4 ) || ! empty ( $this -> idprof5 ) || ! empty ( $this -> idprof6 )) {
2019-11-06 00:27:36 +01:00
$isacompany = 1 ;
2020-12-28 21:08:56 +01:00
} elseif ( ! empty ( $this -> typent_code ) && $this -> typent_code != 'TE_UNKNOWN' ) {
2018-10-08 20:01:45 +02:00
// TODO Add a field is_a_company into dictionary
2020-12-28 21:08:56 +01:00
if ( preg_match ( '/^TE_PRIVATE/' , $this -> typent_code )) {
$isacompany = 0 ;
} else {
$isacompany = 1 ;
}
2018-10-08 20:01:45 +02:00
}
2014-02-19 01:51:19 +01:00
2017-10-13 13:28:26 +02:00
return $isacompany ;
}
2010-09-02 22:06:52 +02:00
2018-04-09 14:25:02 +02:00
/**
* Return if a company is inside the EEC ( European Economic Community )
*
* @ return boolean true = country inside EEC , false = country outside EEC
*/
2020-10-31 14:32:18 +01:00
public function isInEEC ()
2018-04-09 14:25:02 +02:00
{
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
return isInEEC ( $this );
}
2019-10-21 02:18:39 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
2019-10-21 02:18:39 +02:00
* Load the list of provider categories
2017-10-13 13:28:26 +02:00
*
* @ return int 0 if success , <> 0 if error
*/
2020-10-31 14:32:18 +01:00
public function LoadSupplierCateg ()
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
$this -> SupplierCategories = array ();
$sql = " SELECT rowid, label " ;
2019-11-13 18:32:11 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " categorie " ;
$sql .= " WHERE type = " . Categorie :: TYPE_SUPPLIER ;
2010-09-02 22:06:52 +02:00
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2017-10-13 13:28:26 +02:00
$this -> SupplierCategories [ $obj -> rowid ] = $obj -> label ;
}
return 0 ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
return - 1 ;
}
}
2011-08-19 00:25:46 +02:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Insert link supplier - category
*
* @ param int $categorie_id Id of category
* @ return int 0 if success , <> 0 if error
*/
2020-10-31 14:32:18 +01:00
public function AddFournisseurInCategory ( $categorie_id )
2017-10-13 13:28:26 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2020-12-28 21:08:56 +01:00
if ( $categorie_id > 0 && $this -> id > 0 ) {
2017-10-13 13:28:26 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " categorie_fournisseur (fk_categorie, fk_soc) " ;
2021-08-28 03:09:18 +02:00
$sql .= " VALUES ( " . (( int ) $categorie_id ) . " , " . (( int ) $this -> id ) . " ) " ;
2011-08-19 00:25:46 +02:00
2020-12-28 21:08:56 +01:00
if ( $resql = $this -> db -> query ( $sql )) {
return 0 ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
return 0 ;
}
return - 1 ;
}
2010-09-02 22:06:52 +02:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Create a third party into database from a member object
*
2018-12-18 21:00:06 +01:00
* @ param Adherent $member Object member
* @ param string $socname Name of third party to force
* @ param string $socalias Alias name of third party to force
* @ param string $customercode Customer code
* @ return int < 0 if KO , id of created account if OK
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function create_from_member ( Adherent $member , $socname = '' , $socalias = '' , $customercode = '' )
2017-10-13 13:28:26 +02:00
{
2021-10-25 22:07:31 +02:00
// phpcs:enable
2021-01-06 15:35:33 +01:00
global $conf , $user , $langs ;
2017-10-13 13:28:26 +02:00
2018-03-05 21:46:24 +01:00
dol_syslog ( get_class ( $this ) . " ::create_from_member " , LOG_DEBUG );
2019-11-13 18:32:11 +01:00
$name = $socname ? $socname : $member -> societe ;
2020-12-28 21:08:56 +01:00
if ( empty ( $name )) {
$name = $member -> getFullName ( $langs );
}
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$alias = $socalias ? $socalias : '' ;
2017-10-13 13:28:26 +02:00
// Positionne parametres
2019-11-13 18:32:11 +01:00
$this -> nom = $name ; // TODO deprecated
$this -> name = $name ;
$this -> name_alias = $alias ;
$this -> address = $member -> address ;
$this -> zip = $member -> zip ;
$this -> town = $member -> town ;
$this -> country_code = $member -> country_code ;
$this -> country_id = $member -> country_id ;
$this -> phone = $member -> phone ; // Prof phone
$this -> email = $member -> email ;
2020-10-31 14:32:18 +01:00
$this -> socialnetworks = $member -> socialnetworks ;
2020-04-25 13:52:07 +02:00
$this -> entity = $member -> entity ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$this -> client = 1 ; // A member is a customer by default
$this -> code_client = ( $customercode ? $customercode : - 1 );
2017-10-13 13:28:26 +02:00
$this -> code_fournisseur = - 1 ;
2021-03-29 22:16:58 +02:00
$this -> typent_code = ( $member -> morphy == 'phy' ? 'TE_PRIVATE' : 0 );
2021-03-30 00:31:37 +02:00
$this -> typent_id = $this -> typent_code ? dol_getIdFromCode ( $this -> db , $this -> typent_code , 'c_typent' , 'id' , 'code' ) : 0 ;
2017-10-13 13:28:26 +02:00
$this -> db -> begin ();
// Cree et positionne $this->id
2019-11-13 18:32:11 +01:00
$result = $this -> create ( $user );
2021-03-28 19:42:18 +02:00
2020-12-28 21:08:56 +01:00
if ( $result >= 0 ) {
2021-01-06 15:35:33 +01:00
// Auto-create contact on thirdparty creation
2021-01-06 20:20:37 +01:00
if ( ! empty ( $conf -> global -> THIRDPARTY_DEFAULT_CREATE_CONTACT )) {
2021-01-06 15:35:33 +01:00
// Fill fields needed by contact
$this -> name_bis = $member -> lastname ;
$this -> firstname = $member -> firstname ;
$this -> civility_id = $member -> civility_id ;
2021-01-06 20:20:37 +01:00
2021-01-06 15:35:33 +01:00
dol_syslog ( " We ask to create a contact/address too " , LOG_DEBUG );
$result = $this -> create_individual ( $user );
2021-03-28 19:42:18 +02:00
2021-02-26 21:17:52 +01:00
if ( $result < 0 ) {
2021-01-06 15:35:33 +01:00
setEventMessages ( $this -> error , $this -> errors , 'errors' );
2021-01-06 20:20:37 +01:00
$this -> db -> rollback ();
2021-01-06 15:35:33 +01:00
return - 1 ;
}
}
2017-10-13 13:28:26 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent " ;
2021-06-09 15:36:47 +02:00
$sql .= " SET fk_soc = " . (( int ) $this -> id );
$sql .= " WHERE rowid = " . (( int ) $member -> id );
2010-09-02 22:06:52 +02:00
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2017-10-13 13:28:26 +02:00
$this -> db -> commit ();
return $this -> id ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 18:32:11 +01:00
$this -> error = $this -> db -> error ();
2010-12-15 13:05:27 +01:00
2017-10-13 13:28:26 +02:00
$this -> db -> rollback ();
return - 1 ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
// $this->error deja positionne
2019-01-27 11:55:16 +01:00
dol_syslog ( get_class ( $this ) . " ::create_from_member - 2 - " . $this -> error . " - " . join ( ',' , $this -> errors ), LOG_ERR );
2016-07-07 12:19:20 +02:00
2017-10-13 13:28:26 +02:00
$this -> db -> rollback ();
return $result ;
}
}
2010-09-02 22:06:52 +02:00
2017-10-13 13:28:26 +02:00
/**
* Set properties with value into $conf
*
* @ param Conf $conf Conf object ( possibility to use another entity )
* @ return void
*/
2020-10-31 14:32:18 +01:00
public function setMysoc ( Conf $conf )
2017-10-13 13:28:26 +02:00
{
global $langs ;
2010-09-02 22:06:52 +02:00
2019-11-13 18:32:11 +01:00
$this -> id = 0 ;
$this -> name = empty ( $conf -> global -> MAIN_INFO_SOCIETE_NOM ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
$this -> address = empty ( $conf -> global -> MAIN_INFO_SOCIETE_ADDRESS ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_ADDRESS ;
$this -> zip = empty ( $conf -> global -> MAIN_INFO_SOCIETE_ZIP ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_ZIP ;
$this -> town = empty ( $conf -> global -> MAIN_INFO_SOCIETE_TOWN ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_TOWN ;
$this -> region_code = empty ( $conf -> global -> MAIN_INFO_SOCIETE_REGION ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_REGION ;
$this -> object = empty ( $conf -> global -> MAIN_INFO_SOCIETE_OBJECT ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_OBJECT ;
2014-05-03 17:16:37 +02:00
2019-11-13 18:32:11 +01:00
$this -> note_private = empty ( $conf -> global -> MAIN_INFO_SOCIETE_NOTE ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_NOTE ;
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$this -> nom = $this -> name ; // deprecated
2017-10-13 13:28:26 +02:00
// We define country_id, country_code and country
2019-11-13 18:32:11 +01:00
$country_id = $country_code = $country_label = '' ;
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> global -> MAIN_INFO_SOCIETE_COUNTRY )) {
2019-11-13 18:32:11 +01:00
$tmp = explode ( ':' , $conf -> global -> MAIN_INFO_SOCIETE_COUNTRY );
$country_id = $tmp [ 0 ];
2020-12-28 21:08:56 +01:00
if ( ! empty ( $tmp [ 1 ])) { // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
2019-11-13 18:32:11 +01:00
$country_code = $tmp [ 1 ];
$country_label = $tmp [ 2 ];
2020-05-21 15:05:19 +02:00
} else // For backward compatibility
2017-10-13 13:28:26 +02:00
{
2019-06-20 04:11:10 +02:00
dol_syslog ( " Your country setup use an old syntax. Reedit it using setup area. " , LOG_WARNING );
2017-10-13 13:28:26 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
2019-11-13 18:32:11 +01:00
$country_code = getCountry ( $country_id , 2 , $this -> db ); // This need a SQL request, but it's the old feature that should not be used anymore
$country_label = getCountry ( $country_id , 0 , $this -> db ); // This need a SQL request, but it's the old feature that should not be used anymore
2017-10-13 13:28:26 +02:00
}
}
2019-11-13 18:32:11 +01:00
$this -> country_id = $country_id ;
$this -> country_code = $country_code ;
$this -> country = $country_label ;
2020-12-28 21:08:56 +01:00
if ( is_object ( $langs )) {
$this -> country = ( $langs -> trans ( 'Country' . $country_code ) != 'Country' . $country_code ) ? $langs -> trans ( 'Country' . $country_code ) : $country_label ;
}
2017-10-13 13:28:26 +02:00
2019-03-28 00:09:59 +01:00
//TODO This could be replicated for region but function `getRegion` didn't exist, so I didn't added it.
// We define state_id, state_code and state
2019-11-13 18:32:11 +01:00
$state_id = 0 ; $state_code = $state_label = '' ;
2020-12-28 21:08:56 +01:00
if ( ! empty ( $conf -> global -> MAIN_INFO_SOCIETE_STATE )) {
2019-11-13 18:32:11 +01:00
$tmp = explode ( ':' , $conf -> global -> MAIN_INFO_SOCIETE_STATE );
$state_id = $tmp [ 0 ];
2020-12-28 21:08:56 +01:00
if ( ! empty ( $tmp [ 1 ])) { // If $conf->global->MAIN_INFO_SOCIETE_STATE is "id:code:label"
2019-11-13 18:32:11 +01:00
$state_code = $tmp [ 1 ];
$state_label = $tmp [ 2 ];
2021-01-14 15:19:56 +01:00
} else { // For backward compatibility
2021-12-01 14:46:48 +01:00
dol_syslog ( " Your setup of State has an old syntax (entity= " . $conf -> entity . " ). Go in Home - Setup - Organization then Save should remove this error. " , LOG_ERR );
2019-03-28 00:09:59 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
2019-11-13 18:32:11 +01:00
$state_code = getState ( $state_id , 2 , $this -> db ); // This need a SQL request, but it's the old feature that should not be used anymore
$state_label = getState ( $state_id , 0 , $this -> db ); // This need a SQL request, but it's the old feature that should not be used anymore
2019-03-28 00:09:59 +01:00
}
}
2019-11-13 18:32:11 +01:00
$this -> state_id = $state_id ;
$this -> state_code = $state_code ;
$this -> state = $state_label ;
2020-12-28 21:08:56 +01:00
if ( is_object ( $langs )) {
$this -> state = ( $langs -> trans ( 'State' . $state_code ) != 'State' . $state_code ) ? $langs -> trans ( 'State' . $state_code ) : $state_label ;
}
2019-03-28 00:09:59 +01:00
2019-11-13 18:32:11 +01:00
$this -> phone = empty ( $conf -> global -> MAIN_INFO_SOCIETE_TEL ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_TEL ;
$this -> fax = empty ( $conf -> global -> MAIN_INFO_SOCIETE_FAX ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_FAX ;
$this -> url = empty ( $conf -> global -> MAIN_INFO_SOCIETE_WEB ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_WEB ;
2019-12-30 21:17:41 +01:00
// Social networks
$this -> facebook_url = empty ( $conf -> global -> MAIN_INFO_SOCIETE_FACEBOOK_URL ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_FACEBOOK_URL ;
$this -> twitter_url = empty ( $conf -> global -> MAIN_INFO_SOCIETE_TWITTER_URL ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_TWITTER_URL ;
$this -> linkedin_url = empty ( $conf -> global -> MAIN_INFO_SOCIETE_LINKEDIN_URL ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_LINKEDIN_URL ;
$this -> instagram_url = empty ( $conf -> global -> MAIN_INFO_SOCIETE_INSTAGRAM_URL ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_INSTAGRAM_URL ;
$this -> youtube_url = empty ( $conf -> global -> MAIN_INFO_SOCIETE_YOUTUBE_URL ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_YOUTUBE_URL ;
$this -> github_url = empty ( $conf -> global -> MAIN_INFO_SOCIETE_GITHUB_URL ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_GITHUB_URL ;
2020-05-17 20:02:01 +02:00
$this -> socialnetworks = array ();
2020-12-28 21:08:56 +01:00
if ( ! empty ( $this -> facebook_url )) {
$this -> socialnetworks [ 'facebook' ] = $this -> facebook_url ;
}
if ( ! empty ( $this -> twitter_url )) {
$this -> socialnetworks [ 'twitter' ] = $this -> twitter_url ;
}
if ( ! empty ( $this -> linkedin_url )) {
$this -> socialnetworks [ 'linkedin' ] = $this -> linkedin_url ;
}
if ( ! empty ( $this -> instagram_url )) {
$this -> socialnetworks [ 'instagram' ] = $this -> instagram_url ;
}
if ( ! empty ( $this -> youtube_url )) {
$this -> socialnetworks [ 'youtube' ] = $this -> youtube_url ;
}
if ( ! empty ( $this -> github_url )) {
$this -> socialnetworks [ 'github' ] = $this -> github_url ;
}
2019-12-30 21:17:41 +01:00
2017-10-13 13:28:26 +02:00
// Id prof generiques
2019-11-13 18:32:11 +01:00
$this -> idprof1 = empty ( $conf -> global -> MAIN_INFO_SIREN ) ? '' : $conf -> global -> MAIN_INFO_SIREN ;
$this -> idprof2 = empty ( $conf -> global -> MAIN_INFO_SIRET ) ? '' : $conf -> global -> MAIN_INFO_SIRET ;
$this -> idprof3 = empty ( $conf -> global -> MAIN_INFO_APE ) ? '' : $conf -> global -> MAIN_INFO_APE ;
$this -> idprof4 = empty ( $conf -> global -> MAIN_INFO_RCS ) ? '' : $conf -> global -> MAIN_INFO_RCS ;
$this -> idprof5 = empty ( $conf -> global -> MAIN_INFO_PROFID5 ) ? '' : $conf -> global -> MAIN_INFO_PROFID5 ;
$this -> idprof6 = empty ( $conf -> global -> MAIN_INFO_PROFID6 ) ? '' : $conf -> global -> MAIN_INFO_PROFID6 ;
$this -> tva_intra = empty ( $conf -> global -> MAIN_INFO_TVAINTRA ) ? '' : $conf -> global -> MAIN_INFO_TVAINTRA ; // VAT number, not necessarly INTRA.
$this -> managers = empty ( $conf -> global -> MAIN_INFO_SOCIETE_MANAGERS ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_MANAGERS ;
$this -> capital = empty ( $conf -> global -> MAIN_INFO_CAPITAL ) ? '' : $conf -> global -> MAIN_INFO_CAPITAL ;
$this -> forme_juridique_code = empty ( $conf -> global -> MAIN_INFO_SOCIETE_FORME_JURIDIQUE ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_FORME_JURIDIQUE ;
$this -> email = empty ( $conf -> global -> MAIN_INFO_SOCIETE_MAIL ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_MAIL ;
$this -> default_lang = ( empty ( $conf -> global -> MAIN_LANG_DEFAULT ) ? 'auto' : $conf -> global -> MAIN_LANG_DEFAULT );
$this -> logo = empty ( $conf -> global -> MAIN_INFO_SOCIETE_LOGO ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_LOGO ;
$this -> logo_small = empty ( $conf -> global -> MAIN_INFO_SOCIETE_LOGO_SMALL ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_LOGO_SMALL ;
$this -> logo_mini = empty ( $conf -> global -> MAIN_INFO_SOCIETE_LOGO_MINI ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_LOGO_MINI ;
$this -> logo_squarred = empty ( $conf -> global -> MAIN_INFO_SOCIETE_LOGO_SQUARRED ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_LOGO_SQUARRED ;
$this -> logo_squarred_small = empty ( $conf -> global -> MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL ;
$this -> logo_squarred_mini = empty ( $conf -> global -> MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI ;
2017-10-13 13:28:26 +02:00
// Define if company use vat or not
2019-11-13 18:32:11 +01:00
$this -> tva_assuj = $conf -> global -> FACTURE_TVAOPTION ;
2017-10-13 13:28:26 +02:00
// Define if company use local taxes
2019-11-13 18:32:11 +01:00
$this -> localtax1_assuj = (( isset ( $conf -> global -> FACTURE_LOCAL_TAX1_OPTION ) && ( $conf -> global -> FACTURE_LOCAL_TAX1_OPTION == '1' || $conf -> global -> FACTURE_LOCAL_TAX1_OPTION == 'localtax1on' )) ? 1 : 0 );
$this -> localtax2_assuj = (( isset ( $conf -> global -> FACTURE_LOCAL_TAX2_OPTION ) && ( $conf -> global -> FACTURE_LOCAL_TAX2_OPTION == '1' || $conf -> global -> FACTURE_LOCAL_TAX2_OPTION == 'localtax2on' )) ? 1 : 0 );
2017-10-13 13:28:26 +02:00
}
/**
* Initialise an instance with random values .
* Used to build previews or test instances .
* id must be 0 if object instance is a specimen .
*
2019-09-07 14:48:25 +02:00
* @ return int > 0 if ok
2017-10-13 13:28:26 +02:00
*/
2020-10-31 14:32:18 +01:00
public function initAsSpecimen ()
2017-10-13 13:28:26 +02:00
{
2019-11-13 18:32:11 +01:00
$now = dol_now ();
2017-10-13 13:28:26 +02:00
// Initialize parameters
2019-11-13 18:32:11 +01:00
$this -> id = 0 ;
2020-10-29 23:56:42 +01:00
$this -> entity = 1 ;
2019-01-27 11:55:16 +01:00
$this -> name = 'THIRDPARTY SPECIMEN ' . dol_print_date ( $now , 'dayhourlog' );
2019-11-13 18:32:11 +01:00
$this -> nom = $this -> name ; // For backward compatibility
2017-10-13 13:28:26 +02:00
$this -> ref_ext = 'Ref ext' ;
2019-11-13 18:32:11 +01:00
$this -> specimen = 1 ;
$this -> address = '21 jump street' ;
$this -> zip = '99999' ;
$this -> town = 'MyTown' ;
$this -> state_id = 1 ;
$this -> state_code = 'AA' ;
$this -> state = 'MyState' ;
$this -> country_id = 1 ;
$this -> country_code = 'FR' ;
$this -> email = 'specimen@specimen.com' ;
2019-09-12 18:12:28 +02:00
$this -> socialnetworks = array (
'skype' => 'tom.hanson' ,
'twitter' => 'tomhanson' ,
'facebook' => 'tomhanson' ,
'linkedin' => 'tomhanson' ,
);
2019-11-13 18:32:11 +01:00
$this -> url = 'http://www.specimen.com' ;
$this -> phone = '0909090901' ;
$this -> fax = '0909090909' ;
$this -> code_client = 'CC-' . dol_print_date ( $now , 'dayhourlog' );
$this -> code_fournisseur = 'SC-' . dol_print_date ( $now , 'dayhourlog' );
$this -> capital = 10000 ;
$this -> client = 1 ;
$this -> prospect = 1 ;
$this -> fournisseur = 1 ;
$this -> tva_assuj = 1 ;
$this -> tva_intra = 'EU1234567' ;
$this -> note_public = 'This is a comment (public)' ;
$this -> note_private = 'This is a comment (private)' ;
$this -> idprof1 = 'idprof1' ;
$this -> idprof2 = 'idprof2' ;
$this -> idprof3 = 'idprof3' ;
$this -> idprof4 = 'idprof4' ;
$this -> idprof5 = 'idprof5' ;
$this -> idprof6 = 'idprof6' ;
2019-09-07 14:48:25 +02:00
return 1 ;
2017-10-13 13:28:26 +02:00
}
/**
* Check if we must use localtax feature or not according to country ( country of $mysoc in most cases ) .
*
* @ param int $localTaxNum To get info for only localtax1 or localtax2
* @ return boolean true or false
*/
2020-10-31 14:32:18 +01:00
public function useLocalTax ( $localTaxNum = 0 )
2017-10-13 13:28:26 +02:00
{
$sql = " SELECT t.localtax1, t.localtax2 " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_tva as t, " . MAIN_DB_PREFIX . " c_country as c " ;
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = ' " . $this -> db -> escape ( $this -> country_code ) . " ' " ;
$sql .= " AND t.active = 1 " ;
2020-12-28 21:08:56 +01:00
if ( empty ( $localTaxNum )) {
$sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0') " ;
} elseif ( $localTaxNum == 1 ) {
$sql .= " AND t.localtax1_type <> '0' " ;
} elseif ( $localTaxNum == 2 ) {
$sql .= " AND t.localtax2_type <> '0' " ;
}
2017-10-13 13:28:26 +02:00
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
return ( $this -> db -> num_rows ( $resql ) > 0 );
} else {
return false ;
}
2017-10-13 13:28:26 +02:00
}
/**
* Check if we must use NPR Vat ( french stupid rule ) or not according to country ( country of $mysoc in most cases ) .
*
* @ return boolean true or false
*/
2020-10-31 14:32:18 +01:00
public function useNPR ()
2017-10-13 13:28:26 +02:00
{
$sql = " SELECT t.rowid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_tva as t, " . MAIN_DB_PREFIX . " c_country as c " ;
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = ' " . $this -> db -> escape ( $this -> country_code ) . " ' " ;
$sql .= " AND t.active = 1 AND t.recuperableonly = 1 " ;
dol_syslog ( " useNPR " , LOG_DEBUG );
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2017-10-13 13:28:26 +02:00
return ( $this -> db -> num_rows ( $resql ) > 0 );
2020-12-28 21:08:56 +01:00
} else {
return false ;
}
2017-10-13 13:28:26 +02:00
}
/**
* Check if we must use revenue stamps feature or not according to country ( country of $mysocin most cases ) .
2020-01-31 14:53:47 +01:00
* Table c_revenuestamp contains the country and value of stamp per invoice .
2017-10-13 13:28:26 +02:00
*
* @ return boolean true or false
*/
2020-10-31 14:32:18 +01:00
public function useRevenueStamp ()
2017-10-13 13:28:26 +02:00
{
2014-08-10 13:37:39 +02:00
$sql = " SELECT COUNT(*) as nb " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_revenuestamp as r, " . MAIN_DB_PREFIX . " c_country as c " ;
2017-05-12 16:55:11 +02:00
$sql .= " WHERE r.fk_pays = c.rowid AND c.code = ' " . $this -> db -> escape ( $this -> country_code ) . " ' " ;
2013-03-23 17:34:23 +01:00
$sql .= " AND r.active = 1 " ;
2014-06-12 11:31:53 +02:00
dol_syslog ( " useRevenueStamp " , LOG_DEBUG );
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2019-11-13 18:32:11 +01:00
$obj = $this -> db -> fetch_object ( $resql );
2020-12-28 21:08:56 +01:00
return (( $obj -> nb > 0 ) ? true : false );
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 18:32:11 +01:00
$this -> error = $this -> db -> lasterror ();
2013-03-23 17:34:23 +01:00
return false ;
}
2012-11-27 13:05:21 +01:00
}
2013-03-09 16:19:15 +01:00
2013-02-12 15:31:12 +01:00
/**
2013-03-09 16:19:15 +01:00
* Return prostect level
2013-02-12 15:31:12 +01:00
*
* @ return string Libelle
*/
2020-10-31 14:32:18 +01:00
public function getLibProspLevel ()
2013-02-12 15:31:12 +01:00
{
return $this -> LibProspLevel ( $this -> fk_prospectlevel );
}
2013-03-09 16:19:15 +01:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2013-02-12 15:31:12 +01:00
/**
* Return label of prospect level
*
* @ param int $fk_prospectlevel Prospect level
* @ return string label of level
*/
2020-10-31 14:32:18 +01:00
public function LibProspLevel ( $fk_prospectlevel )
2013-02-12 15:31:12 +01:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2013-02-12 15:31:12 +01:00
global $langs ;
2013-03-09 16:19:15 +01:00
2019-11-13 18:32:11 +01:00
$lib = $langs -> trans ( " ProspectLevel " . $fk_prospectlevel );
2013-02-12 15:31:12 +01:00
// If lib not found in language file, we get label from cache/databse
2020-12-28 21:08:56 +01:00
if ( $lib == $langs -> trans ( " ProspectLevel " . $fk_prospectlevel )) {
2019-11-13 18:32:11 +01:00
$lib = $langs -> getLabelFromKey ( $this -> db , $fk_prospectlevel , 'c_prospectlevel' , 'code' , 'label' );
2013-02-12 15:31:12 +01:00
}
return $lib ;
}
2013-03-09 16:19:15 +01:00
2013-02-12 19:16:48 +01:00
/**
* Return status of prospect
*
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long
2015-05-06 23:13:07 +02:00
* @ param string $label Label to use for status for added status
2013-02-12 19:16:48 +01:00
* @ return string Libelle
*/
2020-10-31 14:32:18 +01:00
public function getLibProspCommStatut ( $mode = 0 , $label = '' )
2013-02-12 19:16:48 +01:00
{
2020-04-27 17:35:14 +02:00
return $this -> LibProspCommStatut ( $this -> stcomm_id , $mode , $label , $this -> stcomm_picto );
2013-02-12 19:16:48 +01:00
}
2013-03-09 16:19:15 +01:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2013-02-12 19:16:48 +01:00
/**
* Return label of a given status
*
2019-10-24 16:38:06 +02:00
* @ param int | string $status Id or code for prospection status
2015-05-06 23:13:07 +02:00
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto
* @ param string $label Label to use for status for added status
2020-04-27 17:35:14 +02:00
* @ param string $picto Name of image file to show ( 'filenew' , ... )
2020-04-27 18:01:07 +02:00
* If no extension provided , we use '.png' . Image must be stored into theme / xxx / img directory .
* Example : picto . png if picto . png is stored into htdocs / theme / mytheme / img
* Example : picto . png @ mymodule if picto . png is stored into htdocs / mymodule / img
* Example : / mydir / mysubdir / picto . png if picto . png is stored into htdocs / mydir / mysubdir ( pictoisfullpath must be set to 1 )
2020-02-08 11:32:38 +01:00
* @ return string Label of prospection status
2013-02-12 19:16:48 +01:00
*/
2020-10-31 14:32:18 +01:00
public function LibProspCommStatut ( $status , $mode = 0 , $label = '' , $picto = '' )
2013-02-12 15:31:12 +01:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2013-02-12 15:31:12 +01:00
global $langs ;
2013-02-12 19:16:48 +01:00
$langs -> load ( 'customers' );
2013-03-09 16:19:15 +01:00
2020-07-31 16:41:17 +02:00
if ( $mode == 2 ) {
2020-12-28 21:08:56 +01:00
if ( $status == '-1' || $status == 'ST_NO' ) {
return img_action ( $langs -> trans ( " StatusProspect-1 " ), - 1 , $picto ) . ' ' . $langs -> trans ( " StatusProspect-1 " );
} elseif ( $status == '0' || $status == 'ST_NEVER' ) {
return img_action ( $langs -> trans ( " StatusProspect0 " ), 0 , $picto ) . ' ' . $langs -> trans ( " StatusProspect0 " );
} elseif ( $status == '1' || $status == 'ST_TODO' ) {
return img_action ( $langs -> trans ( " StatusProspect1 " ), 1 , $picto ) . ' ' . $langs -> trans ( " StatusProspect1 " );
} elseif ( $status == '2' || $status == 'ST_PEND' ) {
return img_action ( $langs -> trans ( " StatusProspect2 " ), 2 , $picto ) . ' ' . $langs -> trans ( " StatusProspect2 " );
} elseif ( $status == '3' || $status == 'ST_DONE' ) {
return img_action ( $langs -> trans ( " StatusProspect3 " ), 3 , $picto ) . ' ' . $langs -> trans ( " StatusProspect3 " );
} else {
2020-04-27 17:35:14 +02:00
return img_action (( $langs -> trans ( " StatusProspect " . $status ) != " StatusProspect " . $status ) ? $langs -> trans ( " StatusProspect " . $status ) : $label , 0 , $picto ) . ' ' . (( $langs -> trans ( " StatusProspect " . $status ) != " StatusProspect " . $status ) ? $langs -> trans ( " StatusProspect " . $status ) : $label );
2015-05-06 23:13:07 +02:00
}
2020-07-31 16:41:17 +02:00
} elseif ( $mode == 3 ) {
2020-12-28 21:08:56 +01:00
if ( $status == '-1' || $status == 'ST_NO' ) {
return img_action ( $langs -> trans ( " StatusProspect-1 " ), - 1 , $picto );
} elseif ( $status == '0' || $status == 'ST_NEVER' ) {
return img_action ( $langs -> trans ( " StatusProspect0 " ), 0 , $picto );
} elseif ( $status == '1' || $status == 'ST_TODO' ) {
return img_action ( $langs -> trans ( " StatusProspect1 " ), 1 , $picto );
} elseif ( $status == '2' || $status == 'ST_PEND' ) {
return img_action ( $langs -> trans ( " StatusProspect2 " ), 2 , $picto );
} elseif ( $status == '3' || $status == 'ST_DONE' ) {
return img_action ( $langs -> trans ( " StatusProspect3 " ), 3 , $picto );
} else {
2020-04-27 17:35:14 +02:00
return img_action (( $langs -> trans ( " StatusProspect " . $status ) != " StatusProspect " . $status ) ? $langs -> trans ( " StatusProspect " . $status ) : $label , 0 , $picto );
2015-05-06 23:13:07 +02:00
}
2020-07-31 16:41:17 +02:00
} elseif ( $mode == 4 ) {
2020-12-28 21:08:56 +01:00
if ( $status == '-1' || $status == 'ST_NO' ) {
return img_action ( $langs -> trans ( " StatusProspect-1 " ), - 1 , $picto ) . ' ' . $langs -> trans ( " StatusProspect-1 " );
} elseif ( $status == '0' || $status == 'ST_NEVER' ) {
return img_action ( $langs -> trans ( " StatusProspect0 " ), 0 , $picto ) . ' ' . $langs -> trans ( " StatusProspect0 " );
} elseif ( $status == '1' || $status == 'ST_TODO' ) {
return img_action ( $langs -> trans ( " StatusProspect1 " ), 1 , $picto ) . ' ' . $langs -> trans ( " StatusProspect1 " );
} elseif ( $status == '2' || $status == 'ST_PEND' ) {
return img_action ( $langs -> trans ( " StatusProspect2 " ), 2 , $picto ) . ' ' . $langs -> trans ( " StatusProspect2 " );
} elseif ( $status == '3' || $status == 'ST_DONE' ) {
return img_action ( $langs -> trans ( " StatusProspect3 " ), 3 , $picto ) . ' ' . $langs -> trans ( " StatusProspect3 " );
} else {
2020-04-27 17:35:14 +02:00
return img_action (( $langs -> trans ( " StatusProspect " . $status ) != " StatusProspect " . $status ) ? $langs -> trans ( " StatusProspect " . $status ) : $label , 0 , $picto ) . ' ' . (( $langs -> trans ( " StatusProspect " . $status ) != " StatusProspect " . $status ) ? $langs -> trans ( " StatusProspect " . $status ) : $label );
2015-05-06 23:13:07 +02:00
}
2013-02-12 19:16:48 +01:00
}
2013-03-09 16:19:15 +01:00
2013-02-12 19:16:48 +01:00
return " Error, mode/status not found " ;
}
2013-03-09 16:19:15 +01:00
2017-01-20 14:02:51 +01:00
/**
2021-09-09 02:00:07 +02:00
* Return amount of proposal not yet paid and total an dlist of all proposals
2017-01-20 14:02:51 +01:00
*
2017-01-23 20:54:52 +01:00
* @ param string $mode 'customer' or 'supplier'
2021-09-09 02:00:07 +02:00
* @ return array array ( 'opened' => Amount including tax that remains to pay , 'total_ht' => Total amount without tax of all objects paid or not , 'total_ttc' => Total amunt including tax of all object paid or not )
2017-01-20 14:02:51 +01:00
*/
2020-10-31 14:32:18 +01:00
public function getOutstandingProposals ( $mode = 'customer' )
2017-01-20 14:02:51 +01:00
{
2019-11-13 18:32:11 +01:00
$table = 'propal' ;
2020-12-28 21:08:56 +01:00
if ( $mode == 'supplier' ) {
$table = 'supplier_proposal' ;
}
2017-07-12 11:00:18 +02:00
2021-06-28 16:45:29 +02:00
$sql = " SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM " . MAIN_DB_PREFIX . $table . " as f " ;
$sql .= " WHERE fk_soc = " . (( int ) $this -> id );
2017-07-12 11:00:18 +02:00
if ( $mode == 'supplier' ) {
$sql .= " AND entity IN ( " . getEntity ( 'supplier_proposal' ) . " ) " ;
} else {
$sql .= " AND entity IN ( " . getEntity ( 'propal' ) . " ) " ;
}
2021-06-28 16:45:29 +02:00
dol_syslog ( " getOutstandingProposals for fk_soc = " . (( int ) $this -> id ), LOG_DEBUG );
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2017-07-12 11:00:18 +02:00
$outstandingOpened = 0 ;
$outstandingTotal = 0 ;
$outstandingTotalIncTax = 0 ;
2021-06-28 16:45:29 +02:00
$arrayofref = array ();
2019-11-13 18:32:11 +01:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2021-06-28 16:45:29 +02:00
$arrayofref [ $obj -> rowid ] = $obj -> ref ;
2019-11-13 18:32:11 +01:00
$outstandingTotal += $obj -> total_ht ;
$outstandingTotalIncTax += $obj -> total_ttc ;
2020-12-28 21:08:56 +01:00
if ( $obj -> status != 0 ) {
// Not a draft
2019-11-13 18:32:11 +01:00
$outstandingOpened += $obj -> total_ttc ;
2017-07-12 11:00:18 +02:00
}
}
2021-06-28 16:45:29 +02:00
return array ( 'opened' => $outstandingOpened , 'total_ht' => $outstandingTotal , 'total_ttc' => $outstandingTotalIncTax , 'refs' => $arrayofref ); // 'opened' is 'incl taxes'
2020-12-28 21:08:56 +01:00
} else {
return array ();
}
2013-09-27 22:12:12 +02:00
}
2017-06-07 16:44:04 +02:00
2017-01-20 14:02:51 +01:00
/**
2021-09-09 02:00:07 +02:00
* Return amount of order not yet paid and total and list of all orders
2017-01-20 14:02:51 +01:00
*
2017-01-23 20:54:52 +01:00
* @ param string $mode 'customer' or 'supplier'
2021-09-09 02:00:07 +02:00
* @ return array array ( 'opened' => Amount including tax that remains to pay , 'total_ht' => Total amount without tax of all objects paid or not , 'total_ttc' => Total amunt including tax of all object paid or not )
2017-01-20 14:02:51 +01:00
*/
2020-10-31 14:32:18 +01:00
public function getOutstandingOrders ( $mode = 'customer' )
2017-01-20 14:02:51 +01:00
{
2019-11-13 18:32:11 +01:00
$table = 'commande' ;
2020-12-28 21:08:56 +01:00
if ( $mode == 'supplier' ) {
$table = 'commande_fournisseur' ;
}
2017-07-12 11:00:18 +02:00
2021-06-28 16:45:29 +02:00
$sql = " SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM " . MAIN_DB_PREFIX . $table . " as f " ;
$sql .= " WHERE fk_soc = " . (( int ) $this -> id );
2017-07-12 11:00:18 +02:00
if ( $mode == 'supplier' ) {
$sql .= " AND entity IN ( " . getEntity ( 'supplier_order' ) . " ) " ;
} else {
$sql .= " AND entity IN ( " . getEntity ( 'commande' ) . " ) " ;
}
dol_syslog ( " getOutstandingOrders " , LOG_DEBUG );
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2017-07-12 11:00:18 +02:00
$outstandingOpened = 0 ;
$outstandingTotal = 0 ;
$outstandingTotalIncTax = 0 ;
2021-06-28 16:45:29 +02:00
$arrayofref = array ();
2019-11-13 18:32:11 +01:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2021-06-28 16:45:29 +02:00
$arrayofref [ $obj -> rowid ] = $obj -> ref ;
2019-11-13 18:32:11 +01:00
$outstandingTotal += $obj -> total_ht ;
$outstandingTotalIncTax += $obj -> total_ttc ;
2020-12-28 21:08:56 +01:00
if ( $obj -> status != 0 ) {
// Not a draft
2019-11-13 18:32:11 +01:00
$outstandingOpened += $obj -> total_ttc ;
2017-07-12 11:00:18 +02:00
}
}
2021-06-28 16:45:29 +02:00
return array ( 'opened' => $outstandingOpened , 'total_ht' => $outstandingTotal , 'total_ttc' => $outstandingTotalIncTax , 'refs' => $arrayofref ); // 'opened' is 'incl taxes'
2020-12-28 21:08:56 +01:00
} else {
return array ();
}
2017-01-20 14:02:51 +01:00
}
2017-06-07 16:44:04 +02:00
2017-01-20 14:02:51 +01:00
/**
2021-09-09 02:00:07 +02:00
* Return amount of bill not yet paid and total of all invoices
2017-01-20 14:02:51 +01:00
*
2021-09-09 02:00:07 +02:00
* @ param string $mode 'customer' or 'supplier'
2020-10-15 12:20:37 +02:00
* @ param int $late 0 => all invoice , 1 => only late
2021-09-09 02:00:07 +02:00
* @ return array array ( 'opened' => Amount including tax that remains to pay , 'total_ht' => Total amount without tax of all objects paid or not , 'total_ttc' => Total amunt including tax of all object paid or not )
2017-01-20 14:02:51 +01:00
*/
2020-10-31 14:32:18 +01:00
public function getOutstandingBills ( $mode = 'customer' , $late = 0 )
2017-01-20 14:02:51 +01:00
{
2019-11-13 18:32:11 +01:00
$table = 'facture' ;
2020-12-28 21:08:56 +01:00
if ( $mode == 'supplier' ) {
$table = 'facture_fourn' ;
}
2017-07-12 11:00:18 +02:00
/* Accurate value of remain to pay is to sum remaintopay for each invoice
$paiement = $invoice -> getSommePaiement ();
$creditnotes = $invoice -> getSumCreditNotesUsed ();
$deposits = $invoice -> getSumDepositsUsed ();
$alreadypayed = price2num ( $paiement + $creditnotes + $deposits , 'MT' );
$remaintopay = price2num ( $invoice -> total_ttc - $paiement - $creditnotes - $deposits , 'MT' );
*/
2021-06-28 16:45:29 +02:00
$sql = " SELECT rowid, ref, total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM " . MAIN_DB_PREFIX . $table . " as f " ;
2021-05-04 15:46:38 +02:00
$sql .= " WHERE fk_soc = " . (( int ) $this -> id );
2020-10-15 12:20:37 +02:00
if ( ! empty ( $late )) {
$sql .= " AND date_lim_reglement < ' " . $this -> db -> idate ( dol_now ()) . " ' " ;
}
2017-07-12 11:00:18 +02:00
if ( $mode == 'supplier' ) {
$sql .= " AND entity IN ( " . getEntity ( 'facture_fourn' ) . " ) " ;
} else {
2018-11-15 17:27:49 +01:00
$sql .= " AND entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
2017-07-12 11:00:18 +02:00
}
dol_syslog ( " getOutstandingBills " , LOG_DEBUG );
2019-11-13 18:32:11 +01:00
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2017-07-12 11:00:18 +02:00
$outstandingOpened = 0 ;
$outstandingTotal = 0 ;
$outstandingTotalIncTax = 0 ;
2021-06-28 16:45:29 +02:00
$arrayofref = array ();
2021-09-09 02:18:50 +02:00
$arrayofrefopened = array ();
2020-12-28 21:08:56 +01:00
if ( $mode == 'supplier' ) {
2017-07-12 11:00:18 +02:00
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php' ;
2019-11-13 18:32:11 +01:00
$tmpobject = new FactureFournisseur ( $this -> db );
2020-05-21 15:05:19 +02:00
} else {
2017-07-12 11:00:18 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
2019-11-13 18:32:11 +01:00
$tmpobject = new Facture ( $this -> db );
2017-07-12 11:00:18 +02:00
}
2019-11-13 18:32:11 +01:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2021-06-28 16:45:29 +02:00
$arrayofref [ $obj -> rowid ] = $obj -> ref ;
2020-10-31 14:32:18 +01:00
$tmpobject -> id = $obj -> rowid ;
2019-02-22 15:10:41 +01:00
2020-10-31 14:32:18 +01:00
if ( $obj -> status != $tmpobject :: STATUS_DRAFT // Not a draft
&& ! ( $obj -> status == $tmpobject :: STATUS_ABANDONED && $obj -> close_code == 'replaced' ) // Not a replaced invoice
2020-12-28 21:08:56 +01:00
) {
2019-11-13 18:32:11 +01:00
$outstandingTotal += $obj -> total_ht ;
$outstandingTotalIncTax += $obj -> total_ttc ;
2017-07-12 11:00:18 +02:00
}
2021-09-09 02:18:50 +02:00
$remaintopay = 0 ;
2017-07-12 11:00:18 +02:00
if ( $obj -> paye == 0
2020-02-08 11:32:38 +01:00
&& $obj -> status != $tmpobject :: STATUS_DRAFT // Not a draft
&& $obj -> status != $tmpobject :: STATUS_ABANDONED // Not abandonned
2020-12-28 21:08:56 +01:00
&& $obj -> status != $tmpobject :: STATUS_CLOSED ) { // Not classified as paid
//$sql .= " AND (status <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason
2017-07-12 11:00:18 +02:00
$paiement = $tmpobject -> getSommePaiement ();
$creditnotes = $tmpobject -> getSumCreditNotesUsed ();
$deposits = $tmpobject -> getSumDepositsUsed ();
2019-02-22 15:10:41 +01:00
2021-09-09 02:18:50 +02:00
$remaintopay = ( $obj -> total_ttc - $paiement - $creditnotes - $deposits );
$outstandingOpened += $remaintopay ;
2017-07-12 11:00:18 +02:00
}
2019-08-26 23:56:17 +02:00
2020-10-31 14:32:18 +01:00
//if credit note is converted but not used
// TODO Do this also for customer ?
2020-12-28 21:08:56 +01:00
if ( $mode == 'supplier' && $obj -> type == FactureFournisseur :: TYPE_CREDIT_NOTE && $tmpobject -> isCreditNoteUsed ()) {
2021-09-09 02:18:50 +02:00
$remainingcreditnote = $tmpobject -> getSumFromThisCreditNotesNotUsed ();
$remaintopay -= $remainingcreditnote ;
$outstandingOpened -= $remainingcreditnote ;
}
if ( $remaintopay ) {
$arrayofrefopened [ $obj -> rowid ] = $obj -> ref ;
2020-10-31 14:32:18 +01:00
}
2017-07-12 11:00:18 +02:00
}
2021-09-09 02:18:50 +02:00
return array ( 'opened' => $outstandingOpened , 'total_ht' => $outstandingTotal , 'total_ttc' => $outstandingTotalIncTax , 'refs' => $arrayofref , 'refsopened' => $arrayofrefopened ); // 'opened' is 'incl taxes'
2020-05-21 15:05:19 +02:00
} else {
2021-05-04 15:46:38 +02:00
dol_syslog ( " Sql error " . $this -> db -> lasterror , LOG_ERR );
2017-07-12 11:00:18 +02:00
return array ();
}
2017-01-20 14:02:51 +01:00
}
2017-06-07 16:44:04 +02:00
2013-02-12 19:16:48 +01:00
/**
2013-11-15 22:15:48 +01:00
* Return label of status customer is prospect / customer
2013-02-12 19:16:48 +01:00
*
2013-11-15 22:15:48 +01:00
* @ return string Label
2021-02-05 17:29:11 +01:00
* @ see getTypeUrl ()
2013-02-12 19:16:48 +01:00
*/
2020-10-31 14:32:18 +01:00
public function getLibCustProspStatut ()
2013-02-12 19:16:48 +01:00
{
2013-04-26 19:13:39 +02:00
return $this -> LibCustProspStatut ( $this -> client );
2013-02-12 19:16:48 +01:00
}
2013-03-09 16:19:15 +01:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2013-02-12 19:16:48 +01:00
/**
2019-08-29 00:45:02 +02:00
* Return the label of the customer / prospect status
2013-02-12 19:16:48 +01:00
*
2020-02-08 11:32:38 +01:00
* @ param int $status Id of prospection status
* @ return string Label of prospection status
2013-02-12 19:16:48 +01:00
*/
2020-10-31 14:32:18 +01:00
public function LibCustProspStatut ( $status )
2013-02-12 19:16:48 +01:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2013-02-12 19:16:48 +01:00
global $langs ;
2013-03-09 16:19:15 +01:00
$langs -> load ( 'companies' );
2020-12-28 21:08:56 +01:00
if ( $status == 0 ) {
return $langs -> trans ( " NorProspectNorCustomer " );
} elseif ( $status == 1 ) {
return $langs -> trans ( " Customer " );
} elseif ( $status == 2 ) {
return $langs -> trans ( " Prospect " );
} elseif ( $status == 3 ) {
return $langs -> trans ( " ProspectCustomer " );
}
2013-02-12 19:16:48 +01:00
}
2013-03-09 16:19:15 +01:00
2016-07-07 12:19:20 +02:00
2015-09-06 12:30:41 +02:00
/**
* Create a document onto disk according to template module .
*
2020-09-10 01:49:09 +02:00
* @ param string $modele Generator to use . Caller must set it to obj -> model_pdf or GETPOST ( 'model' , 'alpha' ) for example .
2015-09-06 12:30:41 +02:00
* @ param Translate $outputlangs objet lang a utiliser pour traduction
* @ param int $hidedetails Hide details of lines
* @ param int $hidedesc Hide description
* @ param int $hideref Hide ref
2016-10-05 22:24:14 +02:00
* @ param null | array $moreparams Array to provide more information
2015-09-06 12:30:41 +02:00
* @ return int < 0 if KO , > 0 if OK
*/
2019-01-27 15:20:16 +01:00
public function generateDocument ( $modele , $outputlangs , $hidedetails = 0 , $hidedesc = 0 , $hideref = 0 , $moreparams = null )
2015-09-06 12:30:41 +02:00
{
2019-11-13 18:32:11 +01:00
global $conf , $user , $langs ;
2015-09-06 12:30:41 +02:00
2020-12-28 21:08:56 +01:00
if ( ! empty ( $moreparams ) && ! empty ( $moreparams [ 'use_companybankid' ])) {
2017-10-13 13:28:26 +02:00
$modelpath = " core/modules/bank/doc/ " ;
2015-09-06 12:30:41 +02:00
2017-10-13 13:28:26 +02:00
include_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php' ;
$companybankaccount = new CompanyBankAccount ( $this -> db );
$result = $companybankaccount -> fetch ( $moreparams [ 'use_companybankid' ]);
2020-12-28 21:08:56 +01:00
if ( ! $result ) {
dol_print_error ( $this -> db , $companybankaccount -> error , $companybankaccount -> errors );
}
2019-11-13 18:32:11 +01:00
$result = $companybankaccount -> commonGenerateDocument ( $modelpath , $modele , $outputlangs , $hidedetails , $hidedesc , $hideref , $moreparams );
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
// Positionne le modele sur le nom du modele a utiliser
2020-12-28 21:08:56 +01:00
if ( ! dol_strlen ( $modele )) {
if ( ! empty ( $conf -> global -> COMPANY_ADDON_PDF )) {
2017-10-13 13:28:26 +02:00
$modele = $conf -> global -> COMPANY_ADDON_PDF ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
print $langs -> trans ( " Error " ) . " " . $langs -> trans ( " Error_COMPANY_ADDON_PDF_NotDefined " );
return 0 ;
}
}
2017-06-07 16:44:04 +02:00
2020-10-31 14:32:18 +01:00
if ( ! isset ( $this -> bank_account )) {
2020-05-26 23:22:14 +02:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php' ;
$bac = new CompanyBankAccount ( $this -> db );
$result = $bac -> fetch ( 0 , $this -> id );
if ( $result > 0 ) {
$this -> bank_account = $bac ;
} else {
$this -> bank_account = '' ;
}
}
2017-10-13 13:28:26 +02:00
$modelpath = " core/modules/societe/doc/ " ;
2017-06-07 16:44:04 +02:00
2019-11-13 18:32:11 +01:00
$result = $this -> commonGenerateDocument ( $modelpath , $modele , $outputlangs , $hidedetails , $hidedesc , $hideref , $moreparams );
2016-10-05 22:24:14 +02:00
}
2015-09-06 12:30:41 +02:00
return $result ;
}
2016-07-07 12:19:20 +02:00
2015-09-30 18:46:51 +02:00
/**
* Sets object to supplied categories .
*
* Deletes object from existing categories not supplied .
* Adds it to non existing supplied categories .
* Existing categories are left untouch .
*
2017-10-28 16:55:25 +02:00
* @ param int [] | int $categories Category ID or array of Categories IDs
2019-09-27 13:28:28 +02:00
* @ param string $type_categ Category type ( 'customer' or 'supplier' )
2017-10-28 16:55:25 +02:00
* @ return int < 0 if KO , > 0 if OK
2015-09-30 18:46:51 +02:00
*/
2019-09-27 13:28:28 +02:00
public function setCategories ( $categories , $type_categ )
2015-09-30 18:46:51 +02:00
{
2019-11-13 18:32:11 +01:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2017-06-07 16:44:04 +02:00
2017-10-13 13:28:26 +02:00
// Decode type
2019-11-13 18:32:11 +01:00
if ( ! in_array ( $type_categ , array ( Categorie :: TYPE_CUSTOMER , Categorie :: TYPE_SUPPLIER ))) {
dol_syslog ( __METHOD__ . ': Type ' . $type_categ . 'is an unknown company category type. Done nothing.' , LOG_ERR );
2017-10-28 16:55:25 +02:00
return - 1 ;
2015-09-30 18:46:51 +02:00
}
2020-12-23 23:32:50 +01:00
return parent :: setCategoriesCommon ( $categories , $type_categ );
2015-09-30 18:46:51 +02:00
}
2018-03-09 18:59:06 +01:00
/**
2018-03-22 16:05:50 +01:00
* Sets sales representatives of the thirdparty
2018-03-09 18:59:06 +01:00
*
2018-03-22 16:05:50 +01:00
* @ param int [] | int $salesrep User ID or array of user IDs
2020-08-26 09:40:20 +02:00
* @ param bool $onlyAdd Only add ( no delete before )
2018-03-09 18:59:06 +01:00
* @ return int < 0 if KO , > 0 if OK
*/
2020-08-26 09:40:20 +02:00
public function setSalesRep ( $salesrep , $onlyAdd = false )
2018-03-09 18:59:06 +01:00
{
global $user ;
2018-03-22 16:05:50 +01:00
2018-03-09 18:59:06 +01:00
// Handle single user
if ( ! is_array ( $salesrep )) {
$salesrep = array ( $salesrep );
}
2020-08-26 09:40:20 +02:00
$to_del = array (); // Nothing to delete
$to_add = $salesrep ;
if ( $onlyAdd === false ) {
// Get current users
$existing = $this -> getSalesRepresentatives ( $user , 1 );
// Diff
if ( is_array ( $existing )) {
$to_del = array_diff ( $existing , $salesrep );
$to_add = array_diff ( $salesrep , $existing );
}
2018-03-09 18:59:06 +01:00
}
$error = 0 ;
// Process
foreach ( $to_del as $del ) {
$this -> del_commercial ( $user , $del );
}
foreach ( $to_add as $add ) {
$result = $this -> add_commercial ( $user , $add );
2020-12-28 21:08:56 +01:00
if ( $result < 0 ) {
2018-03-09 18:59:06 +01:00
$error ++ ;
break ;
}
}
return $error ? - 1 : 1 ;
}
2020-12-13 19:50:35 +01:00
/**
* Define third - party type of current company
*
* @ param int $typent_id third party type rowid in llx_c_typent
* @ return int < 0 if KO , > 0 if OK
*/
public function setThirdpartyType ( $typent_id )
{
2020-12-28 21:08:56 +01:00
if ( $this -> id ) {
2020-12-13 19:50:35 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " societe " ;
$sql .= " SET fk_typent = " . ( $typent_id > 0 ? $typent_id : " null " );
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2020-12-13 19:50:35 +01:00
dol_syslog ( get_class ( $this ) . '::setThirdpartyType' , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
2020-12-28 21:08:56 +01:00
if ( $resql ) {
2020-12-13 19:50:35 +01:00
$this -> typent_id = $typent_id ;
2020-12-28 21:08:56 +01:00
$this -> typent_code = dol_getIdFromCode ( $this -> db , $this -> $typent_id , 'c_typent' , 'id' , 'code' );
2020-12-13 19:50:35 +01:00
return 1 ;
} else {
return - 1 ;
}
2020-12-28 21:08:56 +01:00
} else {
return - 1 ;
}
2020-12-13 19:50:35 +01:00
}
2015-09-30 18:46:51 +02:00
2015-04-18 18:11:01 +02:00
/**
* Function used to replace a thirdparty id with another one .
* It must be used within a transaction to avoid trouble
*
2021-11-24 23:07:06 +01:00
* @ param DoliDB $dbs Database handler , because function is static we name it $dbs not $db to avoid breaking coding test
2018-01-31 18:01:56 +01:00
* @ param int $origin_id Old thirdparty id ( will be removed )
* @ param int $dest_id New thirdparty id
* @ return bool True if success , False if error
2015-04-18 18:11:01 +02:00
*/
2021-11-24 23:07:06 +01:00
public static function replaceThirdparty ( DoliDB $dbs , $origin_id , $dest_id )
2015-04-18 18:11:01 +02:00
{
2020-12-28 21:08:56 +01:00
if ( $origin_id == $dest_id ) {
2018-01-31 18:01:56 +01:00
dol_syslog ( 'Error: Try to merge a thirdparty into itself' );
return false ;
}
2015-04-18 18:11:01 +02:00
/**
2018-01-31 18:01:56 +01:00
* Thirdparty commercials cannot be the same in both thirdparties so we look for them and remove some to avoid duplicate .
* Because this function is meant to be executed within a transaction , we won ' t take care of begin / commit .
2015-04-18 18:11:01 +02:00
*/
2016-07-26 09:01:28 +02:00
$sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . 'societe_commerciaux ' ;
$sql .= ' WHERE fk_soc = ' . ( int ) $dest_id . ' AND fk_user IN ( ' ;
2016-07-28 09:53:10 +02:00
$sql .= ' SELECT fk_user ' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe_commerciaux ' ;
$sql .= ' WHERE fk_soc = ' . ( int ) $origin_id . ') ' ;
2015-04-18 18:11:01 +02:00
2021-11-24 23:07:06 +01:00
$resql = $dbs -> query ( $sql );
while ( $obj = $dbs -> fetch_object ( $resql )) {
$dbs -> query ( 'DELETE FROM ' . MAIN_DB_PREFIX . 'societe_commerciaux WHERE rowid = ' . (( int ) $obj -> rowid ));
2015-04-18 18:11:01 +02:00
}
/**
* llx_societe_extrafields table must not be here because we don ' t care about the old thirdparty data
* Do not include llx_societe because it will be replaced later
*/
$tables = array (
'societe_address' ,
'societe_commerciaux' ,
'societe_prices' ,
'societe_remise' ,
'societe_remise_except' ,
'societe_rib'
);
2021-11-24 23:07:06 +01:00
return CommonObject :: commonReplaceThirdparty ( $dbs , $origin_id , $dest_id , $tables );
2015-04-18 18:11:01 +02:00
}
2020-12-04 04:13:42 +01:00
/**
* Sets an accountancy code for a thirdparty .
* Also calls COMPANY_MODIFY trigger when modified
*
* @ param string $type It can be only 'buy' or 'sell'
* @ param string $value Accountancy code
* @ return int < 0 KO > 0 OK
*/
public function setAccountancyCode ( $type , $value )
{
global $user , $langs , $conf ;
$this -> db -> begin ();
2021-08-27 18:18:50 +02:00
$field = 'accountancy_code_sell' ;
2020-12-04 04:13:42 +01:00
if ( $type == 'buy' ) {
$field = 'accountancy_code_buy' ;
} elseif ( $type == 'sell' ) {
$field = 'accountancy_code_sell' ;
} else {
return - 1 ;
}
$sql = " UPDATE " . MAIN_DB_PREFIX . $this -> table_element . " SET " ;
2021-10-25 22:07:31 +02:00
$sql .= $field . " = ' " . $this -> db -> escape ( $value ) . " ' " ;
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2020-12-04 04:13:42 +01:00
2021-08-27 22:42:04 +02:00
dol_syslog ( get_class ( $this ) . " :: " . __FUNCTION__ . " " , LOG_DEBUG );
2020-12-04 04:13:42 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
// Call triggers
2021-10-25 22:07:31 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
$interface = new Interfaces ( $this -> db );
$result = $interface -> run_triggers ( 'COMPANY_MODIFY' , $this , $user , $langs , $conf );
2020-12-04 04:13:42 +01:00
if ( $result < 0 ) {
2021-10-25 22:07:31 +02:00
$this -> errors = $interface -> errors ;
2020-12-04 04:13:42 +01:00
$this -> db -> rollback ();
return - 1 ;
}
// End call triggers
$this -> $field = $value ;
$this -> db -> commit ();
return 1 ;
2021-02-26 21:17:52 +01:00
} else {
2021-10-25 22:07:31 +02:00
$this -> error = $this -> db -> lasterror ();
2020-12-04 04:13:42 +01:00
$this -> db -> rollback ();
return - 1 ;
}
}
2021-06-09 23:48:28 +02:00
/**
* Function to get partnerships array
*
* @ param string $mode 'member' or 'thirdparty'
* @ return int < 0 if KO , > 0 if OK
*/
public function fetchPartnerships ( $mode )
{
global $langs ;
2022-01-19 21:18:49 +01:00
require_once DOL_DOCUMENT_ROOT . '/partnership/class/partnership.class.php' ;
2021-06-09 23:48:28 +02:00
$this -> partnerships [] = array ();
return 1 ;
}
2013-04-26 20:54:53 +02:00
}