Total Complexity | 68 |
Total Lines | 477 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like CommandeFournisseurLigne 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 CommandeFournisseurLigne, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
51 | class CommandeFournisseurLigne extends CommonOrderLine |
||
52 | { |
||
53 | /** |
||
54 | * @var string ID to identify managed object |
||
55 | */ |
||
56 | public $element = 'commande_fournisseurdet'; |
||
57 | |||
58 | /** |
||
59 | * @var string Name of table without prefix where object is stored |
||
60 | */ |
||
61 | public $table_element = 'commande_fournisseurdet'; |
||
62 | |||
63 | public $oldline; |
||
64 | |||
65 | /** |
||
66 | * Id of parent order |
||
67 | * @var int |
||
68 | */ |
||
69 | public $fk_commande; |
||
70 | |||
71 | // From llx_commande_fournisseurdet |
||
72 | /** |
||
73 | * @var int ID |
||
74 | */ |
||
75 | public $fk_parent_line; |
||
76 | |||
77 | /** |
||
78 | * @var int ID |
||
79 | */ |
||
80 | public $fk_facture; |
||
81 | |||
82 | public $rang = 0; |
||
83 | public $special_code = 0; |
||
84 | |||
85 | /** |
||
86 | * Unit price without taxes |
||
87 | * @var float |
||
88 | */ |
||
89 | public $pu_ht; |
||
90 | |||
91 | public $date_start; |
||
92 | public $date_end; |
||
93 | public $fk_fournprice; |
||
94 | public $packaging; |
||
95 | public $pa_ht; |
||
96 | |||
97 | // From llx_product_fournisseur_price |
||
98 | |||
99 | /** |
||
100 | * Supplier reference of price when we added the line. May have been changed after line was added. |
||
101 | * @var string |
||
102 | */ |
||
103 | public $ref_supplier; |
||
104 | |||
105 | /** |
||
106 | * @var string ref supplier |
||
107 | * @deprecated |
||
108 | * @see $ref_supplier |
||
109 | */ |
||
110 | public $ref_fourn; |
||
111 | |||
112 | public $remise; |
||
113 | |||
114 | |||
115 | /** |
||
116 | * Constructor |
||
117 | * |
||
118 | * @param DoliDB $db Database handler |
||
119 | */ |
||
120 | public function __construct($db) |
||
121 | { |
||
122 | $this->db = $db; |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * Load line order |
||
127 | * |
||
128 | * @param int $rowid Id line order |
||
129 | * @return int Return integer <0 if KO, >0 if OK |
||
130 | */ |
||
131 | public function fetch($rowid) |
||
132 | { |
||
133 | $sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx, cd.special_code,'; |
||
134 | $sql .= ' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref as ref_supplier,'; |
||
135 | $sql .= ' cd.remise, cd.remise_percent, cd.subprice,'; |
||
136 | $sql .= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,'; |
||
137 | $sql .= ' cd.total_localtax1, cd.total_localtax2,'; |
||
138 | $sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,'; |
||
139 | $sql .= ' cd.date_start, cd.date_end, cd.fk_unit,'; |
||
140 | $sql .= ' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,'; |
||
141 | $sql .= ' c.fk_soc as socid'; |
||
142 | $sql .= ' FROM ' . $this->db->prefix() . 'commande_fournisseur as c, ' . $this->db->prefix() . 'commande_fournisseurdet as cd'; |
||
143 | $sql .= ' LEFT JOIN ' . $this->db->prefix() . 'product as p ON cd.fk_product = p.rowid'; |
||
144 | $sql .= ' WHERE cd.fk_commande = c.rowid AND cd.rowid = ' . ((int) $rowid); |
||
145 | |||
146 | $result = $this->db->query($sql); |
||
147 | if ($result) { |
||
148 | $objp = $this->db->fetch_object($result); |
||
149 | |||
150 | if (!empty($objp)) { |
||
151 | $this->rowid = $objp->rowid; |
||
|
|||
152 | $this->id = $objp->rowid; |
||
153 | $this->fk_commande = $objp->fk_commande; |
||
154 | $this->desc = $objp->description; |
||
155 | $this->qty = $objp->qty; |
||
156 | $this->ref_fourn = $objp->ref_supplier; |
||
157 | $this->ref_supplier = $objp->ref_supplier; |
||
158 | $this->subprice = $objp->subprice; |
||
159 | $this->tva_tx = $objp->tva_tx; |
||
160 | $this->localtax1_tx = $objp->localtax1_tx; |
||
161 | $this->localtax2_tx = $objp->localtax2_tx; |
||
162 | $this->localtax1_type = $objp->localtax1_type; |
||
163 | $this->localtax2_type = $objp->localtax2_type; |
||
164 | $this->remise = $objp->remise; |
||
165 | $this->remise_percent = $objp->remise_percent; |
||
166 | $this->fk_product = $objp->fk_product; |
||
167 | $this->info_bits = $objp->info_bits; |
||
168 | $this->total_ht = $objp->total_ht; |
||
169 | $this->total_tva = $objp->total_tva; |
||
170 | $this->total_localtax1 = $objp->total_localtax1; |
||
171 | $this->total_localtax2 = $objp->total_localtax2; |
||
172 | $this->total_ttc = $objp->total_ttc; |
||
173 | $this->product_type = $objp->product_type; |
||
174 | $this->special_code = $objp->special_code; |
||
175 | |||
176 | $this->ref = $objp->product_ref; |
||
177 | |||
178 | $this->product_ref = $objp->product_ref; |
||
179 | $this->product_label = $objp->product_label; |
||
180 | $this->product_desc = $objp->product_desc; |
||
181 | |||
182 | if (getDolGlobalInt('PRODUCT_USE_SUPPLIER_PACKAGING')) { |
||
183 | // TODO We should not fetch this properties into the fetch_lines. This is NOT properties of a line. |
||
184 | // Move this into another method and call it when required. |
||
185 | |||
186 | // Take better packaging for $objp->qty (first supplier ref quantity <= $objp->qty) |
||
187 | $sqlsearchpackage = 'SELECT rowid, packaging FROM ' . $this->db->prefix() . "product_fournisseur_price"; |
||
188 | $sqlsearchpackage .= ' WHERE entity IN (' . getEntity('product_fournisseur_price') . ")"; |
||
189 | $sqlsearchpackage .= " AND fk_product = " . ((int) $objp->fk_product); |
||
190 | $sqlsearchpackage .= " AND ref_fourn = '" . $this->db->escape($objp->ref_supplier) . "'"; |
||
191 | $sqlsearchpackage .= " AND quantity <= " . ((float) $objp->qty); // required to be qualified |
||
192 | $sqlsearchpackage .= " AND (packaging IS NULL OR packaging = 0 OR packaging <= " . ((float) $objp->qty) . ")"; // required to be qualified |
||
193 | $sqlsearchpackage .= " AND fk_soc = " . ((int) $objp->socid); |
||
194 | $sqlsearchpackage .= " ORDER BY packaging ASC"; // Take the smaller package first |
||
195 | $sqlsearchpackage .= " LIMIT 1"; |
||
196 | |||
197 | $resqlsearchpackage = $this->db->query($sqlsearchpackage); |
||
198 | if ($resqlsearchpackage) { |
||
199 | $objsearchpackage = $this->db->fetch_object($resqlsearchpackage); |
||
200 | if ($objsearchpackage) { |
||
201 | $this->fk_fournprice = $objsearchpackage->rowid; |
||
202 | $this->packaging = $objsearchpackage->packaging; |
||
203 | } |
||
204 | } else { |
||
205 | $this->error = $this->db->lasterror(); |
||
206 | return -1; |
||
207 | } |
||
208 | } |
||
209 | |||
210 | $this->date_start = $this->db->jdate($objp->date_start); |
||
211 | $this->date_end = $this->db->jdate($objp->date_end); |
||
212 | $this->fk_unit = $objp->fk_unit; |
||
213 | |||
214 | $this->multicurrency_subprice = $objp->multicurrency_subprice; |
||
215 | $this->multicurrency_total_ht = $objp->multicurrency_total_ht; |
||
216 | $this->multicurrency_total_tva = $objp->multicurrency_total_tva; |
||
217 | $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc; |
||
218 | |||
219 | $this->fetch_optionals(); |
||
220 | |||
221 | $this->db->free($result); |
||
222 | return 1; |
||
223 | } else { |
||
224 | $this->error = 'Supplier order line with id=' . $rowid . ' not found'; |
||
225 | dol_syslog(get_class($this) . "::fetch Error " . $this->error, LOG_ERR); |
||
226 | return 0; |
||
227 | } |
||
228 | } else { |
||
229 | dol_print_error($this->db); |
||
230 | return -1; |
||
231 | } |
||
232 | } |
||
233 | |||
234 | /** |
||
235 | * Insert line into database |
||
236 | * |
||
237 | * @param int $notrigger 1 = disable triggers |
||
238 | * @return int Return integer <0 if KO, >0 if OK |
||
239 | */ |
||
240 | public function insert($notrigger = 0) |
||
385 | } |
||
386 | } |
||
387 | /** |
||
388 | * Update the line object into db |
||
389 | * |
||
390 | * @param int $notrigger 1 = disable triggers |
||
391 | * @return int Return integer <0 si ko, >0 si ok |
||
392 | */ |
||
393 | public function update($notrigger = 0) |
||
466 | } |
||
467 | } |
||
468 | |||
469 | /** |
||
470 | * Delete line in database |
||
471 | * |
||
472 | * @param User $user User making the change |
||
473 | * @param int $notrigger 1=Disable call to triggers |
||
474 | * @return int Return integer <0 if KO, >0 if OK |
||
475 | */ |
||
476 | public function delete($user, $notrigger = 0) |
||
528 | } |
||
529 | } |
||
530 | } |
||
531 |
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.