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)) {
1013 if ($ret >= 0 && !$notrigger) {
1015 $result = $this->
call_trigger(
'COMPANY_CREATE', $user);
1025 dol_syslog(get_class($this).
"::Create success id=".$this->
id);
1026 $this->
db->commit();
1029 dol_syslog(get_class($this).
"::Create echec update ".$this->error.(empty($this->errors) ?
'' :
' '.join(
',', $this->errors)), LOG_ERR);
1030 $this->
db->rollback();
1034 if ($this->
db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1035 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", $this->name);
1038 $this->error = $this->
db->lasterror();
1041 $this->
db->rollback();
1045 $this->
db->rollback();
1046 dol_syslog(get_class($this).
"::Create fails verify ".join(
',', $this->errors), LOG_WARNING);
1071 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1074 $contact->name = $this->name_bis;
1075 $contact->firstname = $this->firstname;
1076 $contact->civility_id = $this->civility_id;
1077 $contact->socid = $this->id;
1078 $contact->statut = 1;
1079 $contact->status = 1;
1081 $contact->country_id = $this->country_id;
1082 $contact->state_id = $this->state_id;
1083 $contact->address = $this->address;
1084 $contact->email = $this->email;
1085 $contact->zip = $this->zip;
1086 $contact->town = $this->town;
1088 $contact->phone_pro = $this->phone;
1090 $contactId = $contact->create($user, $notrigger);
1091 if ($contactId < 0) {
1093 $this->error = $contact->error;
1094 $this->errors = $contact->errors;
1095 dol_syslog(get_class($this).
"::create_individual ERROR:".$this->error, LOG_ERR);
1098 if (empty($error) && is_array($tags) && !empty($tags)) {
1099 $result = $contact->setCategories($tags);
1102 $this->error = $contact->error;
1103 $this->errors = array_merge($this->errors, $contact->errors);
1104 dol_syslog(get_class($this).
"::create_individual Affect Tag ERROR:".$this->error, LOG_ERR);
1105 $contactId = $result;
1109 if (empty($error) &&
isModEnabled(
'mailing') && !empty($contact->email) && isset($no_email)) {
1110 $result = $contact->setNoEmail($no_email);
1112 $this->error = $contact->error;
1113 $this->errors = array_merge($this->errors, $contact->errors);
1114 dol_syslog(get_class($this).
"::create_individual set mailing status ERROR:".$this->error, LOG_ERR);
1115 $contactId = $result;
1119 if (empty($error)) {
1120 dol_syslog(get_class($this).
"::create_individual success");
1121 $this->
db->commit();
1123 $this->
db->rollback();
1137 global $conf, $langs, $mysoc;
1140 $this->errors = array();
1144 $this->nom = $this->name;
1147 $this->errors[] =
'ErrorBadThirdPartyName';
1151 if ($this->client) {
1153 if ($rescode != 0 && $rescode != -5) {
1154 if ($rescode == -1) {
1155 $this->errors[] =
'ErrorBadCustomerCodeSyntax';
1156 } elseif ($rescode == -2) {
1157 $this->errors[] =
'ErrorCustomerCodeRequired';
1158 } elseif ($rescode == -3) {
1159 $this->errors[] =
'ErrorCustomerCodeAlreadyUsed';
1160 } elseif ($rescode == -4) {
1161 $this->errors[] =
'ErrorPrefixRequired';
1163 $this->errors[] =
'ErrorUnknownOnCustomerCodeCheck';
1170 if ($this->fournisseur) {
1172 if ($rescode != 0 && $rescode != -5) {
1173 if ($rescode == -1) {
1174 $this->errors[] =
'ErrorBadSupplierCodeSyntax';
1175 } elseif ($rescode == -2) {
1176 $this->errors[] =
'ErrorSupplierCodeRequired';
1177 } elseif ($rescode == -3) {
1178 $this->errors[] =
'ErrorSupplierCodeAlreadyUsed';
1179 } elseif ($rescode == -4) {
1180 $this->errors[] =
'ErrorPrefixRequired';
1182 $this->errors[] =
'ErrorUnknownOnSupplierCodeCheck';
1189 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL',
'TVA_INTRA');
1190 foreach ($array_to_check as $key) {
1191 $keymin = strtolower($key);
1192 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
1193 $vallabel = $this->$keymin;
1198 if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) {
1199 $idprof_mandatory =
'SOCIETE_'.$key.
'_MANDATORY';
1200 if (!$vallabel && !empty($conf->global->$idprof_mandatory)) {
1201 $langs->load(
"errors");
1203 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->transcountry(
'ProfId'.$i, $this->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1210 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1211 $langs->load(
"errors");
1213 $this->errors[] = $langs->transcountry(
'ProfId'.$i, $this->country_code).
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1219 if ($key ==
'EMAIL') {
1221 if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email)) {
1222 $langs->load(
"errors");
1224 $this->errors[] = $langs->trans(
"ErrorBadEMail", $this->email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1228 if (!$error && $vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE)) {
1229 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1230 $langs->load(
"errors");
1231 $error++; $this->errors[] = $langs->trans(
'Email').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1234 } elseif ($key ==
'TVA_INTRA') {
1236 if ($vallabel && !empty($conf->global->SOCIETE_VAT_INTRA_UNIQUE)) {
1237 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1238 $langs->load(
"errors");
1239 $error++; $this->errors[] = $langs->trans(
'VATIntra').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1265 public function update($id, $user =
'', $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action =
'update', $nosyncmember = 1)
1267 global $langs, $conf, $hookmanager;
1269 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1277 dol_syslog(get_class($this).
"::Update id=".$id.
" call_trigger=".$call_trigger.
" allowmodcodeclient=".$allowmodcodeclient.
" allowmodcodefournisseur=".$allowmodcodefournisseur);
1283 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
1284 $this->
name = $this->
name ?trim($this->
name) : trim($this->nom);
1285 $this->nom = $this->name;
1286 $this->name_alias = trim($this->name_alias);
1287 $this->ref_ext = trim($this->ref_ext);
1288 $this->address = $this->address ?trim($this->address) : trim($this->address);
1289 $this->zip = $this->zip ?trim($this->zip) : trim($this->zip);
1290 $this->town = $this->town ?trim($this->town) : trim($this->town);
1291 $this->state_id = trim($this->state_id);
1292 $this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
1293 $this->phone = trim($this->phone);
1294 $this->phone = preg_replace(
"/\s/",
"", $this->phone);
1295 $this->phone = preg_replace(
"/\./",
"", $this->phone);
1296 $this->fax = trim($this->fax);
1297 $this->fax = preg_replace(
"/\s/",
"", $this->fax);
1298 $this->fax = preg_replace(
"/\./",
"", $this->fax);
1299 $this->email = trim($this->email);
1300 $this->url = $this->url ?
clean_url($this->url, 0) :
'';
1301 $this->note_private = trim($this->note_private);
1302 $this->note_public = trim($this->note_public);
1303 $this->idprof1 = trim($this->idprof1);
1304 $this->idprof2 = trim($this->idprof2);
1305 $this->idprof3 = trim($this->idprof3);
1306 $this->idprof4 = trim($this->idprof4);
1307 $this->idprof5 = (!empty($this->idprof5) ?trim($this->idprof5) :
'');
1308 $this->idprof6 = (!empty($this->idprof6) ?trim($this->idprof6) :
'');
1309 $this->prefix_comm = trim($this->prefix_comm);
1310 $this->outstanding_limit =
price2num($this->outstanding_limit);
1311 $this->order_min_amount =
price2num($this->order_min_amount);
1312 $this->supplier_order_min_amount =
price2num($this->supplier_order_min_amount);
1314 $this->tva_assuj = trim($this->tva_assuj);
1316 if (empty($this->status)) {
1320 if (!empty($this->multicurrency_code)) {
1323 if (empty($this->fk_multicurrency)) {
1324 $this->multicurrency_code =
'';
1325 $this->fk_multicurrency = 0;
1329 $this->localtax1_assuj = trim($this->localtax1_assuj);
1330 $this->localtax2_assuj = trim($this->localtax2_assuj);
1332 $this->localtax1_value = trim($this->localtax1_value);
1333 $this->localtax2_value = trim($this->localtax2_value);
1335 if ($this->capital !=
'') {
1336 $this->capital =
price2num(trim($this->capital));
1338 if (!is_numeric($this->capital)) {
1339 $this->capital =
'';
1342 $this->effectif_id = trim($this->effectif_id);
1343 $this->forme_juridique_code = trim($this->forme_juridique_code);
1346 $this->barcode = trim($this->barcode);
1349 if ($this->code_client == -1 || $this->code_client ===
'auto') {
1352 if ($this->code_fournisseur == -1 || $this->code_fournisseur ===
'auto') {
1356 $this->code_compta_client = trim(empty($this->code_compta) ? $this->code_compta_client : $this->code_compta);
1357 $this->code_compta = $this->code_compta_client;
1358 $this->code_compta_fournisseur = trim($this->code_compta_fournisseur);
1361 if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) {
1362 $langs->load(
"errors");
1363 $this->error = $langs->trans(
"BadValueForParameterClientOrSupplier");
1368 if (!empty($allowmodcodeclient) && !empty($this->client)) {
1370 if (empty($this->code_compta_client)) {
1381 if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) {
1383 if (empty($this->code_compta_fournisseur)) {
1394 $this->webservices_url = $this->webservices_url ?
clean_url($this->webservices_url, 0) :
'';
1395 $this->webservices_key = trim($this->webservices_key);
1397 $this->accountancy_code_buy = trim($this->accountancy_code_buy);
1398 $this->accountancy_code_sell = trim($this->accountancy_code_sell);
1401 $this->fk_incoterms = (int) $this->fk_incoterms;
1402 $this->location_incoterms = trim($this->location_incoterms);
1409 if ($action !=
'add' && $action !=
'merge') {
1412 $result = $this->
verify();
1416 if (is_array($this->errors)) {
1417 if (in_array(
'ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) {
1418 if (($key = array_search(
'ErrorBadCustomerCodeSyntax', $this->errors)) !==
false) {
1419 unset($this->errors[$key]);
1422 if (in_array(
'ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) {
1423 if (($key = array_search(
'ErrorBadSupplierCodeSyntax', $this->errors)) !==
false) {
1424 unset($this->errors[$key]);
1427 if (empty($this->errors)) {
1434 dol_syslog(get_class($this).
"::update verify ok or not done");
1436 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe SET ";
1437 $sql .=
"entity = ".$this->db->escape($this->entity);
1438 $sql .=
",nom = '".$this->db->escape($this->
name).
"'";
1439 $sql .=
",name_alias = '".$this->db->escape($this->name_alias).
"'";
1440 $sql .=
",ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1441 $sql .=
",address = '".$this->db->escape($this->address).
"'";
1443 $sql .=
",zip = ".(!empty($this->zip) ?
"'".$this->db->escape($this->zip).
"'" :
"null");
1444 $sql .=
",town = ".(!empty($this->town) ?
"'".$this->db->escape($this->town).
"'" :
"null");
1446 $sql .=
",fk_departement = ".((!empty($this->state_id) && $this->state_id > 0) ? ((
int) $this->state_id) :
'null');
1447 $sql .=
",fk_pays = ".((!empty($this->country_id) && $this->country_id > 0) ? ((
int) $this->country_id) :
'null');
1449 $sql .=
",phone = ".(!empty($this->phone) ?
"'".$this->db->escape($this->phone).
"'" :
"null");
1450 $sql .=
",fax = ".(!empty($this->fax) ?
"'".$this->db->escape($this->fax).
"'" :
"null");
1451 $sql .=
",email = ".(!empty($this->email) ?
"'".$this->db->escape($this->email).
"'" :
"null");
1452 $sql .=
",socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1453 $sql .=
",url = ".(!empty($this->url) ?
"'".$this->db->escape($this->url).
"'" :
"null");
1455 $sql .=
",parent = ".($this->parent > 0 ? $this->parent :
"null");
1457 $sql .=
",note_private = ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
1458 $sql .=
",note_public = ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
1460 $sql .=
",siren = '".$this->db->escape($this->idprof1).
"'";
1461 $sql .=
",siret = '".$this->db->escape($this->idprof2).
"'";
1462 $sql .=
",ape = '".$this->db->escape($this->idprof3).
"'";
1463 $sql .=
",idprof4 = '".$this->db->escape($this->idprof4).
"'";
1464 $sql .=
",idprof5 = '".$this->db->escape($this->idprof5).
"'";
1465 $sql .=
",idprof6 = '".$this->db->escape($this->idprof6).
"'";
1467 $sql .=
",tva_assuj = ".($this->tva_assuj !=
'' ?
"'".$this->db->escape($this->tva_assuj).
"'" :
"null");
1468 $sql .=
",tva_intra = '".$this->db->escape($this->tva_intra).
"'";
1469 $sql .=
",status = ".((int) $this->status);
1472 $sql .=
",localtax1_assuj = ".($this->localtax1_assuj !=
'' ?
"'".$this->db->escape($this->localtax1_assuj).
"'" :
"null");
1473 $sql .=
",localtax2_assuj = ".($this->localtax2_assuj !=
'' ?
"'".$this->db->escape($this->localtax2_assuj).
"'" :
"null");
1474 if ($this->localtax1_assuj == 1) {
1475 if ($this->localtax1_value !=
'') {
1476 $sql .=
",localtax1_value =".$this->localtax1_value;
1478 $sql .=
",localtax1_value =0.000";
1481 $sql .=
",localtax1_value =0.000";
1484 if ($this->localtax2_assuj == 1) {
1485 if ($this->localtax2_value !=
'') {
1486 $sql .=
",localtax2_value =".$this->localtax2_value;
1488 $sql .=
",localtax2_value =0.000";
1491 $sql .=
",localtax2_value =0.000";
1494 $sql .=
",capital = ".($this->capital ==
'' ?
"null" : $this->capital);
1496 $sql .=
",prefix_comm = ".(!empty($this->prefix_comm) ?
"'".$this->db->escape($this->prefix_comm).
"'" :
"null");
1498 $sql .=
",fk_effectif = ".($this->effectif_id > 0 ? ((int) $this->effectif_id) :
"null");
1499 if (isset($this->stcomm_id)) {
1500 $sql .=
",fk_stcomm=".(int) $this->stcomm_id;
1502 if (isset($this->typent_id)) {
1503 $sql .=
",fk_typent = ".($this->typent_id > 0 ? ((int) $this->typent_id) :
"0");
1506 $sql .=
",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ?
"'".$this->db->escape($this->forme_juridique_code).
"'" :
"null");
1508 $sql .=
",mode_reglement = ".(!empty($this->mode_reglement_id) ?
"'".$this->db->escape($this->mode_reglement_id).
"'" :
"null");
1509 $sql .=
",cond_reglement = ".(!empty($this->cond_reglement_id) ?
"'".$this->db->escape($this->cond_reglement_id).
"'" :
"null");
1510 $sql .=
",deposit_percent = ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null");
1511 $sql .=
",transport_mode = ".(!empty($this->transport_mode_id) ?
"'".$this->db->escape($this->transport_mode_id).
"'" :
"null");
1512 $sql .=
",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ?
"'".$this->db->escape($this->mode_reglement_supplier_id).
"'" :
"null");
1513 $sql .=
",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ?
"'".$this->db->escape($this->cond_reglement_supplier_id).
"'" :
"null");
1514 $sql .=
",transport_mode_supplier = ".(!empty($this->transport_mode_supplier_id) ?
"'".$this->db->escape($this->transport_mode_supplier_id).
"'" :
"null");
1515 $sql .=
",fk_shipping_method = ".(!empty($this->shipping_method_id) ?
"'".$this->db->escape($this->shipping_method_id).
"'" :
"null");
1517 $sql .=
",client = ".(!empty($this->client) ? $this->client : 0);
1518 $sql .=
",fournisseur = ".(!empty($this->fournisseur) ? $this->fournisseur : 0);
1519 $sql .=
",barcode = ".(!empty($this->barcode) ?
"'".$this->db->escape($this->barcode).
"'" :
"null");
1520 $sql .=
",default_lang = ".(!empty($this->default_lang) ?
"'".$this->db->escape($this->default_lang).
"'" :
"null");
1521 $sql .=
",logo = ".(!empty($this->logo) ?
"'".$this->db->escape($this->logo).
"'" :
"null");
1522 $sql .=
",logo_squarred = ".(!empty($this->logo_squarred) ?
"'".$this->db->escape($this->logo_squarred).
"'" :
"null");
1523 $sql .=
",outstanding_limit= ".($this->outstanding_limit !=
'' ? $this->outstanding_limit :
'null');
1524 $sql .=
",order_min_amount= ".($this->order_min_amount !=
'' ? $this->order_min_amount :
'null');
1525 $sql .=
",supplier_order_min_amount= ".($this->supplier_order_min_amount !=
'' ? $this->supplier_order_min_amount :
'null');
1526 $sql .=
",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel).
"'";
1527 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1528 $sql .=
", accountancy_code_buy = '".$this->db->escape($this->accountancy_code_buy).
"'";
1529 $sql .=
", accountancy_code_sell= '".$this->db->escape($this->accountancy_code_sell).
"'";
1532 $sql .=
", code_compta = ".(!empty($this->code_compta_client) ?
"'".$this->db->escape($this->code_compta_client).
"'" :
"null");
1536 $sql .=
", code_compta_fournisseur = ".(($this->code_compta_fournisseur !=
"") ?
"'".$this->
db->escape($this->code_compta_fournisseur).
"'" :
"null");
1539 $sql .=
",webservices_url = ".(!empty($this->webservices_url) ?
"'".$this->db->escape($this->webservices_url).
"'" :
"null");
1540 $sql .=
",webservices_key = ".(!empty($this->webservices_key) ?
"'".$this->db->escape($this->webservices_key).
"'" :
"null");
1543 $sql .=
", fk_incoterms = ".((int) $this->fk_incoterms);
1544 $sql .=
", location_incoterms = ".(!empty($this->location_incoterms) ?
"'".$this->db->escape($this->location_incoterms).
"'" :
"null");
1547 $sql .=
", code_client = ".(!empty($this->code_client) ?
"'".$this->db->escape($this->code_client).
"'" :
"null");
1551 $sql .=
", code_fournisseur = ".(!empty($this->code_fournisseur) ?
"'".$this->db->escape($this->code_fournisseur).
"'" :
"null");
1553 $sql .=
", fk_user_modif = ".($user->id > 0 ? $user->id :
"null");
1554 $sql .=
", fk_multicurrency = ".(int) $this->fk_multicurrency;
1555 $sql .=
", multicurrency_code = '".$this->db->escape($this->multicurrency_code).
"'";
1556 $sql .=
", model_pdf = '".$this->db->escape($this->model_pdf).
"'";
1557 $sql .=
" WHERE rowid = ".(int) $id;
1561 if (is_object($this->oldcopy)) {
1562 if ($this->oldcopy->country_id != $this->country_id) {
1563 unset($this->country_code);
1564 unset($this->country);
1566 if ($this->oldcopy->state_id != $this->state_id) {
1567 unset($this->state_code);
1568 unset($this->state);
1571 unset($this->country_code);
1572 unset($this->country);
1573 unset($this->state_code);
1574 unset($this->state);
1577 $nbrowsaffected = $this->
db->affected_rows(
$resql);
1579 if (!$error && $nbrowsaffected) {
1582 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1584 dol_syslog(get_class($this).
"::update update linked member");
1587 $result = $lmember->fetch(0, 0, $this->
id);
1590 $lmember->company = $this->name;
1593 $lmember->address = $this->address;
1594 $lmember->zip = $this->zip;
1595 $lmember->town = $this->town;
1596 $lmember->email = $this->email;
1597 $lmember->socialnetworks = $this->socialnetworks;
1598 $lmember->phone = $this->phone;
1599 $lmember->state_id = $this->state_id;
1600 $lmember->country_id = $this->country_id;
1601 $lmember->default_lang = $this->default_lang;
1603 $result = $lmember->update($user, 0, 1, 1, 1);
1605 $this->error = $lmember->error;
1606 $this->errors = array_merge($this->errors, $lmember->errors);
1607 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
1610 } elseif ($result < 0) {
1611 $this->error = $lmember->error;
1620 if (!$error && !empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1621 $this->
db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int) $conf->entity));
1623 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
1626 $sql .=
", accountancy_code_customer";
1627 $sql .=
", accountancy_code_supplier";
1628 $sql .=
", accountancy_code_buy";
1629 $sql .=
", accountancy_code_sell";
1630 $sql .=
") VALUES (";
1632 $sql .=
", ".$conf->entity;
1633 $sql .=
", '".$this->db->escape($this->code_compta_client).
"'";
1634 $sql .=
", '".$this->db->escape($this->code_compta_fournisseur).
"'";
1635 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1636 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1638 $result = $this->
db->query($sql);
1641 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1653 if (!$error && empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) {
1660 if (!$error && $call_trigger) {
1662 $result = $this->
call_trigger(
'COMPANY_MODIFY', $user);
1670 dol_syslog(get_class($this).
"::Update success");
1671 $this->
db->commit();
1674 $this->
db->rollback();
1678 if ($this->
db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1680 $this->error = $langs->trans(
"ErrorDuplicateField");
1683 $this->error = $this->
db->lasterror();
1686 $this->
db->rollback();
1690 $this->
db->rollback();
1691 dol_syslog(get_class($this).
"::Update fails verify ".join(
',', $this->errors), LOG_WARNING);
1713 public function fetch($rowid, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'')
1718 if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) {
1722 $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';
1723 $sql .=
', s.status, s.fk_warehouse';
1724 $sql .=
', s.price_level';
1725 $sql .=
', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif';
1726 $sql .=
', s.phone, s.fax, s.email';
1727 $sql .=
', s.socialnetworks';
1728 $sql .=
', s.url, s.zip, s.town, s.note_private, s.note_public, s.client, s.fournisseur';
1729 $sql .=
', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1730 $sql .=
', s.capital, s.tva_intra';
1731 $sql .=
', s.fk_typent as typent_id';
1732 $sql .=
', s.fk_effectif as effectif_id';
1733 $sql .=
', s.fk_forme_juridique as forme_juridique_code';
1734 $sql .=
', s.webservices_url, s.webservices_key, s.model_pdf, s.last_main_doc';
1735 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1736 $sql .=
', s.code_compta, s.code_compta_fournisseur, s.accountancy_code_buy, s.accountancy_code_sell';
1738 $sql .=
', spe.accountancy_code_customer as code_compta, spe.accountancy_code_supplier as code_compta_fournisseur, spe.accountancy_code_buy, spe.accountancy_code_sell';
1740 $sql .=
', s.code_client, s.code_fournisseur, s.parent, s.barcode';
1741 $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';
1742 $sql .=
', s.fk_account, s.tva_assuj';
1743 $sql .=
', s.mode_reglement_supplier, s.cond_reglement_supplier, s.transport_mode_supplier';
1744 $sql .=
', s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred';
1745 $sql .=
', s.fk_shipping_method';
1746 $sql .=
', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1747 $sql .=
', s.order_min_amount, s.supplier_order_min_amount';
1748 $sql .=
', s.fk_multicurrency, s.multicurrency_code';
1749 $sql .=
', fj.libelle as forme_juridique';
1750 $sql .=
', e.libelle as effectif';
1751 $sql .=
', c.code as country_code, c.label as country';
1752 $sql .=
', d.code_departement as state_code, d.nom as state';
1753 $sql .=
', r.rowid as region_id, r.code_region as region_code';
1754 $sql .=
', st.libelle as stcomm, st.picto as stcomm_picto';
1755 $sql .=
', te.code as typent_code';
1756 $sql .=
', i.libelle as label_incoterms';
1758 $sql .=
', s.remise_client, s.remise_supplier';
1760 $sql .=
', sr.remise_client, sr2.remise_supplier';
1762 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
1763 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1764 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = ".((int) $conf->entity);
1766 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_effectif as e ON s.fk_effectif = e.id';
1767 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON s.fk_pays = c.rowid';
1768 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcomm as st ON s.fk_stcomm = st.id';
1769 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
1770 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON s.fk_departement = d.rowid';
1771 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_regions as r ON d.fk_region = r.code_region ';
1772 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_typent as te ON s.fk_typent = te.id';
1773 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON s.fk_incoterms = i.rowid';
1777 $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').
'))';
1778 $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').
'))';
1780 $sql .=
' WHERE s.entity IN ('.getEntity($this->element).
')';
1782 $sql .=
' AND s.rowid = '.((int) $rowid);
1785 $sql .=
" AND s.nom = '".$this->db->escape($ref).
"'";
1788 $sql .=
" AND s.name_alias = '".$this->db->escape($ref_alias).
"'";
1791 $sql .=
" AND s.ref_ext = '".$this->db->escape($ref_ext).
"'";
1794 $sql .=
" AND s.barcode = '".$this->db->escape($barcode).
"'";
1797 $sql .=
" AND s.siren = '".$this->db->escape($idprof1).
"'";
1800 $sql .=
" AND s.siret = '".$this->db->escape($idprof2).
"'";
1803 $sql .=
" AND s.ape = '".$this->db->escape($idprof3).
"'";
1806 $sql .=
" AND s.idprof4 = '".$this->db->escape($idprof4).
"'";
1809 $sql .=
" AND s.idprof5 = '".$this->db->escape($idprof5).
"'";
1812 $sql .=
" AND s.idprof6 = '".$this->db->escape($idprof6).
"'";
1815 $sql .=
" AND s.email = '".$this->db->escape($email).
"'";
1820 $num = $this->
db->num_rows(
$resql);
1822 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
1826 $obj = $this->
db->fetch_object(
$resql);
1828 $this->
id = $obj->rowid;
1829 $this->entity = $obj->entity;
1830 $this->canvas = $obj->canvas;
1832 $this->
ref = $obj->rowid;
1833 $this->
name = $obj->name;
1834 $this->nom = $obj->name;
1835 $this->name_alias = $obj->name_alias;
1836 $this->ref_ext = $obj->ref_ext;
1838 $this->date_creation = $this->
db->jdate($obj->date_creation);
1839 $this->date_modification = $this->
db->jdate($obj->date_modification);
1840 $this->user_creation = $obj->fk_user_creat;
1841 $this->user_modification = $obj->fk_user_modif;
1843 $this->address = $obj->address;
1844 $this->zip = $obj->zip;
1845 $this->town = $obj->town;
1847 $this->country_id = $obj->country_id;
1848 $this->country_code = $obj->country_id ? $obj->country_code :
'';
1849 $this->country = $obj->country_id ? (($langs->transnoentities(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code) ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
1851 $this->state_id = $obj->state_id;
1852 $this->state_code = $obj->state_code;
1853 $this->region_id = $obj->region_id;
1854 $this->region_code = $obj->region_code;
1855 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
1857 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcomm);
1858 $label = ($transcode !=
'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm);
1859 $this->stcomm_id = $obj->fk_stcomm;
1860 $this->status_prospect_label = $label;
1861 $this->stcomm_picto = $obj->stcomm_picto;
1863 $this->email = $obj->email;
1864 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
1866 $this->url = $obj->url;
1867 $this->phone = $obj->phone;
1868 $this->fax = $obj->fax;
1870 $this->parent = $obj->parent;
1872 $this->idprof1 = $obj->idprof1;
1873 $this->idprof2 = $obj->idprof2;
1874 $this->idprof3 = $obj->idprof3;
1875 $this->idprof4 = $obj->idprof4;
1876 $this->idprof5 = $obj->idprof5;
1877 $this->idprof6 = $obj->idprof6;
1879 $this->capital = $obj->capital;
1881 $this->code_client = $obj->code_client;
1882 $this->code_fournisseur = $obj->code_fournisseur;
1884 $this->code_compta = $obj->code_compta;
1885 $this->code_compta_client = $obj->code_compta;
1886 $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
1888 $this->barcode = $obj->barcode;
1890 $this->tva_assuj = $obj->tva_assuj;
1891 $this->tva_intra = $obj->tva_intra;
1892 $this->status = $obj->status;
1895 $this->localtax1_assuj = $obj->localtax1_assuj;
1896 $this->localtax2_assuj = $obj->localtax2_assuj;
1898 $this->localtax1_value = $obj->localtax1_value;
1899 $this->localtax2_value = $obj->localtax2_value;
1901 $this->typent_id = $obj->typent_id;
1902 $this->typent_code = $obj->typent_code;
1904 $this->effectif_id = $obj->effectif_id;
1905 $this->effectif = $obj->effectif_id ? $obj->effectif :
'';
1907 $this->forme_juridique_code = $obj->forme_juridique_code;
1908 $this->forme_juridique = $obj->forme_juridique_code ? $obj->forme_juridique :
'';
1910 $this->fk_prospectlevel = $obj->fk_prospectlevel;
1912 $this->prefix_comm = $obj->prefix_comm;
1914 $this->remise_percent = $obj->remise_client ?
price2num($obj->remise_client) : 0;
1915 $this->remise_supplier_percent = $obj->remise_supplier;
1917 $this->mode_reglement_id = $obj->mode_reglement;
1918 $this->cond_reglement_id = $obj->cond_reglement;
1919 $this->deposit_percent = $obj->deposit_percent;
1920 $this->transport_mode_id = $obj->transport_mode;
1921 $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier;
1922 $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier;
1923 $this->transport_mode_supplier_id = $obj->transport_mode_supplier;
1924 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
1925 $this->fk_account = $obj->fk_account;
1927 $this->client = $obj->client;
1928 $this->fournisseur = $obj->fournisseur;
1930 $this->note = $obj->note_private;
1931 $this->note_private = $obj->note_private;
1932 $this->note_public = $obj->note_public;
1933 $this->model_pdf = $obj->model_pdf;
1934 $this->modelpdf = $obj->model_pdf;
1935 $this->default_lang = $obj->default_lang;
1936 $this->logo = $obj->logo;
1937 $this->logo_squarred = $obj->logo_squarred;
1939 $this->webservices_url = $obj->webservices_url;
1940 $this->webservices_key = $obj->webservices_key;
1942 $this->accountancy_code_buy = $obj->accountancy_code_buy;
1943 $this->accountancy_code_sell = $obj->accountancy_code_sell;
1945 $this->outstanding_limit = $obj->outstanding_limit;
1946 $this->order_min_amount = $obj->order_min_amount;
1947 $this->supplier_order_min_amount = $obj->supplier_order_min_amount;
1950 $this->price_level = $obj->price_level;
1953 $this->fk_warehouse = $obj->fk_warehouse;
1955 $this->import_key = $obj->import_key;
1958 $this->fk_incoterms = $obj->fk_incoterms;
1959 $this->location_incoterms = $obj->location_incoterms;
1960 $this->label_incoterms = $obj->label_incoterms;
1963 $this->fk_multicurrency = $obj->fk_multicurrency;
1964 $this->multicurrency_code = $obj->multicurrency_code;
1967 $this->model_pdf = $obj->model_pdf;
1968 $this->last_main_doc = $obj->last_main_doc;
1973 $this->fetch_optionals();
1980 $this->error = $this->
db->lasterror();
1981 $this->errors[] = $this->
db->lasterror();
1986 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($this->price_level)) {
1987 $this->price_level = 1;
2001 public function delete($id,
User $fuser =
null, $call_trigger = 1)
2003 global $langs, $conf, $user;
2005 if (empty($fuser)) {
2009 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2011 $entity = isset($this->entity) ? $this->entity : $conf->entity;
2013 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2018 if (empty($objectisused)) {
2022 if (!$error && $call_trigger) {
2024 $result = $this->
call_trigger(
'COMPANY_DELETE', $fuser);
2032 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2034 $toute_categs = array();
2037 if ($this->client || $this->prospect) {
2038 $toute_categs[
'customer'] = $static_cat->containing($this->
id, Categorie::TYPE_CUSTOMER);
2040 if ($this->fournisseur) {
2041 $toute_categs[
'supplier'] = $static_cat->containing($this->
id, Categorie::TYPE_SUPPLIER);
2045 foreach ($toute_categs as $type => $categs_type) {
2046 foreach ($categs_type as $cat) {
2047 $cat->del_type($this, $type);
2053 foreach ($this->childtablesoncascade as $tabletodelete) {
2054 $deleteFromObject = explode(
':', $tabletodelete);
2055 if (count($deleteFromObject) >= 2) {
2056 $className = str_replace(
'@',
'', $deleteFromObject[0]);
2057 $filepath = $deleteFromObject[1];
2058 $columnName = $deleteFromObject[2];
2060 $child_object =
new $className($this->
db);
2061 $result = $child_object->deleteByParentField($id, $columnName);
2064 $this->errors[] = $child_object->error;
2069 $this->errors[] =
'Cannot include child class file '.$filepath;
2073 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
2074 $sql .=
" WHERE fk_soc = ".((int) $id);
2075 if (!$this->
db->query($sql)) {
2077 $this->errors[] = $this->
db->lasterror();
2089 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
2095 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2096 $sql .=
" SET parent = NULL";
2097 $sql .=
" WHERE parent = ".((int) $id);
2098 if (!$this->
db->query($sql)) {
2100 $this->errors[] = $this->
db->lasterror();
2106 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
2107 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity";
2108 $sql .=
" WHERE fk_soc = ".((int) $id);
2109 if (!$this->
db->query($sql)) {
2111 $this->errors[] = $this->
db->lasterror();
2115 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe";
2116 $sql .=
" WHERE rowid = ".((int) $id);
2117 if (!$this->
db->query($sql)) {
2119 $this->errors[] = $this->
db->lasterror();
2124 $this->
db->commit();
2127 if (!empty($conf->societe->multidir_output[$entity])) {
2128 $docdir = $conf->societe->multidir_output[$entity].
"/".$id;
2137 $this->
db->rollback();
2141 dol_syslog(
"Can't remove thirdparty with id ".$id.
". There is ".$objectisused.
" childs", LOG_WARNING);
2158 if (($this->client == 2 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
2161 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2162 $sql .=
" SET client = ".((int) $newclient);
2163 $sql .=
" WHERE rowid = ".((int) $this->
id);
2167 $this->client = $newclient;
2188 global $conf, $langs;
2191 $note = trim($note);
2193 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2197 dol_syslog(get_class($this).
"::set_remise_client ".$remise.
", ".$note.
", ".$user->id);
2205 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2206 $sql .=
" SET remise_client = '".$this->db->escape($remise).
"'";
2207 $sql .=
" WHERE rowid = ".((int) $this->
id);
2210 $this->
db->rollback();
2211 $this->error = $this->
db->error();
2216 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise";
2217 $sql .=
" (entity, datec, fk_soc, remise_client, note, fk_user_author)";
2218 $sql .=
" VALUES (".$conf->entity.
", '".$this->
db->idate($now).
"', ".((int) $this->
id).
", '".$this->
db->escape($remise).
"',";
2219 $sql .=
" '".$this->db->escape($note).
"',";
2220 $sql .=
" ".((int) $user->id);
2225 $this->
db->rollback();
2226 $this->error = $this->
db->lasterror();
2230 $this->
db->commit();
2247 global $conf, $langs;
2250 $note = trim($note);
2252 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2256 dol_syslog(get_class($this).
"::set_remise_supplier ".$remise.
", ".$note.
", ".$user->id);
2264 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2265 $sql .=
" SET remise_supplier = '".$this->db->escape($remise).
"'";
2266 $sql .=
" WHERE rowid = ".((int) $this->
id);
2269 $this->
db->rollback();
2270 $this->error = $this->
db->error();
2275 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise_supplier";
2276 $sql .=
" (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
2277 $sql .=
" VALUES (".$conf->entity.
", '".$this->
db->idate($now).
"', ".((int) $this->
id).
", '".$this->
db->escape($remise).
"',";
2278 $sql .=
" '".$this->db->escape($note).
"',";
2279 $sql .=
" ".((int) $user->id);
2284 $this->
db->rollback();
2285 $this->error = $this->
db->lasterror();
2289 $this->
db->commit();
2306 public function set_remise_except($remise,
User $user, $desc, $vatrate =
'', $discount_type = 0, $price_base_type =
'HT')
2313 $desc = trim($desc);
2316 if (!($remise > 0)) {
2317 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"1");
2321 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"3");
2325 if ($this->
id > 0) {
2329 if (preg_match(
'/\((.*)\)/', $vatrate, $reg)) {
2330 $vat_src_code = $reg[1];
2331 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2334 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2337 $discount->fk_soc = $this->id;
2339 $discount->discount_type = $discount_type;
2341 if ($price_base_type ==
'TTC') {
2342 $discount->amount_ttc = $discount->multicurrency_amount_ttc =
price2num($remise,
'MT');
2343 $discount->amount_ht = $discount->multicurrency_amount_ht =
price2num($remise / (1 + $vatrate / 100),
'MT');
2344 $discount->amount_tva = $discount->multicurrency_amount_tva =
price2num($discount->amount_ttc - $discount->amount_ht,
'MT');
2346 $discount->amount_ht = $discount->multicurrency_amount_ht =
price2num($remise,
'MT');
2347 $discount->amount_tva = $discount->multicurrency_amount_tva =
price2num($remise * $vatrate / 100,
'MT');
2348 $discount->amount_ttc = $discount->multicurrency_amount_ttc =
price2num($discount->amount_ht + $discount->amount_tva,
'MT');
2351 $discount->tva_tx =
price2num($vatrate);
2352 $discount->vat_src_code = $vat_src_code;
2354 $discount->description = $desc;
2356 $result = $discount->create($user);
2360 $this->error = $discount->error;
2379 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2382 $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type);
2386 $this->error = $discountstatic->error;
2404 $reparray = array();
2406 $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";
2407 $sql .=
", u.office_fax, u.user_mobile, u.personal_mobile";
2408 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc, ".MAIN_DB_PREFIX.
"user as u";
2409 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2410 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
2411 $sql .=
" WHERE ((ug.fk_user = sc.fk_user";
2412 $sql .=
" AND ug.entity = ".$conf->entity.
")";
2413 $sql .=
" OR u.admin = 1)";
2415 $sql .=
" WHERE entity in (0, ".$conf->entity.
")";
2418 $sql .=
" AND u.rowid = sc.fk_user AND sc.fk_soc = ".((int) $this->
id);
2419 if (empty($sortfield) && empty($sortorder)) {
2420 $sortfield =
'u.lastname,u.firstname';
2421 $sortorder =
'ASC,ASC';
2423 $sql .= $this->
db->order($sortfield, $sortorder);
2427 $num = $this->
db->num_rows(
$resql);
2430 $obj = $this->
db->fetch_object(
$resql);
2433 $reparray[$i][
'id'] = $obj->rowid;
2434 $reparray[$i][
'lastname'] = $obj->lastname;
2435 $reparray[$i][
'firstname'] = $obj->firstname;
2436 $reparray[$i][
'email'] = $obj->email;
2437 $reparray[$i][
'phone'] = $obj->office_phone;
2438 $reparray[$i][
'office_phone'] = $obj->office_phone;
2439 $reparray[$i][
'office_fax'] = $obj->office_fax;
2440 $reparray[$i][
'user_mobile'] = $obj->user_mobile;
2441 $reparray[$i][
'personal_mobile'] = $obj->personal_mobile;
2442 $reparray[$i][
'job'] = $obj->job;
2443 $reparray[$i][
'statut'] = $obj->status;
2444 $reparray[$i][
'status'] = $obj->status;
2445 $reparray[$i][
'entity'] = $obj->entity;
2446 $reparray[$i][
'login'] = $obj->login;
2447 $reparray[$i][
'photo'] = $obj->photo;
2448 $reparray[$i][
'gender'] = $obj->gender;
2450 $reparray[] = $obj->rowid;
2473 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2474 $sql .=
" SET price_level = ".((int) $price_level);
2475 $sql .=
" WHERE rowid = ".((int) $this->
id);
2477 if (!$this->
db->query($sql)) {
2482 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_prices";
2483 $sql .=
" (datec, fk_soc, price_level, fk_user_author)";
2484 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $this->
id).
", ".((int) $price_level).
", ".((int) $user->id).
")";
2486 if (!$this->
db->query($sql)) {
2508 if ($this->
id > 0 && $commid > 0) {
2512 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux";
2513 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2517 dol_syslog(get_class($this).
"::add_commercial Error ".$this->
db->lasterror());
2523 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_commerciaux";
2524 $sql .=
" (fk_soc, fk_user)";
2525 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $commid).
")";
2529 dol_syslog(get_class($this).
"::add_commercial Error ".$this->
db->lasterror());
2535 $this->context = array(
'commercial_modified' => $commid);
2537 $result = $this->
call_trigger(
'COMPANY_LINK_SALE_REPRESENTATIVE', $user);
2544 $this->
db->commit();
2547 $this->
db->rollback();
2567 $this->context = array(
'commercial_modified'=>$commid);
2569 $result = $this->
call_trigger(
'COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
2574 if ($this->
id > 0 && $commid > 0) {
2575 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux ";
2576 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2578 if (!$this->
db->query($sql)) {
2579 dol_syslog(get_class($this).
"::del_commercial Erreur");
2597 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1, $noaliasinname = 0, $target =
'')
2599 global $conf, $langs, $hookmanager;
2601 if (!empty($conf->dol_no_mouse_hover)) {
2605 $name = $this->
name ? $this->
name : $this->nom;
2607 if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) {
2608 if (empty($option) && $this->client > 0) {
2609 $option =
'customer';
2611 if (empty($option) && $this->fournisseur > 0) {
2612 $option =
'supplier';
2616 if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto))) {
2618 if (($this->client) && (!empty($this->code_client)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 2)) {
2619 $code = $this->code_client.
' - ';
2622 if (($this->fournisseur) && (!empty($this->code_fournisseur)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 3)) {
2623 $code .= $this->code_fournisseur.
' - ';
2627 if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1) {
2628 $name = $code.
' '.$name;
2635 if (!empty($this->name_alias) && empty($noaliasinname)) {
2636 $name .=
' ('.$this->name_alias.
')';
2639 $result =
''; $label =
''; $label2 =
'';
2640 $linkstart =
''; $linkend =
'';
2642 if (!empty($this->logo) && class_exists(
'Form')) {
2643 $label .=
'<div class="photointooltip floatright">';
2644 $label .=
Form::showphoto(
'societe', $this, 0, 40, 0,
'photoref',
'mini', 0);
2647 } elseif (!empty($this->logo_squarred) && class_exists(
'Form')) {
2653 $label .=
'<div class="centpercent">';
2655 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
2656 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Customer").
'</u>';
2657 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2658 } elseif ($option ==
'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
2659 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Prospect").
'</u>';
2660 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2661 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
2662 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Supplier").
'</u>';
2663 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->id;
2664 } elseif ($option ==
'agenda') {
2665 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2666 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/agenda.php?socid='.$this->id;
2667 } elseif ($option ==
'project') {
2668 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2669 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/project.php?socid='.$this->id;
2670 } elseif ($option ==
'margin') {
2671 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2672 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/margin/tabs/thirdpartyMargins.php?socid='.$this->
id.
'&type=1';
2673 } elseif ($option ==
'contact') {
2674 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2675 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/contact.php?socid='.$this->id;
2676 } elseif ($option ==
'ban') {
2677 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2678 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$this->id;
2682 if (empty($linkstart)) {
2683 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2684 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$this->id;
2686 if (isset($this->status)) {
2687 $label .=
' '.$this->getLibStatut(5);
2689 if (isset($this->client) && isset($this->fournisseur)) {
2690 $label .=
' ';
2695 if (!empty($this->name_alias)) {
2700 $label .=
'<br>'.img_picto(
'',
'email',
'class="pictofixedwidth"').$this->email;
2702 if (!empty($this->phone) || !empty($this->fax)) {
2703 $phonelist = array();
2705 $phonelist[] =
dol_print_phone($this->phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2708 $phonelist[] =
dol_print_phone($this->fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2710 $label .=
'<br>'.implode(
' ', $phonelist);
2713 if (!empty($this->address)) {
2714 $label2 .=
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
' ', $langs);
2715 } elseif (!empty($this->country_code)) {
2716 $label2 .=
'<br><b>'.$langs->trans(
'Country').
':</b> '.$this->country_code;
2718 if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'vatnumber') !==
false)) {
2719 $label2 .=
'<br><b>'.$langs->trans(
'VATIntra').
':</b> '.
dol_escape_htmltag($this->tva_intra);
2722 if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP)) {
2723 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid1') !==
false && $langs->trans(
'ProfId1'.$this->country_code) !=
'-') {
2724 $label2 .=
'<br><b>'.$langs->trans(
'ProfId1'.$this->country_code).
':</b> '.$this->idprof1;
2726 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid2') !==
false && $langs->trans(
'ProfId2'.$this->country_code) !=
'-') {
2727 $label2 .=
'<br><b>'.$langs->trans(
'ProfId2'.$this->country_code).
':</b> '.$this->idprof2;
2729 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid3') !==
false && $langs->trans(
'ProfId3'.$this->country_code) !=
'-') {
2730 $label2 .=
'<br><b>'.$langs->trans(
'ProfId3'.$this->country_code).
':</b> '.$this->idprof3;
2732 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid4') !==
false && $langs->trans(
'ProfId4'.$this->country_code) !=
'-') {
2733 $label2 .=
'<br><b>'.$langs->trans(
'ProfId4'.$this->country_code).
':</b> '.$this->idprof4;
2735 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid5') !==
false && $langs->trans(
'ProfId5'.$this->country_code) !=
'-') {
2736 $label2 .=
'<br><b>'.$langs->trans(
'ProfId5'.$this->country_code).
':</b> '.$this->idprof5;
2738 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid6') !==
false && $langs->trans(
'ProfId6'.$this->country_code) !=
'-') {
2739 $label2 .=
'<br><b>'.$langs->trans(
'ProfId6'.$this->country_code).
':</b> '.$this->idprof6;
2742 if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
2743 $label2 .=
'<br><b>'.$langs->trans(
'CustomerCode').
':</b> '.$this->code_client;
2745 if (!empty($this->code_fournisseur) && $this->fournisseur) {
2746 $label2 .=
'<br><b>'.$langs->trans(
'SupplierCode').
':</b> '.$this->code_fournisseur;
2748 if (
isModEnabled(
'accounting') && ($this->client == 1 || $this->client == 3)) {
2749 $label2 .=
'<br><b>'.$langs->trans(
'CustomerAccountancyCode').
':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client);
2751 if (
isModEnabled(
'accounting') && $this->fournisseur) {
2752 $label2 .=
'<br><b>'.$langs->trans(
'SupplierAccountancyCode').
':</b> '.$this->code_compta_fournisseur;
2754 $label .= ($label2 ?
'<br>'.$label2 :
'').
'</div>';
2757 $linkstart .= (!empty($this->canvas) ?
'&canvas='.$this->canvas :
'');
2759 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2760 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2761 $add_save_lastsearch_values = 1;
2763 if ($add_save_lastsearch_values) {
2764 $linkstart .=
'&save_lastsearch_values=1';
2769 if (empty($notooltip)) {
2770 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2771 $label = $langs->trans(
"ShowCompany");
2772 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2774 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
2775 $linkclose .=
' class="classfortooltip refurl"';
2776 $target_value = array(
'_self',
'_blank',
'_parent',
'_top');
2777 if (in_array($target, $target_value)) {
2778 $linkclose .=
' target="'.dol_escape_htmltag($target).
'"';
2781 $linkstart .= $linkclose.
'>';
2785 if (empty($user->rights->societe->client->voir) && $user->socid > 0 && $this->id != $user->socid) {
2790 $result .= $linkstart;
2792 $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);
2794 if ($withpicto != 2) {
2797 $result .= $linkend;
2800 $hookmanager->initHooks(array(
'thirdpartydao'));
2801 $parameters = array(
2803 'getnomurl' => &$result,
2804 'withpicto '=> $withpicto,
2807 'notooltip'=> $notooltip,
2808 'save_lastsearch_value'=> $save_lastsearch_value
2810 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2812 $result = $hookmanager->resPrint;
2814 $result .= $hookmanager->resPrint;
2829 public function getTypeUrl($withpicto = 0, $option =
'', $notooltip = 0, $tag =
'a')
2831 global $conf, $langs;
2834 if (empty($option) || preg_match(
'/prospect/', $option)) {
2835 if (($this->client == 2 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
2836 $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.
'>';
2839 if (empty($option) || preg_match(
'/customer/', $option)) {
2840 if (($this->client == 1 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
2841 $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.
'>';
2844 if (empty($option) || preg_match(
'/supplier/', $option)) {
2845 if (((
isModEnabled(
"fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) ||
isModEnabled(
"supplier_order") ||
isModEnabled(
"supplier_invoice")) && $this->fournisseur) {
2846 $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.
'>';
2861 return $this->
LibStatut($this->status, $mode);
2876 $langs->load(
'companies');
2878 $statusType =
'status4';
2880 $statusType =
'status6';
2883 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2884 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
2885 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"InActivity");
2886 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
2887 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"InActivity");
2890 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2906 if ($this->email && $addthirdparty) {
2907 if (empty($this->
name)) {
2908 $this->
name = $this->nom;
2910 $contact_emails[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->email.
">";
2913 return $contact_emails;
2929 if (!empty($this->phone)) {
2930 if (empty($this->
name)) {
2931 $this->
name = $this->nom;
2934 $contact_phone[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->phone.
">";
2936 return $contact_phone;
2952 $contact_property = array();
2955 $sql =
"SELECT rowid, email, statut as status, phone_mobile, lastname, poste, firstname";
2956 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
2957 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
2958 $sql .=
" ORDER BY lastname, firstname";
2962 $nump = $this->
db->num_rows(
$resql);
2964 $sepa =
"("; $sepb =
")";
2965 if ($mode ==
'email') {
2967 $sepa =
"<"; $sepb =
">";
2970 while ($i < $nump) {
2971 $obj = $this->
db->fetch_object(
$resql);
2972 if ($mode ==
'email') {
2973 $property = $obj->email;
2974 } elseif ($mode ==
'mobile') {
2975 $property = $obj->phone_mobile;
2977 $property = $obj->$mode;
2981 if ($obj->status == 1 || empty($hidedisabled)) {
2982 if (empty($property)) {
2983 if ($mode ==
'email') {
2984 $property = $langs->transnoentitiesnoconv(
"NoEMail");
2985 } elseif ($mode ==
'mobile') {
2986 $property = $langs->transnoentitiesnoconv(
"NoMobilePhone");
2990 if (!empty($obj->poste)) {
2991 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ?
" - ".$obj->poste :
"").(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
2993 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3002 return $contact_property;
3015 $contacts = array();
3017 $sql =
"SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3020 $nump = $this->
db->num_rows(
$resql);
3023 while ($i < $nump) {
3024 $obj = $this->
db->fetch_object(
$resql);
3044 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
3045 $contacts = array();
3047 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3050 $nump = $this->
db->num_rows(
$resql);
3053 while ($i < $nump) {
3054 $obj = $this->
db->fetch_object(
$resql);
3056 $contact->fetch($obj->rowid);
3057 $contacts[] = $contact;
3078 $contact_property =
'';
3080 if (empty($rowid)) {
3084 $sql =
"SELECT rowid, email, phone_mobile, lastname, firstname";
3085 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3086 $sql .=
" WHERE rowid = ".((int) $rowid);
3090 $nump = $this->
db->num_rows(
$resql);
3093 $obj = $this->
db->fetch_object(
$resql);
3095 if ($mode ==
'email') {
3097 } elseif ($mode ==
'mobile') {
3098 $contact_property = $obj->phone_mobile;
3101 return $contact_property;
3118 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3121 $bac->fetch(0, $this->
id);
3124 if ($mode ==
'label') {
3125 return $bac->getRibLabel(
true);
3126 } elseif ($mode ==
'rum') {
3127 if (empty($bac->rum)) {
3128 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
3130 $bac->fetch_thirdparty();
3131 $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
3134 } elseif ($mode ==
'format') {
3135 return $bac->frstrecur;
3137 return 'BadParameterToFunctionDisplayRib';
3153 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3154 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE type='ban' AND fk_soc = ".((int) $this->
id);
3155 $result = $this->
db->query($sql);
3158 $this->errors[] = $this->
db->lasterror;
3161 $num_rows = $this->
db->num_rows($result);
3162 $rib_array = array();
3164 while ($obj = $this->
db->fetch_object($result)) {
3166 $rib->fetch($obj->rowid);
3167 $rib_array[] = $rib;
3187 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3188 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3190 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3191 foreach ($dirsociete as $dirroot) {
3197 $mod =
new $module();
3199 $this->code_client = $mod->getNextValue($objsoc, $type);
3200 $this->prefixCustomerIsRequired = $mod->prefixIsRequired;
3202 dol_syslog(get_class($this).
"::get_codeclient code_client=".$this->code_client.
" module=".$module);
3219 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3220 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3222 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3223 foreach ($dirsociete as $dirroot) {
3229 $mod =
new $module();
3231 $this->code_fournisseur = $mod->getNextValue($objsoc, $type);
3233 dol_syslog(get_class($this).
"::get_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3248 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3249 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3251 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3252 foreach ($dirsociete as $dirroot) {
3259 $mod =
new $module();
3261 dol_syslog(get_class($this).
"::codeclient_modifiable code_client=".$this->code_client.
" module=".$module);
3262 if ($mod->code_modifiable_null && !$this->code_client) {
3265 if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
3268 if ($mod->code_modifiable) {
3288 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3289 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3291 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3292 foreach ($dirsociete as $dirroot) {
3299 $mod =
new $module();
3301 dol_syslog(get_class($this).
"::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur.
" module=".$module);
3302 if ($mod->code_modifiable_null && !$this->code_fournisseur) {
3305 if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
3308 if ($mod->code_modifiable) {
3334 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3335 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3337 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3338 foreach ($dirsociete as $dirroot) {
3345 $mod =
new $module();
3347 dol_syslog(get_class($this).
"::check_codeclient code_client=".$this->code_client.
" module=".$module);
3348 $result = $mod->verif($this->
db, $this->code_client, $this, 0);
3350 $this->error = $mod->error;
3351 $this->errors = $mod->errors;
3375 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3376 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3378 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3379 foreach ($dirsociete as $dirroot) {
3386 $mod =
new $module();
3388 dol_syslog(get_class($this).
"::check_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3389 $result = $mod->verif($this->
db, $this->code_fournisseur, $this, 1);
3391 $this->error = $mod->error;
3392 $this->errors = $mod->errors;
3414 if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) {
3416 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3417 foreach ($dirsociete as $dirroot) {
3418 $res =
dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.
'.php');
3425 $classname = $conf->global->SOCIETE_CODECOMPTA_ADDON;
3426 $mod =
new $classname;
3429 $result = $mod->get_code($this->
db, $this, $type);
3431 if ($type ==
'customer') {
3432 $this->code_compta_client = $mod->code;
3433 $this->code_compta = $this->code_compta_client;
3434 } elseif ($type ==
'supplier') {
3435 $this->code_compta_fournisseur = $mod->code;
3440 $this->error =
'ErrorAccountancyCodeNotDefined';
3444 if ($type ==
'customer') {
3445 $this->code_compta_client =
'';
3446 $this->code_compta =
'';
3447 } elseif ($type ==
'supplier') {
3448 $this->code_compta_fournisseur =
'';
3463 dol_syslog(get_class($this).
'::setParent', LOG_DEBUG);
3469 if ($sameparent < 0) {
3472 if ($sameparent == 1) {
3473 setEventMessages(
'ParentCompanyToAddIsAlreadyAChildOfModifiedCompany',
null,
'warnings');
3478 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe SET parent = '.($id > 0 ? $id :
'null').
' WHERE rowid = '.((
int) $this->id);
3482 $this->parent = $id;
3502 if ($counter > 100) {
3503 dol_syslog(
"Too high level of parent - child for company. May be an infinite loop ?", LOG_WARNING);
3506 $sql =
'SELECT s.parent';
3507 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
3508 $sql .=
' WHERE rowid = '.((int) $idparent);
3511 $obj = $this->
db->fetch_object(
$resql);
3513 if ($obj->parent ==
'') {
3515 } elseif ($obj->parent == $idchild) {
3537 if ($company_id > 0) {
3538 $sql =
"SELECT parent FROM " . MAIN_DB_PREFIX .
"societe WHERE rowid = $company_id";
3541 if ($obj = $this->
db->fetch_object(
$resql)) {
3542 $parent = $obj->parent;
3543 if ($parent > 0 && !in_array($parent, $parents)) {
3544 $parents[] = $parent;
3552 setEventMessage($langs->trans(
'GetCompanyParentsError', $this->db->lasterror()),
'errors');
3571 $ret = (empty($conf->global->SOCIETE_IDPROF1_UNIQUE) ? false :
true);
3574 $ret = (empty($conf->global->SOCIETE_IDPROF2_UNIQUE) ? false :
true);
3577 $ret = (empty($conf->global->SOCIETE_IDPROF3_UNIQUE) ? false :
true);
3580 $ret = (empty($conf->global->SOCIETE_IDPROF4_UNIQUE) ? false :
true);
3583 $ret = (empty($conf->global->SOCIETE_IDPROF5_UNIQUE) ? false :
true);
3586 $ret = (empty($conf->global->SOCIETE_IDPROF6_UNIQUE) ? false :
true);
3635 $sql =
"SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"societe WHERE ".$field.
" = '".$this->
db->escape($value).
"' AND entity IN (".
getEntity(
'societe').
")";
3637 $sql .=
" AND rowid <> ".$socid;
3641 $obj = $this->
db->fetch_object(
$resql);
3645 print $this->
db->error();
3672 if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3677 if ($idprof == 1 && $soc->country_code ==
'FR') {
3678 $chaine = trim($this->idprof1);
3679 $chaine = preg_replace(
'/(\s)/',
'', $chaine);
3681 if (!is_numeric($chaine)) {
3693 for ($index = 0; $index < 9; $index++) {
3694 $number = (int) $chaine[$index];
3695 if (($index % 2) != 0) {
3696 if (($number *= 2) > 9) {
3704 if (($sum % 10) != 0) {
3710 if ($idprof == 2 && $soc->country_code ==
'FR') {
3711 $chaine = trim($this->idprof2);
3712 $chaine = preg_replace(
'/(\s)/',
'', $chaine);
3714 if (!is_numeric($chaine)) {
3726 for ($index = 0; $index < 14; $index++) {
3727 $number = (int) $chaine[$index];
3728 if (($index % 2) == 0) {
3729 if (($number *= 2) > 9) {
3737 if (($sum % 10) != 0) {
3744 if ($idprof == 1 && $soc->country_code ==
'ES') {
3745 $string = trim($this->idprof1);
3746 $string = preg_replace(
'/(\s)/',
'', $string);
3747 $string = strtoupper($string);
3750 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)) {
3755 for ($i = 0; $i < 9; $i++) {
3756 $num[$i] = substr($string, $i, 1);
3760 if (preg_match(
'/(^[0-9]{8}[A-Z]{1}$)/', $string)) {
3761 if ($num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) {
3769 $sum = $num[2] + $num[4] + $num[6];
3770 for ($i = 1; $i < 8; $i += 2) {
3771 $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1));
3773 $n = 10 - substr($sum, strlen($sum) - 1, 1);
3776 if (preg_match(
'/^[KLM]{1}/', $string)) {
3777 if ($num[8] == chr(64 + $n) || $num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) {
3785 if (preg_match(
'/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) {
3786 if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) {
3794 if (preg_match(
'/^[T]{1}/', $string)) {
3795 if ($num[8] == preg_match(
'/^[T]{1}[A-Z0-9]{8}$/', $string)) {
3803 if (preg_match(
'/^[XYZ]{1}/', $string)) {
3804 if ($num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array(
'X',
'Y',
'Z'), array(
'0',
'1',
'2'), $string), 0, 8) % 23, 1)) {
3817 if ($idprof == 1 && $soc->country_code ==
'PT') {
3818 $string = trim($this->idprof1);
3819 $string = preg_replace(
'/(\s)/',
'', $string);
3822 if (preg_match(
'/(^[0-9]{9}$)/', $string)) {
3831 if ($idprof == 1 && $soc->country_code ==
'DZ') {
3832 $string = trim($this->idprof1);
3833 $string = preg_replace(
'/(\s)/',
'', $string);
3836 if (preg_match(
'/(^[0-9]{15}$)/', $string)) {
3858 global $conf, $langs, $hookmanager;
3863 $hookmanager->initHooks(array(
'idprofurl'));
3864 $parameters = array(
'idprof'=>$idprof,
'company'=>$thirdparty);
3865 $reshook = $hookmanager->executeHooks(
'getIdProfUrl', $parameters, $this, $action);
3866 if (empty($reshook)) {
3867 if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3872 $strippedIdProf1 = str_replace(
' ',
'', $thirdparty->idprof1);
3873 if ($idprof == 1 && $thirdparty->country_code ==
'FR') {
3874 $url =
'https://annuaire-entreprises.data.gouv.fr/entreprise/'.$strippedIdProf1;
3876 if ($idprof == 1 && ($thirdparty->country_code ==
'GB' || $thirdparty->country_code ==
'UK')) {
3877 $url =
'https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
3879 if ($idprof == 1 && $thirdparty->country_code ==
'ES') {
3880 $url =
'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
3882 if ($idprof == 1 && $thirdparty->country_code ==
'IN') {
3883 $url =
'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.
';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3885 if ($idprof == 1 && $thirdparty->country_code ==
'DZ') {
3886 $url =
'http://nif.mfdgi.gov.dz/nif.asp?Nif='.$strippedIdProf1;
3888 if ($idprof == 1 && $thirdparty->country_code ==
'PT') {
3889 $url =
'http://www.nif.pt/'.$strippedIdProf1;
3893 return '<a target="_blank" rel="noopener noreferrer" href="'.$url.
'">'.$langs->trans(
"Check").
'</a>';
3896 return $hookmanager->resPrint;
3911 $sql =
"SELECT COUNT(*) as numproj FROM ".MAIN_DB_PREFIX.
"projet WHERE fk_soc = ".((int) $this->
id);
3914 $obj = $this->
db->fetch_object(
$resql);
3915 $count = $obj->numproj;
3918 print $this->
db->error();
3921 return ($count > 0);
3933 $sql =
"SELECT s.rowid, s.nom as name, s.datec, tms as datem,";
3934 $sql .=
" fk_user_creat, fk_user_modif";
3935 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
3936 $sql .=
" WHERE s.rowid = ".((int) $id);
3938 $result = $this->
db->query($sql);
3940 if ($this->
db->num_rows($result)) {
3941 $obj = $this->
db->fetch_object($result);
3943 $this->
id = $obj->rowid;
3945 $this->user_creation_id = $obj->fk_user_creat;
3946 $this->user_modification_id = $obj->fk_user_modif;
3947 $this->date_creation = $this->
db->jdate($obj->datec);
3948 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
3950 $this->
ref = $obj->name;
3953 $this->
db->free($result);
3969 $isacompany = empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES) ? 0 : 1;
3970 if (!empty($this->tva_intra)) {
3972 } elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) {
3974 } elseif (!empty($this->typent_code) && $this->typent_code !=
'TE_UNKNOWN') {
3976 if (preg_match(
'/^TE_PRIVATE/', $this->typent_code)) {
3993 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4006 $this->SupplierCategories = array();
4007 $sql =
"SELECT rowid, label";
4008 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
4009 $sql .=
" WHERE type = ".Categorie::TYPE_SUPPLIER;
4013 while ($obj = $this->
db->fetch_object(
$resql)) {
4014 $this->SupplierCategories[$obj->rowid] = $obj->label;
4032 if ($categorie_id > 0 && $this->
id > 0) {
4033 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_fournisseur (fk_categorie, fk_soc) ";
4034 $sql .=
" VALUES (".((int) $categorie_id).
", ".((int) $this->
id).
")";
4036 if (
$resql = $this->
db->query($sql)) {
4052 $sql =
"SELECT count(mc.email) as nb";
4053 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
4054 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->email).
"' ";
4055 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
4059 $obj = $this->
db->fetch_object(
$resql);
4065 $this->error = $this->
db->error();
4085 $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).
"'";
4088 $obj = $this->
db->fetch_object(
$resql);
4089 $noemail = $obj->nb;
4090 if (empty($noemail)) {
4091 $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()).
"')";
4095 $this->error = $this->
db->lasterror();
4096 $this->errors[] = $this->error;
4101 $this->error = $this->
db->lasterror();
4102 $this->errors[] = $this->error;
4105 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->
db->escape($this->email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
4109 $this->error = $this->
db->lasterror();
4110 $this->errors[] = $this->error;
4114 if (empty($error)) {
4115 $this->no_email = $no_email;
4116 $this->
db->commit();
4119 $this->
db->rollback();
4136 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->
db->escape($this->email).
"'";
4139 $obj = $this->
db->fetch_object(
$resql);
4140 $this->no_email = $obj->nb;
4143 $this->error = $this->
db->lasterror();
4144 $this->errors[] = $this->error;
4164 global $conf, $user, $langs;
4166 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
4169 if ($member->morphy ==
'mor') {
4170 if (empty($socname)) {
4171 $socname = $member->company? $member->company : $member->societe;
4173 if (!empty($fullname) && empty($socalias)) {
4174 $socalias = $fullname;
4176 } elseif (empty($socname) && $member->morphy ==
'phy') {
4177 if (empty($socname)) {
4178 $socname = $fullname;
4180 if (!empty($member->company) && empty($socalias)) {
4181 $socalias = $member->company;
4186 $alias = $socalias ? $socalias :
'';
4190 $this->
name = $name;
4191 $this->name_alias = $alias;
4192 $this->address = $member->address;
4193 $this->zip = $member->zip;
4194 $this->town = $member->town;
4195 $this->country_code = $member->country_code;
4196 $this->country_id = $member->country_id;
4197 $this->phone = $member->phone;
4198 $this->email = $member->email;
4199 $this->socialnetworks = $member->socialnetworks;
4200 $this->entity = $member->entity;
4203 $this->code_client = ($customercode ? $customercode : -1);
4204 $this->code_fournisseur = -1;
4205 $this->typent_code = ($member->morphy ==
'phy' ?
'TE_PRIVATE' : 0);
4206 $this->typent_id = $this->typent_code ?
dol_getIdFromCode($this->
db, $this->typent_code,
'c_typent',
'id',
'code') : 0;
4211 $result = $this->
create($user);
4215 if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT)) {
4217 $this->name_bis = $member->lastname;
4218 $this->firstname = $member->firstname;
4219 $this->civility_id = $member->civility_id;
4221 dol_syslog(
"We ask to create a contact/address too", LOG_DEBUG);
4226 $this->
db->rollback();
4231 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent";
4232 $sql .=
" SET fk_soc = ".((int) $this->
id);
4233 $sql .=
" WHERE rowid = ".((int) $member->id);
4237 $this->
db->commit();
4240 $this->error = $this->
db->error();
4242 $this->
db->rollback();
4247 dol_syslog(get_class($this).
"::create_from_member - 2 - ".$this->error.
" - ".join(
',', $this->errors), LOG_ERR);
4249 $this->
db->rollback();
4265 $this->
name = empty($conf->global->MAIN_INFO_SOCIETE_NOM) ?
'' : $conf->global->MAIN_INFO_SOCIETE_NOM;
4266 $this->address = empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS) ?
'' : $conf->global->MAIN_INFO_SOCIETE_ADDRESS;
4267 $this->zip = empty($conf->global->MAIN_INFO_SOCIETE_ZIP) ?
'' : $conf->global->MAIN_INFO_SOCIETE_ZIP;
4268 $this->town = empty($conf->global->MAIN_INFO_SOCIETE_TOWN) ?
'' : $conf->global->MAIN_INFO_SOCIETE_TOWN;
4269 $this->region_code = empty($conf->global->MAIN_INFO_SOCIETE_REGION) ?
'' : $conf->global->MAIN_INFO_SOCIETE_REGION;
4270 $this->
object = empty($conf->global->MAIN_INFO_SOCIETE_OBJECT) ?
'' : $conf->global->MAIN_INFO_SOCIETE_OBJECT;
4272 $this->note_private = empty($conf->global->MAIN_INFO_SOCIETE_NOTE) ?
'' : $conf->global->MAIN_INFO_SOCIETE_NOTE;
4274 $this->nom = $this->name;
4277 $country_id = $country_code = $country_label =
'';
4278 if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
4279 $tmp = explode(
':', $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
4280 $country_id = $tmp[0];
4281 if (!empty($tmp[1])) {
4282 $country_code = $tmp[1];
4283 $country_label = $tmp[2];
4286 dol_syslog(
"Your country setup use an old syntax. Reedit it using setup area.", LOG_WARNING);
4287 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4289 $country_label =
getCountry($country_id, 0, $this->
db);
4292 $this->country_id = $country_id;
4293 $this->country_code = $country_code;
4294 $this->country = $country_label;
4295 if (is_object($langs)) {
4296 $this->country = ($langs->trans(
'Country'.$country_code) !=
'Country'.$country_code) ? $langs->trans(
'Country'.$country_code) : $country_label;
4301 $state_id = 0; $state_code = $state_label =
'';
4302 if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE)) {
4303 $tmp = explode(
':', $conf->global->MAIN_INFO_SOCIETE_STATE);
4304 $state_id = $tmp[0];
4305 if (!empty($tmp[1])) {
4306 $state_code = $tmp[1];
4307 $state_label = $tmp[2];
4309 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);
4310 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4311 $state_code =
getState($state_id, 2, $this->
db);
4312 $state_label =
getState($state_id, 0, $this->
db);
4315 $this->state_id = $state_id;
4316 $this->state_code = $state_code;
4317 $this->state = $state_label;
4318 if (is_object($langs)) {
4319 $this->state = ($langs->trans(
'State'.$state_code) !=
'State'.$state_code) ? $langs->trans(
'State'.$state_code) : $state_label;
4322 $this->phone = empty($conf->global->MAIN_INFO_SOCIETE_TEL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_TEL;
4323 $this->fax = empty($conf->global->MAIN_INFO_SOCIETE_FAX) ?
'' : $conf->global->MAIN_INFO_SOCIETE_FAX;
4324 $this->url = empty($conf->global->MAIN_INFO_SOCIETE_WEB) ?
'' : $conf->global->MAIN_INFO_SOCIETE_WEB;
4327 $this->facebook_url = empty($conf->global->MAIN_INFO_SOCIETE_FACEBOOK_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_FACEBOOK_URL;
4328 $this->twitter_url = empty($conf->global->MAIN_INFO_SOCIETE_TWITTER_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_TWITTER_URL;
4329 $this->linkedin_url = empty($conf->global->MAIN_INFO_SOCIETE_LINKEDIN_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LINKEDIN_URL;
4330 $this->instagram_url = empty($conf->global->MAIN_INFO_SOCIETE_INSTAGRAM_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_INSTAGRAM_URL;
4331 $this->youtube_url = empty($conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL;
4332 $this->github_url = empty($conf->global->MAIN_INFO_SOCIETE_GITHUB_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_GITHUB_URL;
4333 $this->socialnetworks = array();
4334 if (!empty($this->facebook_url)) {
4335 $this->socialnetworks[
'facebook'] = $this->facebook_url;
4337 if (!empty($this->twitter_url)) {
4338 $this->socialnetworks[
'twitter'] = $this->twitter_url;
4340 if (!empty($this->linkedin_url)) {
4341 $this->socialnetworks[
'linkedin'] = $this->linkedin_url;
4343 if (!empty($this->instagram_url)) {
4344 $this->socialnetworks[
'instagram'] = $this->instagram_url;
4346 if (!empty($this->youtube_url)) {
4347 $this->socialnetworks[
'youtube'] = $this->youtube_url;
4349 if (!empty($this->github_url)) {
4350 $this->socialnetworks[
'github'] = $this->github_url;
4354 $this->idprof1 = empty($conf->global->MAIN_INFO_SIREN) ?
'' : $conf->global->MAIN_INFO_SIREN;
4355 $this->idprof2 = empty($conf->global->MAIN_INFO_SIRET) ?
'' : $conf->global->MAIN_INFO_SIRET;
4356 $this->idprof3 = empty($conf->global->MAIN_INFO_APE) ?
'' : $conf->global->MAIN_INFO_APE;
4357 $this->idprof4 = empty($conf->global->MAIN_INFO_RCS) ?
'' : $conf->global->MAIN_INFO_RCS;
4358 $this->idprof5 = empty($conf->global->MAIN_INFO_PROFID5) ?
'' : $conf->global->MAIN_INFO_PROFID5;
4359 $this->idprof6 = empty($conf->global->MAIN_INFO_PROFID6) ?
'' : $conf->global->MAIN_INFO_PROFID6;
4360 $this->tva_intra = empty($conf->global->MAIN_INFO_TVAINTRA) ?
'' : $conf->global->MAIN_INFO_TVAINTRA;
4361 $this->managers = empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS) ?
'' : $conf->global->MAIN_INFO_SOCIETE_MANAGERS;
4362 $this->capital = empty($conf->global->MAIN_INFO_CAPITAL) ?
'' : $conf->global->MAIN_INFO_CAPITAL;
4363 $this->forme_juridique_code = empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE) ?
'' : $conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
4364 $this->email = empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_MAIL;
4365 $this->default_lang = (empty($conf->global->MAIN_LANG_DEFAULT) ?
'auto' : $conf->global->MAIN_LANG_DEFAULT);
4366 $this->logo = empty($conf->global->MAIN_INFO_SOCIETE_LOGO) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO;
4367 $this->logo_small = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
4368 $this->logo_mini = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
4369 $this->logo_squarred = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED;
4370 $this->logo_squarred_small = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL;
4371 $this->logo_squarred_mini = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI;
4374 $this->tva_assuj = $conf->global->FACTURE_TVAOPTION;
4377 $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);
4378 $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);
4395 $this->
name =
'THIRDPARTY SPECIMEN '.dol_print_date($now,
'dayhourlog');
4396 $this->nom = $this->name;
4397 $this->ref_ext =
'Ref ext';
4398 $this->specimen = 1;
4399 $this->address =
'21 jump street';
4400 $this->zip =
'99999';
4401 $this->town =
'MyTown';
4402 $this->state_id = 1;
4403 $this->state_code =
'AA';
4404 $this->state =
'MyState';
4405 $this->country_id = 1;
4406 $this->country_code =
'FR';
4407 $this->email =
'specimen@specimen.com';
4408 $this->socialnetworks = array(
4409 'skype' =>
'tom.hanson',
4410 'twitter' =>
'tomhanson',
4411 'facebook' =>
'tomhanson',
4412 'linkedin' =>
'tomhanson',
4414 $this->url =
'http://www.specimen.com';
4416 $this->phone =
'0909090901';
4417 $this->fax =
'0909090909';
4419 $this->code_client =
'CC-'.dol_print_date($now,
'dayhourlog');
4420 $this->code_fournisseur =
'SC-'.dol_print_date($now,
'dayhourlog');
4421 $this->capital = 10000;
4423 $this->prospect = 1;
4424 $this->fournisseur = 1;
4425 $this->tva_assuj = 1;
4426 $this->tva_intra =
'EU1234567';
4427 $this->note_public =
'This is a comment (public)';
4428 $this->note_private =
'This is a comment (private)';
4430 $this->idprof1 =
'idprof1';
4431 $this->idprof2 =
'idprof2';
4432 $this->idprof3 =
'idprof3';
4433 $this->idprof4 =
'idprof4';
4434 $this->idprof5 =
'idprof5';
4435 $this->idprof6 =
'idprof6';
4447 $sql =
"SELECT t.localtax1, t.localtax2";
4448 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4449 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4450 $sql .=
" AND t.active = 1";
4451 if (empty($localTaxNum)) {
4452 $sql .=
" AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
4453 } elseif ($localTaxNum == 1) {
4454 $sql .=
" AND t.localtax1_type <> '0'";
4455 } elseif ($localTaxNum == 2) {
4456 $sql .=
" AND t.localtax2_type <> '0'";
4461 return ($this->
db->num_rows(
$resql) > 0);
4474 $sql =
"SELECT t.rowid";
4475 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4476 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4477 $sql .=
" AND t.active = 1 AND t.recuperableonly = 1";
4482 return ($this->
db->num_rows(
$resql) > 0);
4496 $sql =
"SELECT COUNT(*) as nb";
4497 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_revenuestamp as r, ".MAIN_DB_PREFIX.
"c_country as c";
4498 $sql .=
" WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4499 $sql .=
" AND r.active = 1";
4504 $obj = $this->
db->fetch_object(
$resql);
4505 return (($obj->nb > 0) ?
true:
false);
4507 $this->error = $this->
db->lasterror();
4534 $lib = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
4536 if ($lib == $langs->trans(
"ProspectLevel".$fk_prospectlevel)) {
4537 $lib = $langs->getLabelFromKey($this->
db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
4551 return $this->
LibProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
4572 $langs->load(
'customers');
4575 if ($status ==
'-1' || $status ==
'ST_NO') {
4576 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
4577 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4578 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
4579 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4580 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
4581 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4582 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
4583 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4584 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
4586 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);
4588 } elseif ($mode == 3) {
4589 if ($status ==
'-1' || $status ==
'ST_NO') {
4590 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto);
4591 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4592 return img_action($langs->trans(
"StatusProspect0"), 0, $picto);
4593 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4594 return img_action($langs->trans(
"StatusProspect1"), 1, $picto);
4595 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4596 return img_action($langs->trans(
"StatusProspect2"), 2, $picto);
4597 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4598 return img_action($langs->trans(
"StatusProspect3"), 3, $picto);
4600 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto);
4602 } elseif ($mode == 4) {
4603 if ($status ==
'-1' || $status ==
'ST_NO') {
4604 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
4605 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4606 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
4607 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4608 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
4609 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4610 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
4611 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4612 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
4614 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);
4618 return "Error, mode/status not found";
4630 if ($mode ==
'supplier') {
4631 $table =
'supplier_proposal';
4634 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4635 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4636 if ($mode ==
'supplier') {
4637 $sql .=
" AND entity IN (".getEntity(
'supplier_proposal').
")";
4639 $sql .=
" AND entity IN (".getEntity(
'propal').
")";
4642 dol_syslog(
"getOutstandingProposals for fk_soc = ".((
int) $this->
id), LOG_DEBUG);
4646 $outstandingOpened = 0;
4647 $outstandingTotal = 0;
4648 $outstandingTotalIncTax = 0;
4649 $arrayofref = array();
4650 while ($obj = $this->
db->fetch_object(
$resql)) {
4651 $arrayofref[$obj->rowid] = $obj->ref;
4652 $outstandingTotal += $obj->total_ht;
4653 $outstandingTotalIncTax += $obj->total_ttc;
4654 if ($obj->status != 0) {
4656 $outstandingOpened += $obj->total_ttc;
4659 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref);
4673 $table =
'commande';
4674 if ($mode ==
'supplier') {
4675 $table =
'commande_fournisseur';
4678 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4679 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4680 if ($mode ==
'supplier') {
4681 $sql .=
" AND entity IN (".getEntity(
'supplier_order').
")";
4683 $sql .=
" AND entity IN (".getEntity(
'commande').
")";
4686 dol_syslog(
"getOutstandingOrders", LOG_DEBUG);
4689 $outstandingOpened = 0;
4690 $outstandingTotal = 0;
4691 $outstandingTotalIncTax = 0;
4692 $arrayofref = array();
4693 while ($obj = $this->
db->fetch_object(
$resql)) {
4694 $arrayofref[$obj->rowid] = $obj->ref;
4695 $outstandingTotal += $obj->total_ht;
4696 $outstandingTotalIncTax += $obj->total_ttc;
4697 if ($obj->status != 0) {
4699 $outstandingOpened += $obj->total_ttc;
4702 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref);
4718 if ($mode ==
'supplier') {
4719 $table =
'facture_fourn';
4729 $sql =
"SELECT rowid, ref, total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table.
" as f";
4730 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4731 if (!empty($late)) {
4732 $sql .=
" AND date_lim_reglement < '".$this->db->idate(
dol_now()).
"'";
4734 if ($mode ==
'supplier') {
4735 $sql .=
" AND entity IN (".getEntity(
'facture_fourn').
")";
4737 $sql .=
" AND entity IN (".getEntity(
'invoice').
")";
4740 dol_syslog(
"getOutstandingBills", LOG_DEBUG);
4743 $outstandingOpened = 0;
4744 $outstandingTotal = 0;
4745 $outstandingTotalIncTax = 0;
4746 $arrayofref = array();
4747 $arrayofrefopened = array();
4748 if ($mode ==
'supplier') {
4749 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
4752 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
4755 while ($obj = $this->
db->fetch_object(
$resql)) {
4756 $arrayofref[$obj->rowid] = $obj->ref;
4757 $tmpobject->id = $obj->rowid;
4759 if ($obj->status != $tmpobject::STATUS_DRAFT
4760 && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code ==
'replaced')
4762 $outstandingTotal += $obj->total_ht;
4763 $outstandingTotalIncTax += $obj->total_ttc;
4769 && $obj->status != $tmpobject::STATUS_DRAFT
4770 && $obj->status != $tmpobject::STATUS_ABANDONED
4771 && $obj->status != $tmpobject::STATUS_CLOSED) {
4773 $paiement = $tmpobject->getSommePaiement();
4774 $creditnotes = $tmpobject->getSumCreditNotesUsed();
4775 $deposits = $tmpobject->getSumDepositsUsed();
4777 $remaintopay = ($obj->total_ttc - $paiement - $creditnotes - $deposits);
4778 $outstandingOpened += $remaintopay;
4784 $remainingcreditnote = $tmpobject->getSumFromThisCreditNotesNotUsed();
4785 $remaintopay -= $remainingcreditnote;
4786 $outstandingOpened -= $remainingcreditnote;
4790 $arrayofrefopened[$obj->rowid] = $obj->ref;
4793 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref,
'refsopened'=>$arrayofrefopened);
4795 dol_syslog(
"Sql error ".$this->
db->lasterror, LOG_ERR);
4822 $langs->load(
'companies');
4825 return $langs->trans(
"NorProspectNorCustomer");
4826 } elseif ($status == 1) {
4827 return $langs->trans(
"Customer");
4828 } elseif ($status == 2) {
4829 return $langs->trans(
"Prospect");
4830 } elseif ($status == 3) {
4831 return $langs->trans(
"ProspectCustomer");
4847 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4849 global $conf, $user, $langs;
4851 if (!empty($moreparams) && !empty($moreparams[
'use_companybankid'])) {
4852 $modelpath =
"core/modules/bank/doc/";
4854 include_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
4856 $result = $companybankaccount->fetch($moreparams[
'use_companybankid']);
4858 dol_print_error($this->
db, $companybankaccount->error, $companybankaccount->errors);
4860 $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4864 if (!empty($conf->global->COMPANY_ADDON_PDF)) {
4865 $modele = $conf->global->COMPANY_ADDON_PDF;
4867 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_COMPANY_ADDON_PDF_NotDefined");
4872 if (!isset($this->bank_account)) {
4873 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
4875 $result = $bac->fetch(0, $this->
id);
4877 $this->bank_account = $bac;
4879 $this->bank_account =
'';
4883 $modelpath =
"core/modules/societe/doc/";
4885 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4905 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4908 if (!in_array($type_categ, array(Categorie::TYPE_CUSTOMER, Categorie::TYPE_SUPPLIER))) {
4909 dol_syslog(__METHOD__.
': Type '.$type_categ.
'is an unknown company category type. Done nothing.', LOG_ERR);
4913 return parent::setCategoriesCommon($categories, $type_categ);
4928 if (!is_array($salesrep)) {
4929 $salesrep = array($salesrep);
4933 $to_add = $salesrep;
4934 if ($onlyAdd ===
false) {
4939 if (is_array($existing)) {
4940 $to_del = array_diff($existing, $salesrep);
4941 $to_add = array_diff($salesrep, $existing);
4948 foreach ($to_del as $del) {
4951 foreach ($to_add as $add) {
4959 return $error ? -1 : 1;
4975 $result = $this->
setValueFrom(
'fk_typent', $typent_id,
'',
null,
'',
'', $user,
'COMPANY_MODIFY');
4978 $this->typent_id = $typent_id;
4979 $this->typent_code =
dol_getIdFromCode($this->
db, $this->typent_id,
'c_typent',
'id',
'code');
5000 if ($origin_id == $dest_id) {
5001 dol_syslog(
'Error: Try to merge a thirdparty into itself');
5009 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5010 $sql .=
' WHERE fk_soc = '.(int) $dest_id.
' AND fk_user IN ( ';
5011 $sql .=
' SELECT fk_user ';
5012 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5013 $sql .=
' WHERE fk_soc = '.(int) $origin_id.
') ';
5017 $dbs->
query(
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_commerciaux WHERE rowid = '.((
int) $obj->rowid));
5026 'societe_commerciaux',
5029 'societe_remise_except',
5046 global $user, $langs, $conf;
5050 $field =
'accountancy_code_sell';
5051 if ($type ==
'buy') {
5052 $field =
'accountancy_code_buy';
5053 } elseif ($type ==
'sell') {
5054 $field =
'accountancy_code_sell';
5059 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ";
5060 $sql .= $field.
" = '".$this->
db->escape($value).
"'";
5061 $sql .=
" WHERE rowid = ".((int) $this->
id);
5063 dol_syslog(get_class($this).
"::".__FUNCTION__.
"", LOG_DEBUG);
5068 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
5070 $result = $interface->run_triggers(
'COMPANY_MODIFY', $this, $user, $langs, $conf);
5072 $this->errors = $interface->errors;
5073 $this->
db->rollback();
5078 $this->$field = $value;
5080 $this->
db->commit();
5083 $this->error = $this->
db->lasterror();
5084 $this->
db->rollback();
5099 require_once DOL_DOCUMENT_ROOT.
'/partnership/class/partnership.class.php';
5102 $this->partnerships[] = array();