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.
'/core/lib/company.lib.php';
49require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
65 public $TRIGGER_PREFIX =
'COMPANY';
70 public $module =
'societe';
75 public $element =
'societe';
80 public $table_element =
'societe';
85 public $fk_element =
'fk_soc';
90 public $fieldsforcombobox =
'nom,name_alias';
95 protected $childtables = array(
96 'supplier_proposal' => array(
'name' =>
'SupplierProposal'),
97 'propal' => array(
'name' =>
'Proposal'),
98 'commande' => array(
'name' =>
'Order'),
99 'facture' => array(
'name' =>
'Invoice'),
100 'facture_rec' => array(
'name' =>
'RecurringInvoiceTemplate'),
101 'contrat' => array(
'name' =>
'Contract'),
102 'fichinter' => array(
'name' =>
'Fichinter'),
103 'facture_fourn' => array(
'name' =>
'SupplierInvoice'),
104 'commande_fournisseur' => array(
'name' =>
'SupplierOrder'),
105 'projet' => array(
'name' =>
'Project'),
106 'expedition' => array(
'name' =>
'Shipment'),
107 'prelevement_lignes' => array(
'name' =>
'DirectDebitRecord'),
114 protected $childtablesoncascade = array(
116 'product_fournisseur_price',
117 'product_customer_price_log',
118 'product_customer_price',
119 '@Contact:/contact/class/contact.class.php:fk_soc',
124 'societe_remise_except',
125 'societe_commerciaux',
135 public $picto =
'company';
141 public $restrictiononfksoc = 1;
147 public $SupplierCategories = array();
153 public $prefixCustomerIsRequired;
184 public $fields = array(
185 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'noteditable' => 1,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id',
'css' =>
'left'),
186 'parent' => array(
'type' =>
'integer',
'label' =>
'Parent',
'enabled' => 1,
'visible' => -1,
'position' => 20),
187 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 25),
188 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 30),
189 'nom' => array(
'type' =>
'varchar(128)',
'length' => 128,
'label' =>
'Nom',
'enabled' => 1,
'visible' => -1,
'position' => 35,
'showoncombobox' => 1,
'csslist' =>
'tdoverflowmax150'),
190 'name_alias' => array(
'type' =>
'varchar(128)',
'label' =>
'Name alias',
'enabled' => 1,
'visible' => -1,
'position' => 36,
'showoncombobox' => 2),
191 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 40,
'index' => 1),
192 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 45),
193 'code_client' => array(
'type' =>
'varchar(24)',
'label' =>
'CustomerCode',
'enabled' => 1,
'visible' => -1,
'position' => 55),
194 'code_fournisseur' => array(
'type' =>
'varchar(24)',
'label' =>
'SupplierCode',
'enabled' => 1,
'visible' => -1,
'position' => 60),
195 'code_compta' => array(
'type' =>
'varchar(24)',
'label' =>
'CustomerAccountancyCode',
'enabled' => 1,
'visible' => -1,
'position' => 65),
196 'code_compta_fournisseur' => array(
'type' =>
'varchar(24)',
'label' =>
'SupplierAccountancyCode',
'enabled' => 1,
'visible' => -1,
'position' => 70),
197 'address' => array(
'type' =>
'varchar(255)',
'label' =>
'Address',
'enabled' => 1,
'visible' => -1,
'position' => 75),
198 'zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Zip',
'enabled' => 1,
'visible' => -1,
'position' => 80),
199 'town' => array(
'type' =>
'varchar(50)',
'label' =>
'Town',
'enabled' => 1,
'visible' => -1,
'position' => 85),
200 'fk_departement' => array(
'type' =>
'integer',
'label' =>
'State',
'enabled' => 1,
'visible' => -1,
'position' => 90),
201 'fk_pays' => array(
'type' =>
'integer:Ccountry:core/class/ccountry.class.php',
'label' =>
'Country',
'enabled' => 1,
'visible' => -1,
'position' => 95),
202 'phone' => array(
'type' =>
'varchar(20)',
'label' =>
'Phone',
'enabled' => 1,
'visible' => -1,
'position' => 100),
203 'phone_mobile' => array(
'type' =>
'varchar(20)',
'label' =>
'PhoneMobile',
'enabled' => 1,
'visible' => -1,
'position' => 102),
204 'fax' => array(
'type' =>
'varchar(20)',
'label' =>
'Fax',
'enabled' => 1,
'visible' => -1,
'position' => 105),
205 'url' => array(
'type' =>
'varchar(255)',
'label' =>
'Url',
'enabled' => 1,
'visible' => -1,
'position' => 110),
206 'email' => array(
'type' =>
'varchar(128)',
'label' =>
'Email',
'enabled' => 1,
'visible' => -1,
'position' => 115),
207 'socialnetworks' => array(
'type' =>
'text',
'label' =>
'Socialnetworks',
'enabled' => 1,
'visible' => -1,
'position' => 120),
208 'fk_effectif' => array(
'type' =>
'integer',
'label' =>
'Workforce',
'enabled' => 1,
'visible' => -1,
'position' => 170),
209 'fk_typent' => array(
'type' =>
'integer',
'label' =>
'ThirdPartyType',
'enabled' => 1,
'visible' => -1,
'position' => 175,
'csslist' =>
'minwidth200'),
210 'fk_forme_juridique' => array(
'type' =>
'integer',
'label' =>
'JuridicalStatus',
'enabled' => 1,
'visible' => -1,
'position' => 180),
211 'birth' => array(
'type' =>
'date',
'label' =>
'CompnanyBirthDate',
'enabled' => 1,
'visible' => -1,
'position' => 182),
212 'fk_currency' => array(
'type' =>
'varchar(3)',
'label' =>
'Currency',
'enabled' => 1,
'visible' => -1,
'position' => 185),
213 'siren' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof1',
'enabled' => 1,
'visible' => -1,
'position' => 190),
214 'siret' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof2',
'enabled' => 1,
'visible' => -1,
'position' => 195),
215 'ape' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof3',
'enabled' => 1,
'visible' => -1,
'position' => 200),
216 'idprof4' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof4',
'enabled' => 1,
'visible' => -1,
'position' => 205),
217 'idprof5' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof5',
'enabled' => 1,
'visible' => -1,
'position' => 206),
218 'idprof6' => array(
'type' =>
'varchar(128)',
'label' =>
'Idprof6',
'enabled' => 1,
'visible' => -1,
'position' => 207),
219 'tva_intra' => array(
'type' =>
'varchar(20)',
'label' =>
'Tva intra',
'enabled' => 1,
'visible' => -1,
'position' => 210),
220 'capital' => array(
'type' =>
'double(24,8)',
'label' =>
'Capital',
'enabled' => 1,
'visible' => -1,
'position' => 215),
221 'fk_stcomm' => array(
'type' =>
'integer',
'label' =>
'CommercialStatus',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 220),
222 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 225),
223 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 230),
224 'client' => array(
'type' =>
'tinyint(4)',
'label' =>
'Client',
'enabled' => 1,
'visible' => -1,
'position' => 240),
225 'fournisseur' => array(
'type' =>
'tinyint(4)',
'label' =>
'Fournisseur',
'enabled' => 1,
'visible' => -1,
'position' => 245),
226 'supplier_account' => array(
'type' =>
'varchar(32)',
'label' =>
'Supplier account',
'enabled' => 1,
'visible' => -1,
'position' => 250),
227 'fk_prospectlevel' => array(
'type' =>
'varchar(12)',
'label' =>
'ProspectLevel',
'enabled' => 1,
'visible' => -1,
'position' => 255),
228 'customer_bad' => array(
'type' =>
'tinyint(4)',
'label' =>
'Customer bad',
'enabled' => 1,
'visible' => -1,
'position' => 260),
229 'customer_rate' => array(
'type' =>
'double',
'label' =>
'Customer rate',
'enabled' => 1,
'visible' => -1,
'position' => 265),
230 'supplier_rate' => array(
'type' =>
'double',
'label' =>
'Supplier rate',
'enabled' => 1,
'visible' => -1,
'position' => 270),
231 'fk_user_creat' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -2,
'position' => 275),
232 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 280),
235 'mode_reglement' => array(
'type' =>
'smallint(6)',
'label' =>
'Mode reglement',
'enabled' => 1,
'visible' => -1,
'position' => 295),
236 'cond_reglement' => array(
'type' =>
'tinyint(4)',
'label' =>
'Cond reglement',
'enabled' => 1,
'visible' => -1,
'position' => 300),
237 'deposit_percent' => array(
'type' =>
'varchar(63)',
'label' =>
'DepositPercent',
'enabled' => 1,
'visible' => -1,
'position' => 301),
238 'mode_reglement_supplier' => array(
'type' =>
'integer',
'label' =>
'Mode reglement supplier',
'enabled' => 1,
'visible' => -1,
'position' => 305),
239 'cond_reglement_supplier' => array(
'type' =>
'integer',
'label' =>
'Cond reglement supplier',
'enabled' => 1,
'visible' => -1,
'position' => 308),
240 'outstanding_limit' => array(
'type' =>
'double(24,8)',
'label' =>
'OutstandingBill',
'enabled' => 1,
'visible' => -1,
'position' => 310,
'isameasure' => 1),
241 'order_min_amount' => array(
'type' =>
'double(24,8)',
'label' =>
'Order min amount',
'enabled' =>
'isModEnabled("order") && getDolGlobalInt("ORDER_MANAGE_MIN_AMOUNT")',
'visible' => -1,
'position' => 315,
'isameasure' => 1),
242 'supplier_order_min_amount' => array(
'type' =>
'double(24,8)',
'label' =>
'Supplier order min amount',
'enabled' =>
'isModEnabled("order") && getDolGlobalInt("ORDER_MANAGE_MIN_AMOUNT")',
'visible' => -1,
'position' => 320,
'isameasure' => 1),
243 'fk_shipping_method' => array(
'type' =>
'integer',
'label' =>
'ShippingMode',
'enabled' => 1,
'visible' => -1,
'position' => 330),
244 'tva_assuj' => array(
'type' =>
'tinyint(4)',
'label' =>
'VATIsUsed',
'enabled' => 1,
'visible' => -1,
'position' => 335),
245 'localtax1_assuj' => array(
'type' =>
'tinyint(4)',
'label' =>
'LocalTax1IsUsed',
'enabled' => 1,
'visible' => -1,
'position' => 340),
246 'localtax1_value' => array(
'type' =>
'double(6,3)',
'label' =>
'LocalTax1 value',
'enabled' => 1,
'visible' => -1,
'position' => 345),
247 'localtax2_assuj' => array(
'type' =>
'tinyint(4)',
'label' =>
'LocalTax2IsUsed',
'enabled' => 1,
'visible' => -1,
'position' => 350),
248 'localtax2_value' => array(
'type' =>
'double(6,3)',
'label' =>
'LocalTax2 value',
'enabled' => 1,
'visible' => -1,
'position' => 355),
249 'vat_reverse_charge' => array(
'type' =>
'tinyint(4)',
'label' =>
'Vat reverse charge',
'enabled' => 1,
'visible' => -1,
'position' => 335),
250 'barcode' => array(
'type' =>
'varchar(255)',
'label' =>
'Barcode',
'enabled' => 1,
'visible' => -1,
'position' => 360),
251 'price_level' => array(
'type' =>
'integer',
'label' =>
'Price level',
'enabled' =>
'getDolGlobalString("PRODUIT_MULTIPRICES") || getDolGlobalString("PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES") || getDolGlobalString("PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES")',
'visible' => -1,
'position' => 365),
252 'default_lang' => array(
'type' =>
'varchar(6)',
'label' =>
'Default lang',
'enabled' => 1,
'visible' => -1,
'position' => 370),
253 'canvas' => array(
'type' =>
'varchar(32)',
'label' =>
'Canvas',
'enabled' => 1,
'visible' => -1,
'position' => 375),
254 'fk_barcode_type' => array(
'type' =>
'integer',
'label' =>
'Fk barcode type',
'enabled' => 1,
'visible' => -1,
'position' => 405),
255 'webservices_url' => array(
'type' =>
'varchar(255)',
'label' =>
'Webservices url',
'enabled' => 1,
'visible' => -1,
'position' => 410),
256 'webservices_key' => array(
'type' =>
'varchar(128)',
'label' =>
'Webservices key',
'enabled' => 1,
'visible' => -1,
'position' => 415),
257 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'Fk incoterms',
'enabled' => 1,
'visible' => -1,
'position' => 425),
258 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'Location incoterms',
'enabled' => 1,
'visible' => -1,
'position' => 430),
259 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 435),
260 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -1,
'position' => 270),
261 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Fk multicurrency',
'enabled' => 1,
'visible' => -1,
'position' => 440),
262 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Multicurrency code',
'enabled' => 1,
'visible' => -1,
'position' => 445),
263 'fk_account' => array(
'type' =>
'integer',
'label' =>
'PaymentBankAccount',
'enabled' => 1,
'visible' => -1,
'position' => 450),
264 'fk_warehouse' => array(
'type' =>
'integer',
'label' =>
'Warehouse',
'enabled' => 1,
'visible' => -1,
'position' => 455),
265 'logo' => array(
'type' =>
'varchar(255)',
'label' =>
'Logo',
'enabled' => 1,
'visible' => -1,
'position' => 400),
266 'logo_squarred' => array(
'type' =>
'varchar(255)',
'label' =>
'Logo squarred',
'enabled' => 1,
'visible' => -1,
'position' => 401),
267 'status' => array(
'type' =>
'tinyint(4)',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'position' => 500),
268 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 1000),
321 public $departement_code;
346 public $phone_mobile;
493 public $socialobject;
503 public $tva_assuj = 1;
513 public $vat_reverse_charge = 0;
519 public $localtax1_assuj;
523 public $localtax1_value;
527 public $localtax2_assuj;
531 public $localtax2_value;
546 public $typent_id = 0;
561 public $effectif_id = 0;
565 public $forme_juridique_code = 0;
570 public $forme_juridique;
579 public $remise_percent;
583 public $remise_supplier_percent;
588 public $mode_reglement_id;
592 public $cond_reglement_id;
596 public $deposit_percent;
600 public $mode_reglement_supplier_id;
604 public $cond_reglement_supplier_id;
608 public $transport_mode_supplier_id;
613 public $fk_prospectlevel;
625 public $user_modification;
632 public $user_creation;
644 public $prospect = 0;
662 public $code_fournisseur;
668 public $code_compta_client;
674 public $accountancy_code_customer_general;
680 public $accountancy_code_customer;
686 public $code_compta_fournisseur;
692 public $accountancy_code_supplier_general;
698 public $accountancy_code_supplier;
704 public $code_compta_product;
717 public $note_private;
735 public $stcomm_picto;
741 public $status_prospect_label;
752 public $outstanding_limit;
757 public $order_min_amount;
762 public $supplier_order_min_amount;
768 public $commercial_id;
780 public $default_lang;
811 public $webservices_url;
817 public $webservices_key;
837 public $logo_squarred;
842 public $logo_squarred_small;
847 public $logo_squarred_mini;
852 public $accountancy_code_sell;
857 public $accountancy_code_buy;
862 public $currency_code;
868 public $fk_multicurrency;
873 public $multicurrency_code;
879 public $fk_warehouse;
892 public $partnerships = array();
898 public $bank_account;
908 const STATUS_CEASED = 0;
909 const STATUS_INACTIVITY = 1;
950 'code_compta' =>
'code_compta_client',
952 + parent::deprecatedProperties();
966 $this->ismultientitymanaged = 1;
967 $this->isextrafieldmanaged = 1;
970 $this->fournisseur = 0;
971 $this->typent_id = 0;
972 $this->effectif_id = 0;
973 $this->forme_juridique_code = 0;
974 $this->tva_assuj = 1;
975 $this->vat_reverse_charge = 0;
979 $this->fields[
'address'][
'showoncombobox'] =
getDolGlobalInt(
'COMPANY_SHOW_ADDRESS_SELECTLIST');
980 $this->fields[
'zip'][
'showoncombobox'] =
getDolGlobalInt(
'COMPANY_SHOW_ADDRESS_SELECTLIST');
981 $this->fields[
'town'][
'showoncombobox'] =
getDolGlobalInt(
'COMPANY_SHOW_ADDRESS_SELECTLIST');
997 global $langs, $conf;
1002 if (empty($this->
status)) {
1005 $this->
name = $this->
name ? trim($this->
name) : trim((
string) $this->nom);
1007 $this->nom = $this->name;
1009 if (empty($this->client)) {
1012 if (empty($this->fournisseur)) {
1013 $this->fournisseur = 0;
1015 $this->import_key = trim((
string) $this->import_key);
1017 $this->code_compta_client = trim($this->code_compta_client ??
'');
1019 $this->accountancy_code_customer_general = trim($this->accountancy_code_customer_general ??
'');
1020 if ($this->accountancy_code_customer_general ===
'-1') {
1021 $this->accountancy_code_customer_general =
'';
1023 $this->accountancy_code_customer = trim((
string) $this->code_compta_client);
1024 $this->accountancy_code_supplier_general = trim($this->accountancy_code_supplier_general ??
'');
1025 if ($this->accountancy_code_supplier_general ===
'-1') {
1026 $this->accountancy_code_supplier_general =
'';
1028 $this->accountancy_code_supplier = trim((
string) $this->code_compta_fournisseur);
1029 $this->accountancy_code_buy = trim((
string) $this->accountancy_code_buy);
1030 $this->accountancy_code_sell = trim((
string) $this->accountancy_code_sell);
1032 if (!empty($this->multicurrency_code)) {
1035 if (empty($this->fk_multicurrency)) {
1036 $this->multicurrency_code =
'';
1037 $this->fk_multicurrency = 0;
1044 if (empty($this->date_creation)) {
1045 $this->date_creation = $now;
1051 if ($this->code_client == -1 || $this->code_client ===
'auto') {
1052 $this->get_codeclient($this, 0);
1054 if ($this->code_fournisseur ==
'-1' || $this->code_fournisseur ===
'auto') {
1055 $this->get_codefournisseur($this, 1);
1060 $result = $this->
verify();
1065 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe (";
1067 $sql .=
", name_alias";
1070 $sql .=
", fk_user_creat";
1071 $sql .=
", fk_typent";
1074 $sql .=
", ref_ext";
1075 $sql .=
", fk_stcomm";
1076 $sql .=
", fk_incoterms";
1077 $sql .=
", location_incoterms";
1078 $sql .=
", import_key";
1079 $sql .=
", fk_multicurrency";
1080 $sql .=
", multicurrency_code";
1083 $sql .=
", vat_reverse_charge";
1084 $sql .=
", accountancy_code_buy";
1085 $sql .=
", accountancy_code_sell";
1087 $sql .=
") VALUES ('".$this->db->escape($this->name).
"',";
1088 $sql .=
" '".$this->db->escape($this->name_alias).
"',";
1089 $sql .=
" ".((int) $this->entity).
",";
1090 $sql .=
" '".$this->db->idate($this->date_creation).
"'";
1091 $sql .=
", ".(!empty($user->id) ? ((int) $user->id) :
"null");
1092 $sql .=
", ".(!empty($this->typent_id) ? ((int) $this->typent_id) :
"null");
1093 $sql .=
", ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null");
1094 $sql .=
", ".((int) $this->
status);
1095 $sql .=
", ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1097 $sql .=
", ".(int) $this->fk_incoterms;
1098 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1099 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1100 $sql .=
", ".(int) $this->fk_multicurrency;
1101 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1102 $sql .=
", ".(empty($this->ip) ?
"null" :
"'".$this->db->escape($this->ip).
"'");
1104 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1105 $sql .=
", '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1106 $sql .=
", '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1110 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1112 $result = $this->db->query($sql);
1114 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"societe");
1116 $ret = $this->
update($this->
id, $user, 0, 1, 1,
'add');
1120 $this->db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int) $conf->entity));
1122 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
1125 $sql .=
", vat_reverse_charge";
1126 $sql .=
", accountancy_code_customer_general";
1127 $sql .=
", accountancy_code_customer";
1128 $sql .=
", accountancy_code_supplier_general";
1129 $sql .=
", accountancy_code_supplier";
1130 $sql .=
", accountancy_code_buy";
1131 $sql .=
", accountancy_code_sell";
1132 $sql .=
") VALUES (";
1134 $sql .=
", ".((int) $conf->entity);
1135 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1136 $sql .=
", '".$this->db->escape($this->accountancy_code_customer_general).
"'";
1137 $sql .=
", '".$this->db->escape($this->accountancy_code_customer).
"'";
1138 $sql .=
", '".$this->db->escape($this->accountancy_code_supplier_general).
"'";
1139 $sql .=
", '".$this->db->escape($this->accountancy_code_supplier).
"'";
1140 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1141 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1143 $result = $this->db->query($sql);
1146 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1151 if ($this->commercial_id !=
'' && $this->commercial_id != -1) {
1153 } elseif (!$user->hasRight(
'societe',
'client',
'voir')) {
1161 $result = $this->call_trigger(
'COMPANY_CREATE', $user);
1172 dol_syslog(get_class($this).
"::Create success id=".$this->
id);
1173 $this->db->commit();
1176 dol_syslog(get_class($this).
"::Create echec update ".$this->error.(empty($this->errors) ?
'' :
' '.implode(
',', $this->errors)), LOG_ERR);
1177 $this->db->rollback();
1181 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1182 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", $this->name);
1185 $this->error = $this->db->lasterror();
1188 $this->db->rollback();
1192 $this->db->rollback();
1193 dol_syslog(get_class($this).
"::Create fails verify ".implode(
',', $this->errors), LOG_WARNING);
1216 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1217 $contact =
new Contact($this->db);
1219 $contact->name = $this->name_bis;
1220 $contact->firstname = $this->firstname;
1221 $contact->civility_id = $this->civility_id;
1222 $contact->socid = $this->id;
1223 $contact->statut = 1;
1224 $contact->status = 1;
1226 $contact->country_id = $this->country_id;
1227 $contact->state_id = $this->state_id;
1228 $contact->address = $this->address;
1229 $contact->email = $this->email;
1230 $contact->zip = $this->zip;
1231 $contact->town = $this->town;
1233 $contact->phone_pro = $this->phone;
1238 $contactId = $contact->create($user, $notrigger);
1239 if ($contactId < 0) {
1242 dol_syslog(get_class($this).
"::create_individual ERROR:".$this->error, LOG_ERR);
1245 if (empty($error) && is_array($tags) && !empty($tags)) {
1246 $result = $contact->setCategories($tags);
1250 dol_syslog(get_class($this).
"::create_individual Affect Tag ERROR:".$this->error, LOG_ERR);
1251 $contactId = $result;
1255 if (empty($error) &&
isModEnabled(
'mailing') && !empty($contact->email) && isset($no_email)) {
1256 $result = $contact->setNoEmail($no_email);
1259 dol_syslog(get_class($this).
"::create_individual set mailing status ERROR:".$this->error, LOG_ERR);
1260 $contactId = $result;
1264 if (empty($error)) {
1265 dol_syslog(get_class($this).
"::create_individual success");
1266 $this->db->commit();
1268 $this->db->rollback();
1285 $this->errors = array();
1289 $this->nom = $this->name;
1292 $this->errors[] =
'ErrorBadThirdPartyName';
1296 if ($this->client) {
1298 if ($rescode != 0 && $rescode != -5) {
1299 if ($rescode == -1) {
1300 $this->errors[] =
'ErrorBadCustomerCodeSyntax';
1301 } elseif ($rescode == -2) {
1302 $this->errors[] =
'ErrorCustomerCodeRequired';
1303 } elseif ($rescode == -3) {
1304 $this->errors[] =
'ErrorCustomerCodeAlreadyUsed';
1305 } elseif ($rescode == -4) {
1306 $this->errors[] =
'ErrorPrefixRequired';
1308 $this->errors[] =
'ErrorUnknownOnCustomerCodeCheck';
1315 if ($this->fournisseur) {
1317 if ($rescode != 0 && $rescode != -5) {
1318 if ($rescode == -1) {
1319 $this->errors[] =
'ErrorBadSupplierCodeSyntax';
1320 } elseif ($rescode == -2) {
1321 $this->errors[] =
'ErrorSupplierCodeRequired';
1322 } elseif ($rescode == -3) {
1323 $this->errors[] =
'ErrorSupplierCodeAlreadyUsed';
1324 } elseif ($rescode == -4) {
1325 $this->errors[] =
'ErrorPrefixRequired';
1327 $this->errors[] =
'ErrorUnknownOnSupplierCodeCheck';
1334 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL',
'TVA_INTRA',
'ACCOUNTANCY_CODE_CUSTOMER',
'ACCOUNTANCY_CODE_SUPPLIER');
1335 foreach ($array_to_check as $key) {
1336 $keymin = strtolower($key);
1337 $keyfield_db = $keymin;
1338 if ($key ==
'ACCOUNTANCY_CODE_CUSTOMER') {
1339 $keymin =
'code_compta_client';
1340 $keyfield_db =
'code_compta';
1341 } elseif ($key ==
'ACCOUNTANCY_CODE_SUPPLIER') {
1342 $keymin =
'code_compta_fournisseur';
1343 $keyfield_db =
'code_compta_fournisseur';
1345 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
1346 $vallabel = $this->$keymin;
1351 if ($mysoc->country_id > 0 && $this->country_id ==
$mysoc->country_id) {
1352 $idprof_mandatory =
'SOCIETE_'.$key.
'_MANDATORY';
1354 $langs->load(
"errors");
1356 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->transcountry(
'ProfId'.$i, $this->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1363 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1364 $langs->load(
"errors");
1366 $this->errors[] = $langs->transcountry(
'ProfId'.$i, $this->country_code).
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1370 if ($key ==
'EMAIL') {
1373 $langs->load(
"errors");
1375 $this->errors[] = $langs->trans(
"ErrorBadEMail", $this->
email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1380 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1381 $langs->load(
"errors");
1383 $this->errors[] = $langs->trans(
'Email').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1386 } elseif ($key ==
'TVA_INTRA') {
1389 if ($this->
id_prof_exists($keymin, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1390 $langs->load(
"errors");
1392 $this->errors[] = $langs->trans(
'VATIntra').
" ".$langs->trans(
"ErrorProdIdAlreadyExist", $vallabel).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1395 if ($this->tva_assuj && !$vallabel &&
getDolGlobalString(
'SOCIETE_VAT_INTRA_MANDATORY')) {
1396 $langs->load(
"errors");
1398 $this->errors[] = $langs->trans(
"ErrorProdIdIsMandatory", $langs->trans(
'VATIntra')).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1400 } elseif ($key ==
'ACCOUNTANCY_CODE_CUSTOMER' && !empty($this->client)) {
1403 if ($this->
id_prof_exists($keyfield_db, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1404 $langs->loadLangs(array(
"errors",
'compta'));
1406 $this->errors[] = $langs->trans(
'CustomerAccountancyCodeShort') .
" " . $langs->trans(
"ErrorProdIdAlreadyExist", $vallabel) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1411 if (
getDolGlobalString(
'SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_MANDATORY') && (!isset($vallabel) || trim($vallabel) ===
'')) {
1412 $langs->loadLangs(array(
"errors",
'compta'));
1414 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
'CustomerAccountancyCodeShort')) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1416 } elseif ($key ==
'ACCOUNTANCY_CODE_SUPPLIER' && !empty($this->fournisseur)) {
1419 if ($this->
id_prof_exists($keyfield_db, $vallabel, ($this->
id > 0 ? $this->
id : 0))) {
1420 $langs->loadLangs(array(
"errors",
'compta'));
1422 $this->errors[] = $langs->trans(
'SupplierAccountancyCodeShort') .
" " . $langs->trans(
"ErrorProdIdAlreadyExist", $vallabel) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1427 if (
getDolGlobalString(
'SOCIETE_ACCOUNTANCY_CODE_SUPPLIER_MANDATORY') && (!isset($vallabel) || trim($vallabel) ===
'')) {
1428 $langs->loadLangs(array(
"errors",
'compta'));
1430 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
'SupplierAccountancyCodeShort')) .
' (' . $langs->trans(
"ForbiddenBySetupRules") .
')';
1455 public function update($id,
User $user, $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action =
'update', $nosyncmember = 1)
1457 global $langs, $conf, $hookmanager;
1459 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1464 if (empty($this->country_id) && !empty($this->country_code)) {
1465 $this->country_id =
dol_getIdFromCode($this->db, $this->country_code,
'c_country',
'code',
'rowid');
1468 if (empty($this->country_id) && !empty($this->country_code)) {
1469 $country_id =
getCountry($this->country_code,
'3');
1470 $this->country_id = is_int($country_id) ? $country_id : 0;
1475 dol_syslog(get_class($this).
"::Update id=".$id.
" call_trigger=".$call_trigger.
" allowmodcodeclient=".$allowmodcodeclient.
" allowmodcodefournisseur=".$allowmodcodefournisseur);
1481 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
1482 $this->
name = $this->
name ? trim($this->
name) : trim((
string) $this->nom);
1483 $this->nom = $this->name;
1484 $this->name_alias = trim((
string) $this->name_alias);
1485 $this->ref_ext = (empty($this->ref_ext) ?
'' : trim($this->ref_ext));
1487 $this->zip = trim((
string) $this->zip);
1488 $this->town = trim((
string) $this->town);
1489 $this->state_id = (is_numeric($this->state_id)) ? (
int) $this->state_id : 0;
1490 $this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
1491 $this->phone = trim((
string) $this->phone);
1492 $this->phone = preg_replace(
"/\s/",
"", $this->phone);
1493 $this->phone = preg_replace(
"/\./",
"", $this->phone);
1494 $this->phone_mobile = trim((
string) $this->phone_mobile);
1495 $this->phone_mobile = preg_replace(
"/\s/",
"", $this->phone_mobile);
1496 $this->phone_mobile = preg_replace(
"/\./",
"", $this->phone_mobile);
1497 $this->fax = trim((
string) $this->fax);
1498 $this->fax = preg_replace(
"/\s/",
"", $this->fax);
1499 $this->fax = preg_replace(
"/\./",
"", $this->fax);
1501 $this->url = $this->url ?
clean_url($this->url, 0) :
'';
1502 $this->note_private = (empty($this->note_private) ?
'' : trim($this->note_private));
1503 $this->note_public = (empty($this->note_public) ?
'' : trim($this->note_public));
1504 $this->idprof1 = trim((
string) $this->idprof1);
1505 $this->idprof2 = trim((
string) $this->idprof2);
1506 $this->idprof3 = trim((
string) $this->idprof3);
1507 $this->idprof4 = trim((
string) $this->idprof4);
1508 $this->idprof5 = (!empty($this->idprof5) ? trim($this->idprof5) :
'');
1509 $this->idprof6 = (!empty($this->idprof6) ? trim($this->idprof6) :
'');
1510 $this->prefix_comm = trim((
string) $this->prefix_comm);
1511 $this->outstanding_limit =
price2num($this->outstanding_limit);
1512 $this->order_min_amount =
price2num($this->order_min_amount);
1513 $this->supplier_order_min_amount =
price2num($this->supplier_order_min_amount);
1515 $this->tva_assuj = (is_numeric($this->tva_assuj)) ? (
int) trim((
string) $this->tva_assuj) : 0;
1516 $this->tva_intra = trim((
string) $this->tva_intra);
1517 $this->vat_reverse_charge = empty($this->vat_reverse_charge) ? 0 : 1;
1518 if (empty($this->
status)) {
1522 if (!empty($this->multicurrency_code)) {
1525 if (empty($this->fk_multicurrency)) {
1526 $this->multicurrency_code =
'';
1527 $this->fk_multicurrency = 0;
1531 $this->localtax1_assuj = (int) trim((
string) $this->localtax1_assuj);
1532 $this->localtax2_assuj = (int) trim((
string) $this->localtax2_assuj);
1534 $this->localtax1_value = trim($this->localtax1_value);
1535 $this->localtax2_value = trim($this->localtax2_value);
1537 $this->capital = (!is_null($this->capital) && (string) $this->capital !=
'') ? (float)
price2num(trim((
string) $this->capital)) :
null;
1539 $this->effectif_id = (int) $this->effectif_id;
1540 $this->forme_juridique_code = (int) $this->forme_juridique_code;
1543 $this->barcode = trim((
string) $this->barcode);
1546 if ($this->code_client == -1 || $this->code_client ===
'auto') {
1547 $this->get_codeclient($this, 0);
1549 if ($this->code_fournisseur ==
'-1' || $this->code_fournisseur ===
'auto') {
1550 $this->get_codefournisseur($this, 1);
1553 $this->accountancy_code_customer_general = trim((
string) $this->accountancy_code_customer_general);
1554 if ($this->accountancy_code_customer_general ===
'-1') {
1555 $this->accountancy_code_customer_general =
'';
1557 $this->code_compta_client = trim((
string) $this->code_compta_client);
1558 $this->accountancy_code_supplier_general = trim((
string) $this->accountancy_code_supplier_general);
1559 if ($this->accountancy_code_supplier_general ===
'-1') {
1560 $this->accountancy_code_supplier_general =
'';
1562 $this->code_compta_fournisseur = trim((
string) $this->code_compta_fournisseur);
1565 if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) {
1566 $langs->load(
"errors");
1567 $this->error = $langs->trans(
"BadValueForParameterClientOrSupplier");
1572 if (!empty($allowmodcodeclient) && !empty($this->client)) {
1574 if (empty($this->code_compta_client)) {
1585 if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) {
1587 if (empty($this->code_compta_fournisseur)) {
1598 $this->webservices_url = empty($this->webservices_url) ?
'' :
clean_url($this->webservices_url, 0);
1599 $this->webservices_key = trim((
string) $this->webservices_key);
1601 $this->accountancy_code_buy = (empty($this->accountancy_code_buy) ?
'' : trim($this->accountancy_code_buy));
1602 $this->accountancy_code_sell = (empty($this->accountancy_code_sell) ?
'' : trim($this->accountancy_code_sell));
1605 $this->fk_incoterms = (int) $this->fk_incoterms;
1606 $this->location_incoterms = trim((
string) $this->location_incoterms);
1613 if ($action !=
'add' && $action !=
'merge') {
1616 $result = $this->
verify();
1620 if (is_array($this->errors)) {
1621 if (in_array(
'ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) {
1622 if (($key = array_search(
'ErrorBadCustomerCodeSyntax', $this->errors)) !==
false) {
1623 unset($this->errors[$key]);
1626 if (in_array(
'ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) {
1627 if (($key = array_search(
'ErrorBadSupplierCodeSyntax', $this->errors)) !==
false) {
1628 unset($this->errors[$key]);
1631 if (empty($this->errors)) {
1638 dol_syslog(get_class($this).
"::update verify ok or not done");
1640 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe SET ";
1641 $sql .=
"entity = ".((int) $this->entity);
1642 $sql .=
",nom = '".$this->db->escape($this->
name).
"'";
1643 $sql .=
",name_alias = '".$this->db->escape($this->name_alias).
"'";
1644 $sql .=
",ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1645 $sql .=
",address = '".$this->db->escape($this->address).
"'";
1647 $sql .=
",zip = ".(!empty($this->zip) ?
"'".$this->db->escape($this->zip).
"'" :
"null");
1648 $sql .=
",town = ".(!empty($this->town) ?
"'".$this->db->escape($this->town).
"'" :
"null");
1650 $sql .=
",fk_departement = ".((!empty($this->state_id) && $this->state_id > 0) ? ((
int) $this->state_id) :
'null');
1651 $sql .=
",fk_pays = ".((!empty($this->country_id) && $this->country_id > 0) ? ((
int) $this->country_id) :
'null');
1653 $sql .=
",phone = ".(!empty($this->phone) ?
"'".$this->db->escape($this->phone).
"'" :
"null");
1654 $sql .=
",phone_mobile = ".(!empty($this->phone_mobile) ?
"'".$this->db->escape($this->phone_mobile).
"'" :
"null");
1655 $sql .=
",fax = ".(!empty($this->fax) ?
"'".$this->db->escape($this->fax).
"'" :
"null");
1656 $sql .=
",email = ".(!empty($this->email) ?
"'".$this->db->escape($this->email).
"'" :
"null");
1657 $sql .=
",socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1658 $sql .=
",url = ".(!empty($this->url) ?
"'".$this->db->escape($this->url).
"'" :
"null");
1660 $sql .=
",parent = ".($this->parent > 0 ? $this->parent :
"null");
1662 $sql .=
",note_private = ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
1663 $sql .=
",note_public = ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
1665 $sql .=
",siren = '".$this->db->escape($this->idprof1).
"'";
1666 $sql .=
",siret = '".$this->db->escape($this->idprof2).
"'";
1667 $sql .=
",ape = '".$this->db->escape($this->idprof3).
"'";
1668 $sql .=
",idprof4 = '".$this->db->escape($this->idprof4).
"'";
1669 $sql .=
",idprof5 = '".$this->db->escape($this->idprof5).
"'";
1670 $sql .=
",idprof6 = '".$this->db->escape($this->idprof6).
"'";
1672 $sql .=
",tva_assuj = ".($this->tva_assuj !=
'' ?
"'".$this->db->escape((
string) $this->tva_assuj).
"'" :
"null");
1673 $sql .=
",tva_intra = '".$this->db->escape($this->tva_intra).
"'";
1675 $sql .=
",vat_reverse_charge = " . ($this->vat_reverse_charge !=
'' ?
"'" . $this->db->escape((
string) $this->vat_reverse_charge) .
"'" : 0);
1677 $sql .=
",status = ".((int) $this->
status);
1680 $sql .=
",localtax1_assuj = ".($this->localtax1_assuj !=
'' ?
"'".$this->db->escape((
string) $this->localtax1_assuj).
"'" :
"null");
1681 $sql .=
",localtax2_assuj = ".($this->localtax2_assuj !=
'' ?
"'".$this->db->escape((
string) $this->localtax2_assuj).
"'" :
"null");
1682 if ($this->localtax1_assuj == 1) {
1683 if ($this->localtax1_value !=
'') {
1684 $sql .=
", localtax1_value = ".((float) $this->localtax1_value);
1686 $sql .=
", localtax1_value = 0.000";
1689 $sql .=
",localtax1_value =0.000";
1692 if ($this->localtax2_assuj == 1) {
1693 if ($this->localtax2_value !=
'') {
1694 $sql .=
",localtax2_value = ".((float) $this->localtax2_value);
1696 $sql .=
",localtax2_value = 0.000";
1699 $sql .=
",localtax2_value = 0.000";
1702 $sql .=
",capital = ".($this->capital ===
null ?
"null" : (float) $this->capital);
1704 $sql .=
",prefix_comm = ".(!empty($this->prefix_comm) ?
"'".$this->db->escape($this->prefix_comm).
"'" :
"null");
1706 $sql .=
",fk_effectif = ".($this->effectif_id > 0 ? ((int) $this->effectif_id) :
"null");
1707 if (isset($this->stcomm_id)) {
1708 $sql .=
",fk_stcomm=".(int) $this->stcomm_id;
1710 if (isset($this->typent_id)) {
1711 $sql .=
",fk_typent = ".($this->typent_id > 0 ? ((int) $this->typent_id) :
"0");
1714 $sql .=
",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ?
"'".$this->db->escape((
string) $this->forme_juridique_code).
"'" :
"null");
1715 $sql .=
",birth = ".(!empty($this->birth) ?
"'".$this->db->idate($this->birth).
"'" :
"null");
1717 $sql .=
",mode_reglement = ".(!empty($this->mode_reglement_id) ?
"'".$this->db->escape((
string) $this->mode_reglement_id).
"'" :
"null");
1718 $sql .=
",cond_reglement = ".(!empty($this->cond_reglement_id) ?
"'".$this->db->escape((
string) $this->cond_reglement_id).
"'" :
"null");
1719 $sql .=
",deposit_percent = ".(!empty($this->deposit_percent) ?
"'".$this->db->escape((
string) $this->deposit_percent).
"'" :
"null");
1720 $sql .=
",transport_mode = ".(!empty($this->transport_mode_id) ?
"'".$this->db->escape((
string) $this->transport_mode_id).
"'" :
"null");
1721 $sql .=
",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ?
"'".$this->db->escape((
string) $this->mode_reglement_supplier_id).
"'" :
"null");
1722 $sql .=
",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ?
"'".$this->db->escape((
string) $this->cond_reglement_supplier_id).
"'" :
"null");
1723 $sql .=
",transport_mode_supplier = ".(!empty($this->transport_mode_supplier_id) ?
"'".$this->db->escape((
string) $this->transport_mode_supplier_id).
"'" :
"null");
1724 $sql .=
",fk_shipping_method = ".(!empty($this->shipping_method_id) ?
"'".$this->db->escape((
string) $this->shipping_method_id).
"'" :
"null");
1726 $sql .=
",client = ".(!empty($this->client) ? $this->client : 0);
1727 $sql .=
",fournisseur = ".(!empty($this->fournisseur) ? $this->fournisseur : 0);
1728 $sql .=
",barcode = ".(!empty($this->barcode) ?
"'".$this->db->escape($this->barcode).
"'" :
"null");
1729 $sql .=
",default_lang = ".(!empty($this->default_lang) ?
"'".$this->db->escape($this->default_lang).
"'" :
"null");
1730 $sql .=
",logo = ".(!empty($this->logo) ?
"'".$this->db->escape($this->logo).
"'" :
"null");
1731 $sql .=
",logo_squarred = ".(!empty($this->logo_squarred) ?
"'".$this->db->escape($this->logo_squarred).
"'" :
"null");
1732 $sql .=
",outstanding_limit= ".($this->outstanding_limit !=
'' ? $this->outstanding_limit :
'null');
1733 $sql .=
",order_min_amount= ".($this->order_min_amount !=
'' ? $this->order_min_amount :
'null');
1734 $sql .=
",supplier_order_min_amount= ".($this->supplier_order_min_amount !=
'' ? $this->supplier_order_min_amount :
'null');
1735 $sql .=
",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel).
"'";
1737 $sql .=
", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1738 $sql .=
", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1740 $sql .=
", accountancy_code_customer_general = ".(!empty($this->accountancy_code_customer_general) ?
"'".$this->db->escape($this->accountancy_code_customer_general).
"'" :
"null");
1741 $sql .=
", code_compta = ".(!empty($this->code_compta_client) ?
"'".$this->db->escape($this->code_compta_client).
"'" :
"null");
1745 $sql .=
", accountancy_code_supplier_general = ".(!empty($this->accountancy_code_supplier_general) ?
"'".$this->db->escape($this->accountancy_code_supplier_general).
"'" :
"null");
1746 $sql .=
", code_compta_fournisseur = ".(($this->code_compta_fournisseur !=
"") ?
"'".$this->db->escape($this->code_compta_fournisseur).
"'" :
"null");
1749 $sql .=
",webservices_url = ".(!empty($this->webservices_url) ?
"'".$this->db->escape($this->webservices_url).
"'" :
"null");
1750 $sql .=
",webservices_key = ".(!empty($this->webservices_key) ?
"'".$this->db->escape($this->webservices_key).
"'" :
"null");
1753 $sql .=
", fk_incoterms = ".((int) $this->fk_incoterms);
1754 $sql .=
", location_incoterms = ".(!empty($this->location_incoterms) ?
"'".$this->db->escape($this->location_incoterms).
"'" :
"null");
1757 $sql .=
", code_client = ".(!empty($this->code_client) ?
"'".$this->db->escape($this->code_client).
"'" :
"null");
1761 $sql .=
", code_fournisseur = ".(!empty($this->code_fournisseur) ?
"'".$this->db->escape($this->code_fournisseur).
"'" :
"null");
1763 $sql .=
", fk_user_modif = ".($user->id > 0 ? $user->id :
"null");
1764 $sql .=
", fk_multicurrency = ".(int) $this->fk_multicurrency;
1765 $sql .=
", multicurrency_code = '".$this->db->escape($this->multicurrency_code).
"'";
1766 $sql .=
", model_pdf = '".$this->db->escape($this->model_pdf).
"'";
1767 $sql .=
" WHERE rowid = ".(int) $id;
1769 $resql = $this->db->query($sql);
1771 if (is_object($this->oldcopy)) {
1772 if ($this->oldcopy->country_id != $this->country_id) {
1773 unset($this->country_code);
1774 unset($this->country);
1776 if ($this->oldcopy->state_id != $this->state_id) {
1777 unset($this->state_code);
1778 unset($this->state);
1781 unset($this->country_code);
1782 unset($this->country);
1783 unset($this->state_code);
1784 unset($this->state);
1787 $nbrowsaffected = $this->db->affected_rows($resql);
1789 if ($nbrowsaffected) {
1792 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1794 dol_syslog(get_class($this).
"::update update linked member");
1796 $lmember =
new Adherent($this->db);
1797 $result = $lmember->fetch(0,
'0', $this->
id);
1800 $lmember->company = $this->name;
1803 $lmember->address = $this->address;
1804 $lmember->zip = $this->zip;
1805 $lmember->town = $this->town;
1806 $lmember->email = $this->email;
1807 $lmember->socialnetworks = $this->socialnetworks;
1808 $lmember->phone = $this->phone;
1809 $lmember->state_id = $this->state_id;
1810 $lmember->country_id = $this->country_id;
1811 $lmember->default_lang = $this->default_lang;
1813 $result = $lmember->update($user, 0, 1, 1, 1);
1816 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
1819 } elseif ($result < 0) {
1820 $this->error = $lmember->error;
1830 $this->db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity WHERE fk_soc = ".((
int) $this->id).
" AND entity = ".((
int) $conf->entity));
1832 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_perentity (";
1835 $sql .=
", vat_reverse_charge";
1836 $sql .=
", accountancy_code_customer_general";
1837 $sql .=
", accountancy_code_customer";
1838 $sql .=
", accountancy_code_supplier_general";
1839 $sql .=
", accountancy_code_supplier";
1840 $sql .=
", accountancy_code_buy";
1841 $sql .=
", accountancy_code_sell";
1842 $sql .=
") VALUES (";
1844 $sql .=
", ".((int) $conf->entity);
1845 $sql .=
", ".(empty($this->vat_reverse_charge) ?
'0' :
'1');
1846 $sql .=
", '".$this->db->escape($this->accountancy_code_customer_general).
"'";
1847 $sql .=
", '".$this->db->escape($this->code_compta_client).
"'";
1848 $sql .=
", '".$this->db->escape($this->accountancy_code_supplier_general).
"'";
1849 $sql .=
", '".$this->db->escape($this->code_compta_fournisseur).
"'";
1850 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1851 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1853 $result = $this->db->query($sql);
1856 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1875 if (!$error && $call_trigger) {
1877 $result = $this->call_trigger(
'COMPANY_MODIFY', $user);
1885 dol_syslog(get_class($this).
"::Update success");
1886 $this->db->commit();
1889 $this->db->rollback();
1893 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1895 $this->error = $langs->trans(
"ErrorDuplicateField");
1898 $this->error = $this->db->lasterror();
1901 $this->db->rollback();
1905 $this->db->rollback();
1906 dol_syslog(get_class($this).
"::Update fails verify ".implode(
',', $this->errors), LOG_WARNING);
1930 public function fetch($rowid, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'', $is_client = 0, $is_supplier = 0)
1935 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)) {
1939 $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';
1940 $sql .=
', s.status, s.fk_warehouse';
1941 $sql .=
', s.price_level';
1942 $sql .=
', GREATEST(s.tms, sef.tms) as date_modification, s.fk_user_creat, s.fk_user_modif';
1943 $sql .=
', s.phone, s.phone_mobile, s.fax, s.email';
1944 $sql .=
', s.socialnetworks';
1945 $sql .=
', s.url, s.zip, s.town, s.note_private, s.note_public, s.client, s.fournisseur';
1946 $sql .=
', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1947 $sql .=
', s.capital, s.tva_intra';
1948 $sql .=
', s.fk_typent as typent_id';
1949 $sql .=
', s.fk_effectif as effectif_id';
1950 $sql .=
', s.fk_forme_juridique as forme_juridique_code';
1951 $sql .=
', s.birth';
1952 $sql .=
', s.webservices_url, s.webservices_key, s.model_pdf, s.last_main_doc';
1954 $sql .=
', s.accountancy_code_customer_general, s.code_compta';
1955 $sql .=
', s.accountancy_code_supplier_general, s.code_compta_fournisseur';
1956 $sql .=
', s.accountancy_code_buy, s.accountancy_code_sell';
1957 $sql .=
', s.vat_reverse_charge as soc_vat_reverse_charge';
1959 $sql .=
', spe.accountancy_code_customer_general, spe.accountancy_code_customer as code_compta';
1960 $sql .=
', spe.accountancy_code_supplier_general, spe.accountancy_code_supplier as code_compta_fournisseur';
1961 $sql .=
', spe.accountancy_code_buy, spe.accountancy_code_sell';
1962 $sql .=
', spe.vat_reverse_charge as spe_vat_reverse_charge';
1964 $sql .=
', s.code_client, s.code_fournisseur, s.parent, s.barcode';
1965 $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';
1966 $sql .=
', s.fk_account, s.tva_assuj';
1967 $sql .=
', s.mode_reglement_supplier, s.cond_reglement_supplier, s.transport_mode_supplier';
1968 $sql .=
', s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred';
1969 $sql .=
', s.fk_shipping_method';
1970 $sql .=
', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1971 $sql .=
', s.order_min_amount, s.supplier_order_min_amount';
1972 $sql .=
', s.fk_multicurrency, s.multicurrency_code';
1973 $sql .=
', fj.libelle as forme_juridique';
1974 $sql .=
', e.libelle as effectif';
1975 $sql .=
', c.code as country_code, c.label as country';
1976 $sql .=
', d.code_departement as state_code, d.nom as state';
1977 $sql .=
', r.rowid as region_id, r.code_region as region_code';
1978 $sql .=
', st.libelle as stcomm, st.picto as stcomm_picto';
1979 $sql .=
', te.code as typent_code';
1980 $sql .=
', i.libelle as label_incoterms';
1982 $sql .=
', s.remise_client, s.remise_supplier';
1984 $sql .=
', sr.remise_client, sr2.remise_supplier';
1986 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
1987 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as sef ON sef.fk_object=s.rowid';
1989 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = ".((int) $conf->entity);
1991 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_effectif as e ON s.fk_effectif = e.id';
1992 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON s.fk_pays = c.rowid';
1993 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcomm as st ON s.fk_stcomm = st.id';
1994 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
1995 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON s.fk_departement = d.rowid';
1996 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_regions as r ON d.fk_region = r.code_region ';
1997 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_typent as te ON s.fk_typent = te.id';
1998 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON s.fk_incoterms = i.rowid';
2002 $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').
'))';
2003 $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').
'))';
2005 $sql .=
' WHERE s.entity IN ('.getEntity($this->element).
')';
2009 $sql .=
' AND s.client > 0';
2012 $sql .=
' AND s.fournisseur > 0';
2016 $sql .=
' AND s.rowid = '.((int) $rowid);
2019 $sql .=
" AND s.nom = '".$this->db->escape($ref).
"'";
2022 $sql .=
" AND s.name_alias = '".$this->db->escape($ref_alias).
"'";
2025 $sql .=
" AND s.ref_ext = '".$this->db->escape($ref_ext).
"'";
2028 $sql .=
" AND s.barcode = '".$this->db->escape($barcode).
"'";
2031 $sql .=
" AND s.siren = '".$this->db->escape($idprof1).
"'";
2034 $sql .=
" AND s.siret = '".$this->db->escape($idprof2).
"'";
2037 $sql .=
" AND s.ape = '".$this->db->escape($idprof3).
"'";
2040 $sql .=
" AND s.idprof4 = '".$this->db->escape($idprof4).
"'";
2043 $sql .=
" AND s.idprof5 = '".$this->db->escape($idprof5).
"'";
2046 $sql .=
" AND s.idprof6 = '".$this->db->escape($idprof6).
"'";
2049 $sql .=
" AND s.email = '".$this->db->escape($email).
"'";
2052 $resql = $this->db->query($sql);
2054 $num = $this->db->num_rows($resql);
2056 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
2060 $obj = $this->db->fetch_object($resql);
2062 $this->
id = $obj->rowid;
2063 $this->entity = $obj->entity;
2064 $this->canvas = $obj->canvas;
2066 $this->
ref = $obj->name;
2067 $this->
name = $obj->name;
2068 $this->nom = $obj->name;
2069 $this->name_alias = $obj->name_alias;
2070 $this->ref_ext = $obj->ref_ext;
2072 $this->date_creation = $this->db->jdate($obj->date_creation);
2073 $this->date_modification = $this->db->jdate($obj->date_modification);
2074 $this->user_creation_id = $obj->fk_user_creat;
2075 $this->user_modification_id = $obj->fk_user_modif;
2077 $this->
address = $obj->address;
2078 $this->zip = $obj->zip;
2079 $this->town = $obj->town;
2081 $this->country_id = $obj->country_id;
2082 $this->country_code = $obj->country_id ? $obj->country_code :
'';
2083 $this->country = $obj->country_id ? (($langs->transnoentities(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code) ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
2085 $this->state_id = $obj->state_id;
2086 $this->state_code = $obj->state_code;
2087 $this->region_id = $obj->region_id;
2088 $this->region_code = $obj->region_code;
2089 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
2091 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcomm);
2092 $label = ($transcode !=
'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm);
2093 $this->stcomm_id = $obj->fk_stcomm;
2094 $this->status_prospect_label = $label;
2095 $this->stcomm_picto = $obj->stcomm_picto;
2097 $this->
email = $obj->email;
2098 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
2100 $this->url = $obj->url;
2101 $this->phone = $obj->phone;
2102 $this->phone_mobile = $obj->phone_mobile;
2103 $this->fax = $obj->fax;
2105 $this->parent = $obj->parent;
2107 $this->idprof1 = $obj->idprof1;
2108 $this->idprof2 = $obj->idprof2;
2109 $this->idprof3 = $obj->idprof3;
2110 $this->idprof4 = $obj->idprof4;
2111 $this->idprof5 = $obj->idprof5;
2112 $this->idprof6 = $obj->idprof6;
2114 $this->capital = $obj->capital;
2116 $this->code_client = $obj->code_client;
2117 $this->code_fournisseur = $obj->code_fournisseur;
2119 $this->accountancy_code_customer_general = $obj->accountancy_code_customer_general;
2120 $this->code_compta_client = $obj->code_compta;
2121 $this->accountancy_code_supplier_general = $obj->accountancy_code_supplier_general;
2122 $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
2124 $this->barcode = $obj->barcode;
2126 $this->tva_assuj = $obj->tva_assuj;
2127 $this->tva_intra = $obj->tva_intra;
2129 if (!empty($obj->spe_vat_reverse_charge)) {
2130 $this->vat_reverse_charge = $obj->spe_vat_reverse_charge;
2131 } elseif (!empty($obj->soc_vat_reverse_charge)) {
2132 $this->vat_reverse_charge = $obj->soc_vat_reverse_charge;
2134 $this->vat_reverse_charge = 0;
2137 $this->
status = $obj->status;
2140 $this->localtax1_assuj = $obj->localtax1_assuj;
2141 $this->localtax2_assuj = $obj->localtax2_assuj;
2143 $this->localtax1_value = $obj->localtax1_value;
2144 $this->localtax2_value = $obj->localtax2_value;
2146 $this->typent_id = $obj->typent_id;
2147 $this->typent_code = $obj->typent_code;
2149 $this->effectif_id = $obj->effectif_id;
2150 $this->effectif = $obj->effectif_id ? $obj->effectif :
'';
2152 $this->forme_juridique_code = $obj->forme_juridique_code;
2153 $this->forme_juridique = $obj->forme_juridique_code ? $obj->forme_juridique :
'';
2154 $this->birth = $this->db->jdate($obj->birth);
2156 $this->fk_prospectlevel = $obj->fk_prospectlevel;
2158 $this->prefix_comm = $obj->prefix_comm;
2160 $this->remise_percent = $obj->remise_client ?
price2num($obj->remise_client) : 0;
2161 $this->remise_supplier_percent = $obj->remise_supplier;
2163 $this->mode_reglement_id = $obj->mode_reglement;
2164 $this->cond_reglement_id = $obj->cond_reglement;
2165 $this->deposit_percent = $obj->deposit_percent;
2166 $this->transport_mode_id = $obj->transport_mode;
2167 $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier;
2168 $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier;
2169 $this->transport_mode_supplier_id = $obj->transport_mode_supplier;
2170 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
2171 $this->fk_account = $obj->fk_account;
2173 $this->client = $obj->client;
2174 $this->fournisseur = $obj->fournisseur;
2176 $this->note = $obj->note_private;
2177 $this->note_private = $obj->note_private;
2178 $this->note_public = $obj->note_public;
2179 $this->model_pdf = $obj->model_pdf;
2180 $this->default_lang = $obj->default_lang;
2181 $this->logo = $obj->logo;
2182 $this->logo_squarred = $obj->logo_squarred;
2184 $this->webservices_url = $obj->webservices_url;
2185 $this->webservices_key = $obj->webservices_key;
2187 $this->accountancy_code_buy = $obj->accountancy_code_buy;
2188 $this->accountancy_code_sell = $obj->accountancy_code_sell;
2190 $this->outstanding_limit = $obj->outstanding_limit;
2191 $this->order_min_amount = $obj->order_min_amount;
2192 $this->supplier_order_min_amount = $obj->supplier_order_min_amount;
2195 $this->price_level = $obj->price_level;
2198 $this->fk_warehouse = $obj->fk_warehouse;
2200 $this->import_key = $obj->import_key;
2203 $this->fk_incoterms = $obj->fk_incoterms;
2204 $this->location_incoterms = $obj->location_incoterms;
2205 $this->label_incoterms = $obj->label_incoterms;
2208 $this->fk_multicurrency = $obj->fk_multicurrency;
2209 $this->multicurrency_code = $obj->multicurrency_code;
2212 $this->model_pdf = $obj->model_pdf;
2213 $this->last_main_doc = $obj->last_main_doc;
2215 $result = $this->id;
2223 $this->db->free($resql);
2225 $this->error = $this->db->lasterror();
2226 $this->errors[] = $this->db->lasterror();
2232 $this->price_level = 1;
2258 public function findNearest($rowid = 0, $ref =
'', $ref_ext =
'', $barcode =
'', $idprof1 =
'', $idprof2 =
'', $idprof3 =
'', $idprof4 =
'', $idprof5 =
'', $idprof6 =
'', $email =
'', $ref_alias =
'', $is_client = 0, $is_supplier = 0)
2265 dol_syslog(get_class($this).
"::findNearest", LOG_DEBUG);
2266 $tmpthirdparty =
new Societe($this->db);
2269 $result = $tmpthirdparty->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias, $is_client, $is_supplier);
2275 dol_syslog(
"Thirdparty not found with exact match so we try barcode search", LOG_DEBUG);
2277 $result = $tmpthirdparty->fetch(0,
'',
'', $barcode,
'',
'',
'',
'',
'',
'',
'',
'', $is_client, $is_supplier);
2283 $sqlstart =
"SELECT s.rowid as id FROM ".MAIN_DB_PREFIX.
"societe as s";
2284 $sqlstart .=
' WHERE s.entity IN ('.getEntity($this->element).
')';
2286 $sqlstart .=
' AND s.client > 0';
2289 $sqlstart .=
' AND s.fournisseur > 0';
2293 dol_syslog(
"Thirdparty not found with barcode search so we try profids search", LOG_DEBUG);
2296 $sqlprof .=
" s.siren = '".$this->db->escape($idprof1).
"'";
2302 $sqlprof .=
" s.siret = '".$this->db->escape($idprof2).
"'";
2308 $sqlprof .=
" s.ape = '".$this->db->escape($idprof3).
"'";
2314 $sqlprof .=
" s.idprof4 = '".$this->db->escape($idprof4).
"'";
2320 $sqlprof .=
" s.idprof5 = '".$this->db->escape($idprof5).
"'";
2326 $sqlprof .=
" s.idprof6 = '".$this->db->escape($idprof6).
"'";
2330 $sqlprofquery = $sqlstart .
" AND (".$sqlprof.
" )";
2331 $resql = $this->db->query($sqlprofquery);
2333 $num = $this->db->num_rows($resql);
2335 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
2339 $obj = $this->db->fetch_object($resql);
2345 $this->error = $this->db->lasterror();
2346 $this->errors[] = $this->db->lasterror();
2355 dol_syslog(
"Thirdparty not found with profids search so we try email search", LOG_DEBUG);
2357 $result = $tmpthirdparty->fetch(0,
'',
'',
'',
'',
'',
'',
'',
'',
'', $email,
'', $is_client, $is_supplier);
2364 dol_syslog(
"Thirdparty not found with email search so we try ref, ref_ext or ref_alias search", LOG_DEBUG);
2367 $sqlref .=
" s.nom = '".$this->db->escape($ref).
"'";
2373 $sqlref .=
" s.name_alias = '".$this->db->escape($ref_alias).
"'";
2379 $sqlref .=
" s.ref_ext = '".$this->db->escape($ref_ext).
"'";
2383 $sqlrefquery = $sqlstart .
" AND (".$sqlref.
" )";
2384 $resql = $this->db->query($sqlrefquery);
2386 $num = $this->db->num_rows($resql);
2388 $this->error =
'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
2392 $obj = $this->db->fetch_object($resql);
2398 $this->error = $this->db->lasterror();
2399 $this->errors[] = $this->db->lasterror();
2414 public function delete($id, $fuser =
null, $call_trigger = 1)
2416 global $conf, $user;
2418 if (empty($fuser)) {
2422 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2424 $entity = isset($this->entity) ? $this->entity : $conf->entity;
2426 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2431 if (empty($objectisused)) {
2435 if ($call_trigger) {
2437 $result = $this->call_trigger(
'COMPANY_DELETE', $fuser);
2445 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2447 $toute_categs = array();
2450 $toute_categs[
'customer'] = $static_cat->containing($this->
id, Categorie::TYPE_CUSTOMER);
2451 $toute_categs[
'supplier'] = $static_cat->containing($this->
id, Categorie::TYPE_SUPPLIER);
2454 foreach ($toute_categs as $type => $categs_type) {
2455 foreach ($categs_type as $cat) {
2456 $cat->del_type($this, $type);
2462 foreach ($this->childtablesoncascade as $tabletodelete) {
2463 $deleteFromObject = explode(
':', $tabletodelete, 4);
2464 if (count($deleteFromObject) >= 2) {
2465 $className = str_replace(
'@',
'', $deleteFromObject[0]);
2466 $filepath = $deleteFromObject[1];
2467 $columnName = $deleteFromObject[2];
2469 $child_object =
new $className($this->db);
2470 '@phan-var-force CommonObject $child_object';
2471 $result = $child_object->deleteByParentField($id, $columnName);
2474 $this->errors[] = $child_object->error;
2479 $this->errors[] =
'Cannot include child class file '.$filepath;
2483 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
2484 $sql .=
" WHERE fk_soc = ".((int) $id);
2485 if (!$this->db->query($sql)) {
2487 $this->errors[] = $this->db->lasterror();
2499 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
2505 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2506 $sql .=
" SET parent = NULL";
2507 $sql .=
" WHERE parent = ".((int) $id);
2508 if (!$this->db->query($sql)) {
2510 $this->errors[] = $this->db->lasterror();
2517 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_perentity";
2518 $sql .=
" WHERE fk_soc = ".((int) $id);
2519 if (!$this->db->query($sql)) {
2521 $this->errors[] = $this->db->lasterror();
2525 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe";
2526 $sql .=
" WHERE rowid = ".((int) $id);
2527 if (!$this->db->query($sql)) {
2529 $this->errors[] = $this->db->lasterror();
2534 $this->db->commit();
2537 if (!empty($conf->societe->multidir_output[$entity])) {
2538 $docdir = $conf->societe->multidir_output[$entity].
"/".$id;
2547 $this->db->rollback();
2551 dol_syslog(
"Can't remove thirdparty with id ".$id.
". There are ".$objectisused.
" children", LOG_WARNING);
2567 dol_syslog(get_class($this).
"::set_as_client is deprecated use setAsCustomer instead", LOG_NOTICE);
2581 if (($this->client == 2 || $this->client == 3) && !
getDolGlobalInt(
'SOCIETE_DISABLE_PROSPECTSCUSTOMERS')) {
2584 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2585 $sql .=
" SET client = ".((int) $newclient);
2586 $sql .=
" WHERE rowid = ".((int) $this->
id);
2588 $resql = $this->db->query($sql);
2590 $this->client = $newclient;
2611 global $conf, $langs;
2614 $note = trim($note);
2616 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2620 dol_syslog(get_class($this).
"::set_remise_client ".$remise.
", ".$note.
", ".$user->id);
2628 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2629 $sql .=
" SET remise_client = '".$this->db->escape((
string) $remise).
"'";
2630 $sql .=
" WHERE rowid = ".((int) $this->
id);
2631 $resql = $this->db->query($sql);
2633 $this->db->rollback();
2634 $this->error = $this->db->error();
2639 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise";
2640 $sql .=
" (entity, datec, fk_soc, remise_client, note, fk_user_author)";
2641 $sql .=
" VALUES (".((int) $conf->entity).
", '".$this->db->idate($now).
"', ".((int) $this->
id).
", '".$this->db->escape((
string) $remise).
"',";
2642 $sql .=
" '".$this->db->escape($note).
"',";
2643 $sql .=
" ".((int) $user->id);
2646 $resql = $this->db->query($sql);
2648 $this->db->rollback();
2649 $this->error = $this->db->lasterror();
2653 $this->db->commit();
2672 global $conf, $langs;
2675 $note = trim($note);
2677 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NoteReason"));
2681 dol_syslog(get_class($this).
"::set_remise_supplier ".$remise.
", ".$note.
", ".$user->id);
2689 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe ";
2690 $sql .=
" SET remise_supplier = ".((float) $remise);
2691 $sql .=
" WHERE rowid = ".((int) $this->
id);
2692 $resql = $this->db->query($sql);
2694 $this->db->rollback();
2695 $this->error = $this->db->error();
2700 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_remise_supplier";
2701 $sql .=
" (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
2702 $sql .=
" VALUES (".((int) $conf->entity).
", '".$this->db->idate($now).
"', ".((int) $this->
id).
", ".((float) $remise).
",";
2703 $sql .=
" '".$this->db->escape($note).
"',";
2704 $sql .=
" ".((int) $user->id);
2707 $resql = $this->db->query($sql);
2709 $this->db->rollback();
2710 $this->error = $this->db->lasterror();
2714 $this->db->commit();
2733 public function set_remise_except($remise,
User $user, $desc, $vatrate =
'', $discount_type = 0, $price_base_type =
'HT')
2740 $desc = trim($desc);
2743 if (!($remise > 0)) {
2744 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"1");
2748 $this->error = $langs->trans(
"ErrorWrongValueForParameter",
"3");
2752 if ($this->
id > 0) {
2756 if (preg_match(
'/\((.*)\)/', $vatrate, $reg)) {
2757 $vat_src_code = $reg[1];
2758 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2761 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2764 $discount->fk_soc = $this->id;
2765 $discount->socid = $this->id;
2767 $discount->discount_type = $discount_type;
2768 $discount->multicurrency_code = $this->multicurrency_code;
2770 $discount->multicurrency_tx = $this->multicurrency_tx;
2772 if ($price_base_type ==
'TTC') {
2773 $discount->multicurrency_amount_ttc =
price2num($remise * (
float) $discount->multicurrency_tx,
'MT');
2774 $discount->multicurrency_amount_ht =
price2num(((
float) $remise / (1 + (
float) $vatrate / 100)) * (
float) $discount->multicurrency_tx,
'MT');
2775 $discount->multicurrency_amount_tva =
price2num(((
float) $discount->amount_ttc - (
float) $discount->amount_ht) * (
float) $discount->multicurrency_tx,
'MT');
2777 $discount->amount_ttc =
price2num($remise,
'MT');
2778 $discount->amount_ht =
price2num((
float) $remise / (1 + (
float) $vatrate / 100),
'MT');
2779 $discount->amount_tva =
price2num((
float) $discount->amount_ttc - (
float) $discount->amount_ht,
'MT');
2781 $discount->amount_ht =
price2num($remise,
'MT');
2782 $discount->amount_tva =
price2num((
float) $remise * (
float) $vatrate / 100,
'MT');
2783 $discount->amount_ttc =
price2num((
float) $discount->amount_ht + (
float) $discount->amount_tva,
'MT');
2785 $discount->multicurrency_amount_ht =
price2num($remise * (
float) $discount->multicurrency_tx,
'MT');
2786 $discount->multicurrency_amount_tva =
price2num(((
float) $remise * (
float) $vatrate / 100) * (
float) $discount->multicurrency_tx,
'MT');
2787 $discount->multicurrency_amount_ttc =
price2num(((
float) $discount->amount_ht + (
float) $discount->amount_tva) * (
float) $discount->multicurrency_tx,
'MT');
2790 $discount->tva_tx = (float)
price2num($vatrate);
2791 $discount->vat_src_code = $vat_src_code;
2793 $discount->description = $desc;
2795 $result = $discount->create($user);
2799 $this->error = $discount->error;
2818 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2821 $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type);
2825 $this->error = $discountstatic->error;
2841 $sql =
"SELECT COUNT(f.rowid) as nb, SUM(f.total_ttc) as amount, SUM(f.multicurrency_total_ttc) as multicurrency_amount";
2842 if (!empty($discount_type)) {
2843 $sql .=
" FROM ".$this->db->prefix().
"facture_fourn as f";
2845 $sql .=
" FROM ".$this->db->prefix().
"facture as f";
2847 $sql .=
" WHERE f.entity = ".$conf->entity;
2848 $sql .=
" AND paye = 0 AND fk_statut = 1";
2849 $sql .=
" AND f.type = ".CommonInvoice::TYPE_CREDIT_NOTE;
2850 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".$this->db->prefix().
"societe_remise_except as rc";
2851 $sql .=
" WHERE rc.discount_type = ".((int) $discount_type);
2852 if (!empty($discount_type)) {
2853 $sql .=
" AND rc.fk_invoice_supplier = f.rowid";
2855 $sql .=
" AND rc.fk_facture = f.rowid";
2857 $sql .=
" AND rc.fk_soc = ".((int) $this->
id);
2859 $sql .=
" AND f.fk_soc = ".((int) $this->
id);
2861 $resql = $this->db->query($sql);
2863 $obj = $this->db->fetch_object($resql);
2885 $reparray = array();
2887 $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";
2888 $sql .=
", u.office_fax, u.user_mobile, u.personal_mobile";
2889 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc, ".MAIN_DB_PREFIX.
"user as u";
2892 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2894 $sql .=
" WHERE entity IN (0, ".((int) $conf->entity).
")";
2897 $sql .=
" AND u.rowid = sc.fk_user AND sc.fk_soc = ".((int) $this->
id);
2898 if (empty($sortfield)) {
2899 $sortfield =
'u.lastname,u.firstname';
2901 if (empty($sortorder)) {
2902 $sortorder = str_repeat(
'ASC,', count(explode(
',', $sortfield)) - 1) .
'ASC';
2904 $sql .= $this->db->order($sortfield, $sortorder);
2906 $resql = $this->db->query($sql);
2908 $num = $this->db->num_rows($resql);
2911 $obj = $this->db->fetch_object($resql);
2914 $reparray[$i][
'id'] = (int) $obj->rowid;
2915 $reparray[$i][
'lastname'] = $obj->lastname;
2916 $reparray[$i][
'firstname'] = $obj->firstname;
2917 $reparray[$i][
'email'] = $obj->email;
2918 $reparray[$i][
'phone'] = $obj->office_phone;
2919 $reparray[$i][
'office_phone'] = $obj->office_phone;
2920 $reparray[$i][
'office_fax'] = $obj->office_fax;
2921 $reparray[$i][
'user_mobile'] = $obj->user_mobile;
2922 $reparray[$i][
'personal_mobile'] = $obj->personal_mobile;
2923 $reparray[$i][
'job'] = $obj->job;
2924 $reparray[$i][
'statut'] = $obj->status;
2925 $reparray[$i][
'status'] = $obj->status;
2926 $reparray[$i][
'entity'] = $obj->entity;
2927 $reparray[$i][
'login'] = $obj->login;
2928 $reparray[$i][
'photo'] = $obj->photo;
2929 $reparray[$i][
'gender'] = $obj->gender;
2931 $reparray[] = (int) $obj->rowid;
2954 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
2955 $sql .=
" SET price_level = ".((int) $price_level);
2956 $sql .=
" WHERE rowid = ".((int) $this->
id);
2958 if (!$this->db->query($sql)) {
2963 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_prices";
2964 $sql .=
" (datec, fk_soc, price_level, fk_user_author)";
2965 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $this->
id).
", ".((int) $price_level).
", ".((int) $user->id).
")";
2967 if (!$this->db->query($sql)) {
2989 if ($this->
id > 0 && $commid > 0) {
2992 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux";
2993 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
2995 $resql = $this->db->query($sql);
2997 dol_syslog(get_class($this).
"::add_commercial Error ".$this->db->lasterror());
3002 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_commerciaux";
3003 $sql .=
" (fk_soc, fk_user)";
3004 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $commid).
")";
3006 $resql = $this->db->query($sql);
3008 dol_syslog(get_class($this).
"::add_commercial Error ".$this->db->lasterror());
3014 $this->context = array(
'commercial_modified' => $commid);
3016 $result = $this->call_trigger(
'COMPANY_LINK_SALE_REPRESENTATIVE', $user);
3023 $this->db->commit();
3026 $this->db->rollback();
3046 $this->context = array(
'commercial_modified' => $commid);
3048 $result = $this->call_trigger(
'COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
3053 if ($this->
id > 0 && $commid > 0) {
3054 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_commerciaux ";
3055 $sql .=
" WHERE fk_soc = ".((int) $this->
id).
" AND fk_user = ".((int) $commid);
3057 if (!$this->db->query($sql)) {
3059 dol_syslog(get_class($this).
"::del_commercial Erreur");
3079 global $conf, $langs, $user;
3081 $langs->loadLangs([
'companies',
'commercial']);
3085 $option = $params[
'option'] ??
'';
3086 $nofetch = !empty($params[
'nofetch']);
3088 $noaliasinname = (empty($params[
'noaliasinname']) ? 0 : $params[
'noaliasinname']);
3091 return [
'optimize' => $langs->trans(
"ShowCompany")];
3094 if (!empty($this->logo) && class_exists(
'Form')) {
3095 $photo =
'<div class="photointooltip floatright">';
3096 $photo .=
Form::showphoto(
'societe', $this, 0, 40, 0,
'photoref',
'mini', 0);
3098 $datas[
'photo'] = $photo;
3105 $datas[
'divopen'] =
'<div class="centpercent">';
3107 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
3108 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Customer").
'</u>';
3109 } elseif ($option ==
'prospect' && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
3110 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Prospect").
'</u>';
3111 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
3112 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Supplier").
'</u>';
3113 } elseif ($option ==
'agenda') {
3114 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
3115 } elseif ($option ==
'project') {
3116 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
3117 } elseif ($option ==
'margin') {
3118 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
3119 } elseif ($option ==
'contact') {
3120 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
3121 } elseif ($option ==
'ban') {
3122 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
3126 if (empty($datas[
'picto'])) {
3127 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ThirdParty").
'</u>';
3129 if (isset($this->
status)) {
3130 $datas[
'status'] =
' '.$this->getLibStatut(5);
3132 if (isset($this->client) && isset($this->fournisseur)) {
3133 $datas[
'type'] =
' ' . $this->
getTypeUrl(1,
'', 0,
'span');
3136 if (!empty($this->name_alias) && empty($noaliasinname)) {
3139 if (!empty($this->
email)) {
3140 $datas[
'email'] =
'<br>'.img_picto(
'',
'email',
'class="pictofixedwidth"').$this->email;
3142 if (!empty($this->url)) {
3143 $datas[
'url'] =
'<br>'.img_picto(
'',
'globe',
'class="pictofixedwidth"').$this->url;
3145 if (!empty($this->phone) || !empty($this->phone_mobile) || !empty($this->fax)) {
3146 $phonelist = array();
3148 $phonelist[] =
dol_print_phone($this->phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3151 if ($this->phone_mobile) {
3152 $phonelist[] =
dol_print_phone($this->phone_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3155 $phonelist[] =
dol_print_phone($this->fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3157 $datas[
'phonelist'] =
'<br>'.implode(
' ', $phonelist);
3161 $datas[
'address'] =
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
', ', $langs);
3162 } elseif (!empty($this->country_code)) {
3163 $datas[
'address'] =
'<br><b>'.$langs->trans(
'Country').
':</b> '.$this->country_code;
3165 if (!empty($this->tva_intra) || (
getDolGlobalString(
'SOCIETE_SHOW_FIELD_IN_TOOLTIP') && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'vatnumber') !==
false)) {
3166 $datas[
'vatintra'] =
'<br><b>'.$langs->trans(
'VATIntra').
':</b> '.
dol_escape_htmltag($this->tva_intra);
3170 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid1') !==
false && $langs->trans(
'ProfId1'.$this->country_code) !=
'-') {
3171 $datas[
'profid1'] =
'<br><b>'.$langs->trans(
'ProfId1'.$this->country_code).
':</b> '.$this->idprof1;
3173 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid2') !==
false && $langs->trans(
'ProfId2'.$this->country_code) !=
'-') {
3174 $datas[
'profid2'] =
'<br><b>'.$langs->trans(
'ProfId2'.$this->country_code).
':</b> '.$this->idprof2;
3176 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid3') !==
false && $langs->trans(
'ProfId3'.$this->country_code) !=
'-') {
3177 $datas[
'profid3'] =
'<br><b>'.$langs->trans(
'ProfId3'.$this->country_code).
':</b> '.$this->idprof3;
3179 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid4') !==
false && $langs->trans(
'ProfId4'.$this->country_code) !=
'-') {
3180 $datas[
'profid4'] =
'<br><b>'.$langs->trans(
'ProfId4'.$this->country_code).
':</b> '.$this->idprof4;
3182 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid5') !==
false && $langs->trans(
'ProfId5'.$this->country_code) !=
'-') {
3183 $datas[
'profid5'] =
'<br><b>'.$langs->trans(
'ProfId5'.$this->country_code).
':</b> '.$this->idprof5;
3185 if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP,
'profid6') !==
false && $langs->trans(
'ProfId6'.$this->country_code) !=
'-') {
3186 $datas[
'profid6'] =
'<br><b>'.$langs->trans(
'ProfId6'.$this->country_code).
':</b> '.$this->idprof6;
3190 $datas[
'separator'] =
'<br>';
3192 if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
3193 $datas[
'customercode'] =
'<br><b>'.$langs->trans(
'CustomerCode').
':</b> '.$this->code_client;
3195 if (
isModEnabled(
'accounting') && ($this->client == 1 || $this->client == 3)) {
3196 $langs->load(
'compta');
3197 $datas[
'accountancycustomercode'] =
'<br><b>'.$langs->trans(
'CustomerAccountancyCode').
':</b> '.$this->code_compta_client;
3200 if (!$nofetch &&
isModEnabled(
'category') && $this->client) {
3201 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
3202 $form =
new Form($this->db);
3203 $datas[
'categories_customer'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_CUSTOMER, 1, 1);
3205 if (!empty($this->code_fournisseur) && $this->fournisseur) {
3206 $datas[
'suppliercode'] =
'<br><b>'.$langs->trans(
'SupplierCode').
':</b> '.$this->code_fournisseur;
3208 if (
isModEnabled(
'accounting') && $this->fournisseur) {
3209 $langs->load(
'compta');
3210 $datas[
'accountancysuppliercode'] =
'<br><b>'.$langs->trans(
'SupplierAccountancyCode').
':</b> '.$this->code_compta_fournisseur;
3213 if (!$nofetch &&
isModEnabled(
'category') && $this->fournisseur) {
3214 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
3215 $form =
new Form($this->db);
3216 $datas[
'categories_supplier'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_SUPPLIER, 1, 1);
3219 $datas[
'divclose'] =
'</div>';
3237 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1, $noaliasinname = 0, $target =
'', $morecss =
'')
3239 global $conf, $langs, $hookmanager, $user;
3241 if (!empty($conf->dol_no_mouse_hover)) {
3245 $name = $this->
name ? $this->
name : $this->nom;
3247 if (
getDolGlobalString(
'SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD')) {
3248 if (empty($option) && $this->client > 0) {
3249 $option =
'customer';
3251 if (empty($option) && $this->fournisseur > 0) {
3252 $option =
'supplier';
3258 if (($this->client) && (!empty($this->code_client)) && (
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 1 ||
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 2)) {
3259 $code = $this->code_client.
' - ';
3262 if (($this->fournisseur) && (!empty($this->code_fournisseur)) && (
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 1 ||
getDolGlobalInt(
'SOCIETE_ADD_REF_IN_LIST') == 3)) {
3263 $code .= $this->code_fournisseur.
' - ';
3268 $name = $code.
' '.$name;
3275 if (!empty($this->name_alias) && empty($noaliasinname)) {
3276 $name .=
' ('.$this->name_alias.
')';
3282 'objecttype' => $this->element,
3283 'option' => $option,
3286 $classfortooltip =
'classfortooltip';
3289 $classfortooltip =
'classforajaxtooltip';
3290 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3299 if ($option ==
'customer' || $option ==
'compta' || $option ==
'category') {
3300 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
3301 } elseif ($option ==
'prospect' && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
3302 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->id;
3303 } elseif ($option ==
'supplier' || $option ==
'category_supplier') {
3304 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->id;
3305 } elseif ($option ==
'agenda') {
3306 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/agenda.php?socid='.$this->id;
3307 } elseif ($option ==
'project') {
3308 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/project.php?socid='.$this->id;
3309 } elseif ($option ==
'margin') {
3310 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/margin/tabs/thirdpartyMargins.php?socid='.$this->
id.
'&type=1';
3311 } elseif ($option ==
'contact') {
3312 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/contact.php?socid='.$this->id;
3313 } elseif ($option ==
'ban') {
3314 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$this->id;
3318 if (empty($linkstart)) {
3319 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$this->id;
3323 $linkstart .= (!empty($this->canvas) ?
'&canvas='.$this->canvas :
'');
3325 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3326 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3327 $add_save_lastsearch_values = 1;
3329 if ($add_save_lastsearch_values) {
3330 $linkstart .=
'&save_lastsearch_values=1';
3335 if (empty($notooltip)) {
3337 $label = $langs->trans(
"ShowCompany");
3338 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3340 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3341 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
' refurl valignmiddle"';
3342 $target_value = array(
'_self',
'_blank',
'_parent',
'_top');
3343 if (in_array($target, $target_value)) {
3344 $linkclose .=
' target="'.dol_escape_htmltag($target).
'"';
3347 $linkclose .=
' class="valignmiddle'.($morecss ?
' '.$morecss :
'').
'"';
3349 $linkstart .= $linkclose.
'>';
3352 if (!$user->hasRight(
'societe',
'client',
'voir') && $user->socid > 0 && $this->id != $user->socid) {
3357 $result .= $linkstart;
3359 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (
' class="'.(($withpicto != 2) ?
'paddingright' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
3361 if ($withpicto != 2) {
3364 $result .= $linkend;
3367 $hookmanager->initHooks(array(
'thirdpartydao'));
3368 $parameters = array(
3370 'getnomurl' => &$result,
3371 'withpicto ' => $withpicto,
3372 'option' => $option,
3373 'maxlen' => $maxlen,
3374 'notooltip' => $notooltip,
3375 'save_lastsearch_value' => $save_lastsearch_value
3377 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3379 $result = $hookmanager->resPrint;
3381 $result .= $hookmanager->resPrint;
3396 public function getTypeUrl($withpicto = 0, $option =
'', $notooltip = 0, $tag =
'a')
3401 if (empty($option) || preg_match(
'/prospect/', $option)) {
3402 if (($this->client == 2 || $this->client == 3) && !
getDolGlobalString(
'SOCIETE_DISABLE_PROSPECTS')) {
3403 $s .=
'<'.$tag.
' class="customer-back opacitymedium" title="'.
dolPrintHTMLForAttribute($langs->trans(
"Prospect")).
'"';
3404 $s .= $tag ==
'a' ?
' href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->
id.
'"' :
'';
3405 $s .=
'>'.dol_substr($langs->trans(
"Prospect"), 0, 1).
'</'.$tag.
'>';
3408 if (empty($option) || preg_match(
'/customer/', $option)) {
3409 if (($this->client == 1 || $this->client == 3) && !
getDolGlobalString(
'SOCIETE_DISABLE_CUSTOMERS')) {
3411 $s .= $tag ==
'a' ?
' href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$this->
id.
'"' :
'';
3412 $s .=
'>'.dol_substr($langs->trans(
"Customer"), 0, 1).
'</'.$tag.
'>';
3415 if (empty($option) || preg_match(
'/supplier/', $option)) {
3418 $s .= $tag ==
'a' ?
' href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$this->
id.
'"' :
'';
3419 $s .=
'>'.dol_substr($langs->trans(
"Supplier"), 0, 1).
'</'.$tag.
'>';
3450 $langs->load(
'companies');
3452 $statusType =
'status4';
3454 $statusType =
'status6';
3457 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3458 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
3459 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"InActivity");
3460 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
3461 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"InActivity");
3464 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3481 if ($this->
email && $addthirdparty) {
3482 if (empty($this->
name)) {
3483 $this->
name = $this->nom;
3485 $contact_emails[
'thirdparty'] = ($addthirdparty == 2 ?
'<span class="opacitymedium">' :
'').$langs->transnoentitiesnoconv(
"ThirdParty").($addthirdparty == 2 ?
'</span>' :
'').
': '.
dol_trunc($this->
name, 16).
" <".$this->
email.
">";
3489 return $contact_emails;
3505 if (!empty($this->phone)) {
3506 if (empty($this->
name)) {
3507 $this->
name = $this->nom;
3510 $contact_phone[
'thirdparty'] = $langs->transnoentitiesnoconv(
"ThirdParty").
': '.
dol_trunc($this->
name, 16).
" <".$this->phone.
">";
3512 return $contact_phone;
3528 $contact_property = array();
3531 $sql =
"SELECT rowid, email, statut as status, phone_mobile, lastname, poste, firstname";
3532 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3533 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
3534 $sql .=
" AND entity IN (".getEntity($this->element).
")";
3535 $sql .=
" ORDER BY lastname, firstname";
3537 $resql = $this->db->query($sql);
3539 $nump = $this->db->num_rows($resql);
3543 if ($mode ==
'email') {
3549 while ($i < $nump) {
3550 $obj = $this->db->fetch_object($resql);
3551 if ($mode ==
'email') {
3552 $property = $obj->email;
3553 } elseif ($mode ==
'mobile') {
3554 $property = $obj->phone_mobile;
3556 $property = $obj->$mode;
3560 if ($obj->status == 1 || empty($hidedisabled)) {
3561 if (empty($property)) {
3562 if ($mode ==
'email') {
3563 $property = $langs->transnoentitiesnoconv(
"NoEMail");
3564 } elseif ($mode ==
'mobile') {
3565 $property = $langs->transnoentitiesnoconv(
"NoMobilePhone");
3569 if (!empty($obj->poste)) {
3570 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ?
" - ".$obj->poste :
"").(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3572 $contact_property[$obj->rowid] = trim(
dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode !=
'poste' && $property) ?
" ".$sepa.$property.$sepb :
'');
3581 return $contact_property;
3594 $contacts = array();
3596 $sql =
"SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3597 $resql = $this->db->query($sql);
3599 $nump = $this->db->num_rows($resql);
3602 while ($i < $nump) {
3603 $obj = $this->db->fetch_object($resql);
3623 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
3624 $contacts = array();
3626 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople WHERE fk_soc = ".((int) $this->
id);
3627 $resql = $this->db->query($sql);
3629 $nump = $this->db->num_rows($resql);
3632 while ($i < $nump) {
3633 $obj = $this->db->fetch_object($resql);
3634 $contact =
new Contact($this->db);
3635 $contact->fetch($obj->rowid);
3636 $contacts[] = $contact;
3657 $contact_property =
'';
3659 if (empty($rowid)) {
3663 $sql =
"SELECT rowid, email, phone_mobile, lastname, firstname";
3664 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
3665 $sql .=
" WHERE rowid = ".((int) $rowid);
3667 $resql = $this->db->query($sql);
3669 $nump = $this->db->num_rows($resql);
3672 $obj = $this->db->fetch_object($resql);
3674 if ($mode ==
'email') {
3676 } elseif ($mode ==
'mobile') {
3677 $contact_property = $obj->phone_mobile;
3680 return $contact_property;
3699 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3703 $bac->fetch(0,
'', $this->
id);
3706 if ($mode ==
'label') {
3707 return $bac->getRibLabel(
true);
3708 } elseif ($mode ==
'rum') {
3709 if (empty($bac->rum)) {
3710 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
3712 $bac->fetch_thirdparty();
3713 $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, (
string) $bac->id);
3716 } elseif ($mode ==
'format') {
3717 return $bac->frstrecur;
3719 return 'BadParameterToFunctionDisplayRib';
3735 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3736 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE type = 'ban' AND fk_soc = ".((int) $this->
id);
3737 $result = $this->db->query($sql);
3739 $this->error = $this->db->lasterror();
3740 $this->errors[] = $this->db->lasterror();
3743 $num_rows = $this->db->num_rows($result);
3744 $rib_array = array();
3746 while ($obj = $this->db->fetch_object($result)) {
3748 $rib->fetch($obj->rowid);
3749 $rib_array[] = $rib;
3762 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
3763 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE type = 'ban' AND default_rib = 1 AND fk_soc = ". (int) $this->
id;
3764 $resql = $this->db->query($sql);
3766 $this->error = $this->db->lasterror();
3767 $this->errors[] = $this->db->lasterror();
3770 $num_rows = $this->db->num_rows($resql);
3771 $rib_array = array();
3773 while ($obj = $this->db->fetch_object($resql)) {
3791 public function get_codeclient($objsoc =
null, $type = 0)
3798 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3799 foreach ($dirsociete as $dirroot) {
3806 $mod =
new $module($this->db);
3807 '@phan-var-force ModeleThirdPartyCode $mod';
3809 $this->code_client = $mod->getNextValue($objsoc, $type);
3810 $this->prefixCustomerIsRequired = $mod->prefixIsRequired;
3812 dol_syslog(get_class($this).
"::get_codeclient code_client=".$this->code_client.
" module=".$module);
3825 public function get_codefournisseur($objsoc =
null, $type = 1)
3832 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3833 foreach ($dirsociete as $dirroot) {
3840 $mod =
new $module($this->db);
3841 '@phan-var-force ModeleThirdPartyCode $mod';
3843 $this->code_fournisseur = $mod->getNextValue($objsoc, $type);
3845 dol_syslog(get_class($this).
"::get_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
3863 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3864 foreach ($dirsociete as $dirroot) {
3871 $mod =
new $module($this->db);
3872 '@phan-var-force ModeleThirdPartyCode $mod';
3874 dol_syslog(get_class($this).
"::codeclient_modifiable code_client=".$this->code_client.
" module=".$module);
3875 if ($mod->code_modifiable_null && !$this->code_client) {
3878 if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
3881 if ($mod->code_modifiable) {
3904 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3905 foreach ($dirsociete as $dirroot) {
3912 $mod =
new $module($this->db);
3913 '@phan-var-force ModeleThirdPartyCode $mod';
3915 dol_syslog(get_class($this).
"::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur.
" module=".$module);
3916 if ($mod->code_modifiable_null && !$this->code_fournisseur) {
3919 if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
3922 if ($mod->code_modifiable) {
3951 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3952 foreach ($dirsociete as $dirroot) {
3959 $mod =
new $module($this->db);
3960 '@phan-var-force ModeleThirdPartyCode $mod';
3962 dol_syslog(get_class($this).
"::check_codeclient code_client=".$this->code_client.
" module=".$module);
3963 $result = $mod->verif($this->db, $this->code_client, $this, 0);
3965 $this->error = $mod->error;
3966 $this->errors = $mod->errors;
3993 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
3994 foreach ($dirsociete as $dirroot) {
4001 $mod =
new $module($this->db);
4002 '@phan-var-force ModeleThirdPartyCode $mod';
4004 dol_syslog(get_class($this).
"::check_codefournisseur code_fournisseur=".$this->code_fournisseur.
" module=".$module);
4005 $result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
4007 $this->error = $mod->error;
4008 $this->errors = $mod->errors;
4033 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
4034 foreach ($dirsociete as $dirroot) {
4042 $mod =
new $module();
4043 '@phan-var-force ModeleAccountancyCode $mod';
4046 $result = $mod->get_code($this->db, $this, $type);
4048 if ($type ==
'customer') {
4049 $this->code_compta_client = $mod->code;
4050 } elseif ($type ==
'supplier') {
4051 $this->code_compta_fournisseur = $mod->code;
4056 $this->error =
'ErrorAccountancyCodeNotDefined';
4060 if ($type ==
'customer') {
4061 $this->code_compta_client =
'';
4062 } elseif ($type ==
'supplier') {
4063 $this->code_compta_fournisseur =
'';
4078 dol_syslog(get_class($this).
'::setParent', LOG_DEBUG);
4084 if ($sameparent < 0) {
4087 if ($sameparent == 1) {
4088 setEventMessages(
'ParentCompanyToAddIsAlreadyAChildOfModifiedCompany',
null,
'warnings');
4093 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe SET parent = '.($id > 0 ? $id :
'null').
' WHERE rowid = '.((
int) $this->id);
4095 $resql = $this->db->query($sql);
4097 $this->parent = $id;
4117 if ($counter > 100) {
4118 dol_syslog(
"Too high level of parent - child for company. May be an infinite loop ?", LOG_WARNING);
4121 $sql =
'SELECT s.parent';
4122 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s';
4123 $sql .=
' WHERE rowid = '.((int) $idparent);
4124 $resql = $this->db->query($sql);
4126 $obj = $this->db->fetch_object($resql);
4128 if ($obj->parent ==
'') {
4130 } elseif ($obj->parent == $idchild) {
4152 if ($company_id > 0) {
4153 $sql =
"SELECT parent FROM " . MAIN_DB_PREFIX .
"societe WHERE rowid = ".((int) $company_id);
4154 $resql = $this->db->query($sql);
4156 if ($obj = $this->db->fetch_object($resql)) {
4157 $parent = $obj->parent;
4158 if ($parent > 0 && !in_array($parent, $parents)) {
4159 $parents[] = $parent;
4165 $this->db->free($resql);
4167 setEventMessage($langs->trans(
'GetCompanyParentsError', $this->db->lasterror()),
'errors');
4252 $sql =
"SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"societe WHERE ".$field.
" = '".$this->db->escape($value).
"' AND entity IN (".
getEntity(
'societe').
")";
4254 $sql .=
" AND rowid <> ".$socid;
4256 $resql = $this->db->query($sql);
4258 $obj = $this->db->fetch_object($resql);
4262 print $this->db->error();
4264 $this->db->free($resql);
4293 require_once DOL_DOCUMENT_ROOT.
'/core/lib/profid.lib.php';
4296 if ($idprof == 1 && $soc->country_code ==
'FR' && !
isValidSiren($this->idprof1)) {
4301 if ($idprof == 2 && $soc->country_code ==
'FR' && !
isValidSiret($this->idprof2)) {
4306 if ($idprof == 1 && $soc->country_code ==
'ES') {
4311 if ($idprof == 1 && $soc->country_code ==
'PT' && !
isValidTinForPT($this->idprof1)) {
4316 if ($idprof == 1 && $soc->country_code ==
'DZ' && !
isValidTinForDZ($this->idprof1)) {
4321 if ($idprof == 1 && $soc->country_code ==
'BE' && !
isValidTinForBE($this->idprof1)) {
4340 global $langs, $hookmanager;
4345 $hookmanager->initHooks(array(
'idprofurl'));
4346 $parameters = array(
'idprof' => $idprof,
'company' => $thirdparty);
4347 $reshook = $hookmanager->executeHooks(
'getIdProfUrl', $parameters, $this, $action);
4348 if (empty($reshook)) {
4354 $strippedIdProf1 = str_replace(
' ',
'', $thirdparty->idprof1);
4355 if ($idprof == 1 && $thirdparty->country_code ==
'FR') {
4356 $url =
'https://annuaire-entreprises.data.gouv.fr/entreprise/'.urlencode($strippedIdProf1);
4358 if ($idprof == 1 && ($thirdparty->country_code ==
'GB' || $thirdparty->country_code ==
'UK')) {
4359 $url =
'https://beta.companieshouse.gov.uk/company/'.urlencode($strippedIdProf1);
4361 if ($idprof == 1 && $thirdparty->country_code ==
'ES') {
4362 $url =
'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.urlencode($strippedIdProf1);
4364 if ($idprof == 1 && $thirdparty->country_code ==
'IN') {
4365 $url =
'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.urlencode($strippedIdProf1).
';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
4367 if ($idprof == 1 && $thirdparty->country_code ==
'DZ') {
4368 $url =
'http://nif.mfdgi.gov.dz/nif.asp?Nif='.urlencode($strippedIdProf1);
4370 if ($idprof == 1 && $thirdparty->country_code ==
'PT') {
4371 $url =
'http://www.nif.pt/'.urlencode($strippedIdProf1);
4375 return '<a target="_blank" rel="noopener noreferrer" href="'.$url.
'">'.$langs->trans(
"Check").
'</a>';
4378 return $hookmanager->resPrint;
4393 $sql =
"SELECT COUNT(*) as numproj FROM ".MAIN_DB_PREFIX.
"projet WHERE fk_soc = ".((int) $this->
id);
4394 $resql = $this->db->query($sql);
4396 $obj = $this->db->fetch_object($resql);
4397 $count = $obj->numproj;
4400 print $this->db->error();
4402 $this->db->free($resql);
4403 return ($count > 0);
4415 $sql =
"SELECT s.rowid, s.nom as name, s.datec, GREATEST(s.tms, sef.tms) as datem,";
4416 $sql .=
" fk_user_creat, fk_user_modif";
4417 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
4418 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_extrafields as sef ON sef.fk_object=s.rowid";
4419 $sql .=
" WHERE s.rowid = ".((int) $id);
4421 $result = $this->db->query($sql);
4423 if ($this->db->num_rows($result)) {
4424 $obj = $this->db->fetch_object($result);
4426 $this->
id = $obj->rowid;
4428 $this->user_creation_id = $obj->fk_user_creat;
4429 $this->user_modification_id = $obj->fk_user_modif;
4430 $this->date_creation = $this->db->jdate($obj->datec);
4431 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
4433 $this->
ref = $obj->name;
4436 $this->db->free($result);
4454 $isACompany =
getDolGlobalInt(
'MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES', $defaultvalue);
4457 if (!empty($this->tva_intra)) {
4459 } elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) {
4463 if (preg_match(
'/^TE_PRIVATE/', $this->typent_code)) {
4481 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4492 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4505 $this->SupplierCategories = array();
4506 $sql =
"SELECT rowid, label";
4507 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
4508 $sql .=
" WHERE type = ".Categorie::TYPE_SUPPLIER;
4510 $resql = $this->db->query($sql);
4512 while ($obj = $this->db->fetch_object($resql)) {
4513 $this->SupplierCategories[$obj->rowid] = $obj->label;
4531 if ($categorie_id > 0 && $this->
id > 0) {
4532 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_fournisseur (fk_categorie, fk_soc) ";
4533 $sql .=
" VALUES (".((int) $categorie_id).
", ".((int) $this->
id).
")";
4535 if ($resql = $this->db->query($sql)) {
4551 $sql =
"SELECT count(mc.email) as nb";
4552 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
4553 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->
email).
"' ";
4554 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
4556 $resql = $this->db->query($sql);
4558 $obj = $this->db->fetch_object($resql);
4559 $nb = (int) $obj->nb;
4561 $this->db->free($resql);
4564 $this->error = $this->db->error();
4586 $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).
"'";
4587 $resql = $this->db->query($sql);
4589 $obj = $this->db->fetch_object($resql);
4590 $noemail = $obj->nb;
4591 if (empty($noemail)) {
4593 $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()).
"')";
4594 $resql = $this->db->query($sql);
4597 $this->error = $this->db->lasterror();
4598 $this->errors[] = $this->error;
4603 $this->error = $this->db->lasterror();
4604 $this->errors[] = $this->error;
4608 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->db->escape($this->
email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
4609 $resql = $this->db->query($sql);
4612 $this->error = $this->db->lasterror();
4613 $this->errors[] = $this->error;
4617 if (empty($error)) {
4618 $this->no_email = $no_email;
4619 $this->db->commit();
4622 $this->db->rollback();
4639 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->db->escape($this->
email).
"'";
4640 $resql = $this->db->query($sql);
4642 $obj = $this->db->fetch_object($resql);
4643 $this->no_email = $obj->nb;
4646 $this->error = $this->db->lasterror();
4647 $this->errors[] = $this->error;
4667 global $user, $langs;
4669 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
4670 $fullname = $member->getFullName($langs);
4672 if ($member->morphy ==
'mor') {
4673 if (empty($socname)) {
4674 $socname = $member->company ? $member->company : $member->societe;
4676 if (!empty($fullname) && empty($socalias)) {
4677 $socalias = $fullname;
4679 } elseif (empty($socname) && $member->morphy ==
'phy') {
4680 if (empty($socname)) {
4681 $socname = $fullname;
4683 if (!empty($member->company) && empty($socalias)) {
4684 $socalias = $member->company;
4689 $alias = $socalias ? $socalias :
'';
4693 $this->
name = $name;
4694 $this->name_alias = $alias;
4695 $this->
address = $member->address;
4696 $this->zip = $member->zip;
4697 $this->town = $member->town;
4698 $this->country_code = $member->country_code;
4699 $this->country_id = $member->country_id;
4700 $this->phone = $member->phone;
4701 $this->
email = $member->email;
4702 $this->socialnetworks = $member->socialnetworks;
4703 $this->entity = $member->entity;
4707 $this->code_client = $member->ref;
4709 $this->code_client = ($customercode ? $customercode : -1);
4711 $this->code_fournisseur =
'-1';
4712 $this->typent_code = ($member->morphy ==
'phy' ?
'TE_PRIVATE' : 0);
4713 $this->typent_id = $this->typent_code ?
dol_getIdFromCode($this->db, $this->typent_code,
'c_typent',
'id',
'code') : 0;
4718 $result = $this->
create($user);
4724 $this->name_bis = $member->lastname;
4725 $this->firstname = $member->firstname;
4726 $this->civility_id = (empty($member->civility_code) ? $member->civility_id : $member->civility_code);
4727 $this->civility_code = (empty($member->civility_code) ? $member->civility_id : $member->civility_code);
4729 dol_syslog(
"We ask to create a contact/address too", LOG_DEBUG);
4734 $this->db->rollback();
4739 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent";
4740 $sql .=
" SET fk_soc = ".((int) $this->
id);
4741 $sql .=
" WHERE rowid = ".((int) $member->id);
4743 $resql = $this->db->query($sql);
4745 $this->db->commit();
4748 $this->error = $this->db->error();
4750 $this->db->rollback();
4755 dol_syslog(get_class($this).
"::create_from_member - 2 - ".$this->error.
" - ".implode(
',', $this->errors), LOG_ERR);
4757 $this->db->rollback();
4773 $this->entity = $conf->entity;
4775 $this->nom = $this->name;
4789 $country_code = $country_label =
'';
4792 $country_id = (is_numeric($tmp[0])) ? (
int) $tmp[0] : 0;
4793 if (!empty($tmp[1])) {
4794 $country_code = $tmp[1];
4795 $country_label = $tmp[2];
4798 dol_syslog(
"Your country setup use an old syntax. Reedit it using setup area.", LOG_WARNING);
4799 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4800 $country_code =
getCountry($country_id,
'2', $this->db);
4801 $country_label =
getCountry($country_id,
'', $this->db);
4804 $this->country_id = $country_id;
4805 $this->country_code = $country_code;
4806 $this->country = $country_label;
4807 if (is_object($langs)) {
4808 $this->country = ($langs->trans(
'Country'.$country_code) !=
'Country'.$country_code) ? $langs->trans(
'Country'.$country_code) : $country_label;
4818 $state_id = (int) $tmp[0];
4819 if (!empty($tmp[1])) {
4820 $state_code = $tmp[1];
4821 $state_label = $tmp[2];
4823 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);
4824 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
4825 $state_code =
getState($state_id,
'2', $this->db);
4826 $state_label =
getState($state_id,
'0', $this->db);
4829 $this->state_id = $state_id;
4830 $this->state_code = $state_code;
4831 $this->state = $state_label;
4832 if (is_object($langs)) {
4833 $this->state = ($langs->trans(
'State'.$state_code) !=
'State'.$state_code) ? $langs->trans(
'State'.$state_code) : $state_label;
4848 $this->socialnetworks = array();
4849 if (!empty($facebook_url)) {
4850 $this->socialnetworks[
'facebook'] = $facebook_url;
4852 if (!empty($twitter_url)) {
4853 $this->socialnetworks[
'twitter'] = $twitter_url;
4855 if (!empty($linkedin_url)) {
4856 $this->socialnetworks[
'linkedin'] = $linkedin_url;
4858 if (!empty($instagram_url)) {
4859 $this->socialnetworks[
'instagram'] = $instagram_url;
4861 if (!empty($youtube_url)) {
4862 $this->socialnetworks[
'youtube'] = $youtube_url;
4864 if (!empty($github_url)) {
4865 $this->socialnetworks[
'github'] = $github_url;
4882 $this->forme_juridique_code =
getDolGlobalInt(
'MAIN_INFO_SOCIETE_FORME_JURIDIQUE');
4889 $this->logo_squarred_small =
getDolGlobalString(
'MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL');
4890 $this->logo_squarred_mini =
getDolGlobalString(
'MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI');
4896 $this->localtax1_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && (
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'1' ||
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'localtax1on')) ? 1 : 0);
4897 $this->localtax2_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && (
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'1' ||
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'localtax2on')) ? 1 : 0);
4916 $this->
name =
'THIRDPARTY SPECIMEN '.dol_print_date($now,
'dayhourlog');
4917 $this->ref_ext =
'Ref ext';
4918 $this->specimen = 1;
4919 $this->
address =
'21 jump street';
4920 $this->zip =
'99999';
4921 $this->town =
'MyTown';
4922 $this->state_id = 1;
4923 $this->state_code =
'AA';
4924 $this->state =
'MyState';
4925 $this->country_id = 1;
4926 $this->country_code =
'FR';
4927 $this->
email =
'specimen@specimen.com';
4928 $this->socialnetworks = array(
4929 'skype' =>
'skypepseudo',
4930 'twitter' =>
'twitterpseudo',
4931 'facebook' =>
'facebookpseudo',
4932 'linkedin' =>
'linkedinpseudo',
4934 $this->url =
'http://www.specimen.com';
4936 $this->phone =
'0909090901';
4937 $this->phone_mobile =
'0909090901';
4938 $this->fax =
'0909090909';
4940 $this->code_client =
'CC-'.dol_print_date($now,
'dayhourlog');
4941 $this->code_fournisseur =
'SC-'.dol_print_date($now,
'dayhourlog');
4942 $this->typent_code =
'TE_OTHER';
4943 $this->capital = 10000;
4945 $this->prospect = 1;
4946 $this->fournisseur = 1;
4947 $this->tva_assuj = 1;
4948 $this->tva_intra =
'EU1234567';
4949 $this->note_public =
'This is a comment (public)';
4950 $this->note_private =
'This is a comment (private)';
4952 $this->idprof1 =
'idprof1';
4953 $this->idprof2 =
'idprof2';
4954 $this->idprof3 =
'idprof3';
4955 $this->idprof4 =
'idprof4';
4956 $this->idprof5 =
'idprof5';
4957 $this->idprof6 =
'idprof6';
4970 public function useLocalTax($localTaxNum = 0, $mode = 0, $thirdparty =
null)
4972 if ($mode == 1 && $thirdparty instanceof
Societe) {
4973 if ($localTaxNum == -1) {
4974 return array(1 => ($thirdparty->localtax1_assuj ?
true :
false), 2 => ($thirdparty->localtax2_assuj ?
true :
false));
4975 } elseif ($localTaxNum == 1) {
4976 return $thirdparty->localtax1_assuj ? true :
false;
4977 } elseif ($localTaxNum == 2) {
4978 return $thirdparty->localtax2_assuj ? true :
false;
4982 $sql =
"SELECT t.localtax1, t.localtax2";
4983 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
4984 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
4985 $sql .=
" AND t.active = 1";
4986 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
4987 if (empty($localTaxNum) || $localTaxNum == -1) {
4988 $sql .=
" AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
4989 } elseif ($localTaxNum == 1) {
4990 $sql .=
" AND t.localtax1_type <> '0'";
4991 } elseif ($localTaxNum == 2) {
4992 $sql .=
" AND t.localtax2_type <> '0'";
4995 $resql = $this->db->query($sql);
4997 if ($localTaxNum == -1) {
4998 $obj = $this->db->fetch_object($resql);
5000 return array(1 => ($obj->localtax1 ?
true :
false), 2 => ($obj->localtax2 ?
true :
false));
5002 return array(1 =>
false, 2 =>
false);
5004 return ($this->db->num_rows($resql) > 0);
5019 $sql =
"SELECT t.rowid";
5020 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
5021 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
5022 $sql .=
" AND t.active = 1 AND t.recuperableonly = 1";
5023 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
5026 $resql = $this->db->query($sql);
5028 return ($this->db->num_rows($resql) > 0);
5042 $sql =
"SELECT COUNT(*) as nb";
5043 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_revenuestamp as r, ".MAIN_DB_PREFIX.
"c_country as c";
5044 $sql .=
" WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code).
"'";
5045 $sql .=
" AND r.active = 1";
5048 $resql = $this->db->query($sql);
5050 $obj = $this->db->fetch_object($resql);
5051 return ($obj->nb > 0);
5053 $this->error = $this->db->lasterror();
5081 if ($fk_prospectlevel !=
'') {
5082 $label = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
5084 if ($label ==
"ProspectLevel".$fk_prospectlevel) {
5085 $label = $langs->getLabelFromKey($this->db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
5101 return $this->
LibProspCommStatut((
int) $this->stcomm_id, $mode, $label, $this->stcomm_picto);
5123 $langs->load(
'customers');
5126 if ($status ==
'-1' || $status ==
'ST_NO') {
5127 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect-1");
5128 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
5129 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect0");
5130 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
5131 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect1");
5132 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
5133 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect2");
5134 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
5135 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect3");
5137 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);
5139 } elseif ($mode == 3) {
5140 if ($status ==
'-1' || $status ==
'ST_NO') {
5141 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto,
'class="inline-block valignmiddle"');
5142 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
5143 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto,
'class="inline-block valignmiddle"');
5144 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
5145 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto,
'class="inline-block valignmiddle"');
5146 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
5147 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto,
'class="inline-block valignmiddle"');
5148 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
5149 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto,
'class="inline-block valignmiddle"');
5151 return img_action(($langs->trans(
"StatusProspect".$status) !=
"StatusProspect".$status) ? $langs->trans(
"StatusProspect".$status) : $label,
'0', $picto,
'class="inline-block valignmiddle"');
5153 } elseif ($mode == 4) {
5154 if ($status ==
'-1' || $status ==
'ST_NO') {
5155 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect-1");
5156 } elseif ($status ==
'0' || $status ==
'ST_NEVER') {
5157 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect0");
5158 } elseif ($status ==
'1' || $status ==
'ST_TODO') {
5159 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect1");
5160 } elseif ($status ==
'2' || $status ==
'ST_PEND') {
5161 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect2");
5162 } elseif ($status ==
'3' || $status ==
'ST_DONE') {
5163 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto,
'class="inline-block valignmiddle"').
' '.$langs->trans(
"StatusProspect3");
5165 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);
5169 return "Error, mode/status not found";
5180 global $hookmanager;
5182 if ($mode ==
'supplier') {
5183 $table =
'supplier_proposal';
5186 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
5187 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
5188 if ($mode ==
'supplier') {
5189 $sql .=
" AND entity IN (".getEntity(
'supplier_proposal').
")";
5191 $sql .=
" AND entity IN (".getEntity(
'propal').
")";
5194 dol_syslog(
"getOutstandingProposals for fk_soc = ".((
int) $this->
id), LOG_DEBUG);
5197 $parameters = array(
'mode' => $mode,
'table' => $table);
5198 $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
5199 $sql .= $hookmanager->resPrint;
5201 $resql = $this->db->query($sql);
5203 $outstandingOpened = 0;
5204 $outstandingTotal = 0;
5205 $outstandingTotalIncTax = 0;
5206 $arrayofref = array();
5207 while ($obj = $this->db->fetch_object($resql)) {
5208 $arrayofref[$obj->rowid] = $obj->ref;
5209 $outstandingTotal += $obj->total_ht;
5210 $outstandingTotalIncTax += $obj->total_ttc;
5211 if ($obj->status != 0) {
5213 $outstandingOpened += $obj->total_ttc;
5216 return array(
'opened' => $outstandingOpened,
'total_ht' => $outstandingTotal,
'total_ttc' => $outstandingTotalIncTax,
'refs' => $arrayofref);
5230 global $hookmanager;
5231 $table =
'commande';
5232 if ($mode ==
'supplier') {
5233 $table =
'commande_fournisseur';
5236 $sql =
"SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table.
" as f";
5237 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
5238 if ($mode ==
'supplier') {
5239 $sql .=
" AND entity IN (".getEntity(
'supplier_order').
")";
5241 $sql .=
" AND entity IN (".getEntity(
'commande').
")";
5244 dol_syslog(
"getOutstandingOrders", LOG_DEBUG);
5246 $parameters = array(
'mode' => $mode,
'table' => $table);
5247 $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
5248 $sql .= $hookmanager->resPrint;
5249 $resql = $this->db->query($sql);
5251 $outstandingOpened = 0;
5252 $outstandingTotal = 0;
5253 $outstandingTotalIncTax = 0;
5254 $arrayofref = array();
5255 while ($obj = $this->db->fetch_object($resql)) {
5256 $arrayofref[$obj->rowid] = $obj->ref;
5257 $outstandingTotal += $obj->total_ht;
5258 $outstandingTotalIncTax += $obj->total_ttc;
5259 if ($obj->status != 0) {
5261 $outstandingOpened += $obj->total_ttc;
5264 return array(
'opened' => $outstandingOpened,
'total_ht' => $outstandingTotal,
'total_ttc' => $outstandingTotalIncTax,
'refs' => $arrayofref);
5279 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
5282 if ($mode ==
'supplier') {
5283 $table =
'facture_fourn';
5295 $sql =
"SELECT rowid, ref, total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table.
" as f";
5296 $sql .=
" WHERE fk_soc = ".((int) $this->
id);
5297 if (!empty($late)) {
5298 $sql .=
" AND date_lim_reglement < '".$this->db->idate($today).
"'";
5300 if ($mode ==
'supplier') {
5301 $sql .=
" AND entity IN (".getEntity(
'facture_fourn').
")";
5303 $sql .=
" AND entity IN (".getEntity(
'invoice').
")";
5306 dol_syslog(
"getOutstandingBills", LOG_DEBUG);
5307 $resql = $this->db->query($sql);
5309 $outstandingOpened = 0;
5310 $outstandingTotal = 0;
5311 $outstandingTotalIncTax = 0;
5312 $arrayofref = array();
5313 $arrayofrefopened = array();
5314 if ($mode ==
'supplier') {
5315 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
5318 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
5319 $tmpobject =
new Facture($this->db);
5321 while ($obj = $this->db->fetch_object($resql)) {
5322 $arrayofref[$obj->rowid] = $obj->ref;
5323 $tmpobject->id = $obj->rowid;
5325 if ($obj->status != $tmpobject::STATUS_DRAFT
5326 && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code ==
'replaced')
5328 $outstandingTotal += $obj->total_ht;
5329 $outstandingTotalIncTax += $obj->total_ttc;
5335 && $obj->status != $tmpobject::STATUS_DRAFT
5336 && $obj->status != $tmpobject::STATUS_ABANDONED
5337 && $obj->status != $tmpobject::STATUS_CLOSED) {
5339 $paiement = $tmpobject->getSommePaiement();
5340 $creditnotes = $tmpobject->getSumCreditNotesUsed();
5341 $deposits = $tmpobject->getSumDepositsUsed();
5343 $remaintopay = ($obj->total_ttc - $paiement - $creditnotes - $deposits);
5344 $outstandingOpened += $remaintopay;
5350 $remainingcreditnote = $tmpobject->getSumFromThisCreditNotesNotUsed();
5351 $remaintopay -= $remainingcreditnote;
5352 $outstandingOpened -= $remainingcreditnote;
5356 $arrayofrefopened[$obj->rowid] = $obj->ref;
5359 return array(
'opened' => $outstandingOpened,
'total_ht' => $outstandingTotal,
'total_ttc' => $outstandingTotalIncTax,
'refs' => $arrayofref,
'refsopened' => $arrayofrefopened);
5361 dol_syslog(
"Sql error ".$this->db->lasterror, LOG_ERR);
5388 $langs->load(
'companies');
5391 return $langs->trans(
"NorProspectNorCustomer");
5392 } elseif ($status == 1) {
5393 return $langs->trans(
"Customer");
5394 } elseif ($status == 2) {
5395 return $langs->trans(
"Prospect");
5396 } elseif ($status == 3) {
5397 return $langs->trans(
"ProspectCustomer");
5415 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
5419 if (!empty($moreparams) && !empty($moreparams[
'use_companybankid'])) {
5420 $modelpath =
"core/modules/bank/doc/";
5422 include_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
5424 $result = $companybankaccount->fetch($moreparams[
'use_companybankid']);
5426 dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
5428 $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
5429 $this->last_main_doc = $companybankaccount->last_main_doc;
5436 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_COMPANY_ADDON_PDF_NotDefined");
5441 if (!isset($this->bank_account)) {
5442 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
5445 $result = $bac->fetch(0,
'', $this->
id);
5447 $this->bank_account = $bac;
5449 $this->bank_account =
'';
5453 $modelpath =
"core/modules/societe/doc/";
5455 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
5474 public function setCategories($categories, $type_categ, $remove_existing =
true)
5476 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
5479 if (!in_array($type_categ, array(Categorie::TYPE_CUSTOMER, Categorie::TYPE_SUPPLIER))) {
5480 dol_syslog(__METHOD__.
': Type '.$type_categ.
'is an unknown company category type. Nothing done.', LOG_ERR);
5484 return parent::setCategoriesCommon($categories, $type_categ, $remove_existing);
5499 if (!is_array($salesrep)) {
5500 $salesrep = array($salesrep);
5504 $to_add = $salesrep;
5505 if ($onlyAdd ===
false) {
5510 if (is_array($existing)) {
5511 $to_del = array_diff($existing, $salesrep);
5512 $to_add = array_diff($salesrep, $existing);
5519 foreach ($to_del as $del) {
5522 foreach ($to_add as $add) {
5530 return $error ? -1 : 1;
5546 $result = $this->
setValueFrom(
'fk_typent', $typent_id,
'',
null,
'',
'', $user,
'COMPANY_MODIFY');
5549 $this->typent_id = $typent_id;
5550 $this->typent_code =
dol_getIdFromCode($this->db, $this->typent_id,
'c_typent',
'id',
'code');
5571 if ($origin_id == $dest_id) {
5572 dol_syslog(
'Error: Try to merge a thirdparty into itself');
5578 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5579 $sql .=
' WHERE fk_soc = '.(int) $dest_id.
' AND fk_user IN ( ';
5580 $sql .=
' SELECT fk_user ';
5581 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe_commerciaux ';
5582 $sql .=
' WHERE fk_soc = '.(int) $origin_id.
') ';
5584 $resql = $dbs->
query($sql);
5586 $dbs->
query(
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_commerciaux WHERE rowid = '.((
int) $obj->rowid));
5593 'societe_commerciaux',
5596 'societe_remise_except',
5615 global $user, $langs, $conf;
5619 if ($type ==
'buy') {
5620 $field =
'accountancy_code_buy';
5621 } elseif ($type ==
'sell') {
5622 $field =
'accountancy_code_sell';
5627 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ";
5628 $sql .= $field.
" = '".$this->db->escape($value).
"'";
5629 $sql .=
" WHERE rowid = ".((int) $this->
id);
5631 dol_syslog(get_class($this).
"::".__FUNCTION__, LOG_DEBUG);
5632 $resql = $this->db->query($sql);
5636 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
5638 $result = $interface->run_triggers(
'COMPANY_MODIFY', $this, $user, $langs, $conf);
5640 $this->errors = $interface->errors;
5641 $this->db->rollback();
5646 $this->$field = $value;
5648 $this->db->commit();
5651 $this->error = $this->db->lasterror();
5652 $this->db->rollback();
5665 require_once DOL_DOCUMENT_ROOT.
'/partnership/class/partnership.class.php';
5667 $this->partnerships[] = array();
5681 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
5683 $out =
'<div class="box-flex-item box-flex-grow-zero">';
5684 $out .=
'<div class="info-box info-box-sm">';
5685 $out .=
'<span class="info-box-icon bg-infobox-action">';
5686 if (!empty($this->logo) && class_exists(
'Form')) {
5687 $out .=
Form::showphoto(
'societe', $this, 0, 40, 0,
'photokanban',
'mini', 0);
5692 $out .=
'<div class="info-box-content">';
5693 $out .=
'<div class="info-box-ref inline-block tdoverflowmax125 valignmiddle">' . $this->
getNomUrl(1);
5695 if (!empty($this->phone)) {
5696 $out .=
'<div class="inline-block valignmiddle">';
5698 $out .=
dol_print_phone($this->phone, $this->country_code, 0, $this->
id,
'tel',
'hidenum',
'phone', $this->phone, 0,
'paddingleft paddingright');
5701 if (!empty($this->
email)) {
5702 $out .=
'<div class="inline-block valignmiddle">';
5703 $out .=
dol_print_email($this->
email, 0, $this->
id,
'thirdparty', -1, 1, 2,
'paddingleft paddingright');
5706 if ($selected >= 0) {
5707 $out .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
5709 if (!empty($this->code_client)) {
5710 $out .=
'<br><span class="info-box-label opacitymedium">'.$this->code_client.
'</span>';
5712 $out .=
'<br><div class="info-box-status">' . $this->
getLibStatut(3) .
'</div>';
5735 $sql =
"SELECT sc.rowid, sc.fk_socpeople as id, sc.fk_c_type_contact";
5736 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
5737 $sql .=
", t.civility as civility, t.lastname as lastname, t.firstname, t.email";
5738 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_label";
5739 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact tc";
5740 $sql .=
", ".$this->db->prefix().
"societe_contacts sc";
5741 $sql .=
" LEFT JOIN ".$this->db->prefix().
"socpeople t on sc.fk_socpeople = t.rowid";
5742 $sql .=
" WHERE sc.fk_soc = ".((int) $this->
id);
5743 $sql .=
" AND sc.fk_c_type_contact = tc.rowid";
5744 if (!empty($element)) {
5745 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
5748 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
5750 $sql .=
" AND sc.entity IN (".getEntity($this->element).
")";
5751 $sql .=
" AND tc.source = 'external'";
5752 $sql .=
" AND tc.active = 1";
5754 $sql .=
" ORDER BY t.lastname ASC";
5756 dol_syslog(get_class($this).
"::getContacts", LOG_DEBUG);
5757 $resql = $this->db->query($sql);
5759 $num = $this->db->num_rows($resql);
5762 $obj = $this->db->fetch_object($resql);
5765 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
5766 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_label);
5767 $tab[$obj->id] = array(
5768 'source' => $obj->source,
5769 'socid' => $obj->socid,
5771 'nom' => $obj->lastname,
5772 'civility' => $obj->civility,
5773 'lastname' => $obj->lastname,
5774 'firstname' => $obj->firstname,
5775 'email' => $obj->email,
5776 'login' => (empty($obj->login) ?
'' : $obj->login),
5777 'photo' => (empty($obj->photo) ?
'' : $obj->photo),
5778 'statuscontact' => $obj->statuscontact,
5779 'rowid' => $obj->rowid,
5780 'code' => $obj->code,
5781 'element' => $obj->element,
5782 'libelle' => $libelle_type,
5783 'status' => $obj->statuslink,
5784 'fk_c_type_contact' => $obj->fk_c_type_contact
5787 $tab[$obj->id] = $obj->id;
5795 $this->error = $this->db->lasterror();
5813 global $conf, $langs, $hookmanager, $user, $action;
5816 $soc_origin =
new Societe($this->db);
5818 dol_syslog(
"mergeCompany merge thirdparty id=".$soc_origin_id.
" (will be deleted) into the thirdparty id=".$this->id);
5820 if ($soc_origin->fetch($soc_origin_id) < 1) {
5821 $this->error = $langs->trans(
'ErrorRecordNotFound');
5829 $this->client |= $soc_origin->client;
5830 $this->fournisseur |= $soc_origin->fournisseur;
5831 $listofproperties = array(
5832 'address',
'zip',
'town',
'state_id',
'country_id',
'phone',
'phone_mobile',
'fax',
'email',
'socialnetworks',
'url',
'barcode',
5833 'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
5834 'tva_intra',
'effectif_id',
'forme_juridique',
'remise_percent',
'remise_supplier_percent',
'mode_reglement_supplier_id',
'cond_reglement_supplier_id',
'name_bis',
5835 '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',
5836 'code_client',
'code_fournisseur',
'code_compta',
'code_compta_fournisseur',
5837 'model_pdf',
'webservices_url',
'webservices_key',
'accountancy_code_sell',
'accountancy_code_buy',
'typent_id'
5839 foreach ($listofproperties as $property) {
5840 if (empty($this->$property)) {
5841 $this->$property = $soc_origin->$property;
5845 if ($this->typent_id == -1) {
5846 $this->typent_id = $soc_origin->typent_id;
5850 $listofproperties = array(
5851 'note_public',
'note_private'
5853 foreach ($listofproperties as $property) {
5854 $this->$property =
dol_concatdesc($this->$property, $soc_origin->$property);
5858 if (is_array($soc_origin->array_options)) {
5859 foreach ($soc_origin->array_options as $key => $val) {
5860 if (empty($this->array_options[$key])) {
5861 $this->array_options[$key] = $val;
5867 if (empty($this->name_bis) && $this->
name != $soc_origin->name) {
5868 $this->name_bis = $this->name;
5872 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
5875 $custcats_ori = $static_cat->containing($soc_origin->id,
'customer',
'id');
5876 $custcats = $static_cat->containing($this->
id,
'customer',
'id');
5877 $custcats = array_merge($custcats, $custcats_ori);
5880 $suppcats_ori = $static_cat->containing($soc_origin->id,
'supplier',
'id');
5881 $suppcats = $static_cat->containing($this->
id,
'supplier',
'id');
5882 $suppcats = array_merge($suppcats, $suppcats_ori);
5886 if ($soc_origin->code_client == $this->code_client
5887 || $soc_origin->code_fournisseur == $this->code_fournisseur
5888 || $soc_origin->barcode == $this->barcode) {
5889 dol_syslog(
"We clean customer and supplier code so we will be able to make the update of target");
5890 $soc_origin->code_client =
'';
5891 $soc_origin->code_fournisseur =
'';
5892 $soc_origin->barcode =
'';
5893 $soc_origin->update($soc_origin->id, $user, 0, 1, 1,
'merge');
5897 $result = $this->
update($this->
id, $user, 0, 1, 1,
'merge');
5906 'Adherent' =>
'/adherents/class/adherent.class.php',
5908 'ActionComm' =>
'/comm/action/class/actioncomm.class.php',
5909 'Propal' =>
'/comm/propal/class/propal.class.php',
5910 'Commande' =>
'/commande/class/commande.class.php',
5911 'Facture' =>
'/compta/facture/class/facture.class.php',
5912 'FactureRec' =>
'/compta/facture/class/facture-rec.class.php',
5913 'LignePrelevement' =>
'/compta/prelevement/class/ligneprelevement.class.php',
5914 'Contact' =>
'/contact/class/contact.class.php',
5915 'Contrat' =>
'/contrat/class/contrat.class.php',
5916 'Expedition' =>
'/expedition/class/expedition.class.php',
5917 'CommandeFournisseur' =>
'/fourn/class/fournisseur.commande.class.php',
5918 'FactureFournisseur' =>
'/fourn/class/fournisseur.facture.class.php',
5919 'FactureFournisseurRec' =>
'/fourn/class/fournisseur.facture-rec.class.php',
5920 'Reception' =>
'/reception/class/reception.class.php',
5921 'SupplierProposal' =>
'/supplier_proposal/class/supplier_proposal.class.php',
5922 'ProductFournisseur' =>
'/fourn/class/fournisseur.product.class.php',
5923 'Product' =>
'/product/class/product.class.php',
5925 'Project' =>
'/projet/class/project.class.php',
5926 'User' =>
'/user/class/user.class.php',
5927 'Account' =>
'/compta/bank/class/account.class.php',
5928 'ConferenceOrBoothAttendee' =>
'/eventorganization/class/conferenceorboothattendee.class.php',
5929 'Societe' =>
'/societe/class/societe.class.php',
5932 if ($this->db->DDLListTables($conf->db->name, $this->db->prefix().
'delivery')) {
5933 $objects[
'Delivery'] =
'/delivery/class/delivery.class.php';
5935 if ($this->db->DDLListTables($conf->db->name, $this->db->prefix().
'mrp_mo')) {
5936 $objects[
'Mo'] =
'/mrp/class/mo.class.php';
5938 if ($this->db->DDLListTables($conf->db->name, $this->db->prefix().
'don')) {
5939 $objects[
'Don'] =
'/don/class/don.class.php';
5941 if ($this->db->DDLListTables($conf->db->name, $this->db->prefix().
'partnership')) {
5942 $objects[
'PartnerShip'] =
'/partnership/class/partnership.class.php';
5944 if ($this->db->DDLListTables($conf->db->name, $this->db->prefix().
'fichinter')) {
5945 $objects[
'Fichinter'] =
'/fichinter/class/fichinter.class.php';
5947 if ($this->db->DDLListTables($conf->db->name, $this->db->prefix().
'ticket')) {
5948 $objects[
'Ticket'] =
'/ticket/class/ticket.class.php';
5952 foreach ($objects as $object_name => $object_file) {
5962 require_once DOL_DOCUMENT_ROOT.$object_file;
5964 if (!$object_name::replaceThirdparty($this->db, $soc_origin->id, $this->id)) {
5966 $this->error = $this->db->lasterror();
5974 $parameters = array(
'soc_origin' => $soc_origin->id,
'soc_dest' => $this->id);
5975 $reshook = $hookmanager->executeHooks(
'replaceThirdparty', $parameters, $this, $action);
5978 $this->error = $hookmanager->error;
5979 $this->errors = $hookmanager->errors;
5986 $this->context = array(
'merge' => 1,
'mergefromid' => $soc_origin->id,
'mergefromname' => $soc_origin->name);
5989 $result = $this->call_trigger(
'COMPANY_MODIFY', $user);
5998 if ($soc_origin->delete($soc_origin->id, $user) < 1) {
5999 $this->error = $soc_origin->error;
6000 $this->errors = $soc_origin->errors;
6008 if (!empty($conf->societe->multidir_output[$this->entity])) {
6009 $srcdir = $conf->societe->multidir_output[$this->entity].
"/".$soc_origin->id;
6010 $destdir = $conf->societe->multidir_output[$this->entity].
"/".$this->id;
6014 foreach ($dirlist as $filetomove) {
6015 $destfile = $destdir.
'/'.$filetomove[
'relativename'];
6017 dol_move($filetomove[
'fullname'], $destfile,
'0', 0, 0, 1);
6025 $this->db->commit();
6028 $langs->load(
"errors");
6029 $this->error = $langs->trans(
'ErrorsThirdpartyMerge');
6030 $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 languages 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.
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 getIdAndTxFromCode($dbs, $code, $date_document=0)
Get id and rate of currency from code.
static getIdFromCode($dbs, $code)
Get id of currency from code.
Class to manage third parties objects (customers, suppliers, prospects...)
setParent($id)
Define parent company of current company.
getLibProspLevel()
Return prostect level.
thirdparty_and_contact_email_array($addthirdparty=0)
Return list of contacts emails existing for third party.
setAsCustomer()
Define third party as a customer.
findNearest($rowid=0, $ref='', $ref_ext='', $barcode='', $idprof1='', $idprof2='', $idprof3='', $idprof4='', $idprof5='', $idprof6='', $email='', $ref_alias='', $is_client=0, $is_supplier=0)
Search the thirdparty that match the most the provided parameters.
codefournisseur_modifiable()
Check if a vendor code is editable in the code control module configuration.
contact_get_property($rowid, $mode)
Return property of contact from its id.
check_codeclient()
Check customer code.
verify()
Check properties of third party are ok (like name, third party codes, ...) Used before an add or upda...
isInSEPA()
Return if a company is inside the SEPA zone (Single Euro Payment Area)
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.
useLocalTax($localTaxNum=0, $mode=0, $thirdparty=null)
Check if we must use localtax feature or not according to country (country of $mysoc in most cases).
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.
useRevenueStamp()
Check if we must use revenue stamps feature or not according to country (country of $mysoc in most ca...
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)
setCategories($categories, $type_categ, $remove_existing=true)
Sets object to supplied categories.
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.
setNoEmail($no_email, $unsubscribegroup='')
Set "blacklist" mailing status.
setAccountancyCode($type, $value)
Sets an accountancy code for a thirdparty.
getOpenCreditNotesNotYetConvertedIntoDiscount($discount_type=0)
Return amount (with tax) of discounts currently available for a company, user or other criteria.
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.
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=null)
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_now($mode='gmt')
Return date for now.
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.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
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_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.
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, $contactid=0, $socid=0, $addlink=0, $max=0, $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.
isModEnabled($module)
Is Dolibarr module enabled.
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.
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.