41 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonsocialnetworks.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
60 public $module =
'societe';
65 public $element =
'societe';
70 public $table_element =
'societe';
75 public $fk_element =
'fk_soc';
80 public $fieldsforcombobox =
'nom,name_alias';
85 protected $childtables = array(
86 'supplier_proposal' => array(
'name' =>
'SupplierProposal'),
87 'propal' => array(
'name' =>
'Proposal'),
88 'commande' => array(
'name' =>
'Order'),
89 'facture' => array(
'name' =>
'Invoice'),
90 'facture_rec' => array(
'name' =>
'RecurringInvoiceTemplate'),
91 'contrat' => array(
'name' =>
'Contract'),
92 'fichinter' => array(
'name' =>
'Fichinter'),
93 'facture_fourn' => array(
'name' =>
'SupplierInvoice'),
94 'commande_fournisseur' => array(
'name' =>
'SupplierOrder'),
95 'projet' => array(
'name' =>
'Project'),
96 'expedition' => array(
'name' =>
'Shipment'),
97 'prelevement_lignes' => array(
'name' =>
'DirectDebitRecord'),
104 protected $childtablesoncascade = array(
107 'product_fournisseur_price',
108 'product_customer_price_log',
109 'product_customer_price',
110 '@Contact:/contact/class/contact.class.php:fk_soc',
115 'societe_remise_except',
116 'societe_commerciaux',
126 public $picto =
'company';
132 public $ismultientitymanaged = 1;
137 public $isextrafieldmanaged = 1;
143 public $restrictiononfksoc = 1;
154 public $SupplierCategories = array();
160 public $prefixCustomerIsRequired;
191 public $fields = array(
192 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
193 'parent' =>array(
'type'=>
'integer',
'label'=>
'Parent',
'enabled'=>1,
'visible'=>-1,
'position'=>20),
194 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
195 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
196 'nom' =>array(
'type'=>
'varchar(128)',
'label'=>
'Nom',
'enabled'=>1,
'visible'=>-1,
'position'=>35,
'showoncombobox'=>1),
197 'name_alias' =>array(
'type'=>
'varchar(128)',
'label'=>
'Name alias',
'enabled'=>1,
'visible'=>-1,
'position'=>36,
'showoncombobox'=>2),
198 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>40,
'index'=>1),
199 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefExt',
'enabled'=>1,
'visible'=>0,
'position'=>45),
200 'code_client' =>array(
'type'=>
'varchar(24)',
'label'=>
'CustomerCode',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
201 'code_fournisseur' =>array(
'type'=>
'varchar(24)',
'label'=>
'SupplierCode',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
202 'code_compta' =>array(
'type'=>
'varchar(24)',
'label'=>
'CustomerAccountancyCode',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
203 'code_compta_fournisseur' =>array(
'type'=>
'varchar(24)',
'label'=>
'SupplierAccountancyCode',
'enabled'=>1,
'visible'=>-1,
'position'=>70),
204 'address' =>array(
'type'=>
'varchar(255)',
'label'=>
'Address',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
205 'zip' =>array(
'type'=>
'varchar(25)',
'label'=>
'Zip',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
206 'town' =>array(
'type'=>
'varchar(50)',
'label'=>
'Town',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
207 'fk_departement' =>array(
'type'=>
'integer',
'label'=>
'State',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
208 'fk_pays' =>array(
'type'=>
'integer:Ccountry:core/class/ccountry.class.php',
'label'=>
'Country',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
209 'phone' =>array(
'type'=>
'varchar(20)',
'label'=>
'Phone',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
210 'fax' =>array(
'type'=>
'varchar(20)',
'label'=>
'Fax',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
211 'url' =>array(
'type'=>
'varchar(255)',
'label'=>
'Url',
'enabled'=>1,
'visible'=>-1,
'position'=>110),
212 'email' =>array(
'type'=>
'varchar(128)',
'label'=>
'Email',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
213 'socialnetworks' =>array(
'type'=>
'text',
'label'=>
'Socialnetworks',
'enabled'=>1,
'visible'=>-1,
'position'=>120),
214 'fk_effectif' =>array(
'type'=>
'integer',
'label'=>
'Workforce',
'enabled'=>1,
'visible'=>-1,
'position'=>170),
215 'fk_typent' =>array(
'type'=>
'integer',
'label'=>
'TypeOfCompany',
'enabled'=>1,
'visible'=>-1,
'position'=>175,
'csslist'=>
'minwidth200'),
216 'fk_forme_juridique' =>array(
'type'=>
'integer',
'label'=>
'JuridicalStatus',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
217 'fk_currency' =>array(
'type'=>
'varchar(3)',
'label'=>
'Currency',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
218 'siren' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof1',
'enabled'=>1,
'visible'=>-1,
'position'=>190),
219 'siret' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof2',
'enabled'=>1,
'visible'=>-1,
'position'=>195),
220 'ape' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof3',
'enabled'=>1,
'visible'=>-1,
'position'=>200),
221 'idprof4' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof4',
'enabled'=>1,
'visible'=>-1,
'position'=>205),
222 'idprof5' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof5',
'enabled'=>1,
'visible'=>-1,
'position'=>206),
223 'idprof6' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof6',
'enabled'=>1,
'visible'=>-1,
'position'=>207),
224 'tva_intra' =>array(
'type'=>
'varchar(20)',
'label'=>
'Tva intra',
'enabled'=>1,
'visible'=>-1,
'position'=>210),
225 'capital' =>array(
'type'=>
'double(24,8)',
'label'=>
'Capital',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
226 'fk_stcomm' =>array(
'type'=>
'integer',
'label'=>
'CommercialStatus',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>220),
227 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>225),
228 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>230),
229 'prefix_comm' =>array(
'type'=>
'varchar(5)',
'label'=>
'Prefix comm',
'enabled'=>
"getDolGlobalInt('SOCIETE_USEPREFIX')",
'visible'=>-1,
'position'=>235),
230 'client' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Client',
'enabled'=>1,
'visible'=>-1,
'position'=>240),
231 'fournisseur' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Fournisseur',
'enabled'=>1,
'visible'=>-1,
'position'=>245),
232 'supplier_account' =>array(
'type'=>
'varchar(32)',
'label'=>
'Supplier account',
'enabled'=>1,
'visible'=>-1,
'position'=>250),
233 'fk_prospectlevel' =>array(
'type'=>
'varchar(12)',
'label'=>
'ProspectLevel',
'enabled'=>1,
'visible'=>-1,
'position'=>255),
234 'customer_bad' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Customer bad',
'enabled'=>1,
'visible'=>-1,
'position'=>260),
235 'customer_rate' =>array(
'type'=>
'double',
'label'=>
'Customer rate',
'enabled'=>1,
'visible'=>-1,
'position'=>265),
236 'supplier_rate' =>array(
'type'=>
'double',
'label'=>
'Supplier rate',
'enabled'=>1,
'visible'=>-1,
'position'=>270),
237 'fk_user_creat' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-2,
'position'=>275),
238 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>280),
241 'mode_reglement' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Mode reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>295),
242 'cond_reglement' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Cond reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>300),
243 'deposit_percent' =>array(
'type'=>
'varchar(63)',
'label'=>
'DepositPercent',
'enabled'=>1,
'visible'=>-1,
'position'=>301),
244 'mode_reglement_supplier' =>array(
'type'=>
'integer',
'label'=>
'Mode reglement supplier',
'enabled'=>1,
'visible'=>-1,
'position'=>305),
245 'cond_reglement_supplier' =>array(
'type'=>
'integer',
'label'=>
'Cond reglement supplier',
'enabled'=>1,
'visible'=>-1,
'position'=>308),
246 'outstanding_limit' =>array(
'type'=>
'double(24,8)',
'label'=>
'OutstandingBill',
'enabled'=>1,
'visible'=>-1,
'position'=>310,
'isameasure'=>1),
247 'order_min_amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'Order min amount',
'enabled'=>
'isModEnabled("commande") && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)',
'visible'=>-1,
'position'=>315,
'isameasure'=>1),
248 'supplier_order_min_amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'Supplier order min amount',
'enabled'=>
'isModEnabled("commande") && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)',
'visible'=>-1,
'position'=>320,
'isameasure'=>1),
249 'fk_shipping_method' =>array(
'type'=>
'integer',
'label'=>
'Fk shipping method',
'enabled'=>1,
'visible'=>-1,
'position'=>330),
250 'tva_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Tva assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>335),
251 'localtax1_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Localtax1 assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>340),
252 'localtax1_value' =>array(
'type'=>
'double(6,3)',
'label'=>
'Localtax1 value',
'enabled'=>1,
'visible'=>-1,
'position'=>345),
253 'localtax2_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Localtax2 assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>350),
254 'localtax2_value' =>array(
'type'=>
'double(6,3)',
'label'=>
'Localtax2 value',
'enabled'=>1,
'visible'=>-1,
'position'=>355),
255 'vat_reverse_charge' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Vat reverse charge',
'enabled'=>1,
'visible'=>-1,
'position'=>335),
256 'barcode' =>array(
'type'=>
'varchar(255)',
'label'=>
'Barcode',
'enabled'=>1,
'visible'=>-1,
'position'=>360),
257 'price_level' =>array(
'type'=>
'integer',
'label'=>
'Price level',
'enabled'=>
'$conf->global->PRODUIT_MULTIPRICES || $conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES',
'visible'=>-1,
'position'=>365),
258 'default_lang' =>array(
'type'=>
'varchar(6)',
'label'=>
'Default lang',
'enabled'=>1,
'visible'=>-1,
'position'=>370),
259 'canvas' =>array(
'type'=>
'varchar(32)',
'label'=>
'Canvas',
'enabled'=>1,
'visible'=>-1,
'position'=>375),
260 'fk_barcode_type' =>array(
'type'=>
'integer',
'label'=>
'Fk barcode type',
'enabled'=>1,
'visible'=>-1,
'position'=>405),
261 'webservices_url' =>array(
'type'=>
'varchar(255)',
'label'=>
'Webservices url',
'enabled'=>1,
'visible'=>-1,
'position'=>410),
262 'webservices_key' =>array(
'type'=>
'varchar(128)',
'label'=>
'Webservices key',
'enabled'=>1,
'visible'=>-1,
'position'=>415),
263 'fk_incoterms' =>array(
'type'=>
'integer',
'label'=>
'Fk incoterms',
'enabled'=>1,
'visible'=>-1,
'position'=>425),
264 'location_incoterms' =>array(
'type'=>
'varchar(255)',
'label'=>
'Location incoterms',
'enabled'=>1,
'visible'=>-1,
'position'=>430),
265 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>435),
266 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'LastMainDoc',
'enabled'=>1,
'visible'=>-1,
'position'=>270),
267 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>-1,
'position'=>440),
268 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Multicurrency code',
'enabled'=>1,
'visible'=>-1,
'position'=>445),
269 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'PaymentBankAccount',
'enabled'=>1,
'visible'=>-1,
'position'=>450),
270 'fk_warehouse' =>array(
'type'=>
'integer',
'label'=>
'Warehouse',
'enabled'=>1,
'visible'=>-1,
'position'=>455),
271 'logo' =>array(
'type'=>
'varchar(255)',
'label'=>
'Logo',
'enabled'=>1,
'visible'=>-1,
'position'=>400),
272 'logo_squarred' =>array(
'type'=>
'varchar(255)',
'label'=>
'Logo squarred',
'enabled'=>1,
'visible'=>-1,
'position'=>401),
273 'status' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>-1,
'position'=>500),
274 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000),
359 public $departement_code;
502 public $socialobject;
512 public $tva_assuj = 1;
523 public $vat_reverse_charge = 0;
526 public $localtax1_assuj;
527 public $localtax1_value;
528 public $localtax2_assuj;
529 public $localtax2_value;
544 public $typent_id = 0;
547 public $effectif_id = 0;
548 public $forme_juridique_code;
549 public $forme_juridique = 0;
551 public $remise_percent;
552 public $remise_supplier_percent;
554 public $mode_reglement_id;
555 public $cond_reglement_id;
556 public $deposit_percent;
557 public $mode_reglement_supplier_id;
558 public $cond_reglement_supplier_id;
559 public $transport_mode_supplier_id;
564 public $fk_prospectlevel;
577 public $date_modification;
583 public $user_modification;
589 public $date_creation;
595 public $user_creation;
607 public $prospect = 0;
625 public $code_fournisseur;
631 public $code_compta_client;
645 public $accountancy_code_customer;
651 public $code_compta_fournisseur;
657 public $accountancy_code_supplier;
663 public $code_compta_product;
676 public $note_private;
694 public $stcomm_picto;
700 public $status_prospect_label;
711 public $outstanding_limit;
716 public $order_min_amount;
721 public $supplier_order_min_amount;
727 public $commercial_id;
739 public $default_lang;
765 public $webservices_url;
771 public $webservices_key;
791 public $logo_squarred;
796 public $logo_squarred_small;
801 public $logo_squarred_mini;
806 public $accountancy_code_sell;
811 public $accountancy_code_buy;
817 public $fk_multicurrency;
823 public $fk_warehouse;
828 public $multicurrency_code;
832 public $partnerships = array();
838 public $bank_account;
841 const STATUS_CEASED = 0;
842 const STATUS_INACTIVITY = 1;
888 $this->fournisseur = 0;
889 $this->typent_id = 0;
890 $this->effectif_id = 0;
891 $this->forme_juridique_code = 0;
892 $this->tva_assuj = 1;
893 $this->vat_reverse_charge = 0;
896 if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
897 $this->fields[
'address'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
898 $this->fields[
'zip'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
899 $this->fields[
'town'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
914 global $langs, $conf, $mysoc;
919 if (empty($this->status)) {
922 $this->
name = $this->
name ?trim($this->
name) : trim($this->nom);
923 $this->setUpperOrLowerCase();
924 $this->nom = $this->name;
925 if (empty($this->client)) {
928 if (empty($this->fournisseur)) {
929 $this->fournisseur = 0;
931 $this->import_key = trim($this->import_key);
933 $this->accountancy_code_customer = trim($this->code_compta);
934 $this->accountancy_code_supplier = trim($this->code_compta_fournisseur);
935 $this->accountancy_code_buy = trim($this->accountancy_code_buy);
936 $this->accountancy_code_sell = trim($this->accountancy_code_sell);
938 if (!empty($this->multicurrency_code)) {
941 if (empty($this->fk_multicurrency)) {
942 $this->multicurrency_code =
'';
943 $this->fk_multicurrency = 0;
953 if ($this->code_client == -1 || $this->code_client ===
'auto') {
956 if ($this->code_fournisseur == -1 || $this->code_fournisseur ===
'auto') {
962 $result = $this->
verify();
965 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
967 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe (";
969 $sql .=
", name_alias";
972 $sql .=
", fk_user_creat";
973 $sql .=
", fk_typent";
977 $sql .=
", fk_stcomm";
978 $sql .=
", fk_incoterms";
979 $sql .=
", location_incoterms";
980 $sql .=
", import_key";
981 $sql .=
", fk_multicurrency";
982 $sql .=
", multicurrency_code";
983 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
984 $sql .=
", vat_reverse_charge";
985 $sql .=
", accountancy_code_buy";
986 $sql .=
", accountancy_code_sell";
988 $sql .=
") VALUES ('".$this->db->escape($this->name).
"', '".$this->db->escape($this->name_alias).
"', ".((int) $this->entity).
", '".$this->db->idate($now).
"'";
989 $sql .=
", ".(!empty($user->id) ? ((int) $user->id) :
"null");
990 $sql .=
", ".(!empty($this->typent_id) ? ((int) $this->typent_id) :
"null");
991 $sql .=
", ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null");
992 $sql .=
", ".((int) $this->status);
993 $sql .=
", ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
995 $sql .=
", ".(int) $this->fk_incoterms;
996 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
997 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
998 $sql .=
", ".(int) $this->fk_multicurrency;
999 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1000 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1001 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1002 $sql .=
", '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1003 $sql .=
", '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1007 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1008 $result = $this->db->query(
$sql);
1010 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"societe");
1012 $ret = $this->
update($this->
id, $user, 0, 1, 1,
'add');
1015 if (!$error && !empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1016 $this->db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int) $conf->entity));
1018 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
1021 $sql .=
", vat_reverse_charge";
1022 $sql .=
", accountancy_code_customer";
1023 $sql .=
", accountancy_code_supplier";
1024 $sql .=
", accountancy_code_buy";
1025 $sql .=
", accountancy_code_sell";
1026 $sql .=
") VALUES (";
1028 $sql .=
", ".((int) $conf->entity);
1029 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1030 $sql .=
", '".$this->db->escape($this->accountancy_code_customer).
"'";
1031 $sql .=
", '".$this->db->escape($this->accountancy_code_supplier).
"'";
1032 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1033 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1035 $result = $this->db->query(
$sql);
1038 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1043 if ($this->commercial_id !=
'' && $this->commercial_id != -1) {
1045 } elseif (empty($user->rights->societe->client->voir)) {
1052 $result = $this->
call_trigger(
'COMPANY_CREATE', $user);
1062 dol_syslog(get_class($this).
"::Create success id=".$this->
id);
1063 $this->db->commit();
1066 dol_syslog(get_class($this).
"::Create echec update ".$this->error.(empty($this->errors) ?
'' :
' '.join(
',', $this->errors)), LOG_ERR);
1067 $this->db->rollback();
1071 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1072 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", $this->name);
1075 $this->error = $this->db->lasterror();
1078 $this->db->rollback();
1082 $this->db->rollback();
1083 dol_syslog(get_class($this).
"::Create fails verify ".join(
',', $this->errors), LOG_WARNING);
1107 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1108 $contact =
new Contact($this->db);
1110 $contact->name = $this->name_bis;
1111 $contact->firstname = $this->firstname;
1112 $contact->civility_id = $this->civility_id;
1113 $contact->socid = $this->id;
1114 $contact->statut = 1;
1115 $contact->status = 1;
1117 $contact->country_id = $this->country_id;
1118 $contact->state_id = $this->state_id;
1119 $contact->address = $this->address;
1120 $contact->email = $this->email;
1121 $contact->zip = $this->zip;
1122 $contact->town = $this->town;
1123 $this->setUpperOrLowerCase();
1124 $contact->phone_pro = $this->phone;
1126 $contactId = $contact->create($user);
1127 if ($contactId < 0) {
1129 $this->error = $contact->error;
1130 $this->errors = $contact->errors;
1131 dol_syslog(get_class($this).
"::create_individual ERROR:".$this->error, LOG_ERR);
1134 if (empty($error) && is_array($tags) && !empty($tags)) {
1135 $result = $contact->setCategories($tags);
1138 $this->error = $contact->error;
1139 $this->errors = array_merge($this->errors, $contact->errors);
1140 dol_syslog(get_class($this).
"::create_individual Affect Tag ERROR:".$this->error, LOG_ERR);
1141 $contactId = $result;
1145 if (empty($error) &&
isModEnabled(
'mailing') && !empty($contact->email) && isset($no_email)) {
1146 $result = $contact->setNoEmail($no_email);
1148 $this->error = $contact->error;
1149 $this->errors = array_merge($this->errors, $contact->errors);
1150 dol_syslog(get_class($this).
"::create_individual set mailing status ERROR:".$this->error, LOG_ERR);
1151 $contactId = $result;
1155 if (empty($error)) {
1156 dol_syslog(get_class($this).
"::create_individual success");
1157 $this->db->commit();
1159 $this->db->rollback();
1173 global $conf, $langs, $mysoc;
1176 $this->errors = array();
1180 $this->nom = $this->name;
1183 $this->errors[] =
'ErrorBadThirdPartyName';
1187 if ($this->client) {
1189 if ($rescode != 0 && $rescode != -5) {
1190 if ($rescode == -1) {
1191 $this->errors[] =
'ErrorBadCustomerCodeSyntax';
1192 } elseif ($rescode == -2) {
1193 $this->errors[] =
'ErrorCustomerCodeRequired';
1194 } elseif ($rescode == -3) {
1195 $this->errors[] =
'ErrorCustomerCodeAlreadyUsed';
1196 } elseif ($rescode == -4) {
1197 $this->errors[] =
'ErrorPrefixRequired';
1199 $this->errors[] =
'ErrorUnknownOnCustomerCodeCheck';
1206 if ($this->fournisseur) {
1208 if ($rescode != 0 && $rescode != -5) {
1209 if ($rescode == -1) {
1210 $this->errors[] =
'ErrorBadSupplierCodeSyntax';
1211 } elseif ($rescode == -2) {
1212 $this->errors[] =
'ErrorSupplierCodeRequired';
1213 } elseif ($rescode == -3) {
1214 $this->errors[] =
'ErrorSupplierCodeAlreadyUsed';
1215 } elseif ($rescode == -4) {
1216 $this->errors[] =
'ErrorPrefixRequired';
1218 $this->errors[] =
'ErrorUnknownOnSupplierCodeCheck';
1225 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL',
'TVA_INTRA');
1226 foreach ($array_to_check as $key) {
1227 $keymin = strtolower($key);
1228 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
1229 $vallabel = $this->$keymin;
1234 if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) {
1235 $idprof_mandatory =
'SOCIETE_'.$key.
'_MANDATORY';
1236 if (!$vallabel && !empty($conf->global->$idprof_mandatory)) {
1237 $langs->load(
"errors");
1239 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->transcountry(
'ProfId'.$i, $this->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1246 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1247 $langs->load(
"errors");
1249 $this->errors[] = $langs->transcountry(
'ProfId'.$i, $this->country_code).
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1255 if ($key ==
'EMAIL') {
1257 if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email)) {
1258 $langs->load(
"errors");
1260 $this->errors[] = $langs->trans(
"ErrorBadEMail", $this->email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1264 if (!$error && $vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE)) {
1265 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1266 $langs->load(
"errors");
1267 $error++; $this->errors[] = $langs->trans(
'Email').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1270 } elseif ($key ==
'TVA_INTRA') {
1272 if ($vallabel && !empty($conf->global->SOCIETE_VAT_INTRA_UNIQUE)) {
1273 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1274 $langs->load(
"errors");
1275 $error++; $this->errors[] = $langs->trans(
'VATIntra').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1301 public function update($id, $user =
'', $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action =
'update', $nosyncmember = 1)
1303 global $langs, $conf, $hookmanager;
1305 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1313 dol_syslog(get_class($this).
"::Update id=".$id.
" call_trigger=".$call_trigger.
" allowmodcodeclient=".$allowmodcodeclient.
" allowmodcodefournisseur=".$allowmodcodefournisseur);
1319 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
1320 $this->
name = $this->
name ? trim($this->
name) : trim($this->nom);
1321 $this->nom = $this->name;
1322 $this->name_alias = trim($this->name_alias);
1323 $this->ref_ext = trim($this->ref_ext);
1324 $this->address = $this->address ?trim($this->address) : trim($this->address);
1325 $this->zip = $this->zip ?trim($this->zip) : trim($this->zip);
1326 $this->town = $this->town ?trim($this->town) : trim($this->town);
1327 $this->state_id = trim($this->state_id);
1328 $this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
1329 $this->phone = trim($this->phone);
1330 $this->phone = preg_replace(
"/\s/",
"", $this->phone);
1331 $this->phone = preg_replace(
"/\./",
"", $this->phone);
1332 $this->fax = trim($this->fax);
1333 $this->fax = preg_replace(
"/\s/",
"", $this->fax);
1334 $this->fax = preg_replace(
"/\./",
"", $this->fax);
1335 $this->email = trim($this->email);
1336 $this->url = $this->url ?
clean_url($this->url, 0) :
'';
1337 $this->note_private = trim($this->note_private);
1338 $this->note_public = trim($this->note_public);
1339 $this->idprof1 = trim($this->idprof1);
1340 $this->idprof2 = trim($this->idprof2);
1341 $this->idprof3 = trim($this->idprof3);
1342 $this->idprof4 = trim($this->idprof4);
1343 $this->idprof5 = (!empty($this->idprof5) ?trim($this->idprof5) :
'');
1344 $this->idprof6 = (!empty($this->idprof6) ?trim($this->idprof6) :
'');
1345 $this->prefix_comm = trim($this->prefix_comm);
1346 $this->outstanding_limit =
price2num($this->outstanding_limit);
1347 $this->order_min_amount =
price2num($this->order_min_amount);
1348 $this->supplier_order_min_amount =
price2num($this->supplier_order_min_amount);
1350 $this->tva_assuj = trim($this->tva_assuj);
1352 $this->vat_reverse_charge = empty($this->vat_reverse_charge) ?
'0' :
'1';
1353 if (empty($this->status)) {
1357 if (!empty($this->multicurrency_code)) {
1360 if (empty($this->fk_multicurrency)) {
1361 $this->multicurrency_code =
'';
1362 $this->fk_multicurrency = 0;
1366 $this->localtax1_assuj = trim($this->localtax1_assuj);
1367 $this->localtax2_assuj = trim($this->localtax2_assuj);
1369 $this->localtax1_value = trim($this->localtax1_value);
1370 $this->localtax2_value = trim($this->localtax2_value);
1372 if ($this->capital !=
'') {
1373 $this->capital =
price2num(trim($this->capital));
1375 if (!is_numeric($this->capital)) {
1376 $this->capital =
'';
1379 $this->effectif_id = trim($this->effectif_id);
1380 $this->forme_juridique_code = trim($this->forme_juridique_code);
1383 $this->barcode = trim($this->barcode);
1386 if ($this->code_client == -1 || $this->code_client ===
'auto') {
1389 if ($this->code_fournisseur == -1 || $this->code_fournisseur ===
'auto') {
1393 $this->code_compta_client = trim(empty($this->code_compta) ? $this->code_compta_client : $this->code_compta);
1394 $this->code_compta = $this->code_compta_client;
1395 $this->code_compta_fournisseur = trim($this->code_compta_fournisseur);
1398 if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) {
1399 $langs->load(
"errors");
1400 $this->error = $langs->trans(
"BadValueForParameterClientOrSupplier");
1405 if (!empty($allowmodcodeclient) && !empty($this->client)) {
1407 if (empty($this->code_compta_client)) {
1418 if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) {
1420 if (empty($this->code_compta_fournisseur)) {
1431 $this->webservices_url = $this->webservices_url ?
clean_url($this->webservices_url, 0) :
'';
1432 $this->webservices_key = trim($this->webservices_key);
1434 $this->accountancy_code_buy = trim($this->accountancy_code_buy);
1435 $this->accountancy_code_sell = trim($this->accountancy_code_sell);
1438 $this->fk_incoterms = (int) $this->fk_incoterms;
1439 $this->location_incoterms = trim($this->location_incoterms);
1446 if ($action !=
'add' && $action !=
'merge') {
1449 $result = $this->
verify();
1453 if (is_array($this->errors)) {
1454 if (in_array(
'ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) {
1455 if (($key = array_search(
'ErrorBadCustomerCodeSyntax', $this->errors)) !==
false) {
1456 unset($this->errors[$key]);
1459 if (in_array(
'ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) {
1460 if (($key = array_search(
'ErrorBadSupplierCodeSyntax', $this->errors)) !==
false) {
1461 unset($this->errors[$key]);
1464 if (empty($this->errors)) {
1469 $this->setUpperOrLowerCase();
1471 dol_syslog(get_class($this).
"::update verify ok or not done");
1473 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe SET ";
1474 $sql .=
"entity = ".$this->db->escape($this->entity);
1475 $sql .=
",nom = '".$this->db->escape($this->
name).
"'";
1476 $sql .=
",name_alias = '".$this->db->escape($this->name_alias).
"'";
1477 $sql .=
",ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1478 $sql .=
",address = '".$this->db->escape($this->address).
"'";
1480 $sql .=
",zip = ".(!empty($this->zip) ?
"'".$this->db->escape($this->zip).
"'" :
"null");
1481 $sql .=
",town = ".(!empty($this->town) ?
"'".$this->db->escape($this->town).
"'" :
"null");
1483 $sql .=
",fk_departement = ".((!empty($this->state_id) && $this->state_id > 0) ? ((
int) $this->state_id) :
'null');
1484 $sql .=
",fk_pays = ".((!empty($this->country_id) && $this->country_id > 0) ? ((
int) $this->country_id) :
'null');
1486 $sql .=
",phone = ".(!empty($this->phone) ?
"'".$this->db->escape($this->phone).
"'" :
"null");
1487 $sql .=
",fax = ".(!empty($this->fax) ?
"'".$this->db->escape($this->fax).
"'" :
"null");
1488 $sql .=
",email = ".(!empty($this->email) ?
"'".$this->db->escape($this->email).
"'" :
"null");
1489 $sql .=
",socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1490 $sql .=
",url = ".(!empty($this->url) ?
"'".$this->db->escape($this->url).
"'" :
"null");
1492 $sql .=
",parent = ".($this->parent > 0 ? $this->parent :
"null");
1494 $sql .=
",note_private = ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
1495 $sql .=
",note_public = ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
1497 $sql .=
",siren = '".$this->db->escape($this->idprof1).
"'";
1498 $sql .=
",siret = '".$this->db->escape($this->idprof2).
"'";
1499 $sql .=
",ape = '".$this->db->escape($this->idprof3).
"'";
1500 $sql .=
",idprof4 = '".$this->db->escape($this->idprof4).
"'";
1501 $sql .=
",idprof5 = '".$this->db->escape($this->idprof5).
"'";
1502 $sql .=
",idprof6 = '".$this->db->escape($this->idprof6).
"'";
1504 $sql .=
",tva_assuj = ".($this->tva_assuj !=
'' ?
"'".$this->db->escape($this->tva_assuj).
"'" :
"null");
1505 $sql .=
",tva_intra = '".$this->db->escape($this->tva_intra).
"'";
1506 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1507 $sql .=
",vat_reverse_charge = " . ($this->vat_reverse_charge !=
'' ?
"'" . $this->db->escape($this->vat_reverse_charge) .
"'" : 0);
1509 $sql .=
",status = ".((int) $this->status);
1512 $sql .=
",localtax1_assuj = ".($this->localtax1_assuj !=
'' ?
"'".$this->db->escape($this->localtax1_assuj).
"'" :
"null");
1513 $sql .=
",localtax2_assuj = ".($this->localtax2_assuj !=
'' ?
"'".$this->db->escape($this->localtax2_assuj).
"'" :
"null");
1514 if ($this->localtax1_assuj == 1) {
1515 if ($this->localtax1_value !=
'') {
1516 $sql .=
",localtax1_value =".$this->localtax1_value;
1518 $sql .=
",localtax1_value =0.000";
1521 $sql .=
",localtax1_value =0.000";
1524 if ($this->localtax2_assuj == 1) {
1525 if ($this->localtax2_value !=
'') {
1526 $sql .=
",localtax2_value =".$this->localtax2_value;
1528 $sql .=
",localtax2_value =0.000";
1531 $sql .=
",localtax2_value =0.000";
1534 $sql .=
",capital = ".($this->capital ==
'' ?
"null" : $this->capital);
1536 $sql .=
",prefix_comm = ".(!empty($this->prefix_comm) ?
"'".$this->db->escape($this->prefix_comm).
"'" :
"null");
1538 $sql .=
",fk_effectif = ".($this->effectif_id > 0 ? ((int) $this->effectif_id) :
"null");
1539 if (isset($this->stcomm_id)) {
1540 $sql .=
",fk_stcomm=".(int) $this->stcomm_id;
1542 if (isset($this->typent_id)) {
1543 $sql .=
",fk_typent = ".($this->typent_id > 0 ? ((int) $this->typent_id) :
"0");
1546 $sql .=
",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ?
"'".$this->db->escape($this->forme_juridique_code).
"'" :
"null");
1548 $sql .=
",mode_reglement = ".(!empty($this->mode_reglement_id) ?
"'".$this->db->escape($this->mode_reglement_id).
"'" :
"null");
1549 $sql .=
",cond_reglement = ".(!empty($this->cond_reglement_id) ?
"'".$this->db->escape($this->cond_reglement_id).
"'" :
"null");
1550 $sql .=
",deposit_percent = ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null");
1551 $sql .=
",transport_mode = ".(!empty($this->transport_mode_id) ?
"'".$this->db->escape($this->transport_mode_id).
"'" :
"null");
1552 $sql .=
",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ?
"'".$this->db->escape($this->mode_reglement_supplier_id).
"'" :
"null");
1553 $sql .=
",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ?
"'".$this->db->escape($this->cond_reglement_supplier_id).
"'" :
"null");
1554 $sql .=
",transport_mode_supplier = ".(!empty($this->transport_mode_supplier_id) ?
"'".$this->db->escape($this->transport_mode_supplier_id).
"'" :
"null");
1555 $sql .=
",fk_shipping_method = ".(!empty($this->shipping_method_id) ?
"'".$this->db->escape($this->shipping_method_id).
"'" :
"null");
1557 $sql .=
",client = ".(!empty($this->client) ? $this->client : 0);
1558 $sql .=
",fournisseur = ".(!empty($this->fournisseur) ? $this->fournisseur : 0);
1559 $sql .=
",barcode = ".(!empty($this->barcode) ?
"'".$this->db->escape($this->barcode).
"'" :
"null");
1560 $sql .=
",default_lang = ".(!empty($this->default_lang) ?
"'".$this->db->escape($this->default_lang).
"'" :
"null");
1561 $sql .=
",logo = ".(!empty($this->logo) ?
"'".$this->db->escape($this->logo).
"'" :
"null");
1562 $sql .=
",logo_squarred = ".(!empty($this->logo_squarred) ?
"'".$this->db->escape($this->logo_squarred).
"'" :
"null");
1563 $sql .=
",outstanding_limit= ".($this->outstanding_limit !=
'' ? $this->outstanding_limit :
'null');
1564 $sql .=
",order_min_amount= ".($this->order_min_amount !=
'' ? $this->order_min_amount :
'null');
1565 $sql .=
",supplier_order_min_amount= ".($this->supplier_order_min_amount !=
'' ? $this->supplier_order_min_amount :
'null');
1566 $sql .=
",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel).
"'";
1567 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1568 $sql .=
", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1569 $sql .=
", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1571 $sql .=
", code_compta = ".(!empty($this->code_compta_client) ?
"'".$this->db->escape($this->code_compta_client).
"'" :
"null");
1575 $sql .=
", code_compta_fournisseur = ".(($this->code_compta_fournisseur !=
"") ?
"'".$this->db->escape($this->code_compta_fournisseur).
"'" :
"null");
1578 $sql .=
",webservices_url = ".(!empty($this->webservices_url) ?
"'".$this->db->escape($this->webservices_url).
"'" :
"null");
1579 $sql .=
",webservices_key = ".(!empty($this->webservices_key) ?
"'".$this->db->escape($this->webservices_key).
"'" :
"null");
1582 $sql .=
", fk_incoterms = ".((int) $this->fk_incoterms);
1583 $sql .=
", location_incoterms = ".(!empty($this->location_incoterms) ?
"'".$this->db->escape($this->location_incoterms).
"'" :
"null");
1586 $sql .=
", code_client = ".(!empty($this->code_client) ?
"'".$this->db->escape($this->code_client).
"'" :
"null");
1590 $sql .=
", code_fournisseur = ".(!empty($this->code_fournisseur) ?
"'".$this->db->escape($this->code_fournisseur).
"'" :
"null");
1592 $sql .=
", fk_user_modif = ".($user->id > 0 ? $user->id :
"null");
1593 $sql .=
", fk_multicurrency = ".(int) $this->fk_multicurrency;
1594 $sql .=
", multicurrency_code = '".$this->db->escape($this->multicurrency_code).
"'";
1595 $sql .=
", model_pdf = '".$this->db->escape($this->model_pdf).
"'";
1596 $sql .=
" WHERE rowid = ".(int) $id;
1598 $resql = $this->db->query(
$sql);
1600 if (is_object($this->oldcopy)) {
1601 if ($this->oldcopy->country_id != $this->country_id) {
1602 unset($this->country_code);
1603 unset($this->country);
1605 if ($this->oldcopy->state_id != $this->state_id) {
1606 unset($this->state_code);
1607 unset($this->state);
1610 unset($this->country_code);
1611 unset($this->country);
1612 unset($this->state_code);
1613 unset($this->state);
1616 $nbrowsaffected = $this->db->affected_rows($resql);
1618 if (!$error && $nbrowsaffected) {
1621 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1623 dol_syslog(get_class($this).
"::update update linked member");
1625 $lmember =
new Adherent($this->db);
1626 $result = $lmember->fetch(0, 0, $this->
id);
1629 $lmember->company = $this->name;
1632 $lmember->address = $this->address;
1633 $lmember->zip = $this->zip;
1634 $lmember->town = $this->town;
1635 $lmember->email = $this->email;
1636 $lmember->socialnetworks = $this->socialnetworks;
1637 $lmember->phone = $this->phone;
1638 $lmember->state_id = $this->state_id;
1639 $lmember->country_id = $this->country_id;
1640 $lmember->default_lang = $this->default_lang;
1642 $result = $lmember->update($user, 0, 1, 1, 1);
1644 $this->error = $lmember->error;
1645 $this->errors = array_merge($this->errors, $lmember->errors);
1646 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
1649 } elseif ($result < 0) {
1650 $this->error = $lmember->error;
1659 if (!$error && !empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1660 $this->db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int) $conf->entity));
1662 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
1665 $sql .=
", vat_reverse_charge";
1666 $sql .=
", accountancy_code_customer";
1667 $sql .=
", accountancy_code_supplier";
1668 $sql .=
", accountancy_code_buy";
1669 $sql .=
", accountancy_code_sell";
1670 $sql .=
") VALUES (";
1672 $sql .=
", ".$conf->entity;
1673 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1674 $sql .=
", '".$this->db->escape($this->code_compta_client).
"'";
1675 $sql .=
", '".$this->db->escape($this->code_compta_fournisseur).
"'";
1676 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1677 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1679 $result = $this->db->query(
$sql);
1682 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1694 if (!$error && empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) {
1701 if (!$error && $call_trigger) {
1703 $result = $this->
call_trigger(
'COMPANY_MODIFY', $user);
1711 dol_syslog(get_class($this).
"::Update success");
1712 $this->db->commit();
1715 $this->db->rollback();
1719 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1721 $this->error = $langs->trans(
"ErrorDuplicateField");
1724 $this->error = $this->db->lasterror();
1727 $this->db->rollback();
1731 $this->db->rollback();
1732 dol_syslog(get_class($this).
"::Update fails verify ".join(
',', $this->errors), LOG_WARNING);
1754 public function fetch($rowid, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'')
1759 if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) {
1763 $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';
1764 $sql .=
', s.status, s.fk_warehouse';
1765 $sql .=
', s.price_level';
1766 $sql .=
', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif';
1767 $sql .=
', s.phone, s.fax, s.email';
1768 $sql .=
', s.socialnetworks';
1769 $sql .=
', s.url, s.zip, s.town, s.note_private, s.note_public, s.client, s.fournisseur';
1770 $sql .=
', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1771 $sql .=
', s.capital, s.tva_intra';
1772 $sql .=
', s.fk_typent as typent_id';
1773 $sql .=
', s.fk_effectif as effectif_id';
1774 $sql .=
', s.fk_forme_juridique as forme_juridique_code';
1775 $sql .=
', s.webservices_url, s.webservices_key, s.model_pdf, s.last_main_doc';
1776 if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1777 $sql .=
', s.code_compta, s.code_compta_fournisseur, s.accountancy_code_buy, s.accountancy_code_sell';
1778 $sql .=
', s.vat_reverse_charge as soc_vat_reverse_charge';
1780 $sql .=
', spe.accountancy_code_customer as code_compta, spe.accountancy_code_supplier as code_compta_fournisseur, spe.accountancy_code_buy, spe.accountancy_code_sell';
1781 $sql .=
', spe.vat_reverse_charge as spe_vat_reverse_charge';
1783 $sql .=
', s.code_client, s.code_fournisseur, s.parent, s.barcode';
1784 $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';
1785 $sql .=
', s.fk_account, s.tva_assuj';
1786 $sql .=
', s.mode_reglement_supplier, s.cond_reglement_supplier, s.transport_mode_supplier';
1787 $sql .=
', s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred';
1788 $sql .=
', s.fk_shipping_method';
1789 $sql .=
', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1790 $sql .=
', s.order_min_amount, s.supplier_order_min_amount';
1791 $sql .=
', s.fk_multicurrency, s.multicurrency_code';
1792 $sql .=
', fj.libelle as forme_juridique';
1793 $sql .=
', e.libelle as effectif';
1794 $sql .=
', c.code as country_code, c.label as country';
1795 $sql .=
', d.code_departement as state_code, d.nom as state';
1796 $sql .=
', r.rowid as region_id, r.code_region as region_code';
1797 $sql .=
', st.libelle as stcomm, st.picto as stcomm_picto';
1798 $sql .=
', te.code as typent_code';
1799 $sql .=
', i.libelle as label_incoterms';
1801 $sql .=
', s.remise_client, s.remise_supplier';
1803 $sql .=
', sr.remise_client, sr2.remise_supplier';
1805 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
1806 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
1807 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = ".((int) $conf->entity);
1809 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_effectif as e ON s.fk_effectif = e.id';
1810 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON s.fk_pays = c.rowid';
1811 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcomm as st ON s.fk_stcomm = st.id';
1812 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
1813 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON s.fk_departement = d.rowid';
1814 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_regions as r ON d.fk_region = r.code_region ';
1815 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_typent as te ON s.fk_typent = te.id';
1816 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON s.fk_incoterms = i.rowid';
1820 $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').
'))';
1821 $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').
'))';
1823 $sql .=
' WHERE s.entity IN ('.getEntity($this->element).
')';
1825 $sql .=
' AND s.rowid = '.((int) $rowid);
1828 $sql .=
" AND s.nom = '".$this->db->escape($ref).
"'";
1831 $sql .=
" AND s.name_alias = '".$this->db->escape($ref_alias).
"'";
1834 $sql .=
" AND s.ref_ext = '".$this->db->escape($ref_ext).
"'";
1837 $sql .=
" AND s.barcode = '".$this->db->escape($barcode).
"'";
1840 $sql .=
" AND s.siren = '".$this->db->escape($idprof1).
"'";
1843 $sql .=
" AND s.siret = '".$this->db->escape($idprof2).
"'";
1846 $sql .=
" AND s.ape = '".$this->db->escape($idprof3).
"'";
1849 $sql .=
" AND s.idprof4 = '".$this->db->escape($idprof4).
"'";
1852 $sql .=
" AND s.idprof5 = '".$this->db->escape($idprof5).
"'";
1855 $sql .=
" AND s.idprof6 = '".$this->db->escape($idprof6).
"'";
1858 $sql .=
" AND s.email = '".$this->db->escape($email).
"'";
1861 $resql = $this->db->query(
$sql);
1863 $num = $this->db->num_rows($resql);
1865 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
1869 $obj = $this->db->fetch_object($resql);
1871 $this->
id = $obj->rowid;
1872 $this->entity = $obj->entity;
1873 $this->canvas = $obj->canvas;
1875 $this->
ref = $obj->rowid;
1876 $this->
name = $obj->name;
1877 $this->nom = $obj->name;
1878 $this->name_alias = $obj->name_alias;
1879 $this->ref_ext = $obj->ref_ext;
1881 $this->date_creation = $this->db->jdate($obj->date_creation);
1882 $this->date_modification = $this->db->jdate($obj->date_modification);
1883 $this->user_creation = $obj->fk_user_creat;
1884 $this->user_modification = $obj->fk_user_modif;
1886 $this->address = $obj->address;
1887 $this->zip = $obj->zip;
1888 $this->town = $obj->town;
1890 $this->country_id = $obj->country_id;
1891 $this->country_code = $obj->country_id ? $obj->country_code :
'';
1892 $this->country = $obj->country_id ? (($langs->transnoentities(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code) ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
1894 $this->state_id = $obj->state_id;
1895 $this->state_code = $obj->state_code;
1896 $this->region_id = $obj->region_id;
1897 $this->region_code = $obj->region_code;
1898 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
1900 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcomm);
1901 $label = ($transcode !=
'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm);
1902 $this->stcomm_id = $obj->fk_stcomm;
1903 $this->status_prospect_label = $label;
1904 $this->stcomm_picto = $obj->stcomm_picto;
1906 $this->email = $obj->email;
1907 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
1909 $this->url = $obj->url;
1910 $this->phone = $obj->phone;
1911 $this->fax = $obj->fax;
1913 $this->parent = $obj->parent;
1915 $this->idprof1 = $obj->idprof1;
1916 $this->idprof2 = $obj->idprof2;
1917 $this->idprof3 = $obj->idprof3;
1918 $this->idprof4 = $obj->idprof4;
1919 $this->idprof5 = $obj->idprof5;
1920 $this->idprof6 = $obj->idprof6;
1922 $this->capital = $obj->capital;
1924 $this->code_client = $obj->code_client;
1925 $this->code_fournisseur = $obj->code_fournisseur;
1927 $this->code_compta = $obj->code_compta;
1928 $this->code_compta_client = $obj->code_compta;
1929 $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
1931 $this->barcode = $obj->barcode;
1933 $this->tva_assuj = $obj->tva_assuj;
1934 $this->tva_intra = $obj->tva_intra;
1936 if (!empty($obj->spe_vat_reverse_charge)) {
1937 $this->vat_reverse_charge = $obj->spe_vat_reverse_charge;
1938 } elseif (!empty($obj->soc_vat_reverse_charge)) {
1939 $this->vat_reverse_charge = $obj->soc_vat_reverse_charge;
1941 $this->vat_reverse_charge = 0;
1944 $this->status = $obj->status;
1947 $this->localtax1_assuj = $obj->localtax1_assuj;
1948 $this->localtax2_assuj = $obj->localtax2_assuj;
1950 $this->localtax1_value = $obj->localtax1_value;
1951 $this->localtax2_value = $obj->localtax2_value;
1953 $this->typent_id = $obj->typent_id;
1954 $this->typent_code = $obj->typent_code;
1956 $this->effectif_id = $obj->effectif_id;
1957 $this->effectif = $obj->effectif_id ? $obj->effectif :
'';
1959 $this->forme_juridique_code = $obj->forme_juridique_code;
1960 $this->forme_juridique = $obj->forme_juridique_code ? $obj->forme_juridique :
'';
1962 $this->fk_prospectlevel = $obj->fk_prospectlevel;
1964 $this->prefix_comm = $obj->prefix_comm;
1966 $this->remise_percent = $obj->remise_client ?
price2num($obj->remise_client) : 0;
1967 $this->remise_supplier_percent = $obj->remise_supplier;
1969 $this->mode_reglement_id = $obj->mode_reglement;
1970 $this->cond_reglement_id = $obj->cond_reglement;
1971 $this->deposit_percent = $obj->deposit_percent;
1972 $this->transport_mode_id = $obj->transport_mode;
1973 $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier;
1974 $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier;
1975 $this->transport_mode_supplier_id = $obj->transport_mode_supplier;
1976 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
1977 $this->fk_account = $obj->fk_account;
1979 $this->client = $obj->client;
1980 $this->fournisseur = $obj->fournisseur;
1982 $this->note = $obj->note_private;
1983 $this->note_private = $obj->note_private;
1984 $this->note_public = $obj->note_public;
1985 $this->model_pdf = $obj->model_pdf;
1986 $this->modelpdf = $obj->model_pdf;
1987 $this->default_lang = $obj->default_lang;
1988 $this->logo = $obj->logo;
1989 $this->logo_squarred = $obj->logo_squarred;
1991 $this->webservices_url = $obj->webservices_url;
1992 $this->webservices_key = $obj->webservices_key;
1994 $this->accountancy_code_buy = $obj->accountancy_code_buy;
1995 $this->accountancy_code_sell = $obj->accountancy_code_sell;
1997 $this->outstanding_limit = $obj->outstanding_limit;
1998 $this->order_min_amount = $obj->order_min_amount;
1999 $this->supplier_order_min_amount = $obj->supplier_order_min_amount;
2002 $this->price_level = $obj->price_level;
2005 $this->fk_warehouse = $obj->fk_warehouse;
2007 $this->import_key = $obj->import_key;
2010 $this->fk_incoterms = $obj->fk_incoterms;
2011 $this->location_incoterms = $obj->location_incoterms;
2012 $this->label_incoterms = $obj->label_incoterms;
2015 $this->fk_multicurrency = $obj->fk_multicurrency;
2016 $this->multicurrency_code = $obj->multicurrency_code;
2019 $this->model_pdf = $obj->model_pdf;
2020 $this->last_main_doc = $obj->last_main_doc;
2025 $this->fetch_optionals();
2030 $this->db->free($resql);
2032 $this->error = $this->db->lasterror();
2033 $this->errors[] = $this->db->lasterror();
2038 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($this->price_level)) {
2039 $this->price_level = 1;
2053 public function delete($id,
User $fuser =
null, $call_trigger = 1)
2055 global $langs, $conf, $user;
2057 if (empty($fuser)) {
2061 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2063 $entity = isset($this->entity) ? $this->entity : $conf->entity;
2065 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2070 if (empty($objectisused)) {
2074 if (!$error && $call_trigger) {
2076 $result = $this->
call_trigger(
'COMPANY_DELETE', $fuser);
2084 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2086 $toute_categs = array();
2089 if ($this->client || $this->prospect) {
2090 $toute_categs[
'customer'] = $static_cat->containing($this->
id, Categorie::TYPE_CUSTOMER);
2092 if ($this->fournisseur) {
2093 $toute_categs[
'supplier'] = $static_cat->containing($this->
id, Categorie::TYPE_SUPPLIER);
2097 foreach ($toute_categs as $type => $categs_type) {
2098 foreach ($categs_type as $cat) {
2099 $cat->del_type($this, $type);
2105 foreach ($this->childtablesoncascade as $tabletodelete) {
2106 $deleteFromObject = explode(
':', $tabletodelete);
2107 if (count($deleteFromObject) >= 2) {
2108 $className = str_replace(
'@',
'', $deleteFromObject[0]);
2109 $filepath = $deleteFromObject[1];
2110 $columnName = $deleteFromObject[2];
2112 $child_object =
new $className($this->db);
2113 $result = $child_object->deleteByParentField($id, $columnName);
2116 $this->errors[] = $child_object->error;
2121 $this->errors[] =
'Cannot include child class file '.$filepath;
2125 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
2126 $sql .=
" WHERE fk_soc = ".((int) $id);
2127 if (!$this->db->query(
$sql)) {
2129 $this->errors[] = $this->db->lasterror();
2141 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
2147 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2148 $sql .=
" SET parent = NULL";
2149 $sql .=
" WHERE parent = ".((int) $id);
2150 if (!$this->db->query(
$sql)) {
2152 $this->errors[] = $this->db->lasterror();
2158 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
2159 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity";
2160 $sql .=
" WHERE fk_soc = ".((int) $id);
2161 if (!$this->db->query(
$sql)) {
2163 $this->errors[] = $this->db->lasterror();
2167 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe";
2168 $sql .=
" WHERE rowid = ".((int) $id);
2169 if (!$this->db->query(
$sql)) {
2171 $this->errors[] = $this->db->lasterror();
2176 $this->db->commit();
2179 if (!empty($conf->societe->multidir_output[$entity])) {
2180 $docdir = $conf->societe->multidir_output[$entity].
"/".$id;
2189 $this->db->rollback();
2193 dol_syslog(
"Can't remove thirdparty with id ".$id.
". There is ".$objectisused.
" childs", LOG_WARNING);
2209 if ($this->client == 2 || $this->client == 3) {
2212 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2213 $sql .=
" SET client = ".((int) $newclient);
2214 $sql .=
" WHERE rowid = ".((int) $this->
id);
2216 $resql = $this->db->query(
$sql);
2218 $this->client = $newclient;
2239 global $conf, $langs;
2242 $note = trim($note);
2244 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2248 dol_syslog(get_class($this).
"::set_remise_client ".$remise.
", ".$note.
", ".$user->id);
2256 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2257 $sql .=
" SET remise_client = '".$this->db->escape($remise).
"'";
2258 $sql .=
" WHERE rowid = ".((int) $this->
id);
2259 $resql = $this->db->query(
$sql);
2261 $this->db->rollback();
2262 $this->error = $this->db->error();
2267 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise";
2268 $sql .=
" (entity, datec, fk_soc, remise_client, note, fk_user_author)";
2269 $sql .=
" VALUES (".$conf->entity.
", '".$this->db->idate($now).
"', ".((int) $this->
id).
", '".$this->db->escape($remise).
"',";
2270 $sql .=
" '".$this->db->escape($note).
"',";
2271 $sql .=
" ".((int) $user->id);
2274 $resql = $this->db->query(
$sql);
2276 $this->db->rollback();
2277 $this->error = $this->db->lasterror();
2281 $this->db->commit();
2299 global $conf, $langs;
2302 $note = trim($note);
2304 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2308 dol_syslog(get_class($this).
"::set_remise_supplier ".$remise.
", ".$note.
", ".$user->id);
2316 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2317 $sql .=
" SET remise_supplier = '".$this->db->escape($remise).
"'";
2318 $sql .=
" WHERE rowid = ".((int) $this->
id);
2319 $resql = $this->db->query(
$sql);
2321 $this->db->rollback();
2322 $this->error = $this->db->error();
2327 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise_supplier";
2328 $sql .=
" (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
2329 $sql .=
" VALUES (".$conf->entity.
", '".$this->db->idate($now).
"', ".((int) $this->
id).
", '".$this->db->escape($remise).
"',";
2330 $sql .=
" '".$this->db->escape($note).
"',";
2331 $sql .=
" ".((int) $user->id);
2334 $resql = $this->db->query(
$sql);
2336 $this->db->rollback();
2337 $this->error = $this->db->lasterror();
2341 $this->db->commit();
2360 public function set_remise_except($remise,
User $user, $desc, $vatrate =
'', $discount_type = 0, $price_base_type =
'HT')
2367 $desc = trim($desc);
2370 if (!($remise > 0)) {
2371 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"1");
2375 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"3");
2379 if ($this->
id > 0) {
2383 if (preg_match(
'/\((.*)\)/', $vatrate, $reg)) {
2384 $vat_src_code = $reg[1];
2385 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2388 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2391 $discount->fk_soc = $this->id;
2393 $discount->discount_type = $discount_type;
2395 if ($price_base_type ==
'TTC') {
2396 $discount->amount_ttc = $discount->multicurrency_amount_ttc =
price2num($remise,
'MT');
2397 $discount->amount_ht = $discount->multicurrency_amount_ht =
price2num($remise / (1 + $vatrate / 100),
'MT');
2398 $discount->amount_tva = $discount->multicurrency_amount_tva =
price2num($discount->amount_ttc - $discount->amount_ht,
'MT');
2400 $discount->amount_ht = $discount->multicurrency_amount_ht =
price2num($remise,
'MT');
2401 $discount->amount_tva = $discount->multicurrency_amount_tva =
price2num($remise * $vatrate / 100,
'MT');
2402 $discount->amount_ttc = $discount->multicurrency_amount_ttc =
price2num($discount->amount_ht + $discount->amount_tva,
'MT');
2405 $discount->tva_tx =
price2num($vatrate);
2406 $discount->vat_src_code = $vat_src_code;
2408 $discount->description = $desc;
2410 $result = $discount->create($user);
2414 $this->error = $discount->error;
2433 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2436 $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type);
2440 $this->error = $discountstatic->error;
2458 $reparray = array();
2460 $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";
2461 $sql .=
", u.office_fax, u.user_mobile, u.personal_mobile";
2462 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc, ".MAIN_DB_PREFIX.
"user as u";
2463 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2464 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
2465 $sql .=
" WHERE ((ug.fk_user = sc.fk_user";
2466 $sql .=
" AND ug.entity = ".$conf->entity.
")";
2467 $sql .=
" OR u.admin = 1)";
2469 $sql .=
" WHERE entity in (0, ".$conf->entity.
")";
2472 $sql .=
" AND u.rowid = sc.fk_user AND sc.fk_soc = ".((int) $this->
id);
2473 if (empty($sortfield) && empty($sortorder)) {
2474 $sortfield =
'u.lastname,u.firstname';
2475 $sortorder =
'ASC,ASC';
2477 $sql .= $this->db->order($sortfield, $sortorder);
2479 $resql = $this->db->query(
$sql);
2481 $num = $this->db->num_rows($resql);
2484 $obj = $this->db->fetch_object($resql);
2487 $reparray[$i][
'id'] = $obj->rowid;
2488 $reparray[$i][
'lastname'] = $obj->lastname;
2489 $reparray[$i][
'firstname'] = $obj->firstname;
2490 $reparray[$i][
'email'] = $obj->email;
2491 $reparray[$i][
'phone'] = $obj->office_phone;
2492 $reparray[$i][
'office_phone'] = $obj->office_phone;
2493 $reparray[$i][
'office_fax'] = $obj->office_fax;
2494 $reparray[$i][
'user_mobile'] = $obj->user_mobile;
2495 $reparray[$i][
'personal_mobile'] = $obj->personal_mobile;
2496 $reparray[$i][
'job'] = $obj->job;
2497 $reparray[$i][
'statut'] = $obj->status;
2498 $reparray[$i][
'status'] = $obj->status;
2499 $reparray[$i][
'entity'] = $obj->entity;
2500 $reparray[$i][
'login'] = $obj->login;
2501 $reparray[$i][
'photo'] = $obj->photo;
2502 $reparray[$i][
'gender'] = $obj->gender;
2504 $reparray[] = $obj->rowid;
2527 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2528 $sql .=
" SET price_level = ".((int) $price_level);
2529 $sql .=
" WHERE rowid = ".((int) $this->
id);
2531 if (!$this->db->query(
$sql)) {
2536 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_prices";
2537 $sql .=
" (datec, fk_soc, price_level, fk_user_author)";
2538 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $this->
id).
", ".((int) $price_level).
", ".((int) $user->id).
")";
2540 if (!$this->db->query(
$sql)) {
2562 if ($this->
id > 0 && $commid > 0) {
2566 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux";
2567 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2569 $resql = $this->db->query(
$sql);
2571 dol_syslog(get_class($this).
"::add_commercial Error ".$this->db->lasterror());
2577 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_commerciaux";
2578 $sql .=
" (fk_soc, fk_user)";
2579 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $commid).
")";
2581 $resql = $this->db->query(
$sql);
2583 dol_syslog(get_class($this).
"::add_commercial Error ".$this->db->lasterror());
2589 $this->context = array(
'commercial_modified' => $commid);
2591 $result = $this->
call_trigger(
'COMPANY_LINK_SALE_REPRESENTATIVE', $user);
2598 $this->db->commit();
2601 $this->db->rollback();
2621 $this->context = array(
'commercial_modified'=>$commid);
2623 $result = $this->
call_trigger(
'COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
2628 if ($this->
id > 0 && $commid > 0) {
2629 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux ";
2630 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2632 if (!$this->db->query(
$sql)) {
2633 dol_syslog(get_class($this).
"::del_commercial Erreur");
2647 global $conf, $langs, $user;
2649 $langs->loadLangs([
'companies',
'commercial']);
2653 $option = $params[
'option'] ??
'';
2654 $nofetch = !empty($params[
'nofetch']);
2656 $name = $this->name;
2657 $noaliasinname = (empty($params[
'noaliasinname']) ? 0 : $params[
'noaliasinname']);
2659 if (!empty($this->name_alias) && empty($noaliasinname)) {
2660 $name .=
' ('.$this->name_alias.
')';
2662 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2663 return [
'optimize' => $langs->trans(
"ShowCompany")];
2666 if (!empty($this->logo) && class_exists(
'Form')) {
2667 $photo =
'<div class="photointooltip floatright">';
2668 $photo .=
Form::showphoto(
'societe', $this, 0, 40, 0,
'photoref',
'mini', 0);
2670 $datas[
'photo'] = $photo;
2671 } elseif (!empty($this->logo_squarred) && class_exists(
'Form')) {
2677 $datas[
'divopen'] =
'<div class="centpercent">';
2679 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
2680 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Customer").
'</u>';
2681 } elseif ($option ==
'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
2682 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Prospect").
'</u>';
2683 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
2684 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Supplier").
'</u>';
2685 } elseif ($option ==
'agenda') {
2686 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2687 } elseif ($option ==
'project') {
2688 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2689 } elseif ($option ==
'margin') {
2690 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2691 } elseif ($option ==
'contact') {
2692 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2693 } elseif ($option ==
'ban') {
2694 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2698 if (empty($datas[
'picto'])) {
2699 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2701 if (isset($this->status)) {
2702 $datas[
'status'] =
' '.$this->getLibStatut(5);
2704 if (isset($this->client) && isset($this->fournisseur)) {
2705 $datas[
'type'] =
' ' . $this->
getTypeUrl(1);
2708 if (!empty($this->name_alias)) {
2709 $datas[
'namealias'] =
' ('.dol_escape_htmltag($this->name_alias).
')';
2711 if (!empty($this->email)) {
2712 $datas[
'email'] =
'<br>'.img_picto(
'',
'email',
'class="pictofixedwidth"').$this->email;
2714 if (!empty($this->url)) {
2715 $datas[
'url'] =
'<br>'.img_picto(
'',
'globe',
'class="pictofixedwidth"').$this->url;
2717 if (!empty($this->phone) || !empty($this->fax)) {
2718 $phonelist = array();
2720 $phonelist[] =
dol_print_phone($this->phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2723 $phonelist[] =
dol_print_phone($this->fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2725 $datas[
'phonelist'] =
'<br>'.implode(
' ', $phonelist);
2728 if (!empty($this->address)) {
2729 $datas[
'address'] =
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
' ', $langs);
2730 } elseif (!empty($this->country_code)) {
2731 $datas[
'address'] =
'<br><b>'.$langs->trans(
'Country').
':</b> '.$this->country_code;
2733 if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'vatnumber') !==
false)) {
2734 $datas[
'vatintra'] =
'<br><b>'.$langs->trans(
'VATIntra').
':</b> '.
dol_escape_htmltag($this->tva_intra);
2737 if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP)) {
2738 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid1') !==
false && $langs->trans(
'ProfId1'.$this->country_code) !=
'-') {
2739 $datas[
'profid1'] =
'<br><b>'.$langs->trans(
'ProfId1'.$this->country_code).
':</b> '.$this->idprof1;
2741 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid2') !==
false && $langs->trans(
'ProfId2'.$this->country_code) !=
'-') {
2742 $datas[
'profid2'] =
'<br><b>'.$langs->trans(
'ProfId2'.$this->country_code).
':</b> '.$this->idprof2;
2744 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid3') !==
false && $langs->trans(
'ProfId3'.$this->country_code) !=
'-') {
2745 $datas[
'profid3'] =
'<br><b>'.$langs->trans(
'ProfId3'.$this->country_code).
':</b> '.$this->idprof3;
2747 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid4') !==
false && $langs->trans(
'ProfId4'.$this->country_code) !=
'-') {
2748 $datas[
'profid4'] =
'<br><b>'.$langs->trans(
'ProfId4'.$this->country_code).
':</b> '.$this->idprof4;
2750 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid5') !==
false && $langs->trans(
'ProfId5'.$this->country_code) !=
'-') {
2751 $datas[
'profid5'] =
'<br><b>'.$langs->trans(
'ProfId5'.$this->country_code).
':</b> '.$this->idprof5;
2753 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid6') !==
false && $langs->trans(
'ProfId6'.$this->country_code) !=
'-') {
2754 $datas[
'profid6'] =
'<br><b>'.$langs->trans(
'ProfId6'.$this->country_code).
':</b> '.$this->idprof6;
2758 $datas[
'separator'] =
'<br>';
2760 if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
2761 $datas[
'customercode'] =
'<br><b>'.$langs->trans(
'CustomerCode').
':</b> '.$this->code_client;
2763 if (
isModEnabled(
'accounting') && ($this->client == 1 || $this->client == 3)) {
2764 $langs->load(
'compta');
2765 $datas[
'accountancycustomercode'] =
'<br><b>'.$langs->trans(
'CustomerAccountancyCode').
':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client);
2768 if (!$nofetch &&
isModEnabled(
'categorie') && $this->client) {
2769 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2771 $datas[
'categories_customer'] =
'<br>' .
$form->showCategories($this->
id, Categorie::TYPE_CUSTOMER, 1, 1);
2773 if (!empty($this->code_fournisseur) && $this->fournisseur) {
2774 $datas[
'suppliercode'] =
'<br><b>'.$langs->trans(
'SupplierCode').
':</b> '.$this->code_fournisseur;
2776 if (
isModEnabled(
'accounting') && $this->fournisseur) {
2777 $langs->load(
'compta');
2778 $datas[
'accountancysuppliercode'] =
'<br><b>'.$langs->trans(
'SupplierAccountancyCode').
':</b> '.$this->code_compta_fournisseur;
2781 if (!$nofetch &&
isModEnabled(
'categorie') && $this->fournisseur) {
2782 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2784 $datas[
'categories_supplier'] =
'<br>' .
$form->showCategories($this->
id, Categorie::TYPE_SUPPLIER, 1, 1);
2787 $datas[
'divclose'] =
'</div>';
2804 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1, $noaliasinname = 0, $target =
'')
2806 global $conf, $langs, $hookmanager;
2808 if (!empty($conf->dol_no_mouse_hover)) {
2812 $name = $this->
name ? $this->
name : $this->nom;
2814 if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) {
2815 if (empty($option) && $this->client > 0) {
2816 $option =
'customer';
2818 if (empty($option) && $this->fournisseur > 0) {
2819 $option =
'supplier';
2823 if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto))) {
2825 if (($this->client) && (!empty($this->code_client)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 2)) {
2826 $code = $this->code_client.
' - ';
2829 if (($this->fournisseur) && (!empty($this->code_fournisseur)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 3)) {
2830 $code .= $this->code_fournisseur.
' - ';
2834 if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1) {
2835 $name = $code.
' '.$name;
2842 if (!empty($this->name_alias) && empty($noaliasinname)) {
2843 $name .=
' ('.$this->name_alias.
')';
2849 'objecttype' => $this->element,
2850 'option' => $option,
2853 $classfortooltip =
'classfortooltip';
2856 $classfortooltip =
'classforajaxtooltip';
2857 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2866 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
2867 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2868 } elseif ($option ==
'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
2869 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2870 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
2871 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->id;
2872 } elseif ($option ==
'agenda') {
2873 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/agenda.php?socid='.$this->id;
2874 } elseif ($option ==
'project') {
2875 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/project.php?socid='.$this->id;
2876 } elseif ($option ==
'margin') {
2877 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/margin/tabs/thirdpartyMargins.php?socid='.$this->
id.
'&type=1';
2878 } elseif ($option ==
'contact') {
2879 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/contact.php?socid='.$this->id;
2880 } elseif ($option ==
'ban') {
2881 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$this->id;
2885 if (empty($linkstart)) {
2886 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$this->id;
2890 $linkstart .= (!empty($this->canvas) ?
'&canvas='.$this->canvas :
'');
2892 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2893 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2894 $add_save_lastsearch_values = 1;
2896 if ($add_save_lastsearch_values) {
2897 $linkstart .=
'&save_lastsearch_values=1';
2902 if (empty($notooltip)) {
2903 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2904 $label = $langs->trans(
"ShowCompany");
2905 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2907 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
2908 $linkclose .= $dataparams.
' class="'.$classfortooltip.
' refurl valignmiddle"';
2909 $target_value = array(
'_self',
'_blank',
'_parent',
'_top');
2910 if (in_array($target, $target_value)) {
2911 $linkclose .=
' target="'.dol_escape_htmltag($target).
'"';
2914 $linkclose .=
' class="valignmiddle"';
2916 $linkstart .= $linkclose.
'>';
2920 if (empty($user->rights->societe->client->voir) && $user->socid > 0 && $this->id != $user->socid) {
2925 $result .= $linkstart;
2927 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (
' class="'.(($withpicto != 2) ?
'paddingright' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
2929 if ($withpicto != 2) {
2932 $result .= $linkend;
2935 $hookmanager->initHooks(array(
'thirdpartydao'));
2936 $parameters = array(
2938 'getnomurl' => &$result,
2939 'withpicto '=> $withpicto,
2942 'notooltip'=> $notooltip,
2943 'save_lastsearch_value'=> $save_lastsearch_value
2945 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2947 $result = $hookmanager->resPrint;
2949 $result .= $hookmanager->resPrint;
2964 public function getTypeUrl($withpicto = 0, $option =
'', $notooltip = 0, $tag =
'a')
2966 global $conf, $langs;
2969 if (empty($option) || preg_match(
'/prospect/', $option)) {
2970 if (($this->client == 2 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
2971 $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.
'>';
2974 if (empty($option) || preg_match(
'/customer/', $option)) {
2975 if (($this->client == 1 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
2976 $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.
'>';
2979 if (empty($option) || preg_match(
'/supplier/', $option)) {
2981 $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.
'>';
2996 return $this->
LibStatut($this->status, $mode);
3011 $langs->load(
'companies');
3013 $statusType =
'status4';
3015 $statusType =
'status6';
3018 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3019 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
3020 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"InActivity");
3021 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
3022 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"InActivity");
3025 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3041 if ($this->email && $addthirdparty) {
3042 if (empty($this->
name)) {
3043 $this->
name = $this->nom;
3045 $contact_emails[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->email.
">";
3048 return $contact_emails;
3064 if (!empty($this->phone)) {
3065 if (empty($this->
name)) {
3066 $this->
name = $this->nom;
3069 $contact_phone[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->phone.
">";
3071 return $contact_phone;
3087 $contact_property = array();
3090 $sql =
"SELECT rowid, email, statut as status, phone_mobile, lastname, poste, firstname";
3091 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3092 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
3093 $sql .=
" ORDER BY lastname, firstname";
3095 $resql = $this->db->query(
$sql);
3097 $nump = $this->db->num_rows($resql);
3099 $sepa =
"("; $sepb =
")";
3100 if ($mode ==
'email') {
3102 $sepa =
"<"; $sepb =
">";
3105 while ($i < $nump) {
3106 $obj = $this->db->fetch_object($resql);
3107 if ($mode ==
'email') {
3108 $property = $obj->email;
3109 } elseif ($mode ==
'mobile') {
3110 $property = $obj->phone_mobile;
3112 $property = $obj->$mode;
3116 if ($obj->status == 1 || empty($hidedisabled)) {
3117 if (empty($property)) {
3118 if ($mode ==
'email') {
3119 $property = $langs->transnoentitiesnoconv(
"NoEMail");
3120 } elseif ($mode ==
'mobile') {
3121 $property = $langs->transnoentitiesnoconv(
"NoMobilePhone");
3125 if (!empty($obj->poste)) {
3126 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ?
" - ".$obj->poste :
"").(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3128 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3137 return $contact_property;
3150 $contacts = array();
3152 $sql =
"SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3153 $resql = $this->db->query(
$sql);
3155 $nump = $this->db->num_rows($resql);
3158 while ($i < $nump) {
3159 $obj = $this->db->fetch_object($resql);
3179 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
3180 $contacts = array();
3182 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3183 $resql = $this->db->query(
$sql);
3185 $nump = $this->db->num_rows($resql);
3188 while ($i < $nump) {
3189 $obj = $this->db->fetch_object($resql);
3190 $contact =
new Contact($this->db);
3191 $contact->fetch($obj->rowid);
3192 $contacts[] = $contact;
3213 $contact_property =
'';
3215 if (empty($rowid)) {
3219 $sql =
"SELECT rowid, email, phone_mobile, lastname, firstname";
3220 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3221 $sql .=
" WHERE rowid = ".((int) $rowid);
3223 $resql = $this->db->query(
$sql);
3225 $nump = $this->db->num_rows($resql);
3228 $obj = $this->db->fetch_object($resql);
3230 if ($mode ==
'email') {
3232 } elseif ($mode ==
'mobile') {
3233 $contact_property = $obj->phone_mobile;
3236 return $contact_property;
3255 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3258 $bac->fetch(0, $this->
id);
3261 if ($mode ==
'label') {
3262 return $bac->getRibLabel(
true);
3263 } elseif ($mode ==
'rum') {
3264 if (empty($bac->rum)) {
3265 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
3267 $bac->fetch_thirdparty();
3268 $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
3271 } elseif ($mode ==
'format') {
3272 return $bac->frstrecur;
3274 return 'BadParameterToFunctionDisplayRib';
3290 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3291 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE type='ban' AND fk_soc = ".((int) $this->
id);
3292 $result = $this->db->query(
$sql);
3295 $this->errors[] = $this->db->lasterror;
3298 $num_rows = $this->db->num_rows($result);
3299 $rib_array = array();
3301 while ($obj = $this->db->fetch_object($result)) {
3303 $rib->fetch($obj->rowid);
3304 $rib_array[] = $rib;
3324 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3325 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3327 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3328 foreach ($dirsociete as $dirroot) {
3334 $mod =
new $module();
3336 $this->code_client = $mod->getNextValue($objsoc, $type);
3337 $this->prefixCustomerIsRequired = $mod->prefixIsRequired;
3339 dol_syslog(get_class($this).
"::get_codeclient code_client=".$this->code_client.
" module=".$module);
3356 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3357 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3359 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3360 foreach ($dirsociete as $dirroot) {
3366 $mod =
new $module();
3368 $this->code_fournisseur = $mod->getNextValue($objsoc, $type);
3370 dol_syslog(get_class($this).
"::get_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3385 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3386 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3388 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3389 foreach ($dirsociete as $dirroot) {
3396 $mod =
new $module();
3398 dol_syslog(get_class($this).
"::codeclient_modifiable code_client=".$this->code_client.
" module=".$module);
3399 if ($mod->code_modifiable_null && !$this->code_client) {
3402 if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
3405 if ($mod->code_modifiable) {
3425 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3426 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3428 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3429 foreach ($dirsociete as $dirroot) {
3436 $mod =
new $module();
3438 dol_syslog(get_class($this).
"::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur.
" module=".$module);
3439 if ($mod->code_modifiable_null && !$this->code_fournisseur) {
3442 if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
3445 if ($mod->code_modifiable) {
3471 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3472 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3474 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3475 foreach ($dirsociete as $dirroot) {
3482 $mod =
new $module();
3484 dol_syslog(get_class($this).
"::check_codeclient code_client=".$this->code_client.
" module=".$module);
3485 $result = $mod->verif($this->db, $this->code_client, $this, 0);
3487 $this->error = $mod->error;
3488 $this->errors = $mod->errors;
3512 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3513 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3515 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3516 foreach ($dirsociete as $dirroot) {
3523 $mod =
new $module();
3525 dol_syslog(get_class($this).
"::check_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3526 $result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
3528 $this->error = $mod->error;
3529 $this->errors = $mod->errors;
3551 if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) {
3553 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3554 foreach ($dirsociete as $dirroot) {
3555 $res =
dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.
'.php');
3562 $classname = $conf->global->SOCIETE_CODECOMPTA_ADDON;
3563 $mod =
new $classname;
3566 $result = $mod->get_code($this->db, $this, $type);
3568 if ($type ==
'customer') {
3569 $this->code_compta_client = $mod->code;
3570 $this->code_compta = $this->code_compta_client;
3571 } elseif ($type ==
'supplier') {
3572 $this->code_compta_fournisseur = $mod->code;
3577 $this->error =
'ErrorAccountancyCodeNotDefined';
3581 if ($type ==
'customer') {
3582 $this->code_compta_client =
'';
3583 $this->code_compta =
'';
3584 } elseif ($type ==
'supplier') {
3585 $this->code_compta_fournisseur =
'';
3600 dol_syslog(get_class($this).
'::setParent', LOG_DEBUG);
3606 if ($sameparent < 0) {
3609 if ($sameparent == 1) {
3610 setEventMessages(
'ParentCompanyToAddIsAlreadyAChildOfModifiedCompany',
null,
'warnings');
3615 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe SET parent = '.($id > 0 ? $id :
'null').
' WHERE rowid = '.((
int) $this->id);
3617 $resql = $this->db->query(
$sql);
3619 $this->parent = $id;
3639 if ($counter > 100) {
3640 dol_syslog(
"Too high level of parent - child for company. May be an infinite loop ?", LOG_WARNING);
3643 $sql =
'SELECT s.parent';
3644 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
3645 $sql .=
' WHERE rowid = '.((int) $idparent);
3646 $resql = $this->db->query(
$sql);
3648 $obj = $this->db->fetch_object($resql);
3650 if ($obj->parent ==
'') {
3652 } elseif ($obj->parent == $idchild) {
3674 if ($company_id > 0) {
3675 $sql =
"SELECT parent FROM " . MAIN_DB_PREFIX .
"societe WHERE rowid = $company_id";
3676 $resql = $this->db->query(
$sql);
3678 if ($obj = $this->db->fetch_object($resql)) {
3679 $parent = $obj->parent;
3680 if ($parent > 0 && !in_array($parent, $parents)) {
3681 $parents[] = $parent;
3687 $this->db->free($resql);
3689 setEventMessage($langs->trans(
'GetCompanyParentsError', $this->db->lasterror()),
'errors');
3708 $ret = (empty($conf->global->SOCIETE_IDPROF1_UNIQUE) ? false :
true);
3711 $ret = (empty($conf->global->SOCIETE_IDPROF2_UNIQUE) ? false :
true);
3714 $ret = (empty($conf->global->SOCIETE_IDPROF3_UNIQUE) ? false :
true);
3717 $ret = (empty($conf->global->SOCIETE_IDPROF4_UNIQUE) ? false :
true);
3720 $ret = (empty($conf->global->SOCIETE_IDPROF5_UNIQUE) ? false :
true);
3723 $ret = (empty($conf->global->SOCIETE_IDPROF6_UNIQUE) ? false :
true);
3772 $sql =
"SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"societe WHERE ".$field.
" = '".$this->db->escape($value).
"' AND entity IN (".
getEntity(
'societe').
")";
3774 $sql .=
" AND rowid <> ".$socid;
3776 $resql = $this->db->query(
$sql);
3778 $obj = $this->db->fetch_object($resql);
3782 print $this->db->error();
3784 $this->db->free($resql);
3809 if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3814 if ($idprof == 1 && $soc->country_code ==
'FR') {
3815 $chaine = trim($this->idprof1);
3816 $chaine = preg_replace(
'/(\s)/',
'', $chaine);
3818 if (!is_numeric($chaine)) {
3830 for ($index = 0; $index < 9; $index++) {
3831 $number = (int) $chaine[$index];
3832 if (($index % 2) != 0) {
3833 if (($number *= 2) > 9) {
3841 if (($sum % 10) != 0) {
3847 if ($idprof == 2 && $soc->country_code ==
'FR') {
3848 $chaine = trim($this->idprof2);
3849 $chaine = preg_replace(
'/(\s)/',
'', $chaine);
3851 if (!is_numeric($chaine)) {
3863 for ($index = 0; $index < 14; $index++) {
3864 $number = (int) $chaine[$index];
3865 if (($index % 2) == 0) {
3866 if (($number *= 2) > 9) {
3874 if (($sum % 10) != 0) {
3881 if ($idprof == 1 && $soc->country_code ==
'ES') {
3882 $string = trim($this->idprof1);
3883 $string = preg_replace(
'/(\s)/',
'', $string);
3884 $string = strtoupper($string);
3887 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)) {
3892 for ($i = 0; $i < 9; $i++) {
3893 $num[$i] = substr($string, $i, 1);
3897 if (preg_match(
'/(^[0-9]{8}[A-Z]{1}$)/', $string)) {
3898 if ($num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) {
3906 $sum = $num[2] + $num[4] + $num[6];
3907 for ($i = 1; $i < 8; $i += 2) {
3908 $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1));
3910 $n = 10 - substr($sum, strlen($sum) - 1, 1);
3913 if (preg_match(
'/^[KLM]{1}/', $string)) {
3914 if ($num[8] == chr(64 + $n) || $num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) {
3922 if (preg_match(
'/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) {
3923 if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) {
3931 if (preg_match(
'/^[T]{1}/', $string)) {
3932 if ($num[8] == preg_match(
'/^[T]{1}[A-Z0-9]{8}$/', $string)) {
3940 if (preg_match(
'/^[XYZ]{1}/', $string)) {
3941 if ($num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array(
'X',
'Y',
'Z'), array(
'0',
'1',
'2'), $string), 0, 8) % 23, 1)) {
3954 if ($idprof == 1 && $soc->country_code ==
'PT') {
3955 $string = trim($this->idprof1);
3956 $string = preg_replace(
'/(\s)/',
'', $string);
3959 if (preg_match(
'/(^[0-9]{9}$)/', $string)) {
3968 if ($idprof == 1 && $soc->country_code ==
'DZ') {
3969 $string = trim($this->idprof1);
3970 $string = preg_replace(
'/(\s)/',
'', $string);
3973 if (preg_match(
'/(^[0-9]{15}$)/', $string)) {
3995 global $conf, $langs, $hookmanager;
4000 $hookmanager->initHooks(array(
'idprofurl'));
4001 $parameters = array(
'idprof'=>$idprof,
'company'=>$thirdparty);
4002 $reshook = $hookmanager->executeHooks(
'getIdProfUrl', $parameters, $this, $action);
4003 if (empty($reshook)) {
4004 if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
4009 $strippedIdProf1 = str_replace(
' ',
'', $thirdparty->idprof1);
4010 if ($idprof == 1 && $thirdparty->country_code ==
'FR') {
4011 $url =
'https://annuaire-entreprises.data.gouv.fr/entreprise/'.$strippedIdProf1;
4013 if ($idprof == 1 && ($thirdparty->country_code ==
'GB' || $thirdparty->country_code ==
'UK')) {
4014 $url =
'https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
4016 if ($idprof == 1 && $thirdparty->country_code ==
'ES') {
4017 $url =
'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
4019 if ($idprof == 1 && $thirdparty->country_code ==
'IN') {
4020 $url =
'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.
';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
4022 if ($idprof == 1 && $thirdparty->country_code ==
'DZ') {
4023 $url =
'http://nif.mfdgi.gov.dz/nif.asp?Nif='.$strippedIdProf1;
4025 if ($idprof == 1 && $thirdparty->country_code ==
'PT') {
4026 $url =
'http://www.nif.pt/'.$strippedIdProf1;
4030 return '<a target="_blank" rel="noopener noreferrer" href="'.$url.
'">'.$langs->trans(
"Check").
'</a>';
4033 return $hookmanager->resPrint;
4048 $sql =
"SELECT COUNT(*) as numproj FROM ".MAIN_DB_PREFIX.
"projet WHERE fk_soc = ".((int) $this->
id);
4049 $resql = $this->db->query(
$sql);
4051 $obj = $this->db->fetch_object($resql);
4052 $count = $obj->numproj;
4055 print $this->db->error();
4057 $this->db->free($resql);
4058 return ($count > 0);
4070 $sql =
"SELECT s.rowid, s.nom as name, s.datec, tms as datem,";
4071 $sql .=
" fk_user_creat, fk_user_modif";
4072 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
4073 $sql .=
" WHERE s.rowid = ".((int) $id);
4075 $result = $this->db->query(
$sql);
4077 if ($this->db->num_rows($result)) {
4078 $obj = $this->db->fetch_object($result);
4080 $this->
id = $obj->rowid;
4082 $this->user_creation_id = $obj->fk_user_creat;
4083 $this->user_modification_id = $obj->fk_user_modif;
4084 $this->date_creation = $this->db->jdate($obj->datec);
4085 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
4087 $this->
ref = $obj->name;
4090 $this->db->free($result);
4106 $isacompany = empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES) ? 0 : 1;
4107 if (!empty($this->tva_intra)) {
4109 } elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) {
4111 } elseif (!empty($this->typent_code) && $this->typent_code !=
'TE_UNKNOWN') {
4113 if (preg_match(
'/^TE_PRIVATE/', $this->typent_code)) {
4130 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4143 $this->SupplierCategories = array();
4144 $sql =
"SELECT rowid, label";
4145 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
4146 $sql .=
" WHERE type = ".Categorie::TYPE_SUPPLIER;
4148 $resql = $this->db->query(
$sql);
4150 while ($obj = $this->db->fetch_object($resql)) {
4151 $this->SupplierCategories[$obj->rowid] = $obj->label;
4169 if ($categorie_id > 0 && $this->
id > 0) {
4170 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_fournisseur (fk_categorie, fk_soc) ";
4171 $sql .=
" VALUES (".((int) $categorie_id).
", ".((int) $this->
id).
")";
4173 if ($resql = $this->db->query(
$sql)) {
4189 $sql =
"SELECT count(mc.email) as nb";
4190 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
4191 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->email).
"' ";
4192 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
4194 $resql = $this->db->query(
$sql);
4196 $obj = $this->db->fetch_object($resql);
4199 $this->db->free($resql);
4202 $this->error = $this->db->error();
4222 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing', 0).
") AND email = '".$this->db->escape($this->email).
"'";
4223 $resql = $this->db->query(
$sql);
4225 $obj = $this->db->fetch_object($resql);
4226 $noemail = $obj->nb;
4227 if (empty($noemail)) {
4228 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing_unsubscribe(email, entity, date_creat) VALUES ('".$this->db->escape($this->email).
"', ".
getEntity(
'mailing', 0).
", '".$this->db->idate(
dol_now()).
"')";
4229 $resql = $this->db->query(
$sql);
4232 $this->error = $this->db->lasterror();
4233 $this->errors[] = $this->error;
4238 $this->error = $this->db->lasterror();
4239 $this->errors[] = $this->error;
4242 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->db->escape($this->email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
4243 $resql = $this->db->query(
$sql);
4246 $this->error = $this->db->lasterror();
4247 $this->errors[] = $this->error;
4251 if (empty($error)) {
4252 $this->no_email = $no_email;
4253 $this->db->commit();
4256 $this->db->rollback();
4273 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->db->escape($this->email).
"'";
4274 $resql = $this->db->query(
$sql);
4276 $obj = $this->db->fetch_object($resql);
4277 $this->no_email = $obj->nb;
4280 $this->error = $this->db->lasterror();
4281 $this->errors[] = $this->error;
4301 global $conf, $user, $langs;
4303 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
4304 $fullname = $member->getFullName($langs);
4306 if ($member->morphy ==
'mor') {
4307 if (empty($socname)) {
4308 $socname = $member->company? $member->company : $member->societe;
4310 if (!empty($fullname) && empty($socalias)) {
4311 $socalias = $fullname;
4313 } elseif (empty($socname) && $member->morphy ==
'phy') {
4314 if (empty($socname)) {
4315 $socname = $fullname;
4317 if (!empty($member->company) && empty($socalias)) {
4318 $socalias = $member->company;
4323 $alias = $socalias ? $socalias :
'';
4327 $this->
name = $name;
4328 $this->name_alias = $alias;
4329 $this->address = $member->address;
4330 $this->zip = $member->zip;
4331 $this->town = $member->town;
4332 $this->country_code = $member->country_code;
4333 $this->country_id = $member->country_id;
4334 $this->phone = $member->phone;
4335 $this->email = $member->email;
4336 $this->socialnetworks = $member->socialnetworks;
4337 $this->entity = $member->entity;
4340 $this->code_client = ($customercode ? $customercode : -1);
4341 $this->code_fournisseur = -1;
4342 $this->typent_code = ($member->morphy ==
'phy' ?
'TE_PRIVATE' : 0);
4343 $this->typent_id = $this->typent_code ?
dol_getIdFromCode($this->db, $this->typent_code,
'c_typent',
'id',
'code') : 0;
4348 $result = $this->
create($user);
4352 if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT)) {
4354 $this->name_bis = $member->lastname;
4355 $this->firstname = $member->firstname;
4356 $this->civility_id = $member->civility_id;
4358 dol_syslog(
"We ask to create a contact/address too", LOG_DEBUG);
4363 $this->db->rollback();
4368 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent";
4369 $sql .=
" SET fk_soc = ".((int) $this->
id);
4370 $sql .=
" WHERE rowid = ".((int) $member->id);
4372 $resql = $this->db->query(
$sql);
4374 $this->db->commit();
4377 $this->error = $this->db->error();
4379 $this->db->rollback();
4384 dol_syslog(get_class($this).
"::create_from_member - 2 - ".$this->error.
" - ".join(
',', $this->errors), LOG_ERR);
4386 $this->db->rollback();
4402 $this->entity = $conf->entity;
4404 $this->nom = $this->name;
4415 $country_id = $country_code = $country_label =
'';
4416 if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
4417 $tmp = explode(
':', $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
4418 $country_id = $tmp[0];
4419 if (!empty($tmp[1])) {
4420 $country_code = $tmp[1];
4421 $country_label = $tmp[2];
4424 dol_syslog(
"Your country setup use an old syntax. Reedit it using setup area.", LOG_WARNING);
4425 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4426 $country_code =
getCountry($country_id, 2, $this->db);
4427 $country_label =
getCountry($country_id, 0, $this->db);
4430 $this->country_id = $country_id;
4431 $this->country_code = $country_code;
4432 $this->country = $country_label;
4433 if (is_object($langs)) {
4434 $this->country = ($langs->trans(
'Country'.$country_code) !=
'Country'.$country_code) ? $langs->trans(
'Country'.$country_code) : $country_label;
4439 $state_id = 0; $state_code = $state_label =
'';
4440 if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE)) {
4441 $tmp = explode(
':', $conf->global->MAIN_INFO_SOCIETE_STATE);
4442 $state_id = $tmp[0];
4443 if (!empty($tmp[1])) {
4444 $state_code = $tmp[1];
4445 $state_label = $tmp[2];
4447 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);
4448 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4449 $state_code =
getState($state_id, 2, $this->db);
4450 $state_label =
getState($state_id, 0, $this->db);
4453 $this->state_id = $state_id;
4454 $this->state_code = $state_code;
4455 $this->state = $state_label;
4456 if (is_object($langs)) {
4457 $this->state = ($langs->trans(
'State'.$state_code) !=
'State'.$state_code) ? $langs->trans(
'State'.$state_code) : $state_label;
4471 $this->socialnetworks = array();
4472 if (!empty($facebook_url)) {
4473 $this->socialnetworks[
'facebook'] = $facebook_url;
4475 if (!empty($twitter_url)) {
4476 $this->socialnetworks[
'twitter'] = $twitter_url;
4478 if (!empty($linkedin_url)) {
4479 $this->socialnetworks[
'linkedin'] = $linkedin_url;
4481 if (!empty($instagram_url)) {
4482 $this->socialnetworks[
'instagram'] = $instagram_url;
4484 if (!empty($youtube_url)) {
4485 $this->socialnetworks[
'youtube'] = $youtube_url;
4487 if (!empty($github_url)) {
4488 $this->socialnetworks[
'github'] = $github_url;
4501 $this->forme_juridique_code =
getDolGlobalString(
'MAIN_INFO_SOCIETE_FORME_JURIDIQUE');
4508 $this->logo_squarred_small =
getDolGlobalString(
'MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL');
4509 $this->logo_squarred_mini =
getDolGlobalString(
'MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI');
4512 $this->tva_assuj = $conf->global->FACTURE_TVAOPTION;
4515 $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);
4516 $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);
4533 $this->
name =
'THIRDPARTY SPECIMEN '.dol_print_date($now,
'dayhourlog');
4534 $this->nom = $this->name;
4535 $this->ref_ext =
'Ref ext';
4536 $this->specimen = 1;
4537 $this->address =
'21 jump street';
4538 $this->zip =
'99999';
4539 $this->town =
'MyTown';
4540 $this->state_id = 1;
4541 $this->state_code =
'AA';
4542 $this->state =
'MyState';
4543 $this->country_id = 1;
4544 $this->country_code =
'FR';
4545 $this->email =
'specimen@specimen.com';
4546 $this->socialnetworks = array(
4547 'skype' =>
'tom.hanson',
4548 'twitter' =>
'tomhanson',
4549 'facebook' =>
'tomhanson',
4550 'linkedin' =>
'tomhanson',
4552 $this->url =
'http://www.specimen.com';
4554 $this->phone =
'0909090901';
4555 $this->fax =
'0909090909';
4557 $this->code_client =
'CC-'.dol_print_date($now,
'dayhourlog');
4558 $this->code_fournisseur =
'SC-'.dol_print_date($now,
'dayhourlog');
4559 $this->capital = 10000;
4561 $this->prospect = 1;
4562 $this->fournisseur = 1;
4563 $this->tva_assuj = 1;
4564 $this->tva_intra =
'EU1234567';
4565 $this->note_public =
'This is a comment (public)';
4566 $this->note_private =
'This is a comment (private)';
4568 $this->idprof1 =
'idprof1';
4569 $this->idprof2 =
'idprof2';
4570 $this->idprof3 =
'idprof3';
4571 $this->idprof4 =
'idprof4';
4572 $this->idprof5 =
'idprof5';
4573 $this->idprof6 =
'idprof6';
4585 $sql =
"SELECT t.localtax1, t.localtax2";
4586 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4587 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4588 $sql .=
" AND t.active = 1";
4589 if (empty($localTaxNum)) {
4590 $sql .=
" AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
4591 } elseif ($localTaxNum == 1) {
4592 $sql .=
" AND t.localtax1_type <> '0'";
4593 } elseif ($localTaxNum == 2) {
4594 $sql .=
" AND t.localtax2_type <> '0'";
4597 $resql = $this->db->query(
$sql);
4599 return ($this->db->num_rows($resql) > 0);
4612 $sql =
"SELECT t.rowid";
4613 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4614 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4615 $sql .=
" AND t.active = 1 AND t.recuperableonly = 1";
4618 $resql = $this->db->query(
$sql);
4620 return ($this->db->num_rows($resql) > 0);
4634 $sql =
"SELECT COUNT(*) as nb";
4635 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_revenuestamp as r, ".MAIN_DB_PREFIX.
"c_country as c";
4636 $sql .=
" WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4637 $sql .=
" AND r.active = 1";
4640 $resql = $this->db->query(
$sql);
4642 $obj = $this->db->fetch_object($resql);
4643 return (($obj->nb > 0) ?
true:
false);
4645 $this->error = $this->db->lasterror();
4672 $lib = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
4674 if ($lib == $langs->trans(
"ProspectLevel".$fk_prospectlevel)) {
4675 $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
4689 return $this->
LibProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
4711 $langs->load(
'customers');
4714 if ($status ==
'-1' || $status ==
'ST_NO') {
4715 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect-1");
4716 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4717 return img_action($langs->trans(
"StatusProspect0"), 0, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect0");
4718 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4719 return img_action($langs->trans(
"StatusProspect1"), 1, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect1");
4720 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4721 return img_action($langs->trans(
"StatusProspect2"), 2, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect2");
4722 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4723 return img_action($langs->trans(
"StatusProspect3"), 3, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect3");
4725 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto,
'class="inline-block valignmiddle"').
' '.(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label);
4727 } elseif ($mode == 3) {
4728 if ($status ==
'-1' || $status ==
'ST_NO') {
4729 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto,
'class="inline-block valignmiddle"');
4730 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4731 return img_action($langs->trans(
"StatusProspect0"), 0, $picto,
'class="inline-block valignmiddle"');
4732 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4733 return img_action($langs->trans(
"StatusProspect1"), 1, $picto,
'class="inline-block valignmiddle"');
4734 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4735 return img_action($langs->trans(
"StatusProspect2"), 2, $picto,
'class="inline-block valignmiddle"');
4736 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4737 return img_action($langs->trans(
"StatusProspect3"), 3, $picto,
'class="inline-block valignmiddle"');
4739 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto,
'class="inline-block valignmiddle"');
4741 } elseif ($mode == 4) {
4742 if ($status ==
'-1' || $status ==
'ST_NO') {
4743 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect-1");
4744 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4745 return img_action($langs->trans(
"StatusProspect0"), 0, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect0");
4746 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4747 return img_action($langs->trans(
"StatusProspect1"), 1, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect1");
4748 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4749 return img_action($langs->trans(
"StatusProspect2"), 2, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect2");
4750 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4751 return img_action($langs->trans(
"StatusProspect3"), 3, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect3");
4753 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto,
'class="inline-block valignmiddle"').
' '.(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label);
4757 return "Error, mode/status not found";
4769 if ($mode ==
'supplier') {
4770 $table =
'supplier_proposal';
4773 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4774 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4775 if ($mode ==
'supplier') {
4776 $sql .=
" AND entity IN (".getEntity(
'supplier_proposal').
")";
4778 $sql .=
" AND entity IN (".getEntity(
'propal').
")";
4781 dol_syslog(
"getOutstandingProposals for fk_soc = ".((
int) $this->
id), LOG_DEBUG);
4783 $resql = $this->db->query(
$sql);
4785 $outstandingOpened = 0;
4786 $outstandingTotal = 0;
4787 $outstandingTotalIncTax = 0;
4788 $arrayofref = array();
4789 while ($obj = $this->db->fetch_object($resql)) {
4790 $arrayofref[$obj->rowid] = $obj->ref;
4791 $outstandingTotal += $obj->total_ht;
4792 $outstandingTotalIncTax += $obj->total_ttc;
4793 if ($obj->status != 0) {
4795 $outstandingOpened += $obj->total_ttc;
4798 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref);
4812 $table =
'commande';
4813 if ($mode ==
'supplier') {
4814 $table =
'commande_fournisseur';
4817 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4818 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4819 if ($mode ==
'supplier') {
4820 $sql .=
" AND entity IN (".getEntity(
'supplier_order').
")";
4822 $sql .=
" AND entity IN (".getEntity(
'commande').
")";
4825 dol_syslog(
"getOutstandingOrders", LOG_DEBUG);
4826 $resql = $this->db->query(
$sql);
4828 $outstandingOpened = 0;
4829 $outstandingTotal = 0;
4830 $outstandingTotalIncTax = 0;
4831 $arrayofref = array();
4832 while ($obj = $this->db->fetch_object($resql)) {
4833 $arrayofref[$obj->rowid] = $obj->ref;
4834 $outstandingTotal += $obj->total_ht;
4835 $outstandingTotalIncTax += $obj->total_ttc;
4836 if ($obj->status != 0) {
4838 $outstandingOpened += $obj->total_ttc;
4841 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref);
4857 if ($mode ==
'supplier') {
4858 $table =
'facture_fourn';
4868 $sql =
"SELECT rowid, ref, total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table.
" as f";
4869 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4870 if (!empty($late)) {
4871 $sql .=
" AND date_lim_reglement < '".$this->db->idate(
dol_now()).
"'";
4873 if ($mode ==
'supplier') {
4874 $sql .=
" AND entity IN (".getEntity(
'facture_fourn').
")";
4876 $sql .=
" AND entity IN (".getEntity(
'invoice').
")";
4879 dol_syslog(
"getOutstandingBills", LOG_DEBUG);
4880 $resql = $this->db->query(
$sql);
4882 $outstandingOpened = 0;
4883 $outstandingTotal = 0;
4884 $outstandingTotalIncTax = 0;
4885 $arrayofref = array();
4886 $arrayofrefopened = array();
4887 if ($mode ==
'supplier') {
4888 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
4891 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
4892 $tmpobject =
new Facture($this->db);
4894 while ($obj = $this->db->fetch_object($resql)) {
4895 $arrayofref[$obj->rowid] = $obj->ref;
4896 $tmpobject->id = $obj->rowid;
4898 if ($obj->status != $tmpobject::STATUS_DRAFT
4899 && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code ==
'replaced')
4901 $outstandingTotal += $obj->total_ht;
4902 $outstandingTotalIncTax += $obj->total_ttc;
4908 && $obj->status != $tmpobject::STATUS_DRAFT
4909 && $obj->status != $tmpobject::STATUS_ABANDONED
4910 && $obj->status != $tmpobject::STATUS_CLOSED) {
4912 $paiement = $tmpobject->getSommePaiement();
4913 $creditnotes = $tmpobject->getSumCreditNotesUsed();
4914 $deposits = $tmpobject->getSumDepositsUsed();
4916 $remaintopay = ($obj->total_ttc - $paiement - $creditnotes - $deposits);
4917 $outstandingOpened += $remaintopay;
4923 $remainingcreditnote = $tmpobject->getSumFromThisCreditNotesNotUsed();
4924 $remaintopay -= $remainingcreditnote;
4925 $outstandingOpened -= $remainingcreditnote;
4929 $arrayofrefopened[$obj->rowid] = $obj->ref;
4932 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax,
'refs'=>$arrayofref,
'refsopened'=>$arrayofrefopened);
4934 dol_syslog(
"Sql error ".$this->db->lasterror, LOG_ERR);
4961 $langs->load(
'companies');
4964 return $langs->trans(
"NorProspectNorCustomer");
4965 } elseif ($status == 1) {
4966 return $langs->trans(
"Customer");
4967 } elseif ($status == 2) {
4968 return $langs->trans(
"Prospect");
4969 } elseif ($status == 3) {
4970 return $langs->trans(
"ProspectCustomer");
4988 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4990 global $conf, $user, $langs;
4992 if (!empty($moreparams) && !empty($moreparams[
'use_companybankid'])) {
4993 $modelpath =
"core/modules/bank/doc/";
4995 include_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
4997 $result = $companybankaccount->fetch($moreparams[
'use_companybankid']);
4999 dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
5001 $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
5005 if (!empty($conf->global->COMPANY_ADDON_PDF)) {
5006 $modele = $conf->global->COMPANY_ADDON_PDF;
5008 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_COMPANY_ADDON_PDF_NotDefined");
5013 if (!isset($this->bank_account)) {
5014 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
5016 $result = $bac->fetch(0, $this->
id);
5018 $this->bank_account = $bac;
5020 $this->bank_account =
'';
5024 $modelpath =
"core/modules/societe/doc/";
5026 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
5046 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
5049 if (!in_array($type_categ, array(Categorie::TYPE_CUSTOMER, Categorie::TYPE_SUPPLIER))) {
5050 dol_syslog(__METHOD__.
': Type '.$type_categ.
'is an unknown company category type. Done nothing.', LOG_ERR);
5054 return parent::setCategoriesCommon($categories, $type_categ);
5069 if (!is_array($salesrep)) {
5070 $salesrep = array($salesrep);
5074 $to_add = $salesrep;
5075 if ($onlyAdd ===
false) {
5080 if (is_array($existing)) {
5081 $to_del = array_diff($existing, $salesrep);
5082 $to_add = array_diff($salesrep, $existing);
5089 foreach ($to_del as $del) {
5092 foreach ($to_add as $add) {
5100 return $error ? -1 : 1;
5116 $result = $this->
setValueFrom(
'fk_typent', $typent_id,
'',
null,
'',
'', $user,
'COMPANY_MODIFY');
5119 $this->typent_id = $typent_id;
5120 $this->typent_code =
dol_getIdFromCode($this->db, $this->typent_id,
'c_typent',
'id',
'code');
5141 if ($origin_id == $dest_id) {
5142 dol_syslog(
'Error: Try to merge a thirdparty into itself');
5150 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5151 $sql .=
' WHERE fk_soc = '.(int) $dest_id.
' AND fk_user IN ( ';
5152 $sql .=
' SELECT fk_user ';
5153 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5154 $sql .=
' WHERE fk_soc = '.(int) $origin_id.
') ';
5158 $dbs->
query(
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_commerciaux WHERE rowid = '.((
int) $obj->rowid));
5167 'societe_commerciaux',
5170 'societe_remise_except',
5187 global $user, $langs, $conf;
5191 $field =
'accountancy_code_sell';
5192 if ($type ==
'buy') {
5193 $field =
'accountancy_code_buy';
5194 } elseif ($type ==
'sell') {
5195 $field =
'accountancy_code_sell';
5200 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ";
5201 $sql .= $field.
" = '".$this->db->escape($value).
"'";
5202 $sql .=
" WHERE rowid = ".((int) $this->
id);
5204 dol_syslog(get_class($this).
"::".__FUNCTION__, LOG_DEBUG);
5205 $resql = $this->db->query(
$sql);
5209 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
5211 $result = $interface->run_triggers(
'COMPANY_MODIFY', $this, $user, $langs, $conf);
5213 $this->errors = $interface->errors;
5214 $this->db->rollback();
5219 $this->$field = $value;
5221 $this->db->commit();
5224 $this->error = $this->db->lasterror();
5225 $this->db->rollback();
5240 require_once DOL_DOCUMENT_ROOT.
'/partnership/class/partnership.class.php';
5243 $this->partnerships[] = array();
5257 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
5259 $return =
'<div class="box-flex-item box-flex-grow-zero">';
5260 $return .=
'<div class="info-box info-box-sm">';
5261 $return .=
'<span class="info-box-icon bg-infobox-action">';
5263 $return .=
'</span>';
5264 $return .=
'<div class="info-box-content">';
5265 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
5266 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
5267 if (property_exists($this,
'code_client')) {
5268 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->code_client.
'</span>';
5271 if (method_exists($this,
'getLibStatut')) {
5272 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
5274 $return .=
'</div>';
5275 $return .=
'</div>';
5276 $return .=
'</div>';