40 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
55 public $element =
'societe';
60 public $table_element =
'societe';
65 public $fk_element =
'fk_soc';
70 public $fieldsforcombobox =
'nom,name_alias';
75 protected $childtables = array(
76 'supplier_proposal' => array(
'name' =>
'SupplierProposal'),
77 'propal' => array(
'name' =>
'Proposal'),
78 'commande' => array(
'name' =>
'Order'),
79 'facture' => array(
'name' =>
'Invoice'),
80 'facture_rec' => array(
'name' =>
'RecurringInvoiceTemplate'),
81 'contrat' => array(
'name' =>
'Contract'),
82 'fichinter' => array(
'name' =>
'Fichinter'),
83 'facture_fourn' => array(
'name' =>
'SupplierInvoice'),
84 'commande_fournisseur' => array(
'name' =>
'SupplierOrder'),
85 'projet' => array(
'name' =>
'Project'),
86 'expedition' => array(
'name' =>
'Shipment'),
87 'prelevement_lignes' => array(
'name' =>
'DirectDebitRecord'),
94 protected $childtablesoncascade = array(
97 'product_fournisseur_price',
98 'product_customer_price_log',
99 'product_customer_price',
100 '@Contact:/contact/class/contact.class.php:fk_soc',
105 'societe_remise_except',
106 'societe_commerciaux',
116 public $picto =
'company';
122 public $ismultientitymanaged = 1;
128 public $restrictiononfksoc = 1;
160 public $fields = array(
161 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
162 'parent' =>array(
'type'=>
'integer',
'label'=>
'Parent',
'enabled'=>1,
'visible'=>-1,
'position'=>20),
163 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
164 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
165 'nom' =>array(
'type'=>
'varchar(128)',
'label'=>
'Nom',
'enabled'=>1,
'visible'=>-1,
'position'=>35,
'showoncombobox'=>1),
166 'name_alias' =>array(
'type'=>
'varchar(128)',
'label'=>
'Name alias',
'enabled'=>1,
'visible'=>-1,
'position'=>36,
'showoncombobox'=>2),
167 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>40,
'index'=>1),
168 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefExt',
'enabled'=>1,
'visible'=>0,
'position'=>45),
169 'code_client' =>array(
'type'=>
'varchar(24)',
'label'=>
'CustomerCode',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
170 'code_fournisseur' =>array(
'type'=>
'varchar(24)',
'label'=>
'SupplierCode',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
171 'code_compta' =>array(
'type'=>
'varchar(24)',
'label'=>
'CodeCompta',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
172 'code_compta_fournisseur' =>array(
'type'=>
'varchar(24)',
'label'=>
'CodeComptaSupplier',
'enabled'=>1,
'visible'=>-1,
'position'=>70),
173 'address' =>array(
'type'=>
'varchar(255)',
'label'=>
'Address',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
174 'zip' =>array(
'type'=>
'varchar(25)',
'label'=>
'Zip',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
175 'town' =>array(
'type'=>
'varchar(50)',
'label'=>
'Town',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
176 'fk_departement' =>array(
'type'=>
'integer',
'label'=>
'State',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
177 'fk_pays' =>array(
'type'=>
'integer:Ccountry:core/class/ccountry.class.php',
'label'=>
'Country',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
178 'phone' =>array(
'type'=>
'varchar(20)',
'label'=>
'Phone',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
179 'fax' =>array(
'type'=>
'varchar(20)',
'label'=>
'Fax',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
180 'url' =>array(
'type'=>
'varchar(255)',
'label'=>
'Url',
'enabled'=>1,
'visible'=>-1,
'position'=>110),
181 'email' =>array(
'type'=>
'varchar(128)',
'label'=>
'Email',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
182 'socialnetworks' =>array(
'type'=>
'text',
'label'=>
'Socialnetworks',
'enabled'=>1,
'visible'=>-1,
'position'=>120),
183 'fk_effectif' =>array(
'type'=>
'integer',
'label'=>
'Workforce',
'enabled'=>1,
'visible'=>-1,
'position'=>170),
184 'fk_typent' =>array(
'type'=>
'integer',
'label'=>
'TypeOfCompany',
'enabled'=>1,
'visible'=>-1,
'position'=>175,
'csslist'=>
'minwidth200'),
185 'fk_forme_juridique' =>array(
'type'=>
'integer',
'label'=>
'JuridicalStatus',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
186 'fk_currency' =>array(
'type'=>
'varchar(3)',
'label'=>
'Currency',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
187 'siren' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof1',
'enabled'=>1,
'visible'=>-1,
'position'=>190),
188 'siret' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof2',
'enabled'=>1,
'visible'=>-1,
'position'=>195),
189 'ape' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof3',
'enabled'=>1,
'visible'=>-1,
'position'=>200),
190 'idprof4' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof4',
'enabled'=>1,
'visible'=>-1,
'position'=>205),
191 'idprof5' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof5',
'enabled'=>1,
'visible'=>-1,
'position'=>206),
192 'idprof6' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof6',
'enabled'=>1,
'visible'=>-1,
'position'=>207),
193 'tva_intra' =>array(
'type'=>
'varchar(20)',
'label'=>
'Tva intra',
'enabled'=>1,
'visible'=>-1,
'position'=>210),
194 'capital' =>array(
'type'=>
'double(24,8)',
'label'=>
'Capital',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
195 'fk_stcomm' =>array(
'type'=>
'integer',
'label'=>
'CommercialStatus',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>220),
196 'note_public' =>array(
'type'=>
'text',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>225),
197 'note_private' =>array(
'type'=>
'text',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>230),
198 'prefix_comm' =>array(
'type'=>
'varchar(5)',
'label'=>
'Prefix comm',
'enabled'=>
'$conf->global->SOCIETE_USEPREFIX',
'visible'=>-1,
'position'=>235),
199 'client' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Client',
'enabled'=>1,
'visible'=>-1,
'position'=>240),
200 'fournisseur' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Fournisseur',
'enabled'=>1,
'visible'=>-1,
'position'=>245),
201 'supplier_account' =>array(
'type'=>
'varchar(32)',
'label'=>
'Supplier account',
'enabled'=>1,
'visible'=>-1,
'position'=>250),
202 'fk_prospectlevel' =>array(
'type'=>
'varchar(12)',
'label'=>
'ProspectLevel',
'enabled'=>1,
'visible'=>-1,
'position'=>255),
203 'customer_bad' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Customer bad',
'enabled'=>1,
'visible'=>-1,
'position'=>260),
204 'customer_rate' =>array(
'type'=>
'double',
'label'=>
'Customer rate',
'enabled'=>1,
'visible'=>-1,
'position'=>265),
205 'supplier_rate' =>array(
'type'=>
'double',
'label'=>
'Supplier rate',
'enabled'=>1,
'visible'=>-1,
'position'=>270),
206 'fk_user_creat' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-2,
'position'=>275),
207 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>280),
210 'mode_reglement' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Mode reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>295),
211 'cond_reglement' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Cond reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>300),
212 'deposit_percent' =>array(
'type'=>
'varchar(63)',
'label'=>
'DepositPercent',
'enabled'=>1,
'visible'=>-1,
'position'=>301),
213 'mode_reglement_supplier' =>array(
'type'=>
'integer',
'label'=>
'Mode reglement supplier',
'enabled'=>1,
'visible'=>-1,
'position'=>305),
214 'cond_reglement_supplier' =>array(
'type'=>
'integer',
'label'=>
'Cond reglement supplier',
'enabled'=>1,
'visible'=>-1,
'position'=>308),
215 'outstanding_limit' =>array(
'type'=>
'double(24,8)',
'label'=>
'OutstandingBill',
'enabled'=>1,
'visible'=>-1,
'position'=>310,
'isameasure'=>1),
216 'order_min_amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'Order min amount',
'enabled'=>
'!empty($conf->commande->enabled) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)',
'visible'=>-1,
'position'=>315,
'isameasure'=>1),
217 'supplier_order_min_amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'Supplier order min amount',
'enabled'=>
'!empty($conf->commande->enabled) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)',
'visible'=>-1,
'position'=>320,
'isameasure'=>1),
218 'fk_shipping_method' =>array(
'type'=>
'integer',
'label'=>
'Fk shipping method',
'enabled'=>1,
'visible'=>-1,
'position'=>330),
219 'tva_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Tva assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>335),
220 'localtax1_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Localtax1 assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>340),
221 'localtax1_value' =>array(
'type'=>
'double(6,3)',
'label'=>
'Localtax1 value',
'enabled'=>1,
'visible'=>-1,
'position'=>345),
222 'localtax2_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Localtax2 assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>350),
223 'localtax2_value' =>array(
'type'=>
'double(6,3)',
'label'=>
'Localtax2 value',
'enabled'=>1,
'visible'=>-1,
'position'=>355),
224 'barcode' =>array(
'type'=>
'varchar(255)',
'label'=>
'Barcode',
'enabled'=>1,
'visible'=>-1,
'position'=>360),
225 '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),
226 'default_lang' =>array(
'type'=>
'varchar(6)',
'label'=>
'Default lang',
'enabled'=>1,
'visible'=>-1,
'position'=>370),
227 'canvas' =>array(
'type'=>
'varchar(32)',
'label'=>
'Canvas',
'enabled'=>1,
'visible'=>-1,
'position'=>375),
228 'fk_barcode_type' =>array(
'type'=>
'integer',
'label'=>
'Fk barcode type',
'enabled'=>1,
'visible'=>-1,
'position'=>405),
229 'webservices_url' =>array(
'type'=>
'varchar(255)',
'label'=>
'Webservices url',
'enabled'=>1,
'visible'=>-1,
'position'=>410),
230 'webservices_key' =>array(
'type'=>
'varchar(128)',
'label'=>
'Webservices key',
'enabled'=>1,
'visible'=>-1,
'position'=>415),
231 'fk_incoterms' =>array(
'type'=>
'integer',
'label'=>
'Fk incoterms',
'enabled'=>1,
'visible'=>-1,
'position'=>425),
232 'location_incoterms' =>array(
'type'=>
'varchar(255)',
'label'=>
'Location incoterms',
'enabled'=>1,
'visible'=>-1,
'position'=>430),
233 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>435),
234 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>-1,
'position'=>440),
235 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Multicurrency code',
'enabled'=>1,
'visible'=>-1,
'position'=>445),
236 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'AccountingAccount',
'enabled'=>1,
'visible'=>-1,
'position'=>450),
237 'fk_warehouse' =>array(
'type'=>
'integer',
'label'=>
'Warehouse',
'enabled'=>1,
'visible'=>-1,
'position'=>455),
238 'logo' =>array(
'type'=>
'varchar(255)',
'label'=>
'Logo',
'enabled'=>1,
'visible'=>-1,
'position'=>400),
239 'logo_squarred' =>array(
'type'=>
'varchar(255)',
'label'=>
'Logo squarred',
'enabled'=>1,
'visible'=>-1,
'position'=>401),
240 'status' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>-1,
'position'=>500),
241 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000),
326 public $departement_code;
361 public $socialnetworks;
471 public $tva_assuj = 1;
480 public $localtax1_assuj;
481 public $localtax1_value;
482 public $localtax2_assuj;
483 public $localtax2_value;
498 public $typent_id = 0;
501 public $effectif_id = 0;
502 public $forme_juridique_code;
503 public $forme_juridique = 0;
505 public $remise_percent;
506 public $remise_supplier_percent;
508 public $mode_reglement_id;
509 public $cond_reglement_id;
510 public $deposit_percent;
511 public $mode_reglement_supplier_id;
512 public $cond_reglement_supplier_id;
513 public $transport_mode_supplier_id;
518 public $fk_prospectlevel;
531 public $date_modification;
537 public $user_modification;
543 public $date_creation;
549 public $user_creation;
561 public $prospect = 0;
579 public $code_fournisseur;
585 public $code_compta_client;
598 public $accountancy_code_customer;
604 public $code_compta_fournisseur;
610 public $accountancy_code_supplier;
617 public $code_compta_product;
631 public $note_private;
649 public $stcomm_picto;
655 public $status_prospect_label;
666 public $outstanding_limit;
671 public $order_min_amount;
676 public $supplier_order_min_amount;
682 public $commercial_id;
694 public $default_lang;
726 public $webservices_url;
732 public $webservices_key;
752 public $logo_squarred;
757 public $logo_squarred_small;
762 public $logo_squarred_mini;
767 public $accountancy_code_sell;
772 public $accountancy_code_buy;
778 public $fk_multicurrency;
784 public $fk_warehouse;
789 public $multicurrency_code;
794 public $partnerships = array();
797 const STATUS_CEASED = 0;
798 const STATUS_INACTIVITY = 1;
804 public $bank_account;
849 $this->fournisseur = 0;
850 $this->typent_id = 0;
851 $this->effectif_id = 0;
852 $this->forme_juridique_code = 0;
853 $this->tva_assuj = 1;
856 if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
857 $this->fields[
'address'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
858 $this->fields[
'zip'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
859 $this->fields[
'town'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
874 global $langs, $conf, $mysoc;
879 if (empty($this->status)) {
882 $this->
name = $this->
name ?trim($this->
name) : trim($this->nom);
884 $this->nom = $this->name;
885 if (empty($this->client)) {
888 if (empty($this->fournisseur)) {
889 $this->fournisseur = 0;
891 $this->import_key = trim($this->import_key);
893 $this->accountancy_code_customer = trim($this->code_compta);
894 $this->accountancy_code_supplier = trim($this->code_compta_fournisseur);
895 $this->accountancy_code_buy = trim($this->accountancy_code_buy);
896 $this->accountancy_code_sell = trim($this->accountancy_code_sell);
898 if (!empty($this->multicurrency_code)) {
901 if (empty($this->fk_multicurrency)) {
902 $this->multicurrency_code =
'';
903 $this->fk_multicurrency = 0;
913 if ($this->code_client == -1 || $this->code_client ===
'auto') {
916 if ($this->code_fournisseur == -1 || $this->code_fournisseur ===
'auto') {
922 $result = $this->
verify();
925 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
927 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe (";
929 $sql .=
", name_alias";
932 $sql .=
", fk_user_creat";
933 $sql .=
", fk_typent";
937 $sql .=
", fk_stcomm";
938 $sql .=
", fk_incoterms";
939 $sql .=
", location_incoterms";
940 $sql .=
", import_key";
941 $sql .=
", fk_multicurrency";
942 $sql .=
", multicurrency_code";
943 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
944 $sql .=
", accountancy_code_buy";
945 $sql .=
", accountancy_code_sell";
947 $sql .=
") VALUES ('".$this->db->escape($this->name).
"', '".$this->
db->escape($this->name_alias).
"', ".((int) $this->entity).
", '".$this->
db->idate($now).
"'";
948 $sql .=
", ".(!empty($user->id) ? ((int) $user->id) :
"null");
949 $sql .=
", ".(!empty($this->typent_id) ? ((int) $this->typent_id) :
"null");
950 $sql .=
", ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null");
951 $sql .=
", ".((int) $this->status);
952 $sql .=
", ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
954 $sql .=
", ".(int) $this->fk_incoterms;
955 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
956 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
957 $sql .=
", ".(int) $this->fk_multicurrency;
958 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
959 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
960 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
961 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
965 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
966 $result = $this->
db->query($sql);
968 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"societe");
970 $ret = $this->
update($this->
id, $user, 0, 1, 1,
'add');
973 if (!$error && !empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
974 $this->
db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int) $conf->entity));
976 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
979 $sql .=
", accountancy_code_customer";
980 $sql .=
", accountancy_code_supplier";
981 $sql .=
", accountancy_code_buy";
982 $sql .=
", accountancy_code_sell";
983 $sql .=
") VALUES (";
985 $sql .=
", ".((int) $conf->entity);
986 $sql .=
", '".$this->db->escape($this->accountancy_code_customer).
"'";
987 $sql .=
", '".$this->db->escape($this->accountancy_code_supplier).
"'";
988 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
989 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
991 $result = $this->
db->query($sql);
994 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
999 if ($this->commercial_id !=
'' && $this->commercial_id != -1) {
1001 } elseif (empty($user->rights->societe->client->voir)) {
1008 $result = $this->
call_trigger(
'COMPANY_CREATE', $user);
1018 dol_syslog(get_class($this).
"::Create success id=".$this->
id);
1019 $this->
db->commit();
1022 dol_syslog(get_class($this).
"::Create echec update ".$this->error.(empty($this->errors) ?
'' :
' '.join(
',', $this->errors)), LOG_ERR);
1023 $this->
db->rollback();
1027 if ($this->
db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1028 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", $this->name);
1031 $this->error = $this->
db->lasterror();
1034 $this->
db->rollback();
1038 $this->
db->rollback();
1039 dol_syslog(get_class($this).
"::Create fails verify ".join(
',', $this->errors), LOG_WARNING);
1063 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1066 $contact->name = $this->name_bis;
1067 $contact->firstname = $this->firstname;
1068 $contact->civility_id = $this->civility_id;
1069 $contact->socid = $this->id;
1070 $contact->statut = 1;
1071 $contact->status = 1;
1073 $contact->country_id = $this->country_id;
1074 $contact->state_id = $this->state_id;
1075 $contact->address = $this->address;
1076 $contact->email = $this->email;
1077 $contact->zip = $this->zip;
1078 $contact->town = $this->town;
1080 $contact->phone_pro = $this->phone;
1082 $contactId = $contact->create($user);
1083 if ($contactId < 0) {
1085 $this->error = $contact->error;
1086 $this->errors = $contact->errors;
1087 dol_syslog(get_class($this).
"::create_individual ERROR:".$this->error, LOG_ERR);
1090 if (empty($error) && is_array($tags) && !empty($tags)) {
1091 $result = $contact->setCategories($tags);
1094 $this->error = $contact->error;
1095 $this->errors = array_merge($this->errors, $contact->errors);
1096 dol_syslog(get_class($this).
"::create_individual Affect Tag ERROR:".$this->error, LOG_ERR);
1097 $contactId = $result;
1101 if (empty($error) && !empty($conf->mailing->enabled) && !empty($contact->email) && isset($no_email)) {
1102 $result = $contact->setNoEmail($no_email);
1104 $this->error = $contact->error;
1105 $this->errors = array_merge($this->errors, $contact->errors);
1106 dol_syslog(get_class($this).
"::create_individual set mailing status ERROR:".$this->error, LOG_ERR);
1107 $contactId = $result;
1111 if (empty($error)) {
1112 dol_syslog(get_class($this).
"::create_individual success");
1113 $this->
db->commit();
1115 $this->
db->rollback();
1129 global $conf, $langs, $mysoc;
1132 $this->errors = array();
1136 $this->nom = $this->name;
1139 $this->errors[] =
'ErrorBadThirdPartyName';
1143 if ($this->client) {
1145 if ($rescode != 0 && $rescode != -5) {
1146 if ($rescode == -1) {
1147 $this->errors[] =
'ErrorBadCustomerCodeSyntax';
1148 } elseif ($rescode == -2) {
1149 $this->errors[] =
'ErrorCustomerCodeRequired';
1150 } elseif ($rescode == -3) {
1151 $this->errors[] =
'ErrorCustomerCodeAlreadyUsed';
1152 } elseif ($rescode == -4) {
1153 $this->errors[] =
'ErrorPrefixRequired';
1155 $this->errors[] =
'ErrorUnknownOnCustomerCodeCheck';
1162 if ($this->fournisseur) {
1164 if ($rescode != 0 && $rescode != -5) {
1165 if ($rescode == -1) {
1166 $this->errors[] =
'ErrorBadSupplierCodeSyntax';
1167 } elseif ($rescode == -2) {
1168 $this->errors[] =
'ErrorSupplierCodeRequired';
1169 } elseif ($rescode == -3) {
1170 $this->errors[] =
'ErrorSupplierCodeAlreadyUsed';
1171 } elseif ($rescode == -4) {
1172 $this->errors[] =
'ErrorPrefixRequired';
1174 $this->errors[] =
'ErrorUnknownOnSupplierCodeCheck';
1181 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL');
1182 foreach ($array_to_check as $key) {
1183 $keymin = strtolower($key);
1184 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
1185 $vallabel = $this->$keymin;
1190 if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) {
1191 $idprof_mandatory =
'SOCIETE_'.$key.
'_MANDATORY';
1192 if (!$vallabel && !empty($conf->global->$idprof_mandatory)) {
1193 $langs->load(
"errors");
1195 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->transcountry(
'ProfId'.$i, $this->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1202 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1203 $langs->load(
"errors");
1205 $this->errors[] = $langs->transcountry(
'ProfId'.$i, $this->country_code).
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1211 if ($key ==
'EMAIL') {
1213 if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email)) {
1214 $langs->load(
"errors");
1216 $this->errors[] = $langs->trans(
"ErrorBadEMail", $this->email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1220 if (!$error && $vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE)) {
1221 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1222 $langs->load(
"errors");
1223 $error++; $this->errors[] = $langs->trans(
'Email').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1249 public function update($id, $user =
'', $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action =
'update', $nosyncmember = 1)
1251 global $langs, $conf, $hookmanager;
1253 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1261 dol_syslog(get_class($this).
"::Update id=".$id.
" call_trigger=".$call_trigger.
" allowmodcodeclient=".$allowmodcodeclient.
" allowmodcodefournisseur=".$allowmodcodefournisseur);
1267 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
1268 $this->
name = $this->
name ?trim($this->
name) : trim($this->nom);
1269 $this->nom = $this->name;
1270 $this->name_alias = trim($this->name_alias);
1271 $this->ref_ext = trim($this->ref_ext);
1272 $this->address = $this->address ?trim($this->address) : trim($this->address);
1273 $this->zip = $this->zip ?trim($this->zip) : trim($this->zip);
1274 $this->town = $this->town ?trim($this->town) : trim($this->town);
1276 $this->state_id = trim($this->state_id);
1277 $this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
1278 $this->phone = trim($this->phone);
1279 $this->phone = preg_replace(
"/\s/",
"", $this->phone);
1280 $this->phone = preg_replace(
"/\./",
"", $this->phone);
1281 $this->fax = trim($this->fax);
1282 $this->fax = preg_replace(
"/\s/",
"", $this->fax);
1283 $this->fax = preg_replace(
"/\./",
"", $this->fax);
1284 $this->email = trim($this->email);
1285 $this->url = $this->url ?
clean_url($this->url, 0) :
'';
1286 $this->note_private = trim($this->note_private);
1287 $this->note_public = trim($this->note_public);
1288 $this->idprof1 = trim($this->idprof1);
1289 $this->idprof2 = trim($this->idprof2);
1290 $this->idprof3 = trim($this->idprof3);
1291 $this->idprof4 = trim($this->idprof4);
1292 $this->idprof5 = (!empty($this->idprof5) ?trim($this->idprof5) :
'');
1293 $this->idprof6 = (!empty($this->idprof6) ?trim($this->idprof6) :
'');
1294 $this->prefix_comm = trim($this->prefix_comm);
1295 $this->outstanding_limit =
price2num($this->outstanding_limit);
1296 $this->order_min_amount =
price2num($this->order_min_amount);
1297 $this->supplier_order_min_amount =
price2num($this->supplier_order_min_amount);
1299 $this->tva_assuj = trim($this->tva_assuj);
1301 if (empty($this->status)) {
1305 if (!empty($this->multicurrency_code)) {
1308 if (empty($this->fk_multicurrency)) {
1309 $this->multicurrency_code =
'';
1310 $this->fk_multicurrency = 0;
1314 $this->localtax1_assuj = trim($this->localtax1_assuj);
1315 $this->localtax2_assuj = trim($this->localtax2_assuj);
1317 $this->localtax1_value = trim($this->localtax1_value);
1318 $this->localtax2_value = trim($this->localtax2_value);
1320 if ($this->capital !=
'') {
1321 $this->capital =
price2num(trim($this->capital));
1323 if (!is_numeric($this->capital)) {
1324 $this->capital =
'';
1327 $this->effectif_id = trim($this->effectif_id);
1328 $this->forme_juridique_code = trim($this->forme_juridique_code);
1331 $this->barcode = trim($this->barcode);
1334 if ($this->code_client == -1 || $this->code_client ===
'auto') {
1337 if ($this->code_fournisseur == -1 || $this->code_fournisseur ===
'auto') {
1341 $this->code_compta_client = trim(empty($this->code_compta) ? $this->code_compta_client : $this->code_compta);
1342 $this->code_compta = $this->code_compta_client;
1343 $this->code_compta_fournisseur = trim($this->code_compta_fournisseur);
1346 if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) {
1347 $langs->load(
"errors");
1348 $this->error = $langs->trans(
"BadValueForParameterClientOrSupplier");
1353 if (!empty($allowmodcodeclient) && !empty($this->client)) {
1355 if (empty($this->code_compta_client)) {
1366 if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) {
1368 if (empty($this->code_compta_fournisseur)) {
1379 $this->webservices_url = $this->webservices_url ?
clean_url($this->webservices_url, 0) :
'';
1380 $this->webservices_key = trim($this->webservices_key);
1382 $this->accountancy_code_buy = trim($this->accountancy_code_buy);
1383 $this->accountancy_code_sell = trim($this->accountancy_code_sell);
1386 $this->fk_incoterms = (int) $this->fk_incoterms;
1387 $this->location_incoterms = trim($this->location_incoterms);
1394 if ($action !=
'add' && $action !=
'merge') {
1397 $result = $this->
verify();
1401 if (is_array($this->errors)) {
1402 if (in_array(
'ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) {
1403 if (($key = array_search(
'ErrorBadCustomerCodeSyntax', $this->errors)) !==
false) {
1404 unset($this->errors[$key]);
1407 if (in_array(
'ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) {
1408 if (($key = array_search(
'ErrorBadSupplierCodeSyntax', $this->errors)) !==
false) {
1409 unset($this->errors[$key]);
1412 if (empty($this->errors)) {
1419 dol_syslog(get_class($this).
"::update verify ok or not done");
1421 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe SET ";
1422 $sql .=
"entity = ".$this->db->escape($this->entity);
1423 $sql .=
",nom = '".$this->db->escape($this->
name).
"'";
1424 $sql .=
",name_alias = '".$this->db->escape($this->name_alias).
"'";
1425 $sql .=
",ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1426 $sql .=
",address = '".$this->db->escape($this->address).
"'";
1428 $sql .=
",zip = ".(!empty($this->zip) ?
"'".$this->db->escape($this->zip).
"'" :
"null");
1429 $sql .=
",town = ".(!empty($this->town) ?
"'".$this->db->escape($this->town).
"'" :
"null");
1431 $sql .=
",fk_departement = ".((!empty($this->state_id) && $this->state_id > 0) ? ((
int) $this->state_id) :
'null');
1432 $sql .=
",fk_pays = ".((!empty($this->country_id) && $this->country_id > 0) ? ((
int) $this->country_id) :
'null');
1434 $sql .=
",phone = ".(!empty($this->phone) ?
"'".$this->db->escape($this->phone).
"'" :
"null");
1435 $sql .=
",fax = ".(!empty($this->fax) ?
"'".$this->db->escape($this->fax).
"'" :
"null");
1436 $sql .=
",email = ".(!empty($this->email) ?
"'".$this->db->escape($this->email).
"'" :
"null");
1437 $sql .=
",socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1438 $sql .=
",url = ".(!empty($this->url) ?
"'".$this->db->escape($this->url).
"'" :
"null");
1440 $sql .=
",parent = ".($this->parent > 0 ? $this->parent :
"null");
1442 $sql .=
",note_private = ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
1443 $sql .=
",note_public = ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
1445 $sql .=
",siren = '".$this->db->escape($this->idprof1).
"'";
1446 $sql .=
",siret = '".$this->db->escape($this->idprof2).
"'";
1447 $sql .=
",ape = '".$this->db->escape($this->idprof3).
"'";
1448 $sql .=
",idprof4 = '".$this->db->escape($this->idprof4).
"'";
1449 $sql .=
",idprof5 = '".$this->db->escape($this->idprof5).
"'";
1450 $sql .=
",idprof6 = '".$this->db->escape($this->idprof6).
"'";
1452 $sql .=
",tva_assuj = ".($this->tva_assuj !=
'' ?
"'".$this->db->escape($this->tva_assuj).
"'" :
"null");
1453 $sql .=
",tva_intra = '".$this->db->escape($this->tva_intra).
"'";
1454 $sql .=
",status = ".((int) $this->status);
1457 $sql .=
",localtax1_assuj = ".($this->localtax1_assuj !=
'' ?
"'".$this->db->escape($this->localtax1_assuj).
"'" :
"null");
1458 $sql .=
",localtax2_assuj = ".($this->localtax2_assuj !=
'' ?
"'".$this->db->escape($this->localtax2_assuj).
"'" :
"null");
1459 if ($this->localtax1_assuj == 1) {
1460 if ($this->localtax1_value !=
'') {
1461 $sql .=
",localtax1_value =".$this->localtax1_value;
1463 $sql .=
",localtax1_value =0.000";
1466 $sql .=
",localtax1_value =0.000";
1469 if ($this->localtax2_assuj == 1) {
1470 if ($this->localtax2_value !=
'') {
1471 $sql .=
",localtax2_value =".$this->localtax2_value;
1473 $sql .=
",localtax2_value =0.000";
1476 $sql .=
",localtax2_value =0.000";
1479 $sql .=
",capital = ".($this->capital ==
'' ?
"null" : $this->capital);
1481 $sql .=
",prefix_comm = ".(!empty($this->prefix_comm) ?
"'".$this->db->escape($this->prefix_comm).
"'" :
"null");
1483 $sql .=
",fk_effectif = ".($this->effectif_id > 0 ? ((int) $this->effectif_id) :
"null");
1484 if (isset($this->stcomm_id)) {
1485 $sql .=
",fk_stcomm=".(int) $this->stcomm_id;
1487 if (isset($this->typent_id)) {
1488 $sql .=
",fk_typent = ".($this->typent_id > 0 ? ((int) $this->typent_id) :
"0");
1491 $sql .=
",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ?
"'".$this->db->escape($this->forme_juridique_code).
"'" :
"null");
1493 $sql .=
",mode_reglement = ".(!empty($this->mode_reglement_id) ?
"'".$this->db->escape($this->mode_reglement_id).
"'" :
"null");
1494 $sql .=
",cond_reglement = ".(!empty($this->cond_reglement_id) ?
"'".$this->db->escape($this->cond_reglement_id).
"'" :
"null");
1495 $sql .=
",deposit_percent = ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null");
1496 $sql .=
",transport_mode = ".(!empty($this->transport_mode_id) ?
"'".$this->db->escape($this->transport_mode_id).
"'" :
"null");
1497 $sql .=
",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ?
"'".$this->db->escape($this->mode_reglement_supplier_id).
"'" :
"null");
1498 $sql .=
",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ?
"'".$this->db->escape($this->cond_reglement_supplier_id).
"'" :
"null");
1499 $sql .=
",transport_mode_supplier = ".(!empty($this->transport_mode_supplier_id) ?
"'".$this->db->escape($this->transport_mode_supplier_id).
"'" :
"null");
1500 $sql .=
",fk_shipping_method = ".(!empty($this->shipping_method_id) ?
"'".$this->db->escape($this->shipping_method_id).
"'" :
"null");
1502 $sql .=
",client = ".(!empty($this->client) ? $this->client : 0);
1503 $sql .=
",fournisseur = ".(!empty($this->fournisseur) ? $this->fournisseur : 0);
1504 $sql .=
",barcode = ".(!empty($this->barcode) ?
"'".$this->db->escape($this->barcode).
"'" :
"null");
1505 $sql .=
",default_lang = ".(!empty($this->default_lang) ?
"'".$this->db->escape($this->default_lang).
"'" :
"null");
1506 $sql .=
",logo = ".(!empty($this->logo) ?
"'".$this->db->escape($this->logo).
"'" :
"null");
1507 $sql .=
",logo_squarred = ".(!empty($this->logo_squarred) ?
"'".$this->db->escape($this->logo_squarred).
"'" :
"null");
1508 $sql .=
",outstanding_limit= ".($this->outstanding_limit !=
'' ? $this->outstanding_limit :
'null');
1509 $sql .=
",order_min_amount= ".($this->order_min_amount !=
'' ? $this->order_min_amount :
'null');
1510 $sql .=
",supplier_order_min_amount= ".($this->supplier_order_min_amount !=
'' ? $this->supplier_order_min_amount :
'null');
1511 $sql .=
",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel).
"'";
1512 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1513 $sql .=
", accountancy_code_buy = '".$this->db->escape($this->accountancy_code_buy).
"'";
1514 $sql .=
", accountancy_code_sell= '".$this->db->escape($this->accountancy_code_sell).
"'";
1517 $sql .=
", code_compta = ".(!empty($this->code_compta_client) ?
"'".$this->db->escape($this->code_compta_client).
"'" :
"null");
1521 $sql .=
", code_compta_fournisseur = ".(($this->code_compta_fournisseur !=
"") ?
"'".$this->
db->escape($this->code_compta_fournisseur).
"'" :
"null");
1524 $sql .=
",webservices_url = ".(!empty($this->webservices_url) ?
"'".$this->db->escape($this->webservices_url).
"'" :
"null");
1525 $sql .=
",webservices_key = ".(!empty($this->webservices_key) ?
"'".$this->db->escape($this->webservices_key).
"'" :
"null");
1528 $sql .=
", fk_incoterms = ".((int) $this->fk_incoterms);
1529 $sql .=
", location_incoterms = ".(!empty($this->location_incoterms) ?
"'".$this->db->escape($this->location_incoterms).
"'" :
"null");
1532 $sql .=
", code_client = ".(!empty($this->code_client) ?
"'".$this->db->escape($this->code_client).
"'" :
"null");
1536 $sql .=
", code_fournisseur = ".(!empty($this->code_fournisseur) ?
"'".$this->db->escape($this->code_fournisseur).
"'" :
"null");
1538 $sql .=
", fk_user_modif = ".($user->id > 0 ? $user->id :
"null");
1539 $sql .=
", fk_multicurrency = ".(int) $this->fk_multicurrency;
1540 $sql .=
", multicurrency_code = '".$this->db->escape($this->multicurrency_code).
"'";
1541 $sql .=
", model_pdf = '".$this->db->escape($this->model_pdf).
"'";
1542 $sql .=
" WHERE rowid = ".(int) $id;
1546 if (is_object($this->oldcopy)) {
1547 if ($this->oldcopy->country_id != $this->country_id) {
1548 unset($this->country_code);
1549 unset($this->country);
1551 if ($this->oldcopy->state_id != $this->state_id) {
1552 unset($this->state_code);
1553 unset($this->state);
1556 unset($this->country_code);
1557 unset($this->country);
1558 unset($this->state_code);
1559 unset($this->state);
1562 $nbrowsaffected = $this->
db->affected_rows(
$resql);
1564 if (!$error && $nbrowsaffected) {
1566 if (!$nosyncmember && !empty($conf->adherent->enabled)) {
1567 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1569 dol_syslog(get_class($this).
"::update update linked member");
1572 $result = $lmember->fetch(0, 0, $this->
id);
1575 $lmember->company = $this->name;
1578 $lmember->address = $this->address;
1579 $lmember->zip = $this->zip;
1580 $lmember->town = $this->town;
1581 $lmember->email = $this->email;
1582 $lmember->socialnetworks = $this->socialnetworks;
1583 $lmember->phone = $this->phone;
1584 $lmember->state_id = $this->state_id;
1585 $lmember->country_id = $this->country_id;
1587 $result = $lmember->update($user, 0, 1, 1, 1);
1589 $this->error = $lmember->error;
1590 $this->errors = array_merge($this->errors, $lmember->errors);
1591 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
1594 } elseif ($result < 0) {
1595 $this->error = $lmember->error;
1604 if (!$error && !empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1605 $this->
db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int) $conf->entity));
1607 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
1610 $sql .=
", accountancy_code_customer";
1611 $sql .=
", accountancy_code_supplier";
1612 $sql .=
", accountancy_code_buy";
1613 $sql .=
", accountancy_code_sell";
1614 $sql .=
") VALUES (";
1616 $sql .=
", ".$conf->entity;
1617 $sql .=
", '".$this->db->escape($this->code_compta_client).
"'";
1618 $sql .=
", '".$this->db->escape($this->code_compta_fournisseur).
"'";
1619 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1620 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1622 $result = $this->
db->query($sql);
1625 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1637 if (!$error && empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) {
1644 if (!$error && $call_trigger) {
1646 $result = $this->
call_trigger(
'COMPANY_MODIFY', $user);
1654 dol_syslog(get_class($this).
"::Update success");
1655 $this->
db->commit();
1658 $this->
db->rollback();
1662 if ($this->
db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1664 $this->error = $langs->trans(
"ErrorDuplicateField");
1667 $this->error = $this->
db->lasterror();
1670 $this->
db->rollback();
1674 $this->
db->rollback();
1675 dol_syslog(get_class($this).
"::Update fails verify ".join(
',', $this->errors), LOG_WARNING);
1697 public function fetch($rowid, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'')
1702 if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) {
1706 $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';
1707 $sql .=
', s.status, s.fk_warehouse';
1708 $sql .=
', s.price_level';
1709 $sql .=
', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif';
1710 $sql .=
', s.phone, s.fax, s.email';
1711 $sql .=
', s.socialnetworks';
1712 $sql .=
', s.url, s.zip, s.town, s.note_private, s.note_public, s.model_pdf, s.client, s.fournisseur';
1713 $sql .=
', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1714 $sql .=
', s.capital, s.tva_intra';
1715 $sql .=
', s.fk_typent as typent_id';
1716 $sql .=
', s.fk_effectif as effectif_id';
1717 $sql .=
', s.fk_forme_juridique as forme_juridique_code';
1718 $sql .=
', s.webservices_url, s.webservices_key, s.model_pdf';
1719 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1720 $sql .=
', s.code_compta, s.code_compta_fournisseur, s.accountancy_code_buy, s.accountancy_code_sell';
1722 $sql .=
', spe.accountancy_code_customer as code_compta, spe.accountancy_code_supplier as code_compta_fournisseur, spe.accountancy_code_buy, spe.accountancy_code_sell';
1724 $sql .=
', s.code_client, s.code_fournisseur, s.parent, s.barcode';
1725 $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';
1726 $sql .=
', s.fk_account, s.tva_assuj';
1727 $sql .=
', s.mode_reglement_supplier, s.cond_reglement_supplier, s.transport_mode_supplier';
1728 $sql .=
', s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred';
1729 $sql .=
', s.fk_shipping_method';
1730 $sql .=
', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1731 $sql .=
', s.order_min_amount, s.supplier_order_min_amount';
1732 $sql .=
', s.fk_multicurrency, s.multicurrency_code';
1733 $sql .=
', fj.libelle as forme_juridique';
1734 $sql .=
', e.libelle as effectif';
1735 $sql .=
', c.code as country_code, c.label as country';
1736 $sql .=
', d.code_departement as state_code, d.nom as state';
1737 $sql .=
', r.rowid as region_id, r.code_region as region_code';
1738 $sql .=
', st.libelle as stcomm, st.picto as stcomm_picto';
1739 $sql .=
', te.code as typent_code';
1740 $sql .=
', i.libelle as label_incoterms';
1741 if (empty($conf->multicompany->enabled)) {
1742 $sql .=
', s.remise_client, s.remise_supplier';
1744 $sql .=
', sr.remise_client, sr2.remise_supplier';
1746 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
1747 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1748 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = ".((int) $conf->entity);
1750 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_effectif as e ON s.fk_effectif = e.id';
1751 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON s.fk_pays = c.rowid';
1752 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcomm as st ON s.fk_stcomm = st.id';
1753 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
1754 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON s.fk_departement = d.rowid';
1755 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_regions as r ON d.fk_region = r.code_region ';
1756 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_typent as te ON s.fk_typent = te.id';
1757 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON s.fk_incoterms = i.rowid';
1760 if (!empty($conf->multicompany->enabled)) {
1761 $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').
'))';
1762 $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').
'))';
1764 $sql .=
' WHERE s.entity IN ('.getEntity($this->element).
')';
1766 $sql .=
' AND s.rowid = '.((int) $rowid);
1769 $sql .=
" AND s.nom = '".$this->db->escape($ref).
"'";
1772 $sql .=
" AND s.name_alias = '".$this->db->escape($ref_alias).
"'";
1775 $sql .=
" AND s.ref_ext = '".$this->db->escape($ref_ext).
"'";
1778 $sql .=
" AND s.barcode = '".$this->db->escape($barcode).
"'";
1781 $sql .=
" AND s.siren = '".$this->db->escape($idprof1).
"'";
1784 $sql .=
" AND s.siret = '".$this->db->escape($idprof2).
"'";
1787 $sql .=
" AND s.ape = '".$this->db->escape($idprof3).
"'";
1790 $sql .=
" AND s.idprof4 = '".$this->db->escape($idprof4).
"'";
1793 $sql .=
" AND s.idprof5 = '".$this->db->escape($idprof5).
"'";
1796 $sql .=
" AND s.idprof6 = '".$this->db->escape($idprof6).
"'";
1799 $sql .=
" AND s.email = '".$this->db->escape($email).
"'";
1804 $num = $this->
db->num_rows(
$resql);
1806 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
1810 $obj = $this->
db->fetch_object(
$resql);
1812 $this->
id = $obj->rowid;
1813 $this->entity = $obj->entity;
1814 $this->canvas = $obj->canvas;
1816 $this->
ref = $obj->rowid;
1817 $this->
name = $obj->name;
1818 $this->nom = $obj->name;
1819 $this->name_alias = $obj->name_alias;
1820 $this->ref_ext = $obj->ref_ext;
1822 $this->date_creation = $this->
db->jdate($obj->date_creation);
1823 $this->date_modification = $this->
db->jdate($obj->date_modification);
1824 $this->user_creation = $obj->fk_user_creat;
1825 $this->user_modification = $obj->fk_user_modif;
1827 $this->address = $obj->address;
1828 $this->zip = $obj->zip;
1829 $this->town = $obj->town;
1831 $this->country_id = $obj->country_id;
1832 $this->country_code = $obj->country_id ? $obj->country_code :
'';
1833 $this->country = $obj->country_id ? (($langs->transnoentities(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code) ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
1835 $this->state_id = $obj->state_id;
1836 $this->state_code = $obj->state_code;
1837 $this->region_id = $obj->region_id;
1838 $this->region_code = $obj->region_code;
1839 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
1841 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcomm);
1842 $label = ($transcode !=
'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm);
1843 $this->stcomm_id = $obj->fk_stcomm;
1844 $this->status_prospect_label = $label;
1845 $this->stcomm_picto = $obj->stcomm_picto;
1847 $this->email = $obj->email;
1848 $this->socialnetworks = (array) json_decode($obj->socialnetworks,
true);
1850 $this->url = $obj->url;
1851 $this->phone = $obj->phone;
1852 $this->fax = $obj->fax;
1854 $this->parent = $obj->parent;
1856 $this->idprof1 = $obj->idprof1;
1857 $this->idprof2 = $obj->idprof2;
1858 $this->idprof3 = $obj->idprof3;
1859 $this->idprof4 = $obj->idprof4;
1860 $this->idprof5 = $obj->idprof5;
1861 $this->idprof6 = $obj->idprof6;
1863 $this->capital = $obj->capital;
1865 $this->code_client = $obj->code_client;
1866 $this->code_fournisseur = $obj->code_fournisseur;
1868 $this->code_compta = $obj->code_compta;
1869 $this->code_compta_client = $obj->code_compta;
1870 $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
1872 $this->barcode = $obj->barcode;
1874 $this->tva_assuj = $obj->tva_assuj;
1875 $this->tva_intra = $obj->tva_intra;
1876 $this->status = $obj->status;
1879 $this->localtax1_assuj = $obj->localtax1_assuj;
1880 $this->localtax2_assuj = $obj->localtax2_assuj;
1882 $this->localtax1_value = $obj->localtax1_value;
1883 $this->localtax2_value = $obj->localtax2_value;
1885 $this->typent_id = $obj->typent_id;
1886 $this->typent_code = $obj->typent_code;
1888 $this->effectif_id = $obj->effectif_id;
1889 $this->effectif = $obj->effectif_id ? $obj->effectif :
'';
1891 $this->forme_juridique_code = $obj->forme_juridique_code;
1892 $this->forme_juridique = $obj->forme_juridique_code ? $obj->forme_juridique :
'';
1894 $this->fk_prospectlevel = $obj->fk_prospectlevel;
1896 $this->prefix_comm = $obj->prefix_comm;
1898 $this->remise_percent = $obj->remise_client ?
price2num($obj->remise_client) : 0;
1899 $this->remise_supplier_percent = $obj->remise_supplier;
1901 $this->mode_reglement_id = $obj->mode_reglement;
1902 $this->cond_reglement_id = $obj->cond_reglement;
1903 $this->deposit_percent = $obj->deposit_percent;
1904 $this->transport_mode_id = $obj->transport_mode;
1905 $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier;
1906 $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier;
1907 $this->transport_mode_supplier_id = $obj->transport_mode_supplier;
1908 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
1909 $this->fk_account = $obj->fk_account;
1911 $this->client = $obj->client;
1912 $this->fournisseur = $obj->fournisseur;
1914 $this->note = $obj->note_private;
1915 $this->note_private = $obj->note_private;
1916 $this->note_public = $obj->note_public;
1917 $this->model_pdf = $obj->model_pdf;
1918 $this->modelpdf = $obj->model_pdf;
1919 $this->default_lang = $obj->default_lang;
1920 $this->logo = $obj->logo;
1921 $this->logo_squarred = $obj->logo_squarred;
1923 $this->webservices_url = $obj->webservices_url;
1924 $this->webservices_key = $obj->webservices_key;
1926 $this->accountancy_code_buy = $obj->accountancy_code_buy;
1927 $this->accountancy_code_sell = $obj->accountancy_code_sell;
1929 $this->outstanding_limit = $obj->outstanding_limit;
1930 $this->order_min_amount = $obj->order_min_amount;
1931 $this->supplier_order_min_amount = $obj->supplier_order_min_amount;
1934 $this->price_level = $obj->price_level;
1937 $this->fk_warehouse = $obj->fk_warehouse;
1939 $this->import_key = $obj->import_key;
1942 $this->fk_incoterms = $obj->fk_incoterms;
1943 $this->location_incoterms = $obj->location_incoterms;
1944 $this->label_incoterms = $obj->label_incoterms;
1947 $this->fk_multicurrency = $obj->fk_multicurrency;
1948 $this->multicurrency_code = $obj->multicurrency_code;
1949 $this->model_pdf = $obj->model_pdf;
1954 $this->fetch_optionals();
1961 $this->error = $this->
db->lasterror();
1962 $this->errors[] = $this->
db->lasterror();
1967 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($this->price_level)) {
1968 $this->price_level = 1;
1982 public function delete($id,
User $fuser =
null, $call_trigger = 1)
1984 global $langs, $conf, $user;
1986 if (empty($fuser)) {
1990 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1992 $entity = isset($this->entity) ? $this->entity : $conf->entity;
1994 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1999 if (empty($objectisused)) {
2003 if (!$error && $call_trigger) {
2005 $result = $this->
call_trigger(
'COMPANY_DELETE', $fuser);
2013 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2015 $toute_categs = array();
2018 if ($this->client || $this->prospect) {
2019 $toute_categs[
'customer'] = $static_cat->containing($this->
id, Categorie::TYPE_CUSTOMER);
2021 if ($this->fournisseur) {
2022 $toute_categs[
'supplier'] = $static_cat->containing($this->
id, Categorie::TYPE_SUPPLIER);
2026 foreach ($toute_categs as $type => $categs_type) {
2027 foreach ($categs_type as $cat) {
2028 $cat->del_type($this, $type);
2034 foreach ($this->childtablesoncascade as $tabletodelete) {
2035 $deleteFromObject = explode(
':', $tabletodelete);
2036 if (count($deleteFromObject) >= 2) {
2037 $className = str_replace(
'@',
'', $deleteFromObject[0]);
2038 $filepath = $deleteFromObject[1];
2039 $columnName = $deleteFromObject[2];
2041 $child_object =
new $className($this->
db);
2042 $result = $child_object->deleteByParentField($id, $columnName);
2045 $this->errors[] = $child_object->error;
2050 $this->errors[] =
'Cannot include child class file '.$filepath;
2054 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
2055 $sql .=
" WHERE fk_soc = ".((int) $id);
2056 if (!$this->
db->query($sql)) {
2058 $this->errors[] = $this->
db->lasterror();
2070 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
2076 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2077 $sql .=
" SET parent = NULL";
2078 $sql .=
" WHERE parent = ".((int) $id);
2079 if (!$this->
db->query($sql)) {
2081 $this->errors[] = $this->
db->lasterror();
2087 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
2088 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity";
2089 $sql .=
" WHERE fk_soc = ".((int) $id);
2090 if (!$this->
db->query($sql)) {
2092 $this->errors[] = $this->
db->lasterror();
2096 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe";
2097 $sql .=
" WHERE rowid = ".((int) $id);
2098 if (!$this->
db->query($sql)) {
2100 $this->errors[] = $this->
db->lasterror();
2105 $this->
db->commit();
2108 if (!empty($conf->societe->multidir_output[$entity])) {
2109 $docdir = $conf->societe->multidir_output[$entity].
"/".$id;
2118 $this->
db->rollback();
2122 dol_syslog(
"Can't remove thirdparty with id ".$id.
". There is ".$objectisused.
" childs", LOG_WARNING);
2139 if (($this->client == 2 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
2142 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2143 $sql .=
" SET client = ".((int) $newclient);
2144 $sql .=
" WHERE rowid = ".((int) $this->
id);
2148 $this->client = $newclient;
2169 global $conf, $langs;
2172 $note = trim($note);
2174 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2178 dol_syslog(get_class($this).
"::set_remise_client ".$remise.
", ".$note.
", ".$user->id);
2186 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2187 $sql .=
" SET remise_client = '".$this->db->escape($remise).
"'";
2188 $sql .=
" WHERE rowid = ".((int) $this->
id);
2191 $this->
db->rollback();
2192 $this->error = $this->
db->error();
2197 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise";
2198 $sql .=
" (entity, datec, fk_soc, remise_client, note, fk_user_author)";
2199 $sql .=
" VALUES (".$conf->entity.
", '".$this->
db->idate($now).
"', ".((int) $this->
id).
", '".$this->
db->escape($remise).
"',";
2200 $sql .=
" '".$this->db->escape($note).
"',";
2201 $sql .=
" ".((int) $user->id);
2206 $this->
db->rollback();
2207 $this->error = $this->
db->lasterror();
2211 $this->
db->commit();
2228 global $conf, $langs;
2231 $note = trim($note);
2233 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2237 dol_syslog(get_class($this).
"::set_remise_supplier ".$remise.
", ".$note.
", ".$user->id);
2245 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2246 $sql .=
" SET remise_supplier = '".$this->db->escape($remise).
"'";
2247 $sql .=
" WHERE rowid = ".((int) $this->
id);
2250 $this->
db->rollback();
2251 $this->error = $this->
db->error();
2256 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise_supplier";
2257 $sql .=
" (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
2258 $sql .=
" VALUES (".$conf->entity.
", '".$this->
db->idate($now).
"', ".((int) $this->
id).
", '".$this->
db->escape($remise).
"',";
2259 $sql .=
" '".$this->db->escape($note).
"',";
2260 $sql .=
" ".((int) $user->id);
2265 $this->
db->rollback();
2266 $this->error = $this->
db->lasterror();
2270 $this->
db->commit();
2293 $desc = trim($desc);
2296 if (!($remise > 0)) {
2297 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"1");
2301 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"3");
2305 if ($this->
id > 0) {
2309 if (preg_match(
'/\((.*)\)/', $vatrate, $reg)) {
2310 $vat_src_code = $reg[1];
2311 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2314 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2317 $discount->fk_soc = $this->id;
2319 $discount->discount_type = $discount_type;
2321 $discount->amount_ht = $discount->multicurrency_amount_ht =
price2num($remise,
'MT');
2322 $discount->amount_tva = $discount->multicurrency_amount_tva =
price2num($remise * $vatrate / 100,
'MT');
2323 $discount->amount_ttc = $discount->multicurrency_amount_ttc =
price2num($discount->amount_ht + $discount->amount_tva,
'MT');
2325 $discount->tva_tx =
price2num($vatrate);
2326 $discount->vat_src_code = $vat_src_code;
2328 $discount->description = $desc;
2330 $result = $discount->create($user);
2334 $this->error = $discount->error;
2353 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2356 $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type);
2360 $this->error = $discountstatic->error;
2378 $reparray = array();
2380 $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";
2381 $sql .=
", u.office_fax, u.user_mobile, u.personal_mobile";
2382 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc, ".MAIN_DB_PREFIX.
"user as u";
2383 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2384 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
2385 $sql .=
" WHERE ((ug.fk_user = sc.fk_user";
2386 $sql .=
" AND ug.entity = ".$conf->entity.
")";
2387 $sql .=
" OR u.admin = 1)";
2389 $sql .=
" WHERE entity in (0, ".$conf->entity.
")";
2392 $sql .=
" AND u.rowid = sc.fk_user AND sc.fk_soc = ".((int) $this->
id);
2393 if (empty($sortfield) && empty($sortorder)) {
2394 $sortfield =
'u.lastname,u.firstname';
2395 $sortorder =
'ASC,ASC';
2397 $sql .= $this->
db->order($sortfield, $sortorder);
2401 $num = $this->
db->num_rows(
$resql);
2404 $obj = $this->
db->fetch_object(
$resql);
2407 $reparray[$i][
'id'] = $obj->rowid;
2408 $reparray[$i][
'lastname'] = $obj->lastname;
2409 $reparray[$i][
'firstname'] = $obj->firstname;
2410 $reparray[$i][
'email'] = $obj->email;
2411 $reparray[$i][
'phone'] = $obj->office_phone;
2412 $reparray[$i][
'office_phone'] = $obj->office_phone;
2413 $reparray[$i][
'office_fax'] = $obj->office_fax;
2414 $reparray[$i][
'user_mobile'] = $obj->user_mobile;
2415 $reparray[$i][
'personal_mobile'] = $obj->personal_mobile;
2416 $reparray[$i][
'job'] = $obj->job;
2417 $reparray[$i][
'statut'] = $obj->status;
2418 $reparray[$i][
'status'] = $obj->status;
2419 $reparray[$i][
'entity'] = $obj->entity;
2420 $reparray[$i][
'login'] = $obj->login;
2421 $reparray[$i][
'photo'] = $obj->photo;
2422 $reparray[$i][
'gender'] = $obj->gender;
2424 $reparray[] = $obj->rowid;
2447 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2448 $sql .=
" SET price_level = ".((int) $price_level);
2449 $sql .=
" WHERE rowid = ".((int) $this->
id);
2451 if (!$this->
db->query($sql)) {
2456 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_prices";
2457 $sql .=
" (datec, fk_soc, price_level, fk_user_author)";
2458 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $this->
id).
", ".((int) $price_level).
", ".((int) $user->id).
")";
2460 if (!$this->
db->query($sql)) {
2482 if ($this->
id > 0 && $commid > 0) {
2486 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux";
2487 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2491 dol_syslog(get_class($this).
"::add_commercial Error ".$this->
db->lasterror());
2497 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_commerciaux";
2498 $sql .=
" (fk_soc, fk_user)";
2499 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $commid).
")";
2503 dol_syslog(get_class($this).
"::add_commercial Error ".$this->
db->lasterror());
2509 $this->context = array(
'commercial_modified' => $commid);
2511 $result = $this->
call_trigger(
'COMPANY_LINK_SALE_REPRESENTATIVE', $user);
2518 $this->
db->commit();
2521 $this->
db->rollback();
2541 $this->context = array(
'commercial_modified'=>$commid);
2543 $result = $this->
call_trigger(
'COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
2548 if ($this->
id > 0 && $commid > 0) {
2549 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux ";
2550 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2552 if (!$this->
db->query($sql)) {
2553 dol_syslog(get_class($this).
"::del_commercial Erreur");
2571 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1, $noaliasinname = 0, $target =
'')
2573 global $conf, $langs, $hookmanager;
2575 if (!empty($conf->dol_no_mouse_hover)) {
2579 $name = $this->
name ? $this->
name : $this->nom;
2581 if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) {
2582 if (empty($option) && $this->client > 0) {
2583 $option =
'customer';
2585 if (empty($option) && $this->fournisseur > 0) {
2586 $option =
'supplier';
2590 if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto))) {
2592 if (($this->client) && (!empty($this->code_client)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 2)) {
2593 $code = $this->code_client.
' - ';
2596 if (($this->fournisseur) && (!empty($this->code_fournisseur)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 3)) {
2597 $code .= $this->code_fournisseur.
' - ';
2601 if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1) {
2602 $name = $code.
' '.$name;
2609 if (!empty($this->name_alias) && empty($noaliasinname)) {
2610 $name .=
' ('.$this->name_alias.
')';
2613 $result =
''; $label =
''; $label2 =
'';
2614 $linkstart =
''; $linkend =
'';
2616 if (!empty($this->logo) && class_exists(
'Form')) {
2617 $label .=
'<div class="photointooltip floatright">';
2618 $label .=
Form::showphoto(
'societe', $this, 0, 40, 0,
'photoref',
'mini', 0);
2621 } elseif (!empty($this->logo_squarred) && class_exists(
'Form')) {
2627 $label .=
'<div class="centpercent">';
2629 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
2630 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Customer").
'</u>';
2631 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2632 } elseif ($option ==
'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
2633 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Prospect").
'</u>';
2634 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2635 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
2636 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Supplier").
'</u>';
2637 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->id;
2638 } elseif ($option ==
'agenda') {
2639 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2640 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/agenda.php?socid='.$this->id;
2641 } elseif ($option ==
'project') {
2642 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2643 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/project.php?socid='.$this->id;
2644 } elseif ($option ==
'margin') {
2645 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2646 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/margin/tabs/thirdpartyMargins.php?socid='.$this->
id.
'&type=1';
2647 } elseif ($option ==
'contact') {
2648 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2649 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/contact.php?socid='.$this->id;
2650 } elseif ($option ==
'ban') {
2651 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2652 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$this->id;
2656 if (empty($linkstart)) {
2657 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2658 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$this->id;
2660 if (isset($this->status)) {
2661 $label .=
' '.$this->getLibStatut(5);
2665 if (!empty($this->name_alias)) {
2666 $label .=
' ('.dol_escape_htmltag($this->name_alias).
')';
2669 $label .=
'<br>'.img_picto(
'',
'email',
'class="pictofixedwidth"').$this->email;
2671 if (!empty($this->phone) || !empty($this->fax)) {
2672 $phonelist = array();
2674 $phonelist[] =
dol_print_phone($this->phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2677 $phonelist[] =
dol_print_phone($this->fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2679 $label .=
'<br>'.implode(
' ', $phonelist);
2682 if (!empty($this->address)) {
2683 $label2 .=
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
' ', $langs);
2684 } elseif (!empty($this->country_code)) {
2685 $label2 .=
'<br><b>'.$langs->trans(
'Country').
':</b> '.$this->country_code;
2687 if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'vatnumber') !==
false)) {
2688 $label2 .=
'<br><b>'.$langs->trans(
'VATIntra').
':</b> '.
dol_escape_htmltag($this->tva_intra);
2691 if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP)) {
2692 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid1') !==
false && $langs->trans(
'ProfId1'.$this->country_code) !=
'-') {
2693 $label2 .=
'<br><b>'.$langs->trans(
'ProfId1'.$this->country_code).
':</b> '.$this->idprof1;
2695 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid2') !==
false && $langs->trans(
'ProfId2'.$this->country_code) !=
'-') {
2696 $label2 .=
'<br><b>'.$langs->trans(
'ProfId2'.$this->country_code).
':</b> '.$this->idprof2;
2698 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid3') !==
false && $langs->trans(
'ProfId3'.$this->country_code) !=
'-') {
2699 $label2 .=
'<br><b>'.$langs->trans(
'ProfId3'.$this->country_code).
':</b> '.$this->idprof3;
2701 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid4') !==
false && $langs->trans(
'ProfId4'.$this->country_code) !=
'-') {
2702 $label2 .=
'<br><b>'.$langs->trans(
'ProfId4'.$this->country_code).
':</b> '.$this->idprof4;
2704 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid5') !==
false && $langs->trans(
'ProfId5'.$this->country_code) !=
'-') {
2705 $label2 .=
'<br><b>'.$langs->trans(
'ProfId5'.$this->country_code).
':</b> '.$this->idprof5;
2707 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid6') !==
false && $langs->trans(
'ProfId6'.$this->country_code) !=
'-') {
2708 $label2 .=
'<br><b>'.$langs->trans(
'ProfId6'.$this->country_code).
':</b> '.$this->idprof6;
2711 if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
2712 $label2 .=
'<br><b>'.$langs->trans(
'CustomerCode').
':</b> '.$this->code_client;
2714 if (!empty($this->code_fournisseur) && $this->fournisseur) {
2715 $label2 .=
'<br><b>'.$langs->trans(
'SupplierCode').
':</b> '.$this->code_fournisseur;
2717 if (!empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3)) {
2718 $label2 .=
'<br><b>'.$langs->trans(
'CustomerAccountancyCode').
':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client);
2720 if (!empty($conf->accounting->enabled) && $this->fournisseur) {
2721 $label2 .=
'<br><b>'.$langs->trans(
'SupplierAccountancyCode').
':</b> '.$this->code_compta_fournisseur;
2723 $label .= ($label2 ?
'<br>'.$label2 :
'').
'</div>';
2726 $linkstart .= (!empty($this->canvas) ?
'&canvas='.$this->canvas :
'');
2728 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2729 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2730 $add_save_lastsearch_values = 1;
2732 if ($add_save_lastsearch_values) {
2733 $linkstart .=
'&save_lastsearch_values=1';
2738 if (empty($notooltip)) {
2739 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2740 $label = $langs->trans(
"ShowCompany");
2741 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2743 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
2744 $linkclose .=
' class="classfortooltip refurl"';
2745 $target_value = array(
'_self',
'_blank',
'_parent',
'_top');
2746 if (in_array($target, $target_value)) {
2747 $linkclose .=
' target="'.dol_escape_htmltag($target).
'"';
2750 $linkstart .= $linkclose.
'>';
2754 if (empty($user->rights->societe->client->voir) && $user->socid > 0 && $this->id != $user->socid) {
2759 $result .= $linkstart;
2761 $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);
2763 if ($withpicto != 2) {
2766 $result .= $linkend;
2769 $hookmanager->initHooks(array(
'thirdpartydao'));
2770 $parameters = array(
2772 'getnomurl' => &$result,
2773 'withpicto '=> $withpicto,
2776 'notooltip'=> $notooltip,
2777 'save_lastsearch_value'=> $save_lastsearch_value
2779 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2781 $result = $hookmanager->resPrint;
2783 $result .= $hookmanager->resPrint;
2798 public function getTypeUrl($withpicto = 0, $option =
'', $notooltip = 0, $tag =
'a')
2800 global $conf, $langs;
2803 if (empty($option) || preg_match(
'/prospect/', $option)) {
2804 if (($this->client == 2 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
2805 $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.
'>';
2808 if (empty($option) || preg_match(
'/customer/', $option)) {
2809 if (($this->client == 1 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
2810 $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.
'>';
2813 if (empty($option) || preg_match(
'/supplier/', $option)) {
2814 if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && $this->fournisseur) {
2815 $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.
'>';
2830 return $this->
LibStatut($this->status, $mode);
2845 $langs->load(
'companies');
2847 $statusType =
'status4';
2849 $statusType =
'status6';
2852 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2853 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
2854 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"InActivity");
2855 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
2856 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"InActivity");
2859 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2875 if ($this->email && $addthirdparty) {
2876 if (empty($this->
name)) {
2877 $this->
name = $this->nom;
2879 $contact_emails[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->email.
">";
2882 return $contact_emails;
2898 if (!empty($this->phone)) {
2899 if (empty($this->
name)) {
2900 $this->
name = $this->nom;
2903 $contact_phone[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->phone.
">";
2905 return $contact_phone;
2921 $contact_property = array();
2924 $sql =
"SELECT rowid, email, statut as status, phone_mobile, lastname, poste, firstname";
2925 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
2926 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
2927 $sql .=
" ORDER BY lastname, firstname";
2931 $nump = $this->
db->num_rows(
$resql);
2933 $sepa =
"("; $sepb =
")";
2934 if ($mode ==
'email') {
2936 $sepa =
"<"; $sepb =
">";
2939 while ($i < $nump) {
2940 $obj = $this->
db->fetch_object(
$resql);
2941 if ($mode ==
'email') {
2942 $property = $obj->email;
2943 } elseif ($mode ==
'mobile') {
2944 $property = $obj->phone_mobile;
2946 $property = $obj->$mode;
2950 if ($obj->status == 1 || empty($hidedisabled)) {
2951 if (empty($property)) {
2952 if ($mode ==
'email') {
2953 $property = $langs->transnoentitiesnoconv(
"NoEMail");
2954 } elseif ($mode ==
'mobile') {
2955 $property = $langs->transnoentitiesnoconv(
"NoMobilePhone");
2959 if (!empty($obj->poste)) {
2960 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ?
" - ".$obj->poste :
"").(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
2962 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
2971 return $contact_property;
2984 $contacts = array();
2986 $sql =
"SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
2989 $nump = $this->
db->num_rows(
$resql);
2992 while ($i < $nump) {
2993 $obj = $this->
db->fetch_object(
$resql);
3013 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
3014 $contacts = array();
3016 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3019 $nump = $this->
db->num_rows(
$resql);
3022 while ($i < $nump) {
3023 $obj = $this->
db->fetch_object(
$resql);
3025 $contact->fetch($obj->rowid);
3026 $contacts[] = $contact;
3047 $contact_property =
'';
3049 if (empty($rowid)) {
3053 $sql =
"SELECT rowid, email, phone_mobile, lastname, firstname";
3054 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3055 $sql .=
" WHERE rowid = ".((int) $rowid);
3059 $nump = $this->
db->num_rows(
$resql);
3062 $obj = $this->
db->fetch_object(
$resql);
3064 if ($mode ==
'email') {
3066 } elseif ($mode ==
'mobile') {
3067 $contact_property = $obj->phone_mobile;
3070 return $contact_property;
3087 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3090 $bac->fetch(0, $this->
id);
3093 if ($mode ==
'label') {
3094 return $bac->getRibLabel(
true);
3095 } elseif ($mode ==
'rum') {
3096 if (empty($bac->rum)) {
3097 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
3099 $bac->fetch_thirdparty();
3100 $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
3103 } elseif ($mode ==
'format') {
3104 return $bac->frstrecur;
3106 return 'BadParameterToFunctionDisplayRib';
3122 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3123 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE type='ban' AND fk_soc = ".((int) $this->
id);
3124 $result = $this->
db->query($sql);
3127 $this->errors[] = $this->
db->lasterror;
3130 $num_rows = $this->
db->num_rows($result);
3131 $rib_array = array();
3133 while ($obj = $this->
db->fetch_object($result)) {
3135 $rib->fetch($obj->rowid);
3136 $rib_array[] = $rib;
3156 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3157 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3159 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3160 foreach ($dirsociete as $dirroot) {
3166 $mod =
new $module();
3168 $this->code_client = $mod->getNextValue($objsoc, $type);
3169 $this->prefixCustomerIsRequired = $mod->prefixIsRequired;
3171 dol_syslog(get_class($this).
"::get_codeclient code_client=".$this->code_client.
" module=".$module);
3188 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3189 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3191 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3192 foreach ($dirsociete as $dirroot) {
3198 $mod =
new $module();
3200 $this->code_fournisseur = $mod->getNextValue($objsoc, $type);
3202 dol_syslog(get_class($this).
"::get_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3217 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3218 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3220 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3221 foreach ($dirsociete as $dirroot) {
3228 $mod =
new $module();
3230 dol_syslog(get_class($this).
"::codeclient_modifiable code_client=".$this->code_client.
" module=".$module);
3231 if ($mod->code_modifiable_null && !$this->code_client) {
3234 if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
3237 if ($mod->code_modifiable) {
3257 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3258 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3260 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3261 foreach ($dirsociete as $dirroot) {
3268 $mod =
new $module();
3270 dol_syslog(get_class($this).
"::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur.
" module=".$module);
3271 if ($mod->code_modifiable_null && !$this->code_fournisseur) {
3274 if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
3277 if ($mod->code_modifiable) {
3303 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3304 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3306 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3307 foreach ($dirsociete as $dirroot) {
3314 $mod =
new $module();
3316 dol_syslog(get_class($this).
"::check_codeclient code_client=".$this->code_client.
" module=".$module);
3317 $result = $mod->verif($this->
db, $this->code_client, $this, 0);
3319 $this->error = $mod->error;
3320 $this->errors = $mod->errors;
3344 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3345 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3347 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3348 foreach ($dirsociete as $dirroot) {
3355 $mod =
new $module();
3357 dol_syslog(get_class($this).
"::check_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3358 $result = $mod->verif($this->
db, $this->code_fournisseur, $this, 1);
3360 $this->error = $mod->error;
3361 $this->errors = $mod->errors;
3383 if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) {
3385 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3386 foreach ($dirsociete as $dirroot) {
3387 $res =
dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.
'.php');
3394 $classname = $conf->global->SOCIETE_CODECOMPTA_ADDON;
3395 $mod =
new $classname;
3398 $result = $mod->get_code($this->
db, $this, $type);
3400 if ($type ==
'customer') {
3401 $this->code_compta_client = $mod->code;
3402 $this->code_compta = $this->code_compta_client;
3403 } elseif ($type ==
'supplier') {
3404 $this->code_compta_fournisseur = $mod->code;
3409 $this->error =
'ErrorAccountancyCodeNotDefined';
3413 if ($type ==
'customer') {
3414 $this->code_compta_client =
'';
3415 $this->code_compta =
'';
3416 } elseif ($type ==
'supplier') {
3417 $this->code_compta_fournisseur =
'';
3432 dol_syslog(get_class($this).
'::setParent', LOG_DEBUG);
3438 if ($sameparent < 0) {
3441 if ($sameparent == 1) {
3442 setEventMessages(
'ParentCompanyToAddIsAlreadyAChildOfModifiedCompany',
null,
'warnings');
3447 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe SET parent = '.($id > 0 ? $id :
'null').
' WHERE rowid = '.((
int) $this->id);
3451 $this->parent = $id;
3471 if ($counter > 100) {
3472 dol_syslog(
"Too high level of parent - child for company. May be an infinite loop ?", LOG_WARNING);
3475 $sql =
'SELECT s.parent';
3476 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
3477 $sql .=
' WHERE rowid = '.((int) $idparent);
3480 $obj = $this->
db->fetch_object(
$resql);
3482 if ($obj->parent ==
'') {
3484 } elseif ($obj->parent == $idchild) {
3506 if ($company_id > 0) {
3507 $sql =
"SELECT parent FROM " . MAIN_DB_PREFIX .
"societe WHERE rowid = $company_id";
3510 if ($obj = $this->
db->fetch_object(
$resql)) {
3511 $parent = $obj->parent;
3512 if ($parent > 0 && !in_array($parent, $parents)) {
3513 $parents[] = $parent;
3521 setEventMessage($langs->trans(
'GetCompanyParentsError', $this->db->lasterror()),
'errors');
3540 $ret = (empty($conf->global->SOCIETE_IDPROF1_UNIQUE) ? false :
true);
3543 $ret = (empty($conf->global->SOCIETE_IDPROF2_UNIQUE) ? false :
true);
3546 $ret = (empty($conf->global->SOCIETE_IDPROF3_UNIQUE) ? false :
true);
3549 $ret = (empty($conf->global->SOCIETE_IDPROF4_UNIQUE) ? false :
true);
3552 $ret = (empty($conf->global->SOCIETE_IDPROF5_UNIQUE) ? false :
true);
3555 $ret = (empty($conf->global->SOCIETE_IDPROF6_UNIQUE) ? false :
true);
3604 $sql =
"SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX.
"societe WHERE ".$field.
" = '".$this->
db->escape($value).
"' AND entity IN (".
getEntity(
'societe').
")";
3606 $sql .=
" AND rowid <> ".$socid;
3610 $obj = $this->
db->fetch_object(
$resql);
3611 $count = $obj->idprof;
3614 print $this->
db->error();
3641 if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3646 if ($idprof == 1 && $soc->country_code ==
'FR') {
3647 $chaine = trim($this->idprof1);
3648 $chaine = preg_replace(
'/(\s)/',
'', $chaine);
3650 if (!is_numeric($chaine)) {
3662 for ($index = 0; $index < 9; $index++) {
3663 $number = (int) $chaine[$index];
3664 if (($index % 2) != 0) {
3665 if (($number *= 2) > 9) {
3673 if (($sum % 10) != 0) {
3679 if ($idprof == 2 && $soc->country_code ==
'FR') {
3680 $chaine = trim($this->idprof2);
3681 $chaine = preg_replace(
'/(\s)/',
'', $chaine);
3683 if (!is_numeric($chaine)) {
3695 for ($index = 0; $index < 14; $index++) {
3696 $number = (int) $chaine[$index];
3697 if (($index % 2) == 0) {
3698 if (($number *= 2) > 9) {
3706 if (($sum % 10) != 0) {
3713 if ($idprof == 1 && $soc->country_code ==
'ES') {
3714 $string = trim($this->idprof1);
3715 $string = preg_replace(
'/(\s)/',
'', $string);
3716 $string = strtoupper($string);
3719 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)) {
3724 for ($i = 0; $i < 9; $i++) {
3725 $num[$i] = substr($string, $i, 1);
3729 if (preg_match(
'/(^[0-9]{8}[A-Z]{1}$)/', $string)) {
3730 if ($num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) {
3738 $sum = $num[2] + $num[4] + $num[6];
3739 for ($i = 1; $i < 8; $i += 2) {
3740 $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1));
3742 $n = 10 - substr($sum, strlen($sum) - 1, 1);
3745 if (preg_match(
'/^[KLM]{1}/', $string)) {
3746 if ($num[8] == chr(64 + $n) || $num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) {
3754 if (preg_match(
'/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) {
3755 if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) {
3763 if (preg_match(
'/^[T]{1}/', $string)) {
3764 if ($num[8] == preg_match(
'/^[T]{1}[A-Z0-9]{8}$/', $string)) {
3772 if (preg_match(
'/^[XYZ]{1}/', $string)) {
3773 if ($num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array(
'X',
'Y',
'Z'), array(
'0',
'1',
'2'), $string), 0, 8) % 23, 1)) {
3786 if ($idprof == 1 && $soc->country_code ==
'PT') {
3787 $string = trim($this->idprof1);
3788 $string = preg_replace(
'/(\s)/',
'', $string);
3791 if (preg_match(
'/(^[0-9]{9}$)/', $string)) {
3813 global $conf, $langs, $hookmanager;
3818 $hookmanager->initHooks(array(
'idprofurl'));
3819 $parameters = array(
'idprof'=>$idprof,
'company'=>$thirdparty);
3820 $reshook = $hookmanager->executeHooks(
'getIdProfUrl', $parameters, $this, $action);
3821 if (empty($reshook)) {
3822 if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3827 $strippedIdProf1 = str_replace(
' ',
'', $thirdparty->idprof1);
3828 if ($idprof == 1 && $thirdparty->country_code ==
'FR') {
3829 $url =
'https://annuaire-entreprises.data.gouv.fr/entreprise/'.$strippedIdProf1;
3831 if ($idprof == 1 && ($thirdparty->country_code ==
'GB' || $thirdparty->country_code ==
'UK')) {
3832 $url =
'https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
3834 if ($idprof == 1 && $thirdparty->country_code ==
'ES') {
3835 $url =
'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
3837 if ($idprof == 1 && $thirdparty->country_code ==
'IN') {
3838 $url =
'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.
';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3840 if ($idprof == 1 && $thirdparty->country_code ==
'PT') {
3841 $url =
'http://www.nif.pt/'.$strippedIdProf1;
3845 return '<a target="_blank" rel="noopener noreferrer" href="'.$url.
'">'.$langs->trans(
"Check").
'</a>';
3848 return $hookmanager->resPrint;
3863 $sql =
"SELECT COUNT(*) as numproj FROM ".MAIN_DB_PREFIX.
"projet WHERE fk_soc = ".((int) $this->
id);
3866 $obj = $this->
db->fetch_object(
$resql);
3867 $count = $obj->numproj;
3870 print $this->
db->error();
3873 return ($count > 0);
3885 $sql =
"SELECT s.rowid, s.nom as name, s.datec, tms as datem,";
3886 $sql .=
" fk_user_creat, fk_user_modif";
3887 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
3888 $sql .=
" WHERE s.rowid = ".((int) $id);
3890 $result = $this->
db->query($sql);
3892 if ($this->
db->num_rows($result)) {
3893 $obj = $this->
db->fetch_object($result);
3895 $this->
id = $obj->rowid;
3897 $this->user_creation_id = $obj->fk_user_creat;
3898 $this->user_modification_id = $obj->fk_user_modif;
3899 $this->date_creation = $this->
db->jdate($obj->datec);
3900 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
3902 $this->
ref = $obj->name;
3905 $this->
db->free($result);
3921 $isacompany = empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES) ? 0 : 1;
3922 if (!empty($this->tva_intra)) {
3924 } elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) {
3926 } elseif (!empty($this->typent_code) && $this->typent_code !=
'TE_UNKNOWN') {
3928 if (preg_match(
'/^TE_PRIVATE/', $this->typent_code)) {
3945 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
3958 $this->SupplierCategories = array();
3959 $sql =
"SELECT rowid, label";
3960 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
3961 $sql .=
" WHERE type = ".Categorie::TYPE_SUPPLIER;
3965 while ($obj = $this->
db->fetch_object(
$resql)) {
3966 $this->SupplierCategories[$obj->rowid] = $obj->label;
3984 if ($categorie_id > 0 && $this->
id > 0) {
3985 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_fournisseur (fk_categorie, fk_soc) ";
3986 $sql .=
" VALUES (".((int) $categorie_id).
", ".((int) $this->
id).
")";
3988 if (
$resql = $this->
db->query($sql)) {
4011 global $conf, $user, $langs;
4013 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
4015 $name = $socname ? $socname : $member->societe;
4020 $alias = $socalias ? $socalias :
'';
4024 $this->
name = $name;
4025 $this->name_alias = $alias;
4026 $this->address = $member->address;
4027 $this->zip = $member->zip;
4028 $this->town = $member->town;
4029 $this->country_code = $member->country_code;
4030 $this->country_id = $member->country_id;
4031 $this->phone = $member->phone;
4032 $this->email = $member->email;
4033 $this->socialnetworks = $member->socialnetworks;
4034 $this->entity = $member->entity;
4037 $this->code_client = ($customercode ? $customercode : -1);
4038 $this->code_fournisseur = -1;
4039 $this->typent_code = ($member->morphy ==
'phy' ?
'TE_PRIVATE' : 0);
4040 $this->typent_id = $this->typent_code ?
dol_getIdFromCode($this->
db, $this->typent_code,
'c_typent',
'id',
'code') : 0;
4045 $result = $this->
create($user);
4049 if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT)) {
4051 $this->name_bis = $member->lastname;
4052 $this->firstname = $member->firstname;
4053 $this->civility_id = $member->civility_id;
4055 dol_syslog(
"We ask to create a contact/address too", LOG_DEBUG);
4060 $this->
db->rollback();
4065 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent";
4066 $sql .=
" SET fk_soc = ".((int) $this->
id);
4067 $sql .=
" WHERE rowid = ".((int) $member->id);
4071 $this->
db->commit();
4074 $this->error = $this->
db->error();
4076 $this->
db->rollback();
4081 dol_syslog(get_class($this).
"::create_from_member - 2 - ".$this->error.
" - ".join(
',', $this->errors), LOG_ERR);
4083 $this->
db->rollback();
4099 $this->
name = empty($conf->global->MAIN_INFO_SOCIETE_NOM) ?
'' : $conf->global->MAIN_INFO_SOCIETE_NOM;
4100 $this->address = empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS) ?
'' : $conf->global->MAIN_INFO_SOCIETE_ADDRESS;
4101 $this->zip = empty($conf->global->MAIN_INFO_SOCIETE_ZIP) ?
'' : $conf->global->MAIN_INFO_SOCIETE_ZIP;
4102 $this->town = empty($conf->global->MAIN_INFO_SOCIETE_TOWN) ?
'' : $conf->global->MAIN_INFO_SOCIETE_TOWN;
4103 $this->region_code = empty($conf->global->MAIN_INFO_SOCIETE_REGION) ?
'' : $conf->global->MAIN_INFO_SOCIETE_REGION;
4104 $this->
object = empty($conf->global->MAIN_INFO_SOCIETE_OBJECT) ?
'' : $conf->global->MAIN_INFO_SOCIETE_OBJECT;
4106 $this->note_private = empty($conf->global->MAIN_INFO_SOCIETE_NOTE) ?
'' : $conf->global->MAIN_INFO_SOCIETE_NOTE;
4108 $this->nom = $this->name;
4111 $country_id = $country_code = $country_label =
'';
4112 if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
4113 $tmp = explode(
':', $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
4114 $country_id = $tmp[0];
4115 if (!empty($tmp[1])) {
4116 $country_code = $tmp[1];
4117 $country_label = $tmp[2];
4120 dol_syslog(
"Your country setup use an old syntax. Reedit it using setup area.", LOG_WARNING);
4121 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4123 $country_label =
getCountry($country_id, 0, $this->
db);
4126 $this->country_id = $country_id;
4127 $this->country_code = $country_code;
4128 $this->country = $country_label;
4129 if (is_object($langs)) {
4130 $this->country = ($langs->trans(
'Country'.$country_code) !=
'Country'.$country_code) ? $langs->trans(
'Country'.$country_code) : $country_label;
4135 $state_id = 0; $state_code = $state_label =
'';
4136 if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE)) {
4137 $tmp = explode(
':', $conf->global->MAIN_INFO_SOCIETE_STATE);
4138 $state_id = $tmp[0];
4139 if (!empty($tmp[1])) {
4140 $state_code = $tmp[1];
4141 $state_label = $tmp[2];
4143 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);
4144 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4145 $state_code =
getState($state_id, 2, $this->
db);
4146 $state_label =
getState($state_id, 0, $this->
db);
4149 $this->state_id = $state_id;
4150 $this->state_code = $state_code;
4151 $this->state = $state_label;
4152 if (is_object($langs)) {
4153 $this->state = ($langs->trans(
'State'.$state_code) !=
'State'.$state_code) ? $langs->trans(
'State'.$state_code) : $state_label;
4156 $this->phone = empty($conf->global->MAIN_INFO_SOCIETE_TEL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_TEL;
4157 $this->fax = empty($conf->global->MAIN_INFO_SOCIETE_FAX) ?
'' : $conf->global->MAIN_INFO_SOCIETE_FAX;
4158 $this->url = empty($conf->global->MAIN_INFO_SOCIETE_WEB) ?
'' : $conf->global->MAIN_INFO_SOCIETE_WEB;
4161 $this->facebook_url = empty($conf->global->MAIN_INFO_SOCIETE_FACEBOOK_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_FACEBOOK_URL;
4162 $this->twitter_url = empty($conf->global->MAIN_INFO_SOCIETE_TWITTER_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_TWITTER_URL;
4163 $this->linkedin_url = empty($conf->global->MAIN_INFO_SOCIETE_LINKEDIN_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LINKEDIN_URL;
4164 $this->instagram_url = empty($conf->global->MAIN_INFO_SOCIETE_INSTAGRAM_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_INSTAGRAM_URL;
4165 $this->youtube_url = empty($conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL;
4166 $this->github_url = empty($conf->global->MAIN_INFO_SOCIETE_GITHUB_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_GITHUB_URL;
4167 $this->socialnetworks = array();
4168 if (!empty($this->facebook_url)) {
4169 $this->socialnetworks[
'facebook'] = $this->facebook_url;
4171 if (!empty($this->twitter_url)) {
4172 $this->socialnetworks[
'twitter'] = $this->twitter_url;
4174 if (!empty($this->linkedin_url)) {
4175 $this->socialnetworks[
'linkedin'] = $this->linkedin_url;
4177 if (!empty($this->instagram_url)) {
4178 $this->socialnetworks[
'instagram'] = $this->instagram_url;
4180 if (!empty($this->youtube_url)) {
4181 $this->socialnetworks[
'youtube'] = $this->youtube_url;
4183 if (!empty($this->github_url)) {
4184 $this->socialnetworks[
'github'] = $this->github_url;
4188 $this->idprof1 = empty($conf->global->MAIN_INFO_SIREN) ?
'' : $conf->global->MAIN_INFO_SIREN;
4189 $this->idprof2 = empty($conf->global->MAIN_INFO_SIRET) ?
'' : $conf->global->MAIN_INFO_SIRET;
4190 $this->idprof3 = empty($conf->global->MAIN_INFO_APE) ?
'' : $conf->global->MAIN_INFO_APE;
4191 $this->idprof4 = empty($conf->global->MAIN_INFO_RCS) ?
'' : $conf->global->MAIN_INFO_RCS;
4192 $this->idprof5 = empty($conf->global->MAIN_INFO_PROFID5) ?
'' : $conf->global->MAIN_INFO_PROFID5;
4193 $this->idprof6 = empty($conf->global->MAIN_INFO_PROFID6) ?
'' : $conf->global->MAIN_INFO_PROFID6;
4194 $this->tva_intra = empty($conf->global->MAIN_INFO_TVAINTRA) ?
'' : $conf->global->MAIN_INFO_TVAINTRA;
4195 $this->managers = empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS) ?
'' : $conf->global->MAIN_INFO_SOCIETE_MANAGERS;
4196 $this->capital = empty($conf->global->MAIN_INFO_CAPITAL) ?
'' : $conf->global->MAIN_INFO_CAPITAL;
4197 $this->forme_juridique_code = empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE) ?
'' : $conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
4198 $this->email = empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_MAIL;
4199 $this->default_lang = (empty($conf->global->MAIN_LANG_DEFAULT) ?
'auto' : $conf->global->MAIN_LANG_DEFAULT);
4200 $this->logo = empty($conf->global->MAIN_INFO_SOCIETE_LOGO) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO;
4201 $this->logo_small = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
4202 $this->logo_mini = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
4203 $this->logo_squarred = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED;
4204 $this->logo_squarred_small = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL;
4205 $this->logo_squarred_mini = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI;
4208 $this->tva_assuj = $conf->global->FACTURE_TVAOPTION;
4211 $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);
4212 $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);
4229 $this->
name =
'THIRDPARTY SPECIMEN '.dol_print_date($now,
'dayhourlog');
4230 $this->nom = $this->name;
4231 $this->ref_ext =
'Ref ext';
4232 $this->specimen = 1;
4233 $this->address =
'21 jump street';
4234 $this->zip =
'99999';
4235 $this->town =
'MyTown';
4236 $this->state_id = 1;
4237 $this->state_code =
'AA';
4238 $this->state =
'MyState';
4239 $this->country_id = 1;
4240 $this->country_code =
'FR';
4241 $this->email =
'specimen@specimen.com';
4242 $this->socialnetworks = array(
4243 'skype' =>
'tom.hanson',
4244 'twitter' =>
'tomhanson',
4245 'facebook' =>
'tomhanson',
4246 'linkedin' =>
'tomhanson',
4248 $this->url =
'http://www.specimen.com';
4250 $this->phone =
'0909090901';
4251 $this->fax =
'0909090909';
4253 $this->code_client =
'CC-'.dol_print_date($now,
'dayhourlog');
4254 $this->code_fournisseur =
'SC-'.dol_print_date($now,
'dayhourlog');
4255 $this->capital = 10000;
4257 $this->prospect = 1;
4258 $this->fournisseur = 1;
4259 $this->tva_assuj = 1;
4260 $this->tva_intra =
'EU1234567';
4261 $this->note_public =
'This is a comment (public)';
4262 $this->note_private =
'This is a comment (private)';
4264 $this->idprof1 =
'idprof1';
4265 $this->idprof2 =
'idprof2';
4266 $this->idprof3 =
'idprof3';
4267 $this->idprof4 =
'idprof4';
4268 $this->idprof5 =
'idprof5';
4269 $this->idprof6 =
'idprof6';
4281 $sql =
"SELECT t.localtax1, t.localtax2";
4282 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4283 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4284 $sql .=
" AND t.active = 1";
4285 if (empty($localTaxNum)) {
4286 $sql .=
" AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
4287 } elseif ($localTaxNum == 1) {
4288 $sql .=
" AND t.localtax1_type <> '0'";
4289 } elseif ($localTaxNum == 2) {
4290 $sql .=
" AND t.localtax2_type <> '0'";
4295 return ($this->
db->num_rows(
$resql) > 0);
4308 $sql =
"SELECT t.rowid";
4309 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4310 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4311 $sql .=
" AND t.active = 1 AND t.recuperableonly = 1";
4316 return ($this->
db->num_rows(
$resql) > 0);
4330 $sql =
"SELECT COUNT(*) as nb";
4331 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_revenuestamp as r, ".MAIN_DB_PREFIX.
"c_country as c";
4332 $sql .=
" WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4333 $sql .=
" AND r.active = 1";
4338 $obj = $this->
db->fetch_object(
$resql);
4339 return (($obj->nb > 0) ?
true:
false);
4341 $this->error = $this->
db->lasterror();
4368 $lib = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
4370 if ($lib == $langs->trans(
"ProspectLevel".$fk_prospectlevel)) {
4371 $lib = $langs->getLabelFromKey($this->
db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
4385 return $this->
LibProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
4406 $langs->load(
'customers');
4409 if ($status ==
'-1' || $status ==
'ST_NO') {
4410 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
4411 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4412 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
4413 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4414 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
4415 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4416 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
4417 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4418 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
4420 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);
4422 } elseif ($mode == 3) {
4423 if ($status ==
'-1' || $status ==
'ST_NO') {
4424 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto);
4425 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4426 return img_action($langs->trans(
"StatusProspect0"), 0, $picto);
4427 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4428 return img_action($langs->trans(
"StatusProspect1"), 1, $picto);
4429 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4430 return img_action($langs->trans(
"StatusProspect2"), 2, $picto);
4431 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4432 return img_action($langs->trans(
"StatusProspect3"), 3, $picto);
4434 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto);
4436 } elseif ($mode == 4) {
4437 if ($status ==
'-1' || $status ==
'ST_NO') {
4438 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
4439 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4440 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
4441 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4442 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
4443 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4444 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
4445 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4446 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
4448 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);
4452 return "Error, mode/status not found";
4464 if ($mode ==
'supplier') {
4465 $table =
'supplier_proposal';
4468 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4469 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4470 if ($mode ==
'supplier') {
4471 $sql .=
" AND entity IN (".getEntity(
'supplier_proposal').
")";
4473 $sql .=
" AND entity IN (".getEntity(
'propal').
")";
4476 dol_syslog(
"getOutstandingProposals for fk_soc = ".((
int) $this->
id), LOG_DEBUG);
4480 $outstandingOpened = 0;
4481 $outstandingTotal = 0;
4482 $outstandingTotalIncTax = 0;
4483 $arrayofref = array();
4484 while ($obj = $this->
db->fetch_object(
$resql)) {
4485 $arrayofref[$obj->rowid] = $obj->ref;
4486 $outstandingTotal += $obj->total_ht;
4487 $outstandingTotalIncTax += $obj->total_ttc;
4488 if ($obj->status != 0) {
4490 $outstandingOpened += $obj->total_ttc;
4493 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref);
4507 $table =
'commande';
4508 if ($mode ==
'supplier') {
4509 $table =
'commande_fournisseur';
4512 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4513 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4514 if ($mode ==
'supplier') {
4515 $sql .=
" AND entity IN (".getEntity(
'supplier_order').
")";
4517 $sql .=
" AND entity IN (".getEntity(
'commande').
")";
4520 dol_syslog(
"getOutstandingOrders", LOG_DEBUG);
4523 $outstandingOpened = 0;
4524 $outstandingTotal = 0;
4525 $outstandingTotalIncTax = 0;
4526 $arrayofref = array();
4527 while ($obj = $this->
db->fetch_object(
$resql)) {
4528 $arrayofref[$obj->rowid] = $obj->ref;
4529 $outstandingTotal += $obj->total_ht;
4530 $outstandingTotalIncTax += $obj->total_ttc;
4531 if ($obj->status != 0) {
4533 $outstandingOpened += $obj->total_ttc;
4536 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref);
4552 if ($mode ==
'supplier') {
4553 $table =
'facture_fourn';
4563 $sql =
"SELECT rowid, ref, total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table.
" as f";
4564 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4565 if (!empty($late)) {
4566 $sql .=
" AND date_lim_reglement < '".$this->db->idate(
dol_now()).
"'";
4568 if ($mode ==
'supplier') {
4569 $sql .=
" AND entity IN (".getEntity(
'facture_fourn').
")";
4571 $sql .=
" AND entity IN (".getEntity(
'invoice').
")";
4574 dol_syslog(
"getOutstandingBills", LOG_DEBUG);
4577 $outstandingOpened = 0;
4578 $outstandingTotal = 0;
4579 $outstandingTotalIncTax = 0;
4580 $arrayofref = array();
4581 $arrayofrefopened = array();
4582 if ($mode ==
'supplier') {
4583 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
4586 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
4589 while ($obj = $this->
db->fetch_object(
$resql)) {
4590 $arrayofref[$obj->rowid] = $obj->ref;
4591 $tmpobject->id = $obj->rowid;
4593 if ($obj->status != $tmpobject::STATUS_DRAFT
4594 && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code ==
'replaced')
4596 $outstandingTotal += $obj->total_ht;
4597 $outstandingTotalIncTax += $obj->total_ttc;
4603 && $obj->status != $tmpobject::STATUS_DRAFT
4604 && $obj->status != $tmpobject::STATUS_ABANDONED
4605 && $obj->status != $tmpobject::STATUS_CLOSED) {
4607 $paiement = $tmpobject->getSommePaiement();
4608 $creditnotes = $tmpobject->getSumCreditNotesUsed();
4609 $deposits = $tmpobject->getSumDepositsUsed();
4611 $remaintopay = ($obj->total_ttc - $paiement - $creditnotes - $deposits);
4612 $outstandingOpened += $remaintopay;
4618 $remainingcreditnote = $tmpobject->getSumFromThisCreditNotesNotUsed();
4619 $remaintopay -= $remainingcreditnote;
4620 $outstandingOpened -= $remainingcreditnote;
4624 $arrayofrefopened[$obj->rowid] = $obj->ref;
4627 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref,
'refsopened'=>$arrayofrefopened);
4629 dol_syslog(
"Sql error ".$this->
db->lasterror, LOG_ERR);
4656 $langs->load(
'companies');
4659 return $langs->trans(
"NorProspectNorCustomer");
4660 } elseif ($status == 1) {
4661 return $langs->trans(
"Customer");
4662 } elseif ($status == 2) {
4663 return $langs->trans(
"Prospect");
4664 } elseif ($status == 3) {
4665 return $langs->trans(
"ProspectCustomer");
4681 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4683 global $conf, $user, $langs;
4685 if (!empty($moreparams) && !empty($moreparams[
'use_companybankid'])) {
4686 $modelpath =
"core/modules/bank/doc/";
4688 include_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
4690 $result = $companybankaccount->fetch($moreparams[
'use_companybankid']);
4692 dol_print_error($this->
db, $companybankaccount->error, $companybankaccount->errors);
4694 $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4698 if (!empty($conf->global->COMPANY_ADDON_PDF)) {
4699 $modele = $conf->global->COMPANY_ADDON_PDF;
4701 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_COMPANY_ADDON_PDF_NotDefined");
4706 if (!isset($this->bank_account)) {
4707 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
4709 $result = $bac->fetch(0, $this->
id);
4711 $this->bank_account = $bac;
4713 $this->bank_account =
'';
4717 $modelpath =
"core/modules/societe/doc/";
4719 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4739 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4742 if (!in_array($type_categ, array(Categorie::TYPE_CUSTOMER, Categorie::TYPE_SUPPLIER))) {
4743 dol_syslog(__METHOD__.
': Type '.$type_categ.
'is an unknown company category type. Done nothing.', LOG_ERR);
4747 return parent::setCategoriesCommon($categories, $type_categ);
4762 if (!is_array($salesrep)) {
4763 $salesrep = array($salesrep);
4767 $to_add = $salesrep;
4768 if ($onlyAdd ===
false) {
4773 if (is_array($existing)) {
4774 $to_del = array_diff($existing, $salesrep);
4775 $to_add = array_diff($salesrep, $existing);
4782 foreach ($to_del as $del) {
4785 foreach ($to_add as $add) {
4793 return $error ? -1 : 1;
4805 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
4806 $sql .=
" SET fk_typent = ".($typent_id > 0 ? $typent_id :
"null");
4807 $sql .=
" WHERE rowid = ".((int) $this->
id);
4808 dol_syslog(get_class($this).
'::setThirdpartyType', LOG_DEBUG);
4811 $this->typent_id = $typent_id;
4812 $this->typent_code =
dol_getIdFromCode($this->
db, $this->$typent_id,
'c_typent',
'id',
'code');
4833 if ($origin_id == $dest_id) {
4834 dol_syslog(
'Error: Try to merge a thirdparty into itself');
4842 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
4843 $sql .=
' WHERE fk_soc = '.(int) $dest_id.
' AND fk_user IN ( ';
4844 $sql .=
' SELECT fk_user ';
4845 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
4846 $sql .=
' WHERE fk_soc = '.(int) $origin_id.
') ';
4850 $dbs->
query(
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_commerciaux WHERE rowid = '.((
int) $obj->rowid));
4859 'societe_commerciaux',
4862 'societe_remise_except',
4879 global $user, $langs, $conf;
4883 $field =
'accountancy_code_sell';
4884 if ($type ==
'buy') {
4885 $field =
'accountancy_code_buy';
4886 } elseif ($type ==
'sell') {
4887 $field =
'accountancy_code_sell';
4892 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ";
4893 $sql .= $field.
" = '".$this->
db->escape($value).
"'";
4894 $sql .=
" WHERE rowid = ".((int) $this->
id);
4896 dol_syslog(get_class($this).
"::".__FUNCTION__.
"", LOG_DEBUG);
4901 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
4903 $result = $interface->run_triggers(
'COMPANY_MODIFY', $this, $user, $langs, $conf);
4905 $this->errors = $interface->errors;
4906 $this->
db->rollback();
4911 $this->$field = $value;
4913 $this->
db->commit();
4916 $this->error = $this->
db->lasterror();
4917 $this->
db->rollback();
4932 require_once DOL_DOCUMENT_ROOT.
'/partnership/class/partnership.class.php';
4935 $this->partnerships[] = array();