41 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
56 public $module =
'societe';
61 public $element =
'societe';
66 public $table_element =
'societe';
71 public $fk_element =
'fk_soc';
76 public $fieldsforcombobox =
'nom,name_alias';
81 protected $childtables = array(
82 'supplier_proposal' => array(
'name' =>
'SupplierProposal'),
83 'propal' => array(
'name' =>
'Proposal'),
84 'commande' => array(
'name' =>
'Order'),
85 'facture' => array(
'name' =>
'Invoice'),
86 'facture_rec' => array(
'name' =>
'RecurringInvoiceTemplate'),
87 'contrat' => array(
'name' =>
'Contract'),
88 'fichinter' => array(
'name' =>
'Fichinter'),
89 'facture_fourn' => array(
'name' =>
'SupplierInvoice'),
90 'commande_fournisseur' => array(
'name' =>
'SupplierOrder'),
91 'projet' => array(
'name' =>
'Project'),
92 'expedition' => array(
'name' =>
'Shipment'),
93 'prelevement_lignes' => array(
'name' =>
'DirectDebitRecord'),
100 protected $childtablesoncascade = array(
103 'product_fournisseur_price',
104 'product_customer_price_log',
105 'product_customer_price',
106 '@Contact:/contact/class/contact.class.php:fk_soc',
111 'societe_remise_except',
112 'societe_commerciaux',
122 public $picto =
'company';
128 public $ismultientitymanaged = 1;
134 public $restrictiononfksoc = 1;
166 public $fields = array(
167 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
168 'parent' =>array(
'type'=>
'integer',
'label'=>
'Parent',
'enabled'=>1,
'visible'=>-1,
'position'=>20),
169 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
170 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
171 'nom' =>array(
'type'=>
'varchar(128)',
'label'=>
'Nom',
'enabled'=>1,
'visible'=>-1,
'position'=>35,
'showoncombobox'=>1),
172 'name_alias' =>array(
'type'=>
'varchar(128)',
'label'=>
'Name alias',
'enabled'=>1,
'visible'=>-1,
'position'=>36,
'showoncombobox'=>2),
173 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>40,
'index'=>1),
174 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefExt',
'enabled'=>1,
'visible'=>0,
'position'=>45),
175 'code_client' =>array(
'type'=>
'varchar(24)',
'label'=>
'CustomerCode',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
176 'code_fournisseur' =>array(
'type'=>
'varchar(24)',
'label'=>
'SupplierCode',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
177 'code_compta' =>array(
'type'=>
'varchar(24)',
'label'=>
'CodeCompta',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
178 'code_compta_fournisseur' =>array(
'type'=>
'varchar(24)',
'label'=>
'CodeComptaSupplier',
'enabled'=>1,
'visible'=>-1,
'position'=>70),
179 'address' =>array(
'type'=>
'varchar(255)',
'label'=>
'Address',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
180 'zip' =>array(
'type'=>
'varchar(25)',
'label'=>
'Zip',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
181 'town' =>array(
'type'=>
'varchar(50)',
'label'=>
'Town',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
182 'fk_departement' =>array(
'type'=>
'integer',
'label'=>
'State',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
183 'fk_pays' =>array(
'type'=>
'integer:Ccountry:core/class/ccountry.class.php',
'label'=>
'Country',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
184 'phone' =>array(
'type'=>
'varchar(20)',
'label'=>
'Phone',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
185 'fax' =>array(
'type'=>
'varchar(20)',
'label'=>
'Fax',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
186 'url' =>array(
'type'=>
'varchar(255)',
'label'=>
'Url',
'enabled'=>1,
'visible'=>-1,
'position'=>110),
187 'email' =>array(
'type'=>
'varchar(128)',
'label'=>
'Email',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
188 'socialnetworks' =>array(
'type'=>
'text',
'label'=>
'Socialnetworks',
'enabled'=>1,
'visible'=>-1,
'position'=>120),
189 'fk_effectif' =>array(
'type'=>
'integer',
'label'=>
'Workforce',
'enabled'=>1,
'visible'=>-1,
'position'=>170),
190 'fk_typent' =>array(
'type'=>
'integer',
'label'=>
'TypeOfCompany',
'enabled'=>1,
'visible'=>-1,
'position'=>175,
'csslist'=>
'minwidth200'),
191 'fk_forme_juridique' =>array(
'type'=>
'integer',
'label'=>
'JuridicalStatus',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
192 'fk_currency' =>array(
'type'=>
'varchar(3)',
'label'=>
'Currency',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
193 'siren' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof1',
'enabled'=>1,
'visible'=>-1,
'position'=>190),
194 'siret' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof2',
'enabled'=>1,
'visible'=>-1,
'position'=>195),
195 'ape' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof3',
'enabled'=>1,
'visible'=>-1,
'position'=>200),
196 'idprof4' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof4',
'enabled'=>1,
'visible'=>-1,
'position'=>205),
197 'idprof5' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof5',
'enabled'=>1,
'visible'=>-1,
'position'=>206),
198 'idprof6' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof6',
'enabled'=>1,
'visible'=>-1,
'position'=>207),
199 'tva_intra' =>array(
'type'=>
'varchar(20)',
'label'=>
'Tva intra',
'enabled'=>1,
'visible'=>-1,
'position'=>210),
200 'capital' =>array(
'type'=>
'double(24,8)',
'label'=>
'Capital',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
201 'fk_stcomm' =>array(
'type'=>
'integer',
'label'=>
'CommercialStatus',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>220),
202 'note_public' =>array(
'type'=>
'text',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>225),
203 'note_private' =>array(
'type'=>
'text',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>230),
204 'prefix_comm' =>array(
'type'=>
'varchar(5)',
'label'=>
'Prefix comm',
'enabled'=>
"getDolGlobalInt('SOCIETE_USEPREFIX')",
'visible'=>-1,
'position'=>235),
205 'client' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Client',
'enabled'=>1,
'visible'=>-1,
'position'=>240),
206 'fournisseur' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Fournisseur',
'enabled'=>1,
'visible'=>-1,
'position'=>245),
207 'supplier_account' =>array(
'type'=>
'varchar(32)',
'label'=>
'Supplier account',
'enabled'=>1,
'visible'=>-1,
'position'=>250),
208 'fk_prospectlevel' =>array(
'type'=>
'varchar(12)',
'label'=>
'ProspectLevel',
'enabled'=>1,
'visible'=>-1,
'position'=>255),
209 'customer_bad' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Customer bad',
'enabled'=>1,
'visible'=>-1,
'position'=>260),
210 'customer_rate' =>array(
'type'=>
'double',
'label'=>
'Customer rate',
'enabled'=>1,
'visible'=>-1,
'position'=>265),
211 'supplier_rate' =>array(
'type'=>
'double',
'label'=>
'Supplier rate',
'enabled'=>1,
'visible'=>-1,
'position'=>270),
212 'fk_user_creat' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-2,
'position'=>275),
213 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>280),
216 'mode_reglement' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Mode reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>295),
217 'cond_reglement' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Cond reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>300),
218 'deposit_percent' =>array(
'type'=>
'varchar(63)',
'label'=>
'DepositPercent',
'enabled'=>1,
'visible'=>-1,
'position'=>301),
219 'mode_reglement_supplier' =>array(
'type'=>
'integer',
'label'=>
'Mode reglement supplier',
'enabled'=>1,
'visible'=>-1,
'position'=>305),
220 'cond_reglement_supplier' =>array(
'type'=>
'integer',
'label'=>
'Cond reglement supplier',
'enabled'=>1,
'visible'=>-1,
'position'=>308),
221 'outstanding_limit' =>array(
'type'=>
'double(24,8)',
'label'=>
'OutstandingBill',
'enabled'=>1,
'visible'=>-1,
'position'=>310,
'isameasure'=>1),
222 '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),
223 '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),
224 'fk_shipping_method' =>array(
'type'=>
'integer',
'label'=>
'Fk shipping method',
'enabled'=>1,
'visible'=>-1,
'position'=>330),
225 'tva_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Tva assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>335),
226 'localtax1_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Localtax1 assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>340),
227 'localtax1_value' =>array(
'type'=>
'double(6,3)',
'label'=>
'Localtax1 value',
'enabled'=>1,
'visible'=>-1,
'position'=>345),
228 'localtax2_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Localtax2 assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>350),
229 'localtax2_value' =>array(
'type'=>
'double(6,3)',
'label'=>
'Localtax2 value',
'enabled'=>1,
'visible'=>-1,
'position'=>355),
230 'barcode' =>array(
'type'=>
'varchar(255)',
'label'=>
'Barcode',
'enabled'=>1,
'visible'=>-1,
'position'=>360),
231 '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),
232 'default_lang' =>array(
'type'=>
'varchar(6)',
'label'=>
'Default lang',
'enabled'=>1,
'visible'=>-1,
'position'=>370),
233 'canvas' =>array(
'type'=>
'varchar(32)',
'label'=>
'Canvas',
'enabled'=>1,
'visible'=>-1,
'position'=>375),
234 'fk_barcode_type' =>array(
'type'=>
'integer',
'label'=>
'Fk barcode type',
'enabled'=>1,
'visible'=>-1,
'position'=>405),
235 'webservices_url' =>array(
'type'=>
'varchar(255)',
'label'=>
'Webservices url',
'enabled'=>1,
'visible'=>-1,
'position'=>410),
236 'webservices_key' =>array(
'type'=>
'varchar(128)',
'label'=>
'Webservices key',
'enabled'=>1,
'visible'=>-1,
'position'=>415),
237 'fk_incoterms' =>array(
'type'=>
'integer',
'label'=>
'Fk incoterms',
'enabled'=>1,
'visible'=>-1,
'position'=>425),
238 'location_incoterms' =>array(
'type'=>
'varchar(255)',
'label'=>
'Location incoterms',
'enabled'=>1,
'visible'=>-1,
'position'=>430),
239 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>435),
240 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'LastMainDoc',
'enabled'=>1,
'visible'=>-1,
'position'=>270),
241 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>-1,
'position'=>440),
242 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Multicurrency code',
'enabled'=>1,
'visible'=>-1,
'position'=>445),
243 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'PaymentBankAccount',
'enabled'=>1,
'visible'=>-1,
'position'=>450),
244 'fk_warehouse' =>array(
'type'=>
'integer',
'label'=>
'Warehouse',
'enabled'=>1,
'visible'=>-1,
'position'=>455),
245 'logo' =>array(
'type'=>
'varchar(255)',
'label'=>
'Logo',
'enabled'=>1,
'visible'=>-1,
'position'=>400),
246 'logo_squarred' =>array(
'type'=>
'varchar(255)',
'label'=>
'Logo squarred',
'enabled'=>1,
'visible'=>-1,
'position'=>401),
247 'status' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>-1,
'position'=>500),
248 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000),
333 public $departement_code;
368 public $socialnetworks;
478 public $tva_assuj = 1;
487 public $localtax1_assuj;
488 public $localtax1_value;
489 public $localtax2_assuj;
490 public $localtax2_value;
505 public $typent_id = 0;
508 public $effectif_id = 0;
509 public $forme_juridique_code;
510 public $forme_juridique = 0;
512 public $remise_percent;
513 public $remise_supplier_percent;
515 public $mode_reglement_id;
516 public $cond_reglement_id;
517 public $deposit_percent;
518 public $mode_reglement_supplier_id;
519 public $cond_reglement_supplier_id;
520 public $transport_mode_supplier_id;
525 public $fk_prospectlevel;
538 public $date_modification;
544 public $user_modification;
550 public $date_creation;
556 public $user_creation;
568 public $prospect = 0;
586 public $code_fournisseur;
592 public $code_compta_client;
605 public $accountancy_code_customer;
611 public $code_compta_fournisseur;
617 public $accountancy_code_supplier;
624 public $code_compta_product;
638 public $note_private;
656 public $stcomm_picto;
662 public $status_prospect_label;
673 public $outstanding_limit;
678 public $order_min_amount;
683 public $supplier_order_min_amount;
689 public $commercial_id;
701 public $default_lang;
727 public $webservices_url;
733 public $webservices_key;
753 public $logo_squarred;
758 public $logo_squarred_small;
763 public $logo_squarred_mini;
768 public $accountancy_code_sell;
773 public $accountancy_code_buy;
779 public $fk_multicurrency;
785 public $fk_warehouse;
790 public $multicurrency_code;
799 public $partnerships = array();
805 public $bank_account;
808 const STATUS_CEASED = 0;
809 const STATUS_INACTIVITY = 1;
855 $this->fournisseur = 0;
856 $this->typent_id = 0;
857 $this->effectif_id = 0;
858 $this->forme_juridique_code = 0;
859 $this->tva_assuj = 1;
862 if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
863 $this->fields[
'address'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
864 $this->fields[
'zip'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
865 $this->fields[
'town'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
881 global $langs, $conf, $mysoc;
886 if (empty($this->status)) {
889 $this->
name = $this->
name ?trim($this->
name) : trim($this->nom);
891 $this->nom = $this->name;
892 if (empty($this->client)) {
895 if (empty($this->fournisseur)) {
896 $this->fournisseur = 0;
898 $this->import_key = trim($this->import_key);
900 $this->accountancy_code_customer = trim($this->code_compta);
901 $this->accountancy_code_supplier = trim($this->code_compta_fournisseur);
902 $this->accountancy_code_buy = trim($this->accountancy_code_buy);
903 $this->accountancy_code_sell = trim($this->accountancy_code_sell);
905 if (!empty($this->multicurrency_code)) {
908 if (empty($this->fk_multicurrency)) {
909 $this->multicurrency_code =
'';
910 $this->fk_multicurrency = 0;
920 if ($this->code_client == -1 || $this->code_client ===
'auto') {
923 if ($this->code_fournisseur == -1 || $this->code_fournisseur ===
'auto') {
929 $result = $this->
verify();
932 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
934 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe (";
936 $sql .=
", name_alias";
939 $sql .=
", fk_user_creat";
940 $sql .=
", fk_typent";
944 $sql .=
", fk_stcomm";
945 $sql .=
", fk_incoterms";
946 $sql .=
", location_incoterms";
947 $sql .=
", import_key";
948 $sql .=
", fk_multicurrency";
949 $sql .=
", multicurrency_code";
950 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
951 $sql .=
", accountancy_code_buy";
952 $sql .=
", accountancy_code_sell";
954 $sql .=
") VALUES ('".$this->db->escape($this->name).
"', '".$this->
db->escape($this->name_alias).
"', ".((int) $this->entity).
", '".$this->
db->idate($now).
"'";
955 $sql .=
", ".(!empty($user->id) ? ((int) $user->id) :
"null");
956 $sql .=
", ".(!empty($this->typent_id) ? ((int) $this->typent_id) :
"null");
957 $sql .=
", ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null");
958 $sql .=
", ".((int) $this->status);
959 $sql .=
", ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
961 $sql .=
", ".(int) $this->fk_incoterms;
962 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
963 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
964 $sql .=
", ".(int) $this->fk_multicurrency;
965 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
966 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
967 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
968 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
972 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
973 $result = $this->
db->query($sql);
975 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"societe");
977 $ret = $this->
update($this->
id, $user, 0, 1, 1,
'add');
980 if (!$error && !empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
981 $this->
db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int) $conf->entity));
983 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
986 $sql .=
", accountancy_code_customer";
987 $sql .=
", accountancy_code_supplier";
988 $sql .=
", accountancy_code_buy";
989 $sql .=
", accountancy_code_sell";
990 $sql .=
") VALUES (";
992 $sql .=
", ".((int) $conf->entity);
993 $sql .=
", '".$this->db->escape($this->accountancy_code_customer).
"'";
994 $sql .=
", '".$this->db->escape($this->accountancy_code_supplier).
"'";
995 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
996 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
998 $result = $this->
db->query($sql);
1001 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1006 if ($this->commercial_id !=
'' && $this->commercial_id != -1) {
1008 } elseif (empty($user->rights->societe->client->voir)) {
1016 $result = $this->
call_trigger(
'COMPANY_CREATE', $user);
1027 dol_syslog(get_class($this).
"::Create success id=".$this->
id);
1028 $this->
db->commit();
1031 dol_syslog(get_class($this).
"::Create echec update ".$this->error.(empty($this->errors) ?
'' :
' '.join(
',', $this->errors)), LOG_ERR);
1032 $this->
db->rollback();
1036 if ($this->
db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1037 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", $this->name);
1040 $this->error = $this->
db->lasterror();
1043 $this->
db->rollback();
1047 $this->
db->rollback();
1048 dol_syslog(get_class($this).
"::Create fails verify ".join(
',', $this->errors), LOG_WARNING);
1073 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1076 $contact->name = $this->name_bis;
1077 $contact->firstname = $this->firstname;
1078 $contact->civility_id = $this->civility_id;
1079 $contact->socid = $this->id;
1080 $contact->statut = 1;
1081 $contact->status = 1;
1083 $contact->country_id = $this->country_id;
1084 $contact->state_id = $this->state_id;
1085 $contact->address = $this->address;
1086 $contact->email = $this->email;
1087 $contact->zip = $this->zip;
1088 $contact->town = $this->town;
1090 $contact->phone_pro = $this->phone;
1092 $contactId = $contact->create($user, $notrigger);
1093 if ($contactId < 0) {
1095 $this->error = $contact->error;
1096 $this->errors = $contact->errors;
1097 dol_syslog(get_class($this).
"::create_individual ERROR:".$this->error, LOG_ERR);
1100 if (empty($error) && is_array($tags) && !empty($tags)) {
1101 $result = $contact->setCategories($tags);
1104 $this->error = $contact->error;
1105 $this->errors = array_merge($this->errors, $contact->errors);
1106 dol_syslog(get_class($this).
"::create_individual Affect Tag ERROR:".$this->error, LOG_ERR);
1107 $contactId = $result;
1111 if (empty($error) &&
isModEnabled(
'mailing') && !empty($contact->email) && isset($no_email)) {
1112 $result = $contact->setNoEmail($no_email);
1114 $this->error = $contact->error;
1115 $this->errors = array_merge($this->errors, $contact->errors);
1116 dol_syslog(get_class($this).
"::create_individual set mailing status ERROR:".$this->error, LOG_ERR);
1117 $contactId = $result;
1121 if (empty($error)) {
1122 dol_syslog(get_class($this).
"::create_individual success");
1123 $this->
db->commit();
1125 $this->
db->rollback();
1139 global $conf, $langs, $mysoc;
1142 $this->errors = array();
1146 $this->nom = $this->name;
1149 $this->errors[] =
'ErrorBadThirdPartyName';
1153 if ($this->client) {
1155 if ($rescode != 0 && $rescode != -5) {
1156 if ($rescode == -1) {
1157 $this->errors[] =
'ErrorBadCustomerCodeSyntax';
1158 } elseif ($rescode == -2) {
1159 $this->errors[] =
'ErrorCustomerCodeRequired';
1160 } elseif ($rescode == -3) {
1161 $this->errors[] =
'ErrorCustomerCodeAlreadyUsed';
1162 } elseif ($rescode == -4) {
1163 $this->errors[] =
'ErrorPrefixRequired';
1165 $this->errors[] =
'ErrorUnknownOnCustomerCodeCheck';
1172 if ($this->fournisseur) {
1174 if ($rescode != 0 && $rescode != -5) {
1175 if ($rescode == -1) {
1176 $this->errors[] =
'ErrorBadSupplierCodeSyntax';
1177 } elseif ($rescode == -2) {
1178 $this->errors[] =
'ErrorSupplierCodeRequired';
1179 } elseif ($rescode == -3) {
1180 $this->errors[] =
'ErrorSupplierCodeAlreadyUsed';
1181 } elseif ($rescode == -4) {
1182 $this->errors[] =
'ErrorPrefixRequired';
1184 $this->errors[] =
'ErrorUnknownOnSupplierCodeCheck';
1191 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL',
'TVA_INTRA');
1192 foreach ($array_to_check as $key) {
1193 $keymin = strtolower($key);
1194 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
1195 $vallabel = $this->$keymin;
1200 if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) {
1201 $idprof_mandatory =
'SOCIETE_'.$key.
'_MANDATORY';
1202 if (!$vallabel && !empty($conf->global->$idprof_mandatory)) {
1203 $langs->load(
"errors");
1205 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->transcountry(
'ProfId'.$i, $this->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1212 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1213 $langs->load(
"errors");
1215 $this->errors[] = $langs->transcountry(
'ProfId'.$i, $this->country_code).
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1221 if ($key ==
'EMAIL') {
1223 if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email)) {
1224 $langs->load(
"errors");
1226 $this->errors[] = $langs->trans(
"ErrorBadEMail", $this->email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1230 if (!$error && $vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE)) {
1231 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1232 $langs->load(
"errors");
1233 $error++; $this->errors[] = $langs->trans(
'Email').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1236 } elseif ($key ==
'TVA_INTRA') {
1238 if ($vallabel && !empty($conf->global->SOCIETE_VAT_INTRA_UNIQUE)) {
1239 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1240 $langs->load(
"errors");
1241 $error++; $this->errors[] = $langs->trans(
'VATIntra').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1267 public function update($id, $user =
'', $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action =
'update', $nosyncmember = 1)
1269 global $langs, $conf, $hookmanager;
1271 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1279 dol_syslog(get_class($this).
"::Update id=".$id.
" call_trigger=".$call_trigger.
" allowmodcodeclient=".$allowmodcodeclient.
" allowmodcodefournisseur=".$allowmodcodefournisseur);
1285 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
1286 $this->
name = $this->
name ?trim($this->
name) : trim($this->nom);
1287 $this->nom = $this->name;
1288 $this->name_alias = trim($this->name_alias);
1289 $this->ref_ext = trim($this->ref_ext);
1290 $this->address = $this->address ?trim($this->address) : trim($this->address);
1291 $this->zip = $this->zip ?trim($this->zip) : trim($this->zip);
1292 $this->town = $this->town ?trim($this->town) : trim($this->town);
1293 $this->state_id = trim($this->state_id);
1294 $this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
1295 $this->phone = trim($this->phone);
1296 $this->phone = preg_replace(
"/\s/",
"", $this->phone);
1297 $this->phone = preg_replace(
"/\./",
"", $this->phone);
1298 $this->fax = trim($this->fax);
1299 $this->fax = preg_replace(
"/\s/",
"", $this->fax);
1300 $this->fax = preg_replace(
"/\./",
"", $this->fax);
1301 $this->email = trim($this->email);
1302 $this->url = $this->url ?
clean_url($this->url, 0) :
'';
1303 $this->note_private = trim($this->note_private);
1304 $this->note_public = trim($this->note_public);
1305 $this->idprof1 = trim($this->idprof1);
1306 $this->idprof2 = trim($this->idprof2);
1307 $this->idprof3 = trim($this->idprof3);
1308 $this->idprof4 = trim($this->idprof4);
1309 $this->idprof5 = (!empty($this->idprof5) ?trim($this->idprof5) :
'');
1310 $this->idprof6 = (!empty($this->idprof6) ?trim($this->idprof6) :
'');
1311 $this->prefix_comm = trim($this->prefix_comm);
1312 $this->outstanding_limit =
price2num($this->outstanding_limit);
1313 $this->order_min_amount =
price2num($this->order_min_amount);
1314 $this->supplier_order_min_amount =
price2num($this->supplier_order_min_amount);
1316 $this->tva_assuj = trim($this->tva_assuj);
1318 if (empty($this->status)) {
1322 if (!empty($this->multicurrency_code)) {
1325 if (empty($this->fk_multicurrency)) {
1326 $this->multicurrency_code =
'';
1327 $this->fk_multicurrency = 0;
1331 $this->localtax1_assuj = trim($this->localtax1_assuj);
1332 $this->localtax2_assuj = trim($this->localtax2_assuj);
1334 $this->localtax1_value = trim($this->localtax1_value);
1335 $this->localtax2_value = trim($this->localtax2_value);
1337 if ($this->capital !=
'') {
1338 $this->capital =
price2num(trim($this->capital));
1340 if (!is_numeric($this->capital)) {
1341 $this->capital =
'';
1344 $this->effectif_id = trim($this->effectif_id);
1345 $this->forme_juridique_code = trim($this->forme_juridique_code);
1348 $this->barcode = trim($this->barcode);
1351 if ($this->code_client == -1 || $this->code_client ===
'auto') {
1354 if ($this->code_fournisseur == -1 || $this->code_fournisseur ===
'auto') {
1358 $this->code_compta_client = trim(empty($this->code_compta) ? $this->code_compta_client : $this->code_compta);
1359 $this->code_compta = $this->code_compta_client;
1360 $this->code_compta_fournisseur = trim($this->code_compta_fournisseur);
1363 if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) {
1364 $langs->load(
"errors");
1365 $this->error = $langs->trans(
"BadValueForParameterClientOrSupplier");
1370 if (!empty($allowmodcodeclient) && !empty($this->client)) {
1372 if (empty($this->code_compta_client)) {
1383 if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) {
1385 if (empty($this->code_compta_fournisseur)) {
1396 $this->webservices_url = $this->webservices_url ?
clean_url($this->webservices_url, 0) :
'';
1397 $this->webservices_key = trim($this->webservices_key);
1399 $this->accountancy_code_buy = trim($this->accountancy_code_buy);
1400 $this->accountancy_code_sell = trim($this->accountancy_code_sell);
1403 $this->fk_incoterms = (int) $this->fk_incoterms;
1404 $this->location_incoterms = trim($this->location_incoterms);
1411 if ($action !=
'add' && $action !=
'merge') {
1414 $result = $this->
verify();
1418 if (is_array($this->errors)) {
1419 if (in_array(
'ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) {
1420 if (($key = array_search(
'ErrorBadCustomerCodeSyntax', $this->errors)) !==
false) {
1421 unset($this->errors[$key]);
1424 if (in_array(
'ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) {
1425 if (($key = array_search(
'ErrorBadSupplierCodeSyntax', $this->errors)) !==
false) {
1426 unset($this->errors[$key]);
1429 if (empty($this->errors)) {
1436 dol_syslog(get_class($this).
"::update verify ok or not done");
1438 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe SET ";
1439 $sql .=
"entity = ".$this->db->escape($this->entity);
1440 $sql .=
",nom = '".$this->db->escape($this->
name).
"'";
1441 $sql .=
",name_alias = '".$this->db->escape($this->name_alias).
"'";
1442 $sql .=
",ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1443 $sql .=
",address = '".$this->db->escape($this->address).
"'";
1445 $sql .=
",zip = ".(!empty($this->zip) ?
"'".$this->db->escape($this->zip).
"'" :
"null");
1446 $sql .=
",town = ".(!empty($this->town) ?
"'".$this->db->escape($this->town).
"'" :
"null");
1448 $sql .=
",fk_departement = ".((!empty($this->state_id) && $this->state_id > 0) ? ((
int) $this->state_id) :
'null');
1449 $sql .=
",fk_pays = ".((!empty($this->country_id) && $this->country_id > 0) ? ((
int) $this->country_id) :
'null');
1451 $sql .=
",phone = ".(!empty($this->phone) ?
"'".$this->db->escape($this->phone).
"'" :
"null");
1452 $sql .=
",fax = ".(!empty($this->fax) ?
"'".$this->db->escape($this->fax).
"'" :
"null");
1453 $sql .=
",email = ".(!empty($this->email) ?
"'".$this->db->escape($this->email).
"'" :
"null");
1454 $sql .=
",socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1455 $sql .=
",url = ".(!empty($this->url) ?
"'".$this->db->escape($this->url).
"'" :
"null");
1457 $sql .=
",parent = ".($this->parent > 0 ? $this->parent :
"null");
1459 $sql .=
",note_private = ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
1460 $sql .=
",note_public = ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
1462 $sql .=
",siren = '".$this->db->escape($this->idprof1).
"'";
1463 $sql .=
",siret = '".$this->db->escape($this->idprof2).
"'";
1464 $sql .=
",ape = '".$this->db->escape($this->idprof3).
"'";
1465 $sql .=
",idprof4 = '".$this->db->escape($this->idprof4).
"'";
1466 $sql .=
",idprof5 = '".$this->db->escape($this->idprof5).
"'";
1467 $sql .=
",idprof6 = '".$this->db->escape($this->idprof6).
"'";
1469 $sql .=
",tva_assuj = ".($this->tva_assuj !=
'' ?
"'".$this->db->escape($this->tva_assuj).
"'" :
"null");
1470 $sql .=
",tva_intra = '".$this->db->escape($this->tva_intra).
"'";
1471 $sql .=
",status = ".((int) $this->status);
1474 $sql .=
",localtax1_assuj = ".($this->localtax1_assuj !=
'' ?
"'".$this->db->escape($this->localtax1_assuj).
"'" :
"null");
1475 $sql .=
",localtax2_assuj = ".($this->localtax2_assuj !=
'' ?
"'".$this->db->escape($this->localtax2_assuj).
"'" :
"null");
1476 if ($this->localtax1_assuj == 1) {
1477 if ($this->localtax1_value !=
'') {
1478 $sql .=
",localtax1_value =".$this->localtax1_value;
1480 $sql .=
",localtax1_value =0.000";
1483 $sql .=
",localtax1_value =0.000";
1486 if ($this->localtax2_assuj == 1) {
1487 if ($this->localtax2_value !=
'') {
1488 $sql .=
",localtax2_value =".$this->localtax2_value;
1490 $sql .=
",localtax2_value =0.000";
1493 $sql .=
",localtax2_value =0.000";
1496 $sql .=
",capital = ".($this->capital ==
'' ?
"null" : $this->capital);
1498 $sql .=
",prefix_comm = ".(!empty($this->prefix_comm) ?
"'".$this->db->escape($this->prefix_comm).
"'" :
"null");
1500 $sql .=
",fk_effectif = ".($this->effectif_id > 0 ? ((int) $this->effectif_id) :
"null");
1501 if (isset($this->stcomm_id)) {
1502 $sql .=
",fk_stcomm=".(int) $this->stcomm_id;
1504 if (isset($this->typent_id)) {
1505 $sql .=
",fk_typent = ".($this->typent_id > 0 ? ((int) $this->typent_id) :
"0");
1508 $sql .=
",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ?
"'".$this->db->escape($this->forme_juridique_code).
"'" :
"null");
1510 $sql .=
",mode_reglement = ".(!empty($this->mode_reglement_id) ?
"'".$this->db->escape($this->mode_reglement_id).
"'" :
"null");
1511 $sql .=
",cond_reglement = ".(!empty($this->cond_reglement_id) ?
"'".$this->db->escape($this->cond_reglement_id).
"'" :
"null");
1512 $sql .=
",deposit_percent = ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null");
1513 $sql .=
",transport_mode = ".(!empty($this->transport_mode_id) ?
"'".$this->db->escape($this->transport_mode_id).
"'" :
"null");
1514 $sql .=
",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ?
"'".$this->db->escape($this->mode_reglement_supplier_id).
"'" :
"null");
1515 $sql .=
",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ?
"'".$this->db->escape($this->cond_reglement_supplier_id).
"'" :
"null");
1516 $sql .=
",transport_mode_supplier = ".(!empty($this->transport_mode_supplier_id) ?
"'".$this->db->escape($this->transport_mode_supplier_id).
"'" :
"null");
1517 $sql .=
",fk_shipping_method = ".(!empty($this->shipping_method_id) ?
"'".$this->db->escape($this->shipping_method_id).
"'" :
"null");
1519 $sql .=
",client = ".(!empty($this->client) ? $this->client : 0);
1520 $sql .=
",fournisseur = ".(!empty($this->fournisseur) ? $this->fournisseur : 0);
1521 $sql .=
",barcode = ".(!empty($this->barcode) ?
"'".$this->db->escape($this->barcode).
"'" :
"null");
1522 $sql .=
",default_lang = ".(!empty($this->default_lang) ?
"'".$this->db->escape($this->default_lang).
"'" :
"null");
1523 $sql .=
",logo = ".(!empty($this->logo) ?
"'".$this->db->escape($this->logo).
"'" :
"null");
1524 $sql .=
",logo_squarred = ".(!empty($this->logo_squarred) ?
"'".$this->db->escape($this->logo_squarred).
"'" :
"null");
1525 $sql .=
",outstanding_limit= ".($this->outstanding_limit !=
'' ? $this->outstanding_limit :
'null');
1526 $sql .=
",order_min_amount= ".($this->order_min_amount !=
'' ? $this->order_min_amount :
'null');
1527 $sql .=
",supplier_order_min_amount= ".($this->supplier_order_min_amount !=
'' ? $this->supplier_order_min_amount :
'null');
1528 $sql .=
",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel).
"'";
1529 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1530 $sql .=
", accountancy_code_buy = '".$this->db->escape($this->accountancy_code_buy).
"'";
1531 $sql .=
", accountancy_code_sell= '".$this->db->escape($this->accountancy_code_sell).
"'";
1534 $sql .=
", code_compta = ".(!empty($this->code_compta_client) ?
"'".$this->db->escape($this->code_compta_client).
"'" :
"null");
1538 $sql .=
", code_compta_fournisseur = ".(($this->code_compta_fournisseur !=
"") ?
"'".$this->
db->escape($this->code_compta_fournisseur).
"'" :
"null");
1541 $sql .=
",webservices_url = ".(!empty($this->webservices_url) ?
"'".$this->db->escape($this->webservices_url).
"'" :
"null");
1542 $sql .=
",webservices_key = ".(!empty($this->webservices_key) ?
"'".$this->db->escape($this->webservices_key).
"'" :
"null");
1545 $sql .=
", fk_incoterms = ".((int) $this->fk_incoterms);
1546 $sql .=
", location_incoterms = ".(!empty($this->location_incoterms) ?
"'".$this->db->escape($this->location_incoterms).
"'" :
"null");
1549 $sql .=
", code_client = ".(!empty($this->code_client) ?
"'".$this->db->escape($this->code_client).
"'" :
"null");
1553 $sql .=
", code_fournisseur = ".(!empty($this->code_fournisseur) ?
"'".$this->db->escape($this->code_fournisseur).
"'" :
"null");
1555 $sql .=
", fk_user_modif = ".($user->id > 0 ? $user->id :
"null");
1556 $sql .=
", fk_multicurrency = ".(int) $this->fk_multicurrency;
1557 $sql .=
", multicurrency_code = '".$this->db->escape($this->multicurrency_code).
"'";
1558 $sql .=
", model_pdf = '".$this->db->escape($this->model_pdf).
"'";
1559 $sql .=
" WHERE rowid = ".(int) $id;
1563 if (is_object($this->oldcopy)) {
1564 if ($this->oldcopy->country_id != $this->country_id) {
1565 unset($this->country_code);
1566 unset($this->country);
1568 if ($this->oldcopy->state_id != $this->state_id) {
1569 unset($this->state_code);
1570 unset($this->state);
1573 unset($this->country_code);
1574 unset($this->country);
1575 unset($this->state_code);
1576 unset($this->state);
1579 $nbrowsaffected = $this->
db->affected_rows(
$resql);
1581 if (!$error && $nbrowsaffected) {
1584 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1586 dol_syslog(get_class($this).
"::update update linked member");
1589 $result = $lmember->fetch(0, 0, $this->
id);
1592 $lmember->company = $this->name;
1595 $lmember->address = $this->address;
1596 $lmember->zip = $this->zip;
1597 $lmember->town = $this->town;
1598 $lmember->email = $this->email;
1599 $lmember->socialnetworks = $this->socialnetworks;
1600 $lmember->phone = $this->phone;
1601 $lmember->state_id = $this->state_id;
1602 $lmember->country_id = $this->country_id;
1603 $lmember->default_lang = $this->default_lang;
1605 $result = $lmember->update($user, 0, 1, 1, 1);
1607 $this->error = $lmember->error;
1608 $this->errors = array_merge($this->errors, $lmember->errors);
1609 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
1612 } elseif ($result < 0) {
1613 $this->error = $lmember->error;
1622 if (!$error && !empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1623 $this->
db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int) $conf->entity));
1625 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
1628 $sql .=
", accountancy_code_customer";
1629 $sql .=
", accountancy_code_supplier";
1630 $sql .=
", accountancy_code_buy";
1631 $sql .=
", accountancy_code_sell";
1632 $sql .=
") VALUES (";
1634 $sql .=
", ".$conf->entity;
1635 $sql .=
", '".$this->db->escape($this->code_compta_client).
"'";
1636 $sql .=
", '".$this->db->escape($this->code_compta_fournisseur).
"'";
1637 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1638 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1640 $result = $this->
db->query($sql);
1643 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1655 if (!$error && empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) {
1662 if (!$error && $call_trigger) {
1664 $result = $this->
call_trigger(
'COMPANY_MODIFY', $user);
1672 dol_syslog(get_class($this).
"::Update success");
1673 $this->
db->commit();
1676 $this->
db->rollback();
1680 if ($this->
db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1682 $this->error = $langs->trans(
"ErrorDuplicateField");
1685 $this->error = $this->
db->lasterror();
1688 $this->
db->rollback();
1692 $this->
db->rollback();
1693 dol_syslog(get_class($this).
"::Update fails verify ".join(
',', $this->errors), LOG_WARNING);
1715 public function fetch($rowid, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'')
1720 if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) {
1724 $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';
1725 $sql .=
', s.status, s.fk_warehouse';
1726 $sql .=
', s.price_level';
1727 $sql .=
', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif';
1728 $sql .=
', s.phone, s.fax, s.email';
1729 $sql .=
', s.socialnetworks';
1730 $sql .=
', s.url, s.zip, s.town, s.note_private, s.note_public, s.client, s.fournisseur';
1731 $sql .=
', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1732 $sql .=
', s.capital, s.tva_intra';
1733 $sql .=
', s.fk_typent as typent_id';
1734 $sql .=
', s.fk_effectif as effectif_id';
1735 $sql .=
', s.fk_forme_juridique as forme_juridique_code';
1736 $sql .=
', s.webservices_url, s.webservices_key, s.model_pdf, s.last_main_doc';
1737 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1738 $sql .=
', s.code_compta, s.code_compta_fournisseur, s.accountancy_code_buy, s.accountancy_code_sell';
1740 $sql .=
', spe.accountancy_code_customer as code_compta, spe.accountancy_code_supplier as code_compta_fournisseur, spe.accountancy_code_buy, spe.accountancy_code_sell';
1742 $sql .=
', s.code_client, s.code_fournisseur, s.parent, s.barcode';
1743 $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';
1744 $sql .=
', s.fk_account, s.tva_assuj';
1745 $sql .=
', s.mode_reglement_supplier, s.cond_reglement_supplier, s.transport_mode_supplier';
1746 $sql .=
', s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred';
1747 $sql .=
', s.fk_shipping_method';
1748 $sql .=
', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1749 $sql .=
', s.order_min_amount, s.supplier_order_min_amount';
1750 $sql .=
', s.fk_multicurrency, s.multicurrency_code';
1751 $sql .=
', fj.libelle as forme_juridique';
1752 $sql .=
', e.libelle as effectif';
1753 $sql .=
', c.code as country_code, c.label as country';
1754 $sql .=
', d.code_departement as state_code, d.nom as state';
1755 $sql .=
', r.rowid as region_id, r.code_region as region_code';
1756 $sql .=
', st.libelle as stcomm, st.picto as stcomm_picto';
1757 $sql .=
', te.code as typent_code';
1758 $sql .=
', i.libelle as label_incoterms';
1760 $sql .=
', s.remise_client, s.remise_supplier';
1762 $sql .=
', sr.remise_client, sr2.remise_supplier';
1764 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
1765 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1766 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = ".((int) $conf->entity);
1768 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_effectif as e ON s.fk_effectif = e.id';
1769 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON s.fk_pays = c.rowid';
1770 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcomm as st ON s.fk_stcomm = st.id';
1771 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
1772 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON s.fk_departement = d.rowid';
1773 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_regions as r ON d.fk_region = r.code_region ';
1774 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_typent as te ON s.fk_typent = te.id';
1775 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON s.fk_incoterms = i.rowid';
1779 $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').
'))';
1780 $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').
'))';
1782 $sql .=
' WHERE s.entity IN ('.getEntity($this->element).
')';
1784 $sql .=
' AND s.rowid = '.((int) $rowid);
1787 $sql .=
" AND s.nom = '".$this->db->escape($ref).
"'";
1790 $sql .=
" AND s.name_alias = '".$this->db->escape($ref_alias).
"'";
1793 $sql .=
" AND s.ref_ext = '".$this->db->escape($ref_ext).
"'";
1796 $sql .=
" AND s.barcode = '".$this->db->escape($barcode).
"'";
1799 $sql .=
" AND s.siren = '".$this->db->escape($idprof1).
"'";
1802 $sql .=
" AND s.siret = '".$this->db->escape($idprof2).
"'";
1805 $sql .=
" AND s.ape = '".$this->db->escape($idprof3).
"'";
1808 $sql .=
" AND s.idprof4 = '".$this->db->escape($idprof4).
"'";
1811 $sql .=
" AND s.idprof5 = '".$this->db->escape($idprof5).
"'";
1814 $sql .=
" AND s.idprof6 = '".$this->db->escape($idprof6).
"'";
1817 $sql .=
" AND s.email = '".$this->db->escape($email).
"'";
1822 $num = $this->
db->num_rows(
$resql);
1824 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
1828 $obj = $this->
db->fetch_object(
$resql);
1830 $this->
id = $obj->rowid;
1831 $this->entity = $obj->entity;
1832 $this->canvas = $obj->canvas;
1834 $this->
ref = $obj->rowid;
1835 $this->
name = $obj->name;
1836 $this->nom = $obj->name;
1837 $this->name_alias = $obj->name_alias;
1838 $this->ref_ext = $obj->ref_ext;
1840 $this->date_creation = $this->
db->jdate($obj->date_creation);
1841 $this->date_modification = $this->
db->jdate($obj->date_modification);
1842 $this->user_creation = $obj->fk_user_creat;
1843 $this->user_modification = $obj->fk_user_modif;
1845 $this->address = $obj->address;
1846 $this->zip = $obj->zip;
1847 $this->town = $obj->town;
1849 $this->country_id = $obj->country_id;
1850 $this->country_code = $obj->country_id ? $obj->country_code :
'';
1851 $this->country = $obj->country_id ? (($langs->transnoentities(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code) ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
1853 $this->state_id = $obj->state_id;
1854 $this->state_code = $obj->state_code;
1855 $this->region_id = $obj->region_id;
1856 $this->region_code = $obj->region_code;
1857 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
1859 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcomm);
1860 $label = ($transcode !=
'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm);
1861 $this->stcomm_id = $obj->fk_stcomm;
1862 $this->status_prospect_label = $label;
1863 $this->stcomm_picto = $obj->stcomm_picto;
1865 $this->email = $obj->email;
1866 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
1868 $this->url = $obj->url;
1869 $this->phone = $obj->phone;
1870 $this->fax = $obj->fax;
1872 $this->parent = $obj->parent;
1874 $this->idprof1 = $obj->idprof1;
1875 $this->idprof2 = $obj->idprof2;
1876 $this->idprof3 = $obj->idprof3;
1877 $this->idprof4 = $obj->idprof4;
1878 $this->idprof5 = $obj->idprof5;
1879 $this->idprof6 = $obj->idprof6;
1881 $this->capital = $obj->capital;
1883 $this->code_client = $obj->code_client;
1884 $this->code_fournisseur = $obj->code_fournisseur;
1886 $this->code_compta = $obj->code_compta;
1887 $this->code_compta_client = $obj->code_compta;
1888 $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
1890 $this->barcode = $obj->barcode;
1892 $this->tva_assuj = $obj->tva_assuj;
1893 $this->tva_intra = $obj->tva_intra;
1894 $this->status = $obj->status;
1897 $this->localtax1_assuj = $obj->localtax1_assuj;
1898 $this->localtax2_assuj = $obj->localtax2_assuj;
1900 $this->localtax1_value = $obj->localtax1_value;
1901 $this->localtax2_value = $obj->localtax2_value;
1903 $this->typent_id = $obj->typent_id;
1904 $this->typent_code = $obj->typent_code;
1906 $this->effectif_id = $obj->effectif_id;
1907 $this->effectif = $obj->effectif_id ? $obj->effectif :
'';
1909 $this->forme_juridique_code = $obj->forme_juridique_code;
1910 $this->forme_juridique = $obj->forme_juridique_code ? $obj->forme_juridique :
'';
1912 $this->fk_prospectlevel = $obj->fk_prospectlevel;
1914 $this->prefix_comm = $obj->prefix_comm;
1916 $this->remise_percent = $obj->remise_client ?
price2num($obj->remise_client) : 0;
1917 $this->remise_supplier_percent = $obj->remise_supplier;
1919 $this->mode_reglement_id = $obj->mode_reglement;
1920 $this->cond_reglement_id = $obj->cond_reglement;
1921 $this->deposit_percent = $obj->deposit_percent;
1922 $this->transport_mode_id = $obj->transport_mode;
1923 $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier;
1924 $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier;
1925 $this->transport_mode_supplier_id = $obj->transport_mode_supplier;
1926 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
1927 $this->fk_account = $obj->fk_account;
1929 $this->client = $obj->client;
1930 $this->fournisseur = $obj->fournisseur;
1932 $this->note = $obj->note_private;
1933 $this->note_private = $obj->note_private;
1934 $this->note_public = $obj->note_public;
1935 $this->model_pdf = $obj->model_pdf;
1936 $this->modelpdf = $obj->model_pdf;
1937 $this->default_lang = $obj->default_lang;
1938 $this->logo = $obj->logo;
1939 $this->logo_squarred = $obj->logo_squarred;
1941 $this->webservices_url = $obj->webservices_url;
1942 $this->webservices_key = $obj->webservices_key;
1944 $this->accountancy_code_buy = $obj->accountancy_code_buy;
1945 $this->accountancy_code_sell = $obj->accountancy_code_sell;
1947 $this->outstanding_limit = $obj->outstanding_limit;
1948 $this->order_min_amount = $obj->order_min_amount;
1949 $this->supplier_order_min_amount = $obj->supplier_order_min_amount;
1952 $this->price_level = $obj->price_level;
1955 $this->fk_warehouse = $obj->fk_warehouse;
1957 $this->import_key = $obj->import_key;
1960 $this->fk_incoterms = $obj->fk_incoterms;
1961 $this->location_incoterms = $obj->location_incoterms;
1962 $this->label_incoterms = $obj->label_incoterms;
1965 $this->fk_multicurrency = $obj->fk_multicurrency;
1966 $this->multicurrency_code = $obj->multicurrency_code;
1969 $this->model_pdf = $obj->model_pdf;
1970 $this->last_main_doc = $obj->last_main_doc;
1975 $this->fetch_optionals();
1982 $this->error = $this->
db->lasterror();
1983 $this->errors[] = $this->
db->lasterror();
1988 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($this->price_level)) {
1989 $this->price_level = 1;
2003 public function delete($id,
User $fuser =
null, $call_trigger = 1)
2005 global $langs, $conf, $user;
2007 if (empty($fuser)) {
2011 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2013 $entity = isset($this->entity) ? $this->entity : $conf->entity;
2015 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2020 if (empty($objectisused)) {
2024 if (!$error && $call_trigger) {
2026 $result = $this->
call_trigger(
'COMPANY_DELETE', $fuser);
2034 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2036 $toute_categs = array();
2039 if ($this->client || $this->prospect) {
2040 $toute_categs[
'customer'] = $static_cat->containing($this->
id, Categorie::TYPE_CUSTOMER);
2042 if ($this->fournisseur) {
2043 $toute_categs[
'supplier'] = $static_cat->containing($this->
id, Categorie::TYPE_SUPPLIER);
2047 foreach ($toute_categs as $type => $categs_type) {
2048 foreach ($categs_type as $cat) {
2049 $cat->del_type($this, $type);
2055 foreach ($this->childtablesoncascade as $tabletodelete) {
2056 $deleteFromObject = explode(
':', $tabletodelete);
2057 if (count($deleteFromObject) >= 2) {
2058 $className = str_replace(
'@',
'', $deleteFromObject[0]);
2059 $filepath = $deleteFromObject[1];
2060 $columnName = $deleteFromObject[2];
2062 $child_object =
new $className($this->
db);
2063 $result = $child_object->deleteByParentField($id, $columnName);
2066 $this->errors[] = $child_object->error;
2071 $this->errors[] =
'Cannot include child class file '.$filepath;
2075 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
2076 $sql .=
" WHERE fk_soc = ".((int) $id);
2077 if (!$this->
db->query($sql)) {
2079 $this->errors[] = $this->
db->lasterror();
2091 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
2097 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2098 $sql .=
" SET parent = NULL";
2099 $sql .=
" WHERE parent = ".((int) $id);
2100 if (!$this->
db->query($sql)) {
2102 $this->errors[] = $this->
db->lasterror();
2108 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
2109 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity";
2110 $sql .=
" WHERE fk_soc = ".((int) $id);
2111 if (!$this->
db->query($sql)) {
2113 $this->errors[] = $this->
db->lasterror();
2117 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe";
2118 $sql .=
" WHERE rowid = ".((int) $id);
2119 if (!$this->
db->query($sql)) {
2121 $this->errors[] = $this->
db->lasterror();
2126 $this->
db->commit();
2129 if (!empty($conf->societe->multidir_output[$entity])) {
2130 $docdir = $conf->societe->multidir_output[$entity].
"/".$id;
2139 $this->
db->rollback();
2143 dol_syslog(
"Can't remove thirdparty with id ".$id.
". There is ".$objectisused.
" childs", LOG_WARNING);
2160 if (($this->client == 2 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
2163 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2164 $sql .=
" SET client = ".((int) $newclient);
2165 $sql .=
" WHERE rowid = ".((int) $this->
id);
2169 $this->client = $newclient;
2190 global $conf, $langs;
2193 $note = trim($note);
2195 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2199 dol_syslog(get_class($this).
"::set_remise_client ".$remise.
", ".$note.
", ".$user->id);
2207 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2208 $sql .=
" SET remise_client = '".$this->db->escape($remise).
"'";
2209 $sql .=
" WHERE rowid = ".((int) $this->
id);
2212 $this->
db->rollback();
2213 $this->error = $this->
db->error();
2218 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise";
2219 $sql .=
" (entity, datec, fk_soc, remise_client, note, fk_user_author)";
2220 $sql .=
" VALUES (".$conf->entity.
", '".$this->
db->idate($now).
"', ".((int) $this->
id).
", '".$this->
db->escape($remise).
"',";
2221 $sql .=
" '".$this->db->escape($note).
"',";
2222 $sql .=
" ".((int) $user->id);
2227 $this->
db->rollback();
2228 $this->error = $this->
db->lasterror();
2232 $this->
db->commit();
2249 global $conf, $langs;
2252 $note = trim($note);
2254 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2258 dol_syslog(get_class($this).
"::set_remise_supplier ".$remise.
", ".$note.
", ".$user->id);
2266 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2267 $sql .=
" SET remise_supplier = '".$this->db->escape($remise).
"'";
2268 $sql .=
" WHERE rowid = ".((int) $this->
id);
2271 $this->
db->rollback();
2272 $this->error = $this->
db->error();
2277 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise_supplier";
2278 $sql .=
" (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
2279 $sql .=
" VALUES (".$conf->entity.
", '".$this->
db->idate($now).
"', ".((int) $this->
id).
", '".$this->
db->escape($remise).
"',";
2280 $sql .=
" '".$this->db->escape($note).
"',";
2281 $sql .=
" ".((int) $user->id);
2286 $this->
db->rollback();
2287 $this->error = $this->
db->lasterror();
2291 $this->
db->commit();
2308 public function set_remise_except($remise,
User $user, $desc, $vatrate =
'', $discount_type = 0, $price_base_type =
'HT')
2315 $desc = trim($desc);
2318 if (!($remise > 0)) {
2319 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"1");
2323 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"3");
2327 if ($this->
id > 0) {
2331 if (preg_match(
'/\((.*)\)/', $vatrate, $reg)) {
2332 $vat_src_code = $reg[1];
2333 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2336 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2339 $discount->fk_soc = $this->id;
2341 $discount->discount_type = $discount_type;
2343 if ($price_base_type ==
'TTC') {
2344 $discount->amount_ttc = $discount->multicurrency_amount_ttc =
price2num($remise,
'MT');
2345 $discount->amount_ht = $discount->multicurrency_amount_ht =
price2num($remise / (1 + $vatrate / 100),
'MT');
2346 $discount->amount_tva = $discount->multicurrency_amount_tva =
price2num($discount->amount_ttc - $discount->amount_ht,
'MT');
2348 $discount->amount_ht = $discount->multicurrency_amount_ht =
price2num($remise,
'MT');
2349 $discount->amount_tva = $discount->multicurrency_amount_tva =
price2num($remise * $vatrate / 100,
'MT');
2350 $discount->amount_ttc = $discount->multicurrency_amount_ttc =
price2num($discount->amount_ht + $discount->amount_tva,
'MT');
2353 $discount->tva_tx =
price2num($vatrate);
2354 $discount->vat_src_code = $vat_src_code;
2356 $discount->description = $desc;
2358 $result = $discount->create($user);
2362 $this->error = $discount->error;
2381 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2384 $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type);
2388 $this->error = $discountstatic->error;
2406 $reparray = array();
2408 $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";
2409 $sql .=
", u.office_fax, u.user_mobile, u.personal_mobile";
2410 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc, ".MAIN_DB_PREFIX.
"user as u";
2411 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2412 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
2413 $sql .=
" WHERE ((ug.fk_user = sc.fk_user";
2414 $sql .=
" AND ug.entity = ".$conf->entity.
")";
2415 $sql .=
" OR u.admin = 1)";
2417 $sql .=
" WHERE entity in (0, ".$conf->entity.
")";
2420 $sql .=
" AND u.rowid = sc.fk_user AND sc.fk_soc = ".((int) $this->
id);
2421 if (empty($sortfield) && empty($sortorder)) {
2422 $sortfield =
'u.lastname,u.firstname';
2423 $sortorder =
'ASC,ASC';
2425 $sql .= $this->
db->order($sortfield, $sortorder);
2429 $num = $this->
db->num_rows(
$resql);
2432 $obj = $this->
db->fetch_object(
$resql);
2435 $reparray[$i][
'id'] = $obj->rowid;
2436 $reparray[$i][
'lastname'] = $obj->lastname;
2437 $reparray[$i][
'firstname'] = $obj->firstname;
2438 $reparray[$i][
'email'] = $obj->email;
2439 $reparray[$i][
'phone'] = $obj->office_phone;
2440 $reparray[$i][
'office_phone'] = $obj->office_phone;
2441 $reparray[$i][
'office_fax'] = $obj->office_fax;
2442 $reparray[$i][
'user_mobile'] = $obj->user_mobile;
2443 $reparray[$i][
'personal_mobile'] = $obj->personal_mobile;
2444 $reparray[$i][
'job'] = $obj->job;
2445 $reparray[$i][
'statut'] = $obj->status;
2446 $reparray[$i][
'status'] = $obj->status;
2447 $reparray[$i][
'entity'] = $obj->entity;
2448 $reparray[$i][
'login'] = $obj->login;
2449 $reparray[$i][
'photo'] = $obj->photo;
2450 $reparray[$i][
'gender'] = $obj->gender;
2452 $reparray[] = $obj->rowid;
2475 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2476 $sql .=
" SET price_level = ".((int) $price_level);
2477 $sql .=
" WHERE rowid = ".((int) $this->
id);
2479 if (!$this->
db->query($sql)) {
2484 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_prices";
2485 $sql .=
" (datec, fk_soc, price_level, fk_user_author)";
2486 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $this->
id).
", ".((int) $price_level).
", ".((int) $user->id).
")";
2488 if (!$this->
db->query($sql)) {
2510 if ($this->
id > 0 && $commid > 0) {
2514 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux";
2515 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2519 dol_syslog(get_class($this).
"::add_commercial Error ".$this->
db->lasterror());
2525 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_commerciaux";
2526 $sql .=
" (fk_soc, fk_user)";
2527 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $commid).
")";
2531 dol_syslog(get_class($this).
"::add_commercial Error ".$this->
db->lasterror());
2537 $this->context = array(
'commercial_modified' => $commid);
2539 $result = $this->
call_trigger(
'COMPANY_LINK_SALE_REPRESENTATIVE', $user);
2546 $this->
db->commit();
2549 $this->
db->rollback();
2569 $this->context = array(
'commercial_modified'=>$commid);
2571 $result = $this->
call_trigger(
'COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
2576 if ($this->
id > 0 && $commid > 0) {
2577 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux ";
2578 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2580 if (!$this->
db->query($sql)) {
2581 dol_syslog(get_class($this).
"::del_commercial Erreur");
2599 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1, $noaliasinname = 0, $target =
'')
2601 global $conf, $langs, $hookmanager;
2603 if (!empty($conf->dol_no_mouse_hover)) {
2607 $name = $this->
name ? $this->
name : $this->nom;
2609 if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) {
2610 if (empty($option) && $this->client > 0) {
2611 $option =
'customer';
2613 if (empty($option) && $this->fournisseur > 0) {
2614 $option =
'supplier';
2618 if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto))) {
2620 if (($this->client) && (!empty($this->code_client)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 2)) {
2621 $code = $this->code_client.
' - ';
2624 if (($this->fournisseur) && (!empty($this->code_fournisseur)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 3)) {
2625 $code .= $this->code_fournisseur.
' - ';
2629 if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1) {
2630 $name = $code.
' '.$name;
2637 if (!empty($this->name_alias) && empty($noaliasinname)) {
2638 $name .=
' ('.$this->name_alias.
')';
2641 $result =
''; $label =
''; $label2 =
'';
2642 $linkstart =
''; $linkend =
'';
2644 if (!empty($this->logo) && class_exists(
'Form')) {
2645 $label .=
'<div class="photointooltip floatright">';
2646 $label .=
Form::showphoto(
'societe', $this, 0, 40, 0,
'photoref',
'mini', 0);
2649 } elseif (!empty($this->logo_squarred) && class_exists(
'Form')) {
2655 $label .=
'<div class="centpercent">';
2657 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
2658 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Customer").
'</u>';
2659 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2660 } elseif ($option ==
'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
2661 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Prospect").
'</u>';
2662 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2663 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
2664 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Supplier").
'</u>';
2665 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->id;
2666 } elseif ($option ==
'agenda') {
2667 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2668 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/agenda.php?socid='.$this->id;
2669 } elseif ($option ==
'project') {
2670 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2671 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/project.php?socid='.$this->id;
2672 } elseif ($option ==
'margin') {
2673 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2674 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/margin/tabs/thirdpartyMargins.php?socid='.$this->
id.
'&type=1';
2675 } elseif ($option ==
'contact') {
2676 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2677 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/contact.php?socid='.$this->id;
2678 } elseif ($option ==
'ban') {
2679 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2680 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$this->id;
2684 if (empty($linkstart)) {
2685 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2686 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$this->id;
2688 if (isset($this->status)) {
2689 $label .=
' '.$this->getLibStatut(5);
2691 if (isset($this->client) && isset($this->fournisseur)) {
2692 $label .=
' ';
2697 if (!empty($this->name_alias)) {
2702 $label .=
'<br>'.img_picto(
'',
'email',
'class="pictofixedwidth"').$this->email;
2704 if (!empty($this->phone) || !empty($this->fax)) {
2705 $phonelist = array();
2707 $phonelist[] =
dol_print_phone($this->phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2710 $phonelist[] =
dol_print_phone($this->fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2712 $label .=
'<br>'.implode(
' ', $phonelist);
2715 if (!empty($this->address)) {
2716 $label2 .=
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
' ', $langs);
2717 } elseif (!empty($this->country_code)) {
2718 $label2 .=
'<br><b>'.$langs->trans(
'Country').
':</b> '.$this->country_code;
2720 if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'vatnumber') !==
false)) {
2721 $label2 .=
'<br><b>'.$langs->trans(
'VATIntra').
':</b> '.
dol_escape_htmltag($this->tva_intra);
2724 if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP)) {
2725 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid1') !==
false && $langs->trans(
'ProfId1'.$this->country_code) !=
'-') {
2726 $label2 .=
'<br><b>'.$langs->trans(
'ProfId1'.$this->country_code).
':</b> '.$this->idprof1;
2728 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid2') !==
false && $langs->trans(
'ProfId2'.$this->country_code) !=
'-') {
2729 $label2 .=
'<br><b>'.$langs->trans(
'ProfId2'.$this->country_code).
':</b> '.$this->idprof2;
2731 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid3') !==
false && $langs->trans(
'ProfId3'.$this->country_code) !=
'-') {
2732 $label2 .=
'<br><b>'.$langs->trans(
'ProfId3'.$this->country_code).
':</b> '.$this->idprof3;
2734 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid4') !==
false && $langs->trans(
'ProfId4'.$this->country_code) !=
'-') {
2735 $label2 .=
'<br><b>'.$langs->trans(
'ProfId4'.$this->country_code).
':</b> '.$this->idprof4;
2737 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid5') !==
false && $langs->trans(
'ProfId5'.$this->country_code) !=
'-') {
2738 $label2 .=
'<br><b>'.$langs->trans(
'ProfId5'.$this->country_code).
':</b> '.$this->idprof5;
2740 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid6') !==
false && $langs->trans(
'ProfId6'.$this->country_code) !=
'-') {
2741 $label2 .=
'<br><b>'.$langs->trans(
'ProfId6'.$this->country_code).
':</b> '.$this->idprof6;
2744 if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
2745 $label2 .=
'<br><b>'.$langs->trans(
'CustomerCode').
':</b> '.$this->code_client;
2747 if (!empty($this->code_fournisseur) && $this->fournisseur) {
2748 $label2 .=
'<br><b>'.$langs->trans(
'SupplierCode').
':</b> '.$this->code_fournisseur;
2750 if (
isModEnabled(
'accounting') && ($this->client == 1 || $this->client == 3)) {
2751 $label2 .=
'<br><b>'.$langs->trans(
'CustomerAccountancyCode').
':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client);
2753 if (
isModEnabled(
'accounting') && $this->fournisseur) {
2754 $label2 .=
'<br><b>'.$langs->trans(
'SupplierAccountancyCode').
':</b> '.$this->code_compta_fournisseur;
2756 $label .= ($label2 ?
'<br>'.$label2 :
'').
'</div>';
2759 $linkstart .= (!empty($this->canvas) ?
'&canvas='.$this->canvas :
'');
2761 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2762 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2763 $add_save_lastsearch_values = 1;
2765 if ($add_save_lastsearch_values) {
2766 $linkstart .=
'&save_lastsearch_values=1';
2771 if (empty($notooltip)) {
2772 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2773 $label = $langs->trans(
"ShowCompany");
2774 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2776 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
2777 $linkclose .=
' class="classfortooltip refurl"';
2778 $target_value = array(
'_self',
'_blank',
'_parent',
'_top');
2779 if (in_array($target, $target_value)) {
2780 $linkclose .=
' target="'.dol_escape_htmltag($target).
'"';
2783 $linkstart .= $linkclose.
'>';
2787 if (empty($user->rights->societe->client->voir) && $user->socid > 0 && $this->id != $user->socid) {
2792 $result .= $linkstart;
2794 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
2796 if ($withpicto != 2) {
2799 $result .= $linkend;
2802 $hookmanager->initHooks(array(
'thirdpartydao'));
2803 $parameters = array(
2805 'getnomurl' => &$result,
2806 'withpicto '=> $withpicto,
2809 'notooltip'=> $notooltip,
2810 'save_lastsearch_value'=> $save_lastsearch_value
2812 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2814 $result = $hookmanager->resPrint;
2816 $result .= $hookmanager->resPrint;
2831 public function getTypeUrl($withpicto = 0, $option =
'', $notooltip = 0, $tag =
'a')
2833 global $conf, $langs;
2836 if (empty($option) || preg_match(
'/prospect/', $option)) {
2837 if (($this->client == 2 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
2838 $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.
'>';
2841 if (empty($option) || preg_match(
'/customer/', $option)) {
2842 if (($this->client == 1 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
2843 $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.
'>';
2846 if (empty($option) || preg_match(
'/supplier/', $option)) {
2847 if (((
isModEnabled(
"fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) ||
isModEnabled(
"supplier_order") ||
isModEnabled(
"supplier_invoice")) && $this->fournisseur) {
2848 $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.
'>';
2863 return $this->
LibStatut($this->status, $mode);
2878 $langs->load(
'companies');
2880 $statusType =
'status4';
2882 $statusType =
'status6';
2885 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2886 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
2887 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"InActivity");
2888 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
2889 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"InActivity");
2892 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2908 if ($this->email && $addthirdparty) {
2909 if (empty($this->
name)) {
2910 $this->
name = $this->nom;
2912 $contact_emails[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->email.
">";
2915 return $contact_emails;
2931 if (!empty($this->phone)) {
2932 if (empty($this->
name)) {
2933 $this->
name = $this->nom;
2936 $contact_phone[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->phone.
">";
2938 return $contact_phone;
2954 $contact_property = array();
2957 $sql =
"SELECT rowid, email, statut as status, phone_mobile, lastname, poste, firstname";
2958 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
2959 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
2960 $sql .=
" AND entity IN (".getEntity($this->element).
")";
2961 $sql .=
" ORDER BY lastname, firstname";
2965 $nump = $this->
db->num_rows(
$resql);
2967 $sepa =
"("; $sepb =
")";
2968 if ($mode ==
'email') {
2970 $sepa =
"<"; $sepb =
">";
2973 while ($i < $nump) {
2974 $obj = $this->
db->fetch_object(
$resql);
2975 if ($mode ==
'email') {
2976 $property = $obj->email;
2977 } elseif ($mode ==
'mobile') {
2978 $property = $obj->phone_mobile;
2980 $property = $obj->$mode;
2984 if ($obj->status == 1 || empty($hidedisabled)) {
2985 if (empty($property)) {
2986 if ($mode ==
'email') {
2987 $property = $langs->transnoentitiesnoconv(
"NoEMail");
2988 } elseif ($mode ==
'mobile') {
2989 $property = $langs->transnoentitiesnoconv(
"NoMobilePhone");
2993 if (!empty($obj->poste)) {
2994 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ?
" - ".$obj->poste :
"").(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
2996 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3005 return $contact_property;
3018 $contacts = array();
3020 $sql =
"SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3023 $nump = $this->
db->num_rows(
$resql);
3026 while ($i < $nump) {
3027 $obj = $this->
db->fetch_object(
$resql);
3047 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
3048 $contacts = array();
3050 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3053 $nump = $this->
db->num_rows(
$resql);
3056 while ($i < $nump) {
3057 $obj = $this->
db->fetch_object(
$resql);
3059 $contact->fetch($obj->rowid);
3060 $contacts[] = $contact;
3081 $contact_property =
'';
3083 if (empty($rowid)) {
3087 $sql =
"SELECT rowid, email, phone_mobile, lastname, firstname";
3088 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3089 $sql .=
" WHERE rowid = ".((int) $rowid);
3093 $nump = $this->
db->num_rows(
$resql);
3096 $obj = $this->
db->fetch_object(
$resql);
3098 if ($mode ==
'email') {
3100 } elseif ($mode ==
'mobile') {
3101 $contact_property = $obj->phone_mobile;
3104 return $contact_property;
3121 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3124 $bac->fetch(0, $this->
id);
3127 if ($mode ==
'label') {
3128 return $bac->getRibLabel(
true);
3129 } elseif ($mode ==
'rum') {
3130 if (empty($bac->rum)) {
3131 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
3133 $bac->fetch_thirdparty();
3134 $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
3137 } elseif ($mode ==
'format') {
3138 return $bac->frstrecur;
3140 return 'BadParameterToFunctionDisplayRib';
3156 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3157 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE type='ban' AND fk_soc = ".((int) $this->
id);
3158 $result = $this->
db->query($sql);
3161 $this->errors[] = $this->
db->lasterror;
3164 $num_rows = $this->
db->num_rows($result);
3165 $rib_array = array();
3167 while ($obj = $this->
db->fetch_object($result)) {
3169 $rib->fetch($obj->rowid);
3170 $rib_array[] = $rib;
3190 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3191 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3193 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3194 foreach ($dirsociete as $dirroot) {
3200 $mod =
new $module();
3202 $this->code_client = $mod->getNextValue($objsoc, $type);
3203 $this->prefixCustomerIsRequired = $mod->prefixIsRequired;
3205 dol_syslog(get_class($this).
"::get_codeclient code_client=".$this->code_client.
" module=".$module);
3222 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3223 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3225 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3226 foreach ($dirsociete as $dirroot) {
3232 $mod =
new $module();
3234 $this->code_fournisseur = $mod->getNextValue($objsoc, $type);
3236 dol_syslog(get_class($this).
"::get_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3251 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3252 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3254 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3255 foreach ($dirsociete as $dirroot) {
3262 $mod =
new $module();
3264 dol_syslog(get_class($this).
"::codeclient_modifiable code_client=".$this->code_client.
" module=".$module);
3265 if ($mod->code_modifiable_null && !$this->code_client) {
3268 if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
3271 if ($mod->code_modifiable) {
3291 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3292 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3294 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3295 foreach ($dirsociete as $dirroot) {
3302 $mod =
new $module();
3304 dol_syslog(get_class($this).
"::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur.
" module=".$module);
3305 if ($mod->code_modifiable_null && !$this->code_fournisseur) {
3308 if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
3311 if ($mod->code_modifiable) {
3337 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3338 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3340 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3341 foreach ($dirsociete as $dirroot) {
3348 $mod =
new $module();
3350 dol_syslog(get_class($this).
"::check_codeclient code_client=".$this->code_client.
" module=".$module);
3351 $result = $mod->verif($this->
db, $this->code_client, $this, 0);
3353 $this->error = $mod->error;
3354 $this->errors = $mod->errors;
3378 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3379 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3381 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3382 foreach ($dirsociete as $dirroot) {
3389 $mod =
new $module();
3391 dol_syslog(get_class($this).
"::check_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3392 $result = $mod->verif($this->
db, $this->code_fournisseur, $this, 1);
3394 $this->error = $mod->error;
3395 $this->errors = $mod->errors;
3417 if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) {
3419 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3420 foreach ($dirsociete as $dirroot) {
3421 $res =
dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.
'.php');
3428 $classname = $conf->global->SOCIETE_CODECOMPTA_ADDON;
3429 $mod =
new $classname;
3432 $result = $mod->get_code($this->
db, $this, $type);
3434 if ($type ==
'customer') {
3435 $this->code_compta_client = $mod->code;
3436 $this->code_compta = $this->code_compta_client;
3437 } elseif ($type ==
'supplier') {
3438 $this->code_compta_fournisseur = $mod->code;
3443 $this->error =
'ErrorAccountancyCodeNotDefined';
3447 if ($type ==
'customer') {
3448 $this->code_compta_client =
'';
3449 $this->code_compta =
'';
3450 } elseif ($type ==
'supplier') {
3451 $this->code_compta_fournisseur =
'';
3466 dol_syslog(get_class($this).
'::setParent', LOG_DEBUG);
3472 if ($sameparent < 0) {
3475 if ($sameparent == 1) {
3476 setEventMessages(
'ParentCompanyToAddIsAlreadyAChildOfModifiedCompany',
null,
'warnings');
3481 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe SET parent = '.($id > 0 ? $id :
'null').
' WHERE rowid = '.((
int) $this->id);
3485 $this->parent = $id;
3505 if ($counter > 100) {
3506 dol_syslog(
"Too high level of parent - child for company. May be an infinite loop ?", LOG_WARNING);
3509 $sql =
'SELECT s.parent';
3510 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
3511 $sql .=
' WHERE rowid = '.((int) $idparent);
3514 $obj = $this->
db->fetch_object(
$resql);
3516 if ($obj->parent ==
'') {
3518 } elseif ($obj->parent == $idchild) {
3540 if ($company_id > 0) {
3541 $sql =
"SELECT parent FROM " . MAIN_DB_PREFIX .
"societe WHERE rowid = $company_id";
3544 if ($obj = $this->
db->fetch_object(
$resql)) {
3545 $parent = $obj->parent;
3546 if ($parent > 0 && !in_array($parent, $parents)) {
3547 $parents[] = $parent;
3555 setEventMessage($langs->trans(
'GetCompanyParentsError', $this->db->lasterror()),
'errors');
3574 $ret = (empty($conf->global->SOCIETE_IDPROF1_UNIQUE) ? false :
true);
3577 $ret = (empty($conf->global->SOCIETE_IDPROF2_UNIQUE) ? false :
true);
3580 $ret = (empty($conf->global->SOCIETE_IDPROF3_UNIQUE) ? false :
true);
3583 $ret = (empty($conf->global->SOCIETE_IDPROF4_UNIQUE) ? false :
true);
3586 $ret = (empty($conf->global->SOCIETE_IDPROF5_UNIQUE) ? false :
true);
3589 $ret = (empty($conf->global->SOCIETE_IDPROF6_UNIQUE) ? false :
true);
3638 $sql =
"SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"societe WHERE ".$field.
" = '".$this->
db->escape($value).
"' AND entity IN (".
getEntity(
'societe').
")";
3640 $sql .=
" AND rowid <> ".$socid;
3644 $obj = $this->
db->fetch_object(
$resql);
3648 print $this->
db->error();
3675 if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3680 if ($idprof == 1 && $soc->country_code ==
'FR') {
3681 $chaine = trim($this->idprof1);
3682 $chaine = preg_replace(
'/(\s)/',
'', $chaine);
3684 if (!is_numeric($chaine)) {
3696 for ($index = 0; $index < 9; $index++) {
3697 $number = (int) $chaine[$index];
3698 if (($index % 2) != 0) {
3699 if (($number *= 2) > 9) {
3707 if (($sum % 10) != 0) {
3713 if ($idprof == 2 && $soc->country_code ==
'FR') {
3714 $chaine = trim($this->idprof2);
3715 $chaine = preg_replace(
'/(\s)/',
'', $chaine);
3717 if (!is_numeric($chaine)) {
3729 for ($index = 0; $index < 14; $index++) {
3730 $number = (int) $chaine[$index];
3731 if (($index % 2) == 0) {
3732 if (($number *= 2) > 9) {
3740 if (($sum % 10) != 0) {
3747 if ($idprof == 1 && $soc->country_code ==
'ES') {
3748 $string = trim($this->idprof1);
3749 $string = preg_replace(
'/(\s)/',
'', $string);
3750 $string = strtoupper($string);
3753 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)) {
3758 for ($i = 0; $i < 9; $i++) {
3759 $num[$i] = substr($string, $i, 1);
3763 if (preg_match(
'/(^[0-9]{8}[A-Z]{1}$)/', $string)) {
3764 if ($num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) {
3772 $sum = $num[2] + $num[4] + $num[6];
3773 for ($i = 1; $i < 8; $i += 2) {
3774 $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1));
3776 $n = 10 - substr($sum, strlen($sum) - 1, 1);
3779 if (preg_match(
'/^[KLM]{1}/', $string)) {
3780 if ($num[8] == chr(64 + $n) || $num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) {
3788 if (preg_match(
'/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) {
3789 if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) {
3797 if (preg_match(
'/^[T]{1}/', $string)) {
3798 if ($num[8] == preg_match(
'/^[T]{1}[A-Z0-9]{8}$/', $string)) {
3806 if (preg_match(
'/^[XYZ]{1}/', $string)) {
3807 if ($num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array(
'X',
'Y',
'Z'), array(
'0',
'1',
'2'), $string), 0, 8) % 23, 1)) {
3820 if ($idprof == 1 && $soc->country_code ==
'PT') {
3821 $string = trim($this->idprof1);
3822 $string = preg_replace(
'/(\s)/',
'', $string);
3825 if (preg_match(
'/(^[0-9]{9}$)/', $string)) {
3834 if ($idprof == 1 && $soc->country_code ==
'DZ') {
3835 $string = trim($this->idprof1);
3836 $string = preg_replace(
'/(\s)/',
'', $string);
3839 if (preg_match(
'/(^[0-9]{15}$)/', $string)) {
3861 global $conf, $langs, $hookmanager;
3866 $hookmanager->initHooks(array(
'idprofurl'));
3867 $parameters = array(
'idprof'=>$idprof,
'company'=>$thirdparty);
3868 $reshook = $hookmanager->executeHooks(
'getIdProfUrl', $parameters, $this, $action);
3869 if (empty($reshook)) {
3870 if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3875 $strippedIdProf1 = str_replace(
' ',
'', $thirdparty->idprof1);
3876 if ($idprof == 1 && $thirdparty->country_code ==
'FR') {
3877 $url =
'https://annuaire-entreprises.data.gouv.fr/entreprise/'.$strippedIdProf1;
3879 if ($idprof == 1 && ($thirdparty->country_code ==
'GB' || $thirdparty->country_code ==
'UK')) {
3880 $url =
'https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
3882 if ($idprof == 1 && $thirdparty->country_code ==
'ES') {
3883 $url =
'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
3885 if ($idprof == 1 && $thirdparty->country_code ==
'IN') {
3886 $url =
'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.
';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3888 if ($idprof == 1 && $thirdparty->country_code ==
'DZ') {
3889 $url =
'http://nif.mfdgi.gov.dz/nif.asp?Nif='.$strippedIdProf1;
3891 if ($idprof == 1 && $thirdparty->country_code ==
'PT') {
3892 $url =
'http://www.nif.pt/'.$strippedIdProf1;
3896 return '<a target="_blank" rel="noopener noreferrer" href="'.$url.
'">'.$langs->trans(
"Check").
'</a>';
3899 return $hookmanager->resPrint;
3914 $sql =
"SELECT COUNT(*) as numproj FROM ".MAIN_DB_PREFIX.
"projet WHERE fk_soc = ".((int) $this->
id);
3917 $obj = $this->
db->fetch_object(
$resql);
3918 $count = $obj->numproj;
3921 print $this->
db->error();
3924 return ($count > 0);
3936 $sql =
"SELECT s.rowid, s.nom as name, s.datec, tms as datem,";
3937 $sql .=
" fk_user_creat, fk_user_modif";
3938 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
3939 $sql .=
" WHERE s.rowid = ".((int) $id);
3941 $result = $this->
db->query($sql);
3943 if ($this->
db->num_rows($result)) {
3944 $obj = $this->
db->fetch_object($result);
3946 $this->
id = $obj->rowid;
3948 $this->user_creation_id = $obj->fk_user_creat;
3949 $this->user_modification_id = $obj->fk_user_modif;
3950 $this->date_creation = $this->
db->jdate($obj->datec);
3951 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
3953 $this->
ref = $obj->name;
3956 $this->
db->free($result);
3972 $isacompany = empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES) ? 0 : 1;
3973 if (!empty($this->tva_intra)) {
3975 } elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) {
3977 } elseif (!empty($this->typent_code) && $this->typent_code !=
'TE_UNKNOWN') {
3979 if (preg_match(
'/^TE_PRIVATE/', $this->typent_code)) {
3996 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4009 $this->SupplierCategories = array();
4010 $sql =
"SELECT rowid, label";
4011 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
4012 $sql .=
" WHERE type = ".Categorie::TYPE_SUPPLIER;
4016 while ($obj = $this->
db->fetch_object(
$resql)) {
4017 $this->SupplierCategories[$obj->rowid] = $obj->label;
4035 if ($categorie_id > 0 && $this->
id > 0) {
4036 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_fournisseur (fk_categorie, fk_soc) ";
4037 $sql .=
" VALUES (".((int) $categorie_id).
", ".((int) $this->
id).
")";
4039 if (
$resql = $this->
db->query($sql)) {
4055 $sql =
"SELECT count(mc.email) as nb";
4056 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
4057 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->email).
"' ";
4058 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
4062 $obj = $this->
db->fetch_object(
$resql);
4068 $this->error = $this->
db->error();
4088 $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).
"'";
4091 $obj = $this->
db->fetch_object(
$resql);
4092 $noemail = $obj->nb;
4093 if (empty($noemail)) {
4094 $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()).
"')";
4098 $this->error = $this->
db->lasterror();
4099 $this->errors[] = $this->error;
4104 $this->error = $this->
db->lasterror();
4105 $this->errors[] = $this->error;
4108 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->
db->escape($this->email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
4112 $this->error = $this->
db->lasterror();
4113 $this->errors[] = $this->error;
4117 if (empty($error)) {
4118 $this->no_email = $no_email;
4119 $this->
db->commit();
4122 $this->
db->rollback();
4139 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->
db->escape($this->email).
"'";
4142 $obj = $this->
db->fetch_object(
$resql);
4143 $this->no_email = $obj->nb;
4146 $this->error = $this->
db->lasterror();
4147 $this->errors[] = $this->error;
4167 global $conf, $user, $langs;
4169 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
4172 if ($member->morphy ==
'mor') {
4173 if (empty($socname)) {
4174 $socname = $member->company? $member->company : $member->societe;
4176 if (!empty($fullname) && empty($socalias)) {
4177 $socalias = $fullname;
4179 } elseif (empty($socname) && $member->morphy ==
'phy') {
4180 if (empty($socname)) {
4181 $socname = $fullname;
4183 if (!empty($member->company) && empty($socalias)) {
4184 $socalias = $member->company;
4189 $alias = $socalias ? $socalias :
'';
4193 $this->
name = $name;
4194 $this->name_alias = $alias;
4195 $this->address = $member->address;
4196 $this->zip = $member->zip;
4197 $this->town = $member->town;
4198 $this->country_code = $member->country_code;
4199 $this->country_id = $member->country_id;
4200 $this->phone = $member->phone;
4201 $this->email = $member->email;
4202 $this->socialnetworks = $member->socialnetworks;
4203 $this->entity = $member->entity;
4206 $this->code_client = ($customercode ? $customercode : -1);
4207 $this->code_fournisseur = -1;
4208 $this->typent_code = ($member->morphy ==
'phy' ?
'TE_PRIVATE' : 0);
4209 $this->typent_id = $this->typent_code ?
dol_getIdFromCode($this->
db, $this->typent_code,
'c_typent',
'id',
'code') : 0;
4214 $result = $this->
create($user);
4218 if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT)) {
4220 $this->name_bis = $member->lastname;
4221 $this->firstname = $member->firstname;
4222 $this->civility_id = $member->civility_id;
4224 dol_syslog(
"We ask to create a contact/address too", LOG_DEBUG);
4229 $this->
db->rollback();
4234 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent";
4235 $sql .=
" SET fk_soc = ".((int) $this->
id);
4236 $sql .=
" WHERE rowid = ".((int) $member->id);
4240 $this->
db->commit();
4243 $this->error = $this->
db->error();
4245 $this->
db->rollback();
4250 dol_syslog(get_class($this).
"::create_from_member - 2 - ".$this->error.
" - ".join(
',', $this->errors), LOG_ERR);
4252 $this->
db->rollback();
4268 $this->
name = empty($conf->global->MAIN_INFO_SOCIETE_NOM) ?
'' : $conf->global->MAIN_INFO_SOCIETE_NOM;
4269 $this->address = empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS) ?
'' : $conf->global->MAIN_INFO_SOCIETE_ADDRESS;
4270 $this->zip = empty($conf->global->MAIN_INFO_SOCIETE_ZIP) ?
'' : $conf->global->MAIN_INFO_SOCIETE_ZIP;
4271 $this->town = empty($conf->global->MAIN_INFO_SOCIETE_TOWN) ?
'' : $conf->global->MAIN_INFO_SOCIETE_TOWN;
4272 $this->region_code = empty($conf->global->MAIN_INFO_SOCIETE_REGION) ?
'' : $conf->global->MAIN_INFO_SOCIETE_REGION;
4273 $this->
object = empty($conf->global->MAIN_INFO_SOCIETE_OBJECT) ?
'' : $conf->global->MAIN_INFO_SOCIETE_OBJECT;
4275 $this->note_private = empty($conf->global->MAIN_INFO_SOCIETE_NOTE) ?
'' : $conf->global->MAIN_INFO_SOCIETE_NOTE;
4277 $this->nom = $this->name;
4280 $country_id = $country_code = $country_label =
'';
4281 if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
4282 $tmp = explode(
':', $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
4283 $country_id = $tmp[0];
4284 if (!empty($tmp[1])) {
4285 $country_code = $tmp[1];
4286 $country_label = $tmp[2];
4289 dol_syslog(
"Your country setup use an old syntax. Reedit it using setup area.", LOG_WARNING);
4290 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4292 $country_label =
getCountry($country_id, 0, $this->
db);
4295 $this->country_id = $country_id;
4296 $this->country_code = $country_code;
4297 $this->country = $country_label;
4298 if (is_object($langs)) {
4299 $this->country = ($langs->trans(
'Country'.$country_code) !=
'Country'.$country_code) ? $langs->trans(
'Country'.$country_code) : $country_label;
4304 $state_id = 0; $state_code = $state_label =
'';
4305 if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE)) {
4306 $tmp = explode(
':', $conf->global->MAIN_INFO_SOCIETE_STATE);
4307 $state_id = $tmp[0];
4308 if (!empty($tmp[1])) {
4309 $state_code = $tmp[1];
4310 $state_label = $tmp[2];
4312 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);
4313 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4314 $state_code =
getState($state_id, 2, $this->
db);
4315 $state_label =
getState($state_id, 0, $this->
db);
4318 $this->state_id = $state_id;
4319 $this->state_code = $state_code;
4320 $this->state = $state_label;
4321 if (is_object($langs)) {
4322 $this->state = ($langs->trans(
'State'.$state_code) !=
'State'.$state_code) ? $langs->trans(
'State'.$state_code) : $state_label;
4325 $this->phone = empty($conf->global->MAIN_INFO_SOCIETE_TEL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_TEL;
4326 $this->fax = empty($conf->global->MAIN_INFO_SOCIETE_FAX) ?
'' : $conf->global->MAIN_INFO_SOCIETE_FAX;
4327 $this->url = empty($conf->global->MAIN_INFO_SOCIETE_WEB) ?
'' : $conf->global->MAIN_INFO_SOCIETE_WEB;
4330 $this->facebook_url = empty($conf->global->MAIN_INFO_SOCIETE_FACEBOOK_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_FACEBOOK_URL;
4331 $this->twitter_url = empty($conf->global->MAIN_INFO_SOCIETE_TWITTER_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_TWITTER_URL;
4332 $this->linkedin_url = empty($conf->global->MAIN_INFO_SOCIETE_LINKEDIN_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LINKEDIN_URL;
4333 $this->instagram_url = empty($conf->global->MAIN_INFO_SOCIETE_INSTAGRAM_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_INSTAGRAM_URL;
4334 $this->youtube_url = empty($conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL;
4335 $this->github_url = empty($conf->global->MAIN_INFO_SOCIETE_GITHUB_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_GITHUB_URL;
4336 $this->socialnetworks = array();
4337 if (!empty($this->facebook_url)) {
4338 $this->socialnetworks[
'facebook'] = $this->facebook_url;
4340 if (!empty($this->twitter_url)) {
4341 $this->socialnetworks[
'twitter'] = $this->twitter_url;
4343 if (!empty($this->linkedin_url)) {
4344 $this->socialnetworks[
'linkedin'] = $this->linkedin_url;
4346 if (!empty($this->instagram_url)) {
4347 $this->socialnetworks[
'instagram'] = $this->instagram_url;
4349 if (!empty($this->youtube_url)) {
4350 $this->socialnetworks[
'youtube'] = $this->youtube_url;
4352 if (!empty($this->github_url)) {
4353 $this->socialnetworks[
'github'] = $this->github_url;
4357 $this->idprof1 = empty($conf->global->MAIN_INFO_SIREN) ?
'' : $conf->global->MAIN_INFO_SIREN;
4358 $this->idprof2 = empty($conf->global->MAIN_INFO_SIRET) ?
'' : $conf->global->MAIN_INFO_SIRET;
4359 $this->idprof3 = empty($conf->global->MAIN_INFO_APE) ?
'' : $conf->global->MAIN_INFO_APE;
4360 $this->idprof4 = empty($conf->global->MAIN_INFO_RCS) ?
'' : $conf->global->MAIN_INFO_RCS;
4361 $this->idprof5 = empty($conf->global->MAIN_INFO_PROFID5) ?
'' : $conf->global->MAIN_INFO_PROFID5;
4362 $this->idprof6 = empty($conf->global->MAIN_INFO_PROFID6) ?
'' : $conf->global->MAIN_INFO_PROFID6;
4363 $this->tva_intra = empty($conf->global->MAIN_INFO_TVAINTRA) ?
'' : $conf->global->MAIN_INFO_TVAINTRA;
4364 $this->managers = empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS) ?
'' : $conf->global->MAIN_INFO_SOCIETE_MANAGERS;
4365 $this->capital = empty($conf->global->MAIN_INFO_CAPITAL) ?
'' : $conf->global->MAIN_INFO_CAPITAL;
4366 $this->forme_juridique_code = empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE) ?
'' : $conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
4367 $this->email = empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_MAIL;
4368 $this->default_lang = (empty($conf->global->MAIN_LANG_DEFAULT) ?
'auto' : $conf->global->MAIN_LANG_DEFAULT);
4369 $this->logo = empty($conf->global->MAIN_INFO_SOCIETE_LOGO) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO;
4370 $this->logo_small = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
4371 $this->logo_mini = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
4372 $this->logo_squarred = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED;
4373 $this->logo_squarred_small = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL;
4374 $this->logo_squarred_mini = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI;
4377 $this->tva_assuj = $conf->global->FACTURE_TVAOPTION;
4380 $this->localtax1_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && ($conf->global->FACTURE_LOCAL_TAX1_OPTION ==
'1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION ==
'localtax1on')) ? 1 : 0);
4381 $this->localtax2_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && ($conf->global->FACTURE_LOCAL_TAX2_OPTION ==
'1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION ==
'localtax2on')) ? 1 : 0);
4398 $this->
name =
'THIRDPARTY SPECIMEN '.dol_print_date($now,
'dayhourlog');
4399 $this->nom = $this->name;
4400 $this->ref_ext =
'Ref ext';
4401 $this->specimen = 1;
4402 $this->address =
'21 jump street';
4403 $this->zip =
'99999';
4404 $this->town =
'MyTown';
4405 $this->state_id = 1;
4406 $this->state_code =
'AA';
4407 $this->state =
'MyState';
4408 $this->country_id = 1;
4409 $this->country_code =
'FR';
4410 $this->email =
'specimen@specimen.com';
4411 $this->socialnetworks = array(
4412 'skype' =>
'tom.hanson',
4413 'twitter' =>
'tomhanson',
4414 'facebook' =>
'tomhanson',
4415 'linkedin' =>
'tomhanson',
4417 $this->url =
'http://www.specimen.com';
4419 $this->phone =
'0909090901';
4420 $this->fax =
'0909090909';
4422 $this->code_client =
'CC-'.dol_print_date($now,
'dayhourlog');
4423 $this->code_fournisseur =
'SC-'.dol_print_date($now,
'dayhourlog');
4424 $this->capital = 10000;
4426 $this->prospect = 1;
4427 $this->fournisseur = 1;
4428 $this->tva_assuj = 1;
4429 $this->tva_intra =
'EU1234567';
4430 $this->note_public =
'This is a comment (public)';
4431 $this->note_private =
'This is a comment (private)';
4433 $this->idprof1 =
'idprof1';
4434 $this->idprof2 =
'idprof2';
4435 $this->idprof3 =
'idprof3';
4436 $this->idprof4 =
'idprof4';
4437 $this->idprof5 =
'idprof5';
4438 $this->idprof6 =
'idprof6';
4450 $sql =
"SELECT t.localtax1, t.localtax2";
4451 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4452 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4453 $sql .=
" AND t.active = 1";
4454 if (empty($localTaxNum)) {
4455 $sql .=
" AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
4456 } elseif ($localTaxNum == 1) {
4457 $sql .=
" AND t.localtax1_type <> '0'";
4458 } elseif ($localTaxNum == 2) {
4459 $sql .=
" AND t.localtax2_type <> '0'";
4464 return ($this->
db->num_rows(
$resql) > 0);
4477 $sql =
"SELECT t.rowid";
4478 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4479 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4480 $sql .=
" AND t.active = 1 AND t.recuperableonly = 1";
4485 return ($this->
db->num_rows(
$resql) > 0);
4499 $sql =
"SELECT COUNT(*) as nb";
4500 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_revenuestamp as r, ".MAIN_DB_PREFIX.
"c_country as c";
4501 $sql .=
" WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4502 $sql .=
" AND r.active = 1";
4507 $obj = $this->
db->fetch_object(
$resql);
4508 return (($obj->nb > 0) ?
true:
false);
4510 $this->error = $this->
db->lasterror();
4537 $lib = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
4539 if ($lib == $langs->trans(
"ProspectLevel".$fk_prospectlevel)) {
4540 $lib = $langs->getLabelFromKey($this->
db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
4554 return $this->
LibProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
4575 $langs->load(
'customers');
4578 if ($status ==
'-1' || $status ==
'ST_NO') {
4579 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
4580 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4581 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
4582 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4583 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
4584 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4585 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
4586 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4587 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
4589 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto).
' '.(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label);
4591 } elseif ($mode == 3) {
4592 if ($status ==
'-1' || $status ==
'ST_NO') {
4593 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto);
4594 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4595 return img_action($langs->trans(
"StatusProspect0"), 0, $picto);
4596 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4597 return img_action($langs->trans(
"StatusProspect1"), 1, $picto);
4598 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4599 return img_action($langs->trans(
"StatusProspect2"), 2, $picto);
4600 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4601 return img_action($langs->trans(
"StatusProspect3"), 3, $picto);
4603 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto);
4605 } elseif ($mode == 4) {
4606 if ($status ==
'-1' || $status ==
'ST_NO') {
4607 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
4608 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4609 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
4610 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4611 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
4612 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4613 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
4614 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4615 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
4617 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto).
' '.(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label);
4621 return "Error, mode/status not found";
4633 if ($mode ==
'supplier') {
4634 $table =
'supplier_proposal';
4637 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4638 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4639 if ($mode ==
'supplier') {
4640 $sql .=
" AND entity IN (".getEntity(
'supplier_proposal').
")";
4642 $sql .=
" AND entity IN (".getEntity(
'propal').
")";
4645 dol_syslog(
"getOutstandingProposals for fk_soc = ".((
int) $this->
id), LOG_DEBUG);
4649 $outstandingOpened = 0;
4650 $outstandingTotal = 0;
4651 $outstandingTotalIncTax = 0;
4652 $arrayofref = array();
4653 while ($obj = $this->
db->fetch_object(
$resql)) {
4654 $arrayofref[$obj->rowid] = $obj->ref;
4655 $outstandingTotal += $obj->total_ht;
4656 $outstandingTotalIncTax += $obj->total_ttc;
4657 if ($obj->status != 0) {
4659 $outstandingOpened += $obj->total_ttc;
4662 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref);
4676 $table =
'commande';
4677 if ($mode ==
'supplier') {
4678 $table =
'commande_fournisseur';
4681 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4682 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4683 if ($mode ==
'supplier') {
4684 $sql .=
" AND entity IN (".getEntity(
'supplier_order').
")";
4686 $sql .=
" AND entity IN (".getEntity(
'commande').
")";
4689 dol_syslog(
"getOutstandingOrders", LOG_DEBUG);
4692 $outstandingOpened = 0;
4693 $outstandingTotal = 0;
4694 $outstandingTotalIncTax = 0;
4695 $arrayofref = array();
4696 while ($obj = $this->
db->fetch_object(
$resql)) {
4697 $arrayofref[$obj->rowid] = $obj->ref;
4698 $outstandingTotal += $obj->total_ht;
4699 $outstandingTotalIncTax += $obj->total_ttc;
4700 if ($obj->status != 0) {
4702 $outstandingOpened += $obj->total_ttc;
4705 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref);
4721 if ($mode ==
'supplier') {
4722 $table =
'facture_fourn';
4732 $sql =
"SELECT rowid, ref, total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table.
" as f";
4733 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4734 if (!empty($late)) {
4735 $sql .=
" AND date_lim_reglement < '".$this->db->idate(
dol_now()).
"'";
4737 if ($mode ==
'supplier') {
4738 $sql .=
" AND entity IN (".getEntity(
'facture_fourn').
")";
4740 $sql .=
" AND entity IN (".getEntity(
'invoice').
")";
4743 dol_syslog(
"getOutstandingBills", LOG_DEBUG);
4746 $outstandingOpened = 0;
4747 $outstandingTotal = 0;
4748 $outstandingTotalIncTax = 0;
4749 $arrayofref = array();
4750 $arrayofrefopened = array();
4751 if ($mode ==
'supplier') {
4752 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
4755 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
4758 while ($obj = $this->
db->fetch_object(
$resql)) {
4759 $arrayofref[$obj->rowid] = $obj->ref;
4760 $tmpobject->id = $obj->rowid;
4762 if ($obj->status != $tmpobject::STATUS_DRAFT
4763 && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code ==
'replaced')
4765 $outstandingTotal += $obj->total_ht;
4766 $outstandingTotalIncTax += $obj->total_ttc;
4772 && $obj->status != $tmpobject::STATUS_DRAFT
4773 && $obj->status != $tmpobject::STATUS_ABANDONED
4774 && $obj->status != $tmpobject::STATUS_CLOSED) {
4776 $paiement = $tmpobject->getSommePaiement();
4777 $creditnotes = $tmpobject->getSumCreditNotesUsed();
4778 $deposits = $tmpobject->getSumDepositsUsed();
4780 $remaintopay = ($obj->total_ttc - $paiement - $creditnotes - $deposits);
4781 $outstandingOpened += $remaintopay;
4787 $remainingcreditnote = $tmpobject->getSumFromThisCreditNotesNotUsed();
4788 $remaintopay -= $remainingcreditnote;
4789 $outstandingOpened -= $remainingcreditnote;
4793 $arrayofrefopened[$obj->rowid] = $obj->ref;
4796 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref,
'refsopened'=>$arrayofrefopened);
4798 dol_syslog(
"Sql error ".$this->
db->lasterror, LOG_ERR);
4825 $langs->load(
'companies');
4828 return $langs->trans(
"NorProspectNorCustomer");
4829 } elseif ($status == 1) {
4830 return $langs->trans(
"Customer");
4831 } elseif ($status == 2) {
4832 return $langs->trans(
"Prospect");
4833 } elseif ($status == 3) {
4834 return $langs->trans(
"ProspectCustomer");
4850 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4852 global $conf, $user, $langs;
4854 if (!empty($moreparams) && !empty($moreparams[
'use_companybankid'])) {
4855 $modelpath =
"core/modules/bank/doc/";
4857 include_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
4859 $result = $companybankaccount->fetch($moreparams[
'use_companybankid']);
4861 dol_print_error($this->
db, $companybankaccount->error, $companybankaccount->errors);
4863 $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4867 if (!empty($conf->global->COMPANY_ADDON_PDF)) {
4868 $modele = $conf->global->COMPANY_ADDON_PDF;
4870 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_COMPANY_ADDON_PDF_NotDefined");
4875 if (!isset($this->bank_account)) {
4876 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
4878 $result = $bac->fetch(0, $this->
id);
4880 $this->bank_account = $bac;
4882 $this->bank_account =
'';
4886 $modelpath =
"core/modules/societe/doc/";
4888 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4908 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4911 if (!in_array($type_categ, array(Categorie::TYPE_CUSTOMER, Categorie::TYPE_SUPPLIER))) {
4912 dol_syslog(__METHOD__.
': Type '.$type_categ.
'is an unknown company category type. Done nothing.', LOG_ERR);
4916 return parent::setCategoriesCommon($categories, $type_categ);
4931 if (!is_array($salesrep)) {
4932 $salesrep = array($salesrep);
4936 $to_add = $salesrep;
4937 if ($onlyAdd ===
false) {
4942 if (is_array($existing)) {
4943 $to_del = array_diff($existing, $salesrep);
4944 $to_add = array_diff($salesrep, $existing);
4951 foreach ($to_del as $del) {
4954 foreach ($to_add as $add) {
4962 return $error ? -1 : 1;
4978 $result = $this->
setValueFrom(
'fk_typent', $typent_id,
'',
null,
'',
'', $user,
'COMPANY_MODIFY');
4981 $this->typent_id = $typent_id;
4982 $this->typent_code =
dol_getIdFromCode($this->
db, $this->typent_id,
'c_typent',
'id',
'code');
5003 if ($origin_id == $dest_id) {
5004 dol_syslog(
'Error: Try to merge a thirdparty into itself');
5012 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5013 $sql .=
' WHERE fk_soc = '.(int) $dest_id.
' AND fk_user IN ( ';
5014 $sql .=
' SELECT fk_user ';
5015 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5016 $sql .=
' WHERE fk_soc = '.(int) $origin_id.
') ';
5020 $dbs->
query(
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_commerciaux WHERE rowid = '.((
int) $obj->rowid));
5029 'societe_commerciaux',
5032 'societe_remise_except',
5049 global $user, $langs, $conf;
5053 $field =
'accountancy_code_sell';
5054 if ($type ==
'buy') {
5055 $field =
'accountancy_code_buy';
5056 } elseif ($type ==
'sell') {
5057 $field =
'accountancy_code_sell';
5062 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ";
5063 $sql .= $field.
" = '".$this->
db->escape($value).
"'";
5064 $sql .=
" WHERE rowid = ".((int) $this->
id);
5066 dol_syslog(get_class($this).
"::".__FUNCTION__.
"", LOG_DEBUG);
5071 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
5073 $result = $interface->run_triggers(
'COMPANY_MODIFY', $this, $user, $langs, $conf);
5075 $this->errors = $interface->errors;
5076 $this->
db->rollback();
5081 $this->$field = $value;
5083 $this->
db->commit();
5086 $this->error = $this->
db->lasterror();
5087 $this->
db->rollback();
5102 require_once DOL_DOCUMENT_ROOT.
'/partnership/class/partnership.class.php';
5105 $this->partnerships[] = array();
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,...
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
isObjectUsed($id=0, $entity=0)
Function to check if an object is used by others.
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraLanguages($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif')
Setter generic.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
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...)
getParentsForCompany($company_id, $parents=[])
Get parents for company.
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.
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...
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.
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 ...
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.
thirdparty_and_contact_phone_array()
Return list of contacts mobile phone existing for third party.
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.
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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
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_is_dir($folder)
Test if filename is a directory.
clean_url($url, $http=1)
Clean an url string.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
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.
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.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='')
Clean a string from all punctuation characters to use it as a ref or login.
img_action($titlealt, $numaction, $picto='')
Show logo action.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_substr($string, $start, $length, $stringencoding='', $trunconbytes=0)
Make a substring.
setEventMessage($mesgs, $style='mesgs')
Set event message 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.
isModEnabled($module)
Is Dolibarr module enabled.
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.
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.
$conf db
API class for accounts.