44require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/commonsocialnetworks.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
63 public $module =
'societe';
68 public $element =
'societe';
73 public $table_element =
'societe';
78 public $fk_element =
'fk_soc';
83 public $fieldsforcombobox =
'nom,name_alias';
88 protected $childtables = array(
89 'supplier_proposal' => array(
'name' =>
'SupplierProposal'),
90 'propal' => array(
'name' =>
'Proposal'),
91 'commande' => array(
'name' =>
'Order'),
92 'facture' => array(
'name' =>
'Invoice'),
93 'facture_rec' => array(
'name' =>
'RecurringInvoiceTemplate'),
94 'contrat' => array(
'name' =>
'Contract'),
95 'fichinter' => array(
'name' =>
'Fichinter'),
96 'facture_fourn' => array(
'name' =>
'SupplierInvoice'),
97 'commande_fournisseur' => array(
'name' =>
'SupplierOrder'),
98 'projet' => array(
'name' =>
'Project'),
99 'expedition' => array(
'name' =>
'Shipment'),
100 'prelevement_lignes' => array(
'name' =>
'DirectDebitRecord'),
107 protected $childtablesoncascade = array(
109 'product_fournisseur_price',
110 'product_customer_price_log',
111 'product_customer_price',
112 '@Contact:/contact/class/contact.class.php:fk_soc',
117 'societe_remise_except',
118 'societe_commerciaux',
128 public $picto =
'company';
134 public $restrictiononfksoc = 1;
145 public $SupplierCategories = array();
151 public $prefixCustomerIsRequired;
182 public $fields = array(
183 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'noteditable' => 1,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id',
'css' =>
'left'),
184 'parent' => array(
'type' =>
'integer',
'label' =>
'Parent',
'enabled' => 1,
'visible' => -1,
'position' => 20),
185 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 25),
186 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 30),
187 'nom' => array(
'type' =>
'varchar(128)',
'label' =>
'Nom',
'enabled' => 1,
'visible' => -1,
'position' => 35,
'showoncombobox' => 1),
188 'name_alias' => array(
'type' =>
'varchar(128)',
'label' =>
'Name alias',
'enabled' => 1,
'visible' => -1,
'position' => 36,
'showoncombobox' => 2),
189 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 40,
'index' => 1),
190 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 45),
191 'code_client' => array(
'type' =>
'varchar(24)',
'label' =>
'CustomerCode',
'enabled' => 1,
'visible' => -1,
'position' => 55),
192 'code_fournisseur' => array(
'type' =>
'varchar(24)',
'label' =>
'SupplierCode',
'enabled' => 1,
'visible' => -1,
'position' => 60),
193 'code_compta' => array(
'type' =>
'varchar(24)',
'label' =>
'CustomerAccountancyCode',
'enabled' => 1,
'visible' => -1,
'position' => 65),
194 'code_compta_fournisseur' => array(
'type' =>
'varchar(24)',
'label' =>
'SupplierAccountancyCode',
'enabled' => 1,
'visible' => -1,
'position' => 70),
195 'address' => array(
'type' =>
'varchar(255)',
'label' =>
'Address',
'enabled' => 1,
'visible' => -1,
'position' => 75),
196 'zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Zip',
'enabled' => 1,
'visible' => -1,
'position' => 80),
197 'town' => array(
'type' =>
'varchar(50)',
'label' =>
'Town',
'enabled' => 1,
'visible' => -1,
'position' => 85),
198 'fk_departement' => array(
'type' =>
'integer',
'label' =>
'State',
'enabled' => 1,
'visible' => -1,
'position' => 90),
199 'fk_pays' => array(
'type' =>
'integer:Ccountry:core/class/ccountry.class.php',
'label' =>
'Country',
'enabled' => 1,
'visible' => -1,
'position' => 95),
200 'phone' => array(
'type' =>
'varchar(20)',
'label' =>
'Phone',
'enabled' => 1,
'visible' => -1,
'position' => 100),
201 'phone_mobile' => array(
'type' =>
'varchar(20)',
'label' =>
'PhoneMobile',
'enabled' => 1,
'visible' => -1,
'position' => 102),
202 'fax' => array(
'type' =>
'varchar(20)',
'label' =>
'Fax',
'enabled' => 1,
'visible' => -1,
'position' => 105),
203 'url' => array(
'type' =>
'varchar(255)',
'label' =>
'Url',
'enabled' => 1,
'visible' => -1,
'position' => 110),
204 'email' => array(
'type' =>
'varchar(128)',
'label' =>
'Email',
'enabled' => 1,
'visible' => -1,
'position' => 115),
205 'socialnetworks' => array(
'type' =>
'text',
'label' =>
'Socialnetworks',
'enabled' => 1,
'visible' => -1,
'position' => 120),
206 'fk_effectif' => array(
'type' =>
'integer',
'label' =>
'Workforce',
'enabled' => 1,
'visible' => -1,
'position' => 170),
207 'fk_typent' => array(
'type' =>
'integer',
'label' =>
'TypeOfCompany',
'enabled' => 1,
'visible' => -1,
'position' => 175,
'csslist' =>
'minwidth200'),
208 'fk_forme_juridique' => array(
'type' =>
'integer',
'label' =>
'JuridicalStatus',
'enabled' => 1,
'visible' => -1,
'position' => 180),
209 'fk_currency' => array(
'type' =>
'varchar(3)',
'label' =>
'Currency',
'enabled' => 1,
'visible' => -1,
'position' => 185),
210 'siren' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof1',
'enabled' => 1,
'visible' => -1,
'position' => 190),
211 'siret' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof2',
'enabled' => 1,
'visible' => -1,
'position' => 195),
212 'ape' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof3',
'enabled' => 1,
'visible' => -1,
'position' => 200),
213 'idprof4' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof4',
'enabled' => 1,
'visible' => -1,
'position' => 205),
214 'idprof5' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof5',
'enabled' => 1,
'visible' => -1,
'position' => 206),
215 'idprof6' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof6',
'enabled' => 1,
'visible' => -1,
'position' => 207),
216 'tva_intra' => array(
'type' =>
'varchar(20)',
'label' =>
'Tva intra',
'enabled' => 1,
'visible' => -1,
'position' => 210),
217 'capital' => array(
'type' =>
'double(24,8)',
'label' =>
'Capital',
'enabled' => 1,
'visible' => -1,
'position' => 215),
218 'fk_stcomm' => array(
'type' =>
'integer',
'label' =>
'CommercialStatus',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 220),
219 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 225),
220 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 230),
221 'prefix_comm' => array(
'type' =>
'varchar(5)',
'label' =>
'Prefix comm',
'enabled' =>
"getDolGlobalInt('SOCIETE_USEPREFIX')",
'visible' => -1,
'position' => 235),
222 'client' => array(
'type' =>
'tinyint(4)',
'label' =>
'Client',
'enabled' => 1,
'visible' => -1,
'position' => 240),
223 'fournisseur' => array(
'type' =>
'tinyint(4)',
'label' =>
'Fournisseur',
'enabled' => 1,
'visible' => -1,
'position' => 245),
224 'supplier_account' => array(
'type' =>
'varchar(32)',
'label' =>
'Supplier account',
'enabled' => 1,
'visible' => -1,
'position' => 250),
225 'fk_prospectlevel' => array(
'type' =>
'varchar(12)',
'label' =>
'ProspectLevel',
'enabled' => 1,
'visible' => -1,
'position' => 255),
226 'customer_bad' => array(
'type' =>
'tinyint(4)',
'label' =>
'Customer bad',
'enabled' => 1,
'visible' => -1,
'position' => 260),
227 'customer_rate' => array(
'type' =>
'double',
'label' =>
'Customer rate',
'enabled' => 1,
'visible' => -1,
'position' => 265),
228 'supplier_rate' => array(
'type' =>
'double',
'label' =>
'Supplier rate',
'enabled' => 1,
'visible' => -1,
'position' => 270),
229 'fk_user_creat' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -2,
'position' => 275),
230 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 280),
233 'mode_reglement' => array(
'type' =>
'tinyint(4)',
'label' =>
'Mode reglement',
'enabled' => 1,
'visible' => -1,
'position' => 295),
234 'cond_reglement' => array(
'type' =>
'tinyint(4)',
'label' =>
'Cond reglement',
'enabled' => 1,
'visible' => -1,
'position' => 300),
235 'deposit_percent' => array(
'type' =>
'varchar(63)',
'label' =>
'DepositPercent',
'enabled' => 1,
'visible' => -1,
'position' => 301),
236 'mode_reglement_supplier' => array(
'type' =>
'integer',
'label' =>
'Mode reglement supplier',
'enabled' => 1,
'visible' => -1,
'position' => 305),
237 'cond_reglement_supplier' => array(
'type' =>
'integer',
'label' =>
'Cond reglement supplier',
'enabled' => 1,
'visible' => -1,
'position' => 308),
238 'outstanding_limit' => array(
'type' =>
'double(24,8)',
'label' =>
'OutstandingBill',
'enabled' => 1,
'visible' => -1,
'position' => 310,
'isameasure' => 1),
239 'order_min_amount' => array(
'type' =>
'double(24,8)',
'label' =>
'Order min amount',
'enabled' =>
'isModEnabled("order") && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)',
'visible' => -1,
'position' => 315,
'isameasure' => 1),
240 'supplier_order_min_amount' => array(
'type' =>
'double(24,8)',
'label' =>
'Supplier order min amount',
'enabled' =>
'isModEnabled("order") && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)',
'visible' => -1,
'position' => 320,
'isameasure' => 1),
241 'fk_shipping_method' => array(
'type' =>
'integer',
'label' =>
'Fk shipping method',
'enabled' => 1,
'visible' => -1,
'position' => 330),
242 'tva_assuj' => array(
'type' =>
'tinyint(4)',
'label' =>
'Tva assuj',
'enabled' => 1,
'visible' => -1,
'position' => 335),
243 'localtax1_assuj' => array(
'type' =>
'tinyint(4)',
'label' =>
'Localtax1 assuj',
'enabled' => 1,
'visible' => -1,
'position' => 340),
244 'localtax1_value' => array(
'type' =>
'double(6,3)',
'label' =>
'Localtax1 value',
'enabled' => 1,
'visible' => -1,
'position' => 345),
245 'localtax2_assuj' => array(
'type' =>
'tinyint(4)',
'label' =>
'Localtax2 assuj',
'enabled' => 1,
'visible' => -1,
'position' => 350),
246 'localtax2_value' => array(
'type' =>
'double(6,3)',
'label' =>
'Localtax2 value',
'enabled' => 1,
'visible' => -1,
'position' => 355),
247 'vat_reverse_charge' => array(
'type' =>
'tinyint(4)',
'label' =>
'Vat reverse charge',
'enabled' => 1,
'visible' => -1,
'position' => 335),
248 'barcode' => array(
'type' =>
'varchar(255)',
'label' =>
'Barcode',
'enabled' => 1,
'visible' => -1,
'position' => 360),
249 'price_level' => array(
'type' =>
'integer',
'label' =>
'Price level',
'enabled' =>
'$conf->global->PRODUIT_MULTIPRICES || getDolGlobalString("PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES")',
'visible' => -1,
'position' => 365),
250 'default_lang' => array(
'type' =>
'varchar(6)',
'label' =>
'Default lang',
'enabled' => 1,
'visible' => -1,
'position' => 370),
251 'canvas' => array(
'type' =>
'varchar(32)',
'label' =>
'Canvas',
'enabled' => 1,
'visible' => -1,
'position' => 375),
252 'fk_barcode_type' => array(
'type' =>
'integer',
'label' =>
'Fk barcode type',
'enabled' => 1,
'visible' => -1,
'position' => 405),
253 'webservices_url' => array(
'type' =>
'varchar(255)',
'label' =>
'Webservices url',
'enabled' => 1,
'visible' => -1,
'position' => 410),
254 'webservices_key' => array(
'type' =>
'varchar(128)',
'label' =>
'Webservices key',
'enabled' => 1,
'visible' => -1,
'position' => 415),
255 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'Fk incoterms',
'enabled' => 1,
'visible' => -1,
'position' => 425),
256 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'Location incoterms',
'enabled' => 1,
'visible' => -1,
'position' => 430),
257 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 435),
258 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -1,
'position' => 270),
259 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Fk multicurrency',
'enabled' => 1,
'visible' => -1,
'position' => 440),
260 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Multicurrency code',
'enabled' => 1,
'visible' => -1,
'position' => 445),
261 'fk_account' => array(
'type' =>
'integer',
'label' =>
'PaymentBankAccount',
'enabled' => 1,
'visible' => -1,
'position' => 450),
262 'fk_warehouse' => array(
'type' =>
'integer',
'label' =>
'Warehouse',
'enabled' => 1,
'visible' => -1,
'position' => 455),
263 'logo' => array(
'type' =>
'varchar(255)',
'label' =>
'Logo',
'enabled' => 1,
'visible' => -1,
'position' => 400),
264 'logo_squarred' => array(
'type' =>
'varchar(255)',
'label' =>
'Logo squarred',
'enabled' => 1,
'visible' => -1,
'position' => 401),
265 'status' => array(
'type' =>
'tinyint(4)',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'position' => 500),
266 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 1000),
324 public $departement_code;
349 public $phone_mobile;
496 public $socialobject;
506 public $tva_assuj = 1;
516 public $vat_reverse_charge = 0;
519 public $localtax1_assuj;
520 public $localtax1_value;
521 public $localtax2_assuj;
522 public $localtax2_value;
537 public $typent_id = 0;
540 public $effectif_id = 0;
541 public $forme_juridique_code;
542 public $forme_juridique = 0;
544 public $remise_percent;
545 public $remise_supplier_percent;
547 public $mode_reglement_id;
548 public $cond_reglement_id;
549 public $deposit_percent;
550 public $mode_reglement_supplier_id;
551 public $cond_reglement_supplier_id;
552 public $transport_mode_supplier_id;
557 public $fk_prospectlevel;
570 public $date_modification;
577 public $user_modification;
583 public $date_creation;
590 public $user_creation;
602 public $prospect = 0;
620 public $code_fournisseur;
626 public $code_compta_client;
640 public $accountancy_code_customer;
646 public $code_compta_fournisseur;
652 public $accountancy_code_supplier;
658 public $code_compta_product;
671 public $note_private;
689 public $stcomm_picto;
695 public $status_prospect_label;
706 public $outstanding_limit;
711 public $order_min_amount;
716 public $supplier_order_min_amount;
722 public $commercial_id;
734 public $default_lang;
760 public $webservices_url;
766 public $webservices_key;
786 public $logo_squarred;
791 public $logo_squarred_small;
796 public $logo_squarred_mini;
801 public $accountancy_code_sell;
806 public $accountancy_code_buy;
812 public $fk_multicurrency;
818 public $fk_warehouse;
823 public $multicurrency_code;
827 public $partnerships = array();
833 public $bank_account;
836 const STATUS_CEASED = 0;
837 const STATUS_INACTIVITY = 1;
881 $this->ismultientitymanaged = 1;
882 $this->isextrafieldmanaged = 1;
885 $this->fournisseur = 0;
886 $this->typent_id = 0;
887 $this->effectif_id = 0;
888 $this->forme_juridique_code = 0;
889 $this->tva_assuj = 1;
890 $this->vat_reverse_charge = 0;
894 $this->fields[
'address'][
'showoncombobox'] =
getDolGlobalString(
'COMPANY_SHOW_ADDRESS_SELECTLIST');
895 $this->fields[
'zip'][
'showoncombobox'] =
getDolGlobalString(
'COMPANY_SHOW_ADDRESS_SELECTLIST');
896 $this->fields[
'town'][
'showoncombobox'] =
getDolGlobalString(
'COMPANY_SHOW_ADDRESS_SELECTLIST');
912 global $langs, $conf;
917 if (empty($this->
status)) {
920 $this->
name = $this->
name ? trim($this->
name) : trim((
string) $this->nom);
922 $this->nom = $this->name;
924 if (empty($this->client)) {
927 if (empty($this->fournisseur)) {
928 $this->fournisseur = 0;
930 $this->import_key = trim((
string) $this->import_key);
932 $this->accountancy_code_customer = trim((
string) $this->code_compta);
933 $this->accountancy_code_supplier = trim((
string) $this->code_compta_fournisseur);
934 $this->accountancy_code_buy = trim((
string) $this->accountancy_code_buy);
935 $this->accountancy_code_sell = trim((
string) $this->accountancy_code_sell);
937 if (!empty($this->multicurrency_code)) {
940 if (empty($this->fk_multicurrency)) {
941 $this->multicurrency_code =
'';
942 $this->fk_multicurrency = 0;
949 if (empty($this->date_creation)) {
950 $this->date_creation = $now;
956 if ($this->code_client == -1 || $this->code_client ===
'auto') {
957 $this->get_codeclient($this, 0);
959 if ($this->code_fournisseur ==
'-1' || $this->code_fournisseur ===
'auto') {
960 $this->get_codefournisseur($this, 1);
965 $result = $this->
verify();
968 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
970 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe (";
972 $sql .=
", name_alias";
975 $sql .=
", fk_user_creat";
976 $sql .=
", fk_typent";
980 $sql .=
", fk_stcomm";
981 $sql .=
", fk_incoterms";
982 $sql .=
", location_incoterms";
983 $sql .=
", import_key";
984 $sql .=
", fk_multicurrency";
985 $sql .=
", multicurrency_code";
987 $sql .=
", vat_reverse_charge";
988 $sql .=
", accountancy_code_buy";
989 $sql .=
", accountancy_code_sell";
991 $sql .=
") VALUES ('".$this->db->escape($this->name).
"',";
992 $sql .=
" '".$this->db->escape($this->name_alias).
"',";
993 $sql .=
" ".((int) $this->entity).
",";
994 $sql .=
" '".$this->db->idate($this->date_creation).
"'";
995 $sql .=
", ".(!empty($user->id) ? ((int) $user->id) :
"null");
996 $sql .=
", ".(!empty($this->typent_id) ? ((int) $this->typent_id) :
"null");
997 $sql .=
", ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null");
998 $sql .=
", ".((int) $this->
status);
999 $sql .=
", ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1001 $sql .=
", ".(int) $this->fk_incoterms;
1002 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1003 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1004 $sql .=
", ".(int) $this->fk_multicurrency;
1005 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1007 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1008 $sql .=
", '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1009 $sql .=
", '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1013 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1015 $result = $this->db->query($sql);
1017 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"societe");
1019 $ret = $this->
update($this->
id, $user, 0, 1, 1,
'add');
1023 $this->db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int) $conf->entity));
1025 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
1028 $sql .=
", vat_reverse_charge";
1029 $sql .=
", accountancy_code_customer";
1030 $sql .=
", accountancy_code_supplier";
1031 $sql .=
", accountancy_code_buy";
1032 $sql .=
", accountancy_code_sell";
1033 $sql .=
") VALUES (";
1035 $sql .=
", ".((int) $conf->entity);
1036 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1037 $sql .=
", '".$this->db->escape($this->accountancy_code_customer).
"'";
1038 $sql .=
", '".$this->db->escape($this->accountancy_code_supplier).
"'";
1039 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1040 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1042 $result = $this->db->query($sql);
1045 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1050 if ($this->commercial_id !=
'' && $this->commercial_id != -1) {
1052 } elseif (!$user->hasRight(
'societe',
'client',
'voir')) {
1060 $result = $this->
call_trigger(
'COMPANY_CREATE', $user);
1071 dol_syslog(get_class($this).
"::Create success id=".$this->
id);
1072 $this->db->commit();
1075 dol_syslog(get_class($this).
"::Create echec update ".$this->error.(empty($this->errors) ?
'' :
' '.implode(
',', $this->errors)), LOG_ERR);
1076 $this->db->rollback();
1080 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1081 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", $this->name);
1084 $this->error = $this->db->lasterror();
1087 $this->db->rollback();
1091 $this->db->rollback();
1092 dol_syslog(get_class($this).
"::Create fails verify ".implode(
',', $this->errors), LOG_WARNING);
1117 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1118 $contact =
new Contact($this->db);
1120 $contact->name = $this->name_bis;
1121 $contact->firstname = $this->firstname;
1122 $contact->civility_id = $this->civility_id;
1123 $contact->socid = $this->id;
1124 $contact->statut = 1;
1125 $contact->status = 1;
1127 $contact->country_id = $this->country_id;
1128 $contact->state_id = $this->state_id;
1129 $contact->address = $this->address;
1130 $contact->email = $this->email;
1131 $contact->zip = $this->zip;
1132 $contact->town = $this->town;
1134 $contact->phone_pro = $this->phone;
1136 $contactId = $contact->create($user, $notrigger);
1137 if ($contactId < 0) {
1139 $this->error = $contact->error;
1140 $this->errors = $contact->errors;
1141 dol_syslog(get_class($this).
"::create_individual ERROR:".$this->error, LOG_ERR);
1144 if (empty($error) && is_array($tags) && !empty($tags)) {
1145 $result = $contact->setCategories($tags);
1148 $this->error = $contact->error;
1149 $this->errors = array_merge($this->errors, $contact->errors);
1150 dol_syslog(get_class($this).
"::create_individual Affect Tag ERROR:".$this->error, LOG_ERR);
1151 $contactId = $result;
1155 if (empty($error) && isModEnabled(
'mailing') && !empty($contact->email) && isset($no_email)) {
1156 $result = $contact->setNoEmail($no_email);
1158 $this->error = $contact->error;
1159 $this->errors = array_merge($this->errors, $contact->errors);
1160 dol_syslog(get_class($this).
"::create_individual set mailing status ERROR:".$this->error, LOG_ERR);
1161 $contactId = $result;
1165 if (empty($error)) {
1166 dol_syslog(get_class($this).
"::create_individual success");
1167 $this->db->commit();
1169 $this->db->rollback();
1183 global $conf, $langs, $mysoc;
1186 $this->errors = array();
1190 $this->nom = $this->name;
1193 $this->errors[] =
'ErrorBadThirdPartyName';
1197 if ($this->client) {
1199 if ($rescode != 0 && $rescode != -5) {
1200 if ($rescode == -1) {
1201 $this->errors[] =
'ErrorBadCustomerCodeSyntax';
1202 } elseif ($rescode == -2) {
1203 $this->errors[] =
'ErrorCustomerCodeRequired';
1204 } elseif ($rescode == -3) {
1205 $this->errors[] =
'ErrorCustomerCodeAlreadyUsed';
1206 } elseif ($rescode == -4) {
1207 $this->errors[] =
'ErrorPrefixRequired';
1209 $this->errors[] =
'ErrorUnknownOnCustomerCodeCheck';
1216 if ($this->fournisseur) {
1218 if ($rescode != 0 && $rescode != -5) {
1219 if ($rescode == -1) {
1220 $this->errors[] =
'ErrorBadSupplierCodeSyntax';
1221 } elseif ($rescode == -2) {
1222 $this->errors[] =
'ErrorSupplierCodeRequired';
1223 } elseif ($rescode == -3) {
1224 $this->errors[] =
'ErrorSupplierCodeAlreadyUsed';
1225 } elseif ($rescode == -4) {
1226 $this->errors[] =
'ErrorPrefixRequired';
1228 $this->errors[] =
'ErrorUnknownOnSupplierCodeCheck';
1235 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL',
'TVA_INTRA',
'ACCOUNTANCY_CODE_CUSTOMER',
'ACCOUNTANCY_CODE_SUPPLIER');
1236 foreach ($array_to_check as $key) {
1237 $keymin = strtolower($key);
1238 if ($key ==
'ACCOUNTANCY_CODE_CUSTOMER') {
1239 $keymin =
'code_compta';
1240 } elseif ($key ==
'ACCOUNTANCY_CODE_SUPPLIER') {
1241 $keymin =
'code_compta_fournisseur';
1243 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
1244 $vallabel = $this->$keymin;
1249 if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) {
1250 $idprof_mandatory =
'SOCIETE_'.$key.
'_MANDATORY';
1252 $langs->load(
"errors");
1254 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->transcountry(
'ProfId'.$i, $this->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1261 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1262 $langs->load(
"errors");
1264 $this->errors[] = $langs->transcountry(
'ProfId'.$i, $this->country_code).
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1270 if ($key ==
'EMAIL') {
1273 $langs->load(
"errors");
1275 $this->errors[] = $langs->trans(
"ErrorBadEMail", $this->email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1280 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1281 $langs->load(
"errors");
1283 $this->errors[] = $langs->trans(
'Email').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1286 } elseif ($key ==
'TVA_INTRA') {
1289 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1290 $langs->load(
"errors");
1292 $this->errors[] = $langs->trans(
'VATIntra').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1295 } elseif ($key ==
'ACCOUNTANCY_CODE_CUSTOMER' && !empty($this->client)) {
1298 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1299 $langs->loadLangs(array(
"errors",
'compta'));
1301 $this->errors[] = $langs->trans(
'CustomerAccountancyCodeShort') .
" " . $langs->trans(
"ErrorProdIdAlreadyExist", $vallabel) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1306 if (
getDolGlobalString(
'SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_MANDATORY') && (!isset($vallabel) || trim($vallabel) ===
'')) {
1307 $langs->loadLangs(array(
"errors",
'compta'));
1309 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
'CustomerAccountancyCodeShort')) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1311 } elseif ($key ==
'ACCOUNTANCY_CODE_SUPPLIER' && !empty($this->fournisseur)) {
1314 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1315 $langs->loadLangs(array(
"errors",
'compta'));
1317 $this->errors[] = $langs->trans(
'SupplierAccountancyCodeShort') .
" " . $langs->trans(
"ErrorProdIdAlreadyExist", $vallabel) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1322 if (
getDolGlobalString(
'SOCIETE_ACCOUNTANCY_CODE_SUPPLIER_MANDATORY') && (!isset($vallabel) || trim($vallabel) ===
'')) {
1323 $langs->loadLangs(array(
"errors",
'compta'));
1325 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
'SupplierAccountancyCodeShort')) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1350 public function update($id,
User $user, $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action =
'update', $nosyncmember = 1)
1352 global $langs, $conf, $hookmanager;
1354 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1359 if (empty($this->country_id) && !empty($this->country_code)) {
1360 $this->country_id =
dol_getIdFromCode($this->db, $this->country_code,
'c_country',
'code',
'rowid');
1365 dol_syslog(get_class($this).
"::Update id=".$id.
" call_trigger=".$call_trigger.
" allowmodcodeclient=".$allowmodcodeclient.
" allowmodcodefournisseur=".$allowmodcodefournisseur);
1371 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
1372 $this->
name = $this->
name ? trim($this->
name) : trim((
string) $this->nom);
1373 $this->nom = $this->name;
1374 $this->name_alias = trim((
string) $this->name_alias);
1375 $this->ref_ext = (empty($this->ref_ext) ?
'' : trim($this->ref_ext));
1376 $this->address = trim((
string) $this->address);
1377 $this->zip = trim((
string) $this->zip);
1378 $this->town = trim((
string) $this->town);
1379 $this->state_id = (is_numeric($this->state_id)) ? (
int) $this->state_id : 0;
1380 $this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
1381 $this->phone = trim((
string) $this->phone);
1382 $this->phone = preg_replace(
"/\s/",
"", $this->phone);
1383 $this->phone = preg_replace(
"/\./",
"", $this->phone);
1384 $this->phone_mobile = trim((
string) $this->phone_mobile);
1385 $this->phone_mobile = preg_replace(
"/\s/",
"", $this->phone_mobile);
1386 $this->phone_mobile = preg_replace(
"/\./",
"", $this->phone_mobile);
1387 $this->fax = trim((
string) $this->fax);
1388 $this->fax = preg_replace(
"/\s/",
"", $this->fax);
1389 $this->fax = preg_replace(
"/\./",
"", $this->fax);
1390 $this->email = trim((
string) $this->email);
1391 $this->url = $this->url ?
clean_url($this->url, 0) :
'';
1392 $this->note_private = (empty($this->note_private) ?
'' : trim($this->note_private));
1393 $this->note_public = (empty($this->note_public) ?
'' : trim($this->note_public));
1394 $this->idprof1 = trim((
string) $this->idprof1);
1395 $this->idprof2 = trim((
string) $this->idprof2);
1396 $this->idprof3 = trim((
string) $this->idprof3);
1397 $this->idprof4 = trim((
string) $this->idprof4);
1398 $this->idprof5 = (!empty($this->idprof5) ? trim($this->idprof5) :
'');
1399 $this->idprof6 = (!empty($this->idprof6) ? trim($this->idprof6) :
'');
1400 $this->prefix_comm = trim((
string) $this->prefix_comm);
1401 $this->outstanding_limit =
price2num($this->outstanding_limit);
1402 $this->order_min_amount =
price2num($this->order_min_amount);
1403 $this->supplier_order_min_amount =
price2num($this->supplier_order_min_amount);
1405 $this->tva_assuj = (is_numeric($this->tva_assuj)) ? (
int) trim((
string) $this->tva_assuj) : 0;
1407 $this->vat_reverse_charge = empty($this->vat_reverse_charge) ? 0 : 1;
1408 if (empty($this->
status)) {
1412 if (!empty($this->multicurrency_code)) {
1415 if (empty($this->fk_multicurrency)) {
1416 $this->multicurrency_code =
'';
1417 $this->fk_multicurrency = 0;
1421 $this->localtax1_assuj = trim($this->localtax1_assuj);
1422 $this->localtax2_assuj = trim($this->localtax2_assuj);
1424 $this->localtax1_value = trim($this->localtax1_value);
1425 $this->localtax2_value = trim($this->localtax2_value);
1427 $this->capital = ($this->capital !=
'') ? (
float)
price2num(trim((
string) $this->capital)) :
null;
1429 $this->effectif_id = trim((
string) $this->effectif_id);
1430 $this->forme_juridique_code = trim((
string) $this->forme_juridique_code);
1433 $this->barcode = trim($this->barcode);
1436 if ($this->code_client == -1 || $this->code_client ===
'auto') {
1437 $this->get_codeclient($this, 0);
1439 if ($this->code_fournisseur ==
'-1' || $this->code_fournisseur ===
'auto') {
1440 $this->get_codefournisseur($this, 1);
1443 $this->code_compta_client = trim(empty($this->code_compta) ? $this->code_compta_client : $this->code_compta);
1444 $this->code_compta = $this->code_compta_client;
1445 $this->code_compta_fournisseur = (empty($this->code_compta_fournisseur) ?
'' : trim($this->code_compta_fournisseur));
1448 if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) {
1449 $langs->load(
"errors");
1450 $this->error = $langs->trans(
"BadValueForParameterClientOrSupplier");
1455 if (!empty($allowmodcodeclient) && !empty($this->client)) {
1457 if (empty($this->code_compta_client)) {
1468 if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) {
1470 if (empty($this->code_compta_fournisseur)) {
1481 $this->webservices_url = $this->webservices_url ?
clean_url($this->webservices_url, 0) :
'';
1482 $this->webservices_key = trim($this->webservices_key);
1484 $this->accountancy_code_buy = (empty($this->accountancy_code_buy) ?
'' : trim($this->accountancy_code_buy));
1485 $this->accountancy_code_sell = (empty($this->accountancy_code_sell) ?
'' : trim($this->accountancy_code_sell));
1488 $this->fk_incoterms = (int) $this->fk_incoterms;
1489 $this->location_incoterms = trim($this->location_incoterms);
1496 if ($action !=
'add' && $action !=
'merge') {
1499 $result = $this->
verify();
1503 if (is_array($this->errors)) {
1504 if (in_array(
'ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) {
1505 if (($key = array_search(
'ErrorBadCustomerCodeSyntax', $this->errors)) !==
false) {
1506 unset($this->errors[$key]);
1509 if (in_array(
'ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) {
1510 if (($key = array_search(
'ErrorBadSupplierCodeSyntax', $this->errors)) !==
false) {
1511 unset($this->errors[$key]);
1514 if (empty($this->errors)) {
1521 dol_syslog(get_class($this).
"::update verify ok or not done");
1523 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe SET ";
1524 $sql .=
"entity = ".$this->db->escape($this->entity);
1525 $sql .=
",nom = '".$this->db->escape($this->
name).
"'";
1526 $sql .=
",name_alias = '".$this->db->escape($this->name_alias).
"'";
1527 $sql .=
",ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1528 $sql .=
",address = '".$this->db->escape($this->address).
"'";
1530 $sql .=
",zip = ".(!empty($this->zip) ?
"'".$this->db->escape($this->zip).
"'" :
"null");
1531 $sql .=
",town = ".(!empty($this->town) ?
"'".$this->db->escape($this->town).
"'" :
"null");
1533 $sql .=
",fk_departement = ".((!empty($this->state_id) && $this->state_id > 0) ? ((
int) $this->state_id) :
'null');
1534 $sql .=
",fk_pays = ".((!empty($this->country_id) && $this->country_id > 0) ? ((
int) $this->country_id) :
'null');
1536 $sql .=
",phone = ".(!empty($this->phone) ?
"'".$this->db->escape($this->phone).
"'" :
"null");
1537 $sql .=
",phone_mobile = ".(!empty($this->phone_mobile) ?
"'".$this->db->escape($this->phone_mobile).
"'" :
"null");
1538 $sql .=
",fax = ".(!empty($this->fax) ?
"'".$this->db->escape($this->fax).
"'" :
"null");
1539 $sql .=
",email = ".(!empty($this->email) ?
"'".$this->db->escape($this->email).
"'" :
"null");
1540 $sql .=
",socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1541 $sql .=
",url = ".(!empty($this->url) ?
"'".$this->db->escape($this->url).
"'" :
"null");
1543 $sql .=
",parent = ".($this->parent > 0 ? $this->parent :
"null");
1545 $sql .=
",note_private = ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
1546 $sql .=
",note_public = ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
1548 $sql .=
",siren = '".$this->db->escape($this->idprof1).
"'";
1549 $sql .=
",siret = '".$this->db->escape($this->idprof2).
"'";
1550 $sql .=
",ape = '".$this->db->escape($this->idprof3).
"'";
1551 $sql .=
",idprof4 = '".$this->db->escape($this->idprof4).
"'";
1552 $sql .=
",idprof5 = '".$this->db->escape($this->idprof5).
"'";
1553 $sql .=
",idprof6 = '".$this->db->escape($this->idprof6).
"'";
1555 $sql .=
",tva_assuj = ".($this->tva_assuj !=
'' ?
"'".$this->db->escape($this->tva_assuj).
"'" :
"null");
1556 $sql .=
",tva_intra = '".$this->db->escape($this->tva_intra).
"'";
1558 $sql .=
",vat_reverse_charge = " . ($this->vat_reverse_charge !=
'' ?
"'" . $this->db->escape($this->vat_reverse_charge) .
"'" : 0);
1560 $sql .=
",status = ".((int) $this->
status);
1563 $sql .=
",localtax1_assuj = ".($this->localtax1_assuj !=
'' ?
"'".$this->db->escape($this->localtax1_assuj).
"'" :
"null");
1564 $sql .=
",localtax2_assuj = ".($this->localtax2_assuj !=
'' ?
"'".$this->db->escape($this->localtax2_assuj).
"'" :
"null");
1565 if ($this->localtax1_assuj == 1) {
1566 if ($this->localtax1_value !=
'') {
1567 $sql .=
",localtax1_value =".$this->localtax1_value;
1569 $sql .=
",localtax1_value =0.000";
1572 $sql .=
",localtax1_value =0.000";
1575 if ($this->localtax2_assuj == 1) {
1576 if ($this->localtax2_value !=
'') {
1577 $sql .=
",localtax2_value =".$this->localtax2_value;
1579 $sql .=
",localtax2_value =0.000";
1582 $sql .=
",localtax2_value =0.000";
1585 $sql .=
",capital = ".($this->capital ===
null ?
"null" : $this->capital);
1587 $sql .=
",prefix_comm = ".(!empty($this->prefix_comm) ?
"'".$this->db->escape($this->prefix_comm).
"'" :
"null");
1589 $sql .=
",fk_effectif = ".($this->effectif_id > 0 ? ((int) $this->effectif_id) :
"null");
1590 if (isset($this->stcomm_id)) {
1591 $sql .=
",fk_stcomm=".(int) $this->stcomm_id;
1593 if (isset($this->typent_id)) {
1594 $sql .=
",fk_typent = ".($this->typent_id > 0 ? ((int) $this->typent_id) :
"0");
1597 $sql .=
",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ?
"'".$this->db->escape($this->forme_juridique_code).
"'" :
"null");
1599 $sql .=
",mode_reglement = ".(!empty($this->mode_reglement_id) ?
"'".$this->db->escape($this->mode_reglement_id).
"'" :
"null");
1600 $sql .=
",cond_reglement = ".(!empty($this->cond_reglement_id) ?
"'".$this->db->escape($this->cond_reglement_id).
"'" :
"null");
1601 $sql .=
",deposit_percent = ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null");
1602 $sql .=
",transport_mode = ".(!empty($this->transport_mode_id) ?
"'".$this->db->escape($this->transport_mode_id).
"'" :
"null");
1603 $sql .=
",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ?
"'".$this->db->escape($this->mode_reglement_supplier_id).
"'" :
"null");
1604 $sql .=
",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ?
"'".$this->db->escape($this->cond_reglement_supplier_id).
"'" :
"null");
1605 $sql .=
",transport_mode_supplier = ".(!empty($this->transport_mode_supplier_id) ?
"'".$this->db->escape($this->transport_mode_supplier_id).
"'" :
"null");
1606 $sql .=
",fk_shipping_method = ".(!empty($this->shipping_method_id) ?
"'".$this->db->escape($this->shipping_method_id).
"'" :
"null");
1608 $sql .=
",client = ".(!empty($this->client) ? $this->client : 0);
1609 $sql .=
",fournisseur = ".(!empty($this->fournisseur) ? $this->fournisseur : 0);
1610 $sql .=
",barcode = ".(!empty($this->barcode) ?
"'".$this->db->escape($this->barcode).
"'" :
"null");
1611 $sql .=
",default_lang = ".(!empty($this->default_lang) ?
"'".$this->db->escape($this->default_lang).
"'" :
"null");
1612 $sql .=
",logo = ".(!empty($this->logo) ?
"'".$this->db->escape($this->logo).
"'" :
"null");
1613 $sql .=
",logo_squarred = ".(!empty($this->logo_squarred) ?
"'".$this->db->escape($this->logo_squarred).
"'" :
"null");
1614 $sql .=
",outstanding_limit= ".($this->outstanding_limit !=
'' ? $this->outstanding_limit :
'null');
1615 $sql .=
",order_min_amount= ".($this->order_min_amount !=
'' ? $this->order_min_amount :
'null');
1616 $sql .=
",supplier_order_min_amount= ".($this->supplier_order_min_amount !=
'' ? $this->supplier_order_min_amount :
'null');
1617 $sql .=
",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel).
"'";
1619 $sql .=
", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1620 $sql .=
", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1622 $sql .=
", code_compta = ".(!empty($this->code_compta_client) ?
"'".$this->db->escape($this->code_compta_client).
"'" :
"null");
1626 $sql .=
", code_compta_fournisseur = ".(($this->code_compta_fournisseur !=
"") ?
"'".$this->db->escape($this->code_compta_fournisseur).
"'" :
"null");
1629 $sql .=
",webservices_url = ".(!empty($this->webservices_url) ?
"'".$this->db->escape($this->webservices_url).
"'" :
"null");
1630 $sql .=
",webservices_key = ".(!empty($this->webservices_key) ?
"'".$this->db->escape($this->webservices_key).
"'" :
"null");
1633 $sql .=
", fk_incoterms = ".((int) $this->fk_incoterms);
1634 $sql .=
", location_incoterms = ".(!empty($this->location_incoterms) ?
"'".$this->db->escape($this->location_incoterms).
"'" :
"null");
1637 $sql .=
", code_client = ".(!empty($this->code_client) ?
"'".$this->db->escape($this->code_client).
"'" :
"null");
1641 $sql .=
", code_fournisseur = ".(!empty($this->code_fournisseur) ?
"'".$this->db->escape($this->code_fournisseur).
"'" :
"null");
1643 $sql .=
", fk_user_modif = ".($user->id > 0 ? $user->id :
"null");
1644 $sql .=
", fk_multicurrency = ".(int) $this->fk_multicurrency;
1645 $sql .=
", multicurrency_code = '".$this->db->escape($this->multicurrency_code).
"'";
1646 $sql .=
", model_pdf = '".$this->db->escape($this->model_pdf).
"'";
1647 $sql .=
" WHERE rowid = ".(int) $id;
1649 $resql = $this->db->query($sql);
1651 if (is_object($this->oldcopy)) {
1652 if ($this->oldcopy->country_id != $this->country_id) {
1653 unset($this->country_code);
1654 unset($this->country);
1656 if ($this->oldcopy->state_id != $this->state_id) {
1657 unset($this->state_code);
1658 unset($this->state);
1661 unset($this->country_code);
1662 unset($this->country);
1663 unset($this->state_code);
1664 unset($this->state);
1667 $nbrowsaffected = $this->db->affected_rows($resql);
1669 if (!$error && $nbrowsaffected) {
1671 if (!$nosyncmember && isModEnabled(
'member')) {
1672 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1674 dol_syslog(get_class($this).
"::update update linked member");
1676 $lmember =
new Adherent($this->db);
1677 $result = $lmember->fetch(0, 0, $this->
id);
1680 $lmember->company = $this->name;
1683 $lmember->address = $this->address;
1684 $lmember->zip = $this->zip;
1685 $lmember->town = $this->town;
1686 $lmember->email = $this->email;
1687 $lmember->socialnetworks = $this->socialnetworks;
1688 $lmember->phone = $this->phone;
1689 $lmember->state_id = $this->state_id;
1690 $lmember->country_id = $this->country_id;
1691 $lmember->default_lang = $this->default_lang;
1693 $result = $lmember->update($user, 0, 1, 1, 1);
1695 $this->error = $lmember->error;
1696 $this->errors = array_merge($this->errors, $lmember->errors);
1697 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
1700 } elseif ($result < 0) {
1701 $this->error = $lmember->error;
1711 $this->db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int) $conf->entity));
1713 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
1716 $sql .=
", vat_reverse_charge";
1717 $sql .=
", accountancy_code_customer";
1718 $sql .=
", accountancy_code_supplier";
1719 $sql .=
", accountancy_code_buy";
1720 $sql .=
", accountancy_code_sell";
1721 $sql .=
") VALUES (";
1723 $sql .=
", ".$conf->entity;
1724 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1725 $sql .=
", '".$this->db->escape($this->code_compta_client).
"'";
1726 $sql .=
", '".$this->db->escape($this->code_compta_fournisseur).
"'";
1727 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1728 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1730 $result = $this->db->query($sql);
1733 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1752 if (!$error && $call_trigger) {
1754 $result = $this->
call_trigger(
'COMPANY_MODIFY', $user);
1762 dol_syslog(get_class($this).
"::Update success");
1763 $this->db->commit();
1766 $this->db->rollback();
1770 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1772 $this->error = $langs->trans(
"ErrorDuplicateField");
1775 $this->error = $this->db->lasterror();
1778 $this->db->rollback();
1782 $this->db->rollback();
1783 dol_syslog(get_class($this).
"::Update fails verify ".implode(
',', $this->errors), LOG_WARNING);
1807 public function fetch($rowid, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'', $is_client = 0, $is_supplier = 0)
1812 if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email) && empty($ref_alias)) {
1816 $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';
1817 $sql .=
', s.status, s.fk_warehouse';
1818 $sql .=
', s.price_level';
1819 $sql .=
', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif';
1820 $sql .=
', s.phone, s.phone_mobile, s.fax, s.email';
1821 $sql .=
', s.socialnetworks';
1822 $sql .=
', s.url, s.zip, s.town, s.note_private, s.note_public, s.client, s.fournisseur';
1823 $sql .=
', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1824 $sql .=
', s.capital, s.tva_intra';
1825 $sql .=
', s.fk_typent as typent_id';
1826 $sql .=
', s.fk_effectif as effectif_id';
1827 $sql .=
', s.fk_forme_juridique as forme_juridique_code';
1828 $sql .=
', s.webservices_url, s.webservices_key, s.model_pdf, s.last_main_doc';
1830 $sql .=
', s.code_compta, s.code_compta_fournisseur, s.accountancy_code_buy, s.accountancy_code_sell';
1831 $sql .=
', s.vat_reverse_charge as soc_vat_reverse_charge';
1833 $sql .=
', spe.accountancy_code_customer as code_compta, spe.accountancy_code_supplier as code_compta_fournisseur, spe.accountancy_code_buy, spe.accountancy_code_sell';
1834 $sql .=
', spe.vat_reverse_charge as spe_vat_reverse_charge';
1836 $sql .=
', s.code_client, s.code_fournisseur, s.parent, s.barcode';
1837 $sql .=
', s.fk_departement as state_id, s.fk_pays as country_id, s.fk_stcomm, s.mode_reglement, s.cond_reglement, s.deposit_percent, s.transport_mode';
1838 $sql .=
', s.fk_account, s.tva_assuj';
1839 $sql .=
', s.mode_reglement_supplier, s.cond_reglement_supplier, s.transport_mode_supplier';
1840 $sql .=
', s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred';
1841 $sql .=
', s.fk_shipping_method';
1842 $sql .=
', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1843 $sql .=
', s.order_min_amount, s.supplier_order_min_amount';
1844 $sql .=
', s.fk_multicurrency, s.multicurrency_code';
1845 $sql .=
', fj.libelle as forme_juridique';
1846 $sql .=
', e.libelle as effectif';
1847 $sql .=
', c.code as country_code, c.label as country';
1848 $sql .=
', d.code_departement as state_code, d.nom as state';
1849 $sql .=
', r.rowid as region_id, r.code_region as region_code';
1850 $sql .=
', st.libelle as stcomm, st.picto as stcomm_picto';
1851 $sql .=
', te.code as typent_code';
1852 $sql .=
', i.libelle as label_incoterms';
1853 if (!isModEnabled(
'multicompany')) {
1854 $sql .=
', s.remise_client, s.remise_supplier';
1856 $sql .=
', sr.remise_client, sr2.remise_supplier';
1858 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
1860 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = ".((int) $conf->entity);
1862 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_effectif as e ON s.fk_effectif = e.id';
1863 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON s.fk_pays = c.rowid';
1864 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcomm as st ON s.fk_stcomm = st.id';
1865 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
1866 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON s.fk_departement = d.rowid';
1867 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_regions as r ON d.fk_region = r.code_region ';
1868 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_typent as te ON s.fk_typent = te.id';
1869 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON s.fk_incoterms = i.rowid';
1872 if (isModEnabled(
'multicompany')) {
1873 $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').
'))';
1874 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_remise_supplier as sr2 ON sr2.rowid = (SELECT MAX(rowid) FROM '.MAIN_DB_PREFIX.
'societe_remise_supplier WHERE fk_soc = s.rowid AND entity IN ('.
getEntity(
'discount').
'))';
1876 $sql .=
' WHERE s.entity IN ('.getEntity($this->element).
')';
1880 $sql .=
' AND s.client > 0';
1883 $sql .=
' AND s.fournisseur > 0';
1887 $sql .=
' AND s.rowid = '.((int) $rowid);
1890 $sql .=
" AND s.nom = '".$this->db->escape($ref).
"'";
1893 $sql .=
" AND s.name_alias = '".$this->db->escape($ref_alias).
"'";
1896 $sql .=
" AND s.ref_ext = '".$this->db->escape($ref_ext).
"'";
1899 $sql .=
" AND s.barcode = '".$this->db->escape($barcode).
"'";
1902 $sql .=
" AND s.siren = '".$this->db->escape($idprof1).
"'";
1905 $sql .=
" AND s.siret = '".$this->db->escape($idprof2).
"'";
1908 $sql .=
" AND s.ape = '".$this->db->escape($idprof3).
"'";
1911 $sql .=
" AND s.idprof4 = '".$this->db->escape($idprof4).
"'";
1914 $sql .=
" AND s.idprof5 = '".$this->db->escape($idprof5).
"'";
1917 $sql .=
" AND s.idprof6 = '".$this->db->escape($idprof6).
"'";
1920 $sql .=
" AND s.email = '".$this->db->escape($email).
"'";
1923 $resql = $this->db->query($sql);
1925 $num = $this->db->num_rows($resql);
1927 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
1931 $obj = $this->db->fetch_object($resql);
1933 $this->
id = $obj->rowid;
1934 $this->entity = $obj->entity;
1935 $this->canvas = $obj->canvas;
1937 $this->
ref = $obj->rowid;
1938 $this->
name = $obj->name;
1939 $this->nom = $obj->name;
1940 $this->name_alias = $obj->name_alias;
1941 $this->ref_ext = $obj->ref_ext;
1943 $this->date_creation = $this->db->jdate($obj->date_creation);
1944 $this->date_modification = $this->db->jdate($obj->date_modification);
1945 $this->user_creation_id = $obj->fk_user_creat;
1946 $this->user_modification_id = $obj->fk_user_modif;
1948 $this->address = $obj->address;
1949 $this->zip = $obj->zip;
1950 $this->town = $obj->town;
1952 $this->country_id = $obj->country_id;
1953 $this->country_code = $obj->country_id ? $obj->country_code :
'';
1954 $this->country = $obj->country_id ? (($langs->transnoentities(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code) ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
1956 $this->state_id = $obj->state_id;
1957 $this->state_code = $obj->state_code;
1958 $this->region_id = $obj->region_id;
1959 $this->region_code = $obj->region_code;
1960 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
1962 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcomm);
1963 $label = ($transcode !=
'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm);
1964 $this->stcomm_id = $obj->fk_stcomm;
1965 $this->status_prospect_label = $label;
1966 $this->stcomm_picto = $obj->stcomm_picto;
1968 $this->email = $obj->email;
1969 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
1971 $this->url = $obj->url;
1972 $this->phone = $obj->phone;
1973 $this->phone_mobile = $obj->phone_mobile;
1974 $this->fax = $obj->fax;
1976 $this->parent = $obj->parent;
1978 $this->idprof1 = $obj->idprof1;
1979 $this->idprof2 = $obj->idprof2;
1980 $this->idprof3 = $obj->idprof3;
1981 $this->idprof4 = $obj->idprof4;
1982 $this->idprof5 = $obj->idprof5;
1983 $this->idprof6 = $obj->idprof6;
1985 $this->capital = $obj->capital;
1987 $this->code_client = $obj->code_client;
1988 $this->code_fournisseur = $obj->code_fournisseur;
1990 $this->code_compta = $obj->code_compta;
1991 $this->code_compta_client = $obj->code_compta;
1992 $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
1994 $this->barcode = $obj->barcode;
1996 $this->tva_assuj = $obj->tva_assuj;
1997 $this->tva_intra = $obj->tva_intra;
1999 if (!empty($obj->spe_vat_reverse_charge)) {
2000 $this->vat_reverse_charge = $obj->spe_vat_reverse_charge;
2001 } elseif (!empty($obj->soc_vat_reverse_charge)) {
2002 $this->vat_reverse_charge = $obj->soc_vat_reverse_charge;
2004 $this->vat_reverse_charge = 0;
2007 $this->
status = $obj->status;
2010 $this->localtax1_assuj = $obj->localtax1_assuj;
2011 $this->localtax2_assuj = $obj->localtax2_assuj;
2013 $this->localtax1_value = $obj->localtax1_value;
2014 $this->localtax2_value = $obj->localtax2_value;
2016 $this->typent_id = $obj->typent_id;
2017 $this->typent_code = $obj->typent_code;
2019 $this->effectif_id = $obj->effectif_id;
2020 $this->effectif = $obj->effectif_id ? $obj->effectif :
'';
2022 $this->forme_juridique_code = $obj->forme_juridique_code;
2023 $this->forme_juridique = $obj->forme_juridique_code ? $obj->forme_juridique :
'';
2025 $this->fk_prospectlevel = $obj->fk_prospectlevel;
2027 $this->prefix_comm = $obj->prefix_comm;
2029 $this->remise_percent = $obj->remise_client ?
price2num($obj->remise_client) : 0;
2030 $this->remise_supplier_percent = $obj->remise_supplier;
2032 $this->mode_reglement_id = $obj->mode_reglement;
2033 $this->cond_reglement_id = $obj->cond_reglement;
2034 $this->deposit_percent = $obj->deposit_percent;
2035 $this->transport_mode_id = $obj->transport_mode;
2036 $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier;
2037 $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier;
2038 $this->transport_mode_supplier_id = $obj->transport_mode_supplier;
2039 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
2040 $this->fk_account = $obj->fk_account;
2042 $this->client = $obj->client;
2043 $this->fournisseur = $obj->fournisseur;
2045 $this->note = $obj->note_private;
2046 $this->note_private = $obj->note_private;
2047 $this->note_public = $obj->note_public;
2048 $this->model_pdf = $obj->model_pdf;
2049 $this->default_lang = $obj->default_lang;
2050 $this->logo = $obj->logo;
2051 $this->logo_squarred = $obj->logo_squarred;
2053 $this->webservices_url = $obj->webservices_url;
2054 $this->webservices_key = $obj->webservices_key;
2056 $this->accountancy_code_buy = $obj->accountancy_code_buy;
2057 $this->accountancy_code_sell = $obj->accountancy_code_sell;
2059 $this->outstanding_limit = $obj->outstanding_limit;
2060 $this->order_min_amount = $obj->order_min_amount;
2061 $this->supplier_order_min_amount = $obj->supplier_order_min_amount;
2064 $this->price_level = $obj->price_level;
2067 $this->fk_warehouse = $obj->fk_warehouse;
2069 $this->import_key = $obj->import_key;
2072 $this->fk_incoterms = $obj->fk_incoterms;
2073 $this->location_incoterms = $obj->location_incoterms;
2074 $this->label_incoterms = $obj->label_incoterms;
2077 $this->fk_multicurrency = $obj->fk_multicurrency;
2078 $this->multicurrency_code = $obj->multicurrency_code;
2081 $this->model_pdf = $obj->model_pdf;
2082 $this->last_main_doc = $obj->last_main_doc;
2084 $result = $this->id;
2092 $this->db->free($resql);
2094 $this->error = $this->db->lasterror();
2095 $this->errors[] = $this->db->lasterror();
2101 $this->price_level = 1;
2127 public function findNearest($rowid = 0, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'', $is_client = 0, $is_supplier = 0)
2140 $tmpthirdparty =
new Societe($this->db);
2141 $result = $tmpthirdparty->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias, $is_client, $is_supplier);
2154 public function delete($id,
User $fuser =
null, $call_trigger = 1)
2156 global $conf, $user;
2158 if (empty($fuser)) {
2162 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2164 $entity = isset($this->entity) ? $this->entity : $conf->entity;
2166 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2171 if (empty($objectisused)) {
2175 if (!$error && $call_trigger) {
2177 $result = $this->
call_trigger(
'COMPANY_DELETE', $fuser);
2185 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2187 $toute_categs = array();
2190 $toute_categs[
'customer'] = $static_cat->containing($this->
id, Categorie::TYPE_CUSTOMER);
2191 $toute_categs[
'supplier'] = $static_cat->containing($this->
id, Categorie::TYPE_SUPPLIER);
2194 foreach ($toute_categs as $type => $categs_type) {
2195 foreach ($categs_type as $cat) {
2196 $cat->del_type($this, $type);
2202 foreach ($this->childtablesoncascade as $tabletodelete) {
2203 $deleteFromObject = explode(
':', $tabletodelete, 4);
2204 if (count($deleteFromObject) >= 2) {
2205 $className = str_replace(
'@',
'', $deleteFromObject[0]);
2206 $filepath = $deleteFromObject[1];
2207 $columnName = $deleteFromObject[2];
2209 $child_object =
new $className($this->db);
2210 $result = $child_object->deleteByParentField($id, $columnName);
2213 $this->errors[] = $child_object->error;
2218 $this->errors[] =
'Cannot include child class file '.$filepath;
2222 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
2223 $sql .=
" WHERE fk_soc = ".((int) $id);
2224 if (!$this->db->query($sql)) {
2226 $this->errors[] = $this->db->lasterror();
2238 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
2244 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2245 $sql .=
" SET parent = NULL";
2246 $sql .=
" WHERE parent = ".((int) $id);
2247 if (!$this->db->query($sql)) {
2249 $this->errors[] = $this->db->lasterror();
2256 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity";
2257 $sql .=
" WHERE fk_soc = ".((int) $id);
2258 if (!$this->db->query($sql)) {
2260 $this->errors[] = $this->db->lasterror();
2264 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe";
2265 $sql .=
" WHERE rowid = ".((int) $id);
2266 if (!$this->db->query($sql)) {
2268 $this->errors[] = $this->db->lasterror();
2273 $this->db->commit();
2276 if (!empty($conf->societe->multidir_output[$entity])) {
2277 $docdir = $conf->societe->multidir_output[$entity].
"/".$id;
2286 $this->db->rollback();
2290 dol_syslog(
"Can't remove thirdparty with id ".$id.
". There are ".$objectisused.
" children", LOG_WARNING);
2307 dol_syslog(get_class($this).
"::set_as_client is deprecated use setAsCustomer instead", LOG_NOTICE);
2321 if (($this->client == 2 || $this->client == 3) && !
getDolGlobalInt(
'SOCIETE_DISABLE_PROSPECTSCUSTOMERS')) {
2324 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2325 $sql .=
" SET client = ".((int) $newclient);
2326 $sql .=
" WHERE rowid = ".((int) $this->
id);
2328 $resql = $this->db->query($sql);
2330 $this->client = $newclient;
2351 global $conf, $langs;
2354 $note = trim($note);
2356 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2360 dol_syslog(get_class($this).
"::set_remise_client ".$remise.
", ".$note.
", ".$user->id);
2368 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2369 $sql .=
" SET remise_client = '".$this->db->escape($remise).
"'";
2370 $sql .=
" WHERE rowid = ".((int) $this->
id);
2371 $resql = $this->db->query($sql);
2373 $this->db->rollback();
2374 $this->error = $this->db->error();
2379 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise";
2380 $sql .=
" (entity, datec, fk_soc, remise_client, note, fk_user_author)";
2381 $sql .=
" VALUES (".((int) $conf->entity).
", '".$this->db->idate($now).
"', ".((int) $this->
id).
", '".$this->db->escape($remise).
"',";
2382 $sql .=
" '".$this->db->escape($note).
"',";
2383 $sql .=
" ".((int) $user->id);
2386 $resql = $this->db->query($sql);
2388 $this->db->rollback();
2389 $this->error = $this->db->lasterror();
2393 $this->db->commit();
2412 global $conf, $langs;
2415 $note = trim($note);
2417 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2421 dol_syslog(get_class($this).
"::set_remise_supplier ".$remise.
", ".$note.
", ".$user->id);
2429 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2430 $sql .=
" SET remise_supplier = '".$this->db->escape($remise).
"'";
2431 $sql .=
" WHERE rowid = ".((int) $this->
id);
2432 $resql = $this->db->query($sql);
2434 $this->db->rollback();
2435 $this->error = $this->db->error();
2440 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise_supplier";
2441 $sql .=
" (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
2442 $sql .=
" VALUES (".((int) $conf->entity).
", '".$this->db->idate($now).
"', ".((int) $this->
id).
", '".$this->db->escape($remise).
"',";
2443 $sql .=
" '".$this->db->escape($note).
"',";
2444 $sql .=
" ".((int) $user->id);
2447 $resql = $this->db->query($sql);
2449 $this->db->rollback();
2450 $this->error = $this->db->lasterror();
2454 $this->db->commit();
2473 public function set_remise_except($remise,
User $user, $desc, $vatrate =
'', $discount_type = 0, $price_base_type =
'HT')
2480 $desc = trim($desc);
2483 if (!($remise > 0)) {
2484 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"1");
2488 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"3");
2492 if ($this->
id > 0) {
2496 if (preg_match(
'/\((.*)\)/', $vatrate, $reg)) {
2497 $vat_src_code = $reg[1];
2498 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2501 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2504 $discount->fk_soc = $this->id;
2505 $discount->socid = $this->id;
2507 $discount->discount_type = $discount_type;
2509 if ($price_base_type ==
'TTC') {
2510 $discount->amount_ttc = $discount->multicurrency_amount_ttc =
price2num($remise,
'MT');
2511 $discount->amount_ht = $discount->multicurrency_amount_ht =
price2num((
float) $remise / (1 + (
float) $vatrate / 100),
'MT');
2512 $discount->amount_tva = $discount->multicurrency_amount_tva =
price2num((
float) $discount->amount_ttc - (
float) $discount->amount_ht,
'MT');
2514 $discount->amount_ht = $discount->multicurrency_amount_ht =
price2num($remise,
'MT');
2515 $discount->amount_tva = $discount->multicurrency_amount_tva =
price2num((
float) $remise * (
float) $vatrate / 100,
'MT');
2516 $discount->amount_ttc = $discount->multicurrency_amount_ttc =
price2num((
float) $discount->amount_ht + (
float) $discount->amount_tva,
'MT');
2519 $discount->tva_tx = (float)
price2num($vatrate);
2520 $discount->vat_src_code = $vat_src_code;
2522 $discount->description = $desc;
2524 $result = $discount->create($user);
2528 $this->error = $discount->error;
2547 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2550 $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type);
2554 $this->error = $discountstatic->error;
2572 $reparray = array();
2574 $sql =
"SELECT u.rowid, u.login, u.lastname, u.firstname, u.office_phone, u.job, u.email, u.statut as status, u.entity, u.photo, u.gender";
2575 $sql .=
", u.office_fax, u.user_mobile, u.personal_mobile";
2576 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc, ".MAIN_DB_PREFIX.
"user as u";
2578 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2579 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2581 $sql .=
" WHERE entity IN (0, ".$this->db->sanitize($conf->entity).
")";
2584 $sql .=
" AND u.rowid = sc.fk_user AND sc.fk_soc = ".((int) $this->
id);
2585 if (empty($sortfield) && empty($sortorder)) {
2586 $sortfield =
'u.lastname,u.firstname';
2587 $sortorder =
'ASC,ASC';
2589 $sql .= $this->db->order($sortfield, $sortorder);
2591 $resql = $this->db->query($sql);
2593 $num = $this->db->num_rows($resql);
2596 $obj = $this->db->fetch_object($resql);
2599 $reparray[$i][
'id'] = $obj->rowid;
2600 $reparray[$i][
'lastname'] = $obj->lastname;
2601 $reparray[$i][
'firstname'] = $obj->firstname;
2602 $reparray[$i][
'email'] = $obj->email;
2603 $reparray[$i][
'phone'] = $obj->office_phone;
2604 $reparray[$i][
'office_phone'] = $obj->office_phone;
2605 $reparray[$i][
'office_fax'] = $obj->office_fax;
2606 $reparray[$i][
'user_mobile'] = $obj->user_mobile;
2607 $reparray[$i][
'personal_mobile'] = $obj->personal_mobile;
2608 $reparray[$i][
'job'] = $obj->job;
2609 $reparray[$i][
'statut'] = $obj->status;
2610 $reparray[$i][
'status'] = $obj->status;
2611 $reparray[$i][
'entity'] = $obj->entity;
2612 $reparray[$i][
'login'] = $obj->login;
2613 $reparray[$i][
'photo'] = $obj->photo;
2614 $reparray[$i][
'gender'] = $obj->gender;
2616 $reparray[] = $obj->rowid;
2639 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2640 $sql .=
" SET price_level = ".((int) $price_level);
2641 $sql .=
" WHERE rowid = ".((int) $this->
id);
2643 if (!$this->db->query($sql)) {
2648 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_prices";
2649 $sql .=
" (datec, fk_soc, price_level, fk_user_author)";
2650 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $this->
id).
", ".((int) $price_level).
", ".((int) $user->id).
")";
2652 if (!$this->db->query($sql)) {
2674 if ($this->
id > 0 && $commid > 0) {
2678 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux";
2679 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2681 $resql = $this->db->query($sql);
2683 dol_syslog(get_class($this).
"::add_commercial Error ".$this->db->lasterror());
2689 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_commerciaux";
2690 $sql .=
" (fk_soc, fk_user)";
2691 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $commid).
")";
2693 $resql = $this->db->query($sql);
2695 dol_syslog(get_class($this).
"::add_commercial Error ".$this->db->lasterror());
2701 $this->context = array(
'commercial_modified' => $commid);
2703 $result = $this->
call_trigger(
'COMPANY_LINK_SALE_REPRESENTATIVE', $user);
2710 $this->db->commit();
2713 $this->db->rollback();
2733 $this->context = array(
'commercial_modified' => $commid);
2735 $result = $this->
call_trigger(
'COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
2740 if ($this->
id > 0 && $commid > 0) {
2741 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux ";
2742 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2744 if (!$this->db->query($sql)) {
2746 dol_syslog(get_class($this).
"::del_commercial Erreur");
2766 global $conf, $langs, $user;
2768 $langs->loadLangs([
'companies',
'commercial']);
2772 $option = $params[
'option'] ??
'';
2773 $nofetch = !empty($params[
'nofetch']);
2775 $noaliasinname = (empty($params[
'noaliasinname']) ? 0 : $params[
'noaliasinname']);
2778 return [
'optimize' => $langs->trans(
"ShowCompany")];
2781 if (!empty($this->logo) && class_exists(
'Form')) {
2782 $photo =
'<div class="photointooltip floatright">';
2783 $photo .=
Form::showphoto(
'societe', $this, 0, 40, 0,
'photoref',
'mini', 0);
2785 $datas[
'photo'] = $photo;
2786 } elseif (!empty($this->logo_squarred) && class_exists(
'Form')) {
2792 $datas[
'divopen'] =
'<div class="centpercent">';
2794 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
2795 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Customer").
'</u>';
2796 } elseif ($option ==
'prospect' && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
2797 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Prospect").
'</u>';
2798 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
2799 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Supplier").
'</u>';
2800 } elseif ($option ==
'agenda') {
2801 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2802 } elseif ($option ==
'project') {
2803 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2804 } elseif ($option ==
'margin') {
2805 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2806 } elseif ($option ==
'contact') {
2807 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2808 } elseif ($option ==
'ban') {
2809 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2813 if (empty($datas[
'picto'])) {
2814 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2816 if (isset($this->
status)) {
2817 $datas[
'status'] =
' '.$this->getLibStatut(5);
2819 if (isset($this->client) && isset($this->fournisseur)) {
2820 $datas[
'type'] =
' ' . $this->
getTypeUrl(1);
2823 if (!empty($this->name_alias) && empty($noaliasinname)) {
2826 if (!empty($this->email)) {
2827 $datas[
'email'] =
'<br>'.img_picto(
'',
'email',
'class="pictofixedwidth"').$this->email;
2829 if (!empty($this->url)) {
2830 $datas[
'url'] =
'<br>'.img_picto(
'',
'globe',
'class="pictofixedwidth"').$this->url;
2832 if (!empty($this->phone) || !empty($this->phone_mobile) || !empty($this->fax)) {
2833 $phonelist = array();
2835 $phonelist[] =
dol_print_phone($this->phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2838 if ($this->phone_mobile) {
2839 $phonelist[] =
dol_print_phone($this->phone_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'phone_mobile');
2842 $phonelist[] =
dol_print_phone($this->fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2844 $datas[
'phonelist'] =
'<br>'.implode(
' ', $phonelist);
2847 if (!empty($this->address)) {
2848 $datas[
'address'] =
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
' ', $langs);
2849 } elseif (!empty($this->country_code)) {
2850 $datas[
'address'] =
'<br><b>'.$langs->trans(
'Country').
':</b> '.$this->country_code;
2852 if (!empty($this->tva_intra) || (
getDolGlobalString(
'SOCIETE_SHOW_FIELD_IN_TOOLTIP') && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'vatnumber') !==
false)) {
2853 $datas[
'vatintra'] =
'<br><b>'.$langs->trans(
'VATIntra').
':</b> '.
dol_escape_htmltag($this->tva_intra);
2857 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid1') !==
false && $langs->trans(
'ProfId1'.$this->country_code) !=
'-') {
2858 $datas[
'profid1'] =
'<br><b>'.$langs->trans(
'ProfId1'.$this->country_code).
':</b> '.$this->idprof1;
2860 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid2') !==
false && $langs->trans(
'ProfId2'.$this->country_code) !=
'-') {
2861 $datas[
'profid2'] =
'<br><b>'.$langs->trans(
'ProfId2'.$this->country_code).
':</b> '.$this->idprof2;
2863 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid3') !==
false && $langs->trans(
'ProfId3'.$this->country_code) !=
'-') {
2864 $datas[
'profid3'] =
'<br><b>'.$langs->trans(
'ProfId3'.$this->country_code).
':</b> '.$this->idprof3;
2866 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid4') !==
false && $langs->trans(
'ProfId4'.$this->country_code) !=
'-') {
2867 $datas[
'profid4'] =
'<br><b>'.$langs->trans(
'ProfId4'.$this->country_code).
':</b> '.$this->idprof4;
2869 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid5') !==
false && $langs->trans(
'ProfId5'.$this->country_code) !=
'-') {
2870 $datas[
'profid5'] =
'<br><b>'.$langs->trans(
'ProfId5'.$this->country_code).
':</b> '.$this->idprof5;
2872 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid6') !==
false && $langs->trans(
'ProfId6'.$this->country_code) !=
'-') {
2873 $datas[
'profid6'] =
'<br><b>'.$langs->trans(
'ProfId6'.$this->country_code).
':</b> '.$this->idprof6;
2877 $datas[
'separator'] =
'<br>';
2879 if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
2880 $datas[
'customercode'] =
'<br><b>'.$langs->trans(
'CustomerCode').
':</b> '.$this->code_client;
2882 if (isModEnabled(
'accounting') && ($this->client == 1 || $this->client == 3)) {
2883 $langs->load(
'compta');
2884 $datas[
'accountancycustomercode'] =
'<br><b>'.$langs->trans(
'CustomerAccountancyCode').
':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client);
2887 if (!$nofetch && isModEnabled(
'category') && $this->client) {
2888 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2889 $form =
new Form($this->db);
2890 $datas[
'categories_customer'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_CUSTOMER, 1, 1);
2892 if (!empty($this->code_fournisseur) && $this->fournisseur) {
2893 $datas[
'suppliercode'] =
'<br><b>'.$langs->trans(
'SupplierCode').
':</b> '.$this->code_fournisseur;
2895 if (isModEnabled(
'accounting') && $this->fournisseur) {
2896 $langs->load(
'compta');
2897 $datas[
'accountancysuppliercode'] =
'<br><b>'.$langs->trans(
'SupplierAccountancyCode').
':</b> '.$this->code_compta_fournisseur;
2900 if (!$nofetch && isModEnabled(
'category') && $this->fournisseur) {
2901 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2902 $form =
new Form($this->db);
2903 $datas[
'categories_supplier'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_SUPPLIER, 1, 1);
2906 $datas[
'divclose'] =
'</div>';
2924 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1, $noaliasinname = 0, $target =
'', $morecss =
'')
2926 global $conf, $langs, $hookmanager, $user;
2928 if (!empty($conf->dol_no_mouse_hover)) {
2932 $name = $this->
name ? $this->
name : $this->nom;
2934 if (
getDolGlobalString(
'SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD')) {
2935 if (empty($option) && $this->client > 0) {
2936 $option =
'customer';
2938 if (empty($option) && $this->fournisseur > 0) {
2939 $option =
'supplier';
2945 if (($this->client) && (!empty($this->code_client)) && (
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 1 ||
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 2)) {
2946 $code = $this->code_client.
' - ';
2949 if (($this->fournisseur) && (!empty($this->code_fournisseur)) && (
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 1 ||
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 3)) {
2950 $code .= $this->code_fournisseur.
' - ';
2955 $name = $code.
' '.$name;
2962 if (!empty($this->name_alias) && empty($noaliasinname)) {
2963 $name .=
' ('.$this->name_alias.
')';
2969 'objecttype' => $this->element,
2970 'option' => $option,
2973 $classfortooltip =
'classfortooltip';
2976 $classfortooltip =
'classforajaxtooltip';
2977 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2986 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
2987 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2988 } elseif ($option ==
'prospect' && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
2989 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
2990 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
2991 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->id;
2992 } elseif ($option ==
'agenda') {
2993 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/agenda.php?socid='.$this->id;
2994 } elseif ($option ==
'project') {
2995 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/project.php?socid='.$this->id;
2996 } elseif ($option ==
'margin') {
2997 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/margin/tabs/thirdpartyMargins.php?socid='.$this->
id.
'&type=1';
2998 } elseif ($option ==
'contact') {
2999 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/contact.php?socid='.$this->id;
3000 } elseif ($option ==
'ban') {
3001 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$this->id;
3005 if (empty($linkstart)) {
3006 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$this->id;
3010 $linkstart .= (!empty($this->canvas) ?
'&canvas='.$this->canvas :
'');
3012 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3013 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3014 $add_save_lastsearch_values = 1;
3016 if ($add_save_lastsearch_values) {
3017 $linkstart .=
'&save_lastsearch_values=1';
3022 if (empty($notooltip)) {
3024 $label = $langs->trans(
"ShowCompany");
3025 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
3027 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
3028 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
' refurl valignmiddle"';
3029 $target_value = array(
'_self',
'_blank',
'_parent',
'_top');
3030 if (in_array($target, $target_value)) {
3031 $linkclose .=
' target="'.dol_escape_htmltag($target).
'"';
3034 $linkclose .=
' class="valignmiddle'.($morecss ?
' '.$morecss :
'').
'"';
3036 $linkstart .= $linkclose.
'>';
3039 if (!$user->hasRight(
'societe',
'client',
'voir') && $user->socid > 0 && $this->id != $user->socid) {
3044 $result .= $linkstart;
3046 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (
' class="'.(($withpicto != 2) ?
'paddingright' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
3048 if ($withpicto != 2) {
3051 $result .= $linkend;
3054 $hookmanager->initHooks(array(
'thirdpartydao'));
3055 $parameters = array(
3057 'getnomurl' => &$result,
3058 'withpicto ' => $withpicto,
3059 'option' => $option,
3060 'maxlen' => $maxlen,
3061 'notooltip' => $notooltip,
3062 'save_lastsearch_value' => $save_lastsearch_value
3064 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3066 $result = $hookmanager->resPrint;
3068 $result .= $hookmanager->resPrint;
3083 public function getTypeUrl($withpicto = 0, $option =
'', $notooltip = 0, $tag =
'a')
3085 global $conf, $langs;
3088 if (empty($option) || preg_match(
'/prospect/', $option)) {
3089 if (($this->client == 2 || $this->client == 3) && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
3090 $s .=
'<'.$tag.
' class="customer-back opacitymedium" title="'.$langs->trans(
"Prospect").
'" href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->
id.
'">'.
dol_substr($langs->trans(
"Prospect"), 0, 1).
'</'.$tag.
'>';
3093 if (empty($option) || preg_match(
'/customer/', $option)) {
3094 if (($this->client == 1 || $this->client == 3) && !
getDolGlobalString(
'SOCIETE_DISABLE_CUSTOMERS')) {
3095 $s .=
'<'.$tag.
' class="customer-back" title="'.$langs->trans(
"Customer").
'" href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->
id.
'">'.
dol_substr($langs->trans(
"Customer"), 0, 1).
'</'.$tag.
'>';
3098 if (empty($option) || preg_match(
'/supplier/', $option)) {
3099 if ((isModEnabled(
"supplier_order") || isModEnabled(
"supplier_invoice")) && $this->fournisseur) {
3100 $s .=
'<'.$tag.
' class="vendor-back" title="'.$langs->trans(
"Supplier").
'" href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->
id.
'">'.
dol_substr($langs->trans(
"Supplier"), 0, 1).
'</'.$tag.
'>';
3130 $langs->load(
'companies');
3132 $statusType =
'status4';
3134 $statusType =
'status6';
3137 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3138 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
3139 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"InActivity");
3140 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
3141 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"InActivity");
3144 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3161 if ($this->email && $addthirdparty) {
3162 if (empty($this->
name)) {
3163 $this->
name = $this->nom;
3165 $contact_emails[
'thirdparty'] = ($addthirdparty == 2 ?
'<span class="opacitymedium">' :
'').$langs->transnoentitiesnoconv(
"ThirdParty").($addthirdparty == 2 ?
'</span>' :
'').
': '.
dol_trunc($this->
name, 16).
" <".$this->email.
">";
3169 return $contact_emails;
3185 if (!empty($this->phone)) {
3186 if (empty($this->
name)) {
3187 $this->
name = $this->nom;
3190 $contact_phone[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->phone.
">";
3192 return $contact_phone;
3208 $contact_property = array();
3211 $sql =
"SELECT rowid, email, statut as status, phone_mobile, lastname, poste, firstname";
3212 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3213 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
3214 $sql .=
" AND entity IN (".getEntity($this->element).
")";
3215 $sql .=
" ORDER BY lastname, firstname";
3217 $resql = $this->db->query($sql);
3219 $nump = $this->db->num_rows($resql);
3223 if ($mode ==
'email') {
3229 while ($i < $nump) {
3230 $obj = $this->db->fetch_object($resql);
3231 if ($mode ==
'email') {
3232 $property = $obj->email;
3233 } elseif ($mode ==
'mobile') {
3234 $property = $obj->phone_mobile;
3236 $property = $obj->$mode;
3240 if ($obj->status == 1 || empty($hidedisabled)) {
3241 if (empty($property)) {
3242 if ($mode ==
'email') {
3243 $property = $langs->transnoentitiesnoconv(
"NoEMail");
3244 } elseif ($mode ==
'mobile') {
3245 $property = $langs->transnoentitiesnoconv(
"NoMobilePhone");
3249 if (!empty($obj->poste)) {
3250 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ?
" - ".$obj->poste :
"").(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3252 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3261 return $contact_property;
3274 $contacts = array();
3276 $sql =
"SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3277 $resql = $this->db->query($sql);
3279 $nump = $this->db->num_rows($resql);
3282 while ($i < $nump) {
3283 $obj = $this->db->fetch_object($resql);
3303 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
3304 $contacts = array();
3306 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3307 $resql = $this->db->query($sql);
3309 $nump = $this->db->num_rows($resql);
3312 while ($i < $nump) {
3313 $obj = $this->db->fetch_object($resql);
3314 $contact =
new Contact($this->db);
3315 $contact->fetch($obj->rowid);
3316 $contacts[] = $contact;
3337 $contact_property =
'';
3339 if (empty($rowid)) {
3343 $sql =
"SELECT rowid, email, phone_mobile, lastname, firstname";
3344 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3345 $sql .=
" WHERE rowid = ".((int) $rowid);
3347 $resql = $this->db->query($sql);
3349 $nump = $this->db->num_rows($resql);
3352 $obj = $this->db->fetch_object($resql);
3354 if ($mode ==
'email') {
3356 } elseif ($mode ==
'mobile') {
3357 $contact_property = $obj->phone_mobile;
3360 return $contact_property;
3379 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3383 $bac->fetch(0,
'', $this->
id);
3386 if ($mode ==
'label') {
3387 return $bac->getRibLabel(
true);
3388 } elseif ($mode ==
'rum') {
3389 if (empty($bac->rum)) {
3390 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
3392 $bac->fetch_thirdparty();
3393 $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
3396 } elseif ($mode ==
'format') {
3397 return $bac->frstrecur;
3399 return 'BadParameterToFunctionDisplayRib';
3415 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3416 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE type='ban' AND fk_soc = ".((int) $this->
id);
3417 $result = $this->db->query($sql);
3420 $this->errors[] = $this->db->lasterror;
3423 $num_rows = $this->db->num_rows($result);
3424 $rib_array = array();
3426 while ($obj = $this->db->fetch_object($result)) {
3428 $rib->fetch($obj->rowid);
3429 $rib_array[] = $rib;
3445 public function get_codeclient($objsoc =
null, $type = 0)
3452 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3453 foreach ($dirsociete as $dirroot) {
3460 $mod =
new $module($this->db);
3462 $this->code_client = $mod->getNextValue($objsoc, $type);
3463 $this->prefixCustomerIsRequired = $mod->prefixIsRequired;
3465 dol_syslog(get_class($this).
"::get_codeclient code_client=".$this->code_client.
" module=".$module);
3478 public function get_codefournisseur($objsoc =
null, $type = 1)
3485 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3486 foreach ($dirsociete as $dirroot) {
3493 $mod =
new $module($this->db);
3495 $this->code_fournisseur = $mod->getNextValue($objsoc, $type);
3497 dol_syslog(get_class($this).
"::get_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3515 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3516 foreach ($dirsociete as $dirroot) {
3523 $mod =
new $module($this->db);
3525 dol_syslog(get_class($this).
"::codeclient_modifiable code_client=".$this->code_client.
" module=".$module);
3526 if ($mod->code_modifiable_null && !$this->code_client) {
3529 if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
3532 if ($mod->code_modifiable) {
3555 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3556 foreach ($dirsociete as $dirroot) {
3563 $mod =
new $module($this->db);
3565 dol_syslog(get_class($this).
"::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur.
" module=".$module);
3566 if ($mod->code_modifiable_null && !$this->code_fournisseur) {
3569 if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
3572 if ($mod->code_modifiable) {
3601 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3602 foreach ($dirsociete as $dirroot) {
3609 $mod =
new $module($this->db);
3611 dol_syslog(get_class($this).
"::check_codeclient code_client=".$this->code_client.
" module=".$module);
3612 $result = $mod->verif($this->db, $this->code_client, $this, 0);
3614 $this->error = $mod->error;
3615 $this->errors = $mod->errors;
3642 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3643 foreach ($dirsociete as $dirroot) {
3650 $mod =
new $module($this->db);
3652 dol_syslog(get_class($this).
"::check_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3653 $result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
3655 $this->error = $mod->error;
3656 $this->errors = $mod->errors;
3681 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3682 foreach ($dirsociete as $dirroot) {
3690 $mod =
new $module();
3693 $result = $mod->get_code($this->db, $this, $type);
3695 if ($type ==
'customer') {
3696 $this->code_compta_client = $mod->code;
3697 $this->code_compta = $this->code_compta_client;
3698 } elseif ($type ==
'supplier') {
3699 $this->code_compta_fournisseur = $mod->code;
3704 $this->error =
'ErrorAccountancyCodeNotDefined';
3708 if ($type ==
'customer') {
3709 $this->code_compta_client =
'';
3710 $this->code_compta =
'';
3711 } elseif ($type ==
'supplier') {
3712 $this->code_compta_fournisseur =
'';
3727 dol_syslog(get_class($this).
'::setParent', LOG_DEBUG);
3733 if ($sameparent < 0) {
3736 if ($sameparent == 1) {
3737 setEventMessages(
'ParentCompanyToAddIsAlreadyAChildOfModifiedCompany',
null,
'warnings');
3742 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe SET parent = '.($id > 0 ? $id :
'null').
' WHERE rowid = '.((
int) $this->id);
3744 $resql = $this->db->query($sql);
3746 $this->parent = $id;
3766 if ($counter > 100) {
3767 dol_syslog(
"Too high level of parent - child for company. May be an infinite loop ?", LOG_WARNING);
3770 $sql =
'SELECT s.parent';
3771 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
3772 $sql .=
' WHERE rowid = '.((int) $idparent);
3773 $resql = $this->db->query($sql);
3775 $obj = $this->db->fetch_object($resql);
3777 if ($obj->parent ==
'') {
3779 } elseif ($obj->parent == $idchild) {
3801 if ($company_id > 0) {
3802 $sql =
"SELECT parent FROM " . MAIN_DB_PREFIX .
"societe WHERE rowid = ".((int) $company_id);
3803 $resql = $this->db->query($sql);
3805 if ($obj = $this->db->fetch_object($resql)) {
3806 $parent = $obj->parent;
3807 if ($parent > 0 && !in_array($parent, $parents)) {
3808 $parents[] = $parent;
3814 $this->db->free($resql);
3816 setEventMessage($langs->trans(
'GetCompanyParentsError', $this->db->lasterror()),
'errors');
3901 $sql =
"SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"societe WHERE ".$field.
" = '".$this->db->escape($value).
"' AND entity IN (".
getEntity(
'societe').
")";
3903 $sql .=
" AND rowid <> ".$socid;
3905 $resql = $this->db->query($sql);
3907 $obj = $this->db->fetch_object($resql);
3911 print $this->db->error();
3913 $this->db->free($resql);
3937 require_once DOL_DOCUMENT_ROOT.
'/core/lib/profid.lib.php';
3946 if ($idprof == 1 && $soc->country_code ==
'FR' && !
isValidSiren($this->idprof1)) {
3951 if ($idprof == 2 && $soc->country_code ==
'FR' && !
isValidSiret($this->idprof2)) {
3956 if ($idprof == 1 && $soc->country_code ==
'ES') {
3961 if ($idprof == 1 && $soc->country_code ==
'PT' && !
isValidTinForPT($this->idprof1)) {
3966 if ($idprof == 1 && $soc->country_code ==
'DZ' && !
isValidTinForDZ($this->idprof1)) {
3971 if ($idprof == 1 && $soc->country_code ==
'BE' && !
isValidTinForBE($this->idprof1)) {
3990 global $conf, $langs, $hookmanager;
3995 $hookmanager->initHooks(array(
'idprofurl'));
3996 $parameters = array(
'idprof' => $idprof,
'company' => $thirdparty);
3997 $reshook = $hookmanager->executeHooks(
'getIdProfUrl', $parameters, $this, $action);
3998 if (empty($reshook)) {
4004 $strippedIdProf1 = str_replace(
' ',
'', $thirdparty->idprof1);
4005 if ($idprof == 1 && $thirdparty->country_code ==
'FR') {
4006 $url =
'https://annuaire-entreprises.data.gouv.fr/entreprise/'.$strippedIdProf1;
4008 if ($idprof == 1 && ($thirdparty->country_code ==
'GB' || $thirdparty->country_code ==
'UK')) {
4009 $url =
'https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
4011 if ($idprof == 1 && $thirdparty->country_code ==
'ES') {
4012 $url =
'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
4014 if ($idprof == 1 && $thirdparty->country_code ==
'IN') {
4015 $url =
'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.
';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
4017 if ($idprof == 1 && $thirdparty->country_code ==
'DZ') {
4018 $url =
'http://nif.mfdgi.gov.dz/nif.asp?Nif='.$strippedIdProf1;
4020 if ($idprof == 1 && $thirdparty->country_code ==
'PT') {
4021 $url =
'http://www.nif.pt/'.$strippedIdProf1;
4025 return '<a target="_blank" rel="noopener noreferrer" href="'.$url.
'">'.$langs->trans(
"Check").
'</a>';
4028 return $hookmanager->resPrint;
4043 $sql =
"SELECT COUNT(*) as numproj FROM ".MAIN_DB_PREFIX.
"projet WHERE fk_soc = ".((int) $this->
id);
4044 $resql = $this->db->query($sql);
4046 $obj = $this->db->fetch_object($resql);
4047 $count = $obj->numproj;
4050 print $this->db->error();
4052 $this->db->free($resql);
4053 return ($count > 0);
4065 $sql =
"SELECT s.rowid, s.nom as name, s.datec, tms as datem,";
4066 $sql .=
" fk_user_creat, fk_user_modif";
4067 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
4068 $sql .=
" WHERE s.rowid = ".((int) $id);
4070 $result = $this->db->query($sql);
4072 if ($this->db->num_rows($result)) {
4073 $obj = $this->db->fetch_object($result);
4075 $this->
id = $obj->rowid;
4077 $this->user_creation_id = $obj->fk_user_creat;
4078 $this->user_modification_id = $obj->fk_user_modif;
4079 $this->date_creation = $this->db->jdate($obj->datec);
4080 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
4082 $this->
ref = $obj->name;
4085 $this->db->free($result);
4099 $isACompany =
getDolGlobalInt(
'MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES');
4102 if (!empty($this->tva_intra)) {
4104 } elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) {
4109 if (preg_match(
'/^TE_PRIVATE/', $this->typent_code)) {
4119 return (
bool) $isACompany;
4129 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4142 $this->SupplierCategories = array();
4143 $sql =
"SELECT rowid, label";
4144 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
4145 $sql .=
" WHERE type = ".Categorie::TYPE_SUPPLIER;
4147 $resql = $this->db->query($sql);
4149 while ($obj = $this->db->fetch_object($resql)) {
4150 $this->SupplierCategories[$obj->rowid] = $obj->label;
4168 if ($categorie_id > 0 && $this->
id > 0) {
4169 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_fournisseur (fk_categorie, fk_soc) ";
4170 $sql .=
" VALUES (".((int) $categorie_id).
", ".((int) $this->
id).
")";
4172 if ($resql = $this->db->query($sql)) {
4188 $sql =
"SELECT count(mc.email) as nb";
4189 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
4190 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->email).
"' ";
4191 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
4193 $resql = $this->db->query($sql);
4195 $obj = $this->db->fetch_object($resql);
4198 $this->db->free($resql);
4201 $this->error = $this->db->error();
4221 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing', 0).
") AND email = '".$this->db->escape($this->email).
"'";
4222 $resql = $this->db->query($sql);
4224 $obj = $this->db->fetch_object($resql);
4225 $noemail = $obj->nb;
4226 if (empty($noemail)) {
4227 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing_unsubscribe(email, entity, date_creat) VALUES ('".$this->db->escape($this->email).
"', ".
getEntity(
'mailing', 0).
", '".$this->db->idate(
dol_now()).
"')";
4228 $resql = $this->db->query($sql);
4231 $this->error = $this->db->lasterror();
4232 $this->errors[] = $this->error;
4237 $this->error = $this->db->lasterror();
4238 $this->errors[] = $this->error;
4241 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->db->escape($this->email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
4242 $resql = $this->db->query($sql);
4245 $this->error = $this->db->lasterror();
4246 $this->errors[] = $this->error;
4250 if (empty($error)) {
4251 $this->no_email = $no_email;
4252 $this->db->commit();
4255 $this->db->rollback();
4272 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->db->escape($this->email).
"'";
4273 $resql = $this->db->query($sql);
4275 $obj = $this->db->fetch_object($resql);
4276 $this->no_email = $obj->nb;
4279 $this->error = $this->db->lasterror();
4280 $this->errors[] = $this->error;
4300 global $conf, $user, $langs;
4302 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
4303 $fullname = $member->getFullName($langs);
4305 if ($member->morphy ==
'mor') {
4306 if (empty($socname)) {
4307 $socname = $member->company ? $member->company : $member->societe;
4309 if (!empty($fullname) && empty($socalias)) {
4310 $socalias = $fullname;
4312 } elseif (empty($socname) && $member->morphy ==
'phy') {
4313 if (empty($socname)) {
4314 $socname = $fullname;
4316 if (!empty($member->company) && empty($socalias)) {
4317 $socalias = $member->company;
4322 $alias = $socalias ? $socalias :
'';
4326 $this->
name = $name;
4327 $this->name_alias = $alias;
4328 $this->address = $member->address;
4329 $this->zip = $member->zip;
4330 $this->town = $member->town;
4331 $this->country_code = $member->country_code;
4332 $this->country_id = $member->country_id;
4333 $this->phone = $member->phone;
4334 $this->email = $member->email;
4335 $this->socialnetworks = $member->socialnetworks;
4336 $this->entity = $member->entity;
4339 $this->code_client = ($customercode ? $customercode : -1);
4340 $this->code_fournisseur =
'-1';
4341 $this->typent_code = ($member->morphy ==
'phy' ?
'TE_PRIVATE' : 0);
4342 $this->typent_id = $this->typent_code ?
dol_getIdFromCode($this->db, $this->typent_code,
'c_typent',
'id',
'code') : 0;
4347 $result = $this->
create($user);
4353 $this->name_bis = $member->lastname;
4354 $this->firstname = $member->firstname;
4355 $this->civility_id = $member->civility_id;
4357 dol_syslog(
"We ask to create a contact/address too", LOG_DEBUG);
4362 $this->db->rollback();
4367 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent";
4368 $sql .=
" SET fk_soc = ".((int) $this->
id);
4369 $sql .=
" WHERE rowid = ".((int) $member->id);
4371 $resql = $this->db->query($sql);
4373 $this->db->commit();
4376 $this->error = $this->db->error();
4378 $this->db->rollback();
4383 dol_syslog(get_class($this).
"::create_from_member - 2 - ".$this->error.
" - ".implode(
',', $this->errors), LOG_ERR);
4385 $this->db->rollback();
4401 $this->entity = $conf->entity;
4403 $this->nom = $this->name;
4415 $country_code = $country_label =
'';
4418 $country_id = (is_numeric($tmp[0])) ? (
int) $tmp[0] : 0;
4419 if (!empty($tmp[1])) {
4420 $country_code = $tmp[1];
4421 $country_label = $tmp[2];
4424 dol_syslog(
"Your country setup use an old syntax. Reedit it using setup area.", LOG_WARNING);
4425 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4426 $country_code =
getCountry($country_id, 2, $this->db);
4427 $country_label =
getCountry($country_id, 0, $this->db);
4430 $this->country_id = $country_id;
4431 $this->country_code = $country_code;
4432 $this->country = $country_label;
4433 if (is_object($langs)) {
4434 $this->country = ($langs->trans(
'Country'.$country_code) !=
'Country'.$country_code) ? $langs->trans(
'Country'.$country_code) : $country_label;
4440 $state_code = $state_label =
'';
4443 $state_id = $tmp[0];
4444 if (!empty($tmp[1])) {
4445 $state_code = $tmp[1];
4446 $state_label = $tmp[2];
4448 dol_syslog(
"Your setup of State has an old syntax (entity=".$conf->entity.
"). Go in Home - Setup - Organization then Save should remove this error.", LOG_ERR);
4449 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4450 $state_code =
getState($state_id, 2, $this->db);
4451 $state_label =
getState($state_id, 0, $this->db);
4454 $this->state_id = $state_id;
4455 $this->state_code = $state_code;
4456 $this->state = $state_label;
4457 if (is_object($langs)) {
4458 $this->state = ($langs->trans(
'State'.$state_code) !=
'State'.$state_code) ? $langs->trans(
'State'.$state_code) : $state_label;
4473 $this->socialnetworks = array();
4474 if (!empty($facebook_url)) {
4475 $this->socialnetworks[
'facebook'] = $facebook_url;
4477 if (!empty($twitter_url)) {
4478 $this->socialnetworks[
'twitter'] = $twitter_url;
4480 if (!empty($linkedin_url)) {
4481 $this->socialnetworks[
'linkedin'] = $linkedin_url;
4483 if (!empty($instagram_url)) {
4484 $this->socialnetworks[
'instagram'] = $instagram_url;
4486 if (!empty($youtube_url)) {
4487 $this->socialnetworks[
'youtube'] = $youtube_url;
4489 if (!empty($github_url)) {
4490 $this->socialnetworks[
'github'] = $github_url;
4503 $this->forme_juridique_code =
getDolGlobalString(
'MAIN_INFO_SOCIETE_FORME_JURIDIQUE');
4510 $this->logo_squarred_small =
getDolGlobalString(
'MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL');
4511 $this->logo_squarred_mini =
getDolGlobalString(
'MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI');
4517 $this->localtax1_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && (
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'1' ||
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'localtax1on')) ? 1 : 0);
4518 $this->localtax2_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && (
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'1' ||
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'localtax2on')) ? 1 : 0);
4535 $this->
name =
'THIRDPARTY SPECIMEN '.dol_print_date($now,
'dayhourlog');
4536 $this->nom = $this->name;
4537 $this->ref_ext =
'Ref ext';
4538 $this->specimen = 1;
4539 $this->address =
'21 jump street';
4540 $this->zip =
'99999';
4541 $this->town =
'MyTown';
4542 $this->state_id = 1;
4543 $this->state_code =
'AA';
4544 $this->state =
'MyState';
4545 $this->country_id = 1;
4546 $this->country_code =
'FR';
4547 $this->email =
'specimen@specimen.com';
4548 $this->socialnetworks = array(
4549 'skype' =>
'skypepseudo',
4550 'twitter' =>
'twitterpseudo',
4551 'facebook' =>
'facebookpseudo',
4552 'linkedin' =>
'linkedinpseudo',
4554 $this->url =
'http://www.specimen.com';
4556 $this->phone =
'0909090901';
4557 $this->phone_mobile =
'0909090901';
4558 $this->fax =
'0909090909';
4560 $this->code_client =
'CC-'.dol_print_date($now,
'dayhourlog');
4561 $this->code_fournisseur =
'SC-'.dol_print_date($now,
'dayhourlog');
4562 $this->capital = 10000;
4564 $this->prospect = 1;
4565 $this->fournisseur = 1;
4566 $this->tva_assuj = 1;
4567 $this->tva_intra =
'EU1234567';
4568 $this->note_public =
'This is a comment (public)';
4569 $this->note_private =
'This is a comment (private)';
4571 $this->idprof1 =
'idprof1';
4572 $this->idprof2 =
'idprof2';
4573 $this->idprof3 =
'idprof3';
4574 $this->idprof4 =
'idprof4';
4575 $this->idprof5 =
'idprof5';
4576 $this->idprof6 =
'idprof6';
4589 $sql =
"SELECT t.localtax1, t.localtax2";
4590 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4591 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4592 $sql .=
" AND t.active = 1";
4593 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
4594 if (empty($localTaxNum)) {
4595 $sql .=
" AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
4596 } elseif ($localTaxNum == 1) {
4597 $sql .=
" AND t.localtax1_type <> '0'";
4598 } elseif ($localTaxNum == 2) {
4599 $sql .=
" AND t.localtax2_type <> '0'";
4602 $resql = $this->db->query($sql);
4604 return ($this->db->num_rows($resql) > 0);
4617 $sql =
"SELECT t.rowid";
4618 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4619 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4620 $sql .=
" AND t.active = 1 AND t.recuperableonly = 1";
4621 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
4624 $resql = $this->db->query($sql);
4626 return ($this->db->num_rows($resql) > 0);
4640 $sql =
"SELECT COUNT(*) as nb";
4641 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_revenuestamp as r, ".MAIN_DB_PREFIX.
"c_country as c";
4642 $sql .=
" WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4643 $sql .=
" AND r.active = 1";
4646 $resql = $this->db->query($sql);
4648 $obj = $this->db->fetch_object($resql);
4649 return (($obj->nb > 0) ?
true :
false);
4651 $this->error = $this->db->lasterror();
4679 if ($fk_prospectlevel !=
'') {
4680 $label = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
4682 if ($label ==
"ProspectLevel".$fk_prospectlevel) {
4683 $label = $langs->getLabelFromKey($this->db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
4699 return $this->
LibProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
4721 $langs->load(
'customers');
4724 if ($status ==
'-1' || $status ==
'ST_NO') {
4725 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect-1");
4726 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4727 return img_action($langs->trans(
"StatusProspect0"), 0, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect0");
4728 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4729 return img_action($langs->trans(
"StatusProspect1"), 1, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect1");
4730 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4731 return img_action($langs->trans(
"StatusProspect2"), 2, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect2");
4732 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4733 return img_action($langs->trans(
"StatusProspect3"), 3, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect3");
4735 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto,
'class="inline-block valignmiddle"').
' '.(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label);
4737 } elseif ($mode == 3) {
4738 if ($status ==
'-1' || $status ==
'ST_NO') {
4739 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto,
'class="inline-block valignmiddle"');
4740 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4741 return img_action($langs->trans(
"StatusProspect0"), 0, $picto,
'class="inline-block valignmiddle"');
4742 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4743 return img_action($langs->trans(
"StatusProspect1"), 1, $picto,
'class="inline-block valignmiddle"');
4744 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4745 return img_action($langs->trans(
"StatusProspect2"), 2, $picto,
'class="inline-block valignmiddle"');
4746 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4747 return img_action($langs->trans(
"StatusProspect3"), 3, $picto,
'class="inline-block valignmiddle"');
4749 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto,
'class="inline-block valignmiddle"');
4751 } elseif ($mode == 4) {
4752 if ($status ==
'-1' || $status ==
'ST_NO') {
4753 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect-1");
4754 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4755 return img_action($langs->trans(
"StatusProspect0"), 0, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect0");
4756 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4757 return img_action($langs->trans(
"StatusProspect1"), 1, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect1");
4758 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4759 return img_action($langs->trans(
"StatusProspect2"), 2, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect2");
4760 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4761 return img_action($langs->trans(
"StatusProspect3"), 3, $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect3");
4763 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label, 0, $picto,
'class="inline-block valignmiddle"').
' '.(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label);
4767 return "Error, mode/status not found";
4779 if ($mode ==
'supplier') {
4780 $table =
'supplier_proposal';
4783 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4784 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4785 if ($mode ==
'supplier') {
4786 $sql .=
" AND entity IN (".getEntity(
'supplier_proposal').
")";
4788 $sql .=
" AND entity IN (".getEntity(
'propal').
")";
4791 dol_syslog(
"getOutstandingProposals for fk_soc = ".((
int) $this->
id), LOG_DEBUG);
4793 $resql = $this->db->query($sql);
4795 $outstandingOpened = 0;
4796 $outstandingTotal = 0;
4797 $outstandingTotalIncTax = 0;
4798 $arrayofref = array();
4799 while ($obj = $this->db->fetch_object($resql)) {
4800 $arrayofref[$obj->rowid] = $obj->ref;
4801 $outstandingTotal += $obj->total_ht;
4802 $outstandingTotalIncTax += $obj->total_ttc;
4803 if ($obj->status != 0) {
4805 $outstandingOpened += $obj->total_ttc;
4808 return array(
'opened' => $outstandingOpened,
'total_ht' => $outstandingTotal,
'total_ttc' => $outstandingTotalIncTax,
'refs' => $arrayofref);
4822 $table =
'commande';
4823 if ($mode ==
'supplier') {
4824 $table =
'commande_fournisseur';
4827 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4828 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4829 if ($mode ==
'supplier') {
4830 $sql .=
" AND entity IN (".getEntity(
'supplier_order').
")";
4832 $sql .=
" AND entity IN (".getEntity(
'commande').
")";
4835 dol_syslog(
"getOutstandingOrders", LOG_DEBUG);
4836 $resql = $this->db->query($sql);
4838 $outstandingOpened = 0;
4839 $outstandingTotal = 0;
4840 $outstandingTotalIncTax = 0;
4841 $arrayofref = array();
4842 while ($obj = $this->db->fetch_object($resql)) {
4843 $arrayofref[$obj->rowid] = $obj->ref;
4844 $outstandingTotal += $obj->total_ht;
4845 $outstandingTotalIncTax += $obj->total_ttc;
4846 if ($obj->status != 0) {
4848 $outstandingOpened += $obj->total_ttc;
4851 return array(
'opened' => $outstandingOpened,
'total_ht' => $outstandingTotal,
'total_ttc' => $outstandingTotalIncTax,
'refs' => $arrayofref);
4867 if ($mode ==
'supplier') {
4868 $table =
'facture_fourn';
4878 $sql =
"SELECT rowid, ref, total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table.
" as f";
4879 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4880 if (!empty($late)) {
4881 $sql .=
" AND date_lim_reglement < '".$this->db->idate(
dol_now()).
"'";
4883 if ($mode ==
'supplier') {
4884 $sql .=
" AND entity IN (".getEntity(
'facture_fourn').
")";
4886 $sql .=
" AND entity IN (".getEntity(
'invoice').
")";
4889 dol_syslog(
"getOutstandingBills", LOG_DEBUG);
4890 $resql = $this->db->query($sql);
4892 $outstandingOpened = 0;
4893 $outstandingTotal = 0;
4894 $outstandingTotalIncTax = 0;
4895 $arrayofref = array();
4896 $arrayofrefopened = array();
4897 if ($mode ==
'supplier') {
4898 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
4901 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
4902 $tmpobject =
new Facture($this->db);
4904 while ($obj = $this->db->fetch_object($resql)) {
4905 $arrayofref[$obj->rowid] = $obj->ref;
4906 $tmpobject->id = $obj->rowid;
4908 if ($obj->status != $tmpobject::STATUS_DRAFT
4909 && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code ==
'replaced')
4911 $outstandingTotal += $obj->total_ht;
4912 $outstandingTotalIncTax += $obj->total_ttc;
4918 && $obj->status != $tmpobject::STATUS_DRAFT
4919 && $obj->status != $tmpobject::STATUS_ABANDONED
4920 && $obj->status != $tmpobject::STATUS_CLOSED) {
4922 $paiement = $tmpobject->getSommePaiement();
4923 $creditnotes = $tmpobject->getSumCreditNotesUsed();
4924 $deposits = $tmpobject->getSumDepositsUsed();
4926 $remaintopay = ($obj->total_ttc - $paiement - $creditnotes - $deposits);
4927 $outstandingOpened += $remaintopay;
4933 $remainingcreditnote = $tmpobject->getSumFromThisCreditNotesNotUsed();
4934 $remaintopay -= $remainingcreditnote;
4935 $outstandingOpened -= $remainingcreditnote;
4939 $arrayofrefopened[$obj->rowid] = $obj->ref;
4942 return array(
'opened' => $outstandingOpened,
'total_ht' => $outstandingTotal,
'total_ttc' => $outstandingTotalIncTax,
'refs' => $arrayofref,
'refsopened' => $arrayofrefopened);
4944 dol_syslog(
"Sql error ".$this->db->lasterror, LOG_ERR);
4971 $langs->load(
'companies');
4974 return $langs->trans(
"NorProspectNorCustomer");
4975 } elseif ($status == 1) {
4976 return $langs->trans(
"Customer");
4977 } elseif ($status == 2) {
4978 return $langs->trans(
"Prospect");
4979 } elseif ($status == 3) {
4980 return $langs->trans(
"ProspectCustomer");
4998 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
5002 if (!empty($moreparams) && !empty($moreparams[
'use_companybankid'])) {
5003 $modelpath =
"core/modules/bank/doc/";
5005 include_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
5007 $result = $companybankaccount->fetch($moreparams[
'use_companybankid']);
5009 dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
5011 $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
5012 $this->last_main_doc = $companybankaccount->last_main_doc;
5019 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_COMPANY_ADDON_PDF_NotDefined");
5024 if (!isset($this->bank_account)) {
5025 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
5028 $result = $bac->fetch(0,
'', $this->
id);
5030 $this->bank_account = $bac;
5032 $this->bank_account =
'';
5036 $modelpath =
"core/modules/societe/doc/";
5038 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
5058 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
5061 if (!in_array($type_categ, array(Categorie::TYPE_CUSTOMER, Categorie::TYPE_SUPPLIER))) {
5062 dol_syslog(__METHOD__.
': Type '.$type_categ.
'is an unknown company category type. Done nothing.', LOG_ERR);
5066 return parent::setCategoriesCommon($categories, $type_categ);
5081 if (!is_array($salesrep)) {
5082 $salesrep = array($salesrep);
5086 $to_add = $salesrep;
5087 if ($onlyAdd ===
false) {
5092 if (is_array($existing)) {
5093 $to_del = array_diff($existing, $salesrep);
5094 $to_add = array_diff($salesrep, $existing);
5101 foreach ($to_del as $del) {
5104 foreach ($to_add as $add) {
5112 return $error ? -1 : 1;
5128 $result = $this->
setValueFrom(
'fk_typent', $typent_id,
'',
null,
'',
'', $user,
'COMPANY_MODIFY');
5131 $this->typent_id = $typent_id;
5132 $this->typent_code =
dol_getIdFromCode($this->db, $this->typent_id,
'c_typent',
'id',
'code');
5153 if ($origin_id == $dest_id) {
5154 dol_syslog(
'Error: Try to merge a thirdparty into itself');
5160 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5161 $sql .=
' WHERE fk_soc = '.(int) $dest_id.
' AND fk_user IN ( ';
5162 $sql .=
' SELECT fk_user ';
5163 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5164 $sql .=
' WHERE fk_soc = '.(int) $origin_id.
') ';
5166 $resql = $dbs->
query($sql);
5168 $dbs->
query(
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_commerciaux WHERE rowid = '.((
int) $obj->rowid));
5175 'societe_commerciaux',
5178 'societe_remise_except',
5195 global $user, $langs, $conf;
5199 if ($type ==
'buy') {
5200 $field =
'accountancy_code_buy';
5201 } elseif ($type ==
'sell') {
5202 $field =
'accountancy_code_sell';
5207 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ";
5208 $sql .= $field.
" = '".$this->db->escape($value).
"'";
5209 $sql .=
" WHERE rowid = ".((int) $this->
id);
5211 dol_syslog(get_class($this).
"::".__FUNCTION__, LOG_DEBUG);
5212 $resql = $this->db->query($sql);
5216 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
5218 $result = $interface->run_triggers(
'COMPANY_MODIFY', $this, $user, $langs, $conf);
5220 $this->errors = $interface->errors;
5221 $this->db->rollback();
5226 $this->$field = $value;
5228 $this->db->commit();
5231 $this->error = $this->db->lasterror();
5232 $this->db->rollback();
5247 require_once DOL_DOCUMENT_ROOT.
'/partnership/class/partnership.class.php';
5250 $this->partnerships[] = array();
5264 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
5266 $return =
'<div class="box-flex-item box-flex-grow-zero">';
5267 $return .=
'<div class="info-box info-box-sm">';
5268 $return .=
'<span class="info-box-icon bg-infobox-action">';
5270 $return .=
'</span>';
5271 $return .=
'<div class="info-box-content">';
5272 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
5273 if ($selected >= 0) {
5274 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
5276 if (property_exists($this,
'code_client')) {
5277 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->code_client.
'</span>';
5279 if (method_exists($this,
'getLibStatut')) {
5280 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
5282 $return .=
'</div>';
5283 $return .=
'</div>';
5284 $return .=
'</div>';
5305 $sql =
"SELECT sc.rowid, sc.fk_socpeople as id, sc.fk_c_type_contact";
5306 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
5307 $sql .=
", t.civility as civility, t.lastname as lastname, t.firstname, t.email";
5308 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_label";
5309 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact tc";
5310 $sql .=
", ".$this->db->prefix().
"societe_contacts sc";
5311 $sql .=
" LEFT JOIN ".$this->db->prefix().
"socpeople t on sc.fk_socpeople = t.rowid";
5312 $sql .=
" WHERE sc.fk_soc = ".((int) $this->
id);
5313 $sql .=
" AND sc.fk_c_type_contact = tc.rowid";
5314 if (!empty($element)) {
5315 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
5318 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
5320 $sql .=
" AND sc.entity IN (".getEntity($this->element).
")";
5321 $sql .=
" AND tc.source = 'external'";
5322 $sql .=
" AND tc.active = 1";
5324 $sql .=
" ORDER BY t.lastname ASC";
5326 dol_syslog(get_class($this).
"::getContacts", LOG_DEBUG);
5327 $resql = $this->db->query($sql);
5329 $num = $this->db->num_rows($resql);
5332 $obj = $this->db->fetch_object($resql);
5335 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
5336 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_label);
5338 'source' => $obj->source,
5339 'socid' => $obj->socid,
5341 'nom' => $obj->lastname,
5342 'civility' => $obj->civility,
5343 'lastname' => $obj->lastname,
5344 'firstname' => $obj->firstname,
5345 'email' => $obj->email,
5346 'login' => (empty($obj->login) ?
'' : $obj->login),
5347 'photo' => (empty($obj->photo) ?
'' : $obj->photo),
5348 'statuscontact' => $obj->statuscontact,
5349 'rowid' => $obj->rowid,
5350 'code' => $obj->code,
5351 'element' => $obj->element,
5352 'libelle' => $libelle_type,
5353 'status' => $obj->statuslink,
5354 'fk_c_type_contact' => $obj->fk_c_type_contact
5357 $tab[$i] = $obj->id;
5365 $this->error = $this->db->lasterror();
5383 global $conf, $langs, $hookmanager, $user, $action;
5386 $soc_origin =
new Societe($this->db);
5388 dol_syslog(
"mergeCompany merge thirdparty id=".$soc_origin_id.
" (will be deleted) into the thirdparty id=".$this->id);
5390 if (!$error && $soc_origin->fetch($soc_origin_id) < 1) {
5391 $this->error = $langs->trans(
'ErrorRecordNotFound');
5399 $this->client |= $soc_origin->client;
5400 $this->fournisseur |= $soc_origin->fournisseur;
5401 $listofproperties = array(
5402 'address',
'zip',
'town',
'state_id',
'country_id',
'phone',
'phone_mobile',
'fax',
'email',
'socialnetworks',
'url',
'barcode',
5403 'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
5404 'tva_intra',
'effectif_id',
'forme_juridique',
'remise_percent',
'remise_supplier_percent',
'mode_reglement_supplier_id',
'cond_reglement_supplier_id',
'name_bis',
5405 'stcomm_id',
'outstanding_limit',
'order_min_amount',
'supplier_order_min_amount',
'price_level',
'parent',
'default_lang',
'ref',
'ref_ext',
'import_key',
'fk_incoterms',
'fk_multicurrency',
5406 'code_client',
'code_fournisseur',
'code_compta',
'code_compta_fournisseur',
5407 'model_pdf',
'webservices_url',
'webservices_key',
'accountancy_code_sell',
'accountancy_code_buy',
'typent_id'
5409 foreach ($listofproperties as $property) {
5410 if (empty($this->$property)) {
5411 $this->$property = $soc_origin->$property;
5415 if ($this->typent_id == -1) {
5416 $this->typent_id = $soc_origin->typent_id;
5420 $listofproperties = array(
5421 'note_public',
'note_private'
5423 foreach ($listofproperties as $property) {
5424 $this->$property =
dol_concatdesc($this->$property, $soc_origin->$property);
5428 if (is_array($soc_origin->array_options)) {
5429 foreach ($soc_origin->array_options as $key => $val) {
5430 if (empty($this->array_options[$key])) {
5431 $this->array_options[$key] = $val;
5437 if (empty($this->name_bis) && $this->
name != $soc_origin->name) {
5438 $this->name_bis = $this->name;
5442 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
5445 $custcats_ori = $static_cat->containing($soc_origin->id,
'customer',
'id');
5446 $custcats = $static_cat->containing($this->
id,
'customer',
'id');
5447 $custcats = array_merge($custcats, $custcats_ori);
5450 $suppcats_ori = $static_cat->containing($soc_origin->id,
'supplier',
'id');
5451 $suppcats = $static_cat->containing($this->
id,
'supplier',
'id');
5452 $suppcats = array_merge($suppcats, $suppcats_ori);
5456 if ($soc_origin->code_client == $this->code_client
5457 || $soc_origin->code_fournisseur == $this->code_fournisseur
5458 || $soc_origin->barcode == $this->barcode) {
5459 dol_syslog(
"We clean customer and supplier code so we will be able to make the update of target");
5460 $soc_origin->code_client =
'';
5461 $soc_origin->code_fournisseur =
'';
5462 $soc_origin->barcode =
'';
5463 $soc_origin->update($soc_origin->id, $user, 0, 1, 1,
'merge');
5467 $result = $this->
update($this->
id, $user, 0, 1, 1,
'merge');
5476 'Adherent' =>
'/adherents/class/adherent.class.php',
5478 'ActionComm' =>
'/comm/action/class/actioncomm.class.php',
5479 'Propal' =>
'/comm/propal/class/propal.class.php',
5480 'Commande' =>
'/commande/class/commande.class.php',
5481 'Facture' =>
'/compta/facture/class/facture.class.php',
5482 'FactureRec' =>
'/compta/facture/class/facture-rec.class.php',
5483 'LignePrelevement' =>
'/compta/prelevement/class/ligneprelevement.class.php',
5484 'Contact' =>
'/contact/class/contact.class.php',
5485 'Contrat' =>
'/contrat/class/contrat.class.php',
5486 'Expedition' =>
'/expedition/class/expedition.class.php',
5487 'CommandeFournisseur' =>
'/fourn/class/fournisseur.commande.class.php',
5488 'FactureFournisseur' =>
'/fourn/class/fournisseur.facture.class.php',
5489 'FactureFournisseurRec' =>
'/fourn/class/fournisseur.facture-rec.class.php',
5490 'Reception' =>
'/reception/class/reception.class.php',
5491 'SupplierProposal' =>
'/supplier_proposal/class/supplier_proposal.class.php',
5492 'ProductFournisseur' =>
'/fourn/class/fournisseur.product.class.php',
5493 'Product' =>
'/product/class/product.class.php',
5495 'Project' =>
'/projet/class/project.class.php',
5496 'User' =>
'/user/class/user.class.php',
5497 'Account' =>
'/compta/bank/class/account.class.php',
5498 'ConferenceOrBoothAttendee' =>
'/eventorganization/class/conferenceorboothattendee.class.php',
5499 'Societe' =>
'/societe/class/societe.class.php',
5502 if ($this->db->DDLListTables($conf->db->name, $this->db->prefix().
'delivery')) {
5503 $objects[
'Delivery'] =
'/delivery/class/delivery.class.php';
5505 if ($this->db->DDLListTables($conf->db->name, $this->db->prefix().
'mrp_mo')) {
5506 $objects[
'Mo'] =
'/mrp/class/mo.class.php';
5508 if ($this->db->DDLListTables($conf->db->name, $this->db->prefix().
'don')) {
5509 $objects[
'Don'] =
'/don/class/don.class.php';
5511 if ($this->db->DDLListTables($conf->db->name, $this->db->prefix().
'partnership')) {
5512 $objects[
'PartnerShip'] =
'/partnership/class/partnership.class.php';
5514 if ($this->db->DDLListTables($conf->db->name, $this->db->prefix().
'fichinter')) {
5515 $objects[
'Fichinter'] =
'/fichinter/class/fichinter.class.php';
5517 if ($this->db->DDLListTables($conf->db->name, $this->db->prefix().
'ticket')) {
5518 $objects[
'Ticket'] =
'/ticket/class/ticket.class.php';
5522 foreach ($objects as $object_name => $object_file) {
5523 if (is_array($object_file)) {
5524 if (empty($object_file[
'enabled'])) {
5527 $object_file = $object_file[
'file'];
5530 require_once DOL_DOCUMENT_ROOT.$object_file;
5532 if (!$error && !$object_name::replaceThirdparty($this->db, $soc_origin->id, $this->id)) {
5534 $this->error = $this->db->lasterror();
5542 $parameters = array(
'soc_origin' => $soc_origin->id,
'soc_dest' => $this->id);
5543 $reshook = $hookmanager->executeHooks(
'replaceThirdparty', $parameters, $this, $action);
5546 $this->error = $hookmanager->error;
5547 $this->errors = $hookmanager->errors;
5554 $this->context = array(
'merge' => 1,
'mergefromid' => $soc_origin->id,
'mergefromname' => $soc_origin->name);
5557 $result = $this->
call_trigger(
'COMPANY_MODIFY', $user);
5566 if (!empty($conf->societe->multidir_output[$this->entity])) {
5567 $srcdir = $conf->societe->multidir_output[$this->entity].
"/".$soc_origin->id;
5568 $destdir = $conf->societe->multidir_output[$this->entity].
"/".$this->id;
5572 foreach ($dirlist as $filetomove) {
5573 $destfile = $destdir.
'/'.$filetomove[
'relativename'];
5575 dol_move($filetomove[
'fullname'], $destfile,
'0', 0, 0, 1);
5585 if ($soc_origin->delete($soc_origin->id, $user) < 1) {
5586 $this->error = $soc_origin->error;
5587 $this->errors = $soc_origin->errors;
5593 $this->db->commit();
5596 $langs->load(
"errors");
5597 $this->error = $langs->trans(
'ErrorsThirdpartyMerge');
5598 $this->db->rollback();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Class to manage members of a foundation.
Class to manage withdrawal receipts.
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
isObjectUsed($id=0, $entity=0)
Function to check if an object is used by others (by children).
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraLanguages($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif')
Setter generic.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage bank accounts description of third parties.
Class to stock current configuration.
Class to manage absolute discounts.
Class to manage Dolibarr database access.
Class to manage suppliers invoices.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage invoices.
Class to manage triggers.
static getIdFromCode($dbs, $code)
Get id of currency from code.
Class to manage third parties objects (customers, suppliers, prospects...)
setParent($id)
Define parent company of current company.
getLibProspLevel()
Return prostect level.
thirdparty_and_contact_email_array($addthirdparty=0)
Return list of contacts emails existing for third party.
setAsCustomer()
Define third party as a customer.
findNearest($rowid=0, $ref='', $ref_ext='', $barcode='', $idprof1='', $idprof2='', $idprof3='', $idprof4='', $idprof5='', $idprof6='', $email='', $ref_alias='', $is_client=0, $is_supplier=0)
Search the thirdparty that match the most the provided parameters.
codefournisseur_modifiable()
Check if a vendor code is editable in the code control module configuration.
contact_get_property($rowid, $mode)
Return property of contact from its id.
check_codeclient()
Check customer code.
verify()
Check properties of third party are ok (like name, third party codes, ...) Used before an add or upda...
getContacts($list=0, $code='', $element='')
Get array of all contacts for a society (stored in societe_contacts instead of element_contacts for a...
LibProspCommStatut($status, $mode=0, $label='', $picto='')
Return label of a given status.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
get_all_rib()
Return Array of RIB.
get_codecompta($type)
Assigns a accounting code from the accounting code module.
__construct($db)
Constructor.
del_commercial(User $user, $commid)
Add link to sales representative.
info($id)
Load information for tab info.
has_projects()
Indicates if the company has projects.
setThirdpartyType($typent_id)
Define third-party type of current company.
isACompany()
Check if third party is a company (Business) or an end user (Consumer)
getOutstandingBills($mode='customer', $late=0)
Return amount of bill not yet paid and total of all invoices.
add_commercial(User $user, $commid)
Add link to sales representative.
LibStatut($status, $mode=0)
Return the label of a given status.
update($id, User $user, $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0, $action='update', $nosyncmember=1)
Update parameters of third party.
const PROSPECT
Third party type is a prospect.
create(User $user, $notrigger=0)
Create third party in database.
set_as_client()
Define third party as a customer.
getOutstandingOrders($mode='customer')
Return amount of order not yet paid and total and list of all orders.
id_prof_exists($idprof, $value, $socid=0)
Verify if a profid exists into database for others thirds.
setCategories($categories, $type_categ)
Sets object to supplied categories.
useRevenueStamp()
Check if we must use revenue stamps feature or not according to country (country of $mysocin most cas...
setNoEmail($no_email)
Set "blacklist" mailing status.
id_prof_verifiable($idprof)
Returns if a profid should be verified to be unique.
create_from_member(Adherent $member, $socname='', $socalias='', $customercode='')
Create a third party into database from a member object.
getParentsForCompany($company_id, $parents=array())
Get parents for company.
set_remise_except($remise, User $user, $desc, $vatrate='', $discount_type=0, $price_base_type='HT')
Add a discount for third party.
const CUSTOMER_AND_PROSPECT
Third party type is a customer and a prospect.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
set_remise_client($remise, $note, User $user)
Defines the company as a customer.
getOutstandingProposals($mode='customer')
Return amount of proposal not yet paid and total an dlist of all proposals.
const CUSTOMER
Third party type is a customer.
fetch($rowid, $ref='', $ref_ext='', $barcode='', $idprof1='', $idprof2='', $idprof3='', $idprof4='', $idprof5='', $idprof6='', $email='', $ref_alias='', $is_client=0, $is_supplier=0)
Load a third party from database into memory.
getSalesRepresentatives(User $user, $mode=0, $sortfield=null, $sortorder=null)
Return array of sales representatives.
LoadSupplierCateg()
Load the list of provider categories.
getAvailableDiscounts($user=null, $filter='', $maxvalue=0, $discount_type=0)
Returns amount of included taxes of the current discounts/credits available from the company.
display_rib($mode='label')
Return bank number property of thirdparty (label or rum)
contact_array_objects()
Returns the contact list of this company.
isInEEC()
Return if a company is inside the EEC (European Economic Community)
codeclient_modifiable()
Check if a client code is editable based on the parameters of the code control module.
fetchPartnerships($mode)
Function to get partnerships array.
validateFamilyTree($idparent, $idchild, $counter=0)
Check if a thirdparty $idchild is or not inside the parents (or grand parents) of another thirdparty ...
mergeCompany($soc_origin_id)
Merge a company with current one, deleting the given company $soc_origin_id.
const NO_SUPPLIER
Third party supplier flag is not supplier.
getNbOfEMailings()
Return number of mass Emailing received by this contacts with its email.
setAccountancyCode($type, $value)
Sets an accountancy code for a thirdparty.
getLibCustProspStatut()
Return label of status customer is prospect/customer.
getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0, $save_lastsearch_value=-1, $noaliasinname=0, $target='', $morecss='')
Return a link on thirdparty (with picto)
getLibStatut($mode=0)
Return label of status (activity, closed)
const NO_CUSTOMER
Third party type is no customer.
LibProspLevel($fk_prospectlevel)
Return label of prospect level.
set_remise_supplier($remise, $note, User $user)
Defines the company as a customer.
useLocalTax($localTaxNum=0)
Check if we must use localtax feature or not according to country (country of $mysoc in most cases).
create_individual(User $user, $no_email=0, $tags=array(), $notrigger=0)
Create a contact/address from thirdparty.
getNoEmail()
get "blacklist" mailing status set no_email attribute to 1 or 0
getLibProspCommStatut($mode=0, $label='')
Return status of prospect.
AddFournisseurInCategory($categorie_id)
Insert link supplier - category.
contact_property_array($mode='email', $hidedisabled=0)
Return list of contacts emails or mobile existing for third party.
LibCustProspStatut($status)
Return the label of the customer/prospect status.
id_prof_check($idprof, $soc)
Check the validity of a professional identifier according to the country of the company (siren,...
getTypeUrl($withpicto=0, $option='', $notooltip=0, $tag='a')
Return link(s) on type of thirdparty (with picto)
setPriceLevel($price_level, User $user)
Set the price level.
thirdparty_and_contact_phone_array()
Return list of contacts mobile phone existing for third party.
getTooltipContentArray($params)
getTooltipContentArray
useNPR()
Check if we must use NPR Vat (french stupid rule) or not according to country (country of $mysoc in m...
setSalesRep($salesrep, $onlyAdd=false)
Sets sales representatives of the thirdparty.
getKanbanView($option='', $arraydata=array())
Return clicable link of object (with eventually picto)
const SUPPLIER
Third party supplier flag is a supplier.
check_codefournisseur()
Check supplier code.
contact_array()
Returns the contact list of this company.
initAsSpecimen()
Initialise an instance with random values.
id_prof_url($idprof, $thirdparty)
Return an url to check online a professional id or empty string.
setMysoc(Conf $conf)
Set properties with value into $conf.
Class to manage Dolibarr users.
trait CommonIncoterm
Superclass for incoterm classes.
trait CommonPeople
Support class for thirdparties, contacts, members, users or resources.
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
trait CommonSocialNetworks
Superclass for social networks.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
getState($id, $withcode='0', $dbtouse=null, $withregion=0, $outputlangs=null, $entconv=1)
Return state translated from an id.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array())
Move a file into another name.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
clean_url($url, $http=1)
Clean an url string.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='')
Format phone numbers according to country.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs=null, $mode=0, $extralangcode='')
Return a formatted address (part address/zip/town/state) according to country rules.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
img_action($titlealt, $numaction, $picto='', $moreatt='')
Show logo action.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
query($query, $usesavepoint=0, $type='auto', $result_mode=0)
Execute a SQL request and return the resultset.
fetch_object($resultset)
Returns the current line (as an object) for the resultset cursor.
isValidSiren($siren)
Check the syntax validity of a SIREN.
isValidTinForPT($str)
Check the syntax validity of a Portuguese (PT) Tax Identification Number (TIN).
isValidSiret($siret)
Check the syntax validity of a SIRET.
isValidTinForES($str)
Check the syntax validity of a Spanish (ES) Tax Identification Number (TIN), where:
isValidTinForBE($str)
Check the syntax validity of a Belgium (BE) Tax Identification Number (TIN).
isValidTinForDZ($str)
Check the syntax validity of an Algerian (DZ) Tax Identification Number (TIN).
$conf db name
Only used if Module[ID]Name translation string is not found.