40 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
54 public $element =
'societe';
59 public $table_element =
'societe';
64 public $fk_element =
'fk_soc';
69 public $fieldsforcombobox =
'nom,name_alias';
74 protected $childtables = array(
75 "supplier_proposal" =>
'SupplierProposal',
76 "propal" =>
'Proposal',
77 "commande" =>
'Order',
78 "facture" =>
'Invoice',
79 "facture_rec" =>
'RecurringInvoiceTemplate',
80 "contrat" =>
'Contract',
81 "fichinter" =>
'Fichinter',
82 "facture_fourn" =>
'SupplierInvoice',
83 "commande_fournisseur" =>
'SupplierOrder',
84 "projet" =>
'Project',
85 "expedition" =>
'Shipment',
86 "prelevement_lignes" =>
'DirectDebitRecord',
93 protected $childtablesoncascade = array(
96 "product_fournisseur_price",
97 "product_customer_price_log",
98 "product_customer_price",
99 "@Contact:/contact/class/contact.class.php:fk_soc",
104 "societe_remise_except",
105 "societe_commerciaux",
115 public $picto =
'company';
121 public $ismultientitymanaged = 1;
127 public $restrictiononfksoc = 1;
132 public $fields = array(
133 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
134 'parent' =>array(
'type'=>
'integer',
'label'=>
'Parent',
'enabled'=>1,
'visible'=>-1,
'position'=>20),
135 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
136 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
137 'nom' =>array(
'type'=>
'varchar(128)',
'label'=>
'Nom',
'enabled'=>1,
'visible'=>-1,
'position'=>35,
'showoncombobox'=>1),
138 'name_alias' =>array(
'type'=>
'varchar(128)',
'label'=>
'Name alias',
'enabled'=>1,
'visible'=>-1,
'position'=>36,
'showoncombobox'=>1),
139 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>40,
'index'=>1),
140 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefExt',
'enabled'=>1,
'visible'=>0,
'position'=>45),
141 'code_client' =>array(
'type'=>
'varchar(24)',
'label'=>
'CustomerCode',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
142 'code_fournisseur' =>array(
'type'=>
'varchar(24)',
'label'=>
'SupplierCode',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
143 'code_compta' =>array(
'type'=>
'varchar(24)',
'label'=>
'CodeCompta',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
144 'code_compta_fournisseur' =>array(
'type'=>
'varchar(24)',
'label'=>
'CodeComptaSupplier',
'enabled'=>1,
'visible'=>-1,
'position'=>70),
145 'address' =>array(
'type'=>
'varchar(255)',
'label'=>
'Address',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
146 'zip' =>array(
'type'=>
'varchar(25)',
'label'=>
'Zip',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
147 'town' =>array(
'type'=>
'varchar(50)',
'label'=>
'Town',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
148 'fk_departement' =>array(
'type'=>
'integer',
'label'=>
'State',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
149 'fk_pays' =>array(
'type'=>
'integer:Ccountry:core/class/ccountry.class.php',
'label'=>
'Country',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
150 'phone' =>array(
'type'=>
'varchar(20)',
'label'=>
'Phone',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
151 'fax' =>array(
'type'=>
'varchar(20)',
'label'=>
'Fax',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
152 'url' =>array(
'type'=>
'varchar(255)',
'label'=>
'Url',
'enabled'=>1,
'visible'=>-1,
'position'=>110),
153 'email' =>array(
'type'=>
'varchar(128)',
'label'=>
'Email',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
154 'socialnetworks' =>array(
'type'=>
'text',
'label'=>
'Socialnetworks',
'enabled'=>1,
'visible'=>-1,
'position'=>120),
164 'fk_effectif' =>array(
'type'=>
'integer',
'label'=>
'Workforce',
'enabled'=>1,
'visible'=>-1,
'position'=>170),
165 'fk_typent' =>array(
'type'=>
'integer',
'label'=>
'TypeOfCompany',
'enabled'=>1,
'visible'=>-1,
'position'=>175),
166 'fk_forme_juridique' =>array(
'type'=>
'integer',
'label'=>
'JuridicalStatus',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
167 'fk_currency' =>array(
'type'=>
'varchar(3)',
'label'=>
'Currency',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
168 'siren' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof1',
'enabled'=>1,
'visible'=>-1,
'position'=>190),
169 'siret' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof2',
'enabled'=>1,
'visible'=>-1,
'position'=>195),
170 'ape' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof3',
'enabled'=>1,
'visible'=>-1,
'position'=>200),
171 'idprof4' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof4',
'enabled'=>1,
'visible'=>-1,
'position'=>205),
172 'idprof5' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof5',
'enabled'=>1,
'visible'=>-1,
'position'=>206),
173 'idprof6' =>array(
'type'=>
'varchar(128)',
'label'=>
'Idprof6',
'enabled'=>1,
'visible'=>-1,
'position'=>207),
174 'tva_intra' =>array(
'type'=>
'varchar(20)',
'label'=>
'Tva intra',
'enabled'=>1,
'visible'=>-1,
'position'=>210),
175 'capital' =>array(
'type'=>
'double(24,8)',
'label'=>
'Capital',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
176 'fk_stcomm' =>array(
'type'=>
'integer',
'label'=>
'CommercialStatus',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>220),
177 'note_private' =>array(
'type'=>
'text',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>225),
178 'note_public' =>array(
'type'=>
'text',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>230),
179 'prefix_comm' =>array(
'type'=>
'varchar(5)',
'label'=>
'Prefix comm',
'enabled'=>
'$conf->global->SOCIETE_USEPREFIX',
'visible'=>-1,
'position'=>235),
180 'client' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Client',
'enabled'=>1,
'visible'=>-1,
'position'=>240),
181 'fournisseur' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Fournisseur',
'enabled'=>1,
'visible'=>-1,
'position'=>245),
182 'supplier_account' =>array(
'type'=>
'varchar(32)',
'label'=>
'Supplier account',
'enabled'=>1,
'visible'=>-1,
'position'=>250),
183 'fk_prospectlevel' =>array(
'type'=>
'varchar(12)',
'label'=>
'ProspectLevel',
'enabled'=>1,
'visible'=>-1,
'position'=>255),
184 'customer_bad' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Customer bad',
'enabled'=>1,
'visible'=>-1,
'position'=>260),
185 'customer_rate' =>array(
'type'=>
'double',
'label'=>
'Customer rate',
'enabled'=>1,
'visible'=>-1,
'position'=>265),
186 'supplier_rate' =>array(
'type'=>
'double',
'label'=>
'Supplier rate',
'enabled'=>1,
'visible'=>-1,
'position'=>270),
187 'fk_user_creat' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-2,
'position'=>275),
188 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>280),
191 'mode_reglement' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Mode reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>295),
192 'cond_reglement' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Cond reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>300),
193 'mode_reglement_supplier' =>array(
'type'=>
'integer',
'label'=>
'Mode reglement supplier',
'enabled'=>1,
'visible'=>-1,
'position'=>305),
194 'outstanding_limit' =>array(
'type'=>
'double(24,8)',
'label'=>
'OutstandingBill',
'enabled'=>1,
'visible'=>-1,
'position'=>310,
'isameasure'=>1),
195 'order_min_amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'Order min amount',
'enabled'=>
'!empty($conf->commande->enabled) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)',
'visible'=>-1,
'position'=>315,
'isameasure'=>1),
196 'supplier_order_min_amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'Supplier order min amount',
'enabled'=>
'!empty($conf->commande->enabled) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)',
'visible'=>-1,
'position'=>320,
'isameasure'=>1),
197 'cond_reglement_supplier' =>array(
'type'=>
'integer',
'label'=>
'Cond reglement supplier',
'enabled'=>1,
'visible'=>-1,
'position'=>325),
198 'fk_shipping_method' =>array(
'type'=>
'integer',
'label'=>
'Fk shipping method',
'enabled'=>1,
'visible'=>-1,
'position'=>330),
199 'tva_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Tva assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>335),
200 'localtax1_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Localtax1 assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>340),
201 'localtax1_value' =>array(
'type'=>
'double(6,3)',
'label'=>
'Localtax1 value',
'enabled'=>1,
'visible'=>-1,
'position'=>345),
202 'localtax2_assuj' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Localtax2 assuj',
'enabled'=>1,
'visible'=>-1,
'position'=>350),
203 'localtax2_value' =>array(
'type'=>
'double(6,3)',
'label'=>
'Localtax2 value',
'enabled'=>1,
'visible'=>-1,
'position'=>355),
204 'barcode' =>array(
'type'=>
'varchar(255)',
'label'=>
'Barcode',
'enabled'=>1,
'visible'=>-1,
'position'=>360),
205 '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),
206 'default_lang' =>array(
'type'=>
'varchar(6)',
'label'=>
'Default lang',
'enabled'=>1,
'visible'=>-1,
'position'=>370),
207 'canvas' =>array(
'type'=>
'varchar(32)',
'label'=>
'Canvas',
'enabled'=>1,
'visible'=>-1,
'position'=>375),
208 'fk_barcode_type' =>array(
'type'=>
'integer',
'label'=>
'Fk barcode type',
'enabled'=>1,
'visible'=>-1,
'position'=>405),
209 'webservices_url' =>array(
'type'=>
'varchar(255)',
'label'=>
'Webservices url',
'enabled'=>1,
'visible'=>-1,
'position'=>410),
210 'webservices_key' =>array(
'type'=>
'varchar(128)',
'label'=>
'Webservices key',
'enabled'=>1,
'visible'=>-1,
'position'=>415),
211 'fk_incoterms' =>array(
'type'=>
'integer',
'label'=>
'Fk incoterms',
'enabled'=>1,
'visible'=>-1,
'position'=>425),
212 'location_incoterms' =>array(
'type'=>
'varchar(255)',
'label'=>
'Location incoterms',
'enabled'=>1,
'visible'=>-1,
'position'=>430),
213 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>435),
214 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>-1,
'position'=>440),
215 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Multicurrency code',
'enabled'=>1,
'visible'=>-1,
'position'=>445),
216 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'Fk account',
'enabled'=>1,
'visible'=>-1,
'position'=>450),
217 'fk_entrepot' =>array(
'type'=>
'integer',
'label'=>
'Fk entrepot',
'enabled'=>1,
'visible'=>-1,
'position'=>455),
218 'logo' =>array(
'type'=>
'varchar(255)',
'label'=>
'Logo',
'enabled'=>1,
'visible'=>-1,
'position'=>400),
219 'logo_squarred' =>array(
'type'=>
'varchar(255)',
'label'=>
'Logo squarred',
'enabled'=>1,
'visible'=>-1,
'position'=>401),
220 'status' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>-1,
'position'=>500),
221 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000),
306 public $departement_code;
341 public $socialnetworks;
429 public $tva_assuj = 1;
438 public $localtax1_assuj;
439 public $localtax1_value;
440 public $localtax2_assuj;
441 public $localtax2_value;
456 public $typent_id = 0;
459 public $effectif_id = 0;
460 public $forme_juridique_code;
461 public $forme_juridique = 0;
463 public $remise_percent;
464 public $remise_supplier_percent;
465 public $mode_reglement_supplier_id;
466 public $cond_reglement_supplier_id;
467 public $transport_mode_supplier_id;
472 public $fk_prospectlevel;
485 public $date_modification;
491 public $user_modification;
496 public $date_creation;
502 public $user_creation;
514 public $prospect = 0;
532 public $code_fournisseur;
544 public $code_compta_client;
550 public $code_compta_fournisseur;
563 public $note_private;
581 public $stcomm_picto;
587 public $status_prospect_label;
598 public $outstanding_limit;
603 public $order_min_amount;
608 public $supplier_order_min_amount;
614 public $commercial_id;
626 public $default_lang;
658 public $webservices_url;
664 public $webservices_key;
684 public $logo_squarred;
689 public $logo_squarred_small;
694 public $logo_squarred_mini;
701 public $fk_multicurrency;
706 public $multicurrency_code;
712 public $bank_account;
757 $this->fournisseur = 0;
758 $this->typent_id = 0;
759 $this->effectif_id = 0;
760 $this->forme_juridique_code = 0;
761 $this->tva_assuj = 1;
764 if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
765 $this->
fields[
'address'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
766 $this->
fields[
'zip'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
767 $this->
fields[
'town'][
'showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST;
782 global $langs, $conf, $mysoc;
787 if (empty($this->status)) {
792 $this->
nom = $this->name;
793 if (empty($this->client)) {
796 if (empty($this->fournisseur)) {
797 $this->fournisseur = 0;
799 $this->import_key = trim($this->import_key);
801 if (!empty($this->multicurrency_code)) {
804 if (empty($this->fk_multicurrency)) {
805 $this->multicurrency_code =
'';
806 $this->fk_multicurrency = 0;
816 if ($this->code_client == -1 || $this->code_client ===
'auto') {
819 if ($this->code_fournisseur == -1 || $this->code_fournisseur ===
'auto') {
825 $result = $this->
verify();
828 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
830 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)";
831 $sql .=
" VALUES ('".$this->db->escape($this->name).
"', '".$this->
db->escape($this->name_alias).
"', ".$this->
db->escape($this->entity).
", '".$this->
db->idate($now).
"'";
832 $sql .=
", ".(!empty($user->id) ? ((int) $user->id) :
"null");
833 $sql .=
", ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null");
834 $sql .=
", ".$this->status;
835 $sql .=
", ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
837 $sql .=
", ".(int) $this->fk_incoterms;
838 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
839 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
840 $sql .=
", ".(int) $this->fk_multicurrency;
841 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"')";
843 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
844 $result = $this->
db->query($sql);
846 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"societe");
848 $ret = $this->
update($this->
id, $user, 0, 1, 1,
'add');
851 if ($this->commercial_id !=
'' && $this->commercial_id != -1) {
855 elseif (empty($user->rights->societe->client->voir)) {
871 dol_syslog(get_class($this).
"::Create success id=".$this->
id);
875 dol_syslog(get_class($this).
"::Create echec update ".$this->error.(empty($this->errors) ?
'' :
' '.join(
',', $this->errors)), LOG_ERR);
876 $this->
db->rollback();
880 if ($this->
db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
881 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", $this->name);
884 $this->error = $this->
db->lasterror();
887 $this->
db->rollback();
891 $this->
db->rollback();
892 dol_syslog(get_class($this).
"::Create fails verify ".join(
',', $this->errors), LOG_WARNING);
908 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
911 $contact->name = $this->name_bis;
912 $contact->firstname = $this->firstname;
913 $contact->civility_id = $this->civility_id;
914 $contact->socid = $this->id;
915 $contact->statut = 1;
916 $contact->status = 1;
918 $contact->country_id = $this->country_id;
919 $contact->state_id = $this->state_id;
920 $contact->address = $this->address;
921 $contact->email = $this->email;
922 $contact->zip = $this->zip;
923 $contact->town = $this->town;
924 $contact->phone_pro = $this->phone;
926 $result = $contact->create($user);
928 $this->error = $contact->error;
929 $this->errors = $contact->errors;
930 dol_syslog(get_class($this).
"::create_individual ERROR:".$this->error, LOG_ERR);
944 global $conf, $langs, $mysoc;
947 $this->errors = array();
951 $this->
nom = $this->name;
954 $this->errors[] =
'ErrorBadThirdPartyName';
960 if ($rescode != 0 && $rescode != -5) {
961 if ($rescode == -1) {
962 $this->errors[] =
'ErrorBadCustomerCodeSyntax';
963 } elseif ($rescode == -2) {
964 $this->errors[] =
'ErrorCustomerCodeRequired';
965 } elseif ($rescode == -3) {
966 $this->errors[] =
'ErrorCustomerCodeAlreadyUsed';
967 } elseif ($rescode == -4) {
968 $this->errors[] =
'ErrorPrefixRequired';
970 $this->errors[] =
'ErrorUnknownOnCustomerCodeCheck';
977 if ($this->fournisseur) {
979 if ($rescode != 0 && $rescode != -5) {
980 if ($rescode == -1) {
981 $this->errors[] =
'ErrorBadSupplierCodeSyntax';
982 } elseif ($rescode == -2) {
983 $this->errors[] =
'ErrorSupplierCodeRequired';
984 } elseif ($rescode == -3) {
985 $this->errors[] =
'ErrorSupplierCodeAlreadyUsed';
986 } elseif ($rescode == -4) {
987 $this->errors[] =
'ErrorPrefixRequired';
989 $this->errors[] =
'ErrorUnknownOnSupplierCodeCheck';
996 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL');
997 foreach ($array_to_check as $key) {
998 $keymin = strtolower($key);
999 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
1000 $vallabel = $this->$keymin;
1005 if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) {
1006 $idprof_mandatory =
'SOCIETE_'.$key.
'_MANDATORY';
1007 if (!$vallabel && !empty($conf->global->$idprof_mandatory)) {
1008 $langs->load(
"errors");
1010 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->transcountry(
'ProfId'.$i, $this->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1017 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1018 $langs->load(
"errors");
1020 $this->errors[] = $langs->transcountry(
'ProfId'.$i, $this->country_code).
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1026 if ($key ==
'EMAIL') {
1028 if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email)) {
1029 $langs->load(
"errors");
1031 $this->errors[] = $langs->trans(
"ErrorBadEMail", $this->email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1035 if (!$error && $vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE)) {
1036 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1037 $langs->load(
"errors");
1038 $error++; $this->errors[] = $langs->trans(
'Email').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1064 public function update($id, $user =
'', $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action =
'update', $nosyncmember = 1)
1066 global $langs, $conf, $hookmanager;
1068 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1076 dol_syslog(get_class($this).
"::Update id=".$id.
" call_trigger=".$call_trigger.
" allowmodcodeclient=".$allowmodcodeclient.
" allowmodcodefournisseur=".$allowmodcodefournisseur);
1082 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
1084 $this->
nom = $this->name;
1085 $this->name_alias = trim($this->name_alias);
1086 $this->ref_ext = trim($this->ref_ext);
1087 $this->address = $this->address ?trim($this->address) : trim($this->address);
1088 $this->zip = $this->zip ?trim($this->zip) : trim($this->zip);
1089 $this->town = $this->town ?trim($this->town) : trim($this->town);
1091 $this->state_id = trim($this->state_id);
1092 $this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
1093 $this->phone = trim($this->phone);
1094 $this->phone = preg_replace(
"/\s/",
"", $this->phone);
1095 $this->phone = preg_replace(
"/\./",
"", $this->phone);
1096 $this->fax = trim($this->fax);
1097 $this->fax = preg_replace(
"/\s/",
"", $this->fax);
1098 $this->fax = preg_replace(
"/\./",
"", $this->fax);
1099 $this->email = trim($this->email);
1100 $this->url = $this->url ?
clean_url($this->url, 0) :
'';
1101 $this->note_private = trim($this->note_private);
1102 $this->note_public = trim($this->note_public);
1103 $this->idprof1 = trim($this->idprof1);
1104 $this->idprof2 = trim($this->idprof2);
1105 $this->idprof3 = trim($this->idprof3);
1106 $this->idprof4 = trim($this->idprof4);
1107 $this->idprof5 = (!empty($this->idprof5) ?trim($this->idprof5) :
'');
1108 $this->idprof6 = (!empty($this->idprof6) ?trim($this->idprof6) :
'');
1109 $this->prefix_comm = trim($this->prefix_comm);
1110 $this->outstanding_limit =
price2num($this->outstanding_limit);
1111 $this->order_min_amount =
price2num($this->order_min_amount);
1112 $this->supplier_order_min_amount =
price2num($this->supplier_order_min_amount);
1114 $this->tva_assuj = trim($this->tva_assuj);
1116 if (empty($this->status)) {
1120 if (!empty($this->multicurrency_code)) {
1123 if (empty($this->fk_multicurrency)) {
1124 $this->multicurrency_code =
'';
1125 $this->fk_multicurrency = 0;
1129 $this->localtax1_assuj = trim($this->localtax1_assuj);
1130 $this->localtax2_assuj = trim($this->localtax2_assuj);
1132 $this->localtax1_value = trim($this->localtax1_value);
1133 $this->localtax2_value = trim($this->localtax2_value);
1135 if ($this->capital !=
'') {
1136 $this->capital =
price2num(trim($this->capital));
1138 if (!is_numeric($this->capital)) {
1139 $this->capital =
'';
1142 $this->effectif_id = trim($this->effectif_id);
1143 $this->forme_juridique_code = trim($this->forme_juridique_code);
1146 $this->barcode = trim($this->barcode);
1149 if ($this->code_client == -1 || $this->code_client ===
'auto') {
1152 if ($this->code_fournisseur == -1 || $this->code_fournisseur ===
'auto') {
1156 $this->code_compta = trim($this->code_compta);
1157 $this->code_compta_fournisseur = trim($this->code_compta_fournisseur);
1160 if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) {
1161 $langs->load(
"errors");
1162 $this->error = $langs->trans(
"BadValueForParameterClientOrSupplier");
1167 if (!empty($allowmodcodeclient) && !empty($this->client)) {
1169 if (empty($this->code_compta)) {
1180 if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) {
1182 if ($this->code_compta_fournisseur ==
"") {
1193 $this->webservices_url = $this->webservices_url ?
clean_url($this->webservices_url, 0) :
'';
1194 $this->webservices_key = trim($this->webservices_key);
1197 $this->fk_incoterms = (int) $this->fk_incoterms;
1198 $this->location_incoterms = trim($this->location_incoterms);
1205 if ($action !=
'add' && $action !=
'merge') {
1208 $result = $this->
verify();
1212 if (is_array($this->errors)) {
1213 if (in_array(
'ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) {
1214 if (($key = array_search(
'ErrorBadCustomerCodeSyntax', $this->errors)) !==
false) {
1215 unset($this->errors[$key]);
1218 if (in_array(
'ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) {
1219 if (($key = array_search(
'ErrorBadSupplierCodeSyntax', $this->errors)) !==
false) {
1220 unset($this->errors[$key]);
1223 if (empty($this->errors)) {
1230 dol_syslog(get_class($this).
"::update verify ok or not done");
1232 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe SET ";
1233 $sql .=
"entity = ".$this->db->escape($this->entity);
1234 $sql .=
",nom = '".$this->db->escape($this->
name).
"'";
1235 $sql .=
",name_alias = '".$this->db->escape($this->name_alias).
"'";
1236 $sql .=
",ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1237 $sql .=
",address = '".$this->db->escape($this->address).
"'";
1239 $sql .=
",zip = ".(!empty($this->zip) ?
"'".$this->db->escape($this->zip).
"'" :
"null");
1240 $sql .=
",town = ".(!empty($this->town) ?
"'".$this->db->escape($this->town).
"'" :
"null");
1242 $sql .=
",fk_departement = '".(!empty($this->state_id) ? $this->state_id :
'0').
"'";
1243 $sql .=
",fk_pays = '".(!empty($this->country_id) ? $this->country_id :
'0').
"'";
1245 $sql .=
",phone = ".(!empty($this->phone) ?
"'".$this->db->escape($this->phone).
"'" :
"null");
1246 $sql .=
",fax = ".(!empty($this->fax) ?
"'".$this->db->escape($this->fax).
"'" :
"null");
1247 $sql .=
",email = ".(!empty($this->email) ?
"'".$this->db->escape($this->email).
"'" :
"null");
1248 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1249 $sql .=
",url = ".(!empty($this->url) ?
"'".$this->db->escape($this->url).
"'" :
"null");
1251 $sql .=
",parent = ".($this->parent > 0 ? $this->parent :
"null");
1253 $sql .=
",note_private = ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
1254 $sql .=
",note_public = ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
1256 $sql .=
",siren = '".$this->db->escape($this->idprof1).
"'";
1257 $sql .=
",siret = '".$this->db->escape($this->idprof2).
"'";
1258 $sql .=
",ape = '".$this->db->escape($this->idprof3).
"'";
1259 $sql .=
",idprof4 = '".$this->db->escape($this->idprof4).
"'";
1260 $sql .=
",idprof5 = '".$this->db->escape($this->idprof5).
"'";
1261 $sql .=
",idprof6 = '".$this->db->escape($this->idprof6).
"'";
1263 $sql .=
",tva_assuj = ".($this->tva_assuj !=
'' ?
"'".$this->db->escape($this->tva_assuj).
"'" :
"null");
1264 $sql .=
",tva_intra = '".$this->db->escape($this->tva_intra).
"'";
1265 $sql .=
",status = ".$this->status;
1268 $sql .=
",localtax1_assuj = ".($this->localtax1_assuj !=
'' ?
"'".$this->db->escape($this->localtax1_assuj).
"'" :
"null");
1269 $sql .=
",localtax2_assuj = ".($this->localtax2_assuj !=
'' ?
"'".$this->db->escape($this->localtax2_assuj).
"'" :
"null");
1270 if ($this->localtax1_assuj == 1) {
1271 if ($this->localtax1_value !=
'') {
1272 $sql .=
",localtax1_value =".$this->localtax1_value;
1274 $sql .=
",localtax1_value =0.000";
1277 $sql .=
",localtax1_value =0.000";
1280 if ($this->localtax2_assuj == 1) {
1281 if ($this->localtax2_value !=
'') {
1282 $sql .=
",localtax2_value =".$this->localtax2_value;
1284 $sql .=
",localtax2_value =0.000";
1287 $sql .=
",localtax2_value =0.000";
1290 $sql .=
",capital = ".($this->capital ==
'' ?
"null" : $this->capital);
1292 $sql .=
",prefix_comm = ".(!empty($this->prefix_comm) ?
"'".$this->db->escape($this->prefix_comm).
"'" :
"null");
1294 $sql .=
",fk_effectif = ".(!empty($this->effectif_id) ?
"'".$this->db->escape($this->effectif_id).
"'" :
"null");
1295 if (isset($this->stcomm_id)) {
1296 $sql .=
",fk_stcomm=".(!empty($this->stcomm_id) ? $this->stcomm_id :
"0");
1298 $sql .=
",fk_typent = ".(!empty($this->typent_id) ?
"'".$this->db->escape($this->typent_id).
"'" :
"0");
1300 $sql .=
",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ?
"'".$this->db->escape($this->forme_juridique_code).
"'" :
"null");
1302 $sql .=
",mode_reglement = ".(!empty($this->mode_reglement_id) ?
"'".$this->db->escape($this->mode_reglement_id).
"'" :
"null");
1303 $sql .=
",cond_reglement = ".(!empty($this->cond_reglement_id) ?
"'".$this->db->escape($this->cond_reglement_id).
"'" :
"null");
1304 $sql .=
",transport_mode = ".(!empty($this->transport_mode_id) ?
"'".$this->db->escape($this->transport_mode_id).
"'" :
"null");
1305 $sql .=
",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ?
"'".$this->db->escape($this->mode_reglement_supplier_id).
"'" :
"null");
1306 $sql .=
",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ?
"'".$this->db->escape($this->cond_reglement_supplier_id).
"'" :
"null");
1307 $sql .=
",transport_mode_supplier = ".(!empty($this->transport_mode_supplier_id) ?
"'".$this->db->escape($this->transport_mode_supplier_id).
"'" :
"null");
1308 $sql .=
",fk_shipping_method = ".(!empty($this->shipping_method_id) ?
"'".$this->db->escape($this->shipping_method_id).
"'" :
"null");
1310 $sql .=
",client = ".(!empty($this->client) ? $this->client : 0);
1311 $sql .=
",fournisseur = ".(!empty($this->fournisseur) ? $this->fournisseur : 0);
1312 $sql .=
",barcode = ".(!empty($this->barcode) ?
"'".$this->db->escape($this->barcode).
"'" :
"null");
1313 $sql .=
",default_lang = ".(!empty($this->default_lang) ?
"'".$this->db->escape($this->default_lang).
"'" :
"null");
1314 $sql .=
",logo = ".(!empty($this->logo) ?
"'".$this->db->escape($this->logo).
"'" :
"null");
1315 $sql .=
",logo_squarred = ".(!empty($this->logo_squarred) ?
"'".$this->db->escape($this->logo_squarred).
"'" :
"null");
1316 $sql .=
",outstanding_limit= ".($this->outstanding_limit !=
'' ? $this->outstanding_limit :
'null');
1317 $sql .=
",order_min_amount= ".($this->order_min_amount !=
'' ? $this->order_min_amount :
'null');
1318 $sql .=
",supplier_order_min_amount= ".($this->supplier_order_min_amount !=
'' ? $this->supplier_order_min_amount :
'null');
1319 $sql .=
",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel).
"'";
1321 $sql .=
",webservices_url = ".(!empty($this->webservices_url) ?
"'".$this->db->escape($this->webservices_url).
"'" :
"null");
1322 $sql .=
",webservices_key = ".(!empty($this->webservices_key) ?
"'".$this->db->escape($this->webservices_key).
"'" :
"null");
1325 $sql .=
", fk_incoterms = ".$this->fk_incoterms;
1326 $sql .=
", location_incoterms = ".(!empty($this->location_incoterms) ?
"'".$this->db->escape($this->location_incoterms).
"'" :
"null");
1329 $sql .=
", code_client = ".(!empty($this->code_client) ?
"'".$this->db->escape($this->code_client).
"'" :
"null");
1330 $sql .=
", code_compta = ".(!empty($this->code_compta) ?
"'".$this->db->escape($this->code_compta).
"'" :
"null");
1334 $sql .=
", code_fournisseur = ".(!empty($this->code_fournisseur) ?
"'".$this->db->escape($this->code_fournisseur).
"'" :
"null");
1335 $sql .=
", code_compta_fournisseur = ".(($this->code_compta_fournisseur !=
"") ?
"'".$this->
db->escape($this->code_compta_fournisseur).
"'" :
"null");
1337 $sql .=
", fk_user_modif = ".($user->id > 0 ? $user->id :
"null");
1338 $sql .=
", fk_multicurrency = ".(int) $this->fk_multicurrency;
1339 $sql .=
", multicurrency_code = '".$this->db->escape($this->multicurrency_code).
"'";
1340 $sql .=
", model_pdf = '".$this->db->escape($this->model_pdf).
"'";
1341 $sql .=
" WHERE rowid = ".(int) $id;
1345 if (is_object($this->oldcopy)) {
1346 if ($this->oldcopy->country_id != $this->country_id) {
1347 unset($this->country_code);
1348 unset($this->country);
1350 if ($this->oldcopy->state_id != $this->state_id) {
1351 unset($this->state_code);
1352 unset($this->state);
1355 unset($this->country_code);
1356 unset($this->country);
1357 unset($this->state_code);
1358 unset($this->state);
1361 $nbrowsaffected = $this->
db->affected_rows(
$resql);
1363 if (!$error && $nbrowsaffected) {
1365 if (!$nosyncmember && !empty($conf->adherent->enabled)) {
1366 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1368 dol_syslog(get_class($this).
"::update update linked member");
1371 $result = $lmember->fetch(0, 0, $this->
id);
1374 $lmember->company = $this->name;
1377 $lmember->address = $this->address;
1378 $lmember->zip = $this->zip;
1379 $lmember->town = $this->town;
1380 $lmember->email = $this->email;
1381 $lmember->socialnetworks = $this->socialnetworks;
1382 $lmember->phone = $this->phone;
1383 $lmember->state_id = $this->state_id;
1384 $lmember->country_id = $this->country_id;
1386 $result = $lmember->update($user, 0, 1, 1, 1);
1388 $this->error = $lmember->error;
1389 $this->errors = array_merge($this->errors, $lmember->errors);
1390 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
1393 } elseif ($result < 0) {
1394 $this->error = $lmember->error;
1410 if (!$error && empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) {
1417 if (!$error && $call_trigger) {
1419 $result = $this->
call_trigger(
'COMPANY_MODIFY', $user);
1427 dol_syslog(get_class($this).
"::Update success");
1428 $this->
db->commit();
1431 $this->
db->rollback();
1435 if ($this->
db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1437 $this->error = $langs->trans(
"ErrorDuplicateField");
1440 $this->error = $this->
db->lasterror();
1443 $this->
db->rollback();
1447 $this->
db->rollback();
1448 dol_syslog(get_class($this).
"::Update fails verify ".join(
',', $this->errors), LOG_WARNING);
1470 public function fetch($rowid, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'')
1475 if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) {
1479 $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';
1480 $sql .=
', s.status';
1481 $sql .=
', s.price_level';
1482 $sql .=
', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif';
1483 $sql .=
', s.phone, s.fax, s.email';
1484 $sql .=
', s.socialnetworks';
1485 $sql .=
', s.url, s.zip, s.town, s.note_private, s.note_public, s.model_pdf, s.client, s.fournisseur';
1486 $sql .=
', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1487 $sql .=
', s.capital, s.tva_intra';
1488 $sql .=
', s.fk_typent as typent_id';
1489 $sql .=
', s.fk_effectif as effectif_id';
1490 $sql .=
', s.fk_forme_juridique as forme_juridique_code';
1491 $sql .=
', s.webservices_url, s.webservices_key';
1492 $sql .=
', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode';
1493 $sql .=
', s.fk_departement as state_id, s.fk_pays as country_id, s.fk_stcomm, s.remise_supplier, s.mode_reglement, s.cond_reglement, s.transport_mode';
1494 $sql .=
', s.fk_account, s.tva_assuj';
1495 $sql .=
', s.mode_reglement_supplier, s.cond_reglement_supplier, s.transport_mode_supplier';
1496 $sql .=
', s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred';
1497 $sql .=
', s.fk_shipping_method';
1498 $sql .=
', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1499 $sql .=
', s.order_min_amount, s.supplier_order_min_amount';
1500 $sql .=
', s.fk_multicurrency, s.multicurrency_code';
1501 $sql .=
', fj.libelle as forme_juridique';
1502 $sql .=
', e.libelle as effectif';
1503 $sql .=
', c.code as country_code, c.label as country';
1504 $sql .=
', d.code_departement as state_code, d.nom as state';
1505 $sql .=
', st.libelle as stcomm, st.picto as stcomm_picto';
1506 $sql .=
', te.code as typent_code';
1507 $sql .=
', i.libelle as label_incoterms';
1508 $sql .=
', sr.remise_client, model_pdf';
1509 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
1510 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_effectif as e ON s.fk_effectif = e.id';
1511 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON s.fk_pays = c.rowid';
1512 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcomm as st ON s.fk_stcomm = st.id';
1513 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
1514 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON s.fk_departement = d.rowid';
1515 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_typent as te ON s.fk_typent = te.id';
1516 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON s.fk_incoterms = i.rowid';
1517 $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').
'))';
1519 $sql .=
' WHERE s.entity IN ('.getEntity($this->element).
')';
1521 $sql .=
' AND s.rowid = '.$rowid;
1524 $sql .=
" AND s.nom = '".$this->db->escape($ref).
"'";
1527 $sql .=
" AND s.name_alias = '".$this->db->escape($ref_alias).
"'";
1530 $sql .=
" AND s.ref_ext = '".$this->db->escape($ref_ext).
"'";
1533 $sql .=
" AND s.barcode = '".$this->db->escape($barcode).
"'";
1536 $sql .=
" AND s.siren = '".$this->db->escape($idprof1).
"'";
1539 $sql .=
" AND s.siret = '".$this->db->escape($idprof2).
"'";
1542 $sql .=
" AND s.ape = '".$this->db->escape($idprof3).
"'";
1545 $sql .=
" AND s.idprof4 = '".$this->db->escape($idprof4).
"'";
1548 $sql .=
" AND s.idprof5 = '".$this->db->escape($idprof5).
"'";
1551 $sql .=
" AND s.idprof6 = '".$this->db->escape($idprof6).
"'";
1554 $sql .=
" AND s.email = '".$this->db->escape($email).
"'";
1559 $num = $this->
db->num_rows(
$resql);
1561 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
1565 $obj = $this->
db->fetch_object(
$resql);
1567 $this->
id = $obj->rowid;
1568 $this->entity = $obj->entity;
1569 $this->canvas = $obj->canvas;
1571 $this->ref = $obj->rowid;
1572 $this->
name = $obj->name;
1573 $this->
nom = $obj->name;
1574 $this->name_alias = $obj->name_alias;
1575 $this->ref_ext = $obj->ref_ext;
1577 $this->date_creation = $this->
db->jdate($obj->date_creation);
1578 $this->date_modification = $this->
db->jdate($obj->date_modification);
1579 $this->user_creation = $obj->fk_user_creat;
1580 $this->user_modification = $obj->fk_user_modif;
1582 $this->address = $obj->address;
1583 $this->zip = $obj->zip;
1584 $this->town = $obj->town;
1586 $this->country_id = $obj->country_id;
1587 $this->country_code = $obj->country_id ? $obj->country_code :
'';
1588 $this->country = $obj->country_id ? ($langs->transnoentities(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
1590 $this->state_id = $obj->state_id;
1591 $this->state_code = $obj->state_code;
1592 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
1594 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcomm);
1595 $label = ($transcode !=
'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm);
1596 $this->stcomm_id = $obj->fk_stcomm;
1597 $this->status_prospect_label = $label;
1598 $this->stcomm_picto = $obj->stcomm_picto;
1600 $this->email = $obj->email;
1601 $this->socialnetworks = (array) json_decode($obj->socialnetworks,
true);
1603 $this->url = $obj->url;
1604 $this->phone = $obj->phone;
1605 $this->fax = $obj->fax;
1607 $this->parent = $obj->parent;
1609 $this->idprof1 = $obj->idprof1;
1610 $this->idprof2 = $obj->idprof2;
1611 $this->idprof3 = $obj->idprof3;
1612 $this->idprof4 = $obj->idprof4;
1613 $this->idprof5 = $obj->idprof5;
1614 $this->idprof6 = $obj->idprof6;
1616 $this->capital = $obj->capital;
1618 $this->code_client = $obj->code_client;
1619 $this->code_fournisseur = $obj->code_fournisseur;
1621 $this->code_compta = $obj->code_compta;
1622 $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
1624 $this->barcode = $obj->barcode;
1626 $this->tva_assuj = $obj->tva_assuj;
1627 $this->tva_intra = $obj->tva_intra;
1628 $this->status = $obj->status;
1631 $this->localtax1_assuj = $obj->localtax1_assuj;
1632 $this->localtax2_assuj = $obj->localtax2_assuj;
1634 $this->localtax1_value = $obj->localtax1_value;
1635 $this->localtax2_value = $obj->localtax2_value;
1637 $this->typent_id = $obj->typent_id;
1638 $this->typent_code = $obj->typent_code;
1640 $this->effectif_id = $obj->effectif_id;
1641 $this->effectif = $obj->effectif_id ? $obj->effectif :
'';
1643 $this->forme_juridique_code = $obj->forme_juridique_code;
1644 $this->forme_juridique = $obj->forme_juridique_code ? $obj->forme_juridique :
'';
1646 $this->fk_prospectlevel = $obj->fk_prospectlevel;
1648 $this->prefix_comm = $obj->prefix_comm;
1650 $this->remise_percent = $obj->remise_client ?
price2num($obj->remise_client) : 0;
1651 $this->remise_supplier_percent = $obj->remise_supplier;
1652 $this->mode_reglement_id = $obj->mode_reglement;
1653 $this->cond_reglement_id = $obj->cond_reglement;
1654 $this->transport_mode_id = $obj->transport_mode;
1655 $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier;
1656 $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier;
1657 $this->transport_mode_supplier_id = $obj->transport_mode_supplier;
1658 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method : null;
1659 $this->fk_account = $obj->fk_account;
1661 $this->client = $obj->client;
1662 $this->fournisseur = $obj->fournisseur;
1664 $this->note = $obj->note_private;
1665 $this->note_private = $obj->note_private;
1666 $this->note_public = $obj->note_public;
1667 $this->model_pdf = $obj->model_pdf;
1668 $this->modelpdf = $obj->model_pdf;
1669 $this->default_lang = $obj->default_lang;
1670 $this->logo = $obj->logo;
1671 $this->logo_squarred = $obj->logo_squarred;
1673 $this->webservices_url = $obj->webservices_url;
1674 $this->webservices_key = $obj->webservices_key;
1676 $this->outstanding_limit = $obj->outstanding_limit;
1677 $this->order_min_amount = $obj->order_min_amount;
1678 $this->supplier_order_min_amount = $obj->supplier_order_min_amount;
1681 $this->price_level = $obj->price_level;
1683 $this->import_key = $obj->import_key;
1686 $this->fk_incoterms = $obj->fk_incoterms;
1687 $this->location_incoterms = $obj->location_incoterms;
1688 $this->label_incoterms = $obj->label_incoterms;
1691 $this->fk_multicurrency = $obj->fk_multicurrency;
1692 $this->multicurrency_code = $obj->multicurrency_code;
1693 $this->model_pdf = $obj->model_pdf;
1698 $this->fetch_optionals();
1705 $this->error = $this->
db->lasterror();
1710 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($this->price_level)) {
1711 $this->price_level = 1;
1725 public function delete($id,
User $fuser = null, $call_trigger = 1)
1727 global $langs, $conf, $user;
1729 if (empty($fuser)) {
1733 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1735 $entity = isset($this->entity) ? $this->entity : $conf->entity;
1737 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1742 if (empty($objectisused)) {
1746 if (!$error && $call_trigger) {
1748 $result = $this->
call_trigger(
'COMPANY_DELETE', $fuser);
1756 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1758 $toute_categs = array();
1761 if ($this->client || $this->prospect) {
1762 $toute_categs[
'customer'] = $static_cat->containing($this->
id, Categorie::TYPE_CUSTOMER);
1764 if ($this->fournisseur) {
1765 $toute_categs[
'supplier'] = $static_cat->containing($this->
id, Categorie::TYPE_SUPPLIER);
1769 foreach ($toute_categs as $type => $categs_type) {
1770 foreach ($categs_type as $cat) {
1771 $cat->del_type($this, $type);
1777 foreach ($this->childtablesoncascade as $tabletodelete) {
1778 $deleteFromObject = explode(
':', $tabletodelete);
1779 if (count($deleteFromObject) >= 2) {
1780 $className = str_replace(
'@',
'', $deleteFromObject[0]);
1781 $filepath = $deleteFromObject[1];
1782 $columnName = $deleteFromObject[2];
1784 $child_object =
new $className($this->
db);
1785 $result = $child_object->deleteByParentField($id, $columnName);
1788 $this->errors[] = $child_object->error;
1793 $this->errors[] =
'Cannot include child class file '.$filepath;
1797 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
1798 $sql .=
" WHERE fk_soc = ".$id;
1799 if (!$this->
db->query($sql)) {
1801 $this->errors[] = $this->
db->lasterror();
1813 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
1819 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
1820 $sql .=
" SET parent = NULL";
1821 $sql .=
" WHERE parent = ".$id;
1822 if (!$this->
db->query($sql)) {
1824 $this->errors[] = $this->
db->lasterror();
1830 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe";
1831 $sql .=
" WHERE rowid = ".$id;
1832 if (!$this->
db->query($sql)) {
1834 $this->errors[] = $this->
db->lasterror();
1839 $this->
db->commit();
1842 if (!empty($conf->societe->multidir_output[$entity])) {
1843 $docdir = $conf->societe->multidir_output[$entity].
"/".$id;
1852 $this->
db->rollback();
1856 dol_syslog(
"Can't remove thirdparty with id ".$id.
". There is ".$objectisused.
" childs", LOG_WARNING);
1872 if ($this->client == 2 || $this->client == 3) {
1875 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
1876 $sql .=
" SET client = ".$newclient;
1877 $sql .=
" WHERE rowid = ".$this->id;
1881 $this->client = $newclient;
1902 global $conf, $langs;
1905 $note = trim($note);
1907 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
1911 dol_syslog(get_class($this).
"::set_remise_client ".$remise.
", ".$note.
", ".$user->id);
1919 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
1920 $sql .=
" SET remise_client = '".$this->db->escape($remise).
"'";
1921 $sql .=
" WHERE rowid = ".$this->id;
1924 $this->
db->rollback();
1925 $this->error = $this->
db->error();
1930 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise";
1931 $sql .=
" (entity, datec, fk_soc, remise_client, note, fk_user_author)";
1932 $sql .=
" VALUES (".$conf->entity.
", '".$this->
db->idate($now).
"', ".$this->
id.
", '".$this->
db->escape($remise).
"',";
1933 $sql .=
" '".$this->db->escape($note).
"',";
1934 $sql .=
" ".$user->id;
1939 $this->
db->rollback();
1940 $this->error = $this->
db->lasterror();
1944 $this->
db->commit();
1961 global $conf, $langs;
1964 $note = trim($note);
1966 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
1970 dol_syslog(get_class($this).
"::set_remise_supplier ".$remise.
", ".$note.
", ".$user->id);
1978 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
1979 $sql .=
" SET remise_supplier = '".$this->db->escape($remise).
"'";
1980 $sql .=
" WHERE rowid = ".$this->id;
1983 $this->
db->rollback();
1984 $this->error = $this->
db->error();
1989 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise_supplier";
1990 $sql .=
" (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
1991 $sql .=
" VALUES (".$conf->entity.
", '".$this->
db->idate($now).
"', ".$this->
id.
", '".$this->
db->escape($remise).
"',";
1992 $sql .=
" '".$this->db->escape($note).
"',";
1993 $sql .=
" ".$user->id;
1998 $this->
db->rollback();
1999 $this->error = $this->
db->lasterror();
2003 $this->
db->commit();
2026 $desc = trim($desc);
2030 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"1");
2034 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"3");
2038 if ($this->
id > 0) {
2042 if (preg_match(
'/\((.*)\)/', $vatrate, $reg)) {
2043 $vat_src_code = $reg[1];
2044 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2047 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2050 $discount->fk_soc = $this->id;
2052 $discount->discount_type = $discount_type;
2054 $discount->amount_ht = $discount->multicurrency_amount_ht =
price2num($remise,
'MT');
2055 $discount->amount_tva = $discount->multicurrency_amount_tva =
price2num($remise * $vatrate / 100,
'MT');
2056 $discount->amount_ttc = $discount->multicurrency_amount_ttc =
price2num($discount->amount_ht + $discount->amount_tva,
'MT');
2058 $discount->tva_tx =
price2num($vatrate);
2059 $discount->vat_src_code = $vat_src_code;
2061 $discount->description = $desc;
2063 $result = $discount->create($user);
2067 $this->error = $discount->error;
2086 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2089 $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type);
2093 $this->error = $discountstatic->error;
2111 $reparray = array();
2113 $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";
2114 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc, ".MAIN_DB_PREFIX.
"user as u";
2115 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2116 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
2117 $sql .=
" WHERE ((ug.fk_user = sc.fk_user";
2118 $sql .=
" AND ug.entity = ".$conf->entity.
")";
2119 $sql .=
" OR u.admin = 1)";
2121 $sql .=
" WHERE entity in (0, ".$conf->entity.
")";
2124 $sql .=
" AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
2125 if (empty($sortfield) && empty($sortorder)) {
2126 $sortfield =
'u.lastname,u.firstname';
2127 $sortorder =
'ASC,ASC';
2129 $sql .= $this->
db->order($sortfield, $sortorder);
2133 $num = $this->
db->num_rows(
$resql);
2136 $obj = $this->
db->fetch_object(
$resql);
2139 $reparray[$i][
'id'] = $obj->rowid;
2140 $reparray[$i][
'lastname'] = $obj->lastname;
2141 $reparray[$i][
'firstname'] = $obj->firstname;
2142 $reparray[$i][
'email'] = $obj->email;
2143 $reparray[$i][
'phone'] = $obj->office_phone;
2144 $reparray[$i][
'job'] = $obj->job;
2145 $reparray[$i][
'statut'] = $obj->status;
2146 $reparray[$i][
'status'] = $obj->status;
2147 $reparray[$i][
'entity'] = $obj->entity;
2148 $reparray[$i][
'login'] = $obj->login;
2149 $reparray[$i][
'photo'] = $obj->photo;
2151 $reparray[] = $obj->rowid;
2176 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2177 $sql .=
" SET price_level = '".$this->db->escape($price_level).
"'";
2178 $sql .=
" WHERE rowid = ".$this->id;
2180 if (!$this->
db->query($sql)) {
2185 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_prices";
2186 $sql .=
" (datec, fk_soc, price_level, fk_user_author)";
2187 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".$this->
id.
", '".$this->
db->escape($price_level).
"', ".$user->id.
")";
2189 if (!$this->
db->query($sql)) {
2211 if ($this->
id > 0 && $commid > 0) {
2215 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux";
2216 $sql .=
" WHERE fk_soc = ".$this->id.
" AND fk_user =".$commid;
2220 dol_syslog(get_class($this).
"::add_commercial Error ".$this->
db->lasterror());
2226 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_commerciaux";
2227 $sql .=
" (fk_soc, fk_user)";
2228 $sql .=
" VALUES (".$this->id.
", ".$commid.
")";
2232 dol_syslog(get_class($this).
"::add_commercial Error ".$this->
db->lasterror());
2238 $this->context = array(
'commercial_modified'=>$commid);
2240 $result = $this->
call_trigger(
'COMPANY_LINK_SALE_REPRESENTATIVE', $user);
2247 $this->
db->commit();
2250 $this->
db->rollback();
2270 $this->context = array(
'commercial_modified'=>$commid);
2272 $result = $this->
call_trigger(
'COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
2277 if ($this->
id > 0 && $commid > 0) {
2278 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux ";
2279 $sql .=
" WHERE fk_soc = ".$this->id.
" AND fk_user =".$commid;
2281 if (!$this->
db->query($sql)) {
2282 dol_syslog(get_class($this).
"::del_commercial Erreur");
2298 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1)
2300 global $conf, $langs, $hookmanager;
2302 if (!empty($conf->dol_no_mouse_hover)) {
2306 $name = $this->
name ? $this->
name : $this->nom;
2308 if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) {
2309 if (empty($option) && $this->client > 0) {
2310 $option =
'customer';
2312 if (empty($option) && $this->fournisseur > 0) {
2313 $option =
'supplier';
2317 if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto))) {
2319 if (($this->client) && (!empty($this->code_client)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 2)) {
2320 $code = $this->code_client.
' - ';
2323 if (($this->fournisseur) && (!empty($this->code_fournisseur)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 3)) {
2324 $code .= $this->code_fournisseur.
' - ';
2328 if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1) {
2329 $name = $code.
' '.$name;
2336 if (!empty($this->name_alias)) {
2337 $name .=
' ('.$this->name_alias.
')';
2340 $result =
''; $label =
'';
2341 $linkstart =
''; $linkend =
'';
2343 if (!empty($this->logo) && class_exists(
'Form')) {
2344 $label .=
'<div class="photointooltip">';
2346 $label .=
'</div><div style="clear: both;"></div>';
2347 } elseif (!empty($this->logo_squarred) && class_exists(
'Form')) {
2353 $label .=
'<div class="centpercent">';
2355 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
2356 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Customer").
'</u>';
2357 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2358 } elseif ($option ==
'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
2359 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Prospect").
'</u>';
2360 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2361 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
2362 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Supplier").
'</u>';
2363 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->id;
2364 } elseif ($option ==
'agenda') {
2365 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2366 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/agenda.php?socid='.$this->id;
2367 } elseif ($option ==
'project') {
2368 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2369 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/project.php?socid='.$this->id;
2370 } elseif ($option ==
'margin') {
2371 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2372 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/margin/tabs/thirdpartyMargins.php?socid='.$this->
id.
'&type=1';
2373 } elseif ($option ==
'contact') {
2374 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2375 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/contact.php?socid='.$this->id;
2376 } elseif ($option ==
'ban') {
2377 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2378 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$this->id;
2382 if (empty($linkstart)) {
2383 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2384 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$this->id;
2386 if (isset($this->status)) {
2387 $label .=
' '.$this->getLibStatut(5);
2390 if (!empty($this->
name)) {
2392 if (!empty($this->name_alias)) {
2393 $label .=
' ('.dol_escape_htmltag($this->name_alias).
')';
2396 $label .=
'<br><b>'.$langs->trans(
'Email').
':</b> '.$this->email;
2397 if (!empty($this->country_code)) {
2398 $label .=
'<br><b>'.$langs->trans(
'Country').
':</b> '.$this->country_code;
2400 if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'vatnumber') !==
false)) {
2401 $label .=
'<br><b>'.$langs->trans(
'VATIntra').
':</b> '.
dol_escape_htmltag($this->tva_intra);
2403 if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP)) {
2404 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid1') !==
false) {
2405 $label .=
'<br><b>'.$langs->trans(
'ProfId1'.$this->country_code).
':</b> '.$this->idprof1;
2407 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid2') !==
false) {
2408 $label .=
'<br><b>'.$langs->trans(
'ProfId2'.$this->country_code).
':</b> '.$this->idprof2;
2410 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid3') !==
false) {
2411 $label .=
'<br><b>'.$langs->trans(
'ProfId3'.$this->country_code).
':</b> '.$this->idprof3;
2413 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid4') !==
false) {
2414 $label .=
'<br><b>'.$langs->trans(
'ProfId4'.$this->country_code).
':</b> '.$this->idprof4;
2416 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid5') !==
false) {
2417 $label .=
'<br><b>'.$langs->trans(
'ProfId5'.$this->country_code).
':</b> '.$this->idprof5;
2419 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid6') !==
false) {
2420 $label .=
'<br><b>'.$langs->trans(
'ProfId6'.$this->country_code).
':</b> '.$this->idprof6;
2423 if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
2424 $label .=
'<br><b>'.$langs->trans(
'CustomerCode').
':</b> '.$this->code_client;
2426 if (!empty($this->code_fournisseur) && $this->fournisseur) {
2427 $label .=
'<br><b>'.$langs->trans(
'SupplierCode').
':</b> '.$this->code_fournisseur;
2429 if (!empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3)) {
2430 $label .=
'<br><b>'.$langs->trans(
'CustomerAccountancyCode').
':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client);
2432 if (!empty($conf->accounting->enabled) && $this->fournisseur) {
2433 $label .=
'<br><b>'.$langs->trans(
'SupplierAccountancyCode').
':</b> '.$this->code_compta_fournisseur;
2438 $linkstart .= (!empty($this->canvas) ?
'&canvas='.$this->canvas :
'');
2440 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2441 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) {
2442 $add_save_lastsearch_values = 1;
2444 if ($add_save_lastsearch_values) {
2445 $linkstart .=
'&save_lastsearch_values=1';
2450 if (empty($notooltip)) {
2451 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2452 $label = $langs->trans(
"ShowCompany");
2453 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2455 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
2456 $linkclose .=
' class="classfortooltip refurl"';
2465 $linkstart .= $linkclose.
'>';
2469 if (!$user->rights->societe->client->voir && $user->socid > 0 && $this->id != $user->socid) {
2474 $result .= $linkstart;
2476 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
2478 if ($withpicto != 2) {
2481 $result .= $linkend;
2484 $hookmanager->initHooks(array(
'thirdpartydao'));
2485 $parameters = array(
2487 'getnomurl'=>$result,
2488 'withpicto '=> $withpicto,
2491 'notooltip'=> $notooltip,
2492 'save_lastsearch_value'=> $save_lastsearch_value
2494 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2496 $result = $hookmanager->resPrint;
2498 $result .= $hookmanager->resPrint;
2512 return $this->
LibStatut($this->status, $mode);
2527 $langs->load(
'companies');
2529 $statusType =
'status4';
2531 $statusType =
'status6';
2534 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2535 $this->labelStatus[0] = $langs->trans(
"ActivityCeased");
2536 $this->labelStatus[1] = $langs->trans(
"InActivity");
2537 $this->labelStatusShort[0] = $langs->trans(
"ActivityCeased");
2538 $this->labelStatusShort[1] = $langs->trans(
"InActivity");
2541 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2557 if ($this->email && $addthirdparty) {
2558 if (empty($this->
name)) {
2559 $this->
name = $this->nom;
2561 $contact_emails[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->email.
">";
2564 return $contact_emails;
2580 if (!empty($this->phone)) {
2581 if (empty($this->
name)) {
2582 $this->
name = $this->nom;
2585 $contact_phone[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->phone.
">";
2587 return $contact_phone;
2603 $contact_property = array();
2606 $sql =
"SELECT rowid, email, statut as status, phone_mobile, lastname, poste, firstname";
2607 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
2608 $sql .=
" WHERE fk_soc = ".$this->id;
2609 $sql .=
" ORDER BY lastname, firstname";
2613 $nump = $this->
db->num_rows(
$resql);
2615 $sepa =
"("; $sepb =
")";
2616 if ($mode ==
'email') {
2618 $sepa =
"<"; $sepb =
">";
2621 while ($i < $nump) {
2622 $obj = $this->
db->fetch_object(
$resql);
2623 if ($mode ==
'email') {
2624 $property = $obj->email;
2625 } elseif ($mode ==
'mobile') {
2626 $property = $obj->phone_mobile;
2628 $property = $obj->$mode;
2632 if ($obj->status == 1 || empty($hidedisabled)) {
2633 if (empty($property)) {
2634 if ($mode ==
'email') {
2635 $property = $langs->transnoentitiesnoconv(
"NoEMail");
2636 } elseif ($mode ==
'mobile') {
2637 $property = $langs->transnoentitiesnoconv(
"NoMobilePhone");
2641 if (!empty($obj->poste)) {
2642 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ?
" - ".$obj->poste :
"").(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
2644 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
2653 return $contact_property;
2666 $contacts = array();
2668 $sql =
"SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".$this->id;
2671 $nump = $this->
db->num_rows(
$resql);
2674 while ($i < $nump) {
2675 $obj = $this->
db->fetch_object(
$resql);
2695 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2696 $contacts = array();
2698 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".$this->id;
2701 $nump = $this->
db->num_rows(
$resql);
2704 while ($i < $nump) {
2705 $obj = $this->
db->fetch_object(
$resql);
2707 $contact->fetch($obj->rowid);
2708 $contacts[] = $contact;
2729 $contact_property =
'';
2731 if (empty($rowid)) {
2735 $sql =
"SELECT rowid, email, phone_mobile, lastname, firstname";
2736 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
2737 $sql .=
" WHERE rowid = ".((int) $rowid);
2741 $nump = $this->
db->num_rows(
$resql);
2744 $obj = $this->
db->fetch_object(
$resql);
2746 if ($mode ==
'email') {
2748 } elseif ($mode ==
'mobile') {
2749 $contact_property = $obj->phone_mobile;
2752 return $contact_property;
2769 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
2772 $bac->fetch(0, $this->
id);
2775 if ($mode ==
'label') {
2776 return $bac->getRibLabel(
true);
2777 } elseif ($mode ==
'rum') {
2778 if (empty($bac->rum)) {
2779 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
2781 $bac->fetch_thirdparty();
2782 $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
2785 } elseif ($mode ==
'format') {
2786 return $bac->frstrecur;
2788 return 'BadParameterToFunctionDisplayRib';
2804 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
2805 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE type='ban' AND fk_soc = ".$this->id;
2806 $result = $this->
db->query($sql);
2809 $this->errors[] = $this->
db->lasterror;
2812 $num_rows = $this->
db->num_rows($result);
2813 $rib_array = array();
2815 while ($obj = $this->
db->fetch_object($result)) {
2817 $rib->fetch($obj->rowid);
2818 $rib_array[] = $rib;
2838 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
2839 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2841 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
2842 foreach ($dirsociete as $dirroot) {
2848 $mod =
new $module();
2850 $this->code_client = $mod->getNextValue($objsoc, $type);
2851 $this->prefixCustomerIsRequired = $mod->prefixIsRequired;
2853 dol_syslog(get_class($this).
"::get_codeclient code_client=".$this->code_client.
" module=".$module);
2870 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
2871 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2873 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
2874 foreach ($dirsociete as $dirroot) {
2880 $mod =
new $module();
2882 $this->code_fournisseur = $mod->getNextValue($objsoc, $type);
2884 dol_syslog(get_class($this).
"::get_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
2899 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
2900 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2902 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
2903 foreach ($dirsociete as $dirroot) {
2910 $mod =
new $module();
2912 dol_syslog(get_class($this).
"::codeclient_modifiable code_client=".$this->code_client.
" module=".$module);
2913 if ($mod->code_modifiable_null && !$this->code_client) {
2916 if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
2919 if ($mod->code_modifiable) {
2939 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
2940 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2942 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
2943 foreach ($dirsociete as $dirroot) {
2950 $mod =
new $module();
2952 dol_syslog(get_class($this).
"::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur.
" module=".$module);
2953 if ($mod->code_modifiable_null && !$this->code_fournisseur) {
2956 if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
2959 if ($mod->code_modifiable) {
2985 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
2986 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2988 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
2989 foreach ($dirsociete as $dirroot) {
2996 $mod =
new $module();
2998 dol_syslog(get_class($this).
"::check_codeclient code_client=".$this->code_client.
" module=".$module);
2999 $result = $mod->verif($this->
db, $this->code_client, $this, 0);
3001 $this->error = $mod->error;
3002 $this->errors = $mod->errors;
3026 if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
3027 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
3029 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3030 foreach ($dirsociete as $dirroot) {
3037 $mod =
new $module();
3039 dol_syslog(get_class($this).
"::check_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3040 $result = $mod->verif($this->
db, $this->code_fournisseur, $this, 1);
3042 $this->error = $mod->error;
3043 $this->errors = $mod->errors;
3065 if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) {
3067 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3068 foreach ($dirsociete as $dirroot) {
3069 $res =
dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.
'.php');
3076 $classname = $conf->global->SOCIETE_CODECOMPTA_ADDON;
3077 $mod =
new $classname;
3080 $result = $mod->get_code($this->
db, $this, $type);
3082 if ($type ==
'customer') {
3083 $this->code_compta = $mod->code;
3084 } elseif ($type ==
'supplier') {
3085 $this->code_compta_fournisseur = $mod->code;
3090 $this->error =
'ErrorAccountancyCodeNotDefined';
3094 if ($type ==
'customer') {
3095 $this->code_compta =
'';
3096 } elseif ($type ==
'supplier') {
3097 $this->code_compta_fournisseur =
'';
3115 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
3116 $sql .=
" SET parent = ".($id > 0 ? $id :
"null");
3117 $sql .=
" WHERE rowid = ".$this->id;
3118 dol_syslog(get_class($this).
'::set_parent', LOG_DEBUG);
3121 $this->parent = $id;
3145 $ret = (empty($conf->global->SOCIETE_IDPROF1_UNIQUE) ?
false :
true);
3148 $ret = (empty($conf->global->SOCIETE_IDPROF2_UNIQUE) ?
false :
true);
3151 $ret = (empty($conf->global->SOCIETE_IDPROF3_UNIQUE) ?
false :
true);
3154 $ret = (empty($conf->global->SOCIETE_IDPROF4_UNIQUE) ?
false :
true);
3157 $ret = (empty($conf->global->SOCIETE_IDPROF5_UNIQUE) ?
false :
true);
3160 $ret = (empty($conf->global->SOCIETE_IDPROF6_UNIQUE) ?
false :
true);
3209 $sql =
"SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX.
"societe WHERE ".$field.
" = '".$this->
db->escape($value).
"' AND entity IN (".
getEntity(
'societe').
")";
3211 $sql .=
" AND rowid <> ".$socid;
3215 $obj = $this->
db->fetch_object(
$resql);
3216 $count = $obj->idprof;
3246 if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3251 if ($idprof == 1 && $soc->country_code ==
'FR') {
3252 $chaine = trim($this->idprof1);
3253 $chaine = preg_replace(
'/(\s)/',
'', $chaine);
3255 if (!is_numeric($chaine)) {
3267 for ($index = 0; $index < 9; $index++) {
3268 $number = (int) $chaine[$index];
3269 if (($index % 2) != 0) {
3270 if (($number *= 2) > 9) {
3278 if (($sum % 10) != 0) {
3284 if ($idprof == 2 && $soc->country_code ==
'FR') {
3285 $chaine = trim($this->idprof2);
3286 $chaine = preg_replace(
'/(\s)/',
'', $chaine);
3288 if (!is_numeric($chaine)) {
3300 for ($index = 0; $index < 14; $index++) {
3301 $number = (int) $chaine[$index];
3302 if (($index % 2) == 0) {
3303 if (($number *= 2) > 9) {
3311 if (($sum % 10) != 0) {
3318 if ($idprof == 1 && $soc->country_code ==
'ES') {
3319 $string = trim($this->idprof1);
3320 $string = preg_replace(
'/(\s)/',
'', $string);
3321 $string = strtoupper($string);
3324 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)) {
3329 for ($i = 0; $i < 9; $i++) {
3330 $num[$i] = substr($string, $i, 1);
3334 if (preg_match(
'/(^[0-9]{8}[A-Z]{1}$)/', $string)) {
3335 if ($num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) {
3343 $sum = $num[2] + $num[4] + $num[6];
3344 for ($i = 1; $i < 8; $i += 2) {
3345 $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1));
3347 $n = 10 - substr($sum, strlen($sum) - 1, 1);
3350 if (preg_match(
'/^[KLM]{1}/', $string)) {
3351 if ($num[8] == chr(64 + $n) || $num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) {
3359 if (preg_match(
'/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) {
3360 if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) {
3368 if (preg_match(
'/^[T]{1}/', $string)) {
3369 if ($num[8] == preg_match(
'/^[T]{1}[A-Z0-9]{8}$/', $string)) {
3377 if (preg_match(
'/^[XYZ]{1}/', $string)) {
3378 if ($num[8] == substr(
'TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array(
'X',
'Y',
'Z'), array(
'0',
'1',
'2'), $string), 0, 8) % 23, 1)) {
3391 if ($idprof == 1 && $soc->country_code ==
'PT') {
3392 $string = trim($this->idprof1);
3393 $string = preg_replace(
'/(\s)/',
'', $string);
3396 if (preg_match(
'/(^[0-9]{9}$)/', $string)) {
3418 global $conf, $langs, $hookmanager;
3423 $hookmanager->initHooks(array(
'idprofurl'));
3424 $parameters = array(
'idprof'=>$idprof,
'company'=>$thirdparty);
3425 $reshook = $hookmanager->executeHooks(
'getIdProfUrl', $parameters, $this, $action);
3426 if (empty($reshook)) {
3427 if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3432 $strippedIdProf1 = str_replace(
' ',
'', $thirdparty->idprof1);
3433 if ($idprof == 1 && $thirdparty->country_code ==
'FR') {
3434 $url =
'http://www.societe.com/cgi-bin/search?champs='.$strippedIdProf1;
3436 if ($idprof == 1 && ($thirdparty->country_code ==
'GB' || $thirdparty->country_code ==
'UK')) {
3437 $url =
'https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
3439 if ($idprof == 1 && $thirdparty->country_code ==
'ES') {
3440 $url =
'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
3442 if ($idprof == 1 && $thirdparty->country_code ==
'IN') {
3443 $url =
'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.
';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3445 if ($idprof == 1 && $thirdparty->country_code ==
'PT') {
3446 $url =
'http://www.nif.pt/'.$strippedIdProf1;
3450 return '<a target="_blank" href="'.$url.
'">'.$langs->trans(
"Check").
'</a>';
3453 return $hookmanager->resPrint;
3468 $sql =
'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.
'projet WHERE fk_soc = '.$this->id;
3471 $obj = $this->
db->fetch_object(
$resql);
3472 $count = $obj->numproj;
3478 return ($count > 0);
3490 $sql =
"SELECT s.rowid, s.nom as name, s.datec as date_creation, tms as date_modification,";
3491 $sql .=
" fk_user_creat, fk_user_modif";
3492 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
3493 $sql .=
" WHERE s.rowid = ".$id;
3495 $result = $this->
db->query($sql);
3497 if ($this->
db->num_rows($result)) {
3498 $obj = $this->
db->fetch_object($result);
3500 $this->
id = $obj->rowid;
3502 if ($obj->fk_user_creat) {
3503 $cuser =
new User($this->
db);
3504 $cuser->fetch($obj->fk_user_creat);
3505 $this->user_creation = $cuser;
3508 if ($obj->fk_user_modif) {
3509 $muser =
new User($this->
db);
3510 $muser->fetch($obj->fk_user_modif);
3511 $this->user_modification = $muser;
3514 $this->ref = $obj->name;
3515 $this->date_creation = $this->
db->jdate($obj->date_creation);
3516 $this->date_modification = $this->
db->jdate($obj->date_modification);
3519 $this->
db->free($result);
3535 $isacompany = empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES) ? 0 : 1;
3536 if (!empty($this->tva_intra)) {
3538 } elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) {
3540 } elseif (!empty($this->typent_code) && $this->typent_code !=
'TE_UNKNOWN') {
3542 if (preg_match(
'/^TE_PRIVATE/', $this->typent_code)) {
3559 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
3572 $this->SupplierCategories = array();
3573 $sql =
"SELECT rowid, label";
3574 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
3575 $sql .=
" WHERE type = ".Categorie::TYPE_SUPPLIER;
3579 while ($obj = $this->
db->fetch_object(
$resql)) {
3580 $this->SupplierCategories[$obj->rowid] = $obj->label;
3598 if ($categorie_id > 0 && $this->
id > 0) {
3599 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_fournisseur (fk_categorie, fk_soc) ";
3600 $sql .=
" VALUES (".$categorie_id.
", ".$this->
id.
")";
3602 if (
$resql = $this->
db->query($sql)) {
3625 global $conf, $user, $langs;
3627 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
3629 $name = $socname ? $socname : $member->societe;
3634 $alias = $socalias ? $socalias :
'';
3638 $this->
name = $name;
3639 $this->name_alias = $alias;
3640 $this->address = $member->address;
3641 $this->zip = $member->zip;
3642 $this->town = $member->town;
3643 $this->country_code = $member->country_code;
3644 $this->country_id = $member->country_id;
3645 $this->phone = $member->phone;
3646 $this->email = $member->email;
3647 $this->socialnetworks = $member->socialnetworks;
3648 $this->entity = $member->entity;
3651 $this->code_client = ($customercode ? $customercode : -1);
3652 $this->code_fournisseur = -1;
3657 $result = $this->
create($user);
3660 if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT)) {
3662 $this->name_bis = $member->lastname;
3663 $this->firstname = $member->firstname;
3664 $this->civility_id = $member->civility_id;
3666 dol_syslog(
"We ask to create a contact/address too", LOG_DEBUG);
3671 $this->
db->rollback();
3676 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent";
3677 $sql .=
" SET fk_soc=".$this->id;
3678 $sql .=
" WHERE rowid=".$member->id;
3682 $this->
db->commit();
3685 $this->error = $this->
db->error();
3687 $this->
db->rollback();
3692 dol_syslog(get_class($this).
"::create_from_member - 2 - ".$this->error.
" - ".join(
',', $this->errors), LOG_ERR);
3694 $this->
db->rollback();
3710 $this->
name = empty($conf->global->MAIN_INFO_SOCIETE_NOM) ?
'' : $conf->global->MAIN_INFO_SOCIETE_NOM;
3711 $this->address = empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS) ?
'' : $conf->global->MAIN_INFO_SOCIETE_ADDRESS;
3712 $this->zip = empty($conf->global->MAIN_INFO_SOCIETE_ZIP) ?
'' : $conf->global->MAIN_INFO_SOCIETE_ZIP;
3713 $this->town = empty($conf->global->MAIN_INFO_SOCIETE_TOWN) ?
'' : $conf->global->MAIN_INFO_SOCIETE_TOWN;
3714 $this->region_code = empty($conf->global->MAIN_INFO_SOCIETE_REGION) ?
'' : $conf->global->MAIN_INFO_SOCIETE_REGION;
3715 $this->
object = empty($conf->global->MAIN_INFO_SOCIETE_OBJECT) ?
'' : $conf->global->MAIN_INFO_SOCIETE_OBJECT;
3717 $this->note_private = empty($conf->global->MAIN_INFO_SOCIETE_NOTE) ?
'' : $conf->global->MAIN_INFO_SOCIETE_NOTE;
3719 $this->
nom = $this->name;
3722 $country_id = $country_code = $country_label =
'';
3723 if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
3724 $tmp = explode(
':', $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3725 $country_id = $tmp[0];
3726 if (!empty($tmp[1])) {
3727 $country_code = $tmp[1];
3728 $country_label = $tmp[2];
3731 dol_syslog(
"Your country setup use an old syntax. Reedit it using setup area.", LOG_WARNING);
3732 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
3734 $country_label =
getCountry($country_id, 0, $this->
db);
3737 $this->country_id = $country_id;
3738 $this->country_code = $country_code;
3739 $this->country = $country_label;
3740 if (is_object($langs)) {
3741 $this->country = ($langs->trans(
'Country'.$country_code) !=
'Country'.$country_code) ? $langs->trans(
'Country'.$country_code) : $country_label;
3746 $state_id = 0; $state_code = $state_label =
'';
3747 if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE)) {
3748 $tmp = explode(
':', $conf->global->MAIN_INFO_SOCIETE_STATE);
3749 $state_id = $tmp[0];
3750 if (!empty($tmp[1])) {
3751 $state_code = $tmp[1];
3752 $state_label = $tmp[2];
3754 dol_syslog(
"Your state setup use an old syntax (entity=".$conf->entity.
"). Reedit it using setup area.", LOG_ERR);
3755 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
3756 $state_code =
getState($state_id, 2, $this->
db);
3757 $state_label =
getState($state_id, 0, $this->
db);
3760 $this->state_id = $state_id;
3761 $this->state_code = $state_code;
3762 $this->state = $state_label;
3763 if (is_object($langs)) {
3764 $this->state = ($langs->trans(
'State'.$state_code) !=
'State'.$state_code) ? $langs->trans(
'State'.$state_code) : $state_label;
3767 $this->phone = empty($conf->global->MAIN_INFO_SOCIETE_TEL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_TEL;
3768 $this->fax = empty($conf->global->MAIN_INFO_SOCIETE_FAX) ?
'' : $conf->global->MAIN_INFO_SOCIETE_FAX;
3769 $this->url = empty($conf->global->MAIN_INFO_SOCIETE_WEB) ?
'' : $conf->global->MAIN_INFO_SOCIETE_WEB;
3772 $this->facebook_url = empty($conf->global->MAIN_INFO_SOCIETE_FACEBOOK_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_FACEBOOK_URL;
3773 $this->twitter_url = empty($conf->global->MAIN_INFO_SOCIETE_TWITTER_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_TWITTER_URL;
3774 $this->linkedin_url = empty($conf->global->MAIN_INFO_SOCIETE_LINKEDIN_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LINKEDIN_URL;
3775 $this->instagram_url = empty($conf->global->MAIN_INFO_SOCIETE_INSTAGRAM_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_INSTAGRAM_URL;
3776 $this->youtube_url = empty($conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL;
3777 $this->github_url = empty($conf->global->MAIN_INFO_SOCIETE_GITHUB_URL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_GITHUB_URL;
3778 $this->socialnetworks = array();
3779 if (!empty($this->facebook_url)) {
3780 $this->socialnetworks[
'facebook'] = $this->facebook_url;
3782 if (!empty($this->twitter_url)) {
3783 $this->socialnetworks[
'twitter'] = $this->twitter_url;
3785 if (!empty($this->linkedin_url)) {
3786 $this->socialnetworks[
'linkedin'] = $this->linkedin_url;
3788 if (!empty($this->instagram_url)) {
3789 $this->socialnetworks[
'instagram'] = $this->instagram_url;
3791 if (!empty($this->youtube_url)) {
3792 $this->socialnetworks[
'youtube'] = $this->youtube_url;
3794 if (!empty($this->github_url)) {
3795 $this->socialnetworks[
'github'] = $this->github_url;
3799 $this->idprof1 = empty($conf->global->MAIN_INFO_SIREN) ?
'' : $conf->global->MAIN_INFO_SIREN;
3800 $this->idprof2 = empty($conf->global->MAIN_INFO_SIRET) ?
'' : $conf->global->MAIN_INFO_SIRET;
3801 $this->idprof3 = empty($conf->global->MAIN_INFO_APE) ?
'' : $conf->global->MAIN_INFO_APE;
3802 $this->idprof4 = empty($conf->global->MAIN_INFO_RCS) ?
'' : $conf->global->MAIN_INFO_RCS;
3803 $this->idprof5 = empty($conf->global->MAIN_INFO_PROFID5) ?
'' : $conf->global->MAIN_INFO_PROFID5;
3804 $this->idprof6 = empty($conf->global->MAIN_INFO_PROFID6) ?
'' : $conf->global->MAIN_INFO_PROFID6;
3805 $this->tva_intra = empty($conf->global->MAIN_INFO_TVAINTRA) ?
'' : $conf->global->MAIN_INFO_TVAINTRA;
3806 $this->managers = empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS) ?
'' : $conf->global->MAIN_INFO_SOCIETE_MANAGERS;
3807 $this->capital = empty($conf->global->MAIN_INFO_CAPITAL) ?
'' : $conf->global->MAIN_INFO_CAPITAL;
3808 $this->forme_juridique_code = empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE) ?
'' : $conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
3809 $this->email = empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_MAIL;
3810 $this->default_lang = (empty($conf->global->MAIN_LANG_DEFAULT) ?
'auto' : $conf->global->MAIN_LANG_DEFAULT);
3811 $this->logo = empty($conf->global->MAIN_INFO_SOCIETE_LOGO) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO;
3812 $this->logo_small = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
3813 $this->logo_mini = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
3814 $this->logo_squarred = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED;
3815 $this->logo_squarred_small = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL;
3816 $this->logo_squarred_mini = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI) ?
'' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI;
3819 $this->tva_assuj = $conf->global->FACTURE_TVAOPTION;
3822 $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);
3823 $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);
3840 $this->
name =
'THIRDPARTY SPECIMEN '.dol_print_date($now,
'dayhourlog');
3841 $this->
nom = $this->name;
3842 $this->ref_ext =
'Ref ext';
3843 $this->specimen = 1;
3844 $this->address =
'21 jump street';
3845 $this->zip =
'99999';
3846 $this->town =
'MyTown';
3847 $this->state_id = 1;
3848 $this->state_code =
'AA';
3849 $this->state =
'MyState';
3850 $this->country_id = 1;
3851 $this->country_code =
'FR';
3852 $this->email =
'specimen@specimen.com';
3853 $this->socialnetworks = array(
3854 'skype' =>
'tom.hanson',
3855 'twitter' =>
'tomhanson',
3856 'facebook' =>
'tomhanson',
3857 'linkedin' =>
'tomhanson',
3859 $this->url =
'http://www.specimen.com';
3861 $this->phone =
'0909090901';
3862 $this->fax =
'0909090909';
3864 $this->code_client =
'CC-'.dol_print_date($now,
'dayhourlog');
3865 $this->code_fournisseur =
'SC-'.dol_print_date($now,
'dayhourlog');
3866 $this->capital = 10000;
3868 $this->prospect = 1;
3869 $this->fournisseur = 1;
3870 $this->tva_assuj = 1;
3871 $this->tva_intra =
'EU1234567';
3872 $this->note_public =
'This is a comment (public)';
3873 $this->note_private =
'This is a comment (private)';
3875 $this->idprof1 =
'idprof1';
3876 $this->idprof2 =
'idprof2';
3877 $this->idprof3 =
'idprof3';
3878 $this->idprof4 =
'idprof4';
3879 $this->idprof5 =
'idprof5';
3880 $this->idprof6 =
'idprof6';
3892 $sql =
"SELECT t.localtax1, t.localtax2";
3893 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
3894 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
3895 $sql .=
" AND t.active = 1";
3896 if (empty($localTaxNum)) {
3897 $sql .=
" AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
3898 } elseif ($localTaxNum == 1) {
3899 $sql .=
" AND t.localtax1_type <> '0'";
3900 } elseif ($localTaxNum == 2) {
3901 $sql .=
" AND t.localtax2_type <> '0'";
3906 return ($this->
db->num_rows(
$resql) > 0);
3919 $sql =
"SELECT t.rowid";
3920 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
3921 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
3922 $sql .=
" AND t.active = 1 AND t.recuperableonly = 1";
3927 return ($this->
db->num_rows(
$resql) > 0);
3941 $sql =
"SELECT COUNT(*) as nb";
3942 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_revenuestamp as r, ".MAIN_DB_PREFIX.
"c_country as c";
3943 $sql .=
" WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
3944 $sql .=
" AND r.active = 1";
3949 $obj = $this->
db->fetch_object(
$resql);
3950 return (($obj->nb > 0) ?
true:
false);
3952 $this->error = $this->
db->lasterror();
3979 $lib = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
3981 if ($lib == $langs->trans(
"ProspectLevel".$fk_prospectlevel)) {
3982 $lib = $langs->getLabelFromKey($this->
db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
3999 return $this->
update($this->
id, $user);
4011 return $this->
LibProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
4032 $langs->load(
'customers');
4035 if ($status ==
'-1' || $status ==
'ST_NO') {
4036 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
4037 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4038 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
4039 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4040 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
4041 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4042 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
4043 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4044 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
4046 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto).
' '.(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label);
4048 } elseif ($mode == 3) {
4049 if ($status ==
'-1' || $status ==
'ST_NO') {
4050 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto);
4051 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4052 return img_action($langs->trans(
"StatusProspect0"), 0, $picto);
4053 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4054 return img_action($langs->trans(
"StatusProspect1"), 1, $picto);
4055 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4056 return img_action($langs->trans(
"StatusProspect2"), 2, $picto);
4057 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4058 return img_action($langs->trans(
"StatusProspect3"), 3, $picto);
4060 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto);
4062 } elseif ($mode == 4) {
4063 if ($status ==
'-1' || $status ==
'ST_NO') {
4064 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
4065 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4066 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
4067 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4068 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
4069 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4070 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
4071 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4072 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
4074 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto).
' '.(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label);
4078 return "Error, mode/status not found";
4092 return $this->
update($this->
id, $user);
4104 if ($mode ==
'supplier') {
4105 $table =
'supplier_proposal';
4108 $sql =
"SELECT rowid, total_ht, total as total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4109 $sql .=
" WHERE fk_soc = ".$this->id;
4110 if ($mode ==
'supplier') {
4111 $sql .=
" AND entity IN (".getEntity(
'supplier_proposal').
")";
4113 $sql .=
" AND entity IN (".getEntity(
'propal').
")";
4116 dol_syslog(
"getOutstandingProposals", LOG_DEBUG);
4119 $outstandingOpened = 0;
4120 $outstandingTotal = 0;
4121 $outstandingTotalIncTax = 0;
4122 while ($obj = $this->
db->fetch_object(
$resql)) {
4123 $outstandingTotal += $obj->total_ht;
4124 $outstandingTotalIncTax += $obj->total_ttc;
4125 if ($obj->status != 0) {
4127 $outstandingOpened += $obj->total_ttc;
4130 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax);
4144 $table =
'commande';
4145 if ($mode ==
'supplier') {
4146 $table =
'commande_fournisseur';
4149 $sql =
"SELECT rowid, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4150 $sql .=
" WHERE fk_soc = ".$this->id;
4151 if ($mode ==
'supplier') {
4152 $sql .=
" AND entity IN (".getEntity(
'supplier_order').
")";
4154 $sql .=
" AND entity IN (".getEntity(
'commande').
")";
4157 dol_syslog(
"getOutstandingOrders", LOG_DEBUG);
4160 $outstandingOpened = 0;
4161 $outstandingTotal = 0;
4162 $outstandingTotalIncTax = 0;
4163 while ($obj = $this->
db->fetch_object(
$resql)) {
4164 $outstandingTotal += $obj->total_ht;
4165 $outstandingTotalIncTax += $obj->total_ttc;
4166 if ($obj->status != 0) {
4168 $outstandingOpened += $obj->total_ttc;
4171 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax);
4187 if ($mode ==
'supplier') {
4188 $table =
'facture_fourn';
4198 if ($mode ==
'supplier') {
4199 $sql =
"SELECT rowid, total_ht as total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table.
" as f";
4201 $sql =
"SELECT rowid, total as total_ht, total_ttc, paye, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table.
" as f";
4203 $sql .=
" WHERE fk_soc = ".$this->id;
4204 if (!empty($late)) {
4205 $sql .=
" AND date_lim_reglement < '".$this->db->idate(
dol_now()).
"'";
4207 if ($mode ==
'supplier') {
4208 $sql .=
" AND entity IN (".getEntity(
'facture_fourn').
")";
4210 $sql .=
" AND entity IN (".getEntity(
'invoice').
")";
4213 dol_syslog(
"getOutstandingBills", LOG_DEBUG);
4216 $outstandingOpened = 0;
4217 $outstandingTotal = 0;
4218 $outstandingTotalIncTax = 0;
4219 if ($mode ==
'supplier') {
4220 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
4223 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
4226 while ($obj = $this->
db->fetch_object(
$resql)) {
4227 $tmpobject->id = $obj->rowid;
4229 if ($obj->status != $tmpobject::STATUS_DRAFT
4230 && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code ==
'replaced')
4232 $outstandingTotal += $obj->total_ht;
4233 $outstandingTotalIncTax += $obj->total_ttc;
4236 && $obj->status != $tmpobject::STATUS_DRAFT
4237 && $obj->status != $tmpobject::STATUS_ABANDONED
4238 && $obj->status != $tmpobject::STATUS_CLOSED) {
4240 $paiement = $tmpobject->getSommePaiement();
4241 $creditnotes = $tmpobject->getSumCreditNotesUsed();
4242 $deposits = $tmpobject->getSumDepositsUsed();
4244 $outstandingOpened += $obj->total_ttc - $paiement - $creditnotes - $deposits;
4250 $outstandingOpened -= $tmpobject->getSumFromThisCreditNotesNotUsed();
4253 return array(
'opened'=>$outstandingOpened,
'total_ht'=>$outstandingTotal,
'total_ttc'=>$outstandingTotalIncTax);
4280 $langs->load(
'companies');
4283 return $langs->trans(
"NorProspectNorCustomer");
4284 } elseif ($status == 1) {
4285 return $langs->trans(
"Customer");
4286 } elseif ($status == 2) {
4287 return $langs->trans(
"Prospect");
4288 } elseif ($status == 3) {
4289 return $langs->trans(
"ProspectCustomer");
4305 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
4307 global $conf, $user, $langs;
4309 if (!empty($moreparams) && !empty($moreparams[
'use_companybankid'])) {
4310 $modelpath =
"core/modules/bank/doc/";
4312 include_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
4314 $result = $companybankaccount->fetch($moreparams[
'use_companybankid']);
4316 dol_print_error($this->
db, $companybankaccount->error, $companybankaccount->errors);
4318 $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4322 if (!empty($conf->global->COMPANY_ADDON_PDF)) {
4323 $modele = $conf->global->COMPANY_ADDON_PDF;
4325 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_COMPANY_ADDON_PDF_NotDefined");
4330 if (!isset($this->bank_account)) {
4331 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
4333 $result = $bac->fetch(0, $this->
id);
4335 $this->bank_account = $bac;
4337 $this->bank_account =
'';
4341 $modelpath =
"core/modules/societe/doc/";
4343 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4363 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4366 if (!in_array($type_categ, array(Categorie::TYPE_CUSTOMER, Categorie::TYPE_SUPPLIER))) {
4367 dol_syslog(__METHOD__.
': Type '.$type_categ.
'is an unknown company category type. Done nothing.', LOG_ERR);
4372 if (!is_array($categories)) {
4373 $categories = array($categories);
4378 $existing = $c->containing($this->
id, $type_categ,
'id');
4381 if (is_array($existing)) {
4382 $to_del = array_diff($existing, $categories);
4383 $to_add = array_diff($categories, $existing);
4386 $to_add = $categories;
4392 foreach ($to_del as $del) {
4393 if ($c->fetch($del) > 0) {
4394 $c->del_type($this, $type_categ);
4397 foreach ($to_add as $add) {
4398 if ($c->fetch($add) > 0) {
4399 $result = $c->add_type($this, $type_categ);
4402 $this->error = $c->error;
4403 $this->errors = $c->errors;
4409 return $error ? -1 : 1;
4424 if (!is_array($salesrep)) {
4425 $salesrep = array($salesrep);
4429 $to_add = $salesrep;
4430 if ($onlyAdd ===
false) {
4435 if (is_array($existing)) {
4436 $to_del = array_diff($existing, $salesrep);
4437 $to_add = array_diff($salesrep, $existing);
4444 foreach ($to_del as $del) {
4447 foreach ($to_add as $add) {
4455 return $error ? -1 : 1;
4467 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
4468 $sql .=
" SET fk_typent = ".($typent_id > 0 ? $typent_id :
"null");
4469 $sql .=
" WHERE rowid = ".$this->id;
4470 dol_syslog(get_class($this).
'::setThirdpartyType', LOG_DEBUG);
4473 $this->typent_id = $typent_id;
4474 $this->typent_code =
dol_getIdFromCode($this->
db, $this->$typent_id,
'c_typent',
'id',
'code');
4495 if ($origin_id == $dest_id) {
4496 dol_syslog(
'Error: Try to merge a thirdparty into itself');
4504 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
4505 $sql .=
' WHERE fk_soc = '.(int) $dest_id.
' AND fk_user IN ( ';
4506 $sql .=
' SELECT fk_user ';
4507 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
4508 $sql .=
' WHERE fk_soc = '.(int) $origin_id.
') ';
4512 $db->
query(
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_commerciaux WHERE rowid = '.$obj->rowid);
4521 'societe_commerciaux',
4524 'societe_remise_except',
__construct($db)
Constructor.
useLocalTax($localTaxNum=0)
Check if we must use localtax feature or not according to country (country of $mysoc in most cases)...
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
check_codeclient()
Check customer code.
const PROSPECT
Third party is a prospect.
create(User $user)
Create third party in database.
thirdparty_and_contact_email_array($addthirdparty=0)
Return list of contacts emails existing for third party.
getLibStatut($mode=0)
Return label of status (activity, closed)
Class to stock current configuration.
id_prof_url($idprof, $thirdparty)
Return an url to check online a professional id or empty string.
del_commercial(User $user, $commid)
Add link to sales representative.
getLibCustProspStatut()
Return label of status customer is prospect/customer.
useNPR()
Check if we must use NPR Vat (french stupid rule) or not according to country (country of $mysoc in m...
initAsSpecimen()
Initialise an instance with random values.
isACompany()
Return if third party is a company (Business) or an end user (Consumer)
set_remise_supplier($remise, $note, User $user)
Defines the company as a customer.
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
const CUSTOMER_AND_PROSPECT
Third party is a customer and a prospect.
add_commercial(User $user, $commid)
Add link to sales representative.
setCategories($categories, $type_categ)
Sets object to supplied categories.
isObjectUsed($id=0)
Function to check if an object is used by others.
getOutstandingBills($mode= 'customer', $late=0)
Return amount of bill not paid and total.
foreach($object->fields as $key=> $val) if(is_array($extrafields->attributes[$object->table_element]['label'])&&count($extrafields->attributes[$object->table_element]['label']) > 0) $object fields
isInEEC()
Return if a company is inside the EEC (European Economic Community)
dol_now($mode= 'auto')
Return date for now.
const NO_CUSTOMER
Third party is no customer.
set_parent($id)
Define parent commany of current company.
get_codefournisseur($objsoc=0, $type=1)
Assigns a vendor code from the code control module.
getSalesRepresentatives(User $user, $mode=0, $sortfield=null, $sortorder=null)
Return array of sales representatives.
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
getOutstandingProposals($mode= 'customer')
Return amount of order not paid and total.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
Class to manage bank accounts description of third parties.
thirdparty_and_contact_phone_array()
Return list of contacts mobile phone existing for third party.
clean_url($url, $http=1)
Clean an url string.
dol_is_dir($folder)
Test if filename is a directory.
id_prof_exists($idprof, $value, $socid=0)
Verify if a profid exists into database for others thirds.
Class to manage suppliers invoices.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
LibProspLevel($fk_prospectlevel)
Return label of prospect level.
$conf db name
Only used if Module[ID]Name translation string is not found.
create_individual(User $user)
Create a contact/address from thirdparty.
has_projects()
Indicates if the company has projects.
$conf db
API class for accounts.
img_action($titlealt, $numaction, $picto= '')
Show logo action.
create_from_member(Adherent $member, $socname= '', $socalias= '', $customercode= '')
Create a third party into database from a member object.
LoadSupplierCateg()
Load the list of provider categories.
id_prof_verifiable($idprof)
Returns if a profid sould be verified to be unique.
const NO_SUPPLIER
Third party is no supplier.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
get_codeclient($objsoc=0, $type=0)
Assigns a customer code from the code control module.
fetch_object($resultset)
Returns the current line (as an object) for the resultset cursor.
dol_string_nospecial($str, $newstr= '_', $badcharstoreplace= '')
Clean a string from all punctuation characters to use it as a ref or login.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
getOutstandingOrders($mode= 'customer')
Return amount of order not paid and total.
getLibProspLevel()
Return prostect level.
Class to manage third parties objects (customers, suppliers, prospects...)
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Class to manage categories.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
codeclient_modifiable()
Check if a client code is editable based on the parameters of the code control module.
set_as_client()
Define third party as a customer.
const CUSTOMER
Third party is a customer.
if(!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'] s nom
Class to manage withdrawal receipts.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static getIdFromCode($db, $code)
Get id of currency from code.
query($query, $usesavepoint=0, $type= 'auto')
Execute a SQL request and return the resultset.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
contact_get_property($rowid, $mode)
Return property of contact from its id.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
set_remise_client($remise, $note, User $user)
Defines the company as a customer.
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
Class to manage members of a foundation.
fetch($rowid, $ref= '', $ref_ext= '', $barcode= '', $idprof1= '', $idprof2= '', $idprof3= '', $idprof4= '', $idprof5= '', $idprof6= '', $email= '', $ref_alias= '')
Load a third party from database into memory.
LibProspCommStatut($status, $mode=0, $label= '', $picto= '')
Return label of a given status.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
info($id)
Load information for tab info.
set_OutstandingBill(User $user)
Set outstanding value.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
deleteExtraFields()
Delete all extra fields values for the current object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
getState($id, $withcode= '', $dbtouse=0, $withregion=0, $outputlangs= '', $entconv=1)
Return state translated from an id.
display_rib($mode= 'label')
Return bank number property of thirdparty (label or rum)
getAvailableDiscounts($user= '', $filter= '', $maxvalue=0, $discount_type=0)
Returns amount of included taxes of the current discounts/credits available from the company...
setSalesRep($salesrep, $onlyAdd=false)
Sets sales representatives of the thirdparty.
print $_SERVER["PHP_SELF"]
Edit parameters.
get_codecompta($type)
Assigns a accounting code from the accounting code module.
set_prospect_level(User $user)
Set prospect level.
contact_array_objects()
Returns the contact list of this company.
getNomUrl($withpicto=0, $option= '', $maxlen=0, $notooltip=0, $save_lastsearch_value=-1)
Return a link on thirdparty (with picto)
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
const TYPE_CREDIT_NOTE
Credit note invoice.
trait CommonIncoterm
Superclass for incoterm classes.
verify()
Check properties of third party are ok (like name, third party codes, ...) Used before an add or upda...
print
Draft customers invoices.
call_trigger($triggerName, $user)
Call trigger based on this instance.
useRevenueStamp()
Check if we must use revenue stamps feature or not according to country (country of $mysocin most cas...
codefournisseur_modifiable()
Check if a vendor code is editable in the code control module configuration.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Class to manage absolute discounts.
getLibProspCommStatut($mode=0, $label= '')
Return status of prospect.
const SUPPLIER
Third party is a supplier.
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
contact_array()
Returns the contact list of this company.
Class to manage invoices.
setMysoc(Conf $conf)
Set properties with value into $conf.
set_remise_except($remise, User $user, $desc, $vatrate= '', $discount_type=0)
Add a discount for third party.
LibStatut($status, $mode=0)
Return the label of a given status.
AddFournisseurInCategory($categorie_id)
Insert link supplier - category.
update($id, $user= '', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0, $action= 'update', $nosyncmember=1)
Update parameters of third party.
check_codefournisseur()
Check supplier code.
set_price_level($price_level, User $user)
Set the price level.
setThirdpartyType($typent_id)
Define third-party type of current company.
get_all_rib()
Return Array of RIB.
id_prof_check($idprof, $soc)
Check the validity of a professional identifier according to the country of the company (siren...
LibCustProspStatut($status)
Return the label of the customer/prospect status.
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
contact_property_array($mode= 'email', $hidedisabled=0)
Return list of contacts emails or mobile existing for third party.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
insertExtraLanguages($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.