42require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/commonsocialnetworks.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
61 public $module =
'societe';
66 public $element =
'societe';
71 public $table_element =
'societe';
76 public $fk_element =
'fk_soc';
81 public $fieldsforcombobox =
'nom,name_alias';
86 protected $childtables = array(
87 'supplier_proposal' => array(
'name' =>
'SupplierProposal'),
88 'propal' => array(
'name' =>
'Proposal'),
89 'commande' => array(
'name' =>
'Order'),
90 'facture' => array(
'name' =>
'Invoice'),
91 'facture_rec' => array(
'name' =>
'RecurringInvoiceTemplate'),
92 'contrat' => array(
'name' =>
'Contract'),
93 'fichinter' => array(
'name' =>
'Fichinter'),
94 'facture_fourn' => array(
'name' =>
'SupplierInvoice'),
95 'commande_fournisseur' => array(
'name' =>
'SupplierOrder'),
96 'projet' => array(
'name' =>
'Project'),
97 'expedition' => array(
'name' =>
'Shipment'),
98 'prelevement_lignes' => array(
'name' =>
'DirectDebitRecord'),
105 protected $childtablesoncascade = array(
107 'product_fournisseur_price',
108 'product_customer_price_log',
109 'product_customer_price',
110 '@Contact:/contact/class/contact.class.php:fk_soc',
115 'societe_remise_except',
116 'societe_commerciaux',
126 public $picto =
'company';
132 public $ismultientitymanaged = 1;
137 public $isextrafieldmanaged = 1;
143 public $restrictiononfksoc = 1;
154 public $SupplierCategories = array();
160 public $prefixCustomerIsRequired;
191 public $fields = array(
192 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'noteditable'=>1,
'notnull'=> 1,
'index'=>1,
'position'=>1,
'comment'=>
'Id',
'css'=>
'left'),
193 'parent' =>array(
'type'=>
'integer',
'label'=>
'Parent',
'enabled'=>1,
'visible'=>-1,
'position'=>20),
194 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
195 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
196 'nom' =>array(
'type'=>
'varchar(128)',
'label'=>
'Nom',
'enabled'=>1,
'visible'=>-1,
'position'=>35,
'showoncombobox'=>1),
197 'name_alias' =>array(
'type'=>
'varchar(128)',
'label'=>
'Name alias',
'enabled'=>1,
'visible'=>-1,
'position'=>36,
'showoncombobox'=>2),
198 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>40,
'index'=>1),
199 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefExt',
'enabled'=>1,
'visible'=>0,
'position'=>45),
200 'code_client' =>array(
'type'=>
'varchar(24)',
'label'=>
'CustomerCode',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
201 'code_fournisseur' =>array(
'type'=>
'varchar(24)',
'label'=>
'SupplierCode',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
202 'code_compta' =>array(
'type'=>
'varchar(24)',
'label'=>
'CustomerAccountancyCode',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
203 'code_compta_fournisseur' =>array(
'type'=>
'varchar(24)',
'label'=>
'SupplierAccountancyCode',
'enabled'=>1,
'visible'=>-1,
'position'=>70),
204 'address' =>array(
'type'=>
'varchar(255)',
'label'=>
'Address',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
205 'zip' =>array(
'type'=>
'varchar(25)',
'label'=>
'Zip',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
206 'town' =>array(
'type'=>
'varchar(50)',
'label'=>
'Town',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
207 'fk_departement' =>array(
'type'=>
'integer',
'label'=>
'State',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
208 'fk_pays' =>array(
'type'=>
'integer:Ccountry:core/class/ccountry.class.php',
'label'=>
'Country',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
209 'phone' =>array(
'type'=>
'varchar(20)',
'label'=>
'Phone',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
210 'fax' =>array(
'type'=>
'varchar(20)',
'label'=>
'Fax',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
211 'url' =>array(
'type'=>
'varchar(255)',
'label'=>
'Url',
'enabled'=>1,
'visible'=>-1,
'position'=>110),
212 'email' =>array(
'type'=>
'varchar(128)',
'label'=>
'Email',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
213 'socialnetworks' =>array(
'type'=>
'text',
'label'=>
'Socialnetworks',
'enabled'=>1,
'visible'=>-1,
'position'=>120),
214 'fk_effectif' =>array(
'type'=>
'integer',
'label'=>
'Workforce',
'enabled'=>1,
'visible'=>-1,
'position'=>170),
215 'fk_typent' =>array(
'type'=>
'integer',
'label'=>
'TypeOfCompany',
'enabled'=>1,
'visible'=>-1,
'position'=>175,
'csslist'=>
'minwidth200'),
216 'fk_forme_juridique' =>array(
'type'=>
'integer',
'label'=>
'JuridicalStatus',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
217 'fk_currency' =>array(
'type'=>
'varchar(3)',
'label'=>
'Currency',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
218 'siren' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof1',
'enabled'=>1,
'visible'=>-1,
'position'=>190),
219 'siret' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof2',
'enabled'=>1,
'visible'=>-1,
'position'=>195),
220 'ape' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof3',
'enabled'=>1,
'visible'=>-1,
'position'=>200),
221 'idprof4' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof4',
'enabled'=>1,
'visible'=>-1,
'position'=>205),
222 'idprof5' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof5',
'enabled'=>1,
'visible'=>-1,
'position'=>206),
223 'idprof6' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof6',
'enabled'=>1,
'visible'=>-1,
'position'=>207),
224 'tva_intra' =>array(
'type'=>
'varchar(20)',
'label'=>
'Tva intra',
'enabled'=>1,
'visible'=>-1,
'position'=>210),
225 'capital' =>array(
'type'=>
'double(24,8)',
'label'=>
'Capital',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
226 'fk_stcomm' =>array(
'type'=>
'integer',
'label'=>
'CommercialStatus',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>220),
227 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>225),
228 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>230),
229 'prefix_comm' =>array(
'type'=>
'varchar(5)',
'label'=>
'Prefix comm',
'enabled'=>
"getDolGlobalInt('SOCIETE_USEPREFIX')",
'visible'=>-1,
'position'=>235),
230 'client' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Client',
'enabled'=>1,
'visible'=>-1,
'position'=>240),
231 'fournisseur' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Fournisseur',
'enabled'=>1,
'visible'=>-1,
'position'=>245),
232 'supplier_account' =>array(
'type'=>
'varchar(32)',
'label'=>
'Supplier account',
'enabled'=>1,
'visible'=>-1,
'position'=>250),
233 'fk_prospectlevel' =>array(
'type'=>
'varchar(12)',
'label'=>
'ProspectLevel',
'enabled'=>1,
'visible'=>-1,
'position'=>255),
234 'customer_bad' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Customer bad',
'enabled'=>1,
'visible'=>-1,
'position'=>260),
235 'customer_rate' =>array(
'type'=>
'double',
'label'=>
'Customer rate',
'enabled'=>1,
'visible'=>-1,
'position'=>265),
236 'supplier_rate' =>array(
'type'=>
'double',
'label'=>
'Supplier rate',
'enabled'=>1,
'visible'=>-1,
'position'=>270),
237 'fk_user_creat' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-2,
'position'=>275),
238 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>280),
241 'mode_reglement' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Mode reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>295),
242 'cond_reglement' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Cond reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>300),
243 'deposit_percent' =>array(
'type'=>
'varchar(63)',
'label'=>
'DepositPercent',
'enabled'=>1,
'visible'=>-1,
'position'=>301),
244 'mode_reglement_supplier' =>array(
'type'=>
'integer',
'label'=>
'Mode reglement supplier',
'enabled'=>1,
'visible'=>-1,
'position'=>305),
245 'cond_reglement_supplier' =>array(
'type'=>
'integer',
'label'=>
'Cond reglement supplier',
'enabled'=>1,
'visible'=>-1,
'position'=>308),
246 'outstanding_limit' =>array(
'type'=>
'double(24,8)',
'label'=>
'OutstandingBill',
'enabled'=>1,
'visible'=>-1,
'position'=>310,
'isameasure'=>1),
247 'order_min_amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'Order min amount',
'enabled'=>
'isModEnabled("commande") && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)',
'visible'=>-1,
'position'=>315,
'isameasure'=>1),
248 'supplier_order_min_amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'Supplier order min amount',
'enabled'=>
'isModEnabled("commande") && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)',
'visible'=>-1,
'position'=>320,
'isameasure'=>1),
249 'fk_shipping_method' =>array(
'type'=>
'integer',
'label'=>
'Fk shipping method',
'enabled'=>1,
'visible'=>-1,
'position'=>330),
250 'tva_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Tva assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>335),
251 'localtax1_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Localtax1 assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>340),
252 'localtax1_value' =>array(
'type'=>
'double(6,3)',
'label'=>
'Localtax1 value',
'enabled'=>1,
'visible'=>-1,
'position'=>345),
253 'localtax2_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Localtax2 assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>350),
254 'localtax2_value' =>array(
'type'=>
'double(6,3)',
'label'=>
'Localtax2 value',
'enabled'=>1,
'visible'=>-1,
'position'=>355),
255 'vat_reverse_charge' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Vat reverse charge',
'enabled'=>1,
'visible'=>-1,
'position'=>335),
256 'barcode' =>array(
'type'=>
'varchar(255)',
'label'=>
'Barcode',
'enabled'=>1,
'visible'=>-1,
'position'=>360),
257 'price_level' =>array(
'type'=>
'integer',
'label'=>
'Price level',
'enabled'=>
'$conf->global->PRODUIT_MULTIPRICES || $conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES',
'visible'=>-1,
'position'=>365),
258 'default_lang' =>array(
'type'=>
'varchar(6)',
'label'=>
'Default lang',
'enabled'=>1,
'visible'=>-1,
'position'=>370),
259 'canvas' =>array(
'type'=>
'varchar(32)',
'label'=>
'Canvas',
'enabled'=>1,
'visible'=>-1,
'position'=>375),
260 'fk_barcode_type' =>array(
'type'=>
'integer',
'label'=>
'Fk barcode type',
'enabled'=>1,
'visible'=>-1,
'position'=>405),
261 'webservices_url' =>array(
'type'=>
'varchar(255)',
'label'=>
'Webservices url',
'enabled'=>1,
'visible'=>-1,
'position'=>410),
262 'webservices_key' =>array(
'type'=>
'varchar(128)',
'label'=>
'Webservices key',
'enabled'=>1,
'visible'=>-1,
'position'=>415),
263 'fk_incoterms' =>array(
'type'=>
'integer',
'label'=>
'Fk incoterms',
'enabled'=>1,
'visible'=>-1,
'position'=>425),
264 'location_incoterms' =>array(
'type'=>
'varchar(255)',
'label'=>
'Location incoterms',
'enabled'=>1,
'visible'=>-1,
'position'=>430),
265 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>435),
266 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'LastMainDoc',
'enabled'=>1,
'visible'=>-1,
'position'=>270),
267 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>-1,
'position'=>440),
268 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Multicurrency code',
'enabled'=>1,
'visible'=>-1,
'position'=>445),
269 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'PaymentBankAccount',
'enabled'=>1,
'visible'=>-1,
'position'=>450),
270 'fk_warehouse' =>array(
'type'=>
'integer',
'label'=>
'Warehouse',
'enabled'=>1,
'visible'=>-1,
'position'=>455),
271 'logo' =>array(
'type'=>
'varchar(255)',
'label'=>
'Logo',
'enabled'=>1,
'visible'=>-1,
'position'=>400),
272 'logo_squarred' =>array(
'type'=>
'varchar(255)',
'label'=>
'Logo squarred',
'enabled'=>1,
'visible'=>-1,
'position'=>401),
273 'status' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>-1,
'position'=>500),
274 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000),
333 public $departement_code;
476 public $socialobject;
486 public $tva_assuj = 1;
497 public $vat_reverse_charge = 0;
500 public $localtax1_assuj;
501 public $localtax1_value;
502 public $localtax2_assuj;
503 public $localtax2_value;
518 public $typent_id = 0;
521 public $effectif_id = 0;
522 public $forme_juridique_code;
523 public $forme_juridique = 0;
525 public $remise_percent;
526 public $remise_supplier_percent;
528 public $mode_reglement_id;
529 public $cond_reglement_id;
530 public $deposit_percent;
531 public $mode_reglement_supplier_id;
532 public $cond_reglement_supplier_id;
533 public $transport_mode_supplier_id;
538 public $fk_prospectlevel;
551 public $date_modification;
558 public $user_modification;
564 public $date_creation;
571 public $user_creation;
583 public $prospect = 0;
601 public $code_fournisseur;
607 public $code_compta_client;
621 public $accountancy_code_customer;
627 public $code_compta_fournisseur;
633 public $accountancy_code_supplier;
639 public $code_compta_product;
652 public $note_private;
670 public $stcomm_picto;
676 public $status_prospect_label;
687 public $outstanding_limit;
692 public $order_min_amount;
697 public $supplier_order_min_amount;
703 public $commercial_id;
715 public $default_lang;
741 public $webservices_url;
747 public $webservices_key;
767 public $logo_squarred;
772 public $logo_squarred_small;
777 public $logo_squarred_mini;
782 public $accountancy_code_sell;
787 public $accountancy_code_buy;
793 public $fk_multicurrency;
799 public $fk_warehouse;
804 public $multicurrency_code;
808 public $partnerships = array();
814 public $bank_account;
817 const STATUS_CEASED = 0;
818 const STATUS_INACTIVITY = 1;
864 $this->fournisseur = 0;
865 $this->typent_id = 0;
866 $this->effectif_id = 0;
867 $this->forme_juridique_code = 0;
868 $this->tva_assuj = 1;
869 $this->vat_reverse_charge = 0;
873 $this->fields[
'address'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
874 $this->fields[
'zip'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
875 $this->fields[
'town'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
891 global $langs, $conf;
896 if (empty($this->
status)) {
899 $this->
name = $this->
name ? trim($this->
name) : trim($this->nom);
901 $this->nom = $this->name;
902 if (empty($this->client)) {
905 if (empty($this->fournisseur)) {
906 $this->fournisseur = 0;
908 $this->import_key = trim($this->import_key);
910 $this->accountancy_code_customer = trim($this->code_compta);
911 $this->accountancy_code_supplier = trim($this->code_compta_fournisseur);
912 $this->accountancy_code_buy = trim($this->accountancy_code_buy);
913 $this->accountancy_code_sell = trim($this->accountancy_code_sell);
915 if (!empty($this->multicurrency_code)) {
918 if (empty($this->fk_multicurrency)) {
919 $this->multicurrency_code =
'';
920 $this->fk_multicurrency = 0;
930 if ($this->code_client == -1 || $this->code_client ===
'auto') {
933 if ($this->code_fournisseur == -1 || $this->code_fournisseur ===
'auto') {
939 $result = $this->
verify();
942 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
944 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe (";
946 $sql .=
", name_alias";
949 $sql .=
", fk_user_creat";
950 $sql .=
", fk_typent";
954 $sql .=
", fk_stcomm";
955 $sql .=
", fk_incoterms";
956 $sql .=
", location_incoterms";
957 $sql .=
", import_key";
958 $sql .=
", fk_multicurrency";
959 $sql .=
", multicurrency_code";
961 $sql .=
", vat_reverse_charge";
962 $sql .=
", accountancy_code_buy";
963 $sql .=
", accountancy_code_sell";
965 $sql .=
") VALUES ('".$this->db->escape($this->name).
"', '".$this->db->escape($this->name_alias).
"', ".((int) $this->entity).
", '".$this->db->idate($now).
"'";
966 $sql .=
", ".(!empty($user->id) ? ((int) $user->id) :
"null");
967 $sql .=
", ".(!empty($this->typent_id) ? ((int) $this->typent_id) :
"null");
968 $sql .=
", ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null");
969 $sql .=
", ".((int) $this->
status);
970 $sql .=
", ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
972 $sql .=
", ".(int) $this->fk_incoterms;
973 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
974 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
975 $sql .=
", ".(int) $this->fk_multicurrency;
976 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
978 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
979 $sql .=
", '" . $this->db->escape($this->accountancy_code_buy) .
"'";
980 $sql .=
", '" . $this->db->escape($this->accountancy_code_sell) .
"'";
984 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
985 $result = $this->db->query($sql);
987 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"societe");
989 $ret = $this->
update($this->
id, $user, 0, 1, 1,
'add');
993 $this->db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int) $conf->entity));
995 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
998 $sql .=
", vat_reverse_charge";
999 $sql .=
", accountancy_code_customer";
1000 $sql .=
", accountancy_code_supplier";
1001 $sql .=
", accountancy_code_buy";
1002 $sql .=
", accountancy_code_sell";
1003 $sql .=
") VALUES (";
1005 $sql .=
", ".((int) $conf->entity);
1006 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1007 $sql .=
", '".$this->db->escape($this->accountancy_code_customer).
"'";
1008 $sql .=
", '".$this->db->escape($this->accountancy_code_supplier).
"'";
1009 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1010 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1012 $result = $this->db->query($sql);
1015 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1020 if ($this->commercial_id !=
'' && $this->commercial_id != -1) {
1022 } elseif (!$user->hasRight(
'societe',
'client',
'voir')) {
1030 $result = $this->
call_trigger(
'COMPANY_CREATE', $user);
1041 dol_syslog(get_class($this).
"::Create success id=".$this->
id);
1042 $this->db->commit();
1045 dol_syslog(get_class($this).
"::Create echec update ".$this->error.(empty($this->errors) ?
'' :
' '.join(
',', $this->errors)), LOG_ERR);
1046 $this->db->rollback();
1050 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1051 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", $this->name);
1054 $this->error = $this->db->lasterror();
1057 $this->db->rollback();
1061 $this->db->rollback();
1062 dol_syslog(get_class($this).
"::Create fails verify ".join(
',', $this->errors), LOG_WARNING);
1087 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1088 $contact =
new Contact($this->db);
1090 $contact->name = $this->name_bis;
1091 $contact->firstname = $this->firstname;
1092 $contact->civility_id = $this->civility_id;
1093 $contact->socid = $this->id;
1094 $contact->statut = 1;
1095 $contact->status = 1;
1097 $contact->country_id = $this->country_id;
1098 $contact->state_id = $this->state_id;
1099 $contact->address = $this->address;
1100 $contact->email = $this->email;
1101 $contact->zip = $this->zip;
1102 $contact->town = $this->town;
1104 $contact->phone_pro = $this->phone;
1106 $contactId = $contact->create($user, $notrigger);
1107 if ($contactId < 0) {
1109 $this->error = $contact->error;
1110 $this->errors = $contact->errors;
1111 dol_syslog(get_class($this).
"::create_individual ERROR:".$this->error, LOG_ERR);
1114 if (empty($error) && is_array($tags) && !empty($tags)) {
1115 $result = $contact->setCategories($tags);
1118 $this->error = $contact->error;
1119 $this->errors = array_merge($this->errors, $contact->errors);
1120 dol_syslog(get_class($this).
"::create_individual Affect Tag ERROR:".$this->error, LOG_ERR);
1121 $contactId = $result;
1125 if (empty($error) && isModEnabled(
'mailing') && !empty($contact->email) && isset($no_email)) {
1126 $result = $contact->setNoEmail($no_email);
1128 $this->error = $contact->error;
1129 $this->errors = array_merge($this->errors, $contact->errors);
1130 dol_syslog(get_class($this).
"::create_individual set mailing status ERROR:".$this->error, LOG_ERR);
1131 $contactId = $result;
1135 if (empty($error)) {
1136 dol_syslog(get_class($this).
"::create_individual success");
1137 $this->db->commit();
1139 $this->db->rollback();
1153 global $conf, $langs, $mysoc;
1156 $this->errors = array();
1160 $this->nom = $this->name;
1163 $this->errors[] =
'ErrorBadThirdPartyName';
1167 if ($this->client) {
1169 if ($rescode != 0 && $rescode != -5) {
1170 if ($rescode == -1) {
1171 $this->errors[] =
'ErrorBadCustomerCodeSyntax';
1172 } elseif ($rescode == -2) {
1173 $this->errors[] =
'ErrorCustomerCodeRequired';
1174 } elseif ($rescode == -3) {
1175 $this->errors[] =
'ErrorCustomerCodeAlreadyUsed';
1176 } elseif ($rescode == -4) {
1177 $this->errors[] =
'ErrorPrefixRequired';
1179 $this->errors[] =
'ErrorUnknownOnCustomerCodeCheck';
1186 if ($this->fournisseur) {
1188 if ($rescode != 0 && $rescode != -5) {
1189 if ($rescode == -1) {
1190 $this->errors[] =
'ErrorBadSupplierCodeSyntax';
1191 } elseif ($rescode == -2) {
1192 $this->errors[] =
'ErrorSupplierCodeRequired';
1193 } elseif ($rescode == -3) {
1194 $this->errors[] =
'ErrorSupplierCodeAlreadyUsed';
1195 } elseif ($rescode == -4) {
1196 $this->errors[] =
'ErrorPrefixRequired';
1198 $this->errors[] =
'ErrorUnknownOnSupplierCodeCheck';
1205 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL',
'TVA_INTRA',
'ACCOUNTANCY_CODE_CUSTOMER',
'ACCOUNTANCY_CODE_SUPPLIER');
1206 foreach ($array_to_check as $key) {
1207 $keymin = strtolower($key);
1208 if ($key ==
'ACCOUNTANCY_CODE_CUSTOMER') {
1209 $keymin =
'code_compta';
1210 } elseif ($key ==
'ACCOUNTANCY_CODE_SUPPLIER') {
1211 $keymin =
'code_compta_fournisseur';
1213 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
1214 $vallabel = $this->$keymin;
1219 if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) {
1220 $idprof_mandatory =
'SOCIETE_'.$key.
'_MANDATORY';
1222 $langs->load(
"errors");
1224 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->transcountry(
'ProfId'.$i, $this->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1231 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1232 $langs->load(
"errors");
1234 $this->errors[] = $langs->transcountry(
'ProfId'.$i, $this->country_code).
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1240 if ($key ==
'EMAIL') {
1243 $langs->load(
"errors");
1245 $this->errors[] = $langs->trans(
"ErrorBadEMail", $this->email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1250 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1251 $langs->load(
"errors");
1253 $this->errors[] = $langs->trans(
'Email').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1256 } elseif ($key ==
'TVA_INTRA') {
1259 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1260 $langs->load(
"errors");
1262 $this->errors[] = $langs->trans(
'VATIntra').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1265 } elseif ($key ==
'ACCOUNTANCY_CODE_CUSTOMER' && !empty($this->client)) {
1268 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1269 $langs->loadLangs(array(
"errors",
'compta'));
1271 $this->errors[] = $langs->trans(
'CustomerAccountancyCodeShort') .
" " . $langs->trans(
"ErrorProdIdAlreadyExist", $vallabel) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1276 if (
getDolGlobalString(
'SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_MANDATORY') && (!isset($vallabel) || trim($vallabel) ===
'')) {
1277 $langs->loadLangs(array(
"errors",
'compta'));
1279 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
'CustomerAccountancyCodeShort')) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1281 } elseif ($key ==
'ACCOUNTANCY_CODE_SUPPLIER' && !empty($this->fournisseur)) {
1284 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1285 $langs->loadLangs(array(
"errors",
'compta'));
1287 $this->errors[] = $langs->trans(
'SupplierAccountancyCodeShort') .
" " . $langs->trans(
"ErrorProdIdAlreadyExist", $vallabel) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1292 if (
getDolGlobalString(
'SOCIETE_ACCOUNTANCY_CODE_SUPPLIER_MANDATORY') && (!isset($vallabel) || trim($vallabel) ===
'')) {
1293 $langs->loadLangs(array(
"errors",
'compta'));
1295 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
'SupplierAccountancyCodeShort')) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1320 public function update($id, $user =
'', $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action =
'update', $nosyncmember = 1)
1322 global $langs, $conf, $hookmanager;
1324 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1332 dol_syslog(get_class($this).
"::Update id=".$id.
" call_trigger=".$call_trigger.
" allowmodcodeclient=".$allowmodcodeclient.
" allowmodcodefournisseur=".$allowmodcodefournisseur);
1338 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
1339 $this->
name = $this->
name ? trim($this->
name) : trim($this->nom);
1340 $this->nom = $this->name;
1341 $this->name_alias = trim($this->name_alias);
1342 $this->ref_ext = trim($this->ref_ext);
1343 $this->address = $this->address ? trim($this->address) : trim($this->address);
1344 $this->zip = $this->zip ? trim($this->zip) : trim($this->zip);
1345 $this->town = $this->town ? trim($this->town) : trim($this->town);
1346 $this->state_id = trim($this->state_id);
1347 $this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
1348 $this->phone = trim($this->phone);
1349 $this->phone = preg_replace(
"/\s/",
"", $this->phone);
1350 $this->phone = preg_replace(
"/\./",
"", $this->phone);
1351 $this->fax = trim($this->fax);
1352 $this->fax = preg_replace(
"/\s/",
"", $this->fax);
1353 $this->fax = preg_replace(
"/\./",
"", $this->fax);
1354 $this->email = trim($this->email);
1355 $this->url = $this->url ?
clean_url($this->url, 0) :
'';
1356 $this->note_private = trim($this->note_private);
1357 $this->note_public = trim($this->note_public);
1358 $this->idprof1 = trim($this->idprof1);
1359 $this->idprof2 = trim($this->idprof2);
1360 $this->idprof3 = trim($this->idprof3);
1361 $this->idprof4 = trim($this->idprof4);
1362 $this->idprof5 = (!empty($this->idprof5) ? trim($this->idprof5) :
'');
1363 $this->idprof6 = (!empty($this->idprof6) ? trim($this->idprof6) :
'');
1364 $this->prefix_comm = trim($this->prefix_comm);
1365 $this->outstanding_limit =
price2num($this->outstanding_limit);
1366 $this->order_min_amount =
price2num($this->order_min_amount);
1367 $this->supplier_order_min_amount =
price2num($this->supplier_order_min_amount);
1369 $this->tva_assuj = trim($this->tva_assuj);
1371 $this->vat_reverse_charge = empty($this->vat_reverse_charge) ?
'0' :
'1';
1372 if (empty($this->
status)) {
1376 if (!empty($this->multicurrency_code)) {
1379 if (empty($this->fk_multicurrency)) {
1380 $this->multicurrency_code =
'';
1381 $this->fk_multicurrency = 0;
1385 $this->localtax1_assuj = trim($this->localtax1_assuj);
1386 $this->localtax2_assuj = trim($this->localtax2_assuj);
1388 $this->localtax1_value = trim($this->localtax1_value);
1389 $this->localtax2_value = trim($this->localtax2_value);
1391 if ($this->capital !=
'') {
1392 $this->capital =
price2num(trim($this->capital));
1394 if (!is_numeric($this->capital)) {
1395 $this->capital =
'';
1398 $this->effectif_id = trim($this->effectif_id);
1399 $this->forme_juridique_code = trim($this->forme_juridique_code);
1402 $this->barcode = trim($this->barcode);
1405 if ($this->code_client == -1 || $this->code_client ===
'auto') {
1408 if ($this->code_fournisseur == -1 || $this->code_fournisseur ===
'auto') {
1412 $this->code_compta_client = trim(empty($this->code_compta) ? $this->code_compta_client : $this->code_compta);
1413 $this->code_compta = $this->code_compta_client;
1414 $this->code_compta_fournisseur = trim($this->code_compta_fournisseur);
1417 if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) {
1418 $langs->load(
"errors");
1419 $this->error = $langs->trans(
"BadValueForParameterClientOrSupplier");
1424 if (!empty($allowmodcodeclient) && !empty($this->client)) {
1426 if (empty($this->code_compta_client)) {
1437 if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) {
1439 if (empty($this->code_compta_fournisseur)) {
1450 $this->webservices_url = $this->webservices_url ?
clean_url($this->webservices_url, 0) :
'';
1451 $this->webservices_key = trim($this->webservices_key);
1453 $this->accountancy_code_buy = trim($this->accountancy_code_buy);
1454 $this->accountancy_code_sell = trim($this->accountancy_code_sell);
1457 $this->fk_incoterms = (int) $this->fk_incoterms;
1458 $this->location_incoterms = trim($this->location_incoterms);
1465 if ($action !=
'add' && $action !=
'merge') {
1468 $result = $this->
verify();
1472 if (is_array($this->errors)) {
1473 if (in_array(
'ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) {
1474 if (($key = array_search(
'ErrorBadCustomerCodeSyntax', $this->errors)) !==
false) {
1475 unset($this->errors[$key]);
1478 if (in_array(
'ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) {
1479 if (($key = array_search(
'ErrorBadSupplierCodeSyntax', $this->errors)) !==
false) {
1480 unset($this->errors[$key]);
1483 if (empty($this->errors)) {
1490 dol_syslog(get_class($this).
"::update verify ok or not done");
1492 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe SET ";
1493 $sql .=
"entity = ".$this->db->escape($this->entity);
1494 $sql .=
",nom = '".$this->db->escape($this->
name).
"'";
1495 $sql .=
",name_alias = '".$this->db->escape($this->name_alias).
"'";
1496 $sql .=
",ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1497 $sql .=
",address = '".$this->db->escape($this->address).
"'";
1499 $sql .=
",zip = ".(!empty($this->zip) ?
"'".$this->db->escape($this->zip).
"'" :
"null");
1500 $sql .=
",town = ".(!empty($this->town) ?
"'".$this->db->escape($this->town).
"'" :
"null");
1502 $sql .=
",fk_departement = ".((!empty($this->state_id) && $this->state_id > 0) ? ((
int) $this->state_id) :
'null');
1503 $sql .=
",fk_pays = ".((!empty($this->country_id) && $this->country_id > 0) ? ((
int) $this->country_id) :
'null');
1505 $sql .=
",phone = ".(!empty($this->phone) ?
"'".$this->db->escape($this->phone).
"'" :
"null");
1506 $sql .=
",fax = ".(!empty($this->fax) ?
"'".$this->db->escape($this->fax).
"'" :
"null");
1507 $sql .=
",email = ".(!empty($this->email) ?
"'".$this->db->escape($this->email).
"'" :
"null");
1508 $sql .=
",socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1509 $sql .=
",url = ".(!empty($this->url) ?
"'".$this->db->escape($this->url).
"'" :
"null");
1511 $sql .=
",parent = ".($this->parent > 0 ? $this->parent :
"null");
1513 $sql .=
",note_private = ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
1514 $sql .=
",note_public = ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
1516 $sql .=
",siren = '".$this->db->escape($this->idprof1).
"'";
1517 $sql .=
",siret = '".$this->db->escape($this->idprof2).
"'";
1518 $sql .=
",ape = '".$this->db->escape($this->idprof3).
"'";
1519 $sql .=
",idprof4 = '".$this->db->escape($this->idprof4).
"'";
1520 $sql .=
",idprof5 = '".$this->db->escape($this->idprof5).
"'";
1521 $sql .=
",idprof6 = '".$this->db->escape($this->idprof6).
"'";
1523 $sql .=
",tva_assuj = ".($this->tva_assuj !=
'' ?
"'".$this->db->escape($this->tva_assuj).
"'" :
"null");
1524 $sql .=
",tva_intra = '".$this->db->escape($this->tva_intra).
"'";
1526 $sql .=
",vat_reverse_charge = " . ($this->vat_reverse_charge !=
'' ?
"'" . $this->db->escape($this->vat_reverse_charge) .
"'" : 0);
1528 $sql .=
",status = ".((int) $this->
status);
1531 $sql .=
",localtax1_assuj = ".($this->localtax1_assuj !=
'' ?
"'".$this->db->escape($this->localtax1_assuj).
"'" :
"null");
1532 $sql .=
",localtax2_assuj = ".($this->localtax2_assuj !=
'' ?
"'".$this->db->escape($this->localtax2_assuj).
"'" :
"null");
1533 if ($this->localtax1_assuj == 1) {
1534 if ($this->localtax1_value !=
'') {
1535 $sql .=
",localtax1_value =".$this->localtax1_value;
1537 $sql .=
",localtax1_value =0.000";
1540 $sql .=
",localtax1_value =0.000";
1543 if ($this->localtax2_assuj == 1) {
1544 if ($this->localtax2_value !=
'') {
1545 $sql .=
",localtax2_value =".$this->localtax2_value;
1547 $sql .=
",localtax2_value =0.000";
1550 $sql .=
",localtax2_value =0.000";
1553 $sql .=
",capital = ".($this->capital ==
'' ?
"null" : $this->capital);
1555 $sql .=
",prefix_comm = ".(!empty($this->prefix_comm) ?
"'".$this->db->escape($this->prefix_comm).
"'" :
"null");
1557 $sql .=
",fk_effectif = ".($this->effectif_id > 0 ? ((int) $this->effectif_id) :
"null");
1558 if (isset($this->stcomm_id)) {
1559 $sql .=
",fk_stcomm=".(int) $this->stcomm_id;
1561 if (isset($this->typent_id)) {
1562 $sql .=
",fk_typent = ".($this->typent_id > 0 ? ((int) $this->typent_id) :
"0");
1565 $sql .=
",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ?
"'".$this->db->escape($this->forme_juridique_code).
"'" :
"null");
1567 $sql .=
",mode_reglement = ".(!empty($this->mode_reglement_id) ?
"'".$this->db->escape($this->mode_reglement_id).
"'" :
"null");
1568 $sql .=
",cond_reglement = ".(!empty($this->cond_reglement_id) ?
"'".$this->db->escape($this->cond_reglement_id).
"'" :
"null");
1569 $sql .=
",deposit_percent = ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null");
1570 $sql .=
",transport_mode = ".(!empty($this->transport_mode_id) ?
"'".$this->db->escape($this->transport_mode_id).
"'" :
"null");
1571 $sql .=
",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ?
"'".$this->db->escape($this->mode_reglement_supplier_id).
"'" :
"null");
1572 $sql .=
",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ?
"'".$this->db->escape($this->cond_reglement_supplier_id).
"'" :
"null");
1573 $sql .=
",transport_mode_supplier = ".(!empty($this->transport_mode_supplier_id) ?
"'".$this->db->escape($this->transport_mode_supplier_id).
"'" :
"null");
1574 $sql .=
",fk_shipping_method = ".(!empty($this->shipping_method_id) ?
"'".$this->db->escape($this->shipping_method_id).
"'" :
"null");
1576 $sql .=
",client = ".(!empty($this->client) ? $this->client : 0);
1577 $sql .=
",fournisseur = ".(!empty($this->fournisseur) ? $this->fournisseur : 0);
1578 $sql .=
",barcode = ".(!empty($this->barcode) ?
"'".$this->db->escape($this->barcode).
"'" :
"null");
1579 $sql .=
",default_lang = ".(!empty($this->default_lang) ?
"'".$this->db->escape($this->default_lang).
"'" :
"null");
1580 $sql .=
",logo = ".(!empty($this->logo) ?
"'".$this->db->escape($this->logo).
"'" :
"null");
1581 $sql .=
",logo_squarred = ".(!empty($this->logo_squarred) ?
"'".$this->db->escape($this->logo_squarred).
"'" :
"null");
1582 $sql .=
",outstanding_limit= ".($this->outstanding_limit !=
'' ? $this->outstanding_limit :
'null');
1583 $sql .=
",order_min_amount= ".($this->order_min_amount !=
'' ? $this->order_min_amount :
'null');
1584 $sql .=
",supplier_order_min_amount= ".($this->supplier_order_min_amount !=
'' ? $this->supplier_order_min_amount :
'null');
1585 $sql .=
",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel).
"'";
1587 $sql .=
", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1588 $sql .=
", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1590 $sql .=
", code_compta = ".(!empty($this->code_compta_client) ?
"'".$this->db->escape($this->code_compta_client).
"'" :
"null");
1594 $sql .=
", code_compta_fournisseur = ".(($this->code_compta_fournisseur !=
"") ?
"'".$this->db->escape($this->code_compta_fournisseur).
"'" :
"null");
1597 $sql .=
",webservices_url = ".(!empty($this->webservices_url) ?
"'".$this->db->escape($this->webservices_url).
"'" :
"null");
1598 $sql .=
",webservices_key = ".(!empty($this->webservices_key) ?
"'".$this->db->escape($this->webservices_key).
"'" :
"null");
1601 $sql .=
", fk_incoterms = ".((int) $this->fk_incoterms);
1602 $sql .=
", location_incoterms = ".(!empty($this->location_incoterms) ?
"'".$this->db->escape($this->location_incoterms).
"'" :
"null");
1605 $sql .=
", code_client = ".(!empty($this->code_client) ?
"'".$this->db->escape($this->code_client).
"'" :
"null");
1609 $sql .=
", code_fournisseur = ".(!empty($this->code_fournisseur) ?
"'".$this->db->escape($this->code_fournisseur).
"'" :
"null");
1611 $sql .=
", fk_user_modif = ".($user->id > 0 ? $user->id :
"null");
1612 $sql .=
", fk_multicurrency = ".(int) $this->fk_multicurrency;
1613 $sql .=
", multicurrency_code = '".$this->db->escape($this->multicurrency_code).
"'";
1614 $sql .=
", model_pdf = '".$this->db->escape($this->model_pdf).
"'";
1615 $sql .=
" WHERE rowid = ".(int) $id;
1617 $resql = $this->db->query($sql);
1619 if (is_object($this->oldcopy)) {
1620 if ($this->oldcopy->country_id != $this->country_id) {
1621 unset($this->country_code);
1622 unset($this->country);
1624 if ($this->oldcopy->state_id != $this->state_id) {
1625 unset($this->state_code);
1626 unset($this->state);
1629 unset($this->country_code);
1630 unset($this->country);
1631 unset($this->state_code);
1632 unset($this->state);
1635 $nbrowsaffected = $this->db->affected_rows($resql);
1637 if (!$error && $nbrowsaffected) {
1639 if (!$nosyncmember && isModEnabled(
'adherent')) {
1640 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1642 dol_syslog(get_class($this).
"::update update linked member");
1644 $lmember =
new Adherent($this->db);
1645 $result = $lmember->fetch(0, 0, $this->
id);
1648 $lmember->company = $this->name;
1651 $lmember->address = $this->address;
1652 $lmember->zip = $this->zip;
1653 $lmember->town = $this->town;
1654 $lmember->email = $this->email;
1655 $lmember->socialnetworks = $this->socialnetworks;
1656 $lmember->phone = $this->phone;
1657 $lmember->state_id = $this->state_id;
1658 $lmember->country_id = $this->country_id;
1659 $lmember->default_lang = $this->default_lang;
1661 $result = $lmember->update($user, 0, 1, 1, 1);
1663 $this->error = $lmember->error;
1664 $this->errors = array_merge($this->errors, $lmember->errors);
1665 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
1668 } elseif ($result < 0) {
1669 $this->error = $lmember->error;
1679 $this->db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int) $conf->entity));
1681 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
1684 $sql .=
", vat_reverse_charge";
1685 $sql .=
", accountancy_code_customer";
1686 $sql .=
", accountancy_code_supplier";
1687 $sql .=
", accountancy_code_buy";
1688 $sql .=
", accountancy_code_sell";
1689 $sql .=
") VALUES (";
1691 $sql .=
", ".$conf->entity;
1692 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1693 $sql .=
", '".$this->db->escape($this->code_compta_client).
"'";
1694 $sql .=
", '".$this->db->escape($this->code_compta_fournisseur).
"'";
1695 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1696 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1698 $result = $this->db->query($sql);
1701 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1720 if (!$error && $call_trigger) {
1722 $result = $this->
call_trigger(
'COMPANY_MODIFY', $user);
1730 dol_syslog(get_class($this).
"::Update success");
1731 $this->db->commit();
1734 $this->db->rollback();
1738 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1740 $this->error = $langs->trans(
"ErrorDuplicateField");
1743 $this->error = $this->db->lasterror();
1746 $this->db->rollback();
1750 $this->db->rollback();
1751 dol_syslog(get_class($this).
"::Update fails verify ".join(
',', $this->errors), LOG_WARNING);
1773 public function fetch($rowid, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'')
1778 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)) {
1782 $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';
1783 $sql .=
', s.status, s.fk_warehouse';
1784 $sql .=
', s.price_level';
1785 $sql .=
', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif';
1786 $sql .=
', s.phone, s.fax, s.email';
1787 $sql .=
', s.socialnetworks';
1788 $sql .=
', s.url, s.zip, s.town, s.note_private, s.note_public, s.client, s.fournisseur';
1789 $sql .=
', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1790 $sql .=
', s.capital, s.tva_intra';
1791 $sql .=
', s.fk_typent as typent_id';
1792 $sql .=
', s.fk_effectif as effectif_id';
1793 $sql .=
', s.fk_forme_juridique as forme_juridique_code';
1794 $sql .=
', s.webservices_url, s.webservices_key, s.model_pdf, s.last_main_doc';
1796 $sql .=
', s.code_compta, s.code_compta_fournisseur, s.accountancy_code_buy, s.accountancy_code_sell';
1797 $sql .=
', s.vat_reverse_charge as soc_vat_reverse_charge';
1799 $sql .=
', spe.accountancy_code_customer as code_compta, spe.accountancy_code_supplier as code_compta_fournisseur, spe.accountancy_code_buy, spe.accountancy_code_sell';
1800 $sql .=
', spe.vat_reverse_charge as spe_vat_reverse_charge';
1802 $sql .=
', s.code_client, s.code_fournisseur, s.parent, s.barcode';
1803 $sql .=
', s.fk_departement as state_id, s.fk_pays as country_id, s.fk_stcomm, s.mode_reglement, s.cond_reglement, s.deposit_percent, s.transport_mode';
1804 $sql .=
', s.fk_account, s.tva_assuj';
1805 $sql .=
', s.mode_reglement_supplier, s.cond_reglement_supplier, s.transport_mode_supplier';
1806 $sql .=
', s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred';
1807 $sql .=
', s.fk_shipping_method';
1808 $sql .=
', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1809 $sql .=
', s.order_min_amount, s.supplier_order_min_amount';
1810 $sql .=
', s.fk_multicurrency, s.multicurrency_code';
1811 $sql .=
', fj.libelle as forme_juridique';
1812 $sql .=
', e.libelle as effectif';
1813 $sql .=
', c.code as country_code, c.label as country';
1814 $sql .=
', d.code_departement as state_code, d.nom as state';
1815 $sql .=
', r.rowid as region_id, r.code_region as region_code';
1816 $sql .=
', st.libelle as stcomm, st.picto as stcomm_picto';
1817 $sql .=
', te.code as typent_code';
1818 $sql .=
', i.libelle as label_incoterms';
1819 if (!isModEnabled(
'multicompany')) {
1820 $sql .=
', s.remise_client, s.remise_supplier';
1822 $sql .=
', sr.remise_client, sr2.remise_supplier';
1824 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
1826 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = ".((int) $conf->entity);
1828 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_effectif as e ON s.fk_effectif = e.id';
1829 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON s.fk_pays = c.rowid';
1830 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcomm as st ON s.fk_stcomm = st.id';
1831 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
1832 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON s.fk_departement = d.rowid';
1833 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_regions as r ON d.fk_region = r.code_region ';
1834 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_typent as te ON s.fk_typent = te.id';
1835 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON s.fk_incoterms = i.rowid';
1838 if (isModEnabled(
'multicompany')) {
1839 $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').
'))';
1840 $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').
'))';
1842 $sql .=
' WHERE s.entity IN ('.getEntity($this->element).
')';
1844 $sql .=
' AND s.rowid = '.((int) $rowid);
1847 $sql .=
" AND s.nom = '".$this->db->escape($ref).
"'";
1850 $sql .=
" AND s.name_alias = '".$this->db->escape($ref_alias).
"'";
1853 $sql .=
" AND s.ref_ext = '".$this->db->escape($ref_ext).
"'";
1856 $sql .=
" AND s.barcode = '".$this->db->escape($barcode).
"'";
1859 $sql .=
" AND s.siren = '".$this->db->escape($idprof1).
"'";
1862 $sql .=
" AND s.siret = '".$this->db->escape($idprof2).
"'";
1865 $sql .=
" AND s.ape = '".$this->db->escape($idprof3).
"'";
1868 $sql .=
" AND s.idprof4 = '".$this->db->escape($idprof4).
"'";
1871 $sql .=
" AND s.idprof5 = '".$this->db->escape($idprof5).
"'";
1874 $sql .=
" AND s.idprof6 = '".$this->db->escape($idprof6).
"'";
1877 $sql .=
" AND s.email = '".$this->db->escape($email).
"'";
1880 $resql = $this->db->query($sql);
1882 $num = $this->db->num_rows($resql);
1884 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
1888 $obj = $this->db->fetch_object($resql);
1890 $this->
id = $obj->rowid;
1891 $this->entity = $obj->entity;
1892 $this->canvas = $obj->canvas;
1894 $this->
ref = $obj->rowid;
1895 $this->
name = $obj->name;
1896 $this->nom = $obj->name;
1897 $this->name_alias = $obj->name_alias;
1898 $this->ref_ext = $obj->ref_ext;
1900 $this->date_creation = $this->db->jdate($obj->date_creation);
1901 $this->date_modification = $this->db->jdate($obj->date_modification);
1902 $this->user_creation_id = $obj->fk_user_creat;
1903 $this->user_modification_id = $obj->fk_user_modif;
1905 $this->address = $obj->address;
1906 $this->zip = $obj->zip;
1907 $this->town = $obj->town;
1909 $this->country_id = $obj->country_id;
1910 $this->country_code = $obj->country_id ? $obj->country_code :
'';
1911 $this->country = $obj->country_id ? (($langs->transnoentities(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code) ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
1913 $this->state_id = $obj->state_id;
1914 $this->state_code = $obj->state_code;
1915 $this->region_id = $obj->region_id;
1916 $this->region_code = $obj->region_code;
1917 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
1919 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcomm);
1920 $label = ($transcode !=
'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm);
1921 $this->stcomm_id = $obj->fk_stcomm;
1922 $this->status_prospect_label = $label;
1923 $this->stcomm_picto = $obj->stcomm_picto;
1925 $this->email = $obj->email;
1926 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
1928 $this->url = $obj->url;
1929 $this->phone = $obj->phone;
1930 $this->fax = $obj->fax;
1932 $this->parent = $obj->parent;
1934 $this->idprof1 = $obj->idprof1;
1935 $this->idprof2 = $obj->idprof2;
1936 $this->idprof3 = $obj->idprof3;
1937 $this->idprof4 = $obj->idprof4;
1938 $this->idprof5 = $obj->idprof5;
1939 $this->idprof6 = $obj->idprof6;
1941 $this->capital = $obj->capital;
1943 $this->code_client = $obj->code_client;
1944 $this->code_fournisseur = $obj->code_fournisseur;
1946 $this->code_compta = $obj->code_compta;
1947 $this->code_compta_client = $obj->code_compta;
1948 $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
1950 $this->barcode = $obj->barcode;
1952 $this->tva_assuj = $obj->tva_assuj;
1953 $this->tva_intra = $obj->tva_intra;
1955 if (!empty($obj->spe_vat_reverse_charge)) {
1956 $this->vat_reverse_charge = $obj->spe_vat_reverse_charge;
1957 } elseif (!empty($obj->soc_vat_reverse_charge)) {
1958 $this->vat_reverse_charge = $obj->soc_vat_reverse_charge;
1960 $this->vat_reverse_charge = 0;
1963 $this->
status = $obj->status;
1966 $this->localtax1_assuj = $obj->localtax1_assuj;
1967 $this->localtax2_assuj = $obj->localtax2_assuj;
1969 $this->localtax1_value = $obj->localtax1_value;
1970 $this->localtax2_value = $obj->localtax2_value;
1972 $this->typent_id = $obj->typent_id;
1973 $this->typent_code = $obj->typent_code;
1975 $this->effectif_id = $obj->effectif_id;
1976 $this->effectif = $obj->effectif_id ? $obj->effectif :
'';
1978 $this->forme_juridique_code = $obj->forme_juridique_code;
1979 $this->forme_juridique = $obj->forme_juridique_code ? $obj->forme_juridique :
'';
1981 $this->fk_prospectlevel = $obj->fk_prospectlevel;
1983 $this->prefix_comm = $obj->prefix_comm;
1985 $this->remise_percent = $obj->remise_client ?
price2num($obj->remise_client) : 0;
1986 $this->remise_supplier_percent = $obj->remise_supplier;
1988 $this->mode_reglement_id = $obj->mode_reglement;
1989 $this->cond_reglement_id = $obj->cond_reglement;
1990 $this->deposit_percent = $obj->deposit_percent;
1991 $this->transport_mode_id = $obj->transport_mode;
1992 $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier;
1993 $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier;
1994 $this->transport_mode_supplier_id = $obj->transport_mode_supplier;
1995 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
1996 $this->fk_account = $obj->fk_account;
1998 $this->client = $obj->client;
1999 $this->fournisseur = $obj->fournisseur;
2001 $this->note = $obj->note_private;
2002 $this->note_private = $obj->note_private;
2003 $this->note_public = $obj->note_public;
2004 $this->model_pdf = $obj->model_pdf;
2005 $this->default_lang = $obj->default_lang;
2006 $this->logo = $obj->logo;
2007 $this->logo_squarred = $obj->logo_squarred;
2009 $this->webservices_url = $obj->webservices_url;
2010 $this->webservices_key = $obj->webservices_key;
2012 $this->accountancy_code_buy = $obj->accountancy_code_buy;
2013 $this->accountancy_code_sell = $obj->accountancy_code_sell;
2015 $this->outstanding_limit = $obj->outstanding_limit;
2016 $this->order_min_amount = $obj->order_min_amount;
2017 $this->supplier_order_min_amount = $obj->supplier_order_min_amount;
2020 $this->price_level = $obj->price_level;
2023 $this->fk_warehouse = $obj->fk_warehouse;
2025 $this->import_key = $obj->import_key;
2028 $this->fk_incoterms = $obj->fk_incoterms;
2029 $this->location_incoterms = $obj->location_incoterms;
2030 $this->label_incoterms = $obj->label_incoterms;
2033 $this->fk_multicurrency = $obj->fk_multicurrency;
2034 $this->multicurrency_code = $obj->multicurrency_code;
2037 $this->model_pdf = $obj->model_pdf;
2038 $this->last_main_doc = $obj->last_main_doc;
2048 $this->db->free($resql);
2050 $this->error = $this->db->lasterror();
2051 $this->errors[] = $this->db->lasterror();
2057 $this->price_level = 1;
2071 public function delete($id,
User $fuser =
null, $call_trigger = 1)
2073 global $langs, $conf, $user;
2075 if (empty($fuser)) {
2079 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2081 $entity = isset($this->entity) ? $this->entity : $conf->entity;
2083 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2088 if (empty($objectisused)) {
2092 if (!$error && $call_trigger) {
2094 $result = $this->
call_trigger(
'COMPANY_DELETE', $fuser);
2102 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2104 $toute_categs = array();
2107 if ($this->client || $this->prospect) {
2108 $toute_categs[
'customer'] = $static_cat->containing($this->
id, Categorie::TYPE_CUSTOMER);
2110 if ($this->fournisseur) {
2111 $toute_categs[
'supplier'] = $static_cat->containing($this->
id, Categorie::TYPE_SUPPLIER);
2115 foreach ($toute_categs as $type => $categs_type) {
2116 foreach ($categs_type as $cat) {
2117 $cat->del_type($this, $type);
2123 foreach ($this->childtablesoncascade as $tabletodelete) {
2124 $deleteFromObject = explode(
':', $tabletodelete);
2125 if (count($deleteFromObject) >= 2) {
2126 $className = str_replace(
'@',
'', $deleteFromObject[0]);
2127 $filepath = $deleteFromObject[1];
2128 $columnName = $deleteFromObject[2];
2130 $child_object =
new $className($this->db);
2131 $result = $child_object->deleteByParentField($id, $columnName);
2134 $this->errors[] = $child_object->error;
2139 $this->errors[] =
'Cannot include child class file '.$filepath;
2143 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
2144 $sql .=
" WHERE fk_soc = ".((int) $id);
2145 if (!$this->db->query($sql)) {
2147 $this->errors[] = $this->db->lasterror();
2159 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
2165 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2166 $sql .=
" SET parent = NULL";
2167 $sql .=
" WHERE parent = ".((int) $id);
2168 if (!$this->db->query($sql)) {
2170 $this->errors[] = $this->db->lasterror();
2177 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity";
2178 $sql .=
" WHERE fk_soc = ".((int) $id);
2179 if (!$this->db->query($sql)) {
2181 $this->errors[] = $this->db->lasterror();
2185 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe";
2186 $sql .=
" WHERE rowid = ".((int) $id);
2187 if (!$this->db->query($sql)) {
2189 $this->errors[] = $this->db->lasterror();
2194 $this->db->commit();
2197 if (!empty($conf->societe->multidir_output[$entity])) {
2198 $docdir = $conf->societe->multidir_output[$entity].
"/".$id;
2207 $this->db->rollback();
2211 dol_syslog(
"Can't remove thirdparty with id ".$id.
". There is ".$objectisused.
" childs", LOG_WARNING);
2228 dol_syslog(get_class($this).
"::set_as_client is deprecated use setAsCustomer instead", LOG_NOTICE);
2242 if (($this->client == 2 || $this->client == 3) && !
getDolGlobalInt(
'SOCIETE_DISABLE_PROSPECTSCUSTOMERS')) {
2245 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2246 $sql .=
" SET client = ".((int) $newclient);
2247 $sql .=
" WHERE rowid = ".((int) $this->
id);
2249 $resql = $this->db->query($sql);
2251 $this->client = $newclient;
2272 global $conf, $langs;
2275 $note = trim($note);
2277 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2281 dol_syslog(get_class($this).
"::set_remise_client ".$remise.
", ".$note.
", ".$user->id);
2289 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2290 $sql .=
" SET remise_client = '".$this->db->escape($remise).
"'";
2291 $sql .=
" WHERE rowid = ".((int) $this->
id);
2292 $resql = $this->db->query($sql);
2294 $this->db->rollback();
2295 $this->error = $this->db->error();
2300 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise";
2301 $sql .=
" (entity, datec, fk_soc, remise_client, note, fk_user_author)";
2302 $sql .=
" VALUES (".$conf->entity.
", '".$this->db->idate($now).
"', ".((int) $this->
id).
", '".$this->db->escape($remise).
"',";
2303 $sql .=
" '".$this->db->escape($note).
"',";
2304 $sql .=
" ".((int) $user->id);
2307 $resql = $this->db->query($sql);
2309 $this->db->rollback();
2310 $this->error = $this->db->lasterror();
2314 $this->db->commit();
2333 global $conf, $langs;
2336 $note = trim($note);
2338 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2342 dol_syslog(get_class($this).
"::set_remise_supplier ".$remise.
", ".$note.
", ".$user->id);
2350 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2351 $sql .=
" SET remise_supplier = '".$this->db->escape($remise).
"'";
2352 $sql .=
" WHERE rowid = ".((int) $this->
id);
2353 $resql = $this->db->query($sql);
2355 $this->db->rollback();
2356 $this->error = $this->db->error();
2361 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise_supplier";
2362 $sql .=
" (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
2363 $sql .=
" VALUES (".$conf->entity.
", '".$this->db->idate($now).
"', ".((int) $this->
id).
", '".$this->db->escape($remise).
"',";
2364 $sql .=
" '".$this->db->escape($note).
"',";
2365 $sql .=
" ".((int) $user->id);
2368 $resql = $this->db->query($sql);
2370 $this->db->rollback();
2371 $this->error = $this->db->lasterror();
2375 $this->db->commit();
2394 public function set_remise_except($remise,
User $user, $desc, $vatrate =
'', $discount_type = 0, $price_base_type =
'HT')
2401 $desc = trim($desc);
2404 if (!($remise > 0)) {
2405 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"1");
2409 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"3");
2413 if ($this->
id > 0) {
2417 if (preg_match(
'/\((.*)\)/', $vatrate, $reg)) {
2418 $vat_src_code = $reg[1];
2419 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2422 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2425 $discount->fk_soc = $this->id;
2427 $discount->discount_type = $discount_type;
2429 if ($price_base_type ==
'TTC') {
2430 $discount->amount_ttc = $discount->multicurrency_amount_ttc =
price2num($remise,
'MT');
2431 $discount->amount_ht = $discount->multicurrency_amount_ht =
price2num($remise / (1 + $vatrate / 100),
'MT');
2432 $discount->amount_tva = $discount->multicurrency_amount_tva =
price2num($discount->amount_ttc - $discount->amount_ht,
'MT');
2434 $discount->amount_ht = $discount->multicurrency_amount_ht =
price2num($remise,
'MT');
2435 $discount->amount_tva = $discount->multicurrency_amount_tva =
price2num($remise * $vatrate / 100,
'MT');
2436 $discount->amount_ttc = $discount->multicurrency_amount_ttc =
price2num($discount->amount_ht + $discount->amount_tva,
'MT');
2439 $discount->tva_tx =
price2num($vatrate);
2440 $discount->vat_src_code = $vat_src_code;
2442 $discount->description = $desc;
2444 $result = $discount->create($user);
2448 $this->error = $discount->error;
2467 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2470 $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type);
2474 $this->error = $discountstatic->error;
2492 $reparray = array();
2494 $sql =
"SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.office_phone, u.job, u.email, u.statut as status, u.entity, u.photo, u.gender";
2495 $sql .=
", u.office_fax, u.user_mobile, u.personal_mobile";
2496 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc, ".MAIN_DB_PREFIX.
"user as u";
2497 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2498 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
2499 $sql .=
" WHERE ((ug.fk_user = sc.fk_user";
2500 $sql .=
" AND ug.entity = ".$conf->entity.
")";
2501 $sql .=
" OR u.admin = 1)";
2503 $sql .=
" WHERE entity in (0, ".$conf->entity.
")";
2506 $sql .=
" AND u.rowid = sc.fk_user AND sc.fk_soc = ".((int) $this->
id);
2507 if (empty($sortfield) && empty($sortorder)) {
2508 $sortfield =
'u.lastname,u.firstname';
2509 $sortorder =
'ASC,ASC';
2511 $sql .= $this->db->order($sortfield, $sortorder);
2513 $resql = $this->db->query($sql);
2515 $num = $this->db->num_rows($resql);
2518 $obj = $this->db->fetch_object($resql);
2521 $reparray[$i][
'id'] = $obj->rowid;
2522 $reparray[$i][
'lastname'] = $obj->lastname;
2523 $reparray[$i][
'firstname'] = $obj->firstname;
2524 $reparray[$i][
'email'] = $obj->email;
2525 $reparray[$i][
'phone'] = $obj->office_phone;
2526 $reparray[$i][
'office_phone'] = $obj->office_phone;
2527 $reparray[$i][
'office_fax'] = $obj->office_fax;
2528 $reparray[$i][
'user_mobile'] = $obj->user_mobile;
2529 $reparray[$i][
'personal_mobile'] = $obj->personal_mobile;
2530 $reparray[$i][
'job'] = $obj->job;
2531 $reparray[$i][
'statut'] = $obj->status;
2532 $reparray[$i][
'status'] = $obj->status;
2533 $reparray[$i][
'entity'] = $obj->entity;
2534 $reparray[$i][
'login'] = $obj->login;
2535 $reparray[$i][
'photo'] = $obj->photo;
2536 $reparray[$i][
'gender'] = $obj->gender;
2538 $reparray[] = $obj->rowid;
2561 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2562 $sql .=
" SET price_level = ".((int) $price_level);
2563 $sql .=
" WHERE rowid = ".((int) $this->
id);
2565 if (!$this->db->query($sql)) {
2570 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_prices";
2571 $sql .=
" (datec, fk_soc, price_level, fk_user_author)";
2572 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $this->
id).
", ".((int) $price_level).
", ".((int) $user->id).
")";
2574 if (!$this->db->query($sql)) {
2596 if ($this->
id > 0 && $commid > 0) {
2600 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux";
2601 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2603 $resql = $this->db->query($sql);
2605 dol_syslog(get_class($this).
"::add_commercial Error ".$this->db->lasterror());
2611 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_commerciaux";
2612 $sql .=
" (fk_soc, fk_user)";
2613 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $commid).
")";
2615 $resql = $this->db->query($sql);
2617 dol_syslog(get_class($this).
"::add_commercial Error ".$this->db->lasterror());
2623 $this->context = array(
'commercial_modified' => $commid);
2625 $result = $this->
call_trigger(
'COMPANY_LINK_SALE_REPRESENTATIVE', $user);
2632 $this->db->commit();
2635 $this->db->rollback();
2655 $this->context = array(
'commercial_modified'=>$commid);
2657 $result = $this->
call_trigger(
'COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
2662 if ($this->
id > 0 && $commid > 0) {
2663 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux ";
2664 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2666 if (!$this->db->query($sql)) {
2667 dol_syslog(get_class($this).
"::del_commercial Erreur");
2681 global $conf, $langs, $user;
2683 $langs->loadLangs([
'companies',
'commercial']);
2687 $option = $params[
'option'] ??
'';
2688 $nofetch = !empty($params[
'nofetch']);
2690 $noaliasinname = (empty($params[
'noaliasinname']) ? 0 : $params[
'noaliasinname']);
2693 return [
'optimize' => $langs->trans(
"ShowCompany")];
2696 if (!empty($this->logo) && class_exists(
'Form')) {
2697 $photo =
'<div class="photointooltip floatright">';
2698 $photo .=
Form::showphoto(
'societe', $this, 0, 40, 0,
'photoref',
'mini', 0);
2700 $datas[
'photo'] = $photo;
2701 } elseif (!empty($this->logo_squarred) && class_exists(
'Form')) {
2707 $datas[
'divopen'] =
'<div class="centpercent">';
2709 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
2710 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Customer").
'</u>';
2711 } elseif ($option ==
'prospect' && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
2712 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Prospect").
'</u>';
2713 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
2714 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Supplier").
'</u>';
2715 } elseif ($option ==
'agenda') {
2716 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2717 } elseif ($option ==
'project') {
2718 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2719 } elseif ($option ==
'margin') {
2720 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2721 } elseif ($option ==
'contact') {
2722 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2723 } elseif ($option ==
'ban') {
2724 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2728 if (empty($datas[
'picto'])) {
2729 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2731 if (isset($this->
status)) {
2732 $datas[
'status'] =
' '.$this->getLibStatut(5);
2734 if (isset($this->client) && isset($this->fournisseur)) {
2735 $datas[
'type'] =
' ' . $this->
getTypeUrl(1);
2738 if (!empty($this->name_alias) && empty($noaliasinname)) {
2741 if (!empty($this->email)) {
2742 $datas[
'email'] =
'<br>'.img_picto(
'',
'email',
'class="pictofixedwidth"').$this->email;
2744 if (!empty($this->url)) {
2745 $datas[
'url'] =
'<br>'.img_picto(
'',
'globe',
'class="pictofixedwidth"').$this->url;
2747 if (!empty($this->phone) || !empty($this->fax)) {
2748 $phonelist = array();
2750 $phonelist[] =
dol_print_phone($this->phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2753 $phonelist[] =
dol_print_phone($this->fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2755 $datas[
'phonelist'] =
'<br>'.implode(
' ', $phonelist);
2758 if (!empty($this->address)) {
2759 $datas[
'address'] =
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
' ', $langs);
2760 } elseif (!empty($this->country_code)) {
2761 $datas[
'address'] =
'<br><b>'.$langs->trans(
'Country').
':</b> '.$this->country_code;
2763 if (!empty($this->tva_intra) || (
getDolGlobalString(
'SOCIETE_SHOW_FIELD_IN_TOOLTIP') && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'vatnumber') !==
false)) {
2764 $datas[
'vatintra'] =
'<br><b>'.$langs->trans(
'VATIntra').
':</b> '.
dol_escape_htmltag($this->tva_intra);
2768 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid1') !==
false && $langs->trans(
'ProfId1'.$this->country_code) !=
'-') {
2769 $datas[
'profid1'] =
'<br><b>'.$langs->trans(
'ProfId1'.$this->country_code).
':</b> '.$this->idprof1;
2771 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid2') !==
false && $langs->trans(
'ProfId2'.$this->country_code) !=
'-') {
2772 $datas[
'profid2'] =
'<br><b>'.$langs->trans(
'ProfId2'.$this->country_code).
':</b> '.$this->idprof2;
2774 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid3') !==
false && $langs->trans(
'ProfId3'.$this->country_code) !=
'-') {
2775 $datas[
'profid3'] =
'<br><b>'.$langs->trans(
'ProfId3'.$this->country_code).
':</b> '.$this->idprof3;
2777 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid4') !==
false && $langs->trans(
'ProfId4'.$this->country_code) !=
'-') {
2778 $datas[
'profid4'] =
'<br><b>'.$langs->trans(
'ProfId4'.$this->country_code).
':</b> '.$this->idprof4;
2780 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid5') !==
false && $langs->trans(
'ProfId5'.$this->country_code) !=
'-') {
2781 $datas[
'profid5'] =
'<br><b>'.$langs->trans(
'ProfId5'.$this->country_code).
':</b> '.$this->idprof5;
2783 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid6') !==
false && $langs->trans(
'ProfId6'.$this->country_code) !=
'-') {
2784 $datas[
'profid6'] =
'<br><b>'.$langs->trans(
'ProfId6'.$this->country_code).
':</b> '.$this->idprof6;
2788 $datas[
'separator'] =
'<br>';
2790 if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
2791 $datas[
'customercode'] =
'<br><b>'.$langs->trans(
'CustomerCode').
':</b> '.$this->code_client;
2793 if (isModEnabled(
'accounting') && ($this->client == 1 || $this->client == 3)) {
2794 $langs->load(
'compta');
2795 $datas[
'accountancycustomercode'] =
'<br><b>'.$langs->trans(
'CustomerAccountancyCode').
':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client);
2798 if (!$nofetch && isModEnabled(
'categorie') && $this->client) {
2799 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2800 $form =
new Form($this->db);
2801 $datas[
'categories_customer'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_CUSTOMER, 1, 1);
2803 if (!empty($this->code_fournisseur) && $this->fournisseur) {
2804 $datas[
'suppliercode'] =
'<br><b>'.$langs->trans(
'SupplierCode').
':</b> '.$this->code_fournisseur;
2806 if (isModEnabled(
'accounting') && $this->fournisseur) {
2807 $langs->load(
'compta');
2808 $datas[
'accountancysuppliercode'] =
'<br><b>'.$langs->trans(
'SupplierAccountancyCode').
':</b> '.$this->code_compta_fournisseur;
2811 if (!$nofetch && isModEnabled(
'categorie') && $this->fournisseur) {
2812 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2813 $form =
new Form($this->db);
2814 $datas[
'categories_supplier'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_SUPPLIER, 1, 1);
2817 $datas[
'divclose'] =
'</div>';
2834 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1, $noaliasinname = 0, $target =
'')
2836 global $conf, $langs, $hookmanager;
2838 if (!empty($conf->dol_no_mouse_hover)) {
2842 $name = $this->
name ? $this->
name : $this->nom;
2844 if (
getDolGlobalString(
'SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD')) {
2845 if (empty($option) && $this->client > 0) {
2846 $option =
'customer';
2848 if (empty($option) && $this->fournisseur > 0) {
2849 $option =
'supplier';
2855 if (($this->client) && (!empty($this->code_client)) && (
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 1 ||
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 2)) {
2856 $code = $this->code_client.
' - ';
2859 if (($this->fournisseur) && (!empty($this->code_fournisseur)) && (
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 1 ||
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 3)) {
2860 $code .= $this->code_fournisseur.
' - ';
2865 $name = $code.
' '.$name;
2872 if (!empty($this->name_alias) && empty($noaliasinname)) {
2873 $name .=
' ('.$this->name_alias.
')';
2879 'objecttype' => $this->element,
2880 'option' => $option,
2883 $classfortooltip =
'classfortooltip';
2886 $classfortooltip =
'classforajaxtooltip';
2887 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2896 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
2897 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2898 } elseif ($option ==
'prospect' && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
2899 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2900 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
2901 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->id;
2902 } elseif ($option ==
'agenda') {
2903 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/agenda.php?socid='.$this->id;
2904 } elseif ($option ==
'project') {
2905 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/project.php?socid='.$this->id;
2906 } elseif ($option ==
'margin') {
2907 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/margin/tabs/thirdpartyMargins.php?socid='.$this->
id.
'&type=1';
2908 } elseif ($option ==
'contact') {
2909 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/contact.php?socid='.$this->id;
2910 } elseif ($option ==
'ban') {
2911 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$this->id;
2915 if (empty($linkstart)) {
2916 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$this->id;
2920 $linkstart .= (!empty($this->canvas) ?
'&canvas='.$this->canvas :
'');
2922 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2923 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2924 $add_save_lastsearch_values = 1;
2926 if ($add_save_lastsearch_values) {
2927 $linkstart .=
'&save_lastsearch_values=1';
2932 if (empty($notooltip)) {
2934 $label = $langs->trans(
"ShowCompany");
2935 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2937 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
2938 $linkclose .= $dataparams.
' class="'.$classfortooltip.
' refurl valignmiddle"';
2939 $target_value = array(
'_self',
'_blank',
'_parent',
'_top');
2940 if (in_array($target, $target_value)) {
2941 $linkclose .=
' target="'.dol_escape_htmltag($target).
'"';
2944 $linkclose .=
' class="valignmiddle"';
2946 $linkstart .= $linkclose.
'>';
2950 if (!$user->hasRight(
'societe',
'client',
'voir') && $user->socid > 0 && $this->id != $user->socid) {
2955 $result .= $linkstart;
2957 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (
' class="'.(($withpicto != 2) ?
'paddingright' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
2959 if ($withpicto != 2) {
2962 $result .= $linkend;
2965 $hookmanager->initHooks(array(
'thirdpartydao'));
2966 $parameters = array(
2968 'getnomurl' => &$result,
2969 'withpicto '=> $withpicto,
2972 'notooltip'=> $notooltip,
2973 'save_lastsearch_value'=> $save_lastsearch_value
2975 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2977 $result = $hookmanager->resPrint;
2979 $result .= $hookmanager->resPrint;
2994 public function getTypeUrl($withpicto = 0, $option =
'', $notooltip = 0, $tag =
'a')
2996 global $conf, $langs;
2999 if (empty($option) || preg_match(
'/prospect/', $option)) {
3000 if (($this->client == 2 || $this->client == 3) && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
3001 $s .=
'<'.$tag.
' class="customer-back opacitymedium" title="'.$langs->trans(
"Prospect").
'" href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->
id.
'">'.
dol_substr($langs->trans(
"Prospect"), 0, 1).
'</'.$tag.
'>';
3004 if (empty($option) || preg_match(
'/customer/', $option)) {
3005 if (($this->client == 1 || $this->client == 3) && !
getDolGlobalString(
'SOCIETE_DISABLE_CUSTOMERS')) {
3006 $s .=
'<'.$tag.
' class="customer-back" title="'.$langs->trans(
"Customer").
'" href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->
id.
'">'.
dol_substr($langs->trans(
"Customer"), 0, 1).
'</'.$tag.
'>';
3009 if (empty($option) || preg_match(
'/supplier/', $option)) {
3010 if ((isModEnabled(
"supplier_order") || isModEnabled(
"supplier_invoice")) && $this->fournisseur) {
3011 $s .=
'<'.$tag.
' class="vendor-back" title="'.$langs->trans(
"Supplier").
'" href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->
id.
'">'.
dol_substr($langs->trans(
"Supplier"), 0, 1).
'</'.$tag.
'>';
3041 $langs->load(
'companies');
3043 $statusType =
'status4';
3045 $statusType =
'status6';
3048 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3049 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
3050 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"InActivity");
3051 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
3052 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"InActivity");
3055 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3071 if ($this->email && $addthirdparty) {
3072 if (empty($this->
name)) {
3073 $this->
name = $this->nom;
3075 $contact_emails[
'thirdparty'] = ($addthirdparty == 2 ?
'<span class="opacitymedium">' :
'').$langs->transnoentitiesnoconv(
"ThirdParty").($addthirdparty == 2 ?
'</span>' :
'').
': '.
dol_trunc($this->
name, 16).
" <".$this->email.
">";
3078 return $contact_emails;
3094 if (!empty($this->phone)) {
3095 if (empty($this->
name)) {
3096 $this->
name = $this->nom;
3099 $contact_phone[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->phone.
">";
3101 return $contact_phone;
3117 $contact_property = array();
3120 $sql =
"SELECT rowid, email, statut as status, phone_mobile, lastname, poste, firstname";
3121 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3122 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
3123 $sql .=
" AND entity IN (".getEntity($this->element).
")";
3124 $sql .=
" ORDER BY lastname, firstname";
3126 $resql = $this->db->query($sql);
3128 $nump = $this->db->num_rows($resql);
3132 if ($mode ==
'email') {
3138 while ($i < $nump) {
3139 $obj = $this->db->fetch_object($resql);
3140 if ($mode ==
'email') {
3141 $property = $obj->email;
3142 } elseif ($mode ==
'mobile') {
3143 $property = $obj->phone_mobile;
3145 $property = $obj->$mode;
3149 if ($obj->status == 1 || empty($hidedisabled)) {
3150 if (empty($property)) {
3151 if ($mode ==
'email') {
3152 $property = $langs->transnoentitiesnoconv(
"NoEMail");
3153 } elseif ($mode ==
'mobile') {
3154 $property = $langs->transnoentitiesnoconv(
"NoMobilePhone");
3158 if (!empty($obj->poste)) {
3159 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ?
" - ".$obj->poste :
"").(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3161 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3170 return $contact_property;
3183 $contacts = array();
3185 $sql =
"SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3186 $resql = $this->db->query($sql);
3188 $nump = $this->db->num_rows($resql);
3191 while ($i < $nump) {
3192 $obj = $this->db->fetch_object($resql);
3212 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
3213 $contacts = array();
3215 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3216 $resql = $this->db->query($sql);
3218 $nump = $this->db->num_rows($resql);
3221 while ($i < $nump) {
3222 $obj = $this->db->fetch_object($resql);
3223 $contact =
new Contact($this->db);
3224 $contact->fetch($obj->rowid);
3225 $contacts[] = $contact;
3246 $contact_property =
'';
3248 if (empty($rowid)) {
3252 $sql =
"SELECT rowid, email, phone_mobile, lastname, firstname";
3253 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3254 $sql .=
" WHERE rowid = ".((int) $rowid);
3256 $resql = $this->db->query($sql);
3258 $nump = $this->db->num_rows($resql);
3261 $obj = $this->db->fetch_object($resql);
3263 if ($mode ==
'email') {
3265 } elseif ($mode ==
'mobile') {
3266 $contact_property = $obj->phone_mobile;
3269 return $contact_property;
3288 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3291 $bac->fetch(0, $this->
id);
3294 if ($mode ==
'label') {
3295 return $bac->getRibLabel(
true);
3296 } elseif ($mode ==
'rum') {
3297 if (empty($bac->rum)) {
3298 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
3300 $bac->fetch_thirdparty();
3301 $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
3304 } elseif ($mode ==
'format') {
3305 return $bac->frstrecur;
3307 return 'BadParameterToFunctionDisplayRib';
3323 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3324 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE type='ban' AND fk_soc = ".((int) $this->
id);
3325 $result = $this->db->query($sql);
3328 $this->errors[] = $this->db->lasterror;
3331 $num_rows = $this->db->num_rows($result);
3332 $rib_array = array();
3334 while ($obj = $this->db->fetch_object($result)) {
3336 $rib->fetch($obj->rowid);
3337 $rib_array[] = $rib;
3358 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3360 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3361 foreach ($dirsociete as $dirroot) {
3367 $mod =
new $module();
3369 $this->code_client = $mod->getNextValue($objsoc, $type);
3370 $this->prefixCustomerIsRequired = $mod->prefixIsRequired;
3372 dol_syslog(get_class($this).
"::get_codeclient code_client=".$this->code_client.
" module=".$module);
3390 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3392 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3393 foreach ($dirsociete as $dirroot) {
3399 $mod =
new $module();
3401 $this->code_fournisseur = $mod->getNextValue($objsoc, $type);
3403 dol_syslog(get_class($this).
"::get_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3419 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3421 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3422 foreach ($dirsociete as $dirroot) {
3429 $mod =
new $module();
3431 dol_syslog(get_class($this).
"::codeclient_modifiable code_client=".$this->code_client.
" module=".$module);
3432 if ($mod->code_modifiable_null && !$this->code_client) {
3435 if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
3438 if ($mod->code_modifiable) {
3459 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3461 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3462 foreach ($dirsociete as $dirroot) {
3469 $mod =
new $module();
3471 dol_syslog(get_class($this).
"::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur.
" module=".$module);
3472 if ($mod->code_modifiable_null && !$this->code_fournisseur) {
3475 if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
3478 if ($mod->code_modifiable) {
3505 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3507 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3508 foreach ($dirsociete as $dirroot) {
3515 $mod =
new $module();
3517 dol_syslog(get_class($this).
"::check_codeclient code_client=".$this->code_client.
" module=".$module);
3518 $result = $mod->verif($this->db, $this->code_client, $this, 0);
3520 $this->error = $mod->error;
3521 $this->errors = $mod->errors;
3546 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3548 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3549 foreach ($dirsociete as $dirroot) {
3556 $mod =
new $module();
3558 dol_syslog(get_class($this).
"::check_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3559 $result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
3561 $this->error = $mod->error;
3562 $this->errors = $mod->errors;
3585 $module=$conf->global->SOCIETE_CODECOMPTA_ADDON;
3587 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3588 foreach ($dirsociete as $dirroot) {
3596 $mod =
new $module();
3599 $result = $mod->get_code($this->db, $this, $type);
3601 if ($type ==
'customer') {
3602 $this->code_compta_client = $mod->code;
3603 $this->code_compta = $this->code_compta_client;
3604 } elseif ($type ==
'supplier') {
3605 $this->code_compta_fournisseur = $mod->code;
3610 $this->error =
'ErrorAccountancyCodeNotDefined';
3614 if ($type ==
'customer') {
3615 $this->code_compta_client =
'';
3616 $this->code_compta =
'';
3617 } elseif ($type ==
'supplier') {
3618 $this->code_compta_fournisseur =
'';
3633 dol_syslog(get_class($this).
'::setParent', LOG_DEBUG);
3639 if ($sameparent < 0) {
3642 if ($sameparent == 1) {
3643 setEventMessages(
'ParentCompanyToAddIsAlreadyAChildOfModifiedCompany',
null,
'warnings');
3648 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe SET parent = '.($id > 0 ? $id :
'null').
' WHERE rowid = '.((
int) $this->id);
3650 $resql = $this->db->query($sql);
3652 $this->parent = $id;
3672 if ($counter > 100) {
3673 dol_syslog(
"Too high level of parent - child for company. May be an infinite loop ?", LOG_WARNING);
3676 $sql =
'SELECT s.parent';
3677 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
3678 $sql .=
' WHERE rowid = '.((int) $idparent);
3679 $resql = $this->db->query($sql);
3681 $obj = $this->db->fetch_object($resql);
3683 if ($obj->parent ==
'') {
3685 } elseif ($obj->parent == $idchild) {
3707 if ($company_id > 0) {
3708 $sql =
"SELECT parent FROM " . MAIN_DB_PREFIX .
"societe WHERE rowid = ".((int) $company_id);
3709 $resql = $this->db->query($sql);
3711 if ($obj = $this->db->fetch_object($resql)) {
3712 $parent = $obj->parent;
3713 if ($parent > 0 && !in_array($parent, $parents)) {
3714 $parents[] = $parent;
3720 $this->db->free($resql);
3722 setEventMessage($langs->trans(
'GetCompanyParentsError', $this->db->lasterror()),
'errors');
3807 $sql =
"SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"societe WHERE ".$field.
" = '".$this->db->escape($value).
"' AND entity IN (".
getEntity(
'societe').
")";
3809 $sql .=
" AND rowid <> ".$socid;
3811 $resql = $this->db->query($sql);
3813 $obj = $this->db->fetch_object($resql);
3817 print $this->db->error();
3819 $this->db->free($resql);
3849 if ($idprof == 1 && $soc->country_code ==
'FR') {
3850 $chaine = trim($this->idprof1);
3851 $chaine = preg_replace(
'/(\s)/',
'', $chaine);
3853 if (!is_numeric($chaine)) {
3865 for ($index = 0; $index < 9; $index++) {
3866 $number = (int) $chaine[$index];
3867 if ($index % 2 != 0) {
3868 if (($number *= 2) > 9) {
3876 if ($sum % 10 != 0) {
3882 if ($idprof == 2 && $soc->country_code ==
'FR') {
3883 $chaine = trim($this->idprof2);
3884 $chaine = preg_replace(
'/(\s)/',
'', $chaine);
3886 if (!is_numeric($chaine)) {
3898 for ($index = 0; $index < 14; $index++) {
3899 $number = (int) $chaine[$index];
3900 if (($index % 2) == 0) {
3901 if (($number *= 2) > 9) {
3909 if ($sum % 10 != 0) {
3916 if ($idprof == 1 && $soc->country_code ==
'ES') {
3917 $string = trim($this->idprof1);
3918 $string = preg_replace(
'/(\s)/',
'', $string);
3919 $string = strtoupper($string);
3922 if (!preg_match(
'/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string)) {
3927 for ($i = 0; $i < 9; $i++) {
3928 $num[$i] = substr($string, $i, 1);
3932 if (preg_match(
'/(^[0-9]{8}[A-Z]{1}$)/', $string)) {
3933 if ($num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) {
3941 $sum = $num[2] + $num[4] + $num[6];
3942 for ($i = 1; $i < 8; $i += 2) {
3943 $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1));
3945 $n = 10 - substr($sum, strlen($sum) - 1, 1);
3948 if (preg_match(
'/^[KLM]{1}/', $string)) {
3949 if ($num[8] == chr(64 + $n) || $num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) {
3957 if (preg_match(
'/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) {
3958 if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) {
3966 if (preg_match(
'/^[T]{1}/', $string)) {
3967 if ($num[8] == preg_match(
'/^[T]{1}[A-Z0-9]{8}$/', $string)) {
3975 if (preg_match(
'/^[XYZ]{1}/', $string)) {
3976 if ($num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array(
'X',
'Y',
'Z'), array(
'0',
'1',
'2'), $string), 0, 8) % 23, 1)) {
3989 if ($idprof == 1 && $soc->country_code ==
'PT') {
3990 $string = trim($this->idprof1);
3991 $string = preg_replace(
'/(\s)/',
'', $string);
3994 if (preg_match(
'/(^[0-9]{9}$)/', $string)) {
4003 if ($idprof == 1 && $soc->country_code ==
'DZ') {
4004 $string = trim($this->idprof1);
4005 $string = preg_replace(
'/(\s)/',
'', $string);
4008 if (preg_match(
'/(^[0-9]{15}$)/', $string)) {
4017 if ($idprof == 1 && $soc->country_code ==
'BE') {
4018 $string = trim($this->idprof1);
4019 $string = preg_replace(
'/(\s)/',
'', $string);
4022 if (preg_match(
'/(^[0-9]{4}\.[0-9]{3}\.[0-9]{3}$)/', $string)) {
4044 global $conf, $langs, $hookmanager;
4049 $hookmanager->initHooks(array(
'idprofurl'));
4050 $parameters = array(
'idprof'=>$idprof,
'company'=>$thirdparty);
4051 $reshook = $hookmanager->executeHooks(
'getIdProfUrl', $parameters, $this, $action);
4052 if (empty($reshook)) {
4058 $strippedIdProf1 = str_replace(
' ',
'', $thirdparty->idprof1);
4059 if ($idprof == 1 && $thirdparty->country_code ==
'FR') {
4060 $url =
'https://annuaire-entreprises.data.gouv.fr/entreprise/'.$strippedIdProf1;
4062 if ($idprof == 1 && ($thirdparty->country_code ==
'GB' || $thirdparty->country_code ==
'UK')) {
4063 $url =
'https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
4065 if ($idprof == 1 && $thirdparty->country_code ==
'ES') {
4066 $url =
'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
4068 if ($idprof == 1 && $thirdparty->country_code ==
'IN') {
4069 $url =
'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.
';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
4071 if ($idprof == 1 && $thirdparty->country_code ==
'DZ') {
4072 $url =
'http://nif.mfdgi.gov.dz/nif.asp?Nif='.$strippedIdProf1;
4074 if ($idprof == 1 && $thirdparty->country_code ==
'PT') {
4075 $url =
'http://www.nif.pt/'.$strippedIdProf1;
4079 return '<a target="_blank" rel="noopener noreferrer" href="'.$url.
'">'.$langs->trans(
"Check").
'</a>';
4082 return $hookmanager->resPrint;
4097 $sql =
"SELECT COUNT(*) as numproj FROM ".MAIN_DB_PREFIX.
"projet WHERE fk_soc = ".((int) $this->
id);
4098 $resql = $this->db->query($sql);
4100 $obj = $this->db->fetch_object($resql);
4101 $count = $obj->numproj;
4104 print $this->db->error();
4106 $this->db->free($resql);
4107 return ($count > 0);
4119 $sql =
"SELECT s.rowid, s.nom as name, s.datec, tms as datem,";
4120 $sql .=
" fk_user_creat, fk_user_modif";
4121 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
4122 $sql .=
" WHERE s.rowid = ".((int) $id);
4124 $result = $this->db->query($sql);
4126 if ($this->db->num_rows($result)) {
4127 $obj = $this->db->fetch_object($result);
4129 $this->
id = $obj->rowid;
4131 $this->user_creation_id = $obj->fk_user_creat;
4132 $this->user_modification_id = $obj->fk_user_modif;
4133 $this->date_creation = $this->db->jdate($obj->datec);
4134 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
4136 $this->
ref = $obj->name;
4139 $this->db->free($result);
4156 if (!empty($this->tva_intra)) {
4158 } elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) {
4163 if (preg_match(
'/^TE_PRIVATE/', $this->typent_code)) {
4183 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4196 $this->SupplierCategories = array();
4197 $sql =
"SELECT rowid, label";
4198 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
4199 $sql .=
" WHERE type = ".Categorie::TYPE_SUPPLIER;
4201 $resql = $this->db->query($sql);
4203 while ($obj = $this->db->fetch_object($resql)) {
4204 $this->SupplierCategories[$obj->rowid] = $obj->label;
4222 if ($categorie_id > 0 && $this->
id > 0) {
4223 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_fournisseur (fk_categorie, fk_soc) ";
4224 $sql .=
" VALUES (".((int) $categorie_id).
", ".((int) $this->
id).
")";
4226 if ($resql = $this->db->query($sql)) {
4242 $sql =
"SELECT count(mc.email) as nb";
4243 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
4244 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->email).
"' ";
4245 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
4247 $resql = $this->db->query($sql);
4249 $obj = $this->db->fetch_object($resql);
4252 $this->db->free($resql);
4255 $this->error = $this->db->error();
4275 $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).
"'";
4276 $resql = $this->db->query($sql);
4278 $obj = $this->db->fetch_object($resql);
4279 $noemail = $obj->nb;
4280 if (empty($noemail)) {
4281 $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()).
"')";
4282 $resql = $this->db->query($sql);
4285 $this->error = $this->db->lasterror();
4286 $this->errors[] = $this->error;
4291 $this->error = $this->db->lasterror();
4292 $this->errors[] = $this->error;
4295 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->db->escape($this->email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
4296 $resql = $this->db->query($sql);
4299 $this->error = $this->db->lasterror();
4300 $this->errors[] = $this->error;
4304 if (empty($error)) {
4305 $this->no_email = $no_email;
4306 $this->db->commit();
4309 $this->db->rollback();
4326 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->db->escape($this->email).
"'";
4327 $resql = $this->db->query($sql);
4329 $obj = $this->db->fetch_object($resql);
4330 $this->no_email = $obj->nb;
4333 $this->error = $this->db->lasterror();
4334 $this->errors[] = $this->error;
4354 global $conf, $user, $langs;
4356 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
4357 $fullname = $member->getFullName($langs);
4359 if ($member->morphy ==
'mor') {
4360 if (empty($socname)) {
4361 $socname = $member->company ? $member->company : $member->societe;
4363 if (!empty($fullname) && empty($socalias)) {
4364 $socalias = $fullname;
4366 } elseif (empty($socname) && $member->morphy ==
'phy') {
4367 if (empty($socname)) {
4368 $socname = $fullname;
4370 if (!empty($member->company) && empty($socalias)) {
4371 $socalias = $member->company;
4376 $alias = $socalias ? $socalias :
'';
4380 $this->
name = $name;
4381 $this->name_alias = $alias;
4382 $this->address = $member->address;
4383 $this->zip = $member->zip;
4384 $this->town = $member->town;
4385 $this->country_code = $member->country_code;
4386 $this->country_id = $member->country_id;
4387 $this->phone = $member->phone;
4388 $this->email = $member->email;
4389 $this->socialnetworks = $member->socialnetworks;
4390 $this->entity = $member->entity;
4393 $this->code_client = ($customercode ? $customercode : -1);
4394 $this->code_fournisseur = -1;
4395 $this->typent_code = ($member->morphy ==
'phy' ?
'TE_PRIVATE' : 0);
4396 $this->typent_id = $this->typent_code ?
dol_getIdFromCode($this->db, $this->typent_code,
'c_typent',
'id',
'code') : 0;
4401 $result = $this->
create($user);
4407 $this->name_bis = $member->lastname;
4408 $this->firstname = $member->firstname;
4409 $this->civility_id = $member->civility_id;
4411 dol_syslog(
"We ask to create a contact/address too", LOG_DEBUG);
4416 $this->db->rollback();
4421 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent";
4422 $sql .=
" SET fk_soc = ".((int) $this->
id);
4423 $sql .=
" WHERE rowid = ".((int) $member->id);
4425 $resql = $this->db->query($sql);
4427 $this->db->commit();
4430 $this->error = $this->db->error();
4432 $this->db->rollback();
4437 dol_syslog(get_class($this).
"::create_from_member - 2 - ".$this->error.
" - ".join(
',', $this->errors), LOG_ERR);
4439 $this->db->rollback();
4455 $this->entity = $conf->entity;
4457 $this->nom = $this->name;
4468 $country_id = $country_code = $country_label =
'';
4471 $country_id = $tmp[0];
4472 if (!empty($tmp[1])) {
4473 $country_code = $tmp[1];
4474 $country_label = $tmp[2];
4477 dol_syslog(
"Your country setup use an old syntax. Reedit it using setup area.", LOG_WARNING);
4478 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4479 $country_code =
getCountry($country_id, 2, $this->db);
4480 $country_label =
getCountry($country_id, 0, $this->db);
4483 $this->country_id = $country_id;
4484 $this->country_code = $country_code;
4485 $this->country = $country_label;
4486 if (is_object($langs)) {
4487 $this->country = ($langs->trans(
'Country'.$country_code) !=
'Country'.$country_code) ? $langs->trans(
'Country'.$country_code) : $country_label;
4493 $state_code = $state_label =
'';
4496 $state_id = $tmp[0];
4497 if (!empty($tmp[1])) {
4498 $state_code = $tmp[1];
4499 $state_label = $tmp[2];
4501 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);
4502 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4503 $state_code =
getState($state_id, 2, $this->db);
4504 $state_label =
getState($state_id, 0, $this->db);
4507 $this->state_id = $state_id;
4508 $this->state_code = $state_code;
4509 $this->state = $state_label;
4510 if (is_object($langs)) {
4511 $this->state = ($langs->trans(
'State'.$state_code) !=
'State'.$state_code) ? $langs->trans(
'State'.$state_code) : $state_label;
4525 $this->socialnetworks = array();
4526 if (!empty($facebook_url)) {
4527 $this->socialnetworks[
'facebook'] = $facebook_url;
4529 if (!empty($twitter_url)) {
4530 $this->socialnetworks[
'twitter'] = $twitter_url;
4532 if (!empty($linkedin_url)) {
4533 $this->socialnetworks[
'linkedin'] = $linkedin_url;
4535 if (!empty($instagram_url)) {
4536 $this->socialnetworks[
'instagram'] = $instagram_url;
4538 if (!empty($youtube_url)) {
4539 $this->socialnetworks[
'youtube'] = $youtube_url;
4541 if (!empty($github_url)) {
4542 $this->socialnetworks[
'github'] = $github_url;
4555 $this->forme_juridique_code =
getDolGlobalString(
'MAIN_INFO_SOCIETE_FORME_JURIDIQUE');
4562 $this->logo_squarred_small =
getDolGlobalString(
'MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL');
4563 $this->logo_squarred_mini =
getDolGlobalString(
'MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI');
4566 $this->tva_assuj = $conf->global->FACTURE_TVAOPTION;
4569 $this->localtax1_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && (
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'1' ||
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'localtax1on')) ? 1 : 0);
4570 $this->localtax2_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && (
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'1' ||
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'localtax2on')) ? 1 : 0);
4587 $this->
name =
'THIRDPARTY SPECIMEN '.dol_print_date($now,
'dayhourlog');
4588 $this->nom = $this->name;
4589 $this->ref_ext =
'Ref ext';
4590 $this->specimen = 1;
4591 $this->address =
'21 jump street';
4592 $this->zip =
'99999';
4593 $this->town =
'MyTown';
4594 $this->state_id = 1;
4595 $this->state_code =
'AA';
4596 $this->state =
'MyState';
4597 $this->country_id = 1;
4598 $this->country_code =
'FR';
4599 $this->email =
'specimen@specimen.com';
4600 $this->socialnetworks = array(
4601 'skype' =>
'skypepseudo',
4602 'twitter' =>
'twitterpseudo',
4603 'facebook' =>
'facebookpseudo',
4604 'linkedin' =>
'linkedinpseudo',
4606 $this->url =
'http://www.specimen.com';
4608 $this->phone =
'0909090901';
4609 $this->fax =
'0909090909';
4611 $this->code_client =
'CC-'.dol_print_date($now,
'dayhourlog');
4612 $this->code_fournisseur =
'SC-'.dol_print_date($now,
'dayhourlog');
4613 $this->capital = 10000;
4615 $this->prospect = 1;
4616 $this->fournisseur = 1;
4617 $this->tva_assuj = 1;
4618 $this->tva_intra =
'EU1234567';
4619 $this->note_public =
'This is a comment (public)';
4620 $this->note_private =
'This is a comment (private)';
4622 $this->idprof1 =
'idprof1';
4623 $this->idprof2 =
'idprof2';
4624 $this->idprof3 =
'idprof3';
4625 $this->idprof4 =
'idprof4';
4626 $this->idprof5 =
'idprof5';
4627 $this->idprof6 =
'idprof6';
4639 $sql =
"SELECT t.localtax1, t.localtax2";
4640 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4641 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4642 $sql .=
" AND t.active = 1";
4643 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
4644 if (empty($localTaxNum)) {
4645 $sql .=
" AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
4646 } elseif ($localTaxNum == 1) {
4647 $sql .=
" AND t.localtax1_type <> '0'";
4648 } elseif ($localTaxNum == 2) {
4649 $sql .=
" AND t.localtax2_type <> '0'";
4652 $resql = $this->db->query($sql);
4654 return ($this->db->num_rows($resql) > 0);
4667 $sql =
"SELECT t.rowid";
4668 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4669 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4670 $sql .=
" AND t.active = 1 AND t.recuperableonly = 1";
4671 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
4674 $resql = $this->db->query($sql);
4676 return ($this->db->num_rows($resql) > 0);
4690 $sql =
"SELECT COUNT(*) as nb";
4691 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_revenuestamp as r, ".MAIN_DB_PREFIX.
"c_country as c";
4692 $sql .=
" WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4693 $sql .=
" AND r.active = 1";
4696 $resql = $this->db->query($sql);
4698 $obj = $this->db->fetch_object($resql);
4699 return (($obj->nb > 0) ?
true :
false);
4701 $this->error = $this->db->lasterror();
4727 if ($fk_prospectlevel !=
'') {
4728 $lib = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
4730 if ($lib ==
"ProspectLevel".$fk_prospectlevel) {
4731 $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
4746 return $this->
LibProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
4768 $langs->load(
'customers');
4771 if ($status ==
'-1' || $status ==
'ST_NO') {
4772 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect-1");
4773 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4774 return img_action($langs->trans(
"StatusProspect0"), 0, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect0");
4775 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4776 return img_action($langs->trans(
"StatusProspect1"), 1, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect1");
4777 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4778 return img_action($langs->trans(
"StatusProspect2"), 2, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect2");
4779 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4780 return img_action($langs->trans(
"StatusProspect3"), 3, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect3");
4782 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);
4784 } elseif ($mode == 3) {
4785 if ($status ==
'-1' || $status ==
'ST_NO') {
4786 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto,
'class="inline-block valignmiddle"');
4787 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4788 return img_action($langs->trans(
"StatusProspect0"), 0, $picto,
'class="inline-block valignmiddle"');
4789 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4790 return img_action($langs->trans(
"StatusProspect1"), 1, $picto,
'class="inline-block valignmiddle"');
4791 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4792 return img_action($langs->trans(
"StatusProspect2"), 2, $picto,
'class="inline-block valignmiddle"');
4793 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4794 return img_action($langs->trans(
"StatusProspect3"), 3, $picto,
'class="inline-block valignmiddle"');
4796 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto,
'class="inline-block valignmiddle"');
4798 } elseif ($mode == 4) {
4799 if ($status ==
'-1' || $status ==
'ST_NO') {
4800 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect-1");
4801 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4802 return img_action($langs->trans(
"StatusProspect0"), 0, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect0");
4803 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4804 return img_action($langs->trans(
"StatusProspect1"), 1, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect1");
4805 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4806 return img_action($langs->trans(
"StatusProspect2"), 2, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect2");
4807 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4808 return img_action($langs->trans(
"StatusProspect3"), 3, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect3");
4810 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);
4814 return "Error, mode/status not found";
4826 if ($mode ==
'supplier') {
4827 $table =
'supplier_proposal';
4830 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4831 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4832 if ($mode ==
'supplier') {
4833 $sql .=
" AND entity IN (".getEntity(
'supplier_proposal').
")";
4835 $sql .=
" AND entity IN (".getEntity(
'propal').
")";
4838 dol_syslog(
"getOutstandingProposals for fk_soc = ".((
int) $this->
id), LOG_DEBUG);
4840 $resql = $this->db->query($sql);
4842 $outstandingOpened = 0;
4843 $outstandingTotal = 0;
4844 $outstandingTotalIncTax = 0;
4845 $arrayofref = array();
4846 while ($obj = $this->db->fetch_object($resql)) {
4847 $arrayofref[$obj->rowid] = $obj->ref;
4848 $outstandingTotal += $obj->total_ht;
4849 $outstandingTotalIncTax += $obj->total_ttc;
4850 if ($obj->status != 0) {
4852 $outstandingOpened += $obj->total_ttc;
4855 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref);
4869 $table =
'commande';
4870 if ($mode ==
'supplier') {
4871 $table =
'commande_fournisseur';
4874 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4875 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4876 if ($mode ==
'supplier') {
4877 $sql .=
" AND entity IN (".getEntity(
'supplier_order').
")";
4879 $sql .=
" AND entity IN (".getEntity(
'commande').
")";
4882 dol_syslog(
"getOutstandingOrders", LOG_DEBUG);
4883 $resql = $this->db->query($sql);
4885 $outstandingOpened = 0;
4886 $outstandingTotal = 0;
4887 $outstandingTotalIncTax = 0;
4888 $arrayofref = array();
4889 while ($obj = $this->db->fetch_object($resql)) {
4890 $arrayofref[$obj->rowid] = $obj->ref;
4891 $outstandingTotal += $obj->total_ht;
4892 $outstandingTotalIncTax += $obj->total_ttc;
4893 if ($obj->status != 0) {
4895 $outstandingOpened += $obj->total_ttc;
4898 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref);
4914 if ($mode ==
'supplier') {
4915 $table =
'facture_fourn';
4925 $sql =
"SELECT rowid, ref, total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table.
" as f";
4926 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4927 if (!empty($late)) {
4928 $sql .=
" AND date_lim_reglement < '".$this->db->idate(
dol_now()).
"'";
4930 if ($mode ==
'supplier') {
4931 $sql .=
" AND entity IN (".getEntity(
'facture_fourn').
")";
4933 $sql .=
" AND entity IN (".getEntity(
'invoice').
")";
4936 dol_syslog(
"getOutstandingBills", LOG_DEBUG);
4937 $resql = $this->db->query($sql);
4939 $outstandingOpened = 0;
4940 $outstandingTotal = 0;
4941 $outstandingTotalIncTax = 0;
4942 $arrayofref = array();
4943 $arrayofrefopened = array();
4944 if ($mode ==
'supplier') {
4945 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
4948 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
4949 $tmpobject =
new Facture($this->db);
4951 while ($obj = $this->db->fetch_object($resql)) {
4952 $arrayofref[$obj->rowid] = $obj->ref;
4953 $tmpobject->id = $obj->rowid;
4955 if ($obj->status != $tmpobject::STATUS_DRAFT
4956 && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code ==
'replaced')
4958 $outstandingTotal += $obj->total_ht;
4959 $outstandingTotalIncTax += $obj->total_ttc;
4965 && $obj->status != $tmpobject::STATUS_DRAFT
4966 && $obj->status != $tmpobject::STATUS_ABANDONED
4967 && $obj->status != $tmpobject::STATUS_CLOSED) {
4969 $paiement = $tmpobject->getSommePaiement();
4970 $creditnotes = $tmpobject->getSumCreditNotesUsed();
4971 $deposits = $tmpobject->getSumDepositsUsed();
4973 $remaintopay = ($obj->total_ttc - $paiement - $creditnotes - $deposits);
4974 $outstandingOpened += $remaintopay;
4980 $remainingcreditnote = $tmpobject->getSumFromThisCreditNotesNotUsed();
4981 $remaintopay -= $remainingcreditnote;
4982 $outstandingOpened -= $remainingcreditnote;
4986 $arrayofrefopened[$obj->rowid] = $obj->ref;
4989 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref,
'refsopened'=>$arrayofrefopened);
4991 dol_syslog(
"Sql error ".$this->db->lasterror, LOG_ERR);
5018 $langs->load(
'companies');
5021 return $langs->trans(
"NorProspectNorCustomer");
5022 } elseif ($status == 1) {
5023 return $langs->trans(
"Customer");
5024 } elseif ($status == 2) {
5025 return $langs->trans(
"Prospect");
5026 } elseif ($status == 3) {
5027 return $langs->trans(
"ProspectCustomer");
5045 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
5047 global $conf, $user, $langs;
5049 if (!empty($moreparams) && !empty($moreparams[
'use_companybankid'])) {
5050 $modelpath =
"core/modules/bank/doc/";
5052 include_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
5054 $result = $companybankaccount->fetch($moreparams[
'use_companybankid']);
5056 dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
5058 $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
5059 $this->last_main_doc=$companybankaccount->last_main_doc;
5064 $modele = $conf->global->COMPANY_ADDON_PDF;
5066 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_COMPANY_ADDON_PDF_NotDefined");
5071 if (!isset($this->bank_account)) {
5072 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
5074 $result = $bac->fetch(0, $this->
id);
5076 $this->bank_account = $bac;
5078 $this->bank_account =
'';
5082 $modelpath =
"core/modules/societe/doc/";
5084 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
5104 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
5107 if (!in_array($type_categ, array(Categorie::TYPE_CUSTOMER, Categorie::TYPE_SUPPLIER))) {
5108 dol_syslog(__METHOD__.
': Type '.$type_categ.
'is an unknown company category type. Done nothing.', LOG_ERR);
5112 return parent::setCategoriesCommon($categories, $type_categ);
5127 if (!is_array($salesrep)) {
5128 $salesrep = array($salesrep);
5132 $to_add = $salesrep;
5133 if ($onlyAdd ===
false) {
5138 if (is_array($existing)) {
5139 $to_del = array_diff($existing, $salesrep);
5140 $to_add = array_diff($salesrep, $existing);
5147 foreach ($to_del as $del) {
5150 foreach ($to_add as $add) {
5158 return $error ? -1 : 1;
5174 $result = $this->
setValueFrom(
'fk_typent', $typent_id,
'',
null,
'',
'', $user,
'COMPANY_MODIFY');
5177 $this->typent_id = $typent_id;
5178 $this->typent_code =
dol_getIdFromCode($this->db, $this->typent_id,
'c_typent',
'id',
'code');
5199 if ($origin_id == $dest_id) {
5200 dol_syslog(
'Error: Try to merge a thirdparty into itself');
5208 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5209 $sql .=
' WHERE fk_soc = '.(int) $dest_id.
' AND fk_user IN ( ';
5210 $sql .=
' SELECT fk_user ';
5211 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5212 $sql .=
' WHERE fk_soc = '.(int) $origin_id.
') ';
5214 $resql = $dbs->
query($sql);
5216 $dbs->
query(
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_commerciaux WHERE rowid = '.((
int) $obj->rowid));
5225 'societe_commerciaux',
5228 'societe_remise_except',
5245 global $user, $langs, $conf;
5249 $field =
'accountancy_code_sell';
5250 if ($type ==
'buy') {
5251 $field =
'accountancy_code_buy';
5252 } elseif ($type ==
'sell') {
5253 $field =
'accountancy_code_sell';
5258 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ";
5259 $sql .= $field.
" = '".$this->db->escape($value).
"'";
5260 $sql .=
" WHERE rowid = ".((int) $this->
id);
5262 dol_syslog(get_class($this).
"::".__FUNCTION__, LOG_DEBUG);
5263 $resql = $this->db->query($sql);
5267 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
5269 $result = $interface->run_triggers(
'COMPANY_MODIFY', $this, $user, $langs, $conf);
5271 $this->errors = $interface->errors;
5272 $this->db->rollback();
5277 $this->$field = $value;
5279 $this->db->commit();
5282 $this->error = $this->db->lasterror();
5283 $this->db->rollback();
5298 require_once DOL_DOCUMENT_ROOT.
'/partnership/class/partnership.class.php';
5301 $this->partnerships[] = array();
5315 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
5317 $return =
'<div class="box-flex-item box-flex-grow-zero">';
5318 $return .=
'<div class="info-box info-box-sm">';
5319 $return .=
'<span class="info-box-icon bg-infobox-action">';
5321 $return .=
'</span>';
5322 $return .=
'<div class="info-box-content">';
5323 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
5324 if ($selected >= 0) {
5325 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
5327 if (property_exists($this,
'code_client')) {
5328 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->code_client.
'</span>';
5330 if (method_exists($this,
'getLibStatut')) {
5331 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
5333 $return .=
'</div>';
5334 $return .=
'</div>';
5335 $return .=
'</div>';
5356 $sql =
"SELECT sc.rowid, sc.fk_socpeople as id, sc.fk_c_type_contact";
5358 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
5360 $sql .=
", t.civility as civility, t.lastname as lastname, t.firstname, t.email";
5361 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_label";
5362 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact tc";
5363 $sql .=
", ".$this->db->prefix().
"societe_contacts sc";
5365 $sql .=
" LEFT JOIN ".$this->db->prefix().
"socpeople t on sc.fk_socpeople = t.rowid";
5367 $sql .=
" WHERE sc.fk_soc = ".((int) $this->
id);
5368 $sql .=
" AND sc.fk_c_type_contact = tc.rowid";
5369 if (!empty($element)) {
5370 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
5373 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
5375 $sql .=
" AND sc.entity IN (".getEntity($this->element).
")";
5376 $sql .=
" AND tc.source = 'external'";
5377 $sql .=
" AND tc.active=1";
5379 $sql .=
" ORDER BY t.lastname ASC";
5381 dol_syslog(get_class($this).
"::getContacts", LOG_DEBUG);
5382 $resql = $this->db->query($sql);
5384 $num = $this->db->num_rows($resql);
5387 $obj = $this->db->fetch_object($resql);
5390 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
5391 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_label);
5393 'source' => $obj->source,
5394 'socid' => $obj->socid,
5396 'nom' => $obj->lastname,
5397 'civility' => $obj->civility,
5398 'lastname' => $obj->lastname,
5399 'firstname' => $obj->firstname,
5400 'email'=>$obj->email,
5401 'login'=> (empty($obj->login) ?
'' : $obj->login),
5402 'photo' => (empty($obj->photo) ?
'' : $obj->photo),
5403 'statuscontact' => $obj->statuscontact,
5404 'rowid' => $obj->rowid,
5405 'code' => $obj->code,
5406 'element' => $obj->element,
5407 'libelle' => $libelle_type,
5408 'status' => $obj->statuslink,
5409 'fk_c_type_contact' => $obj->fk_c_type_contact
5412 $tab[$i] = $obj->id;
5420 $this->error = $this->db->lasterror();
5435 global $conf, $langs, $hookmanager, $user, $action;
5438 $soc_origin =
new Societe($this->db);
5440 dol_syslog(
"mergeCompany merge thirdparty id=".$soc_origin_id.
" (will be deleted) into the thirdparty id=".$this->id);
5442 if (!$error && $soc_origin->fetch($soc_origin_id) < 1) {
5443 $this->error = $langs->trans(
'ErrorRecordNotFound');
5451 $this->client = $this->client | $soc_origin->client;
5452 $this->fournisseur = $this->fournisseur | $soc_origin->fournisseur;
5453 $listofproperties = array(
5454 'address',
'zip',
'town',
'state_id',
'country_id',
'phone',
'fax',
'email',
'socialnetworks',
'url',
'barcode',
5455 'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
5456 'tva_intra',
'effectif_id',
'forme_juridique',
'remise_percent',
'remise_supplier_percent',
'mode_reglement_supplier_id',
'cond_reglement_supplier_id',
'name_bis',
5457 'stcomm_id',
'outstanding_limit',
'price_level',
'parent',
'default_lang',
'ref',
'ref_ext',
'import_key',
'fk_incoterms',
'fk_multicurrency',
5458 'code_client',
'code_fournisseur',
'code_compta',
'code_compta_fournisseur',
5461 foreach ($listofproperties as $property) {
5462 if (empty($this->$property)) {
5463 $this->$property = $soc_origin->$property;
5468 $listofproperties = array(
5469 'note_public',
'note_private'
5471 foreach ($listofproperties as $property) {
5472 $this->$property =
dol_concatdesc($this->$property, $soc_origin->$property);
5476 if (is_array($soc_origin->array_options)) {
5477 foreach ($soc_origin->array_options as $key => $val) {
5478 if (empty($this->array_options[$key])) {
5479 $this->array_options[$key] = $val;
5485 if (empty($this->name_bis) && $this->
name != $soc_origin->name) {
5486 $this->name_bis = $this->name;
5492 $custcats_ori = $static_cat->containing($soc_origin->id,
'customer',
'id');
5493 $custcats = $static_cat->containing($this->
id,
'customer',
'id');
5494 $custcats = array_merge($custcats, $custcats_ori);
5497 $suppcats_ori = $static_cat->containing($soc_origin->id,
'supplier',
'id');
5498 $suppcats = $static_cat->containing($this->
id,
'supplier',
'id');
5499 $suppcats = array_merge($suppcats, $suppcats_ori);
5503 if ($soc_origin->code_client == $this->code_client
5504 || $soc_origin->code_fournisseur == $this->code_fournisseur
5505 || $soc_origin->barcode == $this->barcode) {
5506 dol_syslog(
"We clean customer and supplier code so we will be able to make the update of target");
5507 $soc_origin->code_client =
'';
5508 $soc_origin->code_fournisseur =
'';
5509 $soc_origin->barcode =
'';
5510 $soc_origin->update($soc_origin->id, $user, 0, 1, 1,
'merge');
5514 $result = $this->
update($this->
id, $user, 0, 1, 1,
'merge');
5523 'Adherent' =>
'/adherents/class/adherent.class.php',
5524 'Don' => array(
'file' =>
'/don/class/don.class.php',
'enabled' => isModEnabled(
'don')),
5525 'Societe' =>
'/societe/class/societe.class.php',
5527 'ActionComm' =>
'/comm/action/class/actioncomm.class.php',
5528 'Propal' =>
'/comm/propal/class/propal.class.php',
5529 'Commande' =>
'/commande/class/commande.class.php',
5530 'Facture' =>
'/compta/facture/class/facture.class.php',
5531 'FactureRec' =>
'/compta/facture/class/facture-rec.class.php',
5532 'LignePrelevement' =>
'/compta/prelevement/class/ligneprelevement.class.php',
5533 'Mo' =>
'/mrp/class/mo.class.php',
5534 'Contact' =>
'/contact/class/contact.class.php',
5535 'Contrat' =>
'/contrat/class/contrat.class.php',
5536 'Expedition' =>
'/expedition/class/expedition.class.php',
5537 'Fichinter' =>
'/fichinter/class/fichinter.class.php',
5538 'CommandeFournisseur' =>
'/fourn/class/fournisseur.commande.class.php',
5539 'FactureFournisseur' =>
'/fourn/class/fournisseur.facture.class.php',
5540 'FactureFournisseurRec' =>
'/fourn/class/fournisseur.facture-rec.class.php',
5541 'Reception' =>
'/reception/class/reception.class.php',
5542 'SupplierProposal' =>
'/supplier_proposal/class/supplier_proposal.class.php',
5543 'ProductFournisseur' =>
'/fourn/class/fournisseur.product.class.php',
5544 'Delivery' =>
'/delivery/class/delivery.class.php',
5545 'Product' =>
'/product/class/product.class.php',
5546 'Project' =>
'/projet/class/project.class.php',
5547 'Ticket' => array(
'file' =>
'/ticket/class/ticket.class.php',
'enabled' => isModEnabled(
'ticket')),
5548 'User' =>
'/user/class/user.class.php',
5549 'Account' =>
'/compta/bank/class/account.class.php',
5550 'ConferenceOrBoothAttendee' =>
'/eventorganization/class/conferenceorboothattendee.class.php'
5554 foreach ($objects as $object_name => $object_file) {
5555 if (is_array($object_file)) {
5556 if (empty($object_file[
'enabled'])) {
5559 $object_file = $object_file[
'file'];
5562 require_once DOL_DOCUMENT_ROOT.$object_file;
5564 if (!$error && !$object_name::replaceThirdparty($this->db, $soc_origin->id, $this->id)) {
5566 $this->error = $this->db->lasterror();
5574 $parameters = array(
'soc_origin' => $soc_origin->id,
'soc_dest' => $this->id);
5575 $reshook = $hookmanager->executeHooks(
'replaceThirdparty', $parameters, $this, $action);
5578 $this->error = $hookmanager->error;
5579 $this->errors = $hookmanager->errors;
5586 $this->context = array(
'merge'=>1,
'mergefromid'=>$soc_origin->id,
'mergefromname'=>$soc_origin->name);
5589 $result = $this->
call_trigger(
'COMPANY_MODIFY', $user);
5598 if (!empty($conf->societe->multidir_output[$this->entity])) {
5599 $srcdir = $conf->societe->multidir_output[$this->entity].
"/".$soc_origin->id;
5600 $destdir = $conf->societe->multidir_output[$this->entity].
"/".$this->id;
5604 foreach ($dirlist as $filetomove) {
5605 $destfile = $destdir.
'/'.$filetomove[
'relativename'];
5607 dol_move($filetomove[
'fullname'], $destfile,
'0', 0, 0, 1);
5617 if ($soc_origin->delete($soc_origin->id, $user) < 1) {
5618 $this->error = $soc_origin->error;
5619 $this->errors = $soc_origin->errors;
5625 $this->db->commit();
5628 $langs->load(
"errors");
5629 $this->error = $langs->trans(
'ErrorsThirdpartyMerge');
5630 $this->db->rollback();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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.
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 fields 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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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 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.
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.
fetch($rowid, $ref='', $ref_ext='', $barcode='', $idprof1='', $idprof2='', $idprof3='', $idprof4='', $idprof5='', $idprof6='', $email='', $ref_alias='')
Load a third party from database into memory.
verify()
Check properties of third party are ok (like name, third party codes, ...) Used before an add or upda...
getContacts($list=0, $code='', $element='')
Get array of all contacts for a society (stored in societe_contacts instead of element_contacts for a...
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()
Return 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.
add_commercial(User $user, $commid)
Add link to sales representative.
LibStatut($status, $mode=0)
Return the label of a given status.
get_codefournisseur($objsoc=0, $type=1)
Assigns a vendor code from the code control module.
const PROSPECT
Third party type is a prospect.
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.
getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0, $save_lastsearch_value=-1, $noaliasinname=0, $target='')
Return a link on thirdparty (with picto)
id_prof_exists($idprof, $value, $socid=0)
Verify if a profid exists into database for others thirds.
setCategories($categories, $type_categ)
Sets object to supplied categories.
useRevenueStamp()
Check if we must use revenue stamps feature or not according to country (country of $mysocin most cas...
setNoEmail($no_email)
Set "blacklist" mailing status.
id_prof_verifiable($idprof)
Returns if a profid sould 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.
get_codeclient($objsoc=0, $type=0)
Assigns a customer code from the code control module.
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.
update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0, $action='update', $nosyncmember=1)
Update parameters of third party.
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.
getSalesRepresentatives(User $user, $mode=0, $sortfield=null, $sortorder=null)
Return array of sales representatives.
LoadSupplierCateg()
Load the list of provider categories.
display_rib($mode='label')
Return bank number property of thirdparty (label or rum)
contact_array_objects()
Returns the contact list of this company.
getAvailableDiscounts($user='', $filter='', $maxvalue=0, $discount_type=0)
Returns amount of included taxes of the current discounts/credits available from the company.
isInEEC()
Return if a company is inside the EEC (European Economic Community)
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.
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 another one, deleting the given company.
const NO_SUPPLIER
Third party supplier flag is not supplier.
getNbOfEMailings()
Return number of mass Emailing received by this contacts with its email.
setAccountancyCode($type, $value)
Sets an accountancy code for a thirdparty.
getLibCustProspStatut()
Return label of status customer is prospect/customer.
getLibStatut($mode=0)
Return label of status (activity, closed)
const NO_CUSTOMER
Third party type is no customer.
LibProspLevel($fk_prospectlevel)
Return label of prospect level.
set_remise_supplier($remise, $note, User $user)
Defines the company as a customer.
useLocalTax($localTaxNum=0)
Check if we must use localtax feature or not according to country (country of $mysoc in most cases).
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 attribut 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.
id_prof_check($idprof, $soc)
Check the validity of a professional identifier according to the country of the company (siren,...
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.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
thirdparty_and_contact_phone_array()
Return list of contacts mobile phone existing for third party.
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.
const SUPPLIER
Third party supplier flag is a supplier.
check_codefournisseur()
Check supplier code.
contact_array()
Returns 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.
trait CommonIncoterm
Superclass for incoterm classes.
trait CommonPeople
Superclass for thirdparties, contacts, members or users.
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
trait CommonSocialNetworks
Superclass for social networks.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
getState($id, $withcode='', $dbtouse=0, $withregion=0, $outputlangs='', $entconv=1)
Return state translated from an id.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array())
Move a file into another name.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($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_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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs='', $mode=0, $extralangcode='')
Return a formated address (part address/zip/town/state) according to country rules.
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.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
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...
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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...
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.
$conf db name
Only used if Module[ID]Name translation string is not found.