Passed
Push — EXTRACT_CLASSES ( ff35ec...a2ff75 )
by Rafael
48:13
created

ProductCustomerPrice   F

Complexity

Total Complexity 164

Size/Duplication

Total Lines 1036
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 671
dl 0
loc 1036
rs 1.929
c 1
b 0
f 0
wmc 164

10 Methods

Rating   Name   Duplication   Size   Complexity  
D fetchAll() 0 120 16
F create() 0 173 54
A initAsSpecimen() 0 25 1
C setPriceOnAffiliateThirdparty() 0 87 11
A __construct() 0 3 1
C fetchAllLog() 0 96 10
B fetch() 0 67 3
A createFromClone() 0 39 4
F update() 0 211 56
B delete() 0 37 8

How to fix   Complexity   

Complex Class

Complex classes like ProductCustomerPrice often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ProductCustomerPrice, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/* Copyright (C) 2007-2012  Laurent Destailleur         <[email protected]>
4
 * Copyright (C) 2014       Florian Henry               <[email protected]>
5
 * Copyright (C) 2024       Frédéric France             <[email protected]>
6
 * Copyright (C) 2024		MDW							<[email protected]>
7
 * Copyright (C) 2024       Rafael San José             <[email protected]>
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21
 */
22
23
namespace Dolibarr\Code\Product\Classes;
24
25
use Dolibarr\Core\Base\CommonObject;
26
use Dolibarr\Core\Base\CommonObjectLine;
27
28
/**
29
 * \file htdocs/product/class/productcustomerprice.class.php
30
 * \ingroup produit
31
 * \brief File of class to manage predefined price products or services by customer
32
 */
33
34
35
/**
36
 * File of class to manage predefined price products or services by customer
37
 */
38
class ProductCustomerPrice extends CommonObject
39
{
40
    /**
41
     * @var array<string,array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}>  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string,array{type:...ring>,comment?:string}> at position 16 could not be parsed: Expected '}' at position 16, but found 'int'.
Loading history...
42
     */
43
    public $fields = array(
44
        'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'visible' => 4, 'position' => 10, 'notnull' => 1, 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'comment' => "Reference of object", 'showoncombobox' => 1, 'noteditable' => 1),
45
        'fk_product' => array('type' => 'integer:Product:product/class/product.class.php:0', 'label' => 'Product', 'enabled' => '$conf->product->enabled', 'visible' => 1, 'position' => 35, 'notnull' => 1, 'index' => 1, 'comment' => "Product to produce", 'css' => 'maxwidth300', 'csslist' => 'tdoverflowmax100', 'picto' => 'product'),
46
        'ref_customer' => array('type' => 'varchar(128)', 'label' => 'RefCustomer', 'enabled' => 1, 'visible' => 4, 'position' => 10, 'notnull' => 1,),
47
        'datec' => array('type' => 'datetime', 'label' => 'AppliedPricesFrom', 'enabled' => 1, 'visible' => 1, 'position' => 500, 'notnull' => 1,),
48
        'price_base_type' => array('type' => 'varchar(255)', 'label' => 'PriceBase', 'enabled' => 1, 'visible' => 1, 'position' => 11, 'notnull' => -1, 'comment' => 'Price Base Type'),
49
        'tva_tx' => array('type' => 'decimal(20,6)', 'label' => 'VAT', 'enabled' => 1, 'visible' => 1, 'position' => 12, 'notnull' => -1, 'comment' => 'TVA Tax Rate'),
50
        'price' => array('type' => 'decimal(20,6)', 'label' => 'HT', 'enabled' => 1, 'visible' => 1, 'position' => 8, 'notnull' => -1, 'comment' => 'Price HT'),
51
        'price_ttc' => array('type' => 'decimal(20,6)', 'label' => 'TTC', 'enabled' => 1, 'visible' => 1, 'position' => 8, 'notnull' => -1, 'comment' => 'Price TTC'),
52
        'price_min' => array('type' => 'decimal(20,6)', 'label' => 'MinPriceHT', 'enabled' => 1, 'visible' => 1, 'position' => 9, 'notnull' => -1, 'comment' => 'Minimum Price'),
53
        'price_min_ttc' => array('type' => 'decimal(20,6)', 'label' => 'MinPriceTTC', 'enabled' => 1, 'visible' => 1, 'position' => 10, 'notnull' => -1, 'comment' => 'Minimum Price TTC'),
54
        'price_label' => array('type' => 'varchar(255)', 'label' => 'PriceLabel', 'enabled' => 1, 'visible' => 1, 'position' => 20, 'notnull' => -1, 'comment' => 'Price Label'),
55
        'fk_user' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => 1, 'position' => 510, 'notnull' => 1, 'foreignkey' => 'user.rowid', 'csslist' => 'tdoverflowmax100'),
56
    );
57
58
    /**
59
     * @var string ID to identify managed object
60
     */
61
    public $element = 'product_customer_price';
62
63
    /**
64
     * @var string Name of table without prefix where object is stored
65
     */
66
    public $table_element = 'product_customer_price';
67
68
    /**
69
     * @var int Entity
70
     */
71
    public $entity;
72
73
    public $datec = '';
74
75
    /**
76
     * @var int ID
77
     */
78
    public $fk_product;
79
80
    /**
81
     * @var int Thirdparty ID
82
     */
83
    public $fk_soc;
84
85
    /**
86
     * @var string Customer reference
87
     */
88
    public $ref_customer;
89
90
    public $price;
91
    public $price_ttc;
92
    public $price_min;
93
    public $price_min_ttc;
94
    public $price_base_type;
95
    public $default_vat_code;
96
    public $tva_tx;
97
    public $recuperableonly;
98
    public $localtax1_type;
99
    public $localtax1_tx;
100
    public $localtax2_type;
101
    public $localtax2_tx;
102
    public $price_label;
103
104
    /**
105
     * @var int User ID
106
     */
107
    public $fk_user;
108
109
    /**
110
     * @var PriceByCustomerLine[]
111
     */
112
    public $lines = array();
113
114
115
    /**
116
     * Constructor
117
     *
118
     * @param DoliDB $db handler
0 ignored issues
show
Bug introduced by
The type Dolibarr\Code\Product\Classes\DoliDB was not found. Did you mean DoliDB? If so, make sure to prefix the type with \.
Loading history...
119
     */
120
    public function __construct($db)
121
    {
122
        $this->db = $db;
123
    }
124
125
    /**
126
     * Create object into database
127
     *
128
     * @param User $user that creates
0 ignored issues
show
Bug introduced by
The type Dolibarr\Code\Product\Classes\User was not found. Did you mean User? If so, make sure to prefix the type with \.
Loading history...
129
     * @param int $notrigger triggers after, 1=disable triggers
130
     * @param int $forceupdateaffiliate update price on each soc child
131
     * @return int Return integer <0 if KO, Id of created object if OK
132
     */
133
    public function create($user, $notrigger = 0, $forceupdateaffiliate = 0)
134
    {
135
        global $conf, $langs;
136
        $error = 0;
137
138
        // Clean parameters
139
140
        if (isset($this->entity)) {
141
            $this->entity = (int) $this->entity;
142
        }
143
        if (isset($this->fk_product)) {
144
            $this->fk_product = (int) $this->fk_product;
145
        }
146
        if (isset($this->fk_soc)) {
147
            $this->fk_soc = (int) $this->fk_soc;
148
        }
149
        if (isset($this->ref_customer)) {
150
            $this->ref_customer = trim($this->ref_customer);
151
        }
152
        if (isset($this->price)) {
153
            $this->price = trim($this->price);
154
        }
155
        if (isset($this->price_ttc)) {
156
            $this->price_ttc = trim($this->price_ttc);
157
        }
158
        if (isset($this->price_min)) {
159
            $this->price_min = trim($this->price_min);
160
        }
161
        if (isset($this->price_min_ttc)) {
162
            $this->price_min_ttc = trim($this->price_min_ttc);
163
        }
164
        if (isset($this->price_base_type)) {
165
            $this->price_base_type = trim($this->price_base_type);
166
        }
167
        if (isset($this->tva_tx)) {
168
            $this->tva_tx = (float) $this->tva_tx;
169
        }
170
        if (isset($this->recuperableonly)) {
171
            $this->recuperableonly = trim($this->recuperableonly);
172
        }
173
        if (isset($this->localtax1_tx)) {
174
            $this->localtax1_tx = trim($this->localtax1_tx);
175
        }
176
        if (isset($this->localtax2_tx)) {
177
            $this->localtax2_tx = trim($this->localtax2_tx);
178
        }
179
        if (isset($this->fk_user)) {
180
            $this->fk_user = (int) $this->fk_user;
181
        }
182
        if (isset($this->price_label)) {
183
            $this->price_label = trim($this->price_label);
184
        }
185
        if (isset($this->import_key)) {
186
            $this->import_key = trim($this->import_key);
187
        }
188
189
        // Check parameters
190
        // Put here code to add control on parameters values
191
192
        if ($this->price != '' || $this->price == 0) {
193
            if ($this->price_base_type == 'TTC') {
194
                $this->price_ttc = price2num($this->price, 'MU');
195
                $this->price = price2num($this->price) / (1 + ($this->tva_tx / 100));
196
                $this->price = price2num($this->price, 'MU');
197
198
                if ($this->price_min != '' || $this->price_min == 0) {
199
                    $this->price_min_ttc = price2num($this->price_min, 'MU');
200
                    $this->price_min = price2num($this->price_min) / (1 + ($this->tva_tx / 100));
201
                    $this->price_min = price2num($this->price_min, 'MU');
202
                } else {
203
                    $this->price_min = 0;
204
                    $this->price_min_ttc = 0;
205
                }
206
            } else {
207
                $this->price = price2num($this->price, 'MU');
208
                $this->price_ttc = ($this->recuperableonly != 1) ? price2num($this->price) * (1 + ($this->tva_tx / 100)) : $this->price;
209
                $this->price_ttc = price2num($this->price_ttc, 'MU');
210
211
                if ($this->price_min != '' || $this->price_min == 0) {
212
                    $this->price_min = price2num($this->price_min, 'MU');
213
                    $this->price_min_ttc = price2num($this->price_min) * (1 + ($this->tva_tx / 100));
214
                    $this->price_min_ttc = price2num($this->price_min_ttc, 'MU');
215
                    // print 'X'.$newminprice.'-'.$price_min;
216
                } else {
217
                    $this->price_min = 0;
218
                    $this->price_min_ttc = 0;
219
                }
220
            }
221
        }
222
223
        // Insert request
224
        $sql = "INSERT INTO " . $this->db->prefix() . "product_customer_price(";
225
        $sql .= "entity,";
226
        $sql .= "datec,";
227
        $sql .= "fk_product,";
228
        $sql .= "fk_soc,";
229
        $sql .= 'ref_customer,';
230
        $sql .= "price,";
231
        $sql .= "price_ttc,";
232
        $sql .= "price_min,";
233
        $sql .= "price_min_ttc,";
234
        $sql .= "price_base_type,";
235
        $sql .= "default_vat_code,";
236
        $sql .= "tva_tx,";
237
        $sql .= "recuperableonly,";
238
        $sql .= "localtax1_type,";
239
        $sql .= "localtax1_tx,";
240
        $sql .= "localtax2_type,";
241
        $sql .= "localtax2_tx,";
242
        $sql .= "fk_user,";
243
        $sql .= "price_label,";
244
        $sql .= "import_key";
245
        $sql .= ") VALUES (";
246
        $sql .= " " . ((int) $conf->entity) . ",";
247
        $sql .= " '" . $this->db->idate(dol_now()) . "',";
248
        $sql .= " " . (!isset($this->fk_product) ? 'NULL' : "'" . $this->db->escape($this->fk_product) . "'") . ",";
249
        $sql .= " " . (!isset($this->fk_soc) ? 'NULL' : "'" . $this->db->escape($this->fk_soc) . "'") . ",";
250
        $sql .= " " . (!isset($this->ref_customer) ? 'NULL' : "'" . $this->db->escape($this->ref_customer) . "'") . ",";
251
        $sql .= " " . (empty($this->price) ? '0' : "'" . $this->db->escape($this->price) . "'") . ",";
252
        $sql .= " " . (empty($this->price_ttc) ? '0' : "'" . $this->db->escape($this->price_ttc) . "'") . ",";
253
        $sql .= " " . (empty($this->price_min) ? '0' : "'" . $this->db->escape($this->price_min) . "'") . ",";
254
        $sql .= " " . (empty($this->price_min_ttc) ? '0' : "'" . $this->db->escape($this->price_min_ttc) . "'") . ",";
255
        $sql .= " " . (!isset($this->price_base_type) ? 'NULL' : "'" . $this->db->escape($this->price_base_type) . "'") . ",";
256
        $sql .= " " . ($this->default_vat_code ? "'" . $this->db->escape($this->default_vat_code) . "'" : "null") . ",";
257
        $sql .= " " . (!isset($this->tva_tx) ? 'NULL' : (empty($this->tva_tx) ? 0 : $this->tva_tx)) . ",";
258
        $sql .= " " . (!isset($this->recuperableonly) ? 'NULL' : "'" . $this->db->escape($this->recuperableonly) . "'") . ",";
259
        $sql .= " " . (empty($this->localtax1_type) ? "'0'" : "'" . $this->db->escape($this->localtax1_type) . "'") . ",";
260
        $sql .= " " . (!isset($this->localtax1_tx) ? 'NULL' : (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx)) . ",";
261
        $sql .= " " . (empty($this->localtax2_type) ? "'0'" : "'" . $this->db->escape($this->localtax2_type) . "'") . ",";
262
        $sql .= " " . (!isset($this->localtax2_tx) ? 'NULL' : (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx)) . ",";
263
        $sql .= " " . ((int) $user->id) . ",";
264
        $sql .=  " " . (!isset($this->price_label) ? 'NULL' : "'" . $this->db->escape($this->price_label) . "'") . ",";
265
        $sql .= " " . (!isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'");
266
        $sql .= ")";
267
268
        $this->db->begin();
269
270
        dol_syslog(get_class($this) . "::create", LOG_DEBUG);
271
        $resql = $this->db->query($sql);
272
        if (!$resql) {
273
            $error++;
274
            $this->errors [] = "Error " . $this->db->lasterror();
275
        }
276
277
        if (!$error) {
278
            $this->id = $this->db->last_insert_id($this->db->prefix() . "product_customer_price");
279
280
            if (!$notrigger) {
281
                $result = $this->call_trigger('PRODUCT_CUSTOMER_PRICE_CREATE', $user);
282
                if ($result < 0) {
283
                    $error++;
284
                }
285
            }
286
        }
287
288
        if (!$error) {
289
            $result = $this->setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate);
290
            if ($result < 0) {
291
                $error++;
292
            }
293
        }
294
295
        // Commit or rollback
296
        if ($error) {
297
            foreach ($this->errors as $errmsg) {
298
                dol_syslog(get_class($this) . "::create " . $errmsg, LOG_ERR);
299
                $this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
300
            }
301
            $this->db->rollback();
302
            return -1 * $error;
303
        } else {
304
            $this->db->commit();
305
            return $this->id;
306
        }
307
    }
308
309
    /**
310
     * Load object in memory from the database
311
     *
312
     * @param   int     $id     ID of customer price
313
     * @return  int             Return integer <0 if KO, 0 if not found, >0 if OK
314
     */
315
    public function fetch($id)
316
    {
317
        global $langs;
318
319
        $sql = "SELECT";
320
        $sql .= " t.rowid,";
321
        $sql .= " t.entity,";
322
        $sql .= " t.datec,";
323
        $sql .= " t.tms,";
324
        $sql .= " t.fk_product,";
325
        $sql .= " t.fk_soc,";
326
        $sql .= " t.ref_customer,";
327
        $sql .= " t.price,";
328
        $sql .= " t.price_ttc,";
329
        $sql .= " t.price_min,";
330
        $sql .= " t.price_min_ttc,";
331
        $sql .= " t.price_base_type,";
332
        $sql .= " t.default_vat_code,";
333
        $sql .= " t.tva_tx,";
334
        $sql .= " t.recuperableonly,";
335
        $sql .= " t.localtax1_tx,";
336
        $sql .= " t.localtax2_tx,";
337
        $sql .= " t.fk_user,";
338
        $sql .= " t.price_label,";
339
        $sql .= " t.import_key";
340
        $sql .= " FROM " . $this->db->prefix() . "product_customer_price as t";
341
        $sql .= " WHERE t.rowid = " . ((int) $id);
342
343
        dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
344
        $resql = $this->db->query($sql);
345
        if ($resql) {
346
            if ($this->db->num_rows($resql)) {
347
                $obj = $this->db->fetch_object($resql);
348
349
                $this->id = $obj->rowid;
350
351
                $this->entity = $obj->entity;
352
                $this->datec = $this->db->jdate($obj->datec);
353
                $this->tms = $this->db->jdate($obj->tms);
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$tms has been deprecated: Use $date_modification ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

353
                /** @scrutinizer ignore-deprecated */ $this->tms = $this->db->jdate($obj->tms);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
354
                $this->fk_product = $obj->fk_product;
355
                $this->fk_soc = $obj->fk_soc;
356
                $this->ref_customer = $obj->ref_customer;
357
                $this->price = $obj->price;
358
                $this->price_ttc = $obj->price_ttc;
359
                $this->price_min = $obj->price_min;
360
                $this->price_min_ttc = $obj->price_min_ttc;
361
                $this->price_base_type = $obj->price_base_type;
362
                $this->default_vat_code = $obj->default_vat_code;
363
                $this->tva_tx = $obj->tva_tx;
364
                $this->recuperableonly = $obj->recuperableonly;
365
                $this->localtax1_tx = $obj->localtax1_tx;
366
                $this->localtax2_tx = $obj->localtax2_tx;
367
                $this->fk_user = $obj->fk_user;
368
                $this->price_label = $obj->price_label;
369
                $this->import_key = $obj->import_key;
370
371
                $this->db->free($resql);
372
373
                return 1;
374
            } else {
375
                $this->db->free($resql);
376
377
                return 0;
378
            }
379
        } else {
380
            $this->error = "Error " . $this->db->lasterror();
381
            return -1;
382
        }
383
    }
384
385
    /**
386
     * Load all customer prices in memory from database
387
     *
388
     * @param   string          $sortorder  Sort order
389
     * @param   string          $sortfield  Sort field
390
     * @param   int             $limit      Limit page
391
     * @param   int             $offset     offset
392
     * @param   string|array    $filter     Filter USF.
393
     * @return  int                         Return integer <0 if KO, >0 if OK
394
     * @since dolibarr v17
395
     */
396
    public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '')
397
    {
398
        if (empty($sortfield)) {
399
            $sortfield = "t.rowid";
400
        }
401
        if (empty($sortorder)) {
402
            $sortorder = "DESC";
403
        }
404
405
        $sql = "SELECT";
406
        $sql .= " t.rowid,";
407
        $sql .= " t.entity,";
408
        $sql .= " t.datec,";
409
        $sql .= " t.tms,";
410
        $sql .= " t.fk_product,";
411
        $sql .= " t.fk_soc,";
412
        $sql .= " t.ref_customer,";
413
        $sql .= " t.price,";
414
        $sql .= " t.price_ttc,";
415
        $sql .= " t.price_min,";
416
        $sql .= " t.price_min_ttc,";
417
        $sql .= " t.price_base_type,";
418
        $sql .= " t.default_vat_code,";
419
        $sql .= " t.tva_tx,";
420
        $sql .= " t.recuperableonly,";
421
        $sql .= " t.localtax1_tx,";
422
        $sql .= " t.localtax2_tx,";
423
        $sql .= " t.localtax1_type,";
424
        $sql .= " t.localtax2_type,";
425
        $sql .= " t.fk_user,";
426
        $sql .= " t.price_label,";
427
        $sql .= " t.import_key,";
428
        $sql .= " soc.nom as socname,";
429
        $sql .= " prod.ref as prodref";
430
        $sql .= " FROM " . $this->db->prefix() . "product_customer_price as t,";
431
        $sql .= " " . $this->db->prefix() . "product as prod,";
432
        $sql .= " " . $this->db->prefix() . "societe as soc";
433
        $sql .= " WHERE soc.rowid=t.fk_soc ";
434
        $sql .= " AND prod.rowid=t.fk_product ";
435
        $sql .= " AND prod.entity IN (" . getEntity('product') . ")";
436
        $sql .= " AND t.entity IN (" . getEntity('productprice') . ")";
437
438
        // Manage filter
439
        if (is_array($filter)) {
440
            if (count($filter) > 0) {
441
                foreach ($filter as $key => $value) {
442
                    if (strpos($key, 'date')) {             // To allow $filter['YEAR(s.dated)']=>$year
443
                        $sql .= " AND " . $this->db->sanitize($key) . " = '" . $this->db->escape($value) . "'";
444
                    } elseif ($key == 'soc.nom') {
445
                        $sql .= " AND " . $this->db->sanitize($key) . " LIKE '%" . $this->db->escape($this->db->escapeforlike($value)) . "%'";
446
                    } elseif ($key == 'prod.ref' || $key == 'prod.label') {
447
                        $sql .= " AND " . $this->db->sanitize($key) . " LIKE '%" . $this->db->escape($this->db->escapeforlike($value)) . "%'";
448
                    } elseif ($key == 't.price' || $key == 't.price_ttc') {
449
                        $sql .= " AND " . $this->db->sanitize($key) . " = " . ((float) price2num($value));
450
                    } else {
451
                        $sql .= " AND " . $this->db->sanitize($key) . " = " . ((int) $value);
452
                    }
453
                }
454
            }
455
456
            $filter = '';
457
        }
458
459
        // Manage filter
460
        $errormessage = '';
461
        $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
462
        if ($errormessage) {
463
            $this->errors[] = $errormessage;
464
            dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
465
            return -1;
466
        }
467
468
        $sql .= $this->db->order($sortfield, $sortorder);
469
        if (!empty($limit)) {
470
            $sql .= $this->db->plimit($limit + 1, $offset);
471
        }
472
473
        dol_syslog(get_class($this) . "::fetchAll", LOG_DEBUG);
474
        $resql = $this->db->query($sql);
475
        if ($resql) {
476
            $this->lines = array();
477
            $num = $this->db->num_rows($resql);
478
479
            while ($obj = $this->db->fetch_object($resql)) {
480
                $line = new PriceByCustomerLine($this->db);
481
482
                $line->id = $obj->rowid;
483
484
                $line->entity = $obj->entity;
485
                $line->datec = $this->db->jdate($obj->datec);
486
                $line->tms = $this->db->jdate($obj->tms);
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$tms has been deprecated: Use $date_modification ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

486
                /** @scrutinizer ignore-deprecated */ $line->tms = $this->db->jdate($obj->tms);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
487
                $line->fk_product = $obj->fk_product;
488
                $line->fk_soc = $obj->fk_soc;
489
                $line->ref_customer = $obj->ref_customer;
490
                $line->price = $obj->price;
491
                $line->price_ttc = $obj->price_ttc;
492
                $line->price_min = $obj->price_min;
493
                $line->price_min_ttc = $obj->price_min_ttc;
494
                $line->price_base_type = $obj->price_base_type;
495
                $line->default_vat_code = $obj->default_vat_code;
496
                $line->tva_tx = $obj->tva_tx;
497
                $line->recuperableonly = $obj->recuperableonly;
498
                $line->localtax1_tx = $obj->localtax1_tx;
499
                $line->localtax2_tx = $obj->localtax2_tx;
500
                $line->localtax1_type = $obj->localtax1_type;
0 ignored issues
show
Bug Best Practice introduced by
The property localtax1_type does not exist on Dolibarr\Code\Product\Classes\PriceByCustomerLine. Since you implemented __set, consider adding a @property annotation.
Loading history...
501
                $line->localtax2_type = $obj->localtax2_type;
0 ignored issues
show
Bug Best Practice introduced by
The property localtax2_type does not exist on Dolibarr\Code\Product\Classes\PriceByCustomerLine. Since you implemented __set, consider adding a @property annotation.
Loading history...
502
                $line->fk_user = $obj->fk_user;
503
                $line->price_label = $obj->price_label;
504
                $line->import_key = $obj->import_key;
505
                $line->socname = $obj->socname;
506
                $line->prodref = $obj->prodref;
507
508
                $this->lines[] = $line;
509
            }
510
            $this->db->free($resql);
511
512
            return $num;
513
        } else {
514
            $this->error = "Error " . $this->db->lasterror();
515
            return -1;
516
        }
517
    }
518
519
    /**
520
     * Load all objects in memory from database
521
     *
522
     * @param   string  $sortorder  order
523
     * @param   string  $sortfield  field
524
     * @param   int     $limit      page
525
     * @param   int     $offset     offset
526
     * @param   array   $filter     Filter for sql request
527
     * @return  int             Return integer <0 if KO, >0 if OK
528
     */
529
    public function fetchAllLog($sortorder, $sortfield, $limit, $offset, $filter = array())
530
    {
531
        if (!empty($sortfield)) {
532
            $sortfield = "t.rowid";
533
        }
534
        if (!empty($sortorder)) {
535
            $sortorder = "DESC";
536
        }
537
538
        $sql = "SELECT";
539
        $sql .= " t.rowid,";
540
        $sql .= " t.entity,";
541
        $sql .= " t.datec,";
542
        $sql .= " t.fk_product,";
543
        $sql .= " t.fk_soc,";
544
        $sql .= " t.ref_customer,";
545
        $sql .= " t.price,";
546
        $sql .= " t.price_ttc,";
547
        $sql .= " t.price_min,";
548
        $sql .= " t.price_min_ttc,";
549
        $sql .= " t.price_base_type,";
550
        $sql .= " t.default_vat_code,";
551
        $sql .= " t.tva_tx,";
552
        $sql .= " t.recuperableonly,";
553
        $sql .= " t.localtax1_tx,";
554
        $sql .= " t.localtax2_tx,";
555
        $sql .= " t.fk_user,";
556
        $sql .= " t.price_label,";
557
        $sql .= " t.import_key,";
558
        $sql .= " soc.nom as socname,";
559
        $sql .= " prod.ref as prodref";
560
        $sql .= " FROM " . $this->db->prefix() . "product_customer_price_log as t";
561
        $sql .= " ," . $this->db->prefix() . "product as prod";
562
        $sql .= " ," . $this->db->prefix() . "societe as soc";
563
        $sql .= " WHERE soc.rowid=t.fk_soc";
564
        $sql .= " AND prod.rowid=t.fk_product ";
565
        $sql .= " AND prod.entity IN (" . getEntity('product') . ")";
566
        $sql .= " AND t.entity IN (" . getEntity('productprice') . ")";
567
        // Manage filter
568
        if (count($filter) > 0) {
569
            foreach ($filter as $key => $value) {
570
                if (strpos($key, 'date')) {                 // To allow $filter['YEAR(s.dated)']=>$year
571
                    $sql .= " AND " . $key . " = '" . $this->db->escape($value) . "'";
572
                } elseif ($key == 'soc.nom') {
573
                    $sql .= " AND " . $key . " LIKE '%" . $this->db->escape($value) . "%'";
574
                } else {
575
                    $sql .= " AND " . $key . " = " . ((int) $value);
576
                }
577
            }
578
        }
579
        $sql .= $this->db->order($sortfield, $sortorder);
580
        if (!empty($limit)) {
581
            $sql .= $this->db->plimit($limit + 1, $offset);
582
        }
583
584
        dol_syslog(get_class($this) . "::fetchAllLog", LOG_DEBUG);
585
        $resql = $this->db->query($sql);
586
        if ($resql) {
587
            $this->lines = array();
588
            $num = $this->db->num_rows($resql);
589
590
            while ($obj = $this->db->fetch_object($resql)) {
591
                $line = new PriceByCustomerLine($this->db);
592
593
                $line->id = $obj->rowid;
594
595
                $line->entity = $obj->entity;
596
                $line->datec = $this->db->jdate($obj->datec);
597
                $line->tms = $this->db->jdate($obj->tms);
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$tms has been deprecated: Use $date_modification ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

597
                /** @scrutinizer ignore-deprecated */ $line->tms = $this->db->jdate($obj->tms);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
598
                $line->fk_product = $obj->fk_product;
599
                $line->fk_soc = $obj->fk_soc;
600
                $line->ref_customer = $obj->ref_customer;
601
                $line->price = $obj->price;
602
                $line->price_ttc = $obj->price_ttc;
603
                $line->price_min = $obj->price_min;
604
                $line->price_min_ttc = $obj->price_min_ttc;
605
                $line->price_base_type = $obj->price_base_type;
606
                $line->default_vat_code = $obj->default_vat_code;
607
                $line->tva_tx = $obj->tva_tx;
608
                $line->recuperableonly = $obj->recuperableonly;
609
                $line->localtax1_tx = $obj->localtax1_tx;
610
                $line->localtax2_tx = $obj->localtax2_tx;
611
                $line->fk_user = $obj->fk_user;
612
                $line->price_label = $obj->price_label;
613
                $line->import_key = $obj->import_key;
614
                $line->socname = $obj->socname;
615
                $line->prodref = $obj->prodref;
616
617
                $this->lines [] = $line;
618
            }
619
            $this->db->free($resql);
620
621
            return $num;
622
        } else {
623
            $this->error = "Error " . $this->db->lasterror();
624
            return -1;
625
        }
626
    }
627
628
    /**
629
     * Update object into database
630
     *
631
     * @param User $user that modifies
632
     * @param int $notrigger triggers after, 1=disable triggers
633
     * @param int $forceupdateaffiliate update price on each soc child
634
     * @return int Return integer <0 if KO, >0 if OK
635
     */
636
    public function update(User $user, $notrigger = 0, $forceupdateaffiliate = 0)
637
    {
638
        global $conf, $langs;
639
        $error = 0;
640
641
        // Clean parameters
642
643
        if (isset($this->entity)) {
644
            $this->entity = (int) $this->entity;
645
        }
646
        if (isset($this->fk_product)) {
647
            $this->fk_product = (int) $this->fk_product;
648
        }
649
        if (isset($this->fk_soc)) {
650
            $this->fk_soc = (int) $this->fk_soc;
651
        }
652
        if (isset($this->ref_customer)) {
653
            $this->ref_customer = trim($this->ref_customer);
654
        }
655
        if (isset($this->price)) {
656
            $this->price = trim($this->price);
657
        }
658
        if (isset($this->price_ttc)) {
659
            $this->price_ttc = trim($this->price_ttc);
660
        }
661
        if (isset($this->price_min)) {
662
            $this->price_min = trim($this->price_min);
663
        }
664
        if (isset($this->price_min_ttc)) {
665
            $this->price_min_ttc = trim($this->price_min_ttc);
666
        }
667
        if (isset($this->price_base_type)) {
668
            $this->price_base_type = trim($this->price_base_type);
669
        }
670
        if (isset($this->tva_tx)) {
671
            $this->tva_tx = (float) $this->tva_tx;
672
        }
673
        if (isset($this->recuperableonly)) {
674
            $this->recuperableonly = trim($this->recuperableonly);
675
        }
676
        if (isset($this->localtax1_tx)) {
677
            $this->localtax1_tx = trim($this->localtax1_tx);
678
        }
679
        if (isset($this->localtax2_tx)) {
680
            $this->localtax2_tx = trim($this->localtax2_tx);
681
        }
682
        if (isset($this->fk_user)) {
683
            $this->fk_user = (int) $this->fk_user;
684
        }
685
        if (isset($this->price_label)) {
686
            $this->price_label = trim($this->price_label);
687
        }
688
        if (isset($this->import_key)) {
689
            $this->import_key = trim($this->import_key);
690
        }
691
692
        // Check parameters
693
        // Put here code to add a control on parameters values
694
695
        if ($this->price != '' || $this->price == 0) {
696
            if ($this->price_base_type == 'TTC') {
697
                $this->price_ttc = price2num($this->price, 'MU');
698
                $this->price = price2num($this->price) / (1 + ($this->tva_tx / 100));
699
                $this->price = price2num($this->price, 'MU');
700
701
                if ($this->price_min != '' || $this->price_min == 0) {
702
                    $this->price_min_ttc = price2num($this->price_min, 'MU');
703
                    $this->price_min = price2num($this->price_min) / (1 + ($this->tva_tx / 100));
704
                    $this->price_min = price2num($this->price_min, 'MU');
705
                } else {
706
                    $this->price_min = 0;
707
                    $this->price_min_ttc = 0;
708
                }
709
            } else {
710
                $this->price = price2num($this->price, 'MU');
711
                $this->price_ttc = ($this->recuperableonly != 1) ? price2num($this->price) * (1 + ($this->tva_tx / 100)) : $this->price;
712
                $this->price_ttc = price2num($this->price_ttc, 'MU');
713
714
                if ($this->price_min != '' || $this->price_min == 0) {
715
                    $this->price_min = price2num($this->price_min, 'MU');
716
                    $this->price_min_ttc = price2num($this->price_min) * (1 + ($this->tva_tx / 100));
717
                    $this->price_min_ttc = price2num($this->price_min_ttc, 'MU');
718
                    // print 'X'.$newminprice.'-'.$price_min;
719
                } else {
720
                    $this->price_min = 0;
721
                    $this->price_min_ttc = 0;
722
                }
723
            }
724
        }
725
726
        // Do a copy of current record into log table
727
        // Insert request
728
        $sql = "INSERT INTO " . $this->db->prefix() . "product_customer_price_log(";
729
730
        $sql .= "entity,";
731
        $sql .= "datec,";
732
        $sql .= "fk_product,";
733
        $sql .= "fk_soc,";
734
        $sql .= "ref_customer,";
735
        $sql .= "price,";
736
        $sql .= "price_ttc,";
737
        $sql .= "price_min,";
738
        $sql .= "price_min_ttc,";
739
        $sql .= "price_base_type,";
740
        $sql .= "default_vat_code,";
741
        $sql .= "tva_tx,";
742
        $sql .= "recuperableonly,";
743
        $sql .= "localtax1_tx,";
744
        $sql .= "localtax2_tx,";
745
        $sql .= "localtax1_type,";
746
        $sql .= "localtax2_type,";
747
        $sql .= "fk_user,";
748
        $sql .= "price_label,";
749
        $sql .= "import_key";
750
751
        $sql .= ") 		";
752
        $sql .= "SELECT";
753
754
        $sql .= " t.entity,";
755
        $sql .= " t.datec,";
756
        $sql .= " t.fk_product,";
757
        $sql .= " t.fk_soc,";
758
        $sql .= " t.ref_customer,";
759
        $sql .= " t.price,";
760
        $sql .= " t.price_ttc,";
761
        $sql .= " t.price_min,";
762
        $sql .= " t.price_min_ttc,";
763
        $sql .= " t.price_base_type,";
764
        $sql .= " t.default_vat_code,";
765
        $sql .= " t.tva_tx,";
766
        $sql .= " t.recuperableonly,";
767
        $sql .= " t.localtax1_tx,";
768
        $sql .= " t.localtax2_tx,";
769
        $sql .= " t.localtax1_type,";
770
        $sql .= " t.localtax2_type,";
771
        $sql .= " t.fk_user,";
772
        $sql .= " t.price_label,";
773
        $sql .= " t.import_key";
774
775
        $sql .= " FROM " . $this->db->prefix() . "product_customer_price as t";
776
        $sql .= " WHERE t.rowid = " . ((int) $this->id);
777
778
        $this->db->begin();
779
        dol_syslog(get_class($this) . "::update", LOG_DEBUG);
780
        $resql = $this->db->query($sql);
781
        if (!$resql) {
782
            $error++;
783
            $this->errors [] = "Error " . $this->db->lasterror();
784
        }
785
786
        // Update request
787
        $sql = "UPDATE " . $this->db->prefix() . "product_customer_price SET";
788
789
        $sql .= " entity=" . $conf->entity . ",";
790
        $sql .= " datec='" . $this->db->idate(dol_now()) . "',";
791
        $sql .= " tms=" . (dol_strlen($this->tms) != 0 ? "'" . $this->db->idate($this->tms) . "'" : 'null') . ",";
792
        $sql .= " fk_product=" . (isset($this->fk_product) ? $this->fk_product : "null") . ",";
793
        $sql .= " fk_soc=" . (isset($this->fk_soc) ? $this->fk_soc : "null") . ",";
794
        $sql .= " ref_customer=" . (isset($this->ref_customer) ? "'" . $this->db->escape($this->ref_customer) . "'" : "null") . ",";
795
        $sql .= " price=" . (isset($this->price) ? $this->price : "null") . ",";
796
        $sql .= " price_ttc=" . (isset($this->price_ttc) ? $this->price_ttc : "null") . ",";
797
        $sql .= " price_min=" . (isset($this->price_min) ? $this->price_min : "null") . ",";
798
        $sql .= " price_min_ttc=" . (isset($this->price_min_ttc) ? $this->price_min_ttc : "null") . ",";
799
        $sql .= " price_base_type=" . (isset($this->price_base_type) ? "'" . $this->db->escape($this->price_base_type) . "'" : "null") . ",";
800
        $sql .= " default_vat_code = " . ($this->default_vat_code ? "'" . $this->db->escape($this->default_vat_code) . "'" : "null") . ",";
801
        $sql .= " tva_tx=" . (isset($this->tva_tx) ? (empty($this->tva_tx) ? 0 : $this->tva_tx) : "null") . ",";
802
        $sql .= " recuperableonly=" . (isset($this->recuperableonly) ? $this->recuperableonly : "null") . ",";
803
        $sql .= " localtax1_tx=" . (isset($this->localtax1_tx) ? (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx) : "null") . ",";
804
        $sql .= " localtax2_tx=" . (isset($this->localtax2_tx) ? (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx) : "null") . ",";
805
        $sql .= " localtax1_type=" . (!empty($this->localtax1_type) ? "'" . $this->db->escape($this->localtax1_type) . "'" : "'0'") . ",";
806
        $sql .= " localtax2_type=" . (!empty($this->localtax2_type) ? "'" . $this->db->escape($this->localtax2_type) . "'" : "'0'") . ",";
807
        $sql .= " fk_user=" . $user->id . ",";
808
        $sql .= " price_label=" . (isset($this->price_label) ? "'" . $this->db->escape($this->price_label) . "'" : "null") . ",";
809
        $sql .= " import_key=" . (isset($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "null");
810
811
        $sql .= " WHERE rowid=" . ((int) $this->id);
812
813
        dol_syslog(get_class($this) . "::update", LOG_DEBUG);
814
        $resql = $this->db->query($sql);
815
        if (!$resql) {
816
            $error++;
817
            $this->errors [] = "Error " . $this->db->lasterror();
818
        }
819
820
        if (!$error && !$notrigger) {
821
            // Call trigger
822
            $result = $this->call_trigger('PRODUCT_CUSTOMER_PRICE_MODIFY', $user);
823
            if ($result < 0) {
824
                $error++;
825
            }
826
            // End call triggers
827
        }
828
829
        if (!$error) {
830
            $result = $this->setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate);
831
            if ($result < 0) {
832
                $error++;
833
            }
834
        }
835
836
        // Commit or rollback
837
        if ($error) {
838
            foreach ($this->errors as $errmsg) {
839
                dol_syslog(get_class($this) . "::update " . $errmsg, LOG_ERR);
840
                $this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
841
            }
842
            $this->db->rollback();
843
            return -1 * $error;
844
        } else {
845
            $this->db->commit();
846
            return 1;
847
        }
848
    }
849
850
    /**
851
     * Force update price on child companies so child company has same prices than parent.
852
     *
853
     * @param   User $user                  User that modifies
854
     * @param   int $forceupdateaffiliate   update price on each soc child
855
     * @return  int                         Return integer <0 if KO, 0 = action disabled, >0 if OK
856
     */
857
    public function setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate)
858
    {
859
        global $conf;
860
861
        if (getDolGlobalString('PRODUCT_DISABLE_PROPAGATE_CUSTOMER_PRICES_ON_CHILD_COMPANIES')) {
862
            return 0;
863
        }
864
865
        $error = 0;
866
867
        // Find all susidiaries
868
        $sql = "SELECT s.rowid";
869
        $sql .= " FROM " . $this->db->prefix() . "societe as s";
870
        $sql .= " WHERE s.parent = " . ((int) $this->fk_soc);
871
        $sql .= " AND s.entity IN (" . getEntity('societe') . ")";
872
873
        dol_syslog(get_class($this) . "::setPriceOnAffiliateThirdparty", LOG_DEBUG);
874
        $resql = $this->db->query($sql);
875
876
        if ($resql) {
877
            $this->lines = array();
878
            $num = $this->db->num_rows($resql);
879
880
            while (($obj = $this->db->fetch_object($resql)) && (empty($error))) {
881
                // find if there is an existing line for the product and the subsidiaries
882
                $prodsocprice = new ProductCustomerPrice($this->db);
883
884
                $filter = array(
885
                    't.fk_product' => $this->fk_product, 't.fk_soc' => $obj->rowid
886
                );
887
888
                $result = $prodsocprice->fetchAll('', '', 0, 0, $filter);
889
                if ($result < 0) {
890
                    $error++;
891
                    $this->error = $prodsocprice->error;
892
                } else {
893
                    // There is one line
894
                    if (count($prodsocprice->lines) > 0) {
895
                        // If force update => Update
896
                        if (!empty($forceupdateaffiliate)) {
897
                            $prodsocpriceupd = new ProductCustomerPrice($this->db);
898
                            $prodsocpriceupd->fetch($prodsocprice->lines [0]->id);
899
900
                            $prodsocpriceupd->price = $this->price;
901
                            $prodsocpriceupd->price_min = $this->price_min;
902
                            $prodsocpriceupd->price_base_type = $this->price_base_type;
903
                            $prodsocpriceupd->tva_tx = $this->tva_tx;
904
                            $prodsocpriceupd->recuperableonly = $this->recuperableonly;
905
                            $prodsocpriceupd->price_label = $this->price_label;
906
907
                            $resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate);
908
                            if ($resultupd < 0) {
909
                                $error++;
910
                                $this->error = $prodsocpriceupd->error;
911
                            }
912
                        }
913
                    } else {
914
                        // If line do not exits then create it
915
                        $prodsocpricenew = new ProductCustomerPrice($this->db);
916
                        $prodsocpricenew->fk_soc = $obj->rowid;
917
                        $prodsocpricenew->ref_customer = $obj->ref_customer;
918
                        $prodsocpricenew->fk_product = $this->fk_product;
919
                        $prodsocpricenew->price = $this->price;
920
                        $prodsocpricenew->price_min = $this->price_min;
921
                        $prodsocpricenew->price_base_type = $this->price_base_type;
922
                        $prodsocpricenew->tva_tx = $this->tva_tx;
923
                        $prodsocpricenew->recuperableonly = $this->recuperableonly;
924
                        $prodsocpricenew->price_label = $this->price_label;
925
926
                        $resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate);
927
                        if ($resultupd < 0) {
928
                            $error++;
929
                            $this->error = $prodsocpricenew->error;
930
                        }
931
                    }
932
                }
933
            }
934
            $this->db->free($resql);
935
936
            if (empty($error)) {
937
                return 1;
938
            } else {
939
                return -1;
940
            }
941
        } else {
942
            $this->error = "Error " . $this->db->lasterror();
943
            return -1;
944
        }
945
    }
946
947
    /**
948
     * Delete object in database
949
     *
950
     * @param User $user that deletes
951
     * @param int $notrigger triggers after, 1=disable triggers
952
     * @return int Return integer <0 if KO, >0 if OK
953
     */
954
    public function delete($user, $notrigger = 0)
955
    {
956
        global $conf, $langs;
957
        $error = 0;
958
959
        $this->db->begin();
960
961
        if (!$notrigger) {
962
            $result = $this->call_trigger('PRODUCT_CUSTOMER_PRICE_DELETE', $user);
963
            if ($result < 0) {
964
                $error++;
965
            }
966
        }
967
968
        if (!$error) {
969
            $sql = "DELETE FROM " . $this->db->prefix() . "product_customer_price";
970
            $sql .= " WHERE rowid=" . ((int) $this->id);
971
972
            dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
973
            $resql = $this->db->query($sql);
974
            if (!$resql) {
975
                $error++;
976
                $this->errors [] = "Error " . $this->db->lasterror();
977
            }
978
        }
979
980
        // Commit or rollback
981
        if ($error) {
982
            foreach ($this->errors as $errmsg) {
983
                dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR);
984
                $this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
985
            }
986
            $this->db->rollback();
987
            return -1 * $error;
988
        } else {
989
            $this->db->commit();
990
            return 1;
991
        }
992
    }
993
994
    /**
995
     * Load an object from its id and create a new one in database
996
     *
997
     * @param   User    $user       User making the clone
998
     * @param   int     $fromid     ID of object to clone
999
     * @return  int                 id of clone
1000
     */
1001
    public function createFromClone(User $user, $fromid)
1002
    {
1003
        $error = 0;
1004
1005
        $object = new ProductCustomerPrice($this->db);
1006
1007
        $this->db->begin();
1008
1009
        // Load source object
1010
        $object->fetch($fromid);
1011
        $object->id = 0;
1012
        $object->statut = 0;
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$statut has been deprecated: Use $status instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1012
        /** @scrutinizer ignore-deprecated */ $object->statut = 0;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
1013
1014
        // Clear fields
1015
        // ...
1016
1017
        // Create clone
1018
        $object->context['createfromclone'] = 'createfromclone';
1019
        $result = $object->create($user);
1020
1021
        // Other options
1022
        if ($result < 0) {
1023
            $this->error = $object->error;
1024
            $this->errors = array_merge($this->errors, $object->errors);
1025
            $error++;
1026
        }
1027
1028
        if (!$error) {
1029
        }
1030
1031
        unset($object->context['createfromclone']);
1032
1033
        // End
1034
        if (!$error) {
1035
            $this->db->commit();
1036
            return $object->id;
1037
        } else {
1038
            $this->db->rollback();
1039
            return -1;
1040
        }
1041
    }
1042
1043
    /**
1044
     * Initialise object with example values
1045
     * Id must be 0 if object instance is a specimen
1046
     *
1047
     * @return int
1048
     */
1049
    public function initAsSpecimen()
1050
    {
1051
        $this->id = 0;
1052
1053
        $this->entity = 0;
1054
        $this->datec = '';
1055
        $this->tms = dol_now();
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$tms has been deprecated: Use $date_modification ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1055
        /** @scrutinizer ignore-deprecated */ $this->tms = dol_now();

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
1056
        $this->fk_product = 0;
1057
        $this->fk_soc = 0;
1058
        $this->ref_customer = '';
1059
        $this->price = '';
1060
        $this->price_ttc = '';
1061
        $this->price_min = '';
1062
        $this->price_min_ttc = '';
1063
        $this->price_base_type = '';
1064
        $this->default_vat_code = '';
1065
        $this->tva_tx = '';
1066
        $this->recuperableonly = '';
1067
        $this->localtax1_tx = '';
1068
        $this->localtax2_tx = '';
1069
        $this->fk_user = 0;
1070
        $this->price_label = '';
1071
        $this->import_key = '';
1072
1073
        return 1;
1074
    }
1075
}
1076