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;
140 public $SupplierCategories = array();
146 public $prefixCustomerIsRequired;
177 public $fields = array(
178 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'noteditable' => 1,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id',
'css' =>
'left'),
179 'parent' => array(
'type' =>
'integer',
'label' =>
'Parent',
'enabled' => 1,
'visible' => -1,
'position' => 20),
180 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 25),
181 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 30),
182 'nom' => array(
'type' =>
'varchar(128)',
'length' => 128,
'label' =>
'Nom',
'enabled' => 1,
'visible' => -1,
'position' => 35,
'showoncombobox' => 1,
'csslist' =>
'tdoverflowmax150'),
183 'name_alias' => array(
'type' =>
'varchar(128)',
'label' =>
'Name alias',
'enabled' => 1,
'visible' => -1,
'position' => 36,
'showoncombobox' => 2),
184 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 40,
'index' => 1),
185 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 45),
186 'code_client' => array(
'type' =>
'varchar(24)',
'label' =>
'CustomerCode',
'enabled' => 1,
'visible' => -1,
'position' => 55),
187 'code_fournisseur' => array(
'type' =>
'varchar(24)',
'label' =>
'SupplierCode',
'enabled' => 1,
'visible' => -1,
'position' => 60),
188 'code_compta' => array(
'type' =>
'varchar(24)',
'label' =>
'CustomerAccountancyCode',
'enabled' => 1,
'visible' => -1,
'position' => 65),
189 'code_compta_fournisseur' => array(
'type' =>
'varchar(24)',
'label' =>
'SupplierAccountancyCode',
'enabled' => 1,
'visible' => -1,
'position' => 70),
190 'address' => array(
'type' =>
'varchar(255)',
'label' =>
'Address',
'enabled' => 1,
'visible' => -1,
'position' => 75),
191 'zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Zip',
'enabled' => 1,
'visible' => -1,
'position' => 80),
192 'town' => array(
'type' =>
'varchar(50)',
'label' =>
'Town',
'enabled' => 1,
'visible' => -1,
'position' => 85),
193 'fk_departement' => array(
'type' =>
'integer',
'label' =>
'State',
'enabled' => 1,
'visible' => -1,
'position' => 90),
194 'fk_pays' => array(
'type' =>
'integer:Ccountry:core/class/ccountry.class.php',
'label' =>
'Country',
'enabled' => 1,
'visible' => -1,
'position' => 95),
195 'phone' => array(
'type' =>
'varchar(20)',
'label' =>
'Phone',
'enabled' => 1,
'visible' => -1,
'position' => 100),
196 'phone_mobile' => array(
'type' =>
'varchar(20)',
'label' =>
'PhoneMobile',
'enabled' => 1,
'visible' => -1,
'position' => 102),
197 'fax' => array(
'type' =>
'varchar(20)',
'label' =>
'Fax',
'enabled' => 1,
'visible' => -1,
'position' => 105),
198 'url' => array(
'type' =>
'varchar(255)',
'label' =>
'Url',
'enabled' => 1,
'visible' => -1,
'position' => 110),
199 'email' => array(
'type' =>
'varchar(128)',
'label' =>
'Email',
'enabled' => 1,
'visible' => -1,
'position' => 115),
200 'socialnetworks' => array(
'type' =>
'text',
'label' =>
'Socialnetworks',
'enabled' => 1,
'visible' => -1,
'position' => 120),
201 'fk_effectif' => array(
'type' =>
'integer',
'label' =>
'Workforce',
'enabled' => 1,
'visible' => -1,
'position' => 170),
202 'fk_typent' => array(
'type' =>
'integer',
'label' =>
'TypeOfCompany',
'enabled' => 1,
'visible' => -1,
'position' => 175,
'csslist' =>
'minwidth200'),
203 'fk_forme_juridique' => array(
'type' =>
'integer',
'label' =>
'JuridicalStatus',
'enabled' => 1,
'visible' => -1,
'position' => 180),
204 'fk_currency' => array(
'type' =>
'varchar(3)',
'label' =>
'Currency',
'enabled' => 1,
'visible' => -1,
'position' => 185),
205 'siren' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof1',
'enabled' => 1,
'visible' => -1,
'position' => 190),
206 'siret' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof2',
'enabled' => 1,
'visible' => -1,
'position' => 195),
207 'ape' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof3',
'enabled' => 1,
'visible' => -1,
'position' => 200),
208 'idprof4' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof4',
'enabled' => 1,
'visible' => -1,
'position' => 205),
209 'idprof5' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof5',
'enabled' => 1,
'visible' => -1,
'position' => 206),
210 'idprof6' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof6',
'enabled' => 1,
'visible' => -1,
'position' => 207),
211 'tva_intra' => array(
'type' =>
'varchar(20)',
'label' =>
'Tva intra',
'enabled' => 1,
'visible' => -1,
'position' => 210),
212 'capital' => array(
'type' =>
'double(24,8)',
'label' =>
'Capital',
'enabled' => 1,
'visible' => -1,
'position' => 215),
213 'fk_stcomm' => array(
'type' =>
'integer',
'label' =>
'CommercialStatus',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 220),
214 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 225),
215 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 230),
216 'prefix_comm' => array(
'type' =>
'varchar(5)',
'label' =>
'Prefix comm',
'enabled' =>
"getDolGlobalInt('SOCIETE_USEPREFIX')",
'visible' => -1,
'position' => 235),
217 'client' => array(
'type' =>
'tinyint(4)',
'label' =>
'Client',
'enabled' => 1,
'visible' => -1,
'position' => 240),
218 'fournisseur' => array(
'type' =>
'tinyint(4)',
'label' =>
'Fournisseur',
'enabled' => 1,
'visible' => -1,
'position' => 245),
219 'supplier_account' => array(
'type' =>
'varchar(32)',
'label' =>
'Supplier account',
'enabled' => 1,
'visible' => -1,
'position' => 250),
220 'fk_prospectlevel' => array(
'type' =>
'varchar(12)',
'label' =>
'ProspectLevel',
'enabled' => 1,
'visible' => -1,
'position' => 255),
221 'customer_bad' => array(
'type' =>
'tinyint(4)',
'label' =>
'Customer bad',
'enabled' => 1,
'visible' => -1,
'position' => 260),
222 'customer_rate' => array(
'type' =>
'double',
'label' =>
'Customer rate',
'enabled' => 1,
'visible' => -1,
'position' => 265),
223 'supplier_rate' => array(
'type' =>
'double',
'label' =>
'Supplier rate',
'enabled' => 1,
'visible' => -1,
'position' => 270),
224 'fk_user_creat' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -2,
'position' => 275),
225 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 280),
228 'mode_reglement' => array(
'type' =>
'tinyint(4)',
'label' =>
'Mode reglement',
'enabled' => 1,
'visible' => -1,
'position' => 295),
229 'cond_reglement' => array(
'type' =>
'tinyint(4)',
'label' =>
'Cond reglement',
'enabled' => 1,
'visible' => -1,
'position' => 300),
230 'deposit_percent' => array(
'type' =>
'varchar(63)',
'label' =>
'DepositPercent',
'enabled' => 1,
'visible' => -1,
'position' => 301),
231 'mode_reglement_supplier' => array(
'type' =>
'integer',
'label' =>
'Mode reglement supplier',
'enabled' => 1,
'visible' => -1,
'position' => 305),
232 'cond_reglement_supplier' => array(
'type' =>
'integer',
'label' =>
'Cond reglement supplier',
'enabled' => 1,
'visible' => -1,
'position' => 308),
233 'outstanding_limit' => array(
'type' =>
'double(24,8)',
'label' =>
'OutstandingBill',
'enabled' => 1,
'visible' => -1,
'position' => 310,
'isameasure' => 1),
234 '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),
235 '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),
236 'fk_shipping_method' => array(
'type' =>
'integer',
'label' =>
'Fk shipping method',
'enabled' => 1,
'visible' => -1,
'position' => 330),
237 'tva_assuj' => array(
'type' =>
'tinyint(4)',
'label' =>
'Tva assuj',
'enabled' => 1,
'visible' => -1,
'position' => 335),
238 'localtax1_assuj' => array(
'type' =>
'tinyint(4)',
'label' =>
'Localtax1 assuj',
'enabled' => 1,
'visible' => -1,
'position' => 340),
239 'localtax1_value' => array(
'type' =>
'double(6,3)',
'label' =>
'Localtax1 value',
'enabled' => 1,
'visible' => -1,
'position' => 345),
240 'localtax2_assuj' => array(
'type' =>
'tinyint(4)',
'label' =>
'Localtax2 assuj',
'enabled' => 1,
'visible' => -1,
'position' => 350),
241 'localtax2_value' => array(
'type' =>
'double(6,3)',
'label' =>
'Localtax2 value',
'enabled' => 1,
'visible' => -1,
'position' => 355),
242 'vat_reverse_charge' => array(
'type' =>
'tinyint(4)',
'label' =>
'Vat reverse charge',
'enabled' => 1,
'visible' => -1,
'position' => 335),
243 'barcode' => array(
'type' =>
'varchar(255)',
'label' =>
'Barcode',
'enabled' => 1,
'visible' => -1,
'position' => 360),
244 'price_level' => array(
'type' =>
'integer',
'label' =>
'Price level',
'enabled' =>
'$conf->global->PRODUIT_MULTIPRICES || getDolGlobalString("PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES") || getDolGlobalString("PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES")',
'visible' => -1,
'position' => 365),
245 'default_lang' => array(
'type' =>
'varchar(6)',
'label' =>
'Default lang',
'enabled' => 1,
'visible' => -1,
'position' => 370),
246 'canvas' => array(
'type' =>
'varchar(32)',
'label' =>
'Canvas',
'enabled' => 1,
'visible' => -1,
'position' => 375),
247 'fk_barcode_type' => array(
'type' =>
'integer',
'label' =>
'Fk barcode type',
'enabled' => 1,
'visible' => -1,
'position' => 405),
248 'webservices_url' => array(
'type' =>
'varchar(255)',
'label' =>
'Webservices url',
'enabled' => 1,
'visible' => -1,
'position' => 410),
249 'webservices_key' => array(
'type' =>
'varchar(128)',
'label' =>
'Webservices key',
'enabled' => 1,
'visible' => -1,
'position' => 415),
250 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'Fk incoterms',
'enabled' => 1,
'visible' => -1,
'position' => 425),
251 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'Location incoterms',
'enabled' => 1,
'visible' => -1,
'position' => 430),
252 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 435),
253 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -1,
'position' => 270),
254 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Fk multicurrency',
'enabled' => 1,
'visible' => -1,
'position' => 440),
255 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Multicurrency code',
'enabled' => 1,
'visible' => -1,
'position' => 445),
256 'fk_account' => array(
'type' =>
'integer',
'label' =>
'PaymentBankAccount',
'enabled' => 1,
'visible' => -1,
'position' => 450),
257 'fk_warehouse' => array(
'type' =>
'integer',
'label' =>
'Warehouse',
'enabled' => 1,
'visible' => -1,
'position' => 455),
258 'logo' => array(
'type' =>
'varchar(255)',
'label' =>
'Logo',
'enabled' => 1,
'visible' => -1,
'position' => 400),
259 'logo_squarred' => array(
'type' =>
'varchar(255)',
'label' =>
'Logo squarred',
'enabled' => 1,
'visible' => -1,
'position' => 401),
260 'status' => array(
'type' =>
'tinyint(4)',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'position' => 500),
261 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 1000),
319 public $departement_code;
344 public $phone_mobile;
491 public $socialobject;
501 public $tva_assuj = 1;
511 public $vat_reverse_charge = 0;
517 public $localtax1_assuj;
521 public $localtax1_value;
525 public $localtax2_assuj;
529 public $localtax2_value;
544 public $typent_id = 0;
556 public $effectif_id = 0;
560 public $forme_juridique_code = 0;
565 public $forme_juridique;
570 public $remise_percent;
574 public $remise_supplier_percent;
579 public $mode_reglement_id;
583 public $cond_reglement_id;
587 public $deposit_percent;
591 public $mode_reglement_supplier_id;
595 public $cond_reglement_supplier_id;
599 public $transport_mode_supplier_id;
604 public $fk_prospectlevel;
616 public $user_modification;
623 public $user_creation;
635 public $prospect = 0;
653 public $code_fournisseur;
659 public $code_compta_client;
665 public $accountancy_code_customer_general;
671 public $accountancy_code_customer;
677 public $code_compta_fournisseur;
683 public $accountancy_code_supplier_general;
689 public $accountancy_code_supplier;
695 public $code_compta_product;
708 public $note_private;
726 public $stcomm_picto;
732 public $status_prospect_label;
743 public $outstanding_limit;
748 public $order_min_amount;
753 public $supplier_order_min_amount;
759 public $commercial_id;
771 public $default_lang;
802 public $webservices_url;
808 public $webservices_key;
828 public $logo_squarred;
833 public $logo_squarred_small;
838 public $logo_squarred_mini;
843 public $accountancy_code_sell;
848 public $accountancy_code_buy;
854 public $fk_multicurrency;
859 public $multicurrency_code;
865 public $fk_warehouse;
878 public $partnerships = array();
884 public $bank_account;
887 const STATUS_CEASED = 0;
888 const STATUS_INACTIVITY = 1;
929 'code_compta' =>
'code_compta_client',
931 + parent::deprecatedProperties();
945 $this->ismultientitymanaged = 1;
946 $this->isextrafieldmanaged = 1;
949 $this->fournisseur = 0;
950 $this->typent_id = 0;
951 $this->effectif_id = 0;
952 $this->forme_juridique_code = 0;
953 $this->tva_assuj = 1;
954 $this->vat_reverse_charge = 0;
958 $this->fields[
'address'][
'showoncombobox'] =
getDolGlobalInt(
'COMPANY_SHOW_ADDRESS_SELECTLIST');
959 $this->fields[
'zip'][
'showoncombobox'] =
getDolGlobalInt(
'COMPANY_SHOW_ADDRESS_SELECTLIST');
960 $this->fields[
'town'][
'showoncombobox'] =
getDolGlobalInt(
'COMPANY_SHOW_ADDRESS_SELECTLIST');
976 global $langs,
$conf;
981 if (empty($this->
status)) {
984 $this->
name = $this->
name ? trim($this->
name) : trim((
string) $this->nom);
986 $this->nom = $this->name;
988 if (empty($this->client)) {
991 if (empty($this->fournisseur)) {
992 $this->fournisseur = 0;
994 $this->import_key = trim((
string) $this->import_key);
996 $this->code_compta_client = trim($this->code_compta_client);
998 $this->accountancy_code_customer_general = trim($this->accountancy_code_customer_general);
999 $this->accountancy_code_customer = trim((
string) $this->code_compta_client);
1000 $this->accountancy_code_supplier_general = trim($this->accountancy_code_supplier_general);
1001 $this->accountancy_code_supplier = trim((
string) $this->code_compta_fournisseur);
1002 $this->accountancy_code_buy = trim((
string) $this->accountancy_code_buy);
1003 $this->accountancy_code_sell = trim((
string) $this->accountancy_code_sell);
1005 if (!empty($this->multicurrency_code)) {
1008 if (empty($this->fk_multicurrency)) {
1009 $this->multicurrency_code =
'';
1010 $this->fk_multicurrency = 0;
1013 if (empty($this->country_id) && !empty($this->country_code)) {
1014 $country_id =
getCountry($this->country_code,
'3');
1015 $this->country_id = is_int($country_id) ? $country_id : 0;
1022 if (empty($this->date_creation)) {
1023 $this->date_creation = $now;
1029 if ($this->code_client == -1 || $this->code_client ===
'auto') {
1030 $this->get_codeclient($this, 0);
1032 if ($this->code_fournisseur ==
'-1' || $this->code_fournisseur ===
'auto') {
1033 $this->get_codefournisseur($this, 1);
1038 $result = $this->
verify();
1043 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe (";
1045 $sql .=
", name_alias";
1048 $sql .=
", fk_user_creat";
1049 $sql .=
", fk_typent";
1052 $sql .=
", ref_ext";
1053 $sql .=
", fk_stcomm";
1054 $sql .=
", fk_incoterms";
1055 $sql .=
", location_incoterms";
1056 $sql .=
", import_key";
1057 $sql .=
", fk_multicurrency";
1058 $sql .=
", multicurrency_code";
1061 $sql .=
", vat_reverse_charge";
1062 $sql .=
", accountancy_code_buy";
1063 $sql .=
", accountancy_code_sell";
1065 $sql .=
") VALUES ('".$this->db->escape($this->name).
"',";
1066 $sql .=
" '".$this->db->escape($this->name_alias).
"',";
1067 $sql .=
" ".((int) $this->entity).
",";
1068 $sql .=
" '".$this->db->idate($this->date_creation).
"'";
1069 $sql .=
", ".(!empty($user->id) ? ((int) $user->id) :
"null");
1070 $sql .=
", ".(!empty($this->typent_id) ? ((int) $this->typent_id) :
"null");
1071 $sql .=
", ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null");
1072 $sql .=
", ".((int) $this->
status);
1073 $sql .=
", ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1075 $sql .=
", ".(int) $this->fk_incoterms;
1076 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1077 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1078 $sql .=
", ".(int) $this->fk_multicurrency;
1079 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1080 $sql .=
", '".$this->db->escape($this->ip).
"'";
1082 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1083 $sql .=
", '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1084 $sql .=
", '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1088 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1090 $result = $this->db->query($sql);
1092 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"societe");
1094 $ret = $this->
update($this->
id, $user, 0, 1, 1,
'add');
1098 $this->db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int)
$conf->entity));
1100 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
1103 $sql .=
", vat_reverse_charge";
1104 $sql .=
", accountancy_code_customer_general";
1105 $sql .=
", accountancy_code_customer";
1106 $sql .=
", accountancy_code_supplier_general";
1107 $sql .=
", accountancy_code_supplier";
1108 $sql .=
", accountancy_code_buy";
1109 $sql .=
", accountancy_code_sell";
1110 $sql .=
") VALUES (";
1112 $sql .=
", ".((int)
$conf->entity);
1113 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1114 $sql .=
", '".$this->db->escape($this->accountancy_code_customer_general).
"'";
1115 $sql .=
", '".$this->db->escape($this->accountancy_code_customer).
"'";
1116 $sql .=
", '".$this->db->escape($this->accountancy_code_supplier_general).
"'";
1117 $sql .=
", '".$this->db->escape($this->accountancy_code_supplier).
"'";
1118 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1119 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1121 $result = $this->db->query($sql);
1124 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1129 if ($this->commercial_id !=
'' && $this->commercial_id != -1) {
1131 } elseif (!$user->hasRight(
'societe',
'client',
'voir')) {
1139 $result = $this->
call_trigger(
'COMPANY_CREATE', $user);
1150 dol_syslog(get_class($this).
"::Create success id=".$this->
id);
1151 $this->db->commit();
1154 dol_syslog(get_class($this).
"::Create echec update ".$this->error.(empty($this->errors) ?
'' :
' '.implode(
',', $this->errors)), LOG_ERR);
1155 $this->db->rollback();
1159 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1160 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", $this->name);
1163 $this->error = $this->db->lasterror();
1166 $this->db->rollback();
1170 $this->db->rollback();
1171 dol_syslog(get_class($this).
"::Create fails verify ".implode(
',', $this->errors), LOG_WARNING);
1196 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1197 $contact =
new Contact($this->db);
1199 $contact->name = $this->name_bis;
1200 $contact->firstname = $this->firstname;
1201 $contact->civility_id = $this->civility_id;
1202 $contact->socid = $this->id;
1203 $contact->statut = 1;
1204 $contact->status = 1;
1206 $contact->country_id = $this->country_id;
1207 $contact->state_id = $this->state_id;
1208 $contact->address = $this->address;
1209 $contact->email = $this->email;
1210 $contact->zip = $this->zip;
1211 $contact->town = $this->town;
1213 $contact->phone_pro = $this->phone;
1218 $contactId = $contact->create($user, $notrigger);
1219 if ($contactId < 0) {
1222 dol_syslog(get_class($this).
"::create_individual ERROR:".$this->error, LOG_ERR);
1225 if (empty($error) && is_array($tags) && !empty($tags)) {
1226 $result = $contact->setCategories($tags);
1230 dol_syslog(get_class($this).
"::create_individual Affect Tag ERROR:".$this->error, LOG_ERR);
1231 $contactId = $result;
1235 if (empty($error) && isModEnabled(
'mailing') && !empty($contact->email) && isset($no_email)) {
1236 $result = $contact->setNoEmail($no_email);
1239 dol_syslog(get_class($this).
"::create_individual set mailing status ERROR:".$this->error, LOG_ERR);
1240 $contactId = $result;
1244 if (empty($error)) {
1245 dol_syslog(get_class($this).
"::create_individual success");
1246 $this->db->commit();
1248 $this->db->rollback();
1262 global
$conf, $langs, $mysoc;
1265 $this->errors = array();
1269 $this->nom = $this->name;
1272 $this->errors[] =
'ErrorBadThirdPartyName';
1276 if ($this->client) {
1278 if ($rescode != 0 && $rescode != -5) {
1279 if ($rescode == -1) {
1280 $this->errors[] =
'ErrorBadCustomerCodeSyntax';
1281 } elseif ($rescode == -2) {
1282 $this->errors[] =
'ErrorCustomerCodeRequired';
1283 } elseif ($rescode == -3) {
1284 $this->errors[] =
'ErrorCustomerCodeAlreadyUsed';
1285 } elseif ($rescode == -4) {
1286 $this->errors[] =
'ErrorPrefixRequired';
1288 $this->errors[] =
'ErrorUnknownOnCustomerCodeCheck';
1295 if ($this->fournisseur) {
1297 if ($rescode != 0 && $rescode != -5) {
1298 if ($rescode == -1) {
1299 $this->errors[] =
'ErrorBadSupplierCodeSyntax';
1300 } elseif ($rescode == -2) {
1301 $this->errors[] =
'ErrorSupplierCodeRequired';
1302 } elseif ($rescode == -3) {
1303 $this->errors[] =
'ErrorSupplierCodeAlreadyUsed';
1304 } elseif ($rescode == -4) {
1305 $this->errors[] =
'ErrorPrefixRequired';
1307 $this->errors[] =
'ErrorUnknownOnSupplierCodeCheck';
1314 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL',
'TVA_INTRA',
'ACCOUNTANCY_CODE_CUSTOMER',
'ACCOUNTANCY_CODE_SUPPLIER');
1315 foreach ($array_to_check as $key) {
1316 $keymin = strtolower($key);
1317 $keyfield_db = $keymin;
1318 if ($key ==
'ACCOUNTANCY_CODE_CUSTOMER') {
1319 $keymin =
'code_compta_client';
1320 $keyfield_db =
'code_compta';
1321 } elseif ($key ==
'ACCOUNTANCY_CODE_SUPPLIER') {
1322 $keymin =
'code_compta_fournisseur';
1323 $keyfield_db =
'code_compta_fournisseur';
1325 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
1326 $vallabel = $this->$keymin;
1331 if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) {
1332 $idprof_mandatory =
'SOCIETE_'.$key.
'_MANDATORY';
1334 $langs->load(
"errors");
1336 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->transcountry(
'ProfId'.$i, $this->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1343 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1344 $langs->load(
"errors");
1346 $this->errors[] = $langs->transcountry(
'ProfId'.$i, $this->country_code).
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1352 if ($key ==
'EMAIL') {
1355 $langs->load(
"errors");
1357 $this->errors[] = $langs->trans(
"ErrorBadEMail", $this->
email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1362 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1363 $langs->load(
"errors");
1365 $this->errors[] = $langs->trans(
'Email').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1368 } elseif ($key ==
'TVA_INTRA') {
1371 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1372 $langs->load(
"errors");
1374 $this->errors[] = $langs->trans(
'VATIntra').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1377 if ($this->tva_assuj && !$vallabel &&
getDolGlobalString(
'SOCIETE_VAT_INTRA_MANDATORY')) {
1378 $langs->load(
"errors");
1380 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->trans(
'VATIntra')).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1382 } elseif ($key ==
'ACCOUNTANCY_CODE_CUSTOMER' && !empty($this->client)) {
1385 if ($this->
id_prof_exists($keyfield_db, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1386 $langs->loadLangs(array(
"errors",
'compta'));
1388 $this->errors[] = $langs->trans(
'CustomerAccountancyCodeShort') .
" " . $langs->trans(
"ErrorProdIdAlreadyExist", $vallabel) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1393 if (
getDolGlobalString(
'SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_MANDATORY') && (!isset($vallabel) || trim($vallabel) ===
'')) {
1394 $langs->loadLangs(array(
"errors",
'compta'));
1396 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
'CustomerAccountancyCodeShort')) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1398 } elseif ($key ==
'ACCOUNTANCY_CODE_SUPPLIER' && !empty($this->fournisseur)) {
1401 if ($this->
id_prof_exists($keyfield_db, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1402 $langs->loadLangs(array(
"errors",
'compta'));
1404 $this->errors[] = $langs->trans(
'SupplierAccountancyCodeShort') .
" " . $langs->trans(
"ErrorProdIdAlreadyExist", $vallabel) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1409 if (
getDolGlobalString(
'SOCIETE_ACCOUNTANCY_CODE_SUPPLIER_MANDATORY') && (!isset($vallabel) || trim($vallabel) ===
'')) {
1410 $langs->loadLangs(array(
"errors",
'compta'));
1412 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
'SupplierAccountancyCodeShort')) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1437 public function update($id,
User $user, $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action =
'update', $nosyncmember = 1)
1439 global $langs,
$conf, $hookmanager;
1441 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1446 if (empty($this->country_id) && !empty($this->country_code)) {
1447 $this->country_id =
dol_getIdFromCode($this->db, $this->country_code,
'c_country',
'code',
'rowid');
1452 dol_syslog(get_class($this).
"::Update id=".$id.
" call_trigger=".$call_trigger.
" allowmodcodeclient=".$allowmodcodeclient.
" allowmodcodefournisseur=".$allowmodcodefournisseur);
1458 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity :
$conf->entity);
1459 $this->
name = $this->
name ? trim($this->
name) : trim((
string) $this->nom);
1460 $this->nom = $this->name;
1461 $this->name_alias = trim((
string) $this->name_alias);
1462 $this->ref_ext = (empty($this->ref_ext) ?
'' : trim($this->ref_ext));
1464 $this->zip = trim((
string) $this->zip);
1465 $this->town = trim((
string) $this->town);
1466 $this->state_id = (is_numeric($this->state_id)) ? (
int) $this->state_id : 0;
1467 $this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
1468 $this->phone = trim((
string) $this->phone);
1469 $this->phone = preg_replace(
"/\s/",
"", $this->phone);
1470 $this->phone = preg_replace(
"/\./",
"", $this->phone);
1471 $this->phone_mobile = trim((
string) $this->phone_mobile);
1472 $this->phone_mobile = preg_replace(
"/\s/",
"", $this->phone_mobile);
1473 $this->phone_mobile = preg_replace(
"/\./",
"", $this->phone_mobile);
1474 $this->fax = trim((
string) $this->fax);
1475 $this->fax = preg_replace(
"/\s/",
"", $this->fax);
1476 $this->fax = preg_replace(
"/\./",
"", $this->fax);
1478 $this->url = $this->url ?
clean_url($this->url, 0) :
'';
1479 $this->note_private = (empty($this->note_private) ?
'' : trim($this->note_private));
1480 $this->note_public = (empty($this->note_public) ?
'' : trim($this->note_public));
1481 $this->idprof1 = trim((
string) $this->idprof1);
1482 $this->idprof2 = trim((
string) $this->idprof2);
1483 $this->idprof3 = trim((
string) $this->idprof3);
1484 $this->idprof4 = trim((
string) $this->idprof4);
1485 $this->idprof5 = (!empty($this->idprof5) ? trim($this->idprof5) :
'');
1486 $this->idprof6 = (!empty($this->idprof6) ? trim($this->idprof6) :
'');
1487 $this->prefix_comm = trim((
string) $this->prefix_comm);
1488 $this->outstanding_limit =
price2num($this->outstanding_limit);
1489 $this->order_min_amount =
price2num($this->order_min_amount);
1490 $this->supplier_order_min_amount =
price2num($this->supplier_order_min_amount);
1492 $this->tva_assuj = (is_numeric($this->tva_assuj)) ? (
int) trim((
string) $this->tva_assuj) : 0;
1493 $this->tva_intra = trim($this->tva_intra);
1494 $this->vat_reverse_charge = empty($this->vat_reverse_charge) ? 0 : 1;
1495 if (empty($this->
status)) {
1499 if (!empty($this->multicurrency_code)) {
1502 if (empty($this->fk_multicurrency)) {
1503 $this->multicurrency_code =
'';
1504 $this->fk_multicurrency = 0;
1508 $this->localtax1_assuj = (int) trim((
string) $this->localtax1_assuj);
1509 $this->localtax2_assuj = (int) trim((
string) $this->localtax2_assuj);
1511 $this->localtax1_value = trim($this->localtax1_value);
1512 $this->localtax2_value = trim($this->localtax2_value);
1514 $this->capital = ($this->capital !=
'') ? (
float)
price2num(trim((
string) $this->capital)) :
null;
1516 $this->effectif_id = (int) $this->effectif_id;
1517 $this->forme_juridique_code = (int) $this->forme_juridique_code;
1520 $this->barcode = trim((
string) $this->barcode);
1523 if ($this->code_client == -1 || $this->code_client ===
'auto') {
1524 $this->get_codeclient($this, 0);
1526 if ($this->code_fournisseur ==
'-1' || $this->code_fournisseur ===
'auto') {
1527 $this->get_codefournisseur($this, 1);
1530 $this->accountancy_code_customer_general = trim((
string) $this->accountancy_code_customer_general);
1531 $this->code_compta_client = trim((
string) $this->code_compta_client);
1532 $this->accountancy_code_supplier_general = trim((
string) $this->accountancy_code_supplier_general);
1533 $this->code_compta_fournisseur = trim((
string) $this->code_compta_fournisseur);
1536 if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) {
1537 $langs->load(
"errors");
1538 $this->error = $langs->trans(
"BadValueForParameterClientOrSupplier");
1543 if (!empty($allowmodcodeclient) && !empty($this->client)) {
1545 if (empty($this->code_compta_client)) {
1556 if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) {
1558 if (empty($this->code_compta_fournisseur)) {
1569 $this->webservices_url = empty($this->webservices_url) ?
'' :
clean_url($this->webservices_url, 0);
1570 $this->webservices_key = trim((
string) $this->webservices_key);
1572 $this->accountancy_code_buy = (empty($this->accountancy_code_buy) ?
'' : trim($this->accountancy_code_buy));
1573 $this->accountancy_code_sell = (empty($this->accountancy_code_sell) ?
'' : trim($this->accountancy_code_sell));
1576 $this->fk_incoterms = (int) $this->fk_incoterms;
1577 $this->location_incoterms = trim((
string) $this->location_incoterms);
1584 if ($action !=
'add' && $action !=
'merge') {
1587 $result = $this->
verify();
1591 if (is_array($this->errors)) {
1592 if (in_array(
'ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) {
1593 if (($key = array_search(
'ErrorBadCustomerCodeSyntax', $this->errors)) !==
false) {
1594 unset($this->errors[$key]);
1597 if (in_array(
'ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) {
1598 if (($key = array_search(
'ErrorBadSupplierCodeSyntax', $this->errors)) !==
false) {
1599 unset($this->errors[$key]);
1602 if (empty($this->errors)) {
1609 dol_syslog(get_class($this).
"::update verify ok or not done");
1611 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe SET ";
1612 $sql .=
"entity = ".((int) $this->entity);
1613 $sql .=
",nom = '".$this->db->escape($this->
name).
"'";
1614 $sql .=
",name_alias = '".$this->db->escape($this->name_alias).
"'";
1615 $sql .=
",ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1616 $sql .=
",address = '".$this->db->escape($this->address).
"'";
1618 $sql .=
",zip = ".(!empty($this->zip) ?
"'".$this->db->escape($this->zip).
"'" :
"null");
1619 $sql .=
",town = ".(!empty($this->town) ?
"'".$this->db->escape($this->town).
"'" :
"null");
1621 $sql .=
",fk_departement = ".((!empty($this->state_id) && $this->state_id > 0) ? ((
int) $this->state_id) :
'null');
1622 $sql .=
",fk_pays = ".((!empty($this->country_id) && $this->country_id > 0) ? ((
int) $this->country_id) :
'null');
1624 $sql .=
",phone = ".(!empty($this->phone) ?
"'".$this->db->escape($this->phone).
"'" :
"null");
1625 $sql .=
",phone_mobile = ".(!empty($this->phone_mobile) ?
"'".$this->db->escape($this->phone_mobile).
"'" :
"null");
1626 $sql .=
",fax = ".(!empty($this->fax) ?
"'".$this->db->escape($this->fax).
"'" :
"null");
1627 $sql .=
",email = ".(!empty($this->email) ?
"'".$this->db->escape($this->email).
"'" :
"null");
1628 $sql .=
",socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1629 $sql .=
",url = ".(!empty($this->url) ?
"'".$this->db->escape($this->url).
"'" :
"null");
1631 $sql .=
",parent = ".($this->parent > 0 ? $this->parent :
"null");
1633 $sql .=
",note_private = ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
1634 $sql .=
",note_public = ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
1636 $sql .=
",siren = '".$this->db->escape($this->idprof1).
"'";
1637 $sql .=
",siret = '".$this->db->escape($this->idprof2).
"'";
1638 $sql .=
",ape = '".$this->db->escape($this->idprof3).
"'";
1639 $sql .=
",idprof4 = '".$this->db->escape($this->idprof4).
"'";
1640 $sql .=
",idprof5 = '".$this->db->escape($this->idprof5).
"'";
1641 $sql .=
",idprof6 = '".$this->db->escape($this->idprof6).
"'";
1643 $sql .=
",tva_assuj = ".($this->tva_assuj !=
'' ?
"'".$this->db->escape($this->tva_assuj).
"'" :
"null");
1644 $sql .=
",tva_intra = '".$this->db->escape($this->tva_intra).
"'";
1646 $sql .=
",vat_reverse_charge = " . ($this->vat_reverse_charge !=
'' ?
"'" . $this->db->escape($this->vat_reverse_charge) .
"'" : 0);
1648 $sql .=
",status = ".((int) $this->
status);
1651 $sql .=
",localtax1_assuj = ".($this->localtax1_assuj !=
'' ?
"'".$this->db->escape($this->localtax1_assuj).
"'" :
"null");
1652 $sql .=
",localtax2_assuj = ".($this->localtax2_assuj !=
'' ?
"'".$this->db->escape($this->localtax2_assuj).
"'" :
"null");
1653 if ($this->localtax1_assuj == 1) {
1654 if ($this->localtax1_value !=
'') {
1655 $sql .=
",localtax1_value =".$this->localtax1_value;
1657 $sql .=
",localtax1_value =0.000";
1660 $sql .=
",localtax1_value =0.000";
1663 if ($this->localtax2_assuj == 1) {
1664 if ($this->localtax2_value !=
'') {
1665 $sql .=
",localtax2_value =".$this->localtax2_value;
1667 $sql .=
",localtax2_value =0.000";
1670 $sql .=
",localtax2_value =0.000";
1673 $sql .=
",capital = ".($this->capital ===
null ?
"null" : $this->capital);
1675 $sql .=
",prefix_comm = ".(!empty($this->prefix_comm) ?
"'".$this->db->escape($this->prefix_comm).
"'" :
"null");
1677 $sql .=
",fk_effectif = ".($this->effectif_id > 0 ? ((int) $this->effectif_id) :
"null");
1678 if (isset($this->stcomm_id)) {
1679 $sql .=
",fk_stcomm=".(int) $this->stcomm_id;
1681 if (isset($this->typent_id)) {
1682 $sql .=
",fk_typent = ".($this->typent_id > 0 ? ((int) $this->typent_id) :
"0");
1685 $sql .=
",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ?
"'".$this->db->escape($this->forme_juridique_code).
"'" :
"null");
1687 $sql .=
",mode_reglement = ".(!empty($this->mode_reglement_id) ?
"'".$this->db->escape($this->mode_reglement_id).
"'" :
"null");
1688 $sql .=
",cond_reglement = ".(!empty($this->cond_reglement_id) ?
"'".$this->db->escape($this->cond_reglement_id).
"'" :
"null");
1689 $sql .=
",deposit_percent = ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null");
1690 $sql .=
",transport_mode = ".(!empty($this->transport_mode_id) ?
"'".$this->db->escape($this->transport_mode_id).
"'" :
"null");
1691 $sql .=
",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ?
"'".$this->db->escape($this->mode_reglement_supplier_id).
"'" :
"null");
1692 $sql .=
",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ?
"'".$this->db->escape($this->cond_reglement_supplier_id).
"'" :
"null");
1693 $sql .=
",transport_mode_supplier = ".(!empty($this->transport_mode_supplier_id) ?
"'".$this->db->escape($this->transport_mode_supplier_id).
"'" :
"null");
1694 $sql .=
",fk_shipping_method = ".(!empty($this->shipping_method_id) ?
"'".$this->db->escape($this->shipping_method_id).
"'" :
"null");
1696 $sql .=
",client = ".(!empty($this->client) ? $this->client : 0);
1697 $sql .=
",fournisseur = ".(!empty($this->fournisseur) ? $this->fournisseur : 0);
1698 $sql .=
",barcode = ".(!empty($this->barcode) ?
"'".$this->db->escape($this->barcode).
"'" :
"null");
1699 $sql .=
",default_lang = ".(!empty($this->default_lang) ?
"'".$this->db->escape($this->default_lang).
"'" :
"null");
1700 $sql .=
",logo = ".(!empty($this->logo) ?
"'".$this->db->escape($this->logo).
"'" :
"null");
1701 $sql .=
",logo_squarred = ".(!empty($this->logo_squarred) ?
"'".$this->db->escape($this->logo_squarred).
"'" :
"null");
1702 $sql .=
",outstanding_limit= ".($this->outstanding_limit !=
'' ? $this->outstanding_limit :
'null');
1703 $sql .=
",order_min_amount= ".($this->order_min_amount !=
'' ? $this->order_min_amount :
'null');
1704 $sql .=
",supplier_order_min_amount= ".($this->supplier_order_min_amount !=
'' ? $this->supplier_order_min_amount :
'null');
1705 $sql .=
",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel).
"'";
1707 $sql .=
", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1708 $sql .=
", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1710 $sql .=
", accountancy_code_customer_general = ".(!empty($this->accountancy_code_customer_general) ?
"'".$this->db->escape($this->accountancy_code_customer_general).
"'" :
"null");
1711 $sql .=
", code_compta = ".(!empty($this->code_compta_client) ?
"'".$this->db->escape($this->code_compta_client).
"'" :
"null");
1715 $sql .=
", accountancy_code_supplier_general = ".(!empty($this->accountancy_code_supplier_general) ?
"'".$this->db->escape($this->accountancy_code_supplier_general).
"'" :
"null");
1716 $sql .=
", code_compta_fournisseur = ".(($this->code_compta_fournisseur !=
"") ?
"'".$this->db->escape($this->code_compta_fournisseur).
"'" :
"null");
1719 $sql .=
",webservices_url = ".(!empty($this->webservices_url) ?
"'".$this->db->escape($this->webservices_url).
"'" :
"null");
1720 $sql .=
",webservices_key = ".(!empty($this->webservices_key) ?
"'".$this->db->escape($this->webservices_key).
"'" :
"null");
1723 $sql .=
", fk_incoterms = ".((int) $this->fk_incoterms);
1724 $sql .=
", location_incoterms = ".(!empty($this->location_incoterms) ?
"'".$this->db->escape($this->location_incoterms).
"'" :
"null");
1727 $sql .=
", code_client = ".(!empty($this->code_client) ?
"'".$this->db->escape($this->code_client).
"'" :
"null");
1731 $sql .=
", code_fournisseur = ".(!empty($this->code_fournisseur) ?
"'".$this->db->escape($this->code_fournisseur).
"'" :
"null");
1733 $sql .=
", fk_user_modif = ".($user->id > 0 ? $user->id :
"null");
1734 $sql .=
", fk_multicurrency = ".(int) $this->fk_multicurrency;
1735 $sql .=
", multicurrency_code = '".$this->db->escape($this->multicurrency_code).
"'";
1736 $sql .=
", model_pdf = '".$this->db->escape($this->model_pdf).
"'";
1737 $sql .=
" WHERE rowid = ".(int) $id;
1739 $resql = $this->db->query($sql);
1741 if (is_object($this->oldcopy)) {
1742 if ($this->oldcopy->country_id != $this->country_id) {
1743 unset($this->country_code);
1744 unset($this->country);
1746 if ($this->oldcopy->state_id != $this->state_id) {
1747 unset($this->state_code);
1748 unset($this->state);
1751 unset($this->country_code);
1752 unset($this->country);
1753 unset($this->state_code);
1754 unset($this->state);
1757 $nbrowsaffected = $this->db->affected_rows($resql);
1759 if (!$error && $nbrowsaffected) {
1761 if (!$nosyncmember && isModEnabled(
'member')) {
1762 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1764 dol_syslog(get_class($this).
"::update update linked member");
1766 $lmember =
new Adherent($this->db);
1767 $result = $lmember->fetch(0, 0, $this->
id);
1770 $lmember->company = $this->name;
1773 $lmember->address = $this->address;
1774 $lmember->zip = $this->zip;
1775 $lmember->town = $this->town;
1776 $lmember->email = $this->email;
1777 $lmember->socialnetworks = $this->socialnetworks;
1778 $lmember->phone = $this->phone;
1779 $lmember->state_id = $this->state_id;
1780 $lmember->country_id = $this->country_id;
1781 $lmember->default_lang = $this->default_lang;
1783 $result = $lmember->update($user, 0, 1, 1, 1);
1785 $this->error = $lmember->error;
1786 $this->errors = array_merge($this->errors, $lmember->errors);
1787 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
1790 } elseif ($result < 0) {
1791 $this->error = $lmember->error;
1801 $this->db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int)
$conf->entity));
1803 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
1806 $sql .=
", vat_reverse_charge";
1807 $sql .=
", accountancy_code_customer_general";
1808 $sql .=
", accountancy_code_customer";
1809 $sql .=
", accountancy_code_supplier_general";
1810 $sql .=
", accountancy_code_supplier";
1811 $sql .=
", accountancy_code_buy";
1812 $sql .=
", accountancy_code_sell";
1813 $sql .=
") VALUES (";
1815 $sql .=
", ".$conf->entity;
1816 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1817 $sql .=
", '".$this->db->escape($this->accountancy_code_customer_general).
"'";
1818 $sql .=
", '".$this->db->escape($this->code_compta_client).
"'";
1819 $sql .=
", '".$this->db->escape($this->accountancy_code_supplier_general).
"'";
1820 $sql .=
", '".$this->db->escape($this->code_compta_fournisseur).
"'";
1821 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1822 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1824 $result = $this->db->query($sql);
1827 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1846 if (!$error && $call_trigger) {
1848 $result = $this->
call_trigger(
'COMPANY_MODIFY', $user);
1856 dol_syslog(get_class($this).
"::Update success");
1857 $this->db->commit();
1860 $this->db->rollback();
1864 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1866 $this->error = $langs->trans(
"ErrorDuplicateField");
1869 $this->error = $this->db->lasterror();
1872 $this->db->rollback();
1876 $this->db->rollback();
1877 dol_syslog(get_class($this).
"::Update fails verify ".implode(
',', $this->errors), LOG_WARNING);
1901 public function fetch($rowid, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'', $is_client = 0, $is_supplier = 0)
1906 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)) {
1910 $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';
1911 $sql .=
', s.status, s.fk_warehouse';
1912 $sql .=
', s.price_level';
1913 $sql .=
', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif';
1914 $sql .=
', s.phone, s.phone_mobile, s.fax, s.email';
1915 $sql .=
', s.socialnetworks';
1916 $sql .=
', s.url, s.zip, s.town, s.note_private, s.note_public, s.client, s.fournisseur';
1917 $sql .=
', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1918 $sql .=
', s.capital, s.tva_intra';
1919 $sql .=
', s.fk_typent as typent_id';
1920 $sql .=
', s.fk_effectif as effectif_id';
1921 $sql .=
', s.fk_forme_juridique as forme_juridique_code';
1922 $sql .=
', s.webservices_url, s.webservices_key, s.model_pdf, s.last_main_doc';
1924 $sql .=
', s.accountancy_code_customer_general, s.code_compta';
1925 $sql .=
', s.accountancy_code_supplier_general, s.code_compta_fournisseur';
1926 $sql .=
', s.accountancy_code_buy, s.accountancy_code_sell';
1927 $sql .=
', s.vat_reverse_charge as soc_vat_reverse_charge';
1929 $sql .=
', spe.accountancy_code_customer_general, spe.accountancy_code_customer as code_compta';
1930 $sql .=
', spe.accountancy_code_supplier_general, spe.accountancy_code_supplier as code_compta_fournisseur';
1931 $sql .=
', spe.accountancy_code_buy, spe.accountancy_code_sell';
1932 $sql .=
', spe.vat_reverse_charge as spe_vat_reverse_charge';
1934 $sql .=
', s.code_client, s.code_fournisseur, s.parent, s.barcode';
1935 $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';
1936 $sql .=
', s.fk_account, s.tva_assuj';
1937 $sql .=
', s.mode_reglement_supplier, s.cond_reglement_supplier, s.transport_mode_supplier';
1938 $sql .=
', s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred';
1939 $sql .=
', s.fk_shipping_method';
1940 $sql .=
', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1941 $sql .=
', s.order_min_amount, s.supplier_order_min_amount';
1942 $sql .=
', s.fk_multicurrency, s.multicurrency_code';
1943 $sql .=
', fj.libelle as forme_juridique';
1944 $sql .=
', e.libelle as effectif';
1945 $sql .=
', c.code as country_code, c.label as country';
1946 $sql .=
', d.code_departement as state_code, d.nom as state';
1947 $sql .=
', r.rowid as region_id, r.code_region as region_code';
1948 $sql .=
', st.libelle as stcomm, st.picto as stcomm_picto';
1949 $sql .=
', te.code as typent_code';
1950 $sql .=
', i.libelle as label_incoterms';
1951 if (!isModEnabled(
'multicompany')) {
1952 $sql .=
', s.remise_client, s.remise_supplier';
1954 $sql .=
', sr.remise_client, sr2.remise_supplier';
1956 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
1958 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = ".((int)
$conf->entity);
1960 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_effectif as e ON s.fk_effectif = e.id';
1961 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON s.fk_pays = c.rowid';
1962 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcomm as st ON s.fk_stcomm = st.id';
1963 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
1964 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON s.fk_departement = d.rowid';
1965 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_regions as r ON d.fk_region = r.code_region ';
1966 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_typent as te ON s.fk_typent = te.id';
1967 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON s.fk_incoterms = i.rowid';
1970 if (isModEnabled(
'multicompany')) {
1971 $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').
'))';
1972 $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').
'))';
1974 $sql .=
' WHERE s.entity IN ('.getEntity($this->element).
')';
1978 $sql .=
' AND s.client > 0';
1981 $sql .=
' AND s.fournisseur > 0';
1985 $sql .=
' AND s.rowid = '.((int) $rowid);
1988 $sql .=
" AND s.nom = '".$this->db->escape($ref).
"'";
1991 $sql .=
" AND s.name_alias = '".$this->db->escape($ref_alias).
"'";
1994 $sql .=
" AND s.ref_ext = '".$this->db->escape($ref_ext).
"'";
1997 $sql .=
" AND s.barcode = '".$this->db->escape($barcode).
"'";
2000 $sql .=
" AND s.siren = '".$this->db->escape($idprof1).
"'";
2003 $sql .=
" AND s.siret = '".$this->db->escape($idprof2).
"'";
2006 $sql .=
" AND s.ape = '".$this->db->escape($idprof3).
"'";
2009 $sql .=
" AND s.idprof4 = '".$this->db->escape($idprof4).
"'";
2012 $sql .=
" AND s.idprof5 = '".$this->db->escape($idprof5).
"'";
2015 $sql .=
" AND s.idprof6 = '".$this->db->escape($idprof6).
"'";
2018 $sql .=
" AND s.email = '".$this->db->escape($email).
"'";
2021 $resql = $this->db->query($sql);
2023 $num = $this->db->num_rows($resql);
2025 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
2029 $obj = $this->db->fetch_object($resql);
2031 $this->
id = $obj->rowid;
2032 $this->entity = $obj->entity;
2033 $this->canvas = $obj->canvas;
2035 $this->
ref = $obj->name;
2036 $this->
name = $obj->name;
2037 $this->nom = $obj->name;
2038 $this->name_alias = $obj->name_alias;
2039 $this->ref_ext = $obj->ref_ext;
2041 $this->date_creation = $this->db->jdate($obj->date_creation);
2042 $this->date_modification = $this->db->jdate($obj->date_modification);
2043 $this->user_creation_id = $obj->fk_user_creat;
2044 $this->user_modification_id = $obj->fk_user_modif;
2046 $this->
address = $obj->address;
2047 $this->zip = $obj->zip;
2048 $this->town = $obj->town;
2050 $this->country_id = $obj->country_id;
2051 $this->country_code = $obj->country_id ? $obj->country_code :
'';
2052 $this->country = $obj->country_id ? (($langs->transnoentities(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code) ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
2054 $this->state_id = $obj->state_id;
2055 $this->state_code = $obj->state_code;
2056 $this->region_id = $obj->region_id;
2057 $this->region_code = $obj->region_code;
2058 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
2060 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcomm);
2061 $label = ($transcode !=
'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm);
2062 $this->stcomm_id = $obj->fk_stcomm;
2063 $this->status_prospect_label = $label;
2064 $this->stcomm_picto = $obj->stcomm_picto;
2066 $this->
email = $obj->email;
2067 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
2069 $this->url = $obj->url;
2070 $this->phone = $obj->phone;
2071 $this->phone_mobile = $obj->phone_mobile;
2072 $this->fax = $obj->fax;
2074 $this->parent = $obj->parent;
2076 $this->idprof1 = $obj->idprof1;
2077 $this->idprof2 = $obj->idprof2;
2078 $this->idprof3 = $obj->idprof3;
2079 $this->idprof4 = $obj->idprof4;
2080 $this->idprof5 = $obj->idprof5;
2081 $this->idprof6 = $obj->idprof6;
2083 $this->capital = $obj->capital;
2085 $this->code_client = $obj->code_client;
2086 $this->code_fournisseur = $obj->code_fournisseur;
2088 $this->accountancy_code_customer_general = $obj->accountancy_code_customer_general;
2089 $this->code_compta_client = $obj->code_compta;
2090 $this->accountancy_code_supplier_general = $obj->accountancy_code_supplier_general;
2091 $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
2093 $this->barcode = $obj->barcode;
2095 $this->tva_assuj = $obj->tva_assuj;
2096 $this->tva_intra = $obj->tva_intra;
2098 if (!empty($obj->spe_vat_reverse_charge)) {
2099 $this->vat_reverse_charge = $obj->spe_vat_reverse_charge;
2100 } elseif (!empty($obj->soc_vat_reverse_charge)) {
2101 $this->vat_reverse_charge = $obj->soc_vat_reverse_charge;
2103 $this->vat_reverse_charge = 0;
2106 $this->
status = $obj->status;
2109 $this->localtax1_assuj = $obj->localtax1_assuj;
2110 $this->localtax2_assuj = $obj->localtax2_assuj;
2112 $this->localtax1_value = $obj->localtax1_value;
2113 $this->localtax2_value = $obj->localtax2_value;
2115 $this->typent_id = $obj->typent_id;
2116 $this->typent_code = $obj->typent_code;
2118 $this->effectif_id = $obj->effectif_id;
2119 $this->effectif = $obj->effectif_id ? $obj->effectif :
'';
2121 $this->forme_juridique_code = $obj->forme_juridique_code;
2122 $this->forme_juridique = $obj->forme_juridique_code ? $obj->forme_juridique :
'';
2124 $this->fk_prospectlevel = $obj->fk_prospectlevel;
2126 $this->prefix_comm = $obj->prefix_comm;
2128 $this->remise_percent = $obj->remise_client ?
price2num($obj->remise_client) : 0;
2129 $this->remise_supplier_percent = $obj->remise_supplier;
2131 $this->mode_reglement_id = $obj->mode_reglement;
2132 $this->cond_reglement_id = $obj->cond_reglement;
2133 $this->deposit_percent = $obj->deposit_percent;
2134 $this->transport_mode_id = $obj->transport_mode;
2135 $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier;
2136 $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier;
2137 $this->transport_mode_supplier_id = $obj->transport_mode_supplier;
2138 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
2139 $this->fk_account = $obj->fk_account;
2141 $this->client = $obj->client;
2142 $this->fournisseur = $obj->fournisseur;
2144 $this->note = $obj->note_private;
2145 $this->note_private = $obj->note_private;
2146 $this->note_public = $obj->note_public;
2147 $this->model_pdf = $obj->model_pdf;
2148 $this->default_lang = $obj->default_lang;
2149 $this->logo = $obj->logo;
2150 $this->logo_squarred = $obj->logo_squarred;
2152 $this->webservices_url = $obj->webservices_url;
2153 $this->webservices_key = $obj->webservices_key;
2155 $this->accountancy_code_buy = $obj->accountancy_code_buy;
2156 $this->accountancy_code_sell = $obj->accountancy_code_sell;
2158 $this->outstanding_limit = $obj->outstanding_limit;
2159 $this->order_min_amount = $obj->order_min_amount;
2160 $this->supplier_order_min_amount = $obj->supplier_order_min_amount;
2163 $this->price_level = $obj->price_level;
2166 $this->fk_warehouse = $obj->fk_warehouse;
2168 $this->import_key = $obj->import_key;
2171 $this->fk_incoterms = $obj->fk_incoterms;
2172 $this->location_incoterms = $obj->location_incoterms;
2173 $this->label_incoterms = $obj->label_incoterms;
2176 $this->fk_multicurrency = $obj->fk_multicurrency;
2177 $this->multicurrency_code = $obj->multicurrency_code;
2180 $this->model_pdf = $obj->model_pdf;
2181 $this->last_main_doc = $obj->last_main_doc;
2183 $result = $this->id;
2191 $this->db->free($resql);
2193 $this->error = $this->db->lasterror();
2194 $this->errors[] = $this->db->lasterror();
2200 $this->price_level = 1;
2226 public function findNearest($rowid = 0, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'', $is_client = 0, $is_supplier = 0)
2239 $tmpthirdparty =
new Societe($this->db);
2240 $result = $tmpthirdparty->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias, $is_client, $is_supplier);
2253 public function delete($id, $fuser =
null, $call_trigger = 1)
2255 global
$conf, $user;
2257 if (empty($fuser)) {
2261 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2263 $entity = isset($this->entity) ? $this->entity :
$conf->entity;
2265 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2270 if (empty($objectisused)) {
2274 if (!$error && $call_trigger) {
2276 $result = $this->
call_trigger(
'COMPANY_DELETE', $fuser);
2284 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2286 $toute_categs = array();
2289 $toute_categs[
'customer'] = $static_cat->containing($this->
id, Categorie::TYPE_CUSTOMER);
2290 $toute_categs[
'supplier'] = $static_cat->containing($this->
id, Categorie::TYPE_SUPPLIER);
2293 foreach ($toute_categs as $type => $categs_type) {
2294 foreach ($categs_type as $cat) {
2295 $cat->del_type($this, $type);
2301 foreach ($this->childtablesoncascade as $tabletodelete) {
2302 $deleteFromObject = explode(
':', $tabletodelete, 4);
2303 if (count($deleteFromObject) >= 2) {
2304 $className = str_replace(
'@',
'', $deleteFromObject[0]);
2305 $filepath = $deleteFromObject[1];
2306 $columnName = $deleteFromObject[2];
2308 $child_object =
new $className($this->db);
2309 '@phan-var-force CommonObject $child_object';
2310 $result = $child_object->deleteByParentField($id, $columnName);
2313 $this->errors[] = $child_object->error;
2318 $this->errors[] =
'Cannot include child class file '.$filepath;
2322 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
2323 $sql .=
" WHERE fk_soc = ".((int) $id);
2324 if (!$this->db->query($sql)) {
2326 $this->errors[] = $this->db->lasterror();
2338 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
2344 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2345 $sql .=
" SET parent = NULL";
2346 $sql .=
" WHERE parent = ".((int) $id);
2347 if (!$this->db->query($sql)) {
2349 $this->errors[] = $this->db->lasterror();
2356 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity";
2357 $sql .=
" WHERE fk_soc = ".((int) $id);
2358 if (!$this->db->query($sql)) {
2360 $this->errors[] = $this->db->lasterror();
2364 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe";
2365 $sql .=
" WHERE rowid = ".((int) $id);
2366 if (!$this->db->query($sql)) {
2368 $this->errors[] = $this->db->lasterror();
2373 $this->db->commit();
2376 if (!empty(
$conf->societe->multidir_output[$entity])) {
2377 $docdir =
$conf->societe->multidir_output[$entity].
"/".$id;
2386 $this->db->rollback();
2390 dol_syslog(
"Can't remove thirdparty with id ".$id.
". There are ".$objectisused.
" children", LOG_WARNING);
2406 dol_syslog(get_class($this).
"::set_as_client is deprecated use setAsCustomer instead", LOG_NOTICE);
2420 if (($this->client == 2 || $this->client == 3) && !
getDolGlobalInt(
'SOCIETE_DISABLE_PROSPECTSCUSTOMERS')) {
2423 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2424 $sql .=
" SET client = ".((int) $newclient);
2425 $sql .=
" WHERE rowid = ".((int) $this->
id);
2427 $resql = $this->db->query($sql);
2429 $this->client = $newclient;
2450 global
$conf, $langs;
2453 $note = trim($note);
2455 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2459 dol_syslog(get_class($this).
"::set_remise_client ".$remise.
", ".$note.
", ".$user->id);
2467 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2468 $sql .=
" SET remise_client = '".$this->db->escape($remise).
"'";
2469 $sql .=
" WHERE rowid = ".((int) $this->
id);
2470 $resql = $this->db->query($sql);
2472 $this->db->rollback();
2473 $this->error = $this->db->error();
2478 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise";
2479 $sql .=
" (entity, datec, fk_soc, remise_client, note, fk_user_author)";
2480 $sql .=
" VALUES (".((int)
$conf->entity).
", '".$this->db->idate($now).
"', ".((int) $this->
id).
", '".$this->db->escape($remise).
"',";
2481 $sql .=
" '".$this->db->escape($note).
"',";
2482 $sql .=
" ".((int) $user->id);
2485 $resql = $this->db->query($sql);
2487 $this->db->rollback();
2488 $this->error = $this->db->lasterror();
2492 $this->db->commit();
2511 global
$conf, $langs;
2514 $note = trim($note);
2516 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2520 dol_syslog(get_class($this).
"::set_remise_supplier ".$remise.
", ".$note.
", ".$user->id);
2528 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2529 $sql .=
" SET remise_supplier = '".$this->db->escape($remise).
"'";
2530 $sql .=
" WHERE rowid = ".((int) $this->
id);
2531 $resql = $this->db->query($sql);
2533 $this->db->rollback();
2534 $this->error = $this->db->error();
2539 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise_supplier";
2540 $sql .=
" (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
2541 $sql .=
" VALUES (".((int)
$conf->entity).
", '".$this->db->idate($now).
"', ".((int) $this->
id).
", '".$this->db->escape($remise).
"',";
2542 $sql .=
" '".$this->db->escape($note).
"',";
2543 $sql .=
" ".((int) $user->id);
2546 $resql = $this->db->query($sql);
2548 $this->db->rollback();
2549 $this->error = $this->db->lasterror();
2553 $this->db->commit();
2572 public function set_remise_except($remise,
User $user, $desc, $vatrate =
'', $discount_type = 0, $price_base_type =
'HT')
2579 $desc = trim($desc);
2582 if (!($remise > 0)) {
2583 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"1");
2587 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"3");
2591 if ($this->
id > 0) {
2595 if (preg_match(
'/\((.*)\)/', $vatrate, $reg)) {
2596 $vat_src_code = $reg[1];
2597 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2600 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2603 $discount->fk_soc = $this->id;
2604 $discount->socid = $this->id;
2606 $discount->discount_type = $discount_type;
2607 $discount->multicurrency_code = $this->multicurrency_code;
2609 $discount->multicurrency_tx = $this->multicurrency_tx;
2611 if ($price_base_type ==
'TTC') {
2612 $discount->amount_ttc =
price2num($remise,
'MT');
2613 $discount->amount_ht =
price2num((
float) $remise / (1 + (
float) $vatrate / 100),
'MT');
2614 $discount->amount_tva =
price2num((
float) $discount->amount_ttc - (
float) $discount->amount_ht,
'MT');
2616 $discount->multicurrency_amount_ttc =
price2num((
float) $remise * (
float) $discount->multicurrency_tx,
'MT');
2617 $discount->multicurrency_amount_ht =
price2num(((
float) $remise / (1 + (
float) $vatrate / 100)) * (
float) $discount->multicurrency_tx,
'MT');
2618 $discount->multicurrency_amount_tva =
price2num(((
float) $discount->amount_ttc - (
float) $discount->amount_ht) * (
float) $discount->multicurrency_tx,
'MT');
2620 $discount->amount_ht =
price2num($remise,
'MT');
2621 $discount->amount_tva =
price2num((
float) $remise * (
float) $vatrate / 100,
'MT');
2622 $discount->amount_ttc =
price2num((
float) $discount->amount_ht + (
float) $discount->amount_tva,
'MT');
2624 $discount->multicurrency_amount_ht =
price2num((
float) $remise * (
float) $discount->multicurrency_tx,
'MT');
2625 $discount->multicurrency_amount_tva =
price2num(((
float) $remise * (
float) $vatrate / 100) * (
float) $discount->multicurrency_tx,
'MT');
2626 $discount->multicurrency_amount_ttc =
price2num(((
float) $discount->amount_ht + (
float) $discount->amount_tva) * (
float) $discount->multicurrency_tx,
'MT');
2629 $discount->tva_tx = (float)
price2num($vatrate);
2630 $discount->vat_src_code = $vat_src_code;
2632 $discount->description = $desc;
2634 $result = $discount->create($user);
2638 $this->error = $discount->error;
2657 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2660 $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type);
2664 $this->error = $discountstatic->error;
2682 $reparray = array();
2684 $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";
2685 $sql .=
", u.office_fax, u.user_mobile, u.personal_mobile";
2686 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc, ".MAIN_DB_PREFIX.
"user as u";
2688 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2689 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2691 $sql .=
" WHERE entity IN (0, ".$this->db->sanitize(
$conf->entity).
")";
2694 $sql .=
" AND u.rowid = sc.fk_user AND sc.fk_soc = ".((int) $this->
id);
2695 if (empty($sortfield) && empty($sortorder)) {
2696 $sortfield =
'u.lastname,u.firstname';
2697 $sortorder =
'ASC,ASC';
2699 $sql .= $this->db->order($sortfield, $sortorder);
2701 $resql = $this->db->query($sql);
2703 $num = $this->db->num_rows($resql);
2706 $obj = $this->db->fetch_object($resql);
2709 $reparray[$i][
'id'] = $obj->rowid;
2710 $reparray[$i][
'lastname'] = $obj->lastname;
2711 $reparray[$i][
'firstname'] = $obj->firstname;
2712 $reparray[$i][
'email'] = $obj->email;
2713 $reparray[$i][
'phone'] = $obj->office_phone;
2714 $reparray[$i][
'office_phone'] = $obj->office_phone;
2715 $reparray[$i][
'office_fax'] = $obj->office_fax;
2716 $reparray[$i][
'user_mobile'] = $obj->user_mobile;
2717 $reparray[$i][
'personal_mobile'] = $obj->personal_mobile;
2718 $reparray[$i][
'job'] = $obj->job;
2719 $reparray[$i][
'statut'] = $obj->status;
2720 $reparray[$i][
'status'] = $obj->status;
2721 $reparray[$i][
'entity'] = $obj->entity;
2722 $reparray[$i][
'login'] = $obj->login;
2723 $reparray[$i][
'photo'] = $obj->photo;
2724 $reparray[$i][
'gender'] = $obj->gender;
2726 $reparray[] = $obj->rowid;
2749 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2750 $sql .=
" SET price_level = ".((int) $price_level);
2751 $sql .=
" WHERE rowid = ".((int) $this->
id);
2753 if (!$this->db->query($sql)) {
2758 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_prices";
2759 $sql .=
" (datec, fk_soc, price_level, fk_user_author)";
2760 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $this->
id).
", ".((int) $price_level).
", ".((int) $user->id).
")";
2762 if (!$this->db->query($sql)) {
2784 if ($this->
id > 0 && $commid > 0) {
2788 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux";
2789 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2791 $resql = $this->db->query($sql);
2793 dol_syslog(get_class($this).
"::add_commercial Error ".$this->db->lasterror());
2799 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_commerciaux";
2800 $sql .=
" (fk_soc, fk_user)";
2801 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $commid).
")";
2803 $resql = $this->db->query($sql);
2805 dol_syslog(get_class($this).
"::add_commercial Error ".$this->db->lasterror());
2811 $this->context = array(
'commercial_modified' => $commid);
2813 $result = $this->
call_trigger(
'COMPANY_LINK_SALE_REPRESENTATIVE', $user);
2820 $this->db->commit();
2823 $this->db->rollback();
2843 $this->context = array(
'commercial_modified' => $commid);
2845 $result = $this->
call_trigger(
'COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
2850 if ($this->
id > 0 && $commid > 0) {
2851 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux ";
2852 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2854 if (!$this->db->query($sql)) {
2856 dol_syslog(get_class($this).
"::del_commercial Erreur");
2876 global
$conf, $langs, $user;
2878 $langs->loadLangs([
'companies',
'commercial']);
2882 $option = $params[
'option'] ??
'';
2883 $nofetch = !empty($params[
'nofetch']);
2885 $noaliasinname = (empty($params[
'noaliasinname']) ? 0 : $params[
'noaliasinname']);
2888 return [
'optimize' => $langs->trans(
"ShowCompany")];
2891 if (!empty($this->logo) && class_exists(
'Form')) {
2892 $photo =
'<div class="photointooltip floatright">';
2893 $photo .=
Form::showphoto(
'societe', $this, 0, 40, 0,
'photoref',
'mini', 0);
2895 $datas[
'photo'] = $photo;
2902 $datas[
'divopen'] =
'<div class="centpercent">';
2904 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
2905 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Customer").
'</u>';
2906 } elseif ($option ==
'prospect' && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
2907 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Prospect").
'</u>';
2908 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
2909 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Supplier").
'</u>';
2910 } elseif ($option ==
'agenda') {
2911 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2912 } elseif ($option ==
'project') {
2913 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2914 } elseif ($option ==
'margin') {
2915 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2916 } elseif ($option ==
'contact') {
2917 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2918 } elseif ($option ==
'ban') {
2919 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2923 if (empty($datas[
'picto'])) {
2924 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
2926 if (isset($this->
status)) {
2927 $datas[
'status'] =
' '.$this->getLibStatut(5);
2929 if (isset($this->client) && isset($this->fournisseur)) {
2930 $datas[
'type'] =
' ' . $this->
getTypeUrl(1,
'', 0,
'span');
2933 if (!empty($this->name_alias) && empty($noaliasinname)) {
2936 if (!empty($this->
email)) {
2937 $datas[
'email'] =
'<br>'.img_picto(
'',
'email',
'class="pictofixedwidth"').$this->email;
2939 if (!empty($this->url)) {
2940 $datas[
'url'] =
'<br>'.img_picto(
'',
'globe',
'class="pictofixedwidth"').$this->url;
2942 if (!empty($this->phone) || !empty($this->phone_mobile) || !empty($this->fax)) {
2943 $phonelist = array();
2945 $phonelist[] =
dol_print_phone($this->phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2948 if ($this->phone_mobile) {
2949 $phonelist[] =
dol_print_phone($this->phone_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'phone_mobile');
2952 $phonelist[] =
dol_print_phone($this->fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2954 $datas[
'phonelist'] =
'<br>'.implode(
' ', $phonelist);
2958 $datas[
'address'] =
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
', ', $langs);
2959 } elseif (!empty($this->country_code)) {
2960 $datas[
'address'] =
'<br><b>'.$langs->trans(
'Country').
':</b> '.$this->country_code;
2962 if (!empty($this->tva_intra) || (
getDolGlobalString(
'SOCIETE_SHOW_FIELD_IN_TOOLTIP') && strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'vatnumber') !==
false)) {
2963 $datas[
'vatintra'] =
'<br><b>'.$langs->trans(
'VATIntra').
':</b> '.
dol_escape_htmltag($this->tva_intra);
2967 if (strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid1') !==
false && $langs->trans(
'ProfId1'.$this->country_code) !=
'-') {
2968 $datas[
'profid1'] =
'<br><b>'.$langs->trans(
'ProfId1'.$this->country_code).
':</b> '.$this->idprof1;
2970 if (strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid2') !==
false && $langs->trans(
'ProfId2'.$this->country_code) !=
'-') {
2971 $datas[
'profid2'] =
'<br><b>'.$langs->trans(
'ProfId2'.$this->country_code).
':</b> '.$this->idprof2;
2973 if (strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid3') !==
false && $langs->trans(
'ProfId3'.$this->country_code) !=
'-') {
2974 $datas[
'profid3'] =
'<br><b>'.$langs->trans(
'ProfId3'.$this->country_code).
':</b> '.$this->idprof3;
2976 if (strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid4') !==
false && $langs->trans(
'ProfId4'.$this->country_code) !=
'-') {
2977 $datas[
'profid4'] =
'<br><b>'.$langs->trans(
'ProfId4'.$this->country_code).
':</b> '.$this->idprof4;
2979 if (strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid5') !==
false && $langs->trans(
'ProfId5'.$this->country_code) !=
'-') {
2980 $datas[
'profid5'] =
'<br><b>'.$langs->trans(
'ProfId5'.$this->country_code).
':</b> '.$this->idprof5;
2982 if (strpos(
$conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid6') !==
false && $langs->trans(
'ProfId6'.$this->country_code) !=
'-') {
2983 $datas[
'profid6'] =
'<br><b>'.$langs->trans(
'ProfId6'.$this->country_code).
':</b> '.$this->idprof6;
2987 $datas[
'separator'] =
'<br>';
2989 if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
2990 $datas[
'customercode'] =
'<br><b>'.$langs->trans(
'CustomerCode').
':</b> '.$this->code_client;
2992 if (isModEnabled(
'accounting') && ($this->client == 1 || $this->client == 3)) {
2993 $langs->load(
'compta');
2994 $datas[
'accountancycustomercode'] =
'<br><b>'.$langs->trans(
'CustomerAccountancyCode').
':</b> '.$this->code_compta_client;
2997 if (!$nofetch && isModEnabled(
'category') && $this->client) {
2998 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2999 $form =
new Form($this->db);
3000 $datas[
'categories_customer'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_CUSTOMER, 1, 1);
3002 if (!empty($this->code_fournisseur) && $this->fournisseur) {
3003 $datas[
'suppliercode'] =
'<br><b>'.$langs->trans(
'SupplierCode').
':</b> '.$this->code_fournisseur;
3005 if (isModEnabled(
'accounting') && $this->fournisseur) {
3006 $langs->load(
'compta');
3007 $datas[
'accountancysuppliercode'] =
'<br><b>'.$langs->trans(
'SupplierAccountancyCode').
':</b> '.$this->code_compta_fournisseur;
3010 if (!$nofetch && isModEnabled(
'category') && $this->fournisseur) {
3011 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
3012 $form =
new Form($this->db);
3013 $datas[
'categories_supplier'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_SUPPLIER, 1, 1);
3016 $datas[
'divclose'] =
'</div>';
3034 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1, $noaliasinname = 0, $target =
'', $morecss =
'')
3036 global
$conf, $langs, $hookmanager, $user;
3038 if (!empty(
$conf->dol_no_mouse_hover)) {
3042 $name = $this->
name ? $this->
name : $this->nom;
3044 if (
getDolGlobalString(
'SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD')) {
3045 if (empty($option) && $this->client > 0) {
3046 $option =
'customer';
3048 if (empty($option) && $this->fournisseur > 0) {
3049 $option =
'supplier';
3055 if (($this->client) && (!empty($this->code_client)) && (
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 1 ||
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 2)) {
3056 $code = $this->code_client.
' - ';
3059 if (($this->fournisseur) && (!empty($this->code_fournisseur)) && (
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 1 ||
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 3)) {
3060 $code .= $this->code_fournisseur.
' - ';
3065 $name = $code.
' '.$name;
3072 if (!empty($this->name_alias) && empty($noaliasinname)) {
3073 $name .=
' ('.$this->name_alias.
')';
3079 'objecttype' => $this->element,
3080 'option' => $option,
3083 $classfortooltip =
'classfortooltip';
3086 $classfortooltip =
'classforajaxtooltip';
3087 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3096 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
3097 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
3098 } elseif ($option ==
'prospect' && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
3099 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
3100 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
3101 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->id;
3102 } elseif ($option ==
'agenda') {
3103 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/agenda.php?socid='.$this->id;
3104 } elseif ($option ==
'project') {
3105 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/project.php?socid='.$this->id;
3106 } elseif ($option ==
'margin') {
3107 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/margin/tabs/thirdpartyMargins.php?socid='.$this->
id.
'&type=1';
3108 } elseif ($option ==
'contact') {
3109 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/contact.php?socid='.$this->id;
3110 } elseif ($option ==
'ban') {
3111 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$this->id;
3115 if (empty($linkstart)) {
3116 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$this->id;
3120 $linkstart .= (!empty($this->canvas) ?
'&canvas='.$this->canvas :
'');
3122 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3123 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3124 $add_save_lastsearch_values = 1;
3126 if ($add_save_lastsearch_values) {
3127 $linkstart .=
'&save_lastsearch_values=1';
3132 if (empty($notooltip)) {
3134 $label = $langs->trans(
"ShowCompany");
3135 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3137 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3138 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
' refurl valignmiddle"';
3139 $target_value = array(
'_self',
'_blank',
'_parent',
'_top');
3140 if (in_array($target, $target_value)) {
3141 $linkclose .=
' target="'.dol_escape_htmltag($target).
'"';
3144 $linkclose .=
' class="valignmiddle'.($morecss ?
' '.$morecss :
'').
'"';
3146 $linkstart .= $linkclose.
'>';
3149 if (!$user->hasRight(
'societe',
'client',
'voir') && $user->socid > 0 && $this->id != $user->socid) {
3154 $result .= $linkstart;
3156 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (
' class="'.(($withpicto != 2) ?
'paddingright' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
3158 if ($withpicto != 2) {
3161 $result .= $linkend;
3164 $hookmanager->initHooks(array(
'thirdpartydao'));
3165 $parameters = array(
3167 'getnomurl' => &$result,
3168 'withpicto ' => $withpicto,
3169 'option' => $option,
3170 'maxlen' => $maxlen,
3171 'notooltip' => $notooltip,
3172 'save_lastsearch_value' => $save_lastsearch_value
3174 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3176 $result = $hookmanager->resPrint;
3178 $result .= $hookmanager->resPrint;
3193 public function getTypeUrl($withpicto = 0, $option =
'', $notooltip = 0, $tag =
'a')
3198 if (empty($option) || preg_match(
'/prospect/', $option)) {
3199 if (($this->client == 2 || $this->client == 3) && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
3200 $s .=
'<'.$tag.
' class="customer-back opacitymedium" title="'.
dolPrintHTMLForAttribute($langs->trans(
"Prospect")).
'"';
3201 $s .= $tag ==
'a' ?
' href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->
id.
'"' :
'';
3202 $s .=
'>'.dol_substr($langs->trans(
"Prospect"), 0, 1).
'</'.$tag.
'>';
3205 if (empty($option) || preg_match(
'/customer/', $option)) {
3206 if (($this->client == 1 || $this->client == 3) && !
getDolGlobalString(
'SOCIETE_DISABLE_CUSTOMERS')) {
3208 $s.= $tag ==
'a' ?
' href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->
id.
'"' :
'';
3209 $s .=
'>'.dol_substr($langs->trans(
"Customer"), 0, 1).
'</'.$tag.
'>';
3212 if (empty($option) || preg_match(
'/supplier/', $option)) {
3213 if ((isModEnabled(
"supplier_order") || isModEnabled(
"supplier_invoice")) && $this->fournisseur) {
3215 $s .= $tag ==
'a' ?
' href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->
id.
'"' :
'';
3216 $s .=
'>'.dol_substr($langs->trans(
"Supplier"), 0, 1).
'</'.$tag.
'>';
3247 $langs->load(
'companies');
3249 $statusType =
'status4';
3251 $statusType =
'status6';
3254 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3255 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
3256 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"InActivity");
3257 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
3258 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"InActivity");
3261 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3278 if ($this->
email && $addthirdparty) {
3279 if (empty($this->
name)) {
3280 $this->
name = $this->nom;
3282 $contact_emails[
'thirdparty'] = ($addthirdparty == 2 ?
'<span class="opacitymedium">' :
'').$langs->transnoentitiesnoconv(
"ThirdParty").($addthirdparty == 2 ?
'</span>' :
'').
': '.
dol_trunc($this->
name, 16).
" <".$this->
email.
">";
3286 return $contact_emails;
3302 if (!empty($this->phone)) {
3303 if (empty($this->
name)) {
3304 $this->
name = $this->nom;
3307 $contact_phone[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->phone.
">";
3309 return $contact_phone;
3325 $contact_property = array();
3328 $sql =
"SELECT rowid, email, statut as status, phone_mobile, lastname, poste, firstname";
3329 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3330 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
3331 $sql .=
" AND entity IN (".getEntity($this->element).
")";
3332 $sql .=
" ORDER BY lastname, firstname";
3334 $resql = $this->db->query($sql);
3336 $nump = $this->db->num_rows($resql);
3340 if ($mode ==
'email') {
3346 while ($i < $nump) {
3347 $obj = $this->db->fetch_object($resql);
3348 if ($mode ==
'email') {
3349 $property = $obj->email;
3350 } elseif ($mode ==
'mobile') {
3351 $property = $obj->phone_mobile;
3353 $property = $obj->$mode;
3357 if ($obj->status == 1 || empty($hidedisabled)) {
3358 if (empty($property)) {
3359 if ($mode ==
'email') {
3360 $property = $langs->transnoentitiesnoconv(
"NoEMail");
3361 } elseif ($mode ==
'mobile') {
3362 $property = $langs->transnoentitiesnoconv(
"NoMobilePhone");
3366 if (!empty($obj->poste)) {
3367 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ?
" - ".$obj->poste :
"").(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3369 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3378 return $contact_property;
3391 $contacts = array();
3393 $sql =
"SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3394 $resql = $this->db->query($sql);
3396 $nump = $this->db->num_rows($resql);
3399 while ($i < $nump) {
3400 $obj = $this->db->fetch_object($resql);
3420 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
3421 $contacts = array();
3423 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3424 $resql = $this->db->query($sql);
3426 $nump = $this->db->num_rows($resql);
3429 while ($i < $nump) {
3430 $obj = $this->db->fetch_object($resql);
3431 $contact =
new Contact($this->db);
3432 $contact->fetch($obj->rowid);
3433 $contacts[] = $contact;
3454 $contact_property =
'';
3456 if (empty($rowid)) {
3460 $sql =
"SELECT rowid, email, phone_mobile, lastname, firstname";
3461 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3462 $sql .=
" WHERE rowid = ".((int) $rowid);
3464 $resql = $this->db->query($sql);
3466 $nump = $this->db->num_rows($resql);
3469 $obj = $this->db->fetch_object($resql);
3471 if ($mode ==
'email') {
3473 } elseif ($mode ==
'mobile') {
3474 $contact_property = $obj->phone_mobile;
3477 return $contact_property;
3496 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3500 $bac->fetch(0,
'', $this->
id);
3503 if ($mode ==
'label') {
3504 return $bac->getRibLabel(
true);
3505 } elseif ($mode ==
'rum') {
3506 if (empty($bac->rum)) {
3507 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
3509 $bac->fetch_thirdparty();
3510 $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
3513 } elseif ($mode ==
'format') {
3514 return $bac->frstrecur;
3516 return 'BadParameterToFunctionDisplayRib';
3532 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3533 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE type = 'ban' AND fk_soc = ".((int) $this->
id);
3534 $result = $this->db->query($sql);
3536 $this->error = $this->db->lasterror();
3537 $this->errors[] = $this->db->lasterror();
3540 $num_rows = $this->db->num_rows($result);
3541 $rib_array = array();
3543 while ($obj = $this->db->fetch_object($result)) {
3545 $rib->fetch($obj->rowid);
3546 $rib_array[] = $rib;
3559 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3560 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE type = 'ban' AND default_rib = 1 AND fk_soc = ". (int) $this->
id;
3561 $resql = $this->db->query($sql);
3563 $this->error = $this->db->lasterror();
3564 $this->errors[] = $this->db->lasterror();
3567 $num_rows = $this->db->num_rows($resql);
3568 $rib_array = array();
3570 while ($obj = $this->db->fetch_object($resql)) {
3588 public function get_codeclient($objsoc =
null, $type = 0)
3595 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
3596 foreach ($dirsociete as $dirroot) {
3603 $mod =
new $module($this->db);
3604 '@phan-var-force ModeleThirdPartyCode $mod';
3606 $this->code_client = $mod->getNextValue($objsoc, $type);
3607 $this->prefixCustomerIsRequired = $mod->prefixIsRequired;
3609 dol_syslog(get_class($this).
"::get_codeclient code_client=".$this->code_client.
" module=".$module);
3622 public function get_codefournisseur($objsoc =
null, $type = 1)
3629 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
3630 foreach ($dirsociete as $dirroot) {
3637 $mod =
new $module($this->db);
3638 '@phan-var-force ModeleThirdPartyCode $mod';
3640 $this->code_fournisseur = $mod->getNextValue($objsoc, $type);
3642 dol_syslog(get_class($this).
"::get_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3660 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
3661 foreach ($dirsociete as $dirroot) {
3668 $mod =
new $module($this->db);
3669 '@phan-var-force ModeleThirdPartyCode $mod';
3671 dol_syslog(get_class($this).
"::codeclient_modifiable code_client=".$this->code_client.
" module=".$module);
3672 if ($mod->code_modifiable_null && !$this->code_client) {
3675 if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
3678 if ($mod->code_modifiable) {
3701 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
3702 foreach ($dirsociete as $dirroot) {
3709 $mod =
new $module($this->db);
3710 '@phan-var-force ModeleThirdPartyCode $mod';
3712 dol_syslog(get_class($this).
"::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur.
" module=".$module);
3713 if ($mod->code_modifiable_null && !$this->code_fournisseur) {
3716 if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
3719 if ($mod->code_modifiable) {
3748 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
3749 foreach ($dirsociete as $dirroot) {
3756 $mod =
new $module($this->db);
3757 '@phan-var-force ModeleThirdPartyCode $mod';
3759 dol_syslog(get_class($this).
"::check_codeclient code_client=".$this->code_client.
" module=".$module);
3760 $result = $mod->verif($this->db, $this->code_client, $this, 0);
3762 $this->error = $mod->error;
3763 $this->errors = $mod->errors;
3790 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
3791 foreach ($dirsociete as $dirroot) {
3798 $mod =
new $module($this->db);
3799 '@phan-var-force ModeleThirdPartyCode $mod';
3801 dol_syslog(get_class($this).
"::check_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3802 $result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
3804 $this->error = $mod->error;
3805 $this->errors = $mod->errors;
3830 $dirsociete = array_merge(array(
'/core/modules/societe/'),
$conf->modules_parts[
'societe']);
3831 foreach ($dirsociete as $dirroot) {
3839 $mod =
new $module();
3840 '@phan-var-force ModeleAccountancyCode $mod';
3843 $result = $mod->get_code($this->db, $this, $type);
3845 if ($type ==
'customer') {
3846 $this->code_compta_client = $mod->code;
3847 } elseif ($type ==
'supplier') {
3848 $this->code_compta_fournisseur = $mod->code;
3853 $this->error =
'ErrorAccountancyCodeNotDefined';
3857 if ($type ==
'customer') {
3858 $this->code_compta_client =
'';
3859 } elseif ($type ==
'supplier') {
3860 $this->code_compta_fournisseur =
'';
3875 dol_syslog(get_class($this).
'::setParent', LOG_DEBUG);
3881 if ($sameparent < 0) {
3884 if ($sameparent == 1) {
3885 setEventMessages(
'ParentCompanyToAddIsAlreadyAChildOfModifiedCompany',
null,
'warnings');
3890 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe SET parent = '.($id > 0 ? $id :
'null').
' WHERE rowid = '.((
int) $this->id);
3892 $resql = $this->db->query($sql);
3894 $this->parent = $id;
3914 if ($counter > 100) {
3915 dol_syslog(
"Too high level of parent - child for company. May be an infinite loop ?", LOG_WARNING);
3918 $sql =
'SELECT s.parent';
3919 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
3920 $sql .=
' WHERE rowid = '.((int) $idparent);
3921 $resql = $this->db->query($sql);
3923 $obj = $this->db->fetch_object($resql);
3925 if ($obj->parent ==
'') {
3927 } elseif ($obj->parent == $idchild) {
3949 if ($company_id > 0) {
3950 $sql =
"SELECT parent FROM " . MAIN_DB_PREFIX .
"societe WHERE rowid = ".((int) $company_id);
3951 $resql = $this->db->query($sql);
3953 if ($obj = $this->db->fetch_object($resql)) {
3954 $parent = $obj->parent;
3955 if ($parent > 0 && !in_array($parent, $parents)) {
3956 $parents[] = $parent;
3962 $this->db->free($resql);
3964 setEventMessage($langs->trans(
'GetCompanyParentsError', $this->db->lasterror()),
'errors');
4049 $sql =
"SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"societe WHERE ".$field.
" = '".$this->db->escape($value).
"' AND entity IN (".
getEntity(
'societe').
")";
4051 $sql .=
" AND rowid <> ".$socid;
4053 $resql = $this->db->query($sql);
4055 $obj = $this->db->fetch_object($resql);
4059 print $this->db->error();
4061 $this->db->free($resql);
4085 require_once DOL_DOCUMENT_ROOT.
'/core/lib/profid.lib.php';
4094 if ($idprof == 1 && $soc->country_code ==
'FR' && !
isValidSiren($this->idprof1)) {
4099 if ($idprof == 2 && $soc->country_code ==
'FR' && !
isValidSiret($this->idprof2)) {
4104 if ($idprof == 1 && $soc->country_code ==
'ES') {
4109 if ($idprof == 1 && $soc->country_code ==
'PT' && !
isValidTinForPT($this->idprof1)) {
4114 if ($idprof == 1 && $soc->country_code ==
'DZ' && !
isValidTinForDZ($this->idprof1)) {
4119 if ($idprof == 1 && $soc->country_code ==
'BE' && !
isValidTinForBE($this->idprof1)) {
4138 global
$conf, $langs, $hookmanager;
4143 $hookmanager->initHooks(array(
'idprofurl'));
4144 $parameters = array(
'idprof' => $idprof,
'company' => $thirdparty);
4145 $reshook = $hookmanager->executeHooks(
'getIdProfUrl', $parameters, $this, $action);
4146 if (empty($reshook)) {
4152 $strippedIdProf1 = str_replace(
' ',
'', $thirdparty->idprof1);
4153 if ($idprof == 1 && $thirdparty->country_code ==
'FR') {
4154 $url =
'https://annuaire-entreprises.data.gouv.fr/entreprise/'.$strippedIdProf1;
4156 if ($idprof == 1 && ($thirdparty->country_code ==
'GB' || $thirdparty->country_code ==
'UK')) {
4157 $url =
'https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
4159 if ($idprof == 1 && $thirdparty->country_code ==
'ES') {
4160 $url =
'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
4162 if ($idprof == 1 && $thirdparty->country_code ==
'IN') {
4163 $url =
'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.
';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
4165 if ($idprof == 1 && $thirdparty->country_code ==
'DZ') {
4166 $url =
'http://nif.mfdgi.gov.dz/nif.asp?Nif='.$strippedIdProf1;
4168 if ($idprof == 1 && $thirdparty->country_code ==
'PT') {
4169 $url =
'http://www.nif.pt/'.$strippedIdProf1;
4173 return '<a target="_blank" rel="noopener noreferrer" href="'.$url.
'">'.$langs->trans(
"Check").
'</a>';
4176 return $hookmanager->resPrint;
4191 $sql =
"SELECT COUNT(*) as numproj FROM ".MAIN_DB_PREFIX.
"projet WHERE fk_soc = ".((int) $this->
id);
4192 $resql = $this->db->query($sql);
4194 $obj = $this->db->fetch_object($resql);
4195 $count = $obj->numproj;
4198 print $this->db->error();
4200 $this->db->free($resql);
4201 return ($count > 0);
4213 $sql =
"SELECT s.rowid, s.nom as name, s.datec, tms as datem,";
4214 $sql .=
" fk_user_creat, fk_user_modif";
4215 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
4216 $sql .=
" WHERE s.rowid = ".((int) $id);
4218 $result = $this->db->query($sql);
4220 if ($this->db->num_rows($result)) {
4221 $obj = $this->db->fetch_object($result);
4223 $this->
id = $obj->rowid;
4225 $this->user_creation_id = $obj->fk_user_creat;
4226 $this->user_modification_id = $obj->fk_user_modif;
4227 $this->date_creation = $this->db->jdate($obj->datec);
4228 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
4230 $this->
ref = $obj->name;
4233 $this->db->free($result);
4247 $isACompany =
getDolGlobalInt(
'MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES', 1);
4250 if (!empty($this->tva_intra)) {
4252 } elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) {
4256 if (preg_match(
'/^TE_PRIVATE/', $this->typent_code)) {
4264 return (
bool) $isACompany;
4274 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4287 $this->SupplierCategories = array();
4288 $sql =
"SELECT rowid, label";
4289 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
4290 $sql .=
" WHERE type = ".Categorie::TYPE_SUPPLIER;
4292 $resql = $this->db->query($sql);
4294 while ($obj = $this->db->fetch_object($resql)) {
4295 $this->SupplierCategories[$obj->rowid] = $obj->label;
4313 if ($categorie_id > 0 && $this->
id > 0) {
4314 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_fournisseur (fk_categorie, fk_soc) ";
4315 $sql .=
" VALUES (".((int) $categorie_id).
", ".((int) $this->
id).
")";
4317 if ($resql = $this->db->query($sql)) {
4333 $sql =
"SELECT count(mc.email) as nb";
4334 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
4335 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->
email).
"' ";
4336 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
4338 $resql = $this->db->query($sql);
4340 $obj = $this->db->fetch_object($resql);
4343 $this->db->free($resql);
4346 $this->error = $this->db->error();
4366 $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).
"'";
4367 $resql = $this->db->query($sql);
4369 $obj = $this->db->fetch_object($resql);
4370 $noemail = $obj->nb;
4371 if (empty($noemail)) {
4372 $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()).
"')";
4373 $resql = $this->db->query($sql);
4376 $this->error = $this->db->lasterror();
4377 $this->errors[] = $this->error;
4382 $this->error = $this->db->lasterror();
4383 $this->errors[] = $this->error;
4386 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->db->escape($this->
email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
4387 $resql = $this->db->query($sql);
4390 $this->error = $this->db->lasterror();
4391 $this->errors[] = $this->error;
4395 if (empty($error)) {
4396 $this->no_email = $no_email;
4397 $this->db->commit();
4400 $this->db->rollback();
4417 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->db->escape($this->
email).
"'";
4418 $resql = $this->db->query($sql);
4420 $obj = $this->db->fetch_object($resql);
4421 $this->no_email = $obj->nb;
4424 $this->error = $this->db->lasterror();
4425 $this->errors[] = $this->error;
4445 global
$conf, $user, $langs;
4447 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
4448 $fullname = $member->getFullName($langs);
4450 if ($member->morphy ==
'mor') {
4451 if (empty($socname)) {
4452 $socname = $member->company ? $member->company : $member->societe;
4454 if (!empty($fullname) && empty($socalias)) {
4455 $socalias = $fullname;
4457 } elseif (empty($socname) && $member->morphy ==
'phy') {
4458 if (empty($socname)) {
4459 $socname = $fullname;
4461 if (!empty($member->company) && empty($socalias)) {
4462 $socalias = $member->company;
4467 $alias = $socalias ? $socalias :
'';
4471 $this->
name = $name;
4472 $this->name_alias = $alias;
4473 $this->
address = $member->address;
4474 $this->zip = $member->zip;
4475 $this->town = $member->town;
4476 $this->country_code = $member->country_code;
4477 $this->country_id = $member->country_id;
4478 $this->phone = $member->phone;
4479 $this->
email = $member->email;
4480 $this->socialnetworks = $member->socialnetworks;
4481 $this->entity = $member->entity;
4484 $this->code_client = ($customercode ? $customercode : -1);
4485 $this->code_fournisseur =
'-1';
4486 $this->typent_code = ($member->morphy ==
'phy' ?
'TE_PRIVATE' : 0);
4487 $this->typent_id = $this->typent_code ?
dol_getIdFromCode($this->db, $this->typent_code,
'c_typent',
'id',
'code') : 0;
4492 $result = $this->
create($user);
4498 $this->name_bis = $member->lastname;
4499 $this->firstname = $member->firstname;
4500 $this->civility_id = $member->civility_id;
4502 dol_syslog(
"We ask to create a contact/address too", LOG_DEBUG);
4507 $this->db->rollback();
4512 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent";
4513 $sql .=
" SET fk_soc = ".((int) $this->
id);
4514 $sql .=
" WHERE rowid = ".((int) $member->id);
4516 $resql = $this->db->query($sql);
4518 $this->db->commit();
4521 $this->error = $this->db->error();
4523 $this->db->rollback();
4528 dol_syslog(get_class($this).
"::create_from_member - 2 - ".$this->error.
" - ".implode(
',', $this->errors), LOG_ERR);
4530 $this->db->rollback();
4546 $this->entity =
$conf->entity;
4548 $this->nom = $this->name;
4560 $country_code = $country_label =
'';
4563 $country_id = (is_numeric($tmp[0])) ? (
int) $tmp[0] : 0;
4564 if (!empty($tmp[1])) {
4565 $country_code = $tmp[1];
4566 $country_label = $tmp[2];
4569 dol_syslog(
"Your country setup use an old syntax. Reedit it using setup area.", LOG_WARNING);
4570 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4571 $country_code =
getCountry($country_id,
'2', $this->db);
4572 $country_label =
getCountry($country_id,
'', $this->db);
4575 $this->country_id = $country_id;
4576 $this->country_code = $country_code;
4577 $this->country = $country_label;
4578 if (is_object($langs)) {
4579 $this->country = ($langs->trans(
'Country'.$country_code) !=
'Country'.$country_code) ? $langs->trans(
'Country'.$country_code) : $country_label;
4589 $state_id = (int) $tmp[0];
4590 if (!empty($tmp[1])) {
4591 $state_code = $tmp[1];
4592 $state_label = $tmp[2];
4594 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);
4595 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4596 $state_code =
getState($state_id,
'2', $this->db);
4597 $state_label =
getState($state_id,
'0', $this->db);
4600 $this->state_id = $state_id;
4601 $this->state_code = $state_code;
4602 $this->state = $state_label;
4603 if (is_object($langs)) {
4604 $this->state = ($langs->trans(
'State'.$state_code) !=
'State'.$state_code) ? $langs->trans(
'State'.$state_code) : $state_label;
4619 $this->socialnetworks = array();
4620 if (!empty($facebook_url)) {
4621 $this->socialnetworks[
'facebook'] = $facebook_url;
4623 if (!empty($twitter_url)) {
4624 $this->socialnetworks[
'twitter'] = $twitter_url;
4626 if (!empty($linkedin_url)) {
4627 $this->socialnetworks[
'linkedin'] = $linkedin_url;
4629 if (!empty($instagram_url)) {
4630 $this->socialnetworks[
'instagram'] = $instagram_url;
4632 if (!empty($youtube_url)) {
4633 $this->socialnetworks[
'youtube'] = $youtube_url;
4635 if (!empty($github_url)) {
4636 $this->socialnetworks[
'github'] = $github_url;
4653 $this->forme_juridique_code =
getDolGlobalInt(
'MAIN_INFO_SOCIETE_FORME_JURIDIQUE');
4660 $this->logo_squarred_small =
getDolGlobalString(
'MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL');
4661 $this->logo_squarred_mini =
getDolGlobalString(
'MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI');
4667 $this->localtax1_assuj = ((isset(
$conf->global->FACTURE_LOCAL_TAX1_OPTION) && (
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'1' ||
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'localtax1on')) ? 1 : 0);
4668 $this->localtax2_assuj = ((isset(
$conf->global->FACTURE_LOCAL_TAX2_OPTION) && (
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'1' ||
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'localtax2on')) ? 1 : 0);
4687 $this->
name =
'THIRDPARTY SPECIMEN '.dol_print_date($now,
'dayhourlog');
4688 $this->nom = $this->name;
4689 $this->ref_ext =
'Ref ext';
4690 $this->specimen = 1;
4691 $this->
address =
'21 jump street';
4692 $this->zip =
'99999';
4693 $this->town =
'MyTown';
4694 $this->state_id = 1;
4695 $this->state_code =
'AA';
4696 $this->state =
'MyState';
4697 $this->country_id = 1;
4698 $this->country_code =
'FR';
4699 $this->
email =
'specimen@specimen.com';
4700 $this->socialnetworks = array(
4701 'skype' =>
'skypepseudo',
4702 'twitter' =>
'twitterpseudo',
4703 'facebook' =>
'facebookpseudo',
4704 'linkedin' =>
'linkedinpseudo',
4706 $this->url =
'http://www.specimen.com';
4708 $this->phone =
'0909090901';
4709 $this->phone_mobile =
'0909090901';
4710 $this->fax =
'0909090909';
4712 $this->code_client =
'CC-'.dol_print_date($now,
'dayhourlog');
4713 $this->code_fournisseur =
'SC-'.dol_print_date($now,
'dayhourlog');
4714 $this->typent_code =
'TE_OTHER';
4715 $this->capital = 10000;
4717 $this->prospect = 1;
4718 $this->fournisseur = 1;
4719 $this->tva_assuj = 1;
4720 $this->tva_intra =
'EU1234567';
4721 $this->note_public =
'This is a comment (public)';
4722 $this->note_private =
'This is a comment (private)';
4724 $this->idprof1 =
'idprof1';
4725 $this->idprof2 =
'idprof2';
4726 $this->idprof3 =
'idprof3';
4727 $this->idprof4 =
'idprof4';
4728 $this->idprof5 =
'idprof5';
4729 $this->idprof6 =
'idprof6';
4742 $sql =
"SELECT t.localtax1, t.localtax2";
4743 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4744 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4745 $sql .=
" AND t.active = 1";
4746 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
4747 if (empty($localTaxNum)) {
4748 $sql .=
" AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
4749 } elseif ($localTaxNum == 1) {
4750 $sql .=
" AND t.localtax1_type <> '0'";
4751 } elseif ($localTaxNum == 2) {
4752 $sql .=
" AND t.localtax2_type <> '0'";
4755 $resql = $this->db->query($sql);
4757 return ($this->db->num_rows($resql) > 0);
4770 $sql =
"SELECT t.rowid";
4771 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4772 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4773 $sql .=
" AND t.active = 1 AND t.recuperableonly = 1";
4774 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
4777 $resql = $this->db->query($sql);
4779 return ($this->db->num_rows($resql) > 0);
4793 $sql =
"SELECT COUNT(*) as nb";
4794 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_revenuestamp as r, ".MAIN_DB_PREFIX.
"c_country as c";
4795 $sql .=
" WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4796 $sql .=
" AND r.active = 1";
4799 $resql = $this->db->query($sql);
4801 $obj = $this->db->fetch_object($resql);
4802 return ($obj->nb > 0);
4804 $this->error = $this->db->lasterror();
4832 if ($fk_prospectlevel !=
'') {
4833 $label = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
4835 if ($label ==
"ProspectLevel".$fk_prospectlevel) {
4836 $label = $langs->getLabelFromKey($this->db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
4852 return $this->
LibProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
4874 $langs->load(
'customers');
4877 if ($status ==
'-1' || $status ==
'ST_NO') {
4878 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect-1");
4879 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4880 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect0");
4881 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4882 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect1");
4883 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4884 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect2");
4885 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4886 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect3");
4888 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);
4890 } elseif ($mode == 3) {
4891 if ($status ==
'-1' || $status ==
'ST_NO') {
4892 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto,
'class="inline-block valignmiddle"');
4893 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4894 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto,
'class="inline-block valignmiddle"');
4895 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4896 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto,
'class="inline-block valignmiddle"');
4897 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4898 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto,
'class="inline-block valignmiddle"');
4899 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4900 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto,
'class="inline-block valignmiddle"');
4902 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label,
'0', $picto,
'class="inline-block valignmiddle"');
4904 } elseif ($mode == 4) {
4905 if ($status ==
'-1' || $status ==
'ST_NO') {
4906 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect-1");
4907 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
4908 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect0");
4909 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
4910 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect1");
4911 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
4912 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect2");
4913 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
4914 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect3");
4916 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);
4920 return "Error, mode/status not found";
4932 if ($mode ==
'supplier') {
4933 $table =
'supplier_proposal';
4936 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4937 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4938 if ($mode ==
'supplier') {
4939 $sql .=
" AND entity IN (".getEntity(
'supplier_proposal').
")";
4941 $sql .=
" AND entity IN (".getEntity(
'propal').
")";
4944 dol_syslog(
"getOutstandingProposals for fk_soc = ".((
int) $this->
id), LOG_DEBUG);
4946 $resql = $this->db->query($sql);
4948 $outstandingOpened = 0;
4949 $outstandingTotal = 0;
4950 $outstandingTotalIncTax = 0;
4951 $arrayofref = array();
4952 while ($obj = $this->db->fetch_object($resql)) {
4953 $arrayofref[$obj->rowid] = $obj->ref;
4954 $outstandingTotal += $obj->total_ht;
4955 $outstandingTotalIncTax += $obj->total_ttc;
4956 if ($obj->status != 0) {
4958 $outstandingOpened += $obj->total_ttc;
4961 return array(
'opened' => $outstandingOpened,
'total_ht' => $outstandingTotal,
'total_ttc' => $outstandingTotalIncTax,
'refs' => $arrayofref);
4975 $table =
'commande';
4976 if ($mode ==
'supplier') {
4977 $table =
'commande_fournisseur';
4980 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
4981 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
4982 if ($mode ==
'supplier') {
4983 $sql .=
" AND entity IN (".getEntity(
'supplier_order').
")";
4985 $sql .=
" AND entity IN (".getEntity(
'commande').
")";
4988 dol_syslog(
"getOutstandingOrders", LOG_DEBUG);
4989 $resql = $this->db->query($sql);
4991 $outstandingOpened = 0;
4992 $outstandingTotal = 0;
4993 $outstandingTotalIncTax = 0;
4994 $arrayofref = array();
4995 while ($obj = $this->db->fetch_object($resql)) {
4996 $arrayofref[$obj->rowid] = $obj->ref;
4997 $outstandingTotal += $obj->total_ht;
4998 $outstandingTotalIncTax += $obj->total_ttc;
4999 if ($obj->status != 0) {
5001 $outstandingOpened += $obj->total_ttc;
5004 return array(
'opened' => $outstandingOpened,
'total_ht' => $outstandingTotal,
'total_ttc' => $outstandingTotalIncTax,
'refs' => $arrayofref);
5019 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
5022 if ($mode ==
'supplier') {
5023 $table =
'facture_fourn';
5035 $sql =
"SELECT rowid, ref, total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table.
" as f";
5036 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
5037 if (!empty($late)) {
5038 $sql .=
" AND date_lim_reglement < '".$this->db->idate($today).
"'";
5040 if ($mode ==
'supplier') {
5041 $sql .=
" AND entity IN (".getEntity(
'facture_fourn').
")";
5043 $sql .=
" AND entity IN (".getEntity(
'invoice').
")";
5046 dol_syslog(
"getOutstandingBills", LOG_DEBUG);
5047 $resql = $this->db->query($sql);
5049 $outstandingOpened = 0;
5050 $outstandingTotal = 0;
5051 $outstandingTotalIncTax = 0;
5052 $arrayofref = array();
5053 $arrayofrefopened = array();
5054 if ($mode ==
'supplier') {
5055 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
5058 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
5059 $tmpobject =
new Facture($this->db);
5061 while ($obj = $this->db->fetch_object($resql)) {
5062 $arrayofref[$obj->rowid] = $obj->ref;
5063 $tmpobject->id = $obj->rowid;
5065 if ($obj->status != $tmpobject::STATUS_DRAFT
5066 && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code ==
'replaced')
5068 $outstandingTotal += $obj->total_ht;
5069 $outstandingTotalIncTax += $obj->total_ttc;
5075 && $obj->status != $tmpobject::STATUS_DRAFT
5076 && $obj->status != $tmpobject::STATUS_ABANDONED
5077 && $obj->status != $tmpobject::STATUS_CLOSED) {
5079 $paiement = $tmpobject->getSommePaiement();
5080 $creditnotes = $tmpobject->getSumCreditNotesUsed();
5081 $deposits = $tmpobject->getSumDepositsUsed();
5083 $remaintopay = ($obj->total_ttc - $paiement - $creditnotes - $deposits);
5084 $outstandingOpened += $remaintopay;
5090 $remainingcreditnote = $tmpobject->getSumFromThisCreditNotesNotUsed();
5091 $remaintopay -= $remainingcreditnote;
5092 $outstandingOpened -= $remainingcreditnote;
5096 $arrayofrefopened[$obj->rowid] = $obj->ref;
5099 return array(
'opened' => $outstandingOpened,
'total_ht' => $outstandingTotal,
'total_ttc' => $outstandingTotalIncTax,
'refs' => $arrayofref,
'refsopened' => $arrayofrefopened);
5101 dol_syslog(
"Sql error ".$this->db->lasterror, LOG_ERR);
5128 $langs->load(
'companies');
5131 return $langs->trans(
"NorProspectNorCustomer");
5132 } elseif ($status == 1) {
5133 return $langs->trans(
"Customer");
5134 } elseif ($status == 2) {
5135 return $langs->trans(
"Prospect");
5136 } elseif ($status == 3) {
5137 return $langs->trans(
"ProspectCustomer");
5155 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
5159 if (!empty($moreparams) && !empty($moreparams[
'use_companybankid'])) {
5160 $modelpath =
"core/modules/bank/doc/";
5162 include_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
5164 $result = $companybankaccount->fetch($moreparams[
'use_companybankid']);
5166 dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
5168 $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
5169 $this->last_main_doc = $companybankaccount->last_main_doc;
5176 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_COMPANY_ADDON_PDF_NotDefined");
5181 if (!isset($this->bank_account)) {
5182 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
5185 $result = $bac->fetch(0,
'', $this->
id);
5187 $this->bank_account = $bac;
5189 $this->bank_account =
'';
5193 $modelpath =
"core/modules/societe/doc/";
5195 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
5215 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
5218 if (!in_array($type_categ, array(Categorie::TYPE_CUSTOMER, Categorie::TYPE_SUPPLIER))) {
5219 dol_syslog(__METHOD__.
': Type '.$type_categ.
'is an unknown company category type. Done nothing.', LOG_ERR);
5223 return parent::setCategoriesCommon($categories, $type_categ);
5238 if (!is_array($salesrep)) {
5239 $salesrep = array($salesrep);
5243 $to_add = $salesrep;
5244 if ($onlyAdd ===
false) {
5249 if (is_array($existing)) {
5250 $to_del = array_diff($existing, $salesrep);
5251 $to_add = array_diff($salesrep, $existing);
5258 foreach ($to_del as $del) {
5261 foreach ($to_add as $add) {
5269 return $error ? -1 : 1;
5285 $result = $this->
setValueFrom(
'fk_typent', $typent_id,
'',
null,
'',
'', $user,
'COMPANY_MODIFY');
5288 $this->typent_id = $typent_id;
5289 $this->typent_code =
dol_getIdFromCode($this->db, $this->typent_id,
'c_typent',
'id',
'code');
5310 if ($origin_id == $dest_id) {
5311 dol_syslog(
'Error: Try to merge a thirdparty into itself');
5317 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5318 $sql .=
' WHERE fk_soc = '.(int) $dest_id.
' AND fk_user IN ( ';
5319 $sql .=
' SELECT fk_user ';
5320 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5321 $sql .=
' WHERE fk_soc = '.(int) $origin_id.
') ';
5323 $resql = $dbs->
query($sql);
5325 $dbs->
query(
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_commerciaux WHERE rowid = '.((
int) $obj->rowid));
5332 'societe_commerciaux',
5335 'societe_remise_except',
5354 global $user, $langs,
$conf;
5358 if ($type ==
'buy') {
5359 $field =
'accountancy_code_buy';
5360 } elseif ($type ==
'sell') {
5361 $field =
'accountancy_code_sell';
5366 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ";
5367 $sql .= $field.
" = '".$this->db->escape($value).
"'";
5368 $sql .=
" WHERE rowid = ".((int) $this->
id);
5370 dol_syslog(get_class($this).
"::".__FUNCTION__, LOG_DEBUG);
5371 $resql = $this->db->query($sql);
5375 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
5377 $result = $interface->run_triggers(
'COMPANY_MODIFY', $this, $user, $langs,
$conf);
5379 $this->errors = $interface->errors;
5380 $this->db->rollback();
5385 $this->$field = $value;
5387 $this->db->commit();
5390 $this->error = $this->db->lasterror();
5391 $this->db->rollback();
5404 require_once DOL_DOCUMENT_ROOT.
'/partnership/class/partnership.class.php';
5406 $this->partnerships[] = array();
5420 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
5422 $return =
'<div class="box-flex-item box-flex-grow-zero">';
5423 $return .=
'<div class="info-box info-box-sm">';
5424 $return .=
'<span class="info-box-icon bg-infobox-action">';
5426 $return .=
'</span>';
5427 $return .=
'<div class="info-box-content">';
5428 $return .=
'<div class="info-box-ref inline-block tdoverflowmax125 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref);
5429 $return .=
'</div>';
5430 if (!empty($this->phone)) {
5431 $return .=
'<div class="inline-block valignmiddle">';
5433 $return .=
dol_print_phone($this->phone, $this->country_code, 0, $this->
id,
'tel',
'hidenum',
'phone', $this->phone, 0,
'paddingleft paddingright');
5434 $return .=
'</div>';
5436 if (!empty($this->
email)) {
5437 $return .=
'<div class="inline-block valignmiddle">';
5438 $return .=
dol_print_email($this->
email, 0, $this->
id,
'thirdparty', -1, 1, 2,
'paddingleft paddingright');
5439 $return .=
'</div>';
5441 if ($selected >= 0) {
5442 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
5444 if (property_exists($this,
'code_client')) {
5445 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->code_client.
'</span>';
5447 if (method_exists($this,
'getLibStatut')) {
5448 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
5450 $return .=
'</div>';
5451 $return .=
'</div>';
5452 $return .=
'</div>';
5473 $sql =
"SELECT sc.rowid, sc.fk_socpeople as id, sc.fk_c_type_contact";
5474 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
5475 $sql .=
", t.civility as civility, t.lastname as lastname, t.firstname, t.email";
5476 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_label";
5477 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact tc";
5478 $sql .=
", ".$this->db->prefix().
"societe_contacts sc";
5479 $sql .=
" LEFT JOIN ".$this->db->prefix().
"socpeople t on sc.fk_socpeople = t.rowid";
5480 $sql .=
" WHERE sc.fk_soc = ".((int) $this->
id);
5481 $sql .=
" AND sc.fk_c_type_contact = tc.rowid";
5482 if (!empty($element)) {
5483 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
5486 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
5488 $sql .=
" AND sc.entity IN (".getEntity($this->element).
")";
5489 $sql .=
" AND tc.source = 'external'";
5490 $sql .=
" AND tc.active = 1";
5492 $sql .=
" ORDER BY t.lastname ASC";
5494 dol_syslog(get_class($this).
"::getContacts", LOG_DEBUG);
5495 $resql = $this->db->query($sql);
5497 $num = $this->db->num_rows($resql);
5500 $obj = $this->db->fetch_object($resql);
5503 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
5504 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_label);
5506 'source' => $obj->source,
5507 'socid' => $obj->socid,
5509 'nom' => $obj->lastname,
5510 'civility' => $obj->civility,
5511 'lastname' => $obj->lastname,
5512 'firstname' => $obj->firstname,
5513 'email' => $obj->email,
5514 'login' => (empty($obj->login) ?
'' : $obj->login),
5515 'photo' => (empty($obj->photo) ?
'' : $obj->photo),
5516 'statuscontact' => $obj->statuscontact,
5517 'rowid' => $obj->rowid,
5518 'code' => $obj->code,
5519 'element' => $obj->element,
5520 'libelle' => $libelle_type,
5521 'status' => $obj->statuslink,
5522 'fk_c_type_contact' => $obj->fk_c_type_contact
5525 $tab[$i] = $obj->id;
5533 $this->error = $this->db->lasterror();
5551 global
$conf, $langs, $hookmanager, $user, $action;
5554 $soc_origin =
new Societe($this->db);
5556 dol_syslog(
"mergeCompany merge thirdparty id=".$soc_origin_id.
" (will be deleted) into the thirdparty id=".$this->id);
5558 if (!$error && $soc_origin->fetch($soc_origin_id) < 1) {
5559 $this->error = $langs->trans(
'ErrorRecordNotFound');
5567 $this->client |= $soc_origin->client;
5568 $this->fournisseur |= $soc_origin->fournisseur;
5569 $listofproperties = array(
5570 'address',
'zip',
'town',
'state_id',
'country_id',
'phone',
'phone_mobile',
'fax',
'email',
'socialnetworks',
'url',
'barcode',
5571 'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
5572 'tva_intra',
'effectif_id',
'forme_juridique',
'remise_percent',
'remise_supplier_percent',
'mode_reglement_supplier_id',
'cond_reglement_supplier_id',
'name_bis',
5573 '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',
5574 'code_client',
'code_fournisseur',
'code_compta',
'code_compta_fournisseur',
5575 'model_pdf',
'webservices_url',
'webservices_key',
'accountancy_code_sell',
'accountancy_code_buy',
'typent_id'
5577 foreach ($listofproperties as $property) {
5578 if (empty($this->$property)) {
5579 $this->$property = $soc_origin->$property;
5583 if ($this->typent_id == -1) {
5584 $this->typent_id = $soc_origin->typent_id;
5588 $listofproperties = array(
5589 'note_public',
'note_private'
5591 foreach ($listofproperties as $property) {
5592 $this->$property =
dol_concatdesc($this->$property, $soc_origin->$property);
5596 if (is_array($soc_origin->array_options)) {
5597 foreach ($soc_origin->array_options as $key => $val) {
5598 if (empty($this->array_options[$key])) {
5599 $this->array_options[$key] = $val;
5605 if (empty($this->name_bis) && $this->
name != $soc_origin->name) {
5606 $this->name_bis = $this->name;
5610 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
5613 $custcats_ori = $static_cat->containing($soc_origin->id,
'customer',
'id');
5614 $custcats = $static_cat->containing($this->
id,
'customer',
'id');
5615 $custcats = array_merge($custcats, $custcats_ori);
5618 $suppcats_ori = $static_cat->containing($soc_origin->id,
'supplier',
'id');
5619 $suppcats = $static_cat->containing($this->
id,
'supplier',
'id');
5620 $suppcats = array_merge($suppcats, $suppcats_ori);
5624 if ($soc_origin->code_client == $this->code_client
5625 || $soc_origin->code_fournisseur == $this->code_fournisseur
5626 || $soc_origin->barcode == $this->barcode) {
5627 dol_syslog(
"We clean customer and supplier code so we will be able to make the update of target");
5628 $soc_origin->code_client =
'';
5629 $soc_origin->code_fournisseur =
'';
5630 $soc_origin->barcode =
'';
5631 $soc_origin->update($soc_origin->id, $user, 0, 1, 1,
'merge');
5635 $result = $this->
update($this->
id, $user, 0, 1, 1,
'merge');
5644 'Adherent' =>
'/adherents/class/adherent.class.php',
5646 'ActionComm' =>
'/comm/action/class/actioncomm.class.php',
5647 'Propal' =>
'/comm/propal/class/propal.class.php',
5648 'Commande' =>
'/commande/class/commande.class.php',
5649 'Facture' =>
'/compta/facture/class/facture.class.php',
5650 'FactureRec' =>
'/compta/facture/class/facture-rec.class.php',
5651 'LignePrelevement' =>
'/compta/prelevement/class/ligneprelevement.class.php',
5652 'Contact' =>
'/contact/class/contact.class.php',
5653 'Contrat' =>
'/contrat/class/contrat.class.php',
5654 'Expedition' =>
'/expedition/class/expedition.class.php',
5655 'CommandeFournisseur' =>
'/fourn/class/fournisseur.commande.class.php',
5656 'FactureFournisseur' =>
'/fourn/class/fournisseur.facture.class.php',
5657 'FactureFournisseurRec' =>
'/fourn/class/fournisseur.facture-rec.class.php',
5658 'Reception' =>
'/reception/class/reception.class.php',
5659 'SupplierProposal' =>
'/supplier_proposal/class/supplier_proposal.class.php',
5660 'ProductFournisseur' =>
'/fourn/class/fournisseur.product.class.php',
5661 'Product' =>
'/product/class/product.class.php',
5663 'Project' =>
'/projet/class/project.class.php',
5664 'User' =>
'/user/class/user.class.php',
5665 'Account' =>
'/compta/bank/class/account.class.php',
5666 'ConferenceOrBoothAttendee' =>
'/eventorganization/class/conferenceorboothattendee.class.php',
5667 'Societe' =>
'/societe/class/societe.class.php',
5670 if ($this->db->DDLListTables(
$conf->db->name, $this->db->prefix().
'delivery')) {
5671 $objects[
'Delivery'] =
'/delivery/class/delivery.class.php';
5673 if ($this->db->DDLListTables(
$conf->db->name, $this->db->prefix().
'mrp_mo')) {
5674 $objects[
'Mo'] =
'/mrp/class/mo.class.php';
5676 if ($this->db->DDLListTables(
$conf->db->name, $this->db->prefix().
'don')) {
5677 $objects[
'Don'] =
'/don/class/don.class.php';
5679 if ($this->db->DDLListTables(
$conf->db->name, $this->db->prefix().
'partnership')) {
5680 $objects[
'PartnerShip'] =
'/partnership/class/partnership.class.php';
5682 if ($this->db->DDLListTables(
$conf->db->name, $this->db->prefix().
'fichinter')) {
5683 $objects[
'Fichinter'] =
'/fichinter/class/fichinter.class.php';
5685 if ($this->db->DDLListTables(
$conf->db->name, $this->db->prefix().
'ticket')) {
5686 $objects[
'Ticket'] =
'/ticket/class/ticket.class.php';
5690 foreach ($objects as $object_name => $object_file) {
5700 require_once DOL_DOCUMENT_ROOT.$object_file;
5702 if (!$error && !$object_name::replaceThirdparty($this->db, $soc_origin->id, $this->id)) {
5704 $this->error = $this->db->lasterror();
5712 $parameters = array(
'soc_origin' => $soc_origin->id,
'soc_dest' => $this->id);
5713 $reshook = $hookmanager->executeHooks(
'replaceThirdparty', $parameters, $this, $action);
5716 $this->error = $hookmanager->error;
5717 $this->errors = $hookmanager->errors;
5724 $this->context = array(
'merge' => 1,
'mergefromid' => $soc_origin->id,
'mergefromname' => $soc_origin->name);
5727 $result = $this->
call_trigger(
'COMPANY_MODIFY', $user);
5736 if ($soc_origin->delete($soc_origin->id, $user) < 1) {
5737 $this->error = $soc_origin->error;
5738 $this->errors = $soc_origin->errors;
5746 if (!empty(
$conf->societe->multidir_output[$this->entity])) {
5747 $srcdir =
$conf->societe->multidir_output[$this->entity].
"/".$soc_origin->id;
5748 $destdir =
$conf->societe->multidir_output[$this->entity].
"/".$this->id;
5752 foreach ($dirlist as $filetomove) {
5753 $destfile = $destdir.
'/'.$filetomove[
'relativename'];
5755 dol_move($filetomove[
'fullname'], $destfile,
'0', 0, 0, 1);
5763 $this->db->commit();
5766 $langs->load(
"errors");
5767 $this->error = $langs->trans(
'ErrorsThirdpartyMerge');
5768 $this->db->rollback();
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.
setErrorsFromObject($object)
setErrorsFromObject
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.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate 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 $mysoc in most ca...
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()
Return 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.
deprecatedProperties()
Provide list of deprecated properties and replacements.
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 clickable link of object (with optional picto)
const SUPPLIER
Third party supplier flag is a supplier.
check_codefournisseur()
Check supplier code.
contact_array()
Return 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.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=0)
Move a file into another name.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=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...
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
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 a 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...
div refaddress div address
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.