45require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/class/commonsocialnetworks.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
50require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
66 public $TRIGGER_PREFIX =
'COMPANY';
71 public $module =
'societe';
76 public $element =
'societe';
81 public $table_element =
'societe';
86 public $fk_element =
'fk_soc';
91 public $fieldsforcombobox =
'nom,name_alias';
96 protected $childtables = array(
97 'supplier_proposal' => array(
'name' =>
'SupplierProposal'),
98 'propal' => array(
'name' =>
'Proposal'),
99 'commande' => array(
'name' =>
'Order'),
100 'facture' => array(
'name' =>
'Invoice'),
101 'facture_rec' => array(
'name' =>
'RecurringInvoiceTemplate'),
102 'contrat' => array(
'name' =>
'Contract'),
103 'fichinter' => array(
'name' =>
'Fichinter'),
104 'facture_fourn' => array(
'name' =>
'SupplierInvoice'),
105 'commande_fournisseur' => array(
'name' =>
'SupplierOrder'),
106 'projet' => array(
'name' =>
'Project'),
107 'expedition' => array(
'name' =>
'Shipment'),
108 'prelevement_lignes' => array(
'name' =>
'DirectDebitRecord'),
109 'adherent' => array(
'name' =>
'Member')
116 protected $childtablesoncascade = array(
118 'product_fournisseur_price',
119 'product_customer_price_log',
120 'product_customer_price',
121 '@Contact:/contact/class/contact.class.php:fk_soc',
126 'societe_remise_except',
127 'societe_commerciaux',
137 public $picto =
'company';
143 public $restrictiononfksoc = 1;
149 public $SupplierCategories = array();
155 public $prefixCustomerIsRequired;
186 public $fields = array(
187 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'noteditable' => 1,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id',
'css' =>
'left'),
188 'parent' => array(
'type' =>
'integer',
'label' =>
'Parent',
'enabled' => 1,
'visible' => -1,
'position' => 20),
189 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 25),
190 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 30),
191 'nom' => array(
'type' =>
'varchar(128)',
'length' => 128,
'label' =>
'Nom',
'enabled' => 1,
'visible' => -1,
'position' => 35,
'showoncombobox' => 1,
'csslist' =>
'tdoverflowmax150'),
192 'name_alias' => array(
'type' =>
'varchar(128)',
'label' =>
'Name alias',
'enabled' => 1,
'visible' => -1,
'position' => 36,
'showoncombobox' => 2),
193 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 40,
'index' => 1),
194 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 45),
195 'code_client' => array(
'type' =>
'varchar(24)',
'label' =>
'CustomerCode',
'enabled' => 1,
'visible' => -1,
'position' => 55),
196 'code_fournisseur' => array(
'type' =>
'varchar(24)',
'label' =>
'SupplierCode',
'enabled' => 1,
'visible' => -1,
'position' => 60),
197 'code_compta' => array(
'type' =>
'varchar(24)',
'label' =>
'CustomerAccountancyCode',
'enabled' => 1,
'visible' => -1,
'position' => 65),
198 'code_compta_fournisseur' => array(
'type' =>
'varchar(24)',
'label' =>
'SupplierAccountancyCode',
'enabled' => 1,
'visible' => -1,
'position' => 70),
199 'address' => array(
'type' =>
'varchar(255)',
'label' =>
'Address',
'enabled' => 1,
'visible' => -1,
'position' => 75),
200 'zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Zip',
'enabled' => 1,
'visible' => -1,
'position' => 80),
201 'town' => array(
'type' =>
'varchar(50)',
'label' =>
'Town',
'enabled' => 1,
'visible' => -1,
'position' => 85),
202 'fk_departement' => array(
'type' =>
'integer',
'label' =>
'State',
'enabled' => 1,
'visible' => -1,
'position' => 90),
203 'fk_pays' => array(
'type' =>
'integer:Ccountry:core/class/ccountry.class.php',
'label' =>
'Country',
'enabled' => 1,
'visible' => -1,
'position' => 95),
204 'phone' => array(
'type' =>
'varchar(20)',
'label' =>
'Phone',
'enabled' => 1,
'visible' => -1,
'position' => 100),
205 'phone_mobile' => array(
'type' =>
'varchar(20)',
'label' =>
'PhoneMobile',
'enabled' => 1,
'visible' => -1,
'position' => 102),
206 'fax' => array(
'type' =>
'varchar(20)',
'label' =>
'Fax',
'enabled' => 1,
'visible' => -1,
'position' => 105),
207 'url' => array(
'type' =>
'varchar(255)',
'label' =>
'Url',
'enabled' => 1,
'visible' => -1,
'position' => 110),
208 'email' => array(
'type' =>
'varchar(128)',
'label' =>
'Email',
'enabled' => 1,
'visible' => -1,
'position' => 115),
209 'socialnetworks' => array(
'type' =>
'text',
'label' =>
'Socialnetworks',
'enabled' => 1,
'visible' => -1,
'position' => 120),
210 'fk_effectif' => array(
'type' =>
'integer',
'label' =>
'Workforce',
'enabled' => 1,
'visible' => -1,
'position' => 170),
211 'fk_typent' => array(
'type' =>
'integer',
'label' =>
'ThirdPartyType',
'enabled' => 1,
'visible' => -1,
'position' => 175,
'csslist' =>
'minwidth200'),
212 'fk_forme_juridique' => array(
'type' =>
'integer',
'label' =>
'JuridicalStatus',
'enabled' => 1,
'visible' => -1,
'position' => 180),
213 'birth' => array(
'type' =>
'date',
'label' =>
'CompanyBirthDate',
'enabled' => 1,
'visible' => -1,
'position' => 182),
214 'fk_currency' => array(
'type' =>
'varchar(3)',
'label' =>
'Currency',
'enabled' => 1,
'visible' => -1,
'position' => 185),
215 'siren' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof1',
'enabled' => 1,
'visible' => -1,
'position' => 190),
216 'siret' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof2',
'enabled' => 1,
'visible' => -1,
'position' => 195),
217 'ape' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof3',
'enabled' => 1,
'visible' => -1,
'position' => 200),
218 'idprof4' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof4',
'enabled' => 1,
'visible' => -1,
'position' => 205),
219 'idprof5' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof5',
'enabled' => 1,
'visible' => -1,
'position' => 206),
220 'idprof6' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof6',
'enabled' => 1,
'visible' => -1,
'position' => 207),
221 'tva_intra' => array(
'type' =>
'varchar(20)',
'label' =>
'VATIntra',
'enabled' => 1,
'visible' => -1,
'position' => 210),
222 'euid' => array(
'type' =>
'varchar(20)',
'label' =>
'EUIDShort',
'enabled' => 1,
'visible' => -1,
'position' => 213),
223 'capital' => array(
'type' =>
'double(24,8)',
'label' =>
'Capital',
'enabled' => 1,
'visible' => -1,
'position' => 215),
224 'fk_stcomm' => array(
'type' =>
'integer',
'label' =>
'CommercialStatus',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 220),
225 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 225),
226 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 230),
227 'client' => array(
'type' =>
'tinyint(4)',
'label' =>
'Customer',
'enabled' => 1,
'visible' => -1,
'position' => 240),
228 'fournisseur' => array(
'type' =>
'tinyint(4)',
'label' =>
'Supplier',
'enabled' => 1,
'visible' => -1,
'position' => 245),
229 'supplier_account' => array(
'type' =>
'varchar(32)',
'label' =>
'Supplier account',
'enabled' => 1,
'visible' => -1,
'position' => 250),
230 'fk_prospectlevel' => array(
'type' =>
'varchar(12)',
'label' =>
'ProspectLevel',
'enabled' => 1,
'visible' => -1,
'position' => 255),
231 'customer_bad' => array(
'type' =>
'tinyint(4)',
'label' =>
'Customer bad',
'enabled' => 1,
'visible' => -1,
'position' => 260),
232 'customer_rate' => array(
'type' =>
'double',
'label' =>
'Customer rate',
'enabled' => 1,
'visible' => -1,
'position' => 265),
233 'supplier_rate' => array(
'type' =>
'double',
'label' =>
'Supplier rate',
'enabled' => 1,
'visible' => -1,
'position' => 270),
234 'fk_user_creat' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -2,
'position' => 275),
235 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 280),
238 'mode_reglement' => array(
'type' =>
'smallint(6)',
'label' =>
'Mode reglement',
'enabled' => 1,
'visible' => -1,
'position' => 295),
239 'cond_reglement' => array(
'type' =>
'tinyint(4)',
'label' =>
'Cond reglement',
'enabled' => 1,
'visible' => -1,
'position' => 300),
240 'deposit_percent' => array(
'type' =>
'varchar(63)',
'label' =>
'DepositPercent',
'enabled' => 1,
'visible' => -1,
'position' => 301),
241 'mode_reglement_supplier' => array(
'type' =>
'integer',
'label' =>
'Mode reglement supplier',
'enabled' => 1,
'visible' => -1,
'position' => 305),
242 'cond_reglement_supplier' => array(
'type' =>
'integer',
'label' =>
'Cond reglement supplier',
'enabled' => 1,
'visible' => -1,
'position' => 308),
243 'outstanding_limit' => array(
'type' =>
'double(24,8)',
'label' =>
'OutstandingBill',
'enabled' => 1,
'visible' => -1,
'position' => 310,
'isameasure' => 1),
244 'order_min_amount' => array(
'type' =>
'double(24,8)',
'label' =>
'Order min amount',
'enabled' =>
'isModEnabled("order") && getDolGlobalInt("ORDER_MANAGE_MIN_AMOUNT")',
'visible' => -1,
'position' => 315,
'isameasure' => 1),
245 'supplier_order_min_amount' => array(
'type' =>
'double(24,8)',
'label' =>
'Supplier order min amount',
'enabled' =>
'isModEnabled("order") && getDolGlobalInt("ORDER_MANAGE_MIN_AMOUNT")',
'visible' => -1,
'position' => 320,
'isameasure' => 1),
246 'fk_shipping_method' => array(
'type' =>
'integer',
'label' =>
'ShippingMode',
'enabled' => 1,
'visible' => -1,
'position' => 330),
247 'tva_assuj' => array(
'type' =>
'tinyint(4)',
'label' =>
'VATIsUsed',
'enabled' => 1,
'visible' => -1,
'position' => 335),
248 'localtax1_assuj' => array(
'type' =>
'tinyint(4)',
'label' =>
'LocalTax1IsUsed',
'enabled' => 1,
'visible' => -1,
'position' => 340),
249 'localtax1_value' => array(
'type' =>
'double(6,3)',
'label' =>
'LocalTax1 value',
'enabled' => 1,
'visible' => -1,
'position' => 345),
250 'localtax2_assuj' => array(
'type' =>
'tinyint(4)',
'label' =>
'LocalTax2IsUsed',
'enabled' => 1,
'visible' => -1,
'position' => 350),
251 'localtax2_value' => array(
'type' =>
'double(6,3)',
'label' =>
'LocalTax2 value',
'enabled' => 1,
'visible' => -1,
'position' => 355),
252 'vat_reverse_charge' => array(
'type' =>
'tinyint(4)',
'label' =>
'Vat reverse charge',
'enabled' => 1,
'visible' => -1,
'position' => 335),
253 'barcode' => array(
'type' =>
'varchar(255)',
'label' =>
'Barcode',
'enabled' => 1,
'visible' => -1,
'position' => 360),
254 'price_level' => array(
'type' =>
'integer',
'label' =>
'Price level',
'enabled' =>
'getDolGlobalString("PRODUIT_MULTIPRICES") || getDolGlobalString("PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES") || getDolGlobalString("PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES")',
'visible' => -1,
'position' => 365),
255 'default_lang' => array(
'type' =>
'varchar(6)',
'label' =>
'Default lang',
'enabled' => 1,
'visible' => -1,
'position' => 370),
256 'canvas' => array(
'type' =>
'varchar(32)',
'label' =>
'Canvas',
'enabled' => 1,
'visible' => -1,
'position' => 375),
257 'fk_barcode_type' => array(
'type' =>
'integer',
'label' =>
'Fk barcode type',
'enabled' => 1,
'visible' => -1,
'position' => 405),
258 'webservices_url' => array(
'type' =>
'varchar(255)',
'label' =>
'Webservices url',
'enabled' => 1,
'visible' => -1,
'position' => 410),
259 'webservices_key' => array(
'type' =>
'varchar(128)',
'label' =>
'Webservices key',
'enabled' => 1,
'visible' => -1,
'position' => 415),
260 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'Fk incoterms',
'enabled' => 1,
'visible' => -1,
'position' => 425),
261 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'Location incoterms',
'enabled' => 1,
'visible' => -1,
'position' => 430),
262 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 435),
263 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -1,
'position' => 270),
264 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Fk multicurrency',
'enabled' => 1,
'visible' => -1,
'position' => 440),
265 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Multicurrency code',
'enabled' => 1,
'visible' => -1,
'position' => 445),
266 'fk_account' => array(
'type' =>
'integer',
'label' =>
'PaymentBankAccount',
'enabled' => 1,
'visible' => -1,
'position' => 450),
267 'fk_warehouse' => array(
'type' =>
'integer',
'label' =>
'Warehouse',
'enabled' => 1,
'visible' => -1,
'position' => 455),
268 'logo' => array(
'type' =>
'varchar(255)',
'label' =>
'Logo',
'enabled' => 1,
'visible' => -1,
'position' => 400),
269 'logo_squarred' => array(
'type' =>
'varchar(255)',
'label' =>
'Logo squarred',
'enabled' => 1,
'visible' => -1,
'position' => 401),
270 'status' => array(
'type' =>
'tinyint(4)',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'position' => 500),
271 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 1000),
324 public $departement_code;
349 public $phone_mobile;
496 public $socialobject;
506 public $tva_assuj = 1;
521 public $vat_reverse_charge = 0;
527 public $localtax1_assuj;
531 public $localtax1_value;
535 public $localtax2_assuj;
539 public $localtax2_value;
554 public $typent_id = 0;
569 public $effectif_id = 0;
573 public $forme_juridique_code = 0;
578 public $forme_juridique;
587 public $remise_percent;
591 public $remise_supplier_percent;
596 public $mode_reglement_id;
600 public $cond_reglement_id;
604 public $deposit_percent;
608 public $mode_reglement_supplier_id;
612 public $cond_reglement_supplier_id;
616 public $transport_mode_supplier_id;
621 public $fk_prospectlevel;
633 public $user_modification;
640 public $user_creation;
652 public $prospect = 0;
670 public $code_fournisseur;
676 public $code_compta_client;
682 public $accountancy_code_customer_general;
688 public $accountancy_code_customer;
694 public $code_compta_fournisseur;
700 public $accountancy_code_supplier_general;
706 public $accountancy_code_supplier;
712 public $code_compta_product;
725 public $note_private;
743 public $stcomm_picto;
749 public $status_prospect_label;
760 public $outstanding_limit;
765 public $order_min_amount;
770 public $supplier_order_min_amount;
776 public $commercial_id;
788 public $default_lang;
819 public $webservices_url;
825 public $webservices_key;
845 public $logo_squarred;
850 public $logo_squarred_small;
855 public $logo_squarred_mini;
860 public $accountancy_code_sell;
865 public $accountancy_code_buy;
870 public $currency_code;
876 public $fk_multicurrency;
881 public $multicurrency_code;
887 public $fk_warehouse;
900 public $partnerships = array();
906 public $bank_account;
916 const STATUS_CEASED = 0;
917 const STATUS_INACTIVITY = 1;
958 'code_compta' =>
'code_compta_client',
960 + parent::deprecatedProperties();
974 $this->ismultientitymanaged = 1;
975 $this->isextrafieldmanaged = 1;
978 $this->fournisseur = 0;
979 $this->typent_id = 0;
980 $this->effectif_id = 0;
981 $this->forme_juridique_code = 0;
982 $this->tva_assuj = 1;
983 $this->vat_reverse_charge = 0;
987 $this->fields[
'address'][
'showoncombobox'] =
getDolGlobalInt(
'COMPANY_SHOW_ADDRESS_SELECTLIST');
988 $this->fields[
'zip'][
'showoncombobox'] =
getDolGlobalInt(
'COMPANY_SHOW_ADDRESS_SELECTLIST');
989 $this->fields[
'town'][
'showoncombobox'] =
getDolGlobalInt(
'COMPANY_SHOW_ADDRESS_SELECTLIST');
1005 global $langs,
$conf;
1010 if (empty($this->
status)) {
1013 $this->
name = $this->
name ? trim($this->
name) : trim((
string) $this->nom);
1015 $this->nom = $this->name;
1017 if (empty($this->client)) {
1020 if (empty($this->fournisseur)) {
1021 $this->fournisseur = 0;
1023 $this->import_key = trim((
string) $this->import_key);
1025 $this->code_compta_client = trim($this->code_compta_client ??
'');
1027 $this->accountancy_code_customer_general = trim($this->accountancy_code_customer_general ??
'');
1028 if ($this->accountancy_code_customer_general ===
'-1') {
1029 $this->accountancy_code_customer_general =
'';
1031 $this->accountancy_code_customer = trim((
string) $this->code_compta_client);
1032 $this->accountancy_code_supplier_general = trim($this->accountancy_code_supplier_general ??
'');
1033 if ($this->accountancy_code_supplier_general ===
'-1') {
1034 $this->accountancy_code_supplier_general =
'';
1036 $this->accountancy_code_supplier = trim((
string) $this->code_compta_fournisseur);
1037 $this->accountancy_code_buy = trim((
string) $this->accountancy_code_buy);
1038 $this->accountancy_code_sell = trim((
string) $this->accountancy_code_sell);
1040 if (!empty($this->multicurrency_code)) {
1043 if (empty($this->fk_multicurrency)) {
1044 $this->multicurrency_code =
'';
1045 $this->fk_multicurrency = 0;
1052 if (empty($this->date_creation)) {
1053 $this->date_creation = $now;
1059 if ($this->code_client == -1 || $this->code_client ===
'auto') {
1060 $this->get_codeclient($this, 0);
1062 if ($this->code_fournisseur ==
'-1' || $this->code_fournisseur ===
'auto') {
1063 $this->get_codefournisseur($this, 1);
1068 $result = $this->
verify();
1073 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe (";
1075 $sql .=
", name_alias";
1078 $sql .=
", fk_user_creat";
1079 $sql .=
", fk_typent";
1082 $sql .=
", ref_ext";
1083 $sql .=
", fk_stcomm";
1084 $sql .=
", fk_incoterms";
1085 $sql .=
", location_incoterms";
1086 $sql .=
", import_key";
1087 $sql .=
", fk_multicurrency";
1088 $sql .=
", multicurrency_code";
1091 $sql .=
", vat_reverse_charge";
1092 $sql .=
", accountancy_code_buy";
1093 $sql .=
", accountancy_code_sell";
1095 $sql .=
") VALUES ('".$this->db->escape($this->name).
"',";
1096 $sql .=
" '".$this->db->escape($this->name_alias).
"',";
1097 $sql .=
" ".((int) $this->entity).
",";
1098 $sql .=
" '".$this->db->idate($this->date_creation).
"'";
1099 $sql .=
", ".(!empty($user->id) ? ((int) $user->id) :
"null");
1100 $sql .=
", ".(!empty($this->typent_id) ? ((int) $this->typent_id) :
"null");
1101 $sql .=
", ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null");
1102 $sql .=
", ".((int) $this->
status);
1103 $sql .=
", ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1105 $sql .=
", ".(int) $this->fk_incoterms;
1106 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1107 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1108 $sql .=
", ".(int) $this->fk_multicurrency;
1109 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1110 $sql .=
", ".(empty($this->ip) ?
"null" :
"'".$this->db->escape($this->ip).
"'");
1112 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1113 $sql .=
", '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1114 $sql .=
", '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1118 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1120 $result = $this->db->query($sql);
1122 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"societe");
1124 $ret = $this->
update($this->
id, $user, 0, 1, 1,
'add');
1127 if ($this->commercial_id !=
'' && $this->commercial_id != -1) {
1129 } elseif (!$user->hasRight(
'societe',
'client',
'voir')) {
1137 $result = $this->call_trigger(
'COMPANY_CREATE', $user);
1148 dol_syslog(get_class($this).
"::Create success id=".$this->
id);
1149 $this->db->commit();
1152 dol_syslog(get_class($this).
"::Create echec update ".$this->error.(empty($this->errors) ?
'' :
' '.implode(
',', $this->errors)), LOG_ERR);
1153 $this->db->rollback();
1157 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1158 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", $this->name);
1161 $this->error = $this->db->lasterror();
1164 $this->db->rollback();
1168 $this->db->rollback();
1169 dol_syslog(get_class($this).
"::Create fails verify ".implode(
',', $this->errors), LOG_WARNING);
1192 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1193 $contact =
new Contact($this->db);
1195 $contact->name = $this->name_bis;
1196 $contact->firstname = $this->firstname;
1197 $contact->civility_id = $this->civility_id;
1198 $contact->socid = $this->id;
1199 $contact->statut = 1;
1200 $contact->status = 1;
1202 $contact->country_id = $this->country_id;
1203 $contact->state_id = $this->state_id;
1204 $contact->address = $this->address;
1205 $contact->email = $this->email;
1206 $contact->zip = $this->zip;
1207 $contact->town = $this->town;
1209 $contact->phone_pro = $this->phone;
1214 $contactId = $contact->create($user, $notrigger);
1215 if ($contactId < 0) {
1218 dol_syslog(get_class($this).
"::create_individual ERROR:".$this->error, LOG_ERR);
1221 if (empty($error) && is_array($tags) && !empty($tags)) {
1222 $result = $contact->setCategories($tags);
1226 dol_syslog(get_class($this).
"::create_individual Affect Tag ERROR:".$this->error, LOG_ERR);
1227 $contactId = $result;
1231 if (empty($error) &&
isModEnabled(
'mailing') && !empty($contact->email) && isset($no_email)) {
1232 $result = $contact->setNoEmail($no_email);
1235 dol_syslog(get_class($this).
"::create_individual set mailing status ERROR:".$this->error, LOG_ERR);
1236 $contactId = $result;
1240 if (empty($error)) {
1241 dol_syslog(get_class($this).
"::create_individual success");
1242 $this->db->commit();
1244 $this->db->rollback();
1261 $this->errors = array();
1265 $this->nom = $this->name;
1268 $this->errors[] =
'ErrorBadThirdPartyName';
1272 if ($this->client) {
1274 if ($rescode != 0 && $rescode != -5) {
1275 if ($rescode == -1) {
1276 $this->errors[] =
'ErrorBadCustomerCodeSyntax';
1277 } elseif ($rescode == -2) {
1278 $this->errors[] =
'ErrorCustomerCodeRequired';
1279 } elseif ($rescode == -3) {
1280 $this->errors[] =
'ErrorCustomerCodeAlreadyUsed';
1281 } elseif ($rescode == -4) {
1282 $this->errors[] =
'ErrorPrefixRequired';
1284 $this->errors[] =
'ErrorUnknownOnCustomerCodeCheck';
1291 if ($this->fournisseur) {
1293 if ($rescode != 0 && $rescode != -5) {
1294 if ($rescode == -1) {
1295 $this->errors[] =
'ErrorBadSupplierCodeSyntax';
1296 } elseif ($rescode == -2) {
1297 $this->errors[] =
'ErrorSupplierCodeRequired';
1298 } elseif ($rescode == -3) {
1299 $this->errors[] =
'ErrorSupplierCodeAlreadyUsed';
1300 } elseif ($rescode == -4) {
1301 $this->errors[] =
'ErrorPrefixRequired';
1303 $this->errors[] =
'ErrorUnknownOnSupplierCodeCheck';
1310 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL',
'TVA_INTRA',
'EUID',
'ACCOUNTANCY_CODE_CUSTOMER',
'ACCOUNTANCY_CODE_SUPPLIER');
1311 foreach ($array_to_check as $key) {
1312 $keymin = strtolower($key);
1313 $keyfield_db = $keymin;
1314 if ($key ==
'ACCOUNTANCY_CODE_CUSTOMER') {
1315 $keymin =
'code_compta_client';
1316 $keyfield_db =
'code_compta';
1317 } elseif ($key ==
'ACCOUNTANCY_CODE_SUPPLIER') {
1318 $keymin =
'code_compta_fournisseur';
1319 $keyfield_db =
'code_compta_fournisseur';
1321 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
1322 $vallabel = $this->$keymin;
1327 if ($mysoc->country_id > 0 && $this->country_id ==
$mysoc->country_id) {
1328 $idprof_mandatory =
'SOCIETE_'.$key.
'_MANDATORY';
1330 $langs->load(
"errors");
1332 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->transcountry(
'ProfId'.$i, $this->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1339 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1340 $langs->load(
"errors");
1342 $this->errors[] = $langs->transcountry(
'ProfId'.$i, $this->country_code).
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1346 if ($key ==
'EMAIL') {
1349 $langs->load(
"errors");
1351 $this->errors[] = $langs->trans(
"ErrorBadEMail", $this->
email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1356 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1357 $langs->load(
"errors");
1359 $this->errors[] = $langs->trans(
'Email').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1362 } elseif ($key ==
'TVA_INTRA') {
1365 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1366 $langs->load(
"errors");
1368 $this->errors[] = $langs->trans(
'VATIntra').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1371 if ($this->tva_assuj && !$vallabel &&
getDolGlobalString(
'SOCIETE_VAT_INTRA_MANDATORY')) {
1372 $langs->load(
"errors");
1374 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->trans(
'VATIntra')).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1376 } elseif ($key ==
'EUID') {
1379 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1380 $langs->load(
"errors");
1382 $this->errors[] = $langs->trans(
'EUIDShort').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1387 if (
getDolGlobalString(
'SOCIETE_EUID_MANDATORY') && (!isset($vallabel) || trim($vallabel) ===
'')) {
1388 $langs->load(
"errors");
1390 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->trans(
'EUIDShort')).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1392 } elseif ($key ==
'ACCOUNTANCY_CODE_CUSTOMER' && !empty($this->client)) {
1395 if ($this->
id_prof_exists($keyfield_db, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1396 $langs->loadLangs(array(
"errors",
'compta'));
1398 $this->errors[] = $langs->trans(
'CustomerAccountancyCodeShort') .
" " . $langs->trans(
"ErrorProdIdAlreadyExist", $vallabel) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1403 if (
getDolGlobalString(
'SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_MANDATORY') && (!isset($vallabel) || trim($vallabel) ===
'')) {
1404 $langs->loadLangs(array(
"errors",
'compta'));
1406 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
'CustomerAccountancyCodeShort')) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1408 } elseif ($key ==
'ACCOUNTANCY_CODE_SUPPLIER' && !empty($this->fournisseur)) {
1411 if ($this->
id_prof_exists($keyfield_db, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1412 $langs->loadLangs(array(
"errors",
'compta'));
1414 $this->errors[] = $langs->trans(
'SupplierAccountancyCodeShort') .
" " . $langs->trans(
"ErrorProdIdAlreadyExist", $vallabel) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1419 if (
getDolGlobalString(
'SOCIETE_ACCOUNTANCY_CODE_SUPPLIER_MANDATORY') && (!isset($vallabel) || trim($vallabel) ===
'')) {
1420 $langs->loadLangs(array(
"errors",
'compta'));
1422 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
'SupplierAccountancyCodeShort')) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1447 public function update($id,
User $user, $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action =
'update', $nosyncmember = 1)
1449 global $langs,
$conf, $hookmanager;
1451 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1456 if (empty($this->country_id) && !empty($this->country_code)) {
1457 $this->country_id =
dol_getIdFromCode($this->db, $this->country_code,
'c_country',
'code',
'rowid');
1460 if (empty($this->country_id) && !empty($this->country_code)) {
1461 $country_id =
getCountry($this->country_code,
'3');
1462 $this->country_id = is_int($country_id) ? $country_id : 0;
1467 dol_syslog(get_class($this).
"::Update id=".$id.
" call_trigger=".$call_trigger.
" allowmodcodeclient=".$allowmodcodeclient.
" allowmodcodefournisseur=".$allowmodcodefournisseur);
1473 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity :
$conf->entity);
1474 $this->
name = $this->
name ? trim($this->
name) : trim((
string) $this->nom);
1475 $this->nom = $this->name;
1476 $this->name_alias = trim((
string) $this->name_alias);
1477 $this->ref_ext = (empty($this->ref_ext) ?
'' : trim($this->ref_ext));
1479 $this->zip = trim((
string) $this->zip);
1480 $this->town = trim((
string) $this->town);
1481 $this->state_id = (is_numeric($this->state_id)) ? (
int) $this->state_id : 0;
1482 $this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
1483 $this->phone = trim((
string) $this->phone);
1484 $this->phone = preg_replace(
"/\s/",
"", $this->phone);
1485 $this->phone = preg_replace(
"/\./",
"", $this->phone);
1486 $this->phone_mobile = trim((
string) $this->phone_mobile);
1487 $this->phone_mobile = preg_replace(
"/\s/",
"", $this->phone_mobile);
1488 $this->phone_mobile = preg_replace(
"/\./",
"", $this->phone_mobile);
1489 $this->fax = trim((
string) $this->fax);
1490 $this->fax = preg_replace(
"/\s/",
"", $this->fax);
1491 $this->fax = preg_replace(
"/\./",
"", $this->fax);
1493 $this->url = $this->url ?
clean_url($this->url, 0) :
'';
1494 $this->note_private = (empty($this->note_private) ?
'' : trim($this->note_private));
1495 $this->note_public = (empty($this->note_public) ?
'' : trim($this->note_public));
1496 $this->idprof1 = trim((
string) $this->idprof1);
1497 $this->idprof2 = trim((
string) $this->idprof2);
1498 $this->idprof3 = trim((
string) $this->idprof3);
1499 $this->idprof4 = trim((
string) $this->idprof4);
1500 $this->idprof5 = (!empty($this->idprof5) ? trim($this->idprof5) :
'');
1501 $this->idprof6 = (!empty($this->idprof6) ? trim($this->idprof6) :
'');
1502 $this->prefix_comm = trim((
string) $this->prefix_comm);
1503 $this->outstanding_limit =
price2num($this->outstanding_limit);
1504 $this->order_min_amount =
price2num($this->order_min_amount);
1505 $this->supplier_order_min_amount =
price2num($this->supplier_order_min_amount);
1506 $this->tva_assuj = (is_numeric($this->tva_assuj)) ? (
int) trim((
string) $this->tva_assuj) : 0;
1507 $this->tva_intra = trim((
string) $this->tva_intra);
1508 $this->vat_reverse_charge = empty($this->vat_reverse_charge) ? 0 : 1;
1509 $this->euid = trim((
string) $this->euid);
1511 if (empty($this->
status)) {
1515 if (!empty($this->multicurrency_code)) {
1518 if (empty($this->fk_multicurrency)) {
1519 $this->multicurrency_code =
'';
1520 $this->fk_multicurrency = 0;
1524 $this->localtax1_assuj = (int) trim((
string) $this->localtax1_assuj);
1525 $this->localtax2_assuj = (int) trim((
string) $this->localtax2_assuj);
1527 $this->localtax1_value = trim($this->localtax1_value);
1528 $this->localtax2_value = trim($this->localtax2_value);
1530 $this->capital = (!is_null($this->capital) && (
string) $this->capital !=
'') ? (float)
price2num(trim((
string) $this->capital)) :
null;
1532 $this->effectif_id = (int) $this->effectif_id;
1533 $this->forme_juridique_code = (int) $this->forme_juridique_code;
1536 $this->barcode = trim((
string) $this->barcode);
1539 if ($this->code_client == -1 || $this->code_client ===
'auto') {
1540 $this->get_codeclient($this, 0);
1542 if ($this->code_fournisseur ==
'-1' || $this->code_fournisseur ===
'auto') {
1543 $this->get_codefournisseur($this, 1);
1546 $this->accountancy_code_customer_general = trim((
string) $this->accountancy_code_customer_general);
1547 if ($this->accountancy_code_customer_general ===
'-1') {
1548 $this->accountancy_code_customer_general =
'';
1550 $this->code_compta_client = trim((
string) $this->code_compta_client);
1551 $this->accountancy_code_supplier_general = trim((
string) $this->accountancy_code_supplier_general);
1552 if ($this->accountancy_code_supplier_general ===
'-1') {
1553 $this->accountancy_code_supplier_general =
'';
1555 $this->code_compta_fournisseur = trim((
string) $this->code_compta_fournisseur);
1558 if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) {
1559 $langs->load(
"errors");
1560 $this->error = $langs->trans(
"BadValueForParameterClientOrSupplier");
1565 if (!empty($allowmodcodeclient) && !empty($this->client)) {
1567 if (empty($this->code_compta_client)) {
1578 if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) {
1580 if (empty($this->code_compta_fournisseur)) {
1591 $this->webservices_url = empty($this->webservices_url) ?
'' :
clean_url($this->webservices_url, 0);
1592 $this->webservices_key = trim((
string) $this->webservices_key);
1594 $this->accountancy_code_buy = (empty($this->accountancy_code_buy) ?
'' : trim($this->accountancy_code_buy));
1595 $this->accountancy_code_sell = (empty($this->accountancy_code_sell) ?
'' : trim($this->accountancy_code_sell));
1598 $this->fk_incoterms = (int) $this->fk_incoterms;
1599 $this->location_incoterms = trim((
string) $this->location_incoterms);
1606 if ($action !=
'add' && $action !=
'merge') {
1609 $result = $this->
verify();
1613 if (is_array($this->errors)) {
1614 if (in_array(
'ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) {
1615 if (($key = array_search(
'ErrorBadCustomerCodeSyntax', $this->errors)) !==
false) {
1616 unset($this->errors[$key]);
1619 if (in_array(
'ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) {
1620 if (($key = array_search(
'ErrorBadSupplierCodeSyntax', $this->errors)) !==
false) {
1621 unset($this->errors[$key]);
1624 if (empty($this->errors)) {
1631 dol_syslog(get_class($this).
"::update verify ok or not done");
1633 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe SET ";
1634 $sql .=
"entity = ".((int) $this->entity);
1635 $sql .=
",nom = '".$this->db->escape($this->
name).
"'";
1636 $sql .=
",name_alias = '".$this->db->escape($this->name_alias).
"'";
1637 $sql .=
",ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1638 $sql .=
",address = '".$this->db->escape($this->address).
"'";
1640 $sql .=
",zip = ".(!empty($this->zip) ?
"'".$this->db->escape($this->zip).
"'" :
"null");
1641 $sql .=
",town = ".(!empty($this->town) ?
"'".$this->db->escape($this->town).
"'" :
"null");
1643 $sql .=
",fk_departement = ".((!empty($this->state_id) && $this->state_id > 0) ? ((
int) $this->state_id) :
'null');
1644 $sql .=
",fk_pays = ".((!empty($this->country_id) && $this->country_id > 0) ? ((
int) $this->country_id) :
'null');
1646 $sql .=
",phone = ".(!empty($this->phone) ?
"'".$this->db->escape($this->phone).
"'" :
"null");
1647 $sql .=
",phone_mobile = ".(!empty($this->phone_mobile) ?
"'".$this->db->escape($this->phone_mobile).
"'" :
"null");
1648 $sql .=
",fax = ".(!empty($this->fax) ?
"'".$this->db->escape($this->fax).
"'" :
"null");
1649 $sql .=
",email = ".(!empty($this->email) ?
"'".$this->db->escape($this->email).
"'" :
"null");
1650 $sql .=
",socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1651 $sql .=
",url = ".(!empty($this->url) ?
"'".$this->db->escape($this->url).
"'" :
"null");
1653 $sql .=
",parent = ".($this->parent > 0 ? ((int) $this->parent) :
"null");
1655 $sql .=
",note_private = ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
1656 $sql .=
",note_public = ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
1658 $sql .=
",siren = '".$this->db->escape($this->idprof1).
"'";
1659 $sql .=
",siret = '".$this->db->escape($this->idprof2).
"'";
1660 $sql .=
",ape = '".$this->db->escape($this->idprof3).
"'";
1661 $sql .=
",idprof4 = '".$this->db->escape($this->idprof4).
"'";
1662 $sql .=
",idprof5 = '".$this->db->escape($this->idprof5).
"'";
1663 $sql .=
",idprof6 = '".$this->db->escape($this->idprof6).
"'";
1665 $sql .=
",tva_assuj = ".($this->tva_assuj !=
'' ?
"'".$this->db->escape((
string) $this->tva_assuj).
"'" :
"null");
1666 $sql .=
",tva_intra = '".$this->db->escape($this->tva_intra).
"'";
1668 $sql .=
",vat_reverse_charge = " . ($this->vat_reverse_charge !=
'' ?
"'" . $this->db->escape((
string) $this->vat_reverse_charge) .
"'" : 0);
1670 $sql .=
",euid = '".$this->db->escape($this->euid).
"'";
1671 $sql .=
",status = ".((int) $this->
status);
1674 $sql .=
",localtax1_assuj = ".($this->localtax1_assuj !=
'' ?
"'".$this->db->escape((
string) $this->localtax1_assuj).
"'" :
"null");
1675 $sql .=
",localtax2_assuj = ".($this->localtax2_assuj !=
'' ?
"'".$this->db->escape((
string) $this->localtax2_assuj).
"'" :
"null");
1676 if ($this->localtax1_assuj == 1) {
1677 if ($this->localtax1_value !=
'') {
1678 $sql .=
", localtax1_value = ".((float) $this->localtax1_value);
1680 $sql .=
", localtax1_value = 0.000";
1683 $sql .=
",localtax1_value =0.000";
1686 if ($this->localtax2_assuj == 1) {
1687 if ($this->localtax2_value !=
'') {
1688 $sql .=
",localtax2_value = ".((float) $this->localtax2_value);
1690 $sql .=
",localtax2_value = 0.000";
1693 $sql .=
",localtax2_value = 0.000";
1696 $sql .=
",capital = ".($this->capital ===
null ?
"null" : (float) $this->capital);
1698 $sql .=
",prefix_comm = ".(!empty($this->prefix_comm) ?
"'".$this->db->escape($this->prefix_comm).
"'" :
"null");
1700 $sql .=
",fk_effectif = ".($this->effectif_id > 0 ? ((int) $this->effectif_id) :
"null");
1701 if (isset($this->stcomm_id)) {
1702 $sql .=
",fk_stcomm=".(int) $this->stcomm_id;
1704 if (isset($this->typent_id)) {
1705 $sql .=
",fk_typent = ".($this->typent_id > 0 ? ((int) $this->typent_id) :
"0");
1708 $sql .=
",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ?
"'".$this->db->escape((
string) $this->forme_juridique_code).
"'" :
"null");
1709 $sql .=
",birth = ".(!empty($this->birth) ?
"'".$this->db->idate($this->birth).
"'" :
"null");
1711 $sql .=
",deposit_percent = ".(!empty($this->deposit_percent) ?
"'".$this->db->escape((
string) $this->deposit_percent).
"'" :
"null");
1712 $sql .=
",transport_mode = ".(!empty($this->transport_mode_id) ?
"'".$this->db->escape((
string) $this->transport_mode_id).
"'" :
"null");
1713 $sql .=
",transport_mode_supplier = ".(!empty($this->transport_mode_supplier_id) ?
"'".$this->db->escape((
string) $this->transport_mode_supplier_id).
"'" :
"null");
1714 $sql .=
",fk_shipping_method = ".(!empty($this->shipping_method_id) ?
"'".$this->db->escape((
string) $this->shipping_method_id).
"'" :
"null");
1716 $sql .=
",client = ".(!empty($this->client) ? ((int) $this->client) : 0);
1717 $sql .=
",fournisseur = ".(!empty($this->fournisseur) ? ((int) $this->fournisseur) : 0);
1718 $sql .=
",barcode = ".(!empty($this->barcode) ?
"'".$this->db->escape($this->barcode).
"'" :
"null");
1719 $sql .=
",default_lang = ".(!empty($this->default_lang) ?
"'".$this->db->escape($this->default_lang).
"'" :
"null");
1720 $sql .=
",logo = ".(!empty($this->logo) ?
"'".$this->db->escape($this->logo).
"'" :
"null");
1721 $sql .=
",logo_squarred = ".(!empty($this->logo_squarred) ?
"'".$this->db->escape($this->logo_squarred).
"'" :
"null");
1722 $sql .=
",outstanding_limit= ".($this->outstanding_limit !=
'' ? ((float) $this->outstanding_limit) :
'null');
1723 $sql .=
",order_min_amount= ".($this->order_min_amount !=
'' ? ((float) $this->order_min_amount) :
'null');
1724 $sql .=
",supplier_order_min_amount= ".($this->supplier_order_min_amount !=
'' ? ((float) $this->supplier_order_min_amount) :
'null');
1725 $sql .=
",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel).
"'";
1727 $sql .=
", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1728 $sql .=
", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1729 $sql .=
", mode_reglement = ".(!empty($this->mode_reglement_id) ?
"'".$this->db->escape((
string) $this->mode_reglement_id).
"'" :
"null");
1730 $sql .=
", cond_reglement = ".(!empty($this->cond_reglement_id) ?
"'".$this->db->escape((
string) $this->cond_reglement_id).
"'" :
"null");
1731 $sql .=
", mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ?
"'".$this->db->escape((
string) $this->mode_reglement_supplier_id).
"'" :
"null");
1732 $sql .=
", cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ?
"'".$this->db->escape((
string) $this->cond_reglement_supplier_id).
"'" :
"null");
1733 $sql .=
", fk_account = ".($this->fk_account > 0 ? (int) $this->fk_account :
"null");
1735 $sql .=
", accountancy_code_customer_general = ".(!empty($this->accountancy_code_customer_general) ?
"'".$this->db->escape($this->accountancy_code_customer_general).
"'" :
"null");
1736 $sql .=
", code_compta = ".(!empty($this->code_compta_client) ?
"'".$this->db->escape($this->code_compta_client).
"'" :
"null");
1740 $sql .=
", accountancy_code_supplier_general = ".(!empty($this->accountancy_code_supplier_general) ?
"'".$this->db->escape($this->accountancy_code_supplier_general).
"'" :
"null");
1741 $sql .=
", code_compta_fournisseur = ".(($this->code_compta_fournisseur !=
"") ?
"'".$this->db->escape($this->code_compta_fournisseur).
"'" :
"null");
1744 $sql .=
",webservices_url = ".(!empty($this->webservices_url) ?
"'".$this->db->escape($this->webservices_url).
"'" :
"null");
1745 $sql .=
",webservices_key = ".(!empty($this->webservices_key) ?
"'".$this->db->escape($this->webservices_key).
"'" :
"null");
1748 $sql .=
", fk_incoterms = ".((int) $this->fk_incoterms);
1749 $sql .=
", location_incoterms = ".(!empty($this->location_incoterms) ?
"'".$this->db->escape($this->location_incoterms).
"'" :
"null");
1752 $sql .=
", code_client = ".(!empty($this->code_client) ?
"'".$this->db->escape($this->code_client).
"'" :
"null");
1756 $sql .=
", code_fournisseur = ".(!empty($this->code_fournisseur) ?
"'".$this->db->escape($this->code_fournisseur).
"'" :
"null");
1758 $sql .=
", fk_user_modif = ".($user->id > 0 ? ((int) $user->id) :
"null");
1759 $sql .=
", fk_multicurrency = ".(int) $this->fk_multicurrency;
1760 $sql .=
", multicurrency_code = '".$this->db->escape($this->multicurrency_code).
"'";
1761 $sql .=
", model_pdf = '".$this->db->escape($this->model_pdf).
"'";
1762 $sql .=
" WHERE rowid = ".(int) $id;
1764 $resql = $this->db->query($sql);
1766 if (is_object($this->oldcopy)) {
1767 if ($this->oldcopy->country_id != $this->country_id) {
1768 unset($this->country_code);
1769 unset($this->country);
1771 if ($this->oldcopy->state_id != $this->state_id) {
1772 unset($this->state_code);
1773 unset($this->state);
1776 unset($this->country_code);
1777 unset($this->country);
1778 unset($this->state_code);
1779 unset($this->state);
1782 $nbrowsaffected = $this->db->affected_rows($resql);
1784 if ($nbrowsaffected) {
1787 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1789 dol_syslog(get_class($this).
"::update update linked member");
1791 $lmember =
new Adherent($this->db);
1792 $result = $lmember->fetch(0,
'0', $this->
id);
1795 $lmember->company = $this->name;
1798 $lmember->address = $this->address;
1799 $lmember->zip = $this->zip;
1800 $lmember->town = $this->town;
1801 $lmember->email = $this->email;
1802 $lmember->socialnetworks = $this->socialnetworks;
1803 $lmember->phone = $this->phone;
1804 $lmember->state_id = $this->state_id;
1805 $lmember->country_id = $this->country_id;
1806 $lmember->default_lang = $this->default_lang;
1808 $result = $lmember->update($user, 0, 1, 1, 1);
1811 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
1814 } elseif ($result < 0) {
1815 $this->error = $lmember->error;
1825 $this->db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int)
$conf->entity));
1827 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
1830 $sql .=
", vat_reverse_charge";
1831 $sql .=
", accountancy_code_customer_general";
1832 $sql .=
", accountancy_code_customer";
1833 $sql .=
", accountancy_code_supplier_general";
1834 $sql .=
", accountancy_code_supplier";
1835 $sql .=
", accountancy_code_buy";
1836 $sql .=
", accountancy_code_sell";
1837 $sql .=
", fk_account";
1838 $sql .=
", mode_reglement";
1839 $sql .=
", cond_reglement";
1840 $sql .=
", mode_reglement_supplier";
1841 $sql .=
", cond_reglement_supplier";
1842 $sql .=
") VALUES (";
1843 $sql .= ((int) $this->
id);
1844 $sql .=
", ".((int)
$conf->entity);
1845 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1846 $sql .=
", '".$this->db->escape($this->accountancy_code_customer_general).
"'";
1847 $sql .=
", '".$this->db->escape($this->code_compta_client).
"'";
1848 $sql .=
", '".$this->db->escape($this->accountancy_code_supplier_general).
"'";
1849 $sql .=
", '".$this->db->escape($this->code_compta_fournisseur).
"'";
1850 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1851 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1852 $sql .=
", ".($this->fk_account > 0 ? (int) $this->fk_account :
"null");
1853 $sql .=
", ".(!empty($this->mode_reglement_id) ? (int) $this->mode_reglement_id :
"null");
1854 $sql .=
", ".(!empty($this->cond_reglement_id) ? (int) $this->cond_reglement_id :
"null");
1855 $sql .=
", ".(!empty($this->mode_reglement_supplier_id) ? (int) $this->mode_reglement_supplier_id :
"null");
1856 $sql .=
", ".(!empty($this->cond_reglement_supplier_id) ? (int) $this->cond_reglement_supplier_id :
"null");
1858 $result = $this->db->query($sql);
1861 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1880 if (!$error && $call_trigger) {
1882 $result = $this->call_trigger(
'COMPANY_MODIFY', $user);
1890 dol_syslog(get_class($this).
"::Update success");
1891 $this->db->commit();
1894 $this->db->rollback();
1898 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1900 $this->error = $langs->trans(
"ErrorDuplicateField");
1903 $this->error = $this->db->lasterror();
1906 $this->db->rollback();
1910 $this->db->rollback();
1911 dol_syslog(get_class($this).
"::Update fails verify ".implode(
',', $this->errors), LOG_WARNING);
1935 public function fetch($rowid, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'', $is_client = 0, $is_supplier = 0)
1940 if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email) && empty($ref_alias)) {
1944 $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';
1945 $sql .=
', s.status, s.fk_warehouse';
1946 $sql .=
', s.price_level';
1947 $sql .=
', GREATEST(s.tms, sef.tms) as date_modification, s.fk_user_creat, s.fk_user_modif';
1948 $sql .=
', s.phone, s.phone_mobile, s.fax, s.email';
1949 $sql .=
', s.socialnetworks';
1950 $sql .=
', s.url, s.zip, s.town, s.note_private, s.note_public, s.client, s.fournisseur';
1951 $sql .=
', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1952 $sql .=
', s.capital, s.tva_intra, s.euid';
1953 $sql .=
', s.fk_typent as typent_id';
1954 $sql .=
', s.fk_effectif as effectif_id';
1955 $sql .=
', s.fk_forme_juridique as forme_juridique_code';
1956 $sql .=
', s.birth';
1957 $sql .=
', s.webservices_url, s.webservices_key, s.model_pdf, s.last_main_doc';
1959 $sql .=
', s.accountancy_code_customer_general, s.code_compta';
1960 $sql .=
', s.accountancy_code_supplier_general, s.code_compta_fournisseur';
1961 $sql .=
', s.accountancy_code_buy, s.accountancy_code_sell';
1962 $sql .=
', s.vat_reverse_charge as soc_vat_reverse_charge';
1963 $sql .=
', s.mode_reglement, s.cond_reglement, s.fk_account';
1964 $sql .=
', s.mode_reglement_supplier, s.cond_reglement_supplier';
1966 $sql .=
', spe.accountancy_code_customer_general, spe.accountancy_code_customer as code_compta';
1967 $sql .=
', spe.accountancy_code_supplier_general, spe.accountancy_code_supplier as code_compta_fournisseur';
1968 $sql .=
', spe.accountancy_code_buy, spe.accountancy_code_sell';
1969 $sql .=
', spe.vat_reverse_charge as spe_vat_reverse_charge';
1970 $sql .=
', spe.mode_reglement, spe.cond_reglement, spe.fk_account';
1971 $sql .=
', spe.mode_reglement_supplier, spe.cond_reglement_supplier';
1973 $sql .=
', s.code_client, s.code_fournisseur, s.parent, s.barcode';
1974 $sql .=
', s.fk_departement as state_id, s.fk_pays as country_id, s.fk_stcomm, s.deposit_percent, s.transport_mode';
1975 $sql .=
', s.tva_assuj';
1976 $sql .=
', s.transport_mode_supplier';
1977 $sql .=
', s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred';
1978 $sql .=
', s.fk_shipping_method';
1979 $sql .=
', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1980 $sql .=
', s.order_min_amount, s.supplier_order_min_amount';
1981 $sql .=
', s.fk_multicurrency, s.multicurrency_code';
1982 $sql .=
', fj.libelle as forme_juridique';
1983 $sql .=
', e.libelle as effectif';
1984 $sql .=
', c.code as country_code, c.label as country';
1985 $sql .=
', d.code_departement as state_code, d.nom as state';
1986 $sql .=
', r.rowid as region_id, r.code_region as region_code';
1987 $sql .=
', st.libelle as stcomm, st.picto as stcomm_picto';
1988 $sql .=
', te.code as typent_code';
1989 $sql .=
', i.libelle as label_incoterms';
1991 $sql .=
', s.remise_client, s.remise_supplier';
1993 $sql .=
', sr.remise_client, sr2.remise_supplier';
1995 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
1996 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as sef ON sef.fk_object=s.rowid';
1998 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = ".((int)
$conf->entity);
2000 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_effectif as e ON s.fk_effectif = e.id';
2001 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON s.fk_pays = c.rowid';
2002 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcomm as st ON s.fk_stcomm = st.id';
2003 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
2004 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON s.fk_departement = d.rowid';
2005 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_regions as r ON d.fk_region = r.code_region ';
2006 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_typent as te ON s.fk_typent = te.id';
2007 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON s.fk_incoterms = i.rowid';
2011 $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').
'))';
2012 $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').
'))';
2014 $sql .=
' WHERE s.entity IN ('.getEntity($this->element).
')';
2018 $sql .=
' AND s.client > 0';
2021 $sql .=
' AND s.fournisseur > 0';
2025 $sql .=
' AND s.rowid = '.((int) $rowid);
2028 $sql .=
" AND s.nom = '".$this->db->escape($ref).
"'";
2031 $sql .=
" AND s.name_alias = '".$this->db->escape($ref_alias).
"'";
2034 $sql .=
" AND s.ref_ext = '".$this->db->escape($ref_ext).
"'";
2037 $sql .=
" AND s.barcode = '".$this->db->escape($barcode).
"'";
2040 $sql .=
" AND s.siren = '".$this->db->escape($idprof1).
"'";
2043 $sql .=
" AND s.siret = '".$this->db->escape($idprof2).
"'";
2046 $sql .=
" AND s.ape = '".$this->db->escape($idprof3).
"'";
2049 $sql .=
" AND s.idprof4 = '".$this->db->escape($idprof4).
"'";
2052 $sql .=
" AND s.idprof5 = '".$this->db->escape($idprof5).
"'";
2055 $sql .=
" AND s.idprof6 = '".$this->db->escape($idprof6).
"'";
2058 $sql .=
" AND s.email = '".$this->db->escape($email).
"'";
2061 $resql = $this->db->query($sql);
2063 $num = $this->db->num_rows($resql);
2065 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
2069 $obj = $this->db->fetch_object($resql);
2071 $this->
id = $obj->rowid;
2072 $this->entity = $obj->entity;
2073 $this->canvas = $obj->canvas;
2075 $this->
ref = $obj->name;
2076 $this->
name = $obj->name;
2077 $this->nom = $obj->name;
2078 $this->name_alias = $obj->name_alias;
2079 $this->ref_ext = $obj->ref_ext;
2081 $this->date_creation = $this->db->jdate($obj->date_creation);
2082 $this->date_modification = $this->db->jdate($obj->date_modification);
2083 $this->user_creation_id = $obj->fk_user_creat;
2084 $this->user_modification_id = $obj->fk_user_modif;
2086 $this->
address = $obj->address;
2087 $this->zip = $obj->zip;
2088 $this->town = $obj->town;
2090 $this->country_id = $obj->country_id;
2091 $this->country_code = $obj->country_id ? $obj->country_code :
'';
2092 $this->country = $obj->country_id ? (($langs->transnoentities(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code) ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
2094 $this->state_id = $obj->state_id;
2095 $this->state_code = $obj->state_code;
2096 $this->region_id = $obj->region_id;
2097 $this->region_code = $obj->region_code;
2098 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
2100 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcomm);
2101 $label = ($transcode !=
'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm);
2102 $this->stcomm_id = $obj->fk_stcomm;
2103 $this->status_prospect_label = $label;
2104 $this->stcomm_picto = $obj->stcomm_picto;
2106 $this->
email = $obj->email;
2107 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
2109 $this->url = $obj->url;
2110 $this->phone = $obj->phone;
2111 $this->phone_mobile = $obj->phone_mobile;
2112 $this->fax = $obj->fax;
2114 $this->parent = $obj->parent;
2116 $this->idprof1 = $obj->idprof1;
2117 $this->idprof2 = $obj->idprof2;
2118 $this->idprof3 = $obj->idprof3;
2119 $this->idprof4 = $obj->idprof4;
2120 $this->idprof5 = $obj->idprof5;
2121 $this->idprof6 = $obj->idprof6;
2123 $this->capital = $obj->capital;
2125 $this->code_client = $obj->code_client;
2126 $this->code_fournisseur = $obj->code_fournisseur;
2128 $this->accountancy_code_customer_general = $obj->accountancy_code_customer_general;
2129 $this->code_compta_client = $obj->code_compta;
2130 $this->accountancy_code_supplier_general = $obj->accountancy_code_supplier_general;
2131 $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
2133 $this->barcode = $obj->barcode;
2135 $this->tva_assuj = $obj->tva_assuj;
2136 $this->tva_intra = $obj->tva_intra;
2138 if (!empty($obj->spe_vat_reverse_charge)) {
2139 $this->vat_reverse_charge = $obj->spe_vat_reverse_charge;
2140 } elseif (!empty($obj->soc_vat_reverse_charge)) {
2141 $this->vat_reverse_charge = $obj->soc_vat_reverse_charge;
2143 $this->vat_reverse_charge = 0;
2145 $this->euid = $obj->euid;
2147 $this->
status = $obj->status;
2150 $this->localtax1_assuj = $obj->localtax1_assuj;
2151 $this->localtax2_assuj = $obj->localtax2_assuj;
2153 $this->localtax1_value = $obj->localtax1_value;
2154 $this->localtax2_value = $obj->localtax2_value;
2156 $this->typent_id = $obj->typent_id;
2157 $this->typent_code = $obj->typent_code;
2159 $this->effectif_id = $obj->effectif_id;
2160 $this->effectif = $obj->effectif_id ? $obj->effectif :
'';
2162 $this->forme_juridique_code = $obj->forme_juridique_code;
2163 $this->forme_juridique = $obj->forme_juridique_code ? $obj->forme_juridique :
'';
2164 $this->birth = $this->db->jdate($obj->birth);
2166 $this->fk_prospectlevel = $obj->fk_prospectlevel;
2168 $this->prefix_comm = $obj->prefix_comm;
2170 $this->remise_percent = $obj->remise_client ?
price2num($obj->remise_client) : 0;
2171 $this->remise_supplier_percent = $obj->remise_supplier;
2173 $this->mode_reglement_id = $obj->mode_reglement;
2174 $this->cond_reglement_id = $obj->cond_reglement;
2175 $this->deposit_percent = $obj->deposit_percent;
2176 $this->transport_mode_id = $obj->transport_mode;
2177 $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier;
2178 $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier;
2179 $this->transport_mode_supplier_id = $obj->transport_mode_supplier;
2180 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
2181 $this->fk_account = $obj->fk_account;
2183 $this->client = $obj->client;
2184 $this->fournisseur = $obj->fournisseur;
2186 $this->note = $obj->note_private;
2187 $this->note_private = $obj->note_private;
2188 $this->note_public = $obj->note_public;
2189 $this->model_pdf = $obj->model_pdf;
2190 $this->default_lang = $obj->default_lang;
2191 $this->logo = $obj->logo;
2192 $this->logo_squarred = $obj->logo_squarred;
2194 $this->webservices_url = $obj->webservices_url;
2195 $this->webservices_key = $obj->webservices_key;
2197 $this->accountancy_code_buy = $obj->accountancy_code_buy;
2198 $this->accountancy_code_sell = $obj->accountancy_code_sell;
2200 $this->outstanding_limit = $obj->outstanding_limit;
2201 $this->order_min_amount = $obj->order_min_amount;
2202 $this->supplier_order_min_amount = $obj->supplier_order_min_amount;
2205 $this->price_level = $obj->price_level;
2208 $this->fk_warehouse = $obj->fk_warehouse;
2210 $this->import_key = $obj->import_key;
2213 $this->fk_incoterms = $obj->fk_incoterms;
2214 $this->location_incoterms = $obj->location_incoterms;
2215 $this->label_incoterms = $obj->label_incoterms;
2218 $this->fk_multicurrency = $obj->fk_multicurrency;
2219 $this->multicurrency_code = $obj->multicurrency_code;
2222 $this->model_pdf = $obj->model_pdf;
2223 $this->last_main_doc = $obj->last_main_doc;
2225 $result = $this->id;
2233 $this->db->free($resql);
2235 $this->error = $this->db->lasterror();
2236 $this->errors[] = $this->db->lasterror();
2242 $this->price_level = 1;
2261 return parent::setBankAccount($fk_account, $notrigger, $userused);
2264 global
$conf, $user;
2266 if (empty($userused)) {
2270 if ($fk_account < 0) {
2271 $fk_account =
'NULL';
2273 dol_syslog(get_class($this).
'::setBankAccount('.$fk_account.
')');
2277 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_perentity SET fk_account = ".((int) $fk_account);
2278 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND entity = ".((int)
$conf->entity);
2279 $resql = $this->db->query($sql);
2280 if ($resql && !$this->db->affected_rows($resql)) {
2281 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (fk_soc, entity, fk_account)";
2282 $sql .=
" VALUES (".((int) $this->
id).
", ".((int)
$conf->entity).
", ".((int) $fk_account).
")";
2283 $resql = $this->db->query($sql);
2287 dol_syslog(get_class($this).
'::setBankAccount Error '.$this->db->error());
2288 $this->error = $this->db->lasterror();
2289 $this->db->rollback();
2294 $this->context[
'bankaccountupdate'] = 1;
2295 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $userused);
2297 $this->db->rollback();
2302 $this->fk_account = ($fk_account ==
'NULL') ?
null : $fk_account;
2303 $this->db->commit();
2319 return parent::setPaymentTerms($id, $deposit_percent);
2326 $fieldname = (get_class($this) ==
'Fournisseur') ?
'cond_reglement_supplier' :
'cond_reglement';
2328 if (empty($deposit_percent) || $deposit_percent < 0) {
2329 $deposit_percent = (float)
getDictionaryValue(
'c_payment_term',
'deposit_percent', $id);
2331 if ($deposit_percent > 100) {
2332 $deposit_percent = 100;
2335 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe SET deposit_percent = ".(empty($deposit_percent) ?
'NULL' :
"'".$this->db->escape((
string) $deposit_percent).
"'");
2336 $sql .=
" WHERE rowid = ".((int) $this->
id);
2337 $resql = $this->db->query($sql);
2340 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_perentity SET ".$this->db->sanitize($fieldname).
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2341 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND entity = ".((int)
$conf->entity);
2342 $resql = $this->db->query($sql);
2343 if ($resql && !$this->db->affected_rows($resql)) {
2344 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (fk_soc, entity, ".$this->db->sanitize($fieldname).
")";
2345 $sql .=
" VALUES (".((int) $this->
id).
", ".((int)
$conf->entity).
", ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL').
")";
2346 $resql = $this->db->query($sql);
2351 dol_syslog(get_class($this).
'::setPaymentTerms Error '.$this->db->error());
2352 $this->error = $this->db->lasterror();
2356 $this->cond_reglement_id = $id;
2357 if (get_class($this) ==
'Fournisseur') {
2358 $this->cond_reglement_supplier_id = $id;
2360 $this->deposit_percent = $deposit_percent;
2374 return parent::setPaymentMethods($id);
2379 dol_syslog(get_class($this).
'::setPaymentMethods('.$id.
')');
2381 $fieldname = (get_class($this) ==
'Fournisseur') ?
'mode_reglement_supplier' :
'mode_reglement';
2383 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_perentity SET ".$this->db->sanitize($fieldname).
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2384 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND entity = ".((int)
$conf->entity);
2385 $resql = $this->db->query($sql);
2386 if ($resql && !$this->db->affected_rows($resql)) {
2387 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (fk_soc, entity, ".$this->db->sanitize($fieldname).
")";
2388 $sql .=
" VALUES (".((int) $this->
id).
", ".((int)
$conf->entity).
", ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL').
")";
2389 $resql = $this->db->query($sql);
2393 dol_syslog(get_class($this).
'::setPaymentMethods Error '.$this->db->error());
2394 $this->error = $this->db->lasterror();
2398 $this->mode_reglement_id = $id;
2399 if (get_class($this) ==
'Fournisseur') {
2400 $this->mode_reglement_supplier_id = $id;
2425 public function findNearest($rowid = 0, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'', $is_client = 0, $is_supplier = 0)
2432 dol_syslog(get_class($this).
"::findNearest", LOG_DEBUG);
2433 $tmpthirdparty =
new Societe($this->db);
2436 $result = $tmpthirdparty->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias, $is_client, $is_supplier);
2442 dol_syslog(
"Thirdparty not found with exact match so we try barcode search", LOG_DEBUG);
2444 $result = $tmpthirdparty->fetch(0,
'',
'', $barcode,
'',
'',
'',
'',
'',
'',
'',
'', $is_client, $is_supplier);
2450 $sqlstart =
"SELECT s.rowid as id FROM ".MAIN_DB_PREFIX.
"societe as s";
2451 $sqlstart .=
' WHERE s.entity IN ('.getEntity($this->element).
')';
2453 $sqlstart .=
' AND s.client > 0';
2456 $sqlstart .=
' AND s.fournisseur > 0';
2460 dol_syslog(
"Thirdparty not found with barcode search so we try profids search", LOG_DEBUG);
2463 $sqlprof .=
" s.siren = '".$this->db->escape($idprof1).
"'";
2469 $sqlprof .=
" s.siret = '".$this->db->escape($idprof2).
"'";
2475 $sqlprof .=
" s.ape = '".$this->db->escape($idprof3).
"'";
2481 $sqlprof .=
" s.idprof4 = '".$this->db->escape($idprof4).
"'";
2487 $sqlprof .=
" s.idprof5 = '".$this->db->escape($idprof5).
"'";
2493 $sqlprof .=
" s.idprof6 = '".$this->db->escape($idprof6).
"'";
2497 $sqlprofquery = $sqlstart .
" AND (".$sqlprof.
" )";
2498 $resql = $this->db->query($sqlprofquery);
2500 $num = $this->db->num_rows($resql);
2502 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
2506 $obj = $this->db->fetch_object($resql);
2512 $this->error = $this->db->lasterror();
2513 $this->errors[] = $this->db->lasterror();
2522 dol_syslog(
"Thirdparty not found with profids search so we try email search", LOG_DEBUG);
2524 $result = $tmpthirdparty->fetch(0,
'',
'',
'',
'',
'',
'',
'',
'',
'', $email,
'', $is_client, $is_supplier);
2531 dol_syslog(
"Thirdparty not found with email search so we try ref, ref_ext or ref_alias search", LOG_DEBUG);
2534 $sqlref .=
" s.nom = '".$this->db->escape($ref).
"'";
2540 $sqlref .=
" s.name_alias = '".$this->db->escape($ref_alias).
"'";
2546 $sqlref .=
" s.ref_ext = '".$this->db->escape($ref_ext).
"'";
2550 $sqlrefquery = $sqlstart .
" AND (".$sqlref.
" )";
2551 $resql = $this->db->query($sqlrefquery);
2553 $num = $this->db->num_rows($resql);
2555 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
2559 $obj = $this->db->fetch_object($resql);
2565 $this->error = $this->db->lasterror();
2566 $this->errors[] = $this->db->lasterror();
2581 public function delete($id, $fuser =
null, $call_trigger = 1)
2583 global
$conf, $user;
2585 if (empty($fuser)) {
2589 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2591 $entity = isset($this->entity) ? $this->entity :
$conf->entity;
2593 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2598 if (empty($objectisused)) {
2602 if ($call_trigger) {
2604 $result = $this->call_trigger(
'COMPANY_DELETE', $fuser);
2612 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2614 $toute_categs = array();
2617 $toute_categs[
'customer'] = $static_cat->containing($this->
id, Categorie::TYPE_CUSTOMER);
2618 $toute_categs[
'supplier'] = $static_cat->containing($this->
id, Categorie::TYPE_SUPPLIER);
2621 foreach ($toute_categs as $type => $categs_type) {
2622 foreach ($categs_type as $cat) {
2623 $cat->del_type($this, $type);
2629 foreach ($this->childtablesoncascade as $tabletodelete) {
2630 $deleteFromObject = explode(
':', $tabletodelete, 4);
2631 if (count($deleteFromObject) >= 2) {
2632 $className = str_replace(
'@',
'', $deleteFromObject[0]);
2633 $filepath = $deleteFromObject[1];
2634 $columnName = $deleteFromObject[2];
2636 $child_object =
new $className($this->db);
2637 '@phan-var-force CommonObject $child_object';
2638 $result = $child_object->deleteByParentField($id, $columnName);
2641 $this->errors[] = $child_object->error;
2646 $this->errors[] =
'Cannot include child class file '.$filepath;
2650 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
2651 $sql .=
" WHERE fk_soc = ".((int) $id);
2652 if (!$this->db->query($sql)) {
2654 $this->errors[] = $this->db->lasterror();
2666 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
2672 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2673 $sql .=
" SET parent = NULL";
2674 $sql .=
" WHERE parent = ".((int) $id);
2675 if (!$this->db->query($sql)) {
2677 $this->errors[] = $this->db->lasterror();
2684 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity";
2685 $sql .=
" WHERE fk_soc = ".((int) $id);
2686 if (!$this->db->query($sql)) {
2688 $this->errors[] = $this->db->lasterror();
2692 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe";
2693 $sql .=
" WHERE rowid = ".((int) $id);
2694 if (!$this->db->query($sql)) {
2696 $this->errors[] = $this->db->lasterror();
2701 $this->db->commit();
2704 if (!empty(
$conf->societe->multidir_output[$entity])) {
2705 $docdir =
$conf->societe->multidir_output[$entity].
"/".$id;
2714 $this->db->rollback();
2718 dol_syslog(
"Can't remove thirdparty with id ".$id.
". There are ".$objectisused.
" children", LOG_WARNING);
2734 dol_syslog(get_class($this).
"::set_as_client is deprecated use setAsCustomer instead", LOG_NOTICE);
2748 if (($this->client == 2 || $this->client == 3) && !
getDolGlobalInt(
'SOCIETE_DISABLE_PROSPECTSCUSTOMERS')) {
2751 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2752 $sql .=
" SET client = ".((int) $newclient);
2753 $sql .=
" WHERE rowid = ".((int) $this->
id);
2755 $resql = $this->db->query($sql);
2757 $this->client = $newclient;
2778 global
$conf, $langs;
2781 $note = trim($note);
2783 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2787 dol_syslog(get_class($this).
"::set_remise_client ".$remise.
", ".$note.
", ".$user->id);
2795 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2796 $sql .=
" SET remise_client = '".$this->db->escape((
string) $remise).
"'";
2797 $sql .=
" WHERE rowid = ".((int) $this->
id);
2798 $resql = $this->db->query($sql);
2800 $this->db->rollback();
2801 $this->error = $this->db->error();
2806 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise";
2807 $sql .=
" (entity, datec, fk_soc, remise_client, note, fk_user_author)";
2808 $sql .=
" VALUES (".((int)
$conf->entity).
", '".$this->db->idate($now).
"', ".((int) $this->
id).
", '".$this->db->escape((
string) $remise).
"',";
2809 $sql .=
" '".$this->db->escape($note).
"',";
2810 $sql .=
" ".((int) $user->id);
2813 $resql = $this->db->query($sql);
2815 $this->db->rollback();
2816 $this->error = $this->db->lasterror();
2820 $this->db->commit();
2839 global
$conf, $langs;
2842 $note = trim($note);
2844 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2848 dol_syslog(get_class($this).
"::set_remise_supplier ".$remise.
", ".$note.
", ".$user->id);
2856 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2857 $sql .=
" SET remise_supplier = ".((float) $remise);
2858 $sql .=
" WHERE rowid = ".((int) $this->
id);
2859 $resql = $this->db->query($sql);
2861 $this->db->rollback();
2862 $this->error = $this->db->error();
2867 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise_supplier";
2868 $sql .=
" (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
2869 $sql .=
" VALUES (".((int)
$conf->entity).
", '".$this->db->idate($now).
"', ".((int) $this->
id).
", ".((float) $remise).
",";
2870 $sql .=
" '".$this->db->escape($note).
"',";
2871 $sql .=
" ".((int) $user->id);
2874 $resql = $this->db->query($sql);
2876 $this->db->rollback();
2877 $this->error = $this->db->lasterror();
2881 $this->db->commit();
2900 public function set_remise_except($remise,
User $user, $desc, $vatrate =
'', $discount_type = 0, $price_base_type =
'HT')
2907 $desc = trim($desc);
2910 if (!($remise > 0)) {
2911 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"1");
2915 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"3");
2919 if ($this->
id > 0) {
2925 if (preg_match(
'/\((.*)\)/', $vatrate, $reg)) {
2926 $vat_src_code = $reg[1];
2927 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2930 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2933 $discount->fk_soc = $this->id;
2934 $discount->socid = $this->id;
2936 $discount->discount_type = $discount_type;
2937 $discount->multicurrency_code = $this->multicurrency_code;
2940 $this->fk_multicurrency = $tmparray[0];
2941 $this->multicurrency_tx = $tmparray[1];
2943 $discount->multicurrency_tx = $this->multicurrency_tx;
2947 $discount->generateFromAmount($remise, ($price_base_type ==
'TTC' ? 1 : 0), $vat_tx, $taxes[
'localtax1'], $taxes[
'localtax2'], (
int) $taxes[
'localtax1_type'], (int) $taxes[
'localtax2_type']);
2949 $discount->vat_src_code = $vat_src_code;
2951 $discount->description = $desc;
2953 $result = $discount->create($user);
2957 $this->error = $discount->error;
2976 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2979 $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type);
2983 $this->error = $discountstatic->error;
2999 $sql =
"SELECT COUNT(f.rowid) as nb, SUM(f.total_ttc) as amount, SUM(f.multicurrency_total_ttc) as multicurrency_amount";
3000 if (!empty($discount_type)) {
3001 $sql .=
" FROM ".$this->db->prefix().
"facture_fourn as f";
3003 $sql .=
" FROM ".$this->db->prefix().
"facture as f";
3005 $sql .=
" WHERE f.entity = ".((int)
$conf->entity);
3006 $sql .=
" AND paye = 0 AND fk_statut = 1";
3007 $sql .=
" AND f.type = ".CommonInvoice::TYPE_CREDIT_NOTE;
3008 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".$this->db->prefix().
"societe_remise_except as rc";
3009 $sql .=
" WHERE rc.discount_type = ".((int) $discount_type);
3010 if (!empty($discount_type)) {
3011 $sql .=
" AND rc.fk_invoice_supplier = f.rowid";
3013 $sql .=
" AND rc.fk_facture = f.rowid";
3015 $sql .=
" AND rc.fk_soc = ".((int) $this->
id);
3017 $sql .=
" AND f.fk_soc = ".((int) $this->
id);
3019 $resql = $this->db->query($sql);
3021 $obj = $this->db->fetch_object($resql);
3043 $reparray = array();
3045 $sql =
"SELECT 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";
3046 $sql .=
", u.office_fax, u.user_mobile, u.personal_mobile";
3047 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc, ".MAIN_DB_PREFIX.
"user as u";
3050 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
3052 $sql .=
" WHERE entity IN (0, ".((int)
$conf->entity).
")";
3055 $sql .=
" AND u.rowid = sc.fk_user AND sc.fk_soc = ".((int) $this->
id);
3056 if (empty($sortfield)) {
3057 $sortfield =
'u.lastname,u.firstname';
3059 if (empty($sortorder)) {
3060 $sortorder = str_repeat(
'ASC,', count(explode(
',', $sortfield)) - 1) .
'ASC';
3062 $sql .= $this->db->order($sortfield, $sortorder);
3064 $resql = $this->db->query($sql);
3066 $num = $this->db->num_rows($resql);
3069 $obj = $this->db->fetch_object($resql);
3072 $reparray[$i][
'id'] = (int) $obj->rowid;
3073 $reparray[$i][
'lastname'] = $obj->lastname;
3074 $reparray[$i][
'firstname'] = $obj->firstname;
3075 $reparray[$i][
'email'] = $obj->email;
3076 $reparray[$i][
'phone'] = $obj->office_phone;
3077 $reparray[$i][
'office_phone'] = $obj->office_phone;
3078 $reparray[$i][
'office_fax'] = $obj->office_fax;
3079 $reparray[$i][
'user_mobile'] = $obj->user_mobile;
3080 $reparray[$i][
'personal_mobile'] = $obj->personal_mobile;
3081 $reparray[$i][
'job'] = $obj->job;
3082 $reparray[$i][
'statut'] = $obj->status;
3083 $reparray[$i][
'status'] = $obj->status;
3084 $reparray[$i][
'entity'] = $obj->entity;
3085 $reparray[$i][
'login'] = $obj->login;
3086 $reparray[$i][
'photo'] = $obj->photo;
3087 $reparray[$i][
'gender'] = $obj->gender;
3089 $reparray[] = (int) $obj->rowid;
3112 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
3113 $sql .=
" SET price_level = ".((int) $price_level);
3114 $sql .=
" WHERE rowid = ".((int) $this->
id);
3116 if (!$this->db->query($sql)) {
3121 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_prices";
3122 $sql .=
" (datec, fk_soc, price_level, fk_user_author)";
3123 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $this->
id).
", ".((int) $price_level).
", ".((int) $user->id).
")";
3125 if (!$this->db->query($sql)) {
3147 if ($this->
id > 0 && $commid > 0) {
3150 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux";
3151 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
3153 $resql = $this->db->query($sql);
3155 dol_syslog(get_class($this).
"::add_commercial Error ".$this->db->lasterror());
3160 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_commerciaux";
3161 $sql .=
" (fk_soc, fk_user)";
3162 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $commid).
")";
3164 $resql = $this->db->query($sql);
3166 dol_syslog(get_class($this).
"::add_commercial Error ".$this->db->lasterror());
3172 $this->context = array(
'commercial_modified' => $commid);
3174 $result = $this->call_trigger(
'COMPANY_LINK_SALE_REPRESENTATIVE', $user);
3181 $this->db->commit();
3184 $this->db->rollback();
3204 $this->context = array(
'commercial_modified' => $commid);
3206 $result = $this->call_trigger(
'COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
3211 if ($this->
id > 0 && $commid > 0) {
3212 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux ";
3213 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
3215 if (!$this->db->query($sql)) {
3217 dol_syslog(get_class($this).
"::del_commercial Erreur");
3237 global
$conf, $langs, $user;
3239 $langs->loadLangs([
'companies',
'commercial']);
3243 $option = $params[
'option'] ??
'';
3244 $nofetch = !empty($params[
'nofetch']);
3246 $noaliasinname = (empty($params[
'noaliasinname']) ? 0 : $params[
'noaliasinname']);
3249 return [
'optimize' => $langs->trans(
"ShowCompany")];
3252 if (!empty($this->logo) && class_exists(
'Form')) {
3253 $photo =
'<div class="photointooltip floatright">';
3254 $photo .=
Form::showphoto(
'societe', $this, 0, 40, 0,
'photoref',
'mini', 0);
3256 $datas[
'photo'] = $photo;
3263 $datas[
'divopen'] =
'<div class="centpercent">';
3265 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
3266 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Customer").
'</u>';
3267 } elseif ($option ==
'prospect' && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
3268 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Prospect").
'</u>';
3269 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
3270 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Supplier").
'</u>';
3271 } elseif ($option ==
'agenda') {
3272 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
3273 } elseif ($option ==
'project') {
3274 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
3275 } elseif ($option ==
'margin') {
3276 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
3277 } elseif ($option ==
'contact') {
3278 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
3279 } elseif ($option ==
'ban') {
3280 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
3284 if (empty($datas[
'picto'])) {
3285 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
3287 if (isset($this->
status)) {
3288 $datas[
'status'] =
' '.$this->getLibStatut(5);
3290 if (isset($this->client) && isset($this->fournisseur)) {
3291 $datas[
'type'] =
' ' . $this->
getTypeUrl(1,
'', 0,
'span');
3294 if (!empty($this->name_alias) && empty($noaliasinname)) {
3297 if (!empty($this->
email)) {
3298 $datas[
'email'] =
'<br>'.img_picto(
'',
'email',
'class="pictofixedwidth"').$this->email;
3300 if (!empty($this->url)) {
3301 $datas[
'url'] =
'<br>'.img_picto(
'',
'globe',
'class="pictofixedwidth"').$this->url;
3303 if (!empty($this->phone) || !empty($this->phone_mobile) || !empty($this->fax)) {
3304 $phonelist = array();
3306 $phonelist[] =
dol_print_phone($this->phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3309 if ($this->phone_mobile) {
3310 $phonelist[] =
dol_print_phone($this->phone_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3313 $phonelist[] =
dol_print_phone($this->fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3315 $datas[
'phonelist'] =
'<br>'.implode(
' ', $phonelist);
3319 $datas[
'address'] =
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
', ', $langs);
3320 } elseif (!empty($this->country_code)) {
3321 $datas[
'address'] =
'<br><b>'.$langs->trans(
'Country').
':</b> '.$this->country_code;
3323 if (!empty($this->tva_intra) || (
getDolGlobalString(
'SOCIETE_SHOW_FIELD_IN_TOOLTIP') && strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'vatnumber') !==
false)) {
3324 $datas[
'vatintra'] =
'<br><b>'.$langs->trans(
'VATIntra').
':</b> '.
dol_escape_htmltag($this->tva_intra);
3327 if (!empty($this->euid) || (
getDolGlobalString(
'SOCIETE_SHOW_FIELD_IN_TOOLTIP') && strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'euid') !==
false)) {
3328 $datas[
'euid'] =
'<br><b>'.$langs->trans(
'EUIDShort').
':</b> '.
dol_escape_htmltag($this->euid);
3332 if (strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid1') !==
false && $langs->trans(
'ProfId1'.$this->country_code) !=
'-') {
3333 $datas[
'profid1'] =
'<br><b>'.$langs->trans(
'ProfId1'.$this->country_code).
':</b> '.$this->idprof1;
3335 if (strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid2') !==
false && $langs->trans(
'ProfId2'.$this->country_code) !=
'-') {
3336 $datas[
'profid2'] =
'<br><b>'.$langs->trans(
'ProfId2'.$this->country_code).
':</b> '.$this->idprof2;
3338 if (strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid3') !==
false && $langs->trans(
'ProfId3'.$this->country_code) !=
'-') {
3339 $datas[
'profid3'] =
'<br><b>'.$langs->trans(
'ProfId3'.$this->country_code).
':</b> '.$this->idprof3;
3341 if (strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid4') !==
false && $langs->trans(
'ProfId4'.$this->country_code) !=
'-') {
3342 $datas[
'profid4'] =
'<br><b>'.$langs->trans(
'ProfId4'.$this->country_code).
':</b> '.$this->idprof4;
3344 if (strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid5') !==
false && $langs->trans(
'ProfId5'.$this->country_code) !=
'-') {
3345 $datas[
'profid5'] =
'<br><b>'.$langs->trans(
'ProfId5'.$this->country_code).
':</b> '.$this->idprof5;
3347 if (strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid6') !==
false && $langs->trans(
'ProfId6'.$this->country_code) !=
'-') {
3348 $datas[
'profid6'] =
'<br><b>'.$langs->trans(
'ProfId6'.$this->country_code).
':</b> '.$this->idprof6;
3352 $datas[
'separator'] =
'<br>';
3354 if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
3355 $datas[
'customercode'] =
'<br><b>'.$langs->trans(
'CustomerCode').
':</b> '.$this->code_client;
3357 if (
isModEnabled(
'accounting') && ($this->client == 1 || $this->client == 3)) {
3358 $langs->load(
'compta');
3359 $datas[
'accountancycustomercode'] =
'<br><b>'.$langs->trans(
'CustomerAccountancyCode').
':</b> '.$this->code_compta_client;
3362 if (!$nofetch &&
isModEnabled(
'category') && $this->client) {
3363 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
3364 $form =
new Form($this->db);
3365 $datas[
'categories_customer'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_CUSTOMER, 1, 1);
3367 if (!empty($this->code_fournisseur) && $this->fournisseur) {
3368 $datas[
'suppliercode'] =
'<br><b>'.$langs->trans(
'SupplierCode').
':</b> '.$this->code_fournisseur;
3370 if (
isModEnabled(
'accounting') && $this->fournisseur) {
3371 $langs->load(
'compta');
3372 $datas[
'accountancysuppliercode'] =
'<br><b>'.$langs->trans(
'SupplierAccountancyCode').
':</b> '.$this->code_compta_fournisseur;
3375 if (!$nofetch &&
isModEnabled(
'category') && $this->fournisseur) {
3376 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
3377 $form =
new Form($this->db);
3378 $datas[
'categories_supplier'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_SUPPLIER, 1, 1);
3381 $datas[
'divclose'] =
'</div>';
3399 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1, $noaliasinname = 0, $target =
'', $morecss =
'')
3401 global
$conf, $langs, $hookmanager, $user;
3403 if (!empty(
$conf->dol_no_mouse_hover)) {
3407 $name = $this->
name ? $this->
name : $this->nom;
3409 if (
getDolGlobalString(
'SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD')) {
3410 if (empty($option) && $this->client > 0) {
3411 $option =
'customer';
3413 if (empty($option) && $this->fournisseur > 0) {
3414 $option =
'supplier';
3420 if (($this->client) && (!empty($this->code_client)) && (
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 1 ||
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 2)) {
3421 $code = $this->code_client.
' - ';
3424 if (($this->fournisseur) && (!empty($this->code_fournisseur)) && (
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 1 ||
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 3)) {
3425 $code .= $this->code_fournisseur.
' - ';
3430 $name = $code.
' '.$name;
3437 if (!empty($this->name_alias) && empty($noaliasinname)) {
3438 $name .=
' ('.$this->name_alias.
')';
3444 'objecttype' => $this->element,
3445 'option' => $option,
3448 $classfortooltip =
'classfortooltip';
3451 $classfortooltip =
'classforajaxtooltip';
3452 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3461 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
3462 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
3463 } elseif ($option ==
'prospect' && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
3464 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
3465 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
3466 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->id;
3467 } elseif ($option ==
'agenda') {
3468 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/agenda.php?socid='.$this->id;
3469 } elseif ($option ==
'project') {
3470 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/project.php?socid='.$this->id;
3471 } elseif ($option ==
'margin') {
3472 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/margin/tabs/thirdpartyMargins.php?socid='.$this->
id.
'&type=1';
3473 } elseif ($option ==
'contact') {
3474 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/contact.php?socid='.$this->id;
3475 } elseif ($option ==
'ban') {
3476 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$this->id;
3480 if (empty($linkstart)) {
3481 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$this->id;
3485 $linkstart .= (!empty($this->canvas) ?
'&canvas='.$this->canvas :
'');
3487 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3488 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3489 $add_save_lastsearch_values = 1;
3491 if ($add_save_lastsearch_values) {
3492 $linkstart .=
'&save_lastsearch_values=1';
3497 if (empty($notooltip)) {
3499 $label = $langs->trans(
"ShowCompany");
3500 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3502 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3503 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
' refurl'.($withpicto ?
' valignmiddle' :
'').
'"';
3504 $target_value = array(
'_self',
'_blank',
'_parent',
'_top');
3505 if (in_array($target, $target_value)) {
3506 $linkclose .=
' target="'.dol_escape_htmltag($target).
'"';
3509 $linkclose .=
' class="valignmiddle'.($morecss ?
' '.$morecss :
'').
'"';
3511 $linkstart .= $linkclose.
'>';
3514 if (!$user->hasRight(
'societe',
'client',
'voir') && $user->socid > 0 && $this->id != $user->socid) {
3519 $result .= $linkstart;
3521 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (
' class="'.(($withpicto != 2) ?
'paddingright' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
3523 if ($withpicto != 2) {
3526 $result .= $linkend;
3529 $hookmanager->initHooks(array(
'thirdpartydao'));
3530 $parameters = array(
3532 'getnomurl' => &$result,
3533 'withpicto ' => $withpicto,
3534 'option' => $option,
3535 'maxlen' => $maxlen,
3536 'notooltip' => $notooltip,
3537 'save_lastsearch_value' => $save_lastsearch_value
3539 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3541 $result = $hookmanager->resPrint;
3543 $result .= $hookmanager->resPrint;
3558 public function getTypeUrl($withpicto = 0, $option =
'', $notooltip = 0, $tag =
'a')
3563 if (empty($option) || preg_match(
'/prospect/', $option)) {
3564 if (($this->client == 2 || $this->client == 3) && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
3565 $s .=
'<'.$tag.
' class="customer-back opacitymedium" title="'.
dolPrintHTMLForAttribute($langs->trans(
"Prospect")).
'"';
3566 $s .= $tag ==
'a' ?
' href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->
id.
'"' :
'';
3567 $s .=
'>'.dol_substr($langs->trans(
"Prospect"), 0, 1).
'</'.$tag.
'>';
3570 if (empty($option) || preg_match(
'/customer/', $option)) {
3571 if (($this->client == 1 || $this->client == 3) && !
getDolGlobalString(
'SOCIETE_DISABLE_CUSTOMERS')) {
3573 $s .= $tag ==
'a' ?
' href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->
id.
'"' :
'';
3574 $s .=
'>'.dol_substr($langs->trans(
"Customer"), 0, 1).
'</'.$tag.
'>';
3577 if (empty($option) || preg_match(
'/supplier/', $option)) {
3580 $s .= $tag ==
'a' ?
' href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->
id.
'"' :
'';
3581 $s .=
'>'.dol_substr($langs->trans(
"Supplier"), 0, 1).
'</'.$tag.
'>';
3612 $langs->load(
'companies');
3614 $statusType =
'status4';
3616 $statusType =
'status6';
3619 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3620 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
3621 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"InActivity");
3622 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
3623 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"InActivity");
3626 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3643 if ($this->
email && $addthirdparty) {
3644 if (empty($this->
name)) {
3645 $this->
name = $this->nom;
3647 $contact_emails[
'thirdparty'] = ($addthirdparty == 2 ?
'<span class="opacitymedium">' :
'').$langs->transnoentitiesnoconv(
"ThirdParty").($addthirdparty == 2 ?
'</span>' :
'').
': '.
dol_trunc($this->
name, 16).
" <".$this->
email.
">";
3651 return $contact_emails;
3667 if (!empty($this->phone)) {
3668 if (empty($this->
name)) {
3669 $this->
name = $this->nom;
3672 $contact_phone[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->phone.
">";
3674 return $contact_phone;
3690 $contact_property = array();
3693 $sql =
"SELECT rowid, email, statut as status, phone_mobile, lastname, poste, firstname";
3694 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3695 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
3696 $sql .=
" AND entity IN (".getEntity($this->element).
")";
3697 $sql .=
" ORDER BY lastname, firstname";
3699 $resql = $this->db->query($sql);
3701 $nump = $this->db->num_rows($resql);
3705 if ($mode ==
'email') {
3711 while ($i < $nump) {
3712 $obj = $this->db->fetch_object($resql);
3713 if ($mode ==
'email') {
3714 $property = $obj->email;
3715 } elseif ($mode ==
'mobile') {
3716 $property = $obj->phone_mobile;
3718 $property = $obj->$mode;
3722 if ($obj->status == 1 || empty($hidedisabled)) {
3723 if (empty($property)) {
3724 if ($mode ==
'email') {
3725 $property = $langs->transnoentitiesnoconv(
"NoEMail");
3726 } elseif ($mode ==
'mobile') {
3727 $property = $langs->transnoentitiesnoconv(
"NoMobilePhone");
3731 if (!empty($obj->poste)) {
3732 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ?
" - ".$obj->poste :
"").(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3734 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3743 return $contact_property;
3756 $contacts = array();
3758 $sql =
"SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3759 $resql = $this->db->query($sql);
3761 $nump = $this->db->num_rows($resql);
3764 while ($i < $nump) {
3765 $obj = $this->db->fetch_object($resql);
3785 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
3786 $contacts = array();
3788 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3789 $resql = $this->db->query($sql);
3791 $nump = $this->db->num_rows($resql);
3794 while ($i < $nump) {
3795 $obj = $this->db->fetch_object($resql);
3796 $contact =
new Contact($this->db);
3797 $contact->fetch($obj->rowid);
3798 $contacts[] = $contact;
3819 $contact_property =
'';
3821 if (empty($rowid)) {
3825 $sql =
"SELECT rowid, email, phone_mobile, lastname, firstname";
3826 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3827 $sql .=
" WHERE rowid = ".((int) $rowid);
3829 $resql = $this->db->query($sql);
3831 $nump = $this->db->num_rows($resql);
3834 $obj = $this->db->fetch_object($resql);
3836 if ($mode ==
'email') {
3838 } elseif ($mode ==
'mobile') {
3839 $contact_property = $obj->phone_mobile;
3842 return $contact_property;
3861 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3865 $bac->fetch(0,
'', $this->
id);
3868 if ($mode ==
'label') {
3869 return $bac->getRibLabel(
true);
3870 } elseif ($mode ==
'rum') {
3871 if (empty($bac->rum)) {
3872 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
3874 $bac->fetch_thirdparty();
3875 $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, (
string) $bac->id);
3878 } elseif ($mode ==
'format') {
3879 return $bac->frstrecur;
3881 return 'BadParameterToFunctionDisplayRib';
3897 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3898 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE type = 'ban' AND fk_soc = ".((int) $this->
id);
3899 $result = $this->db->query($sql);
3901 $this->error = $this->db->lasterror();
3902 $this->errors[] = $this->db->lasterror();
3905 $num_rows = $this->db->num_rows($result);
3906 $rib_array = array();
3908 while ($obj = $this->db->fetch_object($result)) {
3910 $rib->fetch($obj->rowid);
3911 $rib_array[] = $rib;
3924 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3925 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE type = 'ban' AND default_rib = 1 AND fk_soc = ". (int) $this->
id;
3926 $resql = $this->db->query($sql);
3928 $this->error = $this->db->lasterror();
3929 $this->errors[] = $this->db->lasterror();
3932 $num_rows = $this->db->num_rows($resql);
3933 $rib_array = array();
3935 while ($obj = $this->db->fetch_object($resql)) {
3953 public function get_codeclient($objsoc =
null, $type = 0)
3960 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
3961 foreach ($dirsociete as $dirroot) {
3968 $mod =
new $module($this->db);
3969 '@phan-var-force ModeleThirdPartyCode $mod';
3971 $this->code_client = $mod->getNextValue($objsoc, $type);
3972 $this->prefixCustomerIsRequired = $mod->prefixIsRequired;
3974 dol_syslog(get_class($this).
"::get_codeclient code_client=".$this->code_client.
" module=".$module);
3987 public function get_codefournisseur($objsoc =
null, $type = 1)
3994 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
3995 foreach ($dirsociete as $dirroot) {
4002 $mod =
new $module($this->db);
4003 '@phan-var-force ModeleThirdPartyCode $mod';
4005 $this->code_fournisseur = $mod->getNextValue($objsoc, $type);
4007 dol_syslog(get_class($this).
"::get_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
4025 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
4026 foreach ($dirsociete as $dirroot) {
4033 $mod =
new $module($this->db);
4034 '@phan-var-force ModeleThirdPartyCode $mod';
4036 dol_syslog(get_class($this).
"::codeclient_modifiable code_client=".$this->code_client.
" module=".$module);
4037 if ($mod->code_modifiable_null && !$this->code_client) {
4040 if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
4043 if ($mod->code_modifiable) {
4066 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
4067 foreach ($dirsociete as $dirroot) {
4074 $mod =
new $module($this->db);
4075 '@phan-var-force ModeleThirdPartyCode $mod';
4077 dol_syslog(get_class($this).
"::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur.
" module=".$module);
4078 if ($mod->code_modifiable_null && !$this->code_fournisseur) {
4081 if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
4084 if ($mod->code_modifiable) {
4113 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
4114 foreach ($dirsociete as $dirroot) {
4121 $mod =
new $module($this->db);
4122 '@phan-var-force ModeleThirdPartyCode $mod';
4124 dol_syslog(get_class($this).
"::check_codeclient code_client=".$this->code_client.
" module=".$module);
4125 $result = $mod->verif($this->db, $this->code_client, $this, 0);
4127 $this->error = $mod->error;
4128 $this->errors = $mod->errors;
4155 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
4156 foreach ($dirsociete as $dirroot) {
4163 $mod =
new $module($this->db);
4164 '@phan-var-force ModeleThirdPartyCode $mod';
4166 dol_syslog(get_class($this).
"::check_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
4167 $result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
4169 $this->error = $mod->error;
4170 $this->errors = $mod->errors;
4195 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
4196 foreach ($dirsociete as $dirroot) {
4204 $mod =
new $module();
4205 '@phan-var-force ModeleAccountancyCode $mod';
4208 $result = $mod->get_code($this->db, $this, $type);
4210 if ($type ==
'customer') {
4211 $this->code_compta_client = $mod->code;
4212 } elseif ($type ==
'supplier') {
4213 $this->code_compta_fournisseur = $mod->code;
4218 $this->error =
'ErrorAccountancyCodeNotDefined';
4222 if ($type ==
'customer') {
4223 $this->code_compta_client =
'';
4224 } elseif ($type ==
'supplier') {
4225 $this->code_compta_fournisseur =
'';
4240 dol_syslog(get_class($this).
'::setParent', LOG_DEBUG);
4246 if ($sameparent < 0) {
4249 if ($sameparent == 1) {
4250 setEventMessages(
'ParentCompanyToAddIsAlreadyAChildOfModifiedCompany',
null,
'warnings');
4255 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe SET parent = '.($id > 0 ? ((int) $id) :
'null').
' WHERE rowid = '.((
int) $this->id);
4257 $resql = $this->db->query($sql);
4259 $this->parent = $id;
4279 if ($counter > 100) {
4280 dol_syslog(
"Too high level of parent - child for company. May be an infinite loop ?", LOG_WARNING);
4283 $sql =
'SELECT s.parent';
4284 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
4285 $sql .=
' WHERE rowid = '.((int) $idparent);
4286 $resql = $this->db->query($sql);
4288 $obj = $this->db->fetch_object($resql);
4290 if ($obj->parent ==
'') {
4292 } elseif ($obj->parent == $idchild) {
4314 if ($company_id > 0) {
4315 $sql =
"SELECT parent FROM " . MAIN_DB_PREFIX .
"societe WHERE rowid = ".((int) $company_id);
4316 $resql = $this->db->query($sql);
4318 if ($obj = $this->db->fetch_object($resql)) {
4319 $parent = $obj->parent;
4320 if ($parent > 0 && !in_array($parent, $parents)) {
4321 $parents[] = $parent;
4327 $this->db->free($resql);
4329 setEventMessage($langs->trans(
'GetCompanyParentsError', $this->db->lasterror()),
'errors');
4346 $children = array();
4347 if ($company_id > 0) {
4348 $sql =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"societe WHERE parent = ".((int) $company_id);
4349 $resql = $this->db->query($sql);
4351 while ($obj = $this->db->fetch_object($resql)) {
4352 $child = $obj->rowid;
4353 if ($child > 0 && !in_array($child, $children)) {
4354 $children[] = $child;
4357 $this->db->free($resql);
4444 $sql =
"SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"societe WHERE ".$field.
" = '".$this->db->escape($value).
"' AND entity IN (".
getEntity(
'societe').
")";
4446 $sql .=
" AND rowid <> ".((int) $socid);
4448 $resql = $this->db->query($sql);
4450 $obj = $this->db->fetch_object($resql);
4454 print $this->db->error();
4456 $this->db->free($resql);
4477 require_once DOL_DOCUMENT_ROOT.
'/core/lib/profid.lib.php';
4494 global $langs, $hookmanager;
4499 $hookmanager->initHooks(array(
'idprofurl'));
4500 $parameters = array(
'idprof' => $idprof,
'company' => $thirdparty);
4501 $reshook = $hookmanager->executeHooks(
'getIdProfUrl', $parameters, $this, $action);
4502 if (empty($reshook)) {
4508 $strippedIdProf1 = str_replace(
' ',
'', $thirdparty->idprof1);
4509 if ($idprof == 1 && $thirdparty->country_code ==
'FR') {
4510 $url =
'https://annuaire-entreprises.data.gouv.fr/entreprise/'.urlencode($strippedIdProf1);
4512 if ($idprof == 1 && ($thirdparty->country_code ==
'GB' || $thirdparty->country_code ==
'UK')) {
4513 $url =
'https://beta.companieshouse.gov.uk/company/'.urlencode($strippedIdProf1);
4515 if ($idprof == 1 && $thirdparty->country_code ==
'ES') {
4516 $url =
'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.urlencode($strippedIdProf1);
4518 if ($idprof == 1 && $thirdparty->country_code ==
'IN') {
4519 $url =
'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.urlencode($strippedIdProf1).
';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
4521 if ($idprof == 1 && $thirdparty->country_code ==
'DZ') {
4522 $url =
'http://nif.mfdgi.gov.dz/nif.asp?Nif='.urlencode($strippedIdProf1);
4524 if ($idprof == 1 && $thirdparty->country_code ==
'PT') {
4525 $url =
'http://www.nif.pt/'.urlencode($strippedIdProf1);
4529 return '<a target="_blank" rel="noopener noreferrer" href="'.$url.
'">'.$langs->trans(
"Check").
'</a>';
4532 return $hookmanager->resPrint;
4547 $sql =
"SELECT COUNT(*) as numproj FROM ".MAIN_DB_PREFIX.
"projet WHERE fk_soc = ".((int) $this->
id);
4548 $resql = $this->db->query($sql);
4550 $obj = $this->db->fetch_object($resql);
4551 $count = $obj->numproj;
4554 print $this->db->error();
4556 $this->db->free($resql);
4557 return ($count > 0);
4569 $sql =
"SELECT s.rowid, s.nom as name, s.datec, GREATEST(s.tms, sef.tms) as datem,";
4570 $sql .=
" fk_user_creat, fk_user_modif";
4571 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
4572 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_extrafields as sef ON sef.fk_object=s.rowid";
4573 $sql .=
" WHERE s.rowid = ".((int) $id);
4575 $result = $this->db->query($sql);
4577 if ($this->db->num_rows($result)) {
4578 $obj = $this->db->fetch_object($result);
4580 $this->
id = $obj->rowid;
4582 $this->user_creation_id = $obj->fk_user_creat;
4583 $this->user_modification_id = $obj->fk_user_modif;
4584 $this->date_creation = $this->db->jdate($obj->datec);
4585 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
4587 $this->
ref = $obj->name;
4590 $this->db->free($result);
4606 $isACompany =
getDolGlobalInt(
'MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES', $defaultvalue);
4609 if (!empty($this->tva_intra)) {
4611 } elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6) || !empty($this->euid)) {
4615 if (preg_match(
'/^TE_PRIVATE/', $this->typent_code)) {
4633 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4644 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4657 $this->SupplierCategories = array();
4658 $sql =
"SELECT rowid, label";
4659 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
4660 $sql .=
" WHERE type = ".Categorie::TYPE_SUPPLIER;
4662 $resql = $this->db->query($sql);
4664 while ($obj = $this->db->fetch_object($resql)) {
4665 $this->SupplierCategories[$obj->rowid] = $obj->label;
4683 if ($categorie_id > 0 && $this->
id > 0) {
4684 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_fournisseur (fk_categorie, fk_soc) ";
4685 $sql .=
" VALUES (".((int) $categorie_id).
", ".((int) $this->
id).
")";
4687 if ($resql = $this->db->query($sql)) {
4703 $sql =
"SELECT count(mc.email) as nb";
4704 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
4705 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->
email).
"' ";
4706 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
4708 $resql = $this->db->query($sql);
4710 $obj = $this->db->fetch_object($resql);
4711 $nb = (int) $obj->nb;
4713 $this->db->free($resql);
4716 $this->error = $this->db->error();
4738 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing', 0).
") AND email = '".$this->db->escape($this->
email).
"'";
4739 $resql = $this->db->query($sql);
4741 $obj = $this->db->fetch_object($resql);
4742 $noemail = $obj->nb;
4743 if (empty($noemail)) {
4745 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing_unsubscribe(email, entity, date_creat) VALUES ('".$this->db->escape($this->
email).
"', ".
getEntity(
'mailing', 0).
", '".$this->db->idate(
dol_now()).
"')";
4746 $resql = $this->db->query($sql);
4749 $this->error = $this->db->lasterror();
4750 $this->errors[] = $this->error;
4755 $this->error = $this->db->lasterror();
4756 $this->errors[] = $this->error;
4760 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->db->escape($this->
email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
4761 $resql = $this->db->query($sql);
4764 $this->error = $this->db->lasterror();
4765 $this->errors[] = $this->error;
4769 if (empty($error)) {
4770 $this->no_email = $no_email;
4771 $this->db->commit();
4774 $this->db->rollback();
4791 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->db->escape($this->
email).
"'";
4792 $resql = $this->db->query($sql);
4794 $obj = $this->db->fetch_object($resql);
4795 $this->no_email = $obj->nb;
4798 $this->error = $this->db->lasterror();
4799 $this->errors[] = $this->error;
4819 global $user, $langs;
4821 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
4822 $fullname = $member->getFullName($langs);
4824 if ($member->morphy ==
'mor') {
4825 if (empty($socname)) {
4826 $socname = $member->company ? $member->company : $member->societe;
4828 if (!empty($fullname) && empty($socalias)) {
4829 $socalias = $fullname;
4831 } elseif (empty($socname) && $member->morphy ==
'phy') {
4832 if (empty($socname)) {
4833 $socname = $fullname;
4835 if (!empty($member->company) && empty($socalias)) {
4836 $socalias = $member->company;
4840 $name = (
string) $socname;
4841 $alias = $socalias ? $socalias :
'';
4845 $this->
name = $name;
4846 $this->name_alias = $alias;
4847 $this->
address = $member->address;
4848 $this->zip = $member->zip;
4849 $this->town = $member->town;
4850 $this->country_code = $member->country_code;
4851 $this->country_id = $member->country_id;
4852 $this->phone = $member->phone;
4853 $this->
email = $member->email;
4854 $this->socialnetworks = $member->socialnetworks;
4855 $this->entity = $member->entity;
4859 $this->code_client = $member->ref;
4861 $this->code_client = ($customercode ? $customercode : -1);
4863 $this->code_fournisseur =
'-1';
4864 $this->typent_code = ($member->morphy ==
'phy' ?
'TE_PRIVATE' : 0);
4865 $this->typent_id = $this->typent_code ?
dol_getIdFromCode($this->db, $this->typent_code,
'c_typent',
'id',
'code') : 0;
4870 $result = $this->
create($user);
4876 $this->name_bis = $member->lastname;
4877 $this->firstname = $member->firstname;
4878 $this->civility_id = (empty($member->civility_code) ? $member->civility_id : $member->civility_code);
4879 $this->civility_code = (empty($member->civility_code) ? $member->civility_id : $member->civility_code);
4881 dol_syslog(
"We ask to create a contact/address too", LOG_DEBUG);
4886 $this->db->rollback();
4891 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent";
4892 $sql .=
" SET fk_soc = ".((int) $this->
id);
4893 $sql .=
" WHERE rowid = ".((int) $member->id);
4895 $resql = $this->db->query($sql);
4897 $this->db->commit();
4900 $this->error = $this->db->error();
4902 $this->db->rollback();
4907 dol_syslog(get_class($this).
"::create_from_member - 2 - ".$this->error.
" - ".implode(
',', $this->errors), LOG_ERR);
4909 $this->db->rollback();
4925 $this->entity =
$conf->entity;
4927 $this->nom = $this->name;
4941 $country_code = $country_label =
'';
4944 $country_id = (is_numeric($tmp[0])) ? (
int) $tmp[0] : 0;
4945 if (!empty($tmp[1]) && !empty($tmp[2])) {
4946 $country_code = $tmp[1];
4947 $country_label = $tmp[2];
4948 } elseif ($country_id > 0) {
4953 dol_syslog(
"Your country setup use an old syntax. Reedit it using setup area.", LOG_WARNING);
4954 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4955 $country_code =
getCountry($country_id,
'2', $this->db);
4956 $country_label =
getCountry($country_id,
'', $this->db);
4959 $this->country_id = $country_id;
4960 $this->country_code = $country_code;
4961 $this->country = $country_label;
4962 if (is_object($langs)) {
4963 $this->country = ($langs->trans(
'Country'.$country_code) !=
'Country'.$country_code) ? $langs->trans(
'Country'.$country_code) : $country_label;
4973 $state_id = (int) $tmp[0];
4974 if (!empty($tmp[1])) {
4975 $state_code = $tmp[1];
4976 $state_label = $tmp[2];
4978 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);
4979 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4980 $state_code =
getState($state_id,
'2', $this->db);
4981 $state_label =
getState($state_id,
'0', $this->db);
4984 $this->state_id = $state_id;
4985 $this->state_code = $state_code;
4986 $this->state = $state_label;
4987 if (is_object($langs)) {
4988 $this->state = ($langs->trans(
'State'.$state_code) !=
'State'.$state_code) ? $langs->trans(
'State'.$state_code) : $state_label;
5003 $this->socialnetworks = array();
5004 if (!empty($facebook_url)) {
5005 $this->socialnetworks[
'facebook'] = $facebook_url;
5007 if (!empty($twitter_url)) {
5008 $this->socialnetworks[
'twitter'] = $twitter_url;
5010 if (!empty($linkedin_url)) {
5011 $this->socialnetworks[
'linkedin'] = $linkedin_url;
5013 if (!empty($instagram_url)) {
5014 $this->socialnetworks[
'instagram'] = $instagram_url;
5016 if (!empty($youtube_url)) {
5017 $this->socialnetworks[
'youtube'] = $youtube_url;
5019 if (!empty($github_url)) {
5020 $this->socialnetworks[
'github'] = $github_url;
5038 $this->forme_juridique_code =
getDolGlobalInt(
'MAIN_INFO_SOCIETE_FORME_JURIDIQUE');
5045 $this->logo_squarred_small =
getDolGlobalString(
'MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL');
5046 $this->logo_squarred_mini =
getDolGlobalString(
'MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI');
5052 $this->localtax1_assuj = ((isset(
$conf->global->FACTURE_LOCAL_TAX1_OPTION) && (
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'1' ||
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'localtax1on')) ? 1 : 0);
5053 $this->localtax2_assuj = ((isset(
$conf->global->FACTURE_LOCAL_TAX2_OPTION) && (
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'1' ||
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'localtax2on')) ? 1 : 0);
5072 $this->
name =
'THIRDPARTY SPECIMEN '.dol_print_date($now,
'dayhourlog');
5073 $this->ref_ext =
'Ref ext';
5074 $this->specimen = 1;
5075 $this->
address =
'21 jump street';
5076 $this->zip =
'99999';
5077 $this->town =
'MyTown';
5078 $this->state_id = 1;
5079 $this->state_code =
'AA';
5080 $this->state =
'MyState';
5081 $this->country_id = 1;
5082 $this->country_code =
'FR';
5083 $this->
email =
'specimen@specimen.com';
5084 $this->socialnetworks = array(
5085 'skype' =>
'skypepseudo',
5086 'twitter' =>
'twitterpseudo',
5087 'facebook' =>
'facebookpseudo',
5088 'linkedin' =>
'linkedinpseudo',
5090 $this->url =
'https://www.specimen.com';
5092 $this->phone =
'0909090901';
5093 $this->phone_mobile =
'0909090901';
5094 $this->fax =
'0909090909';
5096 $this->code_client =
'CC-'.dol_print_date($now,
'dayhourlog');
5097 $this->code_fournisseur =
'SC-'.dol_print_date($now,
'dayhourlog');
5098 $this->typent_code =
'TE_OTHER';
5099 $this->capital = 10000;
5101 $this->prospect = 1;
5102 $this->fournisseur = 1;
5103 $this->tva_assuj = 1;
5105 $this->tva_intra =
'FR1234567';
5106 $this->note_public =
'This is a comment (public)';
5107 $this->note_private =
'This is a comment (private)';
5109 $this->idprof1 =
'idprof1';
5110 $this->idprof2 =
'idprof2';
5111 $this->idprof3 =
'idprof3';
5112 $this->idprof4 =
'idprof4';
5113 $this->idprof5 =
'idprof5';
5114 $this->idprof6 =
'idprof6';
5116 $this->euid =
'FR-RCSXXXX-idprof1';
5129 public function useLocalTax($localTaxNum = 0, $mode = 0, $thirdparty =
null)
5131 if ($mode == 1 && $thirdparty instanceof
Societe) {
5132 if ($localTaxNum == -1) {
5133 return array(1 => ($thirdparty->localtax1_assuj ?
true :
false), 2 => ($thirdparty->localtax2_assuj ?
true :
false));
5134 } elseif ($localTaxNum == 1) {
5135 return $thirdparty->localtax1_assuj ? true :
false;
5136 } elseif ($localTaxNum == 2) {
5137 return $thirdparty->localtax2_assuj ? true :
false;
5141 $sql =
"SELECT t.localtax1, t.localtax2";
5142 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
5143 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
5144 $sql .=
" AND t.active = 1";
5145 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
5146 if (empty($localTaxNum) || $localTaxNum == -1) {
5147 $sql .=
" AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
5148 } elseif ($localTaxNum == 1) {
5149 $sql .=
" AND t.localtax1_type <> '0'";
5150 } elseif ($localTaxNum == 2) {
5151 $sql .=
" AND t.localtax2_type <> '0'";
5154 $resql = $this->db->query($sql);
5156 if ($localTaxNum == -1) {
5157 $obj = $this->db->fetch_object($resql);
5159 return array(1 => ($obj->localtax1 ?
true :
false), 2 => ($obj->localtax2 ?
true :
false));
5161 return array(1 =>
false, 2 =>
false);
5163 return ($this->db->num_rows($resql) > 0);
5178 $sql =
"SELECT t.rowid";
5179 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
5180 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
5181 $sql .=
" AND t.active = 1 AND t.recuperableonly = 1";
5182 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
5185 $resql = $this->db->query($sql);
5187 return ($this->db->num_rows($resql) > 0);
5201 $sql =
"SELECT COUNT(*) as nb";
5202 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_revenuestamp as r, ".MAIN_DB_PREFIX.
"c_country as c";
5203 $sql .=
" WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
5204 $sql .=
" AND r.active = 1";
5207 $resql = $this->db->query($sql);
5209 $obj = $this->db->fetch_object($resql);
5210 return ($obj->nb > 0);
5212 $this->error = $this->db->lasterror();
5240 if ($fk_prospectlevel !=
'') {
5241 $label = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
5243 if ($label ==
"ProspectLevel".$fk_prospectlevel) {
5244 $label = $langs->getLabelFromKey($this->db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
5260 return $this->
LibProspCommStatut((
int) $this->stcomm_id, $mode, $label, $this->stcomm_picto);
5282 $langs->load(
'customers');
5285 if ($status ==
'-1' || $status ==
'ST_NO') {
5286 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect-1");
5287 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
5288 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect0");
5289 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
5290 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect1");
5291 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
5292 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect2");
5293 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
5294 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect3");
5296 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label,
'0', $picto,
'class="inline-block valignmiddle"').
' '.(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label);
5298 } elseif ($mode == 3) {
5299 if ($status ==
'-1' || $status ==
'ST_NO') {
5300 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto,
'class="inline-block valignmiddle"');
5301 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
5302 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto,
'class="inline-block valignmiddle"');
5303 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
5304 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto,
'class="inline-block valignmiddle"');
5305 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
5306 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto,
'class="inline-block valignmiddle"');
5307 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
5308 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto,
'class="inline-block valignmiddle"');
5310 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label,
'0', $picto,
'class="inline-block valignmiddle"');
5312 } elseif ($mode == 4) {
5313 if ($status ==
'-1' || $status ==
'ST_NO') {
5314 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect-1");
5315 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
5316 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect0");
5317 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
5318 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect1");
5319 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
5320 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect2");
5321 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
5322 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect3");
5324 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label,
'0', $picto,
'class="inline-block valignmiddle"').
' '.(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label);
5328 return "Error, mode/status not found";
5339 global $hookmanager;
5341 if ($mode ==
'supplier') {
5342 $table =
'supplier_proposal';
5345 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
5346 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
5347 if ($mode ==
'supplier') {
5348 $sql .=
" AND entity IN (".getEntity(
'supplier_proposal').
")";
5350 $sql .=
" AND entity IN (".getEntity(
'propal').
")";
5353 dol_syslog(
"getOutstandingProposals for fk_soc = ".((
int) $this->
id), LOG_DEBUG);
5356 $parameters = array(
'mode' => $mode,
'table' => $table);
5357 $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
5358 $sql .= $hookmanager->resPrint;
5360 $resql = $this->db->query($sql);
5362 $outstandingOpened = 0;
5363 $outstandingTotal = 0;
5364 $outstandingTotalIncTax = 0;
5365 $arrayofref = array();
5366 while ($obj = $this->db->fetch_object($resql)) {
5367 $arrayofref[$obj->rowid] = $obj->ref;
5368 $outstandingTotal += $obj->total_ht;
5369 $outstandingTotalIncTax += $obj->total_ttc;
5370 if ($obj->status != 0) {
5372 $outstandingOpened += $obj->total_ttc;
5375 return array(
'opened' => $outstandingOpened,
'total_ht' => $outstandingTotal,
'total_ttc' => $outstandingTotalIncTax,
'refs' => $arrayofref);
5389 global $hookmanager;
5390 $table =
'commande';
5391 if ($mode ==
'supplier') {
5392 $table =
'commande_fournisseur';
5395 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
5396 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
5397 if ($mode ==
'supplier') {
5398 $sql .=
" AND entity IN (".getEntity(
'supplier_order').
")";
5400 $sql .=
" AND entity IN (".getEntity(
'commande').
")";
5403 dol_syslog(
"getOutstandingOrders", LOG_DEBUG);
5405 $parameters = array(
'mode' => $mode,
'table' => $table);
5406 $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
5407 $sql .= $hookmanager->resPrint;
5408 $resql = $this->db->query($sql);
5410 $outstandingOpened = 0;
5411 $outstandingTotal = 0;
5412 $outstandingTotalIncTax = 0;
5413 $arrayofref = array();
5414 while ($obj = $this->db->fetch_object($resql)) {
5415 $arrayofref[$obj->rowid] = $obj->ref;
5416 $outstandingTotal += $obj->total_ht;
5417 $outstandingTotalIncTax += $obj->total_ttc;
5418 if ($obj->status != 0) {
5420 $outstandingOpened += $obj->total_ttc;
5423 return array(
'opened' => $outstandingOpened,
'total_ht' => $outstandingTotal,
'total_ttc' => $outstandingTotalIncTax,
'refs' => $arrayofref);
5438 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
5441 if ($mode ==
'supplier') {
5442 $table =
'facture_fourn';
5454 $sql =
"SELECT rowid, ref, total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table.
" as f";
5455 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
5456 if (!empty($late)) {
5457 $sql .=
" AND date_lim_reglement < '".$this->db->idate($today).
"'";
5459 if ($mode ==
'supplier') {
5460 $sql .=
" AND entity IN (".getEntity(
'facture_fourn').
")";
5462 $sql .=
" AND entity IN (".getEntity(
'invoice').
")";
5465 dol_syslog(
"getOutstandingBills", LOG_DEBUG);
5466 $resql = $this->db->query($sql);
5468 $outstandingOpened = 0;
5469 $outstandingTotal = 0;
5470 $outstandingTotalIncTax = 0;
5471 $arrayofref = array();
5472 $arrayofrefopened = array();
5473 if ($mode ==
'supplier') {
5474 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
5477 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
5478 $tmpobject =
new Facture($this->db);
5480 while ($obj = $this->db->fetch_object($resql)) {
5481 $arrayofref[$obj->rowid] = $obj->ref;
5482 $tmpobject->id = $obj->rowid;
5484 if ($obj->status != $tmpobject::STATUS_DRAFT
5485 && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code ==
'replaced')
5487 $outstandingTotal += $obj->total_ht;
5488 $outstandingTotalIncTax += $obj->total_ttc;
5494 && $obj->status != $tmpobject::STATUS_DRAFT
5495 && $obj->status != $tmpobject::STATUS_ABANDONED
5496 && $obj->status != $tmpobject::STATUS_CLOSED) {
5498 $paiement = $tmpobject->getSommePaiement();
5499 $creditnotes = $tmpobject->getSumCreditNotesUsed();
5500 $deposits = $tmpobject->getSumDepositsUsed();
5502 $remaintopay = ($obj->total_ttc - $paiement - $creditnotes - $deposits);
5503 $outstandingOpened += $remaintopay;
5509 $remainingcreditnote = $tmpobject->getSumFromThisCreditNotesNotUsed();
5510 $remaintopay -= $remainingcreditnote;
5511 $outstandingOpened -= $remainingcreditnote;
5515 $arrayofrefopened[$obj->rowid] = $obj->ref;
5518 return array(
'opened' => $outstandingOpened,
'total_ht' => $outstandingTotal,
'total_ttc' => $outstandingTotalIncTax,
'refs' => $arrayofref,
'refsopened' => $arrayofrefopened);
5520 dol_syslog(
"Sql error ".$this->db->lasterror, LOG_ERR);
5547 $langs->load(
'companies');
5550 return $langs->trans(
"NorProspectNorCustomer");
5551 } elseif ($status == 1) {
5552 return $langs->trans(
"Customer");
5553 } elseif ($status == 2) {
5554 return $langs->trans(
"Prospect");
5555 } elseif ($status == 3) {
5556 return $langs->trans(
"ProspectCustomer");
5571 if ($thirdparty->country_code ==
'FR' && empty($thirdparty->tva_intra) && !empty($thirdparty->tva_assuj)) {
5572 require_once DOL_DOCUMENT_ROOT.
'/core/lib/profid.lib.php';
5574 $siren = preg_replace(
'/\s+/',
'', (
string) $thirdparty->idprof1);
5575 $siret = preg_replace(
'/\s+/',
'', (
string) $thirdparty->idprof2);
5581 $siren = substr($siret, 0, 9);
5583 if (!empty($siren)) {
5586 $cle = (12 + 3 * (((int) $siren) % 97)) % 97;
5587 $tva_intra =
'FR' . str_pad((
string) $cle, 2,
'0', STR_PAD_LEFT) . $siren;
5591 return $tva_intra ??
'';
5606 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
5610 if (!empty($moreparams) && !empty($moreparams[
'use_companybankid'])) {
5611 $modelpath =
"core/modules/bank/doc/";
5613 include_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
5615 $result = $companybankaccount->fetch($moreparams[
'use_companybankid']);
5617 dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
5619 $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
5620 $this->last_main_doc = $companybankaccount->last_main_doc;
5627 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_COMPANY_ADDON_PDF_NotDefined");
5632 if (!isset($this->bank_account)) {
5633 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
5636 $result = $bac->fetch(0,
'', $this->
id);
5638 $this->bank_account = $bac;
5640 $this->bank_account =
'';
5644 $modelpath =
"core/modules/societe/doc/";
5646 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
5665 public function setCategories($categories, $type_categ, $remove_existing =
true)
5667 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
5670 if (!in_array($type_categ, array(Categorie::TYPE_CUSTOMER, Categorie::TYPE_SUPPLIER))) {
5671 dol_syslog(__METHOD__.
': Type '.$type_categ.
'is an unknown company category type. Nothing done.', LOG_ERR);
5675 return parent::setCategoriesCommon($categories, $type_categ, $remove_existing);
5690 if (!is_array($salesrep)) {
5691 $salesrep = array($salesrep);
5695 $to_add = $salesrep;
5696 if ($onlyAdd ===
false) {
5701 if (is_array($existing)) {
5702 $to_del = array_diff($existing, $salesrep);
5703 $to_add = array_diff($salesrep, $existing);
5710 foreach ($to_del as $del) {
5713 foreach ($to_add as $add) {
5721 return $error ? -1 : 1;
5737 $result = $this->
setValueFrom(
'fk_typent', $typent_id,
'',
null,
'',
'', $user,
'COMPANY_MODIFY');
5740 $this->typent_id = $typent_id;
5741 $this->typent_code =
dol_getIdFromCode($this->db, $this->typent_id,
'c_typent',
'id',
'code');
5762 if ($origin_id == $dest_id) {
5763 dol_syslog(
'Error: Try to merge a thirdparty into itself');
5769 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5770 $sql .=
' WHERE fk_soc = '.(int) $dest_id.
' AND fk_user IN ( ';
5771 $sql .=
' SELECT fk_user ';
5772 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5773 $sql .=
' WHERE fk_soc = '.(int) $origin_id.
') ';
5775 $resql = $dbs->
query($sql);
5777 $dbs->
query(
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_commerciaux WHERE rowid = '.((
int) $obj->rowid));
5784 'societe_commerciaux',
5787 'societe_remise_except',
5806 global $user, $langs,
$conf;
5810 if ($type ==
'buy') {
5811 $field =
'accountancy_code_buy';
5812 } elseif ($type ==
'sell') {
5813 $field =
'accountancy_code_sell';
5818 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ";
5819 $sql .= $field.
" = '".$this->db->escape($value).
"'";
5820 $sql .=
" WHERE rowid = ".((int) $this->
id);
5822 dol_syslog(get_class($this).
"::".__FUNCTION__, LOG_DEBUG);
5823 $resql = $this->db->query($sql);
5827 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
5829 $result = $interface->run_triggers(
'COMPANY_MODIFY', $this, $user, $langs,
$conf);
5831 $this->errors = $interface->errors;
5832 $this->db->rollback();
5837 $this->$field = $value;
5839 $this->db->commit();
5842 $this->error = $this->db->lasterror();
5843 $this->db->rollback();
5856 require_once DOL_DOCUMENT_ROOT.
'/partnership/class/partnership.class.php';
5858 $this->partnerships[] = array();
5872 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
5874 $out =
'<div class="box-flex-item box-flex-grow-zero">';
5875 $out .=
'<div class="info-box info-box-sm">';
5876 $out .=
'<span class="info-box-icon bg-infobox-action">';
5877 if (!empty($this->logo) && class_exists(
'Form')) {
5878 $out .=
Form::showphoto(
'societe', $this, 0, 40, 0,
'photokanban',
'mini', 0);
5883 $out .=
'<div class="info-box-content">';
5884 $out .=
'<div class="info-box-ref inline-block tdoverflowmax125 valignmiddle">' . $this->
getNomUrl(1);
5886 if (!empty($this->phone)) {
5887 $out .=
'<div class="inline-block valignmiddle">';
5889 $out .=
dol_print_phone($this->phone, $this->country_code, 0, $this->
id,
'tel',
'hidenum',
'phone', $this->phone, 0,
'paddingleft paddingright');
5892 if (!empty($this->
email)) {
5893 $out .=
'<div class="inline-block valignmiddle">';
5894 $out .=
dol_print_email($this->
email, 0, $this->
id,
'thirdparty', -1, 1, 2,
'paddingleft paddingright');
5897 if ($selected >= 0) {
5898 $out .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
5900 if (!empty($this->code_client)) {
5901 $out .=
'<br><span class="info-box-label opacitymedium">'.$this->code_client.
'</span>';
5903 $out .=
'<br><div class="info-box-status">' . $this->
getLibStatut(3) .
'</div>';
5920 public function getContacts($list = 0, $code =
'', $element =
'', $status = -1)
5927 $sql =
"SELECT sc.rowid, sc.fk_socpeople as id, sc.fk_c_type_contact";
5928 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
5929 $sql .=
", t.civility as civility, t.lastname as lastname, t.firstname, t.email";
5930 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_label";
5931 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact tc";
5932 $sql .=
", ".$this->db->prefix().
"societe_contacts sc";
5933 $sql .=
" LEFT JOIN ".$this->db->prefix().
"socpeople t on sc.fk_socpeople = t.rowid";
5934 $sql .=
" WHERE sc.fk_soc = ".((int) $this->
id);
5935 $sql .=
" AND sc.fk_c_type_contact = tc.rowid";
5939 $sql .=
" AND t.statut = " . ((int) $status);
5941 if (!empty($element)) {
5942 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
5945 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
5947 $sql .=
" AND sc.entity IN (".getEntity($this->element).
")";
5948 $sql .=
" AND tc.source = 'external'";
5949 $sql .=
" AND tc.active = 1";
5951 $sql .=
" ORDER BY t.lastname ASC";
5953 dol_syslog(get_class($this).
"::getContacts", LOG_DEBUG);
5954 $resql = $this->db->query($sql);
5956 $num = $this->db->num_rows($resql);
5959 $obj = $this->db->fetch_object($resql);
5962 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
5963 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_label);
5964 $tab[$obj->id] = array(
5965 'source' => $obj->source,
5966 'socid' => (
int) $obj->socid,
5967 'id' => (
int) $obj->id,
5968 'nom' => $obj->lastname,
5969 'civility' => $obj->civility,
5970 'lastname' => $obj->lastname,
5971 'firstname' => $obj->firstname,
5972 'email' => $obj->email,
5973 'login' => (empty($obj->login) ?
'' : $obj->login),
5974 'photo' => (empty($obj->photo) ?
'' : $obj->photo),
5975 'statuscontact' => $obj->statuscontact,
5976 'rowid' => (
int) $obj->rowid,
5977 'code' => $obj->code,
5978 'element' => $obj->element,
5979 'libelle' => $libelle_type,
5980 'status' => $obj->statuslink,
5981 'fk_c_type_contact' => (int) $obj->fk_c_type_contact
5984 $tab[$obj->id] = (int) $obj->id;
5991 $this->error = $this->db->lasterror();
6009 global
$conf, $langs, $hookmanager, $user, $action;
6012 $soc_origin =
new Societe($this->db);
6014 dol_syslog(
"mergeCompany merge thirdparty id=".$soc_origin_id.
" (will be deleted) into the thirdparty id=".$this->id);
6016 if ($soc_origin->fetch($soc_origin_id) < 1) {
6017 $this->error = $langs->trans(
'ErrorRecordNotFound');
6025 $this->client |= $soc_origin->client;
6026 $this->fournisseur |= $soc_origin->fournisseur;
6027 $listofproperties = array(
6028 'address',
'zip',
'town',
'state_id',
'country_id',
'phone',
'phone_mobile',
'fax',
'email',
'socialnetworks',
'url',
'barcode',
6029 'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
6030 'tva_intra',
'euid',
'effectif_id',
'forme_juridique',
'remise_percent',
'remise_supplier_percent',
'mode_reglement_supplier_id',
'cond_reglement_supplier_id',
'name_bis',
6031 'stcomm_id',
'outstanding_limit',
'order_min_amount',
'supplier_order_min_amount',
'price_level',
'parent',
'default_lang',
'ref',
'ref_ext',
'import_key',
'fk_incoterms',
'fk_multicurrency',
6032 'code_client',
'code_fournisseur',
'code_compta',
'code_compta_fournisseur',
6033 'model_pdf',
'webservices_url',
'webservices_key',
'accountancy_code_sell',
'accountancy_code_buy',
'typent_id'
6035 foreach ($listofproperties as $property) {
6036 if (empty($this->$property)) {
6037 $this->$property = $soc_origin->$property;
6041 if ($this->typent_id == -1) {
6042 $this->typent_id = $soc_origin->typent_id;
6046 $listofproperties = array(
6047 'note_public',
'note_private'
6049 foreach ($listofproperties as $property) {
6050 $this->$property =
dol_concatdesc($this->$property, $soc_origin->$property);
6054 if (is_array($soc_origin->array_options)) {
6055 foreach ($soc_origin->array_options as $key => $val) {
6056 if (empty($this->array_options[$key])) {
6057 $this->array_options[$key] = $val;
6063 if (empty($this->name_bis) && $this->
name != $soc_origin->name) {
6064 $this->name_bis = $this->name;
6068 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
6071 $custcats_ori = $static_cat->containing($soc_origin->id,
'customer',
'id');
6072 $custcats = $static_cat->containing($this->
id,
'customer',
'id');
6073 $custcats = array_merge($custcats, $custcats_ori);
6076 $suppcats_ori = $static_cat->containing($soc_origin->id,
'supplier',
'id');
6077 $suppcats = $static_cat->containing($this->
id,
'supplier',
'id');
6078 $suppcats = array_merge($suppcats, $suppcats_ori);
6082 if ($soc_origin->code_client == $this->code_client
6083 || $soc_origin->code_fournisseur == $this->code_fournisseur
6084 || $soc_origin->barcode == $this->barcode) {
6085 dol_syslog(
"We clean customer and supplier code so we will be able to make the update of target");
6086 $soc_origin->code_client =
'';
6087 $soc_origin->code_fournisseur =
'';
6088 $soc_origin->barcode =
'';
6089 $soc_origin->update($soc_origin->id, $user, 0, 1, 1,
'merge');
6096 if (count($children_ori)) {
6097 foreach ($children_ori as $child_id) {
6098 $child =
new Societe($this->db);
6099 $child->id = $child_id;
6100 $child->setParent($this->
id);
6106 $result = $this->
update($this->
id, $user, 0, 1, 1,
'merge');
6115 'Adherent' =>
'/adherents/class/adherent.class.php',
6117 'ActionComm' =>
'/comm/action/class/actioncomm.class.php',
6118 'Propal' =>
'/comm/propal/class/propal.class.php',
6119 'Commande' =>
'/commande/class/commande.class.php',
6120 'Facture' =>
'/compta/facture/class/facture.class.php',
6121 'FactureRec' =>
'/compta/facture/class/facture-rec.class.php',
6122 'LignePrelevement' =>
'/compta/prelevement/class/ligneprelevement.class.php',
6123 'Contact' =>
'/contact/class/contact.class.php',
6124 'Contrat' =>
'/contrat/class/contrat.class.php',
6125 'Expedition' =>
'/expedition/class/expedition.class.php',
6126 'CommandeFournisseur' =>
'/fourn/class/fournisseur.commande.class.php',
6127 'FactureFournisseur' =>
'/fourn/class/fournisseur.facture.class.php',
6128 'FactureFournisseurRec' =>
'/fourn/class/fournisseur.facture-rec.class.php',
6129 'Reception' =>
'/reception/class/reception.class.php',
6130 'SupplierProposal' =>
'/supplier_proposal/class/supplier_proposal.class.php',
6131 'ProductFournisseur' =>
'/fourn/class/fournisseur.product.class.php',
6132 'Product' =>
'/product/class/product.class.php',
6134 'Project' =>
'/projet/class/project.class.php',
6135 'User' =>
'/user/class/user.class.php',
6136 'Account' =>
'/compta/bank/class/account.class.php',
6137 'ConferenceOrBoothAttendee' =>
'/eventorganization/class/conferenceorboothattendee.class.php',
6138 'Societe' =>
'/societe/class/societe.class.php',
6141 if ($this->db->DDLListTables((
string)
$conf->db->name, $this->db->prefix().
'delivery')) {
6142 $objects[
'Delivery'] =
'/delivery/class/delivery.class.php';
6144 if ($this->db->DDLListTables((
string)
$conf->db->name, $this->db->prefix().
'mrp_mo')) {
6145 $objects[
'Mo'] =
'/mrp/class/mo.class.php';
6147 if ($this->db->DDLListTables((
string)
$conf->db->name, $this->db->prefix().
'don')) {
6148 $objects[
'Don'] =
'/don/class/don.class.php';
6150 if ($this->db->DDLListTables((
string)
$conf->db->name, $this->db->prefix().
'partnership')) {
6151 $objects[
'PartnerShip'] =
'/partnership/class/partnership.class.php';
6153 if ($this->db->DDLListTables((
string)
$conf->db->name, $this->db->prefix().
'fichinter')) {
6154 $objects[
'Fichinter'] =
'/fichinter/class/fichinter.class.php';
6156 if ($this->db->DDLListTables((
string)
$conf->db->name, $this->db->prefix().
'ticket')) {
6157 $objects[
'Ticket'] =
'/ticket/class/ticket.class.php';
6161 foreach ($objects as $object_name => $object_file) {
6171 require_once DOL_DOCUMENT_ROOT.$object_file;
6173 if (!$object_name::replaceThirdparty($this->db, $soc_origin->id, $this->id)) {
6175 $this->error = $this->db->lasterror();
6183 $parameters = array(
'soc_origin' => $soc_origin->id,
'soc_dest' => $this->id);
6184 $reshook = $hookmanager->executeHooks(
'replaceThirdparty', $parameters, $this, $action);
6187 $this->error = $hookmanager->error;
6188 $this->errors = $hookmanager->errors;
6195 $this->context = array(
'merge' => 1,
'mergefromid' => $soc_origin->id,
'mergefromname' => $soc_origin->name);
6198 $result = $this->call_trigger(
'COMPANY_MODIFY', $user);
6207 if ($soc_origin->delete($soc_origin->id, $user) < 1) {
6208 $this->error = $soc_origin->error;
6209 $this->errors = $soc_origin->errors;
6217 if (!empty(
$conf->societe->multidir_output[$this->entity])) {
6218 $srcdir =
$conf->societe->multidir_output[$this->entity].
"/".$soc_origin->id;
6219 $destdir =
$conf->societe->multidir_output[$this->entity].
"/".$this->id;
6223 foreach ($dirlist as $filetomove) {
6224 $destfile = $destdir.
'/'.$filetomove[
'relativename'];
6226 dol_move($filetomove[
'fullname'], $destfile,
'0', 0, 0, 1);
6234 $this->db->commit();
6237 $langs->load(
"errors");
6238 $this->error = $langs->trans(
'ErrorsThirdpartyMerge');
6239 $this->db->rollback();
Class to manage members of a foundation.
Class to manage withdrawal receipts.
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
isObjectUsed($id=0, $entity=0)
Function to check if an object is used by others (by children).
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraLanguages($trigger='', $userused=null)
Add/Update all extra languages values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif')
Setter generic.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage bank accounts description of third parties.
Class to stock current configuration.
Class to manage absolute discounts.
Class to manage Dolibarr database access.
Class to manage suppliers invoices.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage invoices.
Class to manage triggers.
static getIdAndTxFromCode($dbs, $code, $date_document=0)
Get id and rate of currency from code.
static getIdFromCode($dbs, $code)
Get id of currency from code.
Class to manage third parties objects (customers, suppliers, prospects...)
setParent($id)
Define parent company of current company.
getLibProspLevel()
Return prostect level.
thirdparty_and_contact_email_array($addthirdparty=0)
Return list of contacts emails existing for third party.
setAsCustomer()
Define third party as a customer.
findNearest($rowid=0, $ref='', $ref_ext='', $barcode='', $idprof1='', $idprof2='', $idprof3='', $idprof4='', $idprof5='', $idprof6='', $email='', $ref_alias='', $is_client=0, $is_supplier=0)
Search the thirdparty that match the most the provided parameters.
codefournisseur_modifiable()
Check if a vendor code is editable in the code control module configuration.
contact_get_property($rowid, $mode)
Return property of contact from its id.
check_codeclient()
Check customer code.
verify()
Check properties of third party are ok (like name, third party codes, ...) Used before an add or upda...
isInSEPA()
Return if a company is inside the SEPA zone (Single Euro Payment Area)
LibProspCommStatut($status, $mode=0, $label='', $picto='')
Return label of a given status.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
get_all_rib()
Return Array of RIB.
get_codecompta($type)
Assigns a accounting code from the accounting code module.
__construct($db)
Constructor.
del_commercial(User $user, $commid)
Add link to sales representative.
info($id)
Load information for tab info.
has_projects()
Indicates if the company has projects.
setThirdpartyType($typent_id)
Define third-party type of current company.
isACompany()
Check if third party is a company (Business) or an end user (Consumer)
getOutstandingBills($mode='customer', $late=0)
Return amount of bill not yet paid and total of all invoices.
useLocalTax($localTaxNum=0, $mode=0, $thirdparty=null)
Check if we must use localtax feature or not according to country (country of $mysoc in most cases).
add_commercial(User $user, $commid)
Add link to sales representative.
LibStatut($status, $mode=0)
Return the label of a given status.
update($id, User $user, $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0, $action='update', $nosyncmember=1)
Update parameters of third party.
const PROSPECT
Third party type is a prospect.
setPaymentMethods($id)
Change the payments methods.
create(User $user, $notrigger=0)
Create third party in database.
set_as_client()
Define third party as a customer.
getOutstandingOrders($mode='customer')
Return amount of order not yet paid and total and list of all orders.
id_prof_exists($idprof, $value, $socid=0)
Verify if a profid exists into database for others thirds.
useRevenueStamp()
Check if we must use revenue stamps feature or not according to country (country of $mysoc in most ca...
id_prof_check($idprof)
Check the validity of a professional identifier according to the properties (country) of the thirdpar...
id_prof_verifiable($idprof)
Returns if a profid should be verified to be unique.
create_from_member(Adherent $member, $socname='', $socalias='', $customercode='')
Create a third party into database from a member object.
getParentsForCompany($company_id, $parents=array())
Get parents for company.
set_remise_except($remise, User $user, $desc, $vatrate='', $discount_type=0, $price_base_type='HT')
Add a discount for third party.
const CUSTOMER_AND_PROSPECT
Third party type is a customer and a prospect.
getContacts($list=0, $code='', $element='', $status=-1)
Get array of all contacts for a society (stored in societe_contacts instead of element_contacts for a...
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
set_remise_client($remise, $note, User $user)
Defines the company as a customer.
getOutstandingProposals($mode='customer')
Return amount of proposal not yet paid and total an dlist of all proposals.
const CUSTOMER
Third party type is a customer.
fetch($rowid, $ref='', $ref_ext='', $barcode='', $idprof1='', $idprof2='', $idprof3='', $idprof4='', $idprof5='', $idprof6='', $email='', $ref_alias='', $is_client=0, $is_supplier=0)
Load a third party from database into memory.
getSalesRepresentatives(User $user, $mode=0, $sortfield=null, $sortorder=null)
Return array of sales representatives.
LoadSupplierCateg()
Load the list of provider categories.
getAvailableDiscounts($user=null, $filter='', $maxvalue=0, $discount_type=0)
Returns amount of included taxes of the current discounts/credits available from the company.
display_rib($mode='label')
Return bank number property of thirdparty (label or rum)
contact_array_objects()
Return the contact list of this company.
isInEEC()
Return if a company is inside the EEC (European Economic Community)
setCategories($categories, $type_categ, $remove_existing=true)
Sets object to supplied categories.
codeclient_modifiable()
Check if a client code is editable based on the parameters of the code control module.
fetchPartnerships($mode)
Function to get partnerships array.
setBankAccount($fk_account, $notrigger=0, $userused=null)
Change the bank account.
validateFamilyTree($idparent, $idchild, $counter=0)
Check if a thirdparty $idchild is or not inside the parents (or grand parents) of another thirdparty ...
mergeCompany($soc_origin_id)
Merge a company with current one, deleting the given company $soc_origin_id.
const NO_SUPPLIER
Third party supplier flag is not supplier.
getNbOfEMailings()
Return number of mass Emailing received by this contacts with its email.
setNoEmail($no_email, $unsubscribegroup='')
Set "blacklist" mailing status.
setAccountancyCode($type, $value)
Sets an accountancy code for a thirdparty.
getOpenCreditNotesNotYetConvertedIntoDiscount($discount_type=0)
Return amount (with tax) of discounts currently available for a company, user or other criteria.
getChildrenForCompany($company_id)
Get children for company.
getLibCustProspStatut()
Return label of status customer is prospect/customer.
getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0, $save_lastsearch_value=-1, $noaliasinname=0, $target='', $morecss='')
Return a link on thirdparty (with picto)
getLibStatut($mode=0)
Return label of status (activity, closed)
const NO_CUSTOMER
Third party type is no customer.
calculateVATNumberFromProperties($thirdparty)
Calculate VAT intracommunity number for a thirdparty if missing, from the professional ID.
LibProspLevel($fk_prospectlevel)
Return label of prospect level.
set_remise_supplier($remise, $note, User $user)
Defines the company as a customer.
create_individual(User $user, $no_email=0, $tags=array(), $notrigger=0)
Create a contact/address from thirdparty.
getNoEmail()
get "blacklist" mailing status set no_email attribute to 1 or 0
getLibProspCommStatut($mode=0, $label='')
Return status of prospect.
AddFournisseurInCategory($categorie_id)
Insert link supplier - category.
contact_property_array($mode='email', $hidedisabled=0)
Return list of contacts emails or mobile existing for third party.
LibCustProspStatut($status)
Return the label of the customer/prospect status.
getTypeUrl($withpicto=0, $option='', $notooltip=0, $tag='a')
Return link(s) on type of thirdparty (with picto)
setPriceLevel($price_level, User $user)
Set the price level.
setPaymentTerms($id, $deposit_percent=null)
Change the payments terms.
thirdparty_and_contact_phone_array()
Return list of contacts mobile phone existing for third party.
deprecatedProperties()
Provide list of deprecated properties and replacements.
getTooltipContentArray($params)
getTooltipContentArray
useNPR()
Check if we must use NPR Vat (french stupid rule) or not according to country (country of $mysoc in m...
setSalesRep($salesrep, $onlyAdd=false)
Sets sales representatives of the thirdparty.
getKanbanView($option='', $arraydata=array())
Return clickable link of object (with optional picto)
const SUPPLIER
Third party supplier flag is a supplier.
check_codefournisseur()
Check supplier code.
contact_array()
Return the contact list of this company.
initAsSpecimen()
Initialise an instance with random values.
id_prof_url($idprof, $thirdparty)
Return an url to check online a professional id or empty string.
setMysoc(Conf $conf)
Set properties with value into $conf.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
trait CommonSocialNetworks
Superclass for social networks.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
getState($id, $withcode='0', $dbtouse=null, $withregion=0, $outputlangs=null, $entconv=1)
Return state translated from an id.
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=null)
Move a file into another name.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
clean_url($url, $http=1)
Clean an url string.
dol_now($mode='gmt')
Return date for now.
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=2, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
setEntity($currentobject)
Set entity id to use when to create an object.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs=null, $mode=0, $extralangcode='')
Return a formatted address (part address/zip/town/state) according to country rules.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
img_action($titlealt, $numaction, $picto='', $moreatt='')
Show logo action.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
if(!function_exists( 'utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists( 'str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists( 'str_contains')) formatLogObject($data)
Return a string serialized to be output on log with dol_syslog() An option allow to output log in one...
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
div refaddress div address
query($query, $usesavepoint=0, $type='auto', $result_mode=0)
Execute a SQL request and return the resultset.
fetch_object($resultset)
Returns the current line (as an object) for the resultset cursor.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
isValidSiren($siren, $lengthonly=0)
Check the syntax validity of a SIREN.
isValidProfIds($idprof, $thirdparty, $lenghtonly=0)
Check the validity of a professional identifier according to the properties (country) of the company ...
isValidSiret($siret, $lengthonly=0)
Check the syntax validity of a SIRET.
$conf db name
Only used if Module[ID]Name translation string is not found.