Total Complexity | 184 |
Total Lines | 907 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like AccountingAccount 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 AccountingAccount, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
40 | class AccountingAccount extends CommonObject |
||
41 | { |
||
42 | /** |
||
43 | * @var string Name of element |
||
44 | */ |
||
45 | public $element = 'accounting_account'; |
||
46 | |||
47 | /** |
||
48 | * @var string Name of table without prefix where object is stored |
||
49 | */ |
||
50 | public $table_element = 'accounting_account'; |
||
51 | |||
52 | /** |
||
53 | * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png |
||
54 | */ |
||
55 | public $picto = 'billr'; |
||
56 | |||
57 | /** |
||
58 | * 0=Default, 1=View may be restricted to sales representative only if no permission to see all or to company of external user if external user |
||
59 | * @var integer |
||
60 | */ |
||
61 | public $restrictiononfksoc = 1; |
||
62 | |||
63 | /** |
||
64 | * @var DoliDB Database handler. |
||
|
|||
65 | */ |
||
66 | public $db; |
||
67 | |||
68 | /** |
||
69 | * @var int ID |
||
70 | */ |
||
71 | public $id; |
||
72 | |||
73 | /** |
||
74 | * @var int ID |
||
75 | */ |
||
76 | public $rowid; |
||
77 | |||
78 | /** |
||
79 | * Date creation record (datec) |
||
80 | * |
||
81 | * @var integer |
||
82 | */ |
||
83 | public $datec; |
||
84 | |||
85 | /** |
||
86 | * @var string pcg version |
||
87 | */ |
||
88 | public $fk_pcg_version; |
||
89 | |||
90 | /** |
||
91 | * @var string pcg type |
||
92 | */ |
||
93 | public $pcg_type; |
||
94 | |||
95 | /** |
||
96 | * @var string account number |
||
97 | */ |
||
98 | public $account_number; |
||
99 | |||
100 | /** |
||
101 | * @var int ID parent account |
||
102 | */ |
||
103 | public $account_parent; |
||
104 | |||
105 | /** |
||
106 | * @var int ID category account |
||
107 | */ |
||
108 | public $account_category; |
||
109 | |||
110 | /** |
||
111 | * @var int Label category account |
||
112 | */ |
||
113 | public $account_category_label; |
||
114 | |||
115 | /** |
||
116 | * @var int Status |
||
117 | */ |
||
118 | public $status; |
||
119 | |||
120 | /** |
||
121 | * @var string Label of account |
||
122 | */ |
||
123 | public $label; |
||
124 | |||
125 | /** |
||
126 | * @var string Label short of account |
||
127 | */ |
||
128 | public $labelshort; |
||
129 | |||
130 | /** |
||
131 | * @var int ID |
||
132 | */ |
||
133 | public $fk_user_author; |
||
134 | |||
135 | /** |
||
136 | * @var int ID |
||
137 | */ |
||
138 | public $fk_user_modif; |
||
139 | |||
140 | /** |
||
141 | * @var int active (duplicate with status) |
||
142 | */ |
||
143 | public $active; |
||
144 | |||
145 | /** |
||
146 | * @var int reconcilable |
||
147 | */ |
||
148 | public $reconcilable; |
||
149 | |||
150 | /** |
||
151 | * @var array cache array |
||
152 | */ |
||
153 | private $accountingaccount_codetotid_cache = array(); |
||
154 | |||
155 | |||
156 | const STATUS_ENABLED = 1; |
||
157 | const STATUS_DISABLED = 0; |
||
158 | |||
159 | |||
160 | /** |
||
161 | * Constructor |
||
162 | * |
||
163 | * @param DoliDB $db Database handle |
||
164 | */ |
||
165 | public function __construct($db) |
||
166 | { |
||
167 | $this->db = $db; |
||
168 | |||
169 | $this->ismultientitymanaged = 1; |
||
170 | $this->next_prev_filter = "fk_pcg_version IN (SELECT pcg_version FROM " . MAIN_DB_PREFIX . "accounting_system WHERE rowid = " . ((int) getDolGlobalInt('CHARTOFACCOUNTS')) . ")"; // Used to add a filter in Form::showrefnav method |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * Load record in memory |
||
175 | * |
||
176 | * @param int $rowid Id |
||
177 | * @param string|null $account_number Account number |
||
178 | * @param int|boolean $limittocurrentchart 1 or true=Load record only if it is into current active chart of account |
||
179 | * @param string $limittoachartaccount 'ABC'=Load record only if it is into chart account with code 'ABC' (better and faster than previous parameter if you have chart of account code). |
||
180 | * @return int Return integer <0 if KO, 0 if not found, Id of record if OK and found |
||
181 | */ |
||
182 | public function fetch($rowid = 0, $account_number = null, $limittocurrentchart = 0, $limittoachartaccount = '') |
||
183 | { |
||
184 | global $conf; |
||
185 | |||
186 | if ($rowid || $account_number) { |
||
187 | $sql = "SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.account_number, a.account_parent, a.label, a.labelshort, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active, a.reconcilable"; |
||
188 | $sql .= ", ca.label as category_label"; |
||
189 | $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a"; |
||
190 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_accounting_category as ca ON a.fk_accounting_category = ca.rowid"; |
||
191 | $sql .= " WHERE"; |
||
192 | if ($rowid) { |
||
193 | $sql .= " a.rowid = " . (int) $rowid; |
||
194 | } elseif ($account_number) { |
||
195 | $sql .= " a.account_number = '" . $this->db->escape($account_number) . "'"; |
||
196 | $sql .= " AND a.entity = " . $conf->entity; |
||
197 | } |
||
198 | if (!empty($limittocurrentchart)) { |
||
199 | $sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid = ' . ((int) getDolGlobalInt('CHARTOFACCOUNTS')) . ')'; |
||
200 | } |
||
201 | if (!empty($limittoachartaccount)) { |
||
202 | $sql .= " AND a.fk_pcg_version = '" . $this->db->escape($limittoachartaccount) . "'"; |
||
203 | } |
||
204 | |||
205 | dol_syslog(get_only_class($this) . "::fetch rowid=" . $rowid . " account_number=" . $account_number, LOG_DEBUG); |
||
206 | |||
207 | $result = $this->db->query($sql); |
||
208 | if ($result) { |
||
209 | $obj = $this->db->fetch_object($result); |
||
210 | |||
211 | if ($obj) { |
||
212 | $this->id = $obj->rowid; |
||
213 | $this->rowid = $obj->rowid; |
||
214 | $this->ref = $obj->account_number; |
||
215 | $this->datec = $this->db->jdate($obj->datec); |
||
216 | $this->date_creation = $this->db->jdate($obj->datec); |
||
217 | $this->date_modification = $this->db->jdate($obj->tms); |
||
218 | //$this->tms = $this->datem; |
||
219 | $this->fk_pcg_version = $obj->fk_pcg_version; |
||
220 | $this->pcg_type = $obj->pcg_type; |
||
221 | $this->account_number = $obj->account_number; |
||
222 | $this->account_parent = $obj->account_parent; |
||
223 | $this->label = $obj->label; |
||
224 | $this->labelshort = $obj->labelshort; |
||
225 | $this->account_category = $obj->fk_accounting_category; |
||
226 | $this->account_category_label = $obj->category_label; |
||
227 | $this->fk_user_author = $obj->fk_user_author; |
||
228 | $this->fk_user_modif = $obj->fk_user_modif; |
||
229 | $this->active = $obj->active; |
||
230 | $this->status = $obj->active; |
||
231 | $this->reconcilable = $obj->reconcilable; |
||
232 | |||
233 | return $this->id; |
||
234 | } else { |
||
235 | return 0; |
||
236 | } |
||
237 | } else { |
||
238 | $this->error = "Error " . $this->db->lasterror(); |
||
239 | $this->errors[] = "Error " . $this->db->lasterror(); |
||
240 | } |
||
241 | } |
||
242 | return -1; |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * Insert new accounting account in chart of accounts |
||
247 | * |
||
248 | * @param User $user User making action |
||
249 | * @param int $notrigger Disable triggers |
||
250 | * @return int Return integer <0 if KO, >0 if OK |
||
251 | */ |
||
252 | public function create($user, $notrigger = 0) |
||
253 | { |
||
254 | global $conf; |
||
255 | $error = 0; |
||
256 | $now = dol_now(); |
||
257 | |||
258 | // Clean parameters |
||
259 | if (isset($this->fk_pcg_version)) { |
||
260 | $this->fk_pcg_version = trim($this->fk_pcg_version); |
||
261 | } |
||
262 | if (isset($this->pcg_type)) { |
||
263 | $this->pcg_type = trim($this->pcg_type); |
||
264 | } |
||
265 | if (isset($this->account_number)) { |
||
266 | $this->account_number = trim($this->account_number); |
||
267 | } |
||
268 | if (isset($this->label)) { |
||
269 | $this->label = trim($this->label); |
||
270 | } |
||
271 | if (isset($this->labelshort)) { |
||
272 | $this->labelshort = trim($this->labelshort); |
||
273 | } |
||
274 | |||
275 | if (empty($this->pcg_type) || $this->pcg_type == '-1') { |
||
276 | $this->pcg_type = 'XXXXXX'; |
||
277 | } |
||
278 | // Check parameters |
||
279 | // Put here code to add control on parameters values |
||
280 | |||
281 | // Insert request |
||
282 | $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_account("; |
||
283 | $sql .= "datec"; |
||
284 | $sql .= ", entity"; |
||
285 | $sql .= ", fk_pcg_version"; |
||
286 | $sql .= ", pcg_type"; |
||
287 | $sql .= ", account_number"; |
||
288 | $sql .= ", account_parent"; |
||
289 | $sql .= ", label"; |
||
290 | $sql .= ", labelshort"; |
||
291 | $sql .= ", fk_accounting_category"; |
||
292 | $sql .= ", fk_user_author"; |
||
293 | $sql .= ", active"; |
||
294 | $sql .= ", reconcilable"; |
||
295 | $sql .= ") VALUES ("; |
||
296 | $sql .= " '" . $this->db->idate($now) . "'"; |
||
297 | $sql .= ", " . ((int) $conf->entity); |
||
298 | $sql .= ", " . (empty($this->fk_pcg_version) ? 'NULL' : "'" . $this->db->escape($this->fk_pcg_version) . "'"); |
||
299 | $sql .= ", " . (empty($this->pcg_type) ? 'NULL' : "'" . $this->db->escape($this->pcg_type) . "'"); |
||
300 | $sql .= ", " . (empty($this->account_number) ? 'NULL' : "'" . $this->db->escape($this->account_number) . "'"); |
||
301 | $sql .= ", " . (empty($this->account_parent) ? 0 : (int) $this->account_parent); |
||
302 | $sql .= ", " . (empty($this->label) ? "''" : "'" . $this->db->escape($this->label) . "'"); |
||
303 | $sql .= ", " . (empty($this->labelshort) ? "''" : "'" . $this->db->escape($this->labelshort) . "'"); |
||
304 | $sql .= ", " . (empty($this->account_category) ? 0 : (int) $this->account_category); |
||
305 | $sql .= ", " . ((int) $user->id); |
||
306 | $sql .= ", " . (int) $this->active; |
||
307 | $sql .= ", " . (int) $this->reconcilable; |
||
308 | $sql .= ")"; |
||
309 | |||
310 | $this->db->begin(); |
||
311 | |||
312 | dol_syslog(get_only_class($this) . "::create", LOG_DEBUG); |
||
313 | $resql = $this->db->query($sql); |
||
314 | if (!$resql) { |
||
315 | $error++; |
||
316 | $this->errors[] = "Error " . $this->db->lasterror(); |
||
317 | } |
||
318 | |||
319 | if (!$error) { |
||
320 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_account"); |
||
321 | |||
322 | // Uncomment this and change MYOBJECT to your own tag if you |
||
323 | // want this action to call a trigger. |
||
324 | //if (! $error && ! $notrigger) { |
||
325 | |||
326 | // // Call triggers |
||
327 | // $result=$this->call_trigger('MYOBJECT_CREATE',$user); |
||
328 | // if ($result < 0) $error++; |
||
329 | // // End call triggers |
||
330 | //} |
||
331 | } |
||
332 | |||
333 | // Commit or rollback |
||
334 | if ($error) { |
||
335 | foreach ($this->errors as $errmsg) { |
||
336 | dol_syslog(get_only_class($this) . "::create " . $errmsg, LOG_ERR); |
||
337 | $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); |
||
338 | } |
||
339 | $this->db->rollback(); |
||
340 | return -1 * $error; |
||
341 | } else { |
||
342 | $this->db->commit(); |
||
343 | return $this->id; |
||
344 | } |
||
345 | } |
||
346 | |||
347 | /** |
||
348 | * Update record |
||
349 | * |
||
350 | * @param User $user User making update |
||
351 | * @return int Return integer <0 if KO (-2 = duplicate), >0 if OK |
||
352 | */ |
||
353 | public function update($user) |
||
354 | { |
||
355 | // Check parameters |
||
356 | if (empty($this->pcg_type) || $this->pcg_type == '-1') { |
||
357 | $this->pcg_type = 'XXXXXX'; |
||
358 | } |
||
359 | |||
360 | $this->db->begin(); |
||
361 | |||
362 | $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; |
||
363 | $sql .= " SET fk_pcg_version = " . ($this->fk_pcg_version ? "'" . $this->db->escape($this->fk_pcg_version) . "'" : "null"); |
||
364 | $sql .= " , pcg_type = " . ($this->pcg_type ? "'" . $this->db->escape($this->pcg_type) . "'" : "null"); |
||
365 | $sql .= " , account_number = '" . $this->db->escape($this->account_number) . "'"; |
||
366 | $sql .= " , account_parent = " . (int) $this->account_parent; |
||
367 | $sql .= " , label = " . ($this->label ? "'" . $this->db->escape($this->label) . "'" : "''"); |
||
368 | $sql .= " , labelshort = " . ($this->labelshort ? "'" . $this->db->escape($this->labelshort) . "'" : "''"); |
||
369 | $sql .= " , fk_accounting_category = " . (empty($this->account_category) ? 0 : (int) $this->account_category); |
||
370 | $sql .= " , fk_user_modif = " . ((int) $user->id); |
||
371 | $sql .= " , active = " . (int) $this->active; |
||
372 | $sql .= " , reconcilable = " . (int) $this->reconcilable; |
||
373 | $sql .= " WHERE rowid = " . ((int) $this->id); |
||
374 | |||
375 | dol_syslog(get_only_class($this) . "::update", LOG_DEBUG); |
||
376 | $result = $this->db->query($sql); |
||
377 | if ($result) { |
||
378 | $this->db->commit(); |
||
379 | return 1; |
||
380 | } else { |
||
381 | if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { |
||
382 | $this->error = $this->db->lasterror(); |
||
383 | $this->db->rollback(); |
||
384 | return -2; |
||
385 | } |
||
386 | |||
387 | $this->error = $this->db->lasterror(); |
||
388 | $this->db->rollback(); |
||
389 | return -1; |
||
390 | } |
||
391 | } |
||
392 | |||
393 | /** |
||
394 | * Check usage of accounting code |
||
395 | * |
||
396 | * @return int Return integer <0 if KO, >0 if OK |
||
397 | */ |
||
398 | public function checkUsage() |
||
399 | { |
||
400 | global $langs; |
||
401 | |||
402 | // TODO Looks a stupid check |
||
403 | $sql = "(SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facturedet"; |
||
404 | $sql .= " WHERE fk_code_ventilation=" . ((int) $this->id) . ")"; |
||
405 | $sql .= "UNION"; |
||
406 | $sql .= " (SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facture_fourn_det"; |
||
407 | $sql .= " WHERE fk_code_ventilation=" . ((int) $this->id) . ")"; |
||
408 | |||
409 | dol_syslog(get_only_class($this) . "::checkUsage", LOG_DEBUG); |
||
410 | $resql = $this->db->query($sql); |
||
411 | |||
412 | if ($resql) { |
||
413 | $num = $this->db->num_rows($resql); |
||
414 | if ($num > 0) { |
||
415 | $this->error = $langs->trans('ErrorAccountancyCodeIsAlreadyUse'); |
||
416 | return 0; |
||
417 | } else { |
||
418 | return 1; |
||
419 | } |
||
420 | } else { |
||
421 | $this->error = $this->db->lasterror(); |
||
422 | return -1; |
||
423 | } |
||
424 | } |
||
425 | |||
426 | /** |
||
427 | * Delete object in database |
||
428 | * |
||
429 | * @param User $user User that deletes |
||
430 | * @param int $notrigger 0=triggers after, 1=disable triggers |
||
431 | * @return int Return integer <0 if KO, >0 if OK |
||
432 | */ |
||
433 | public function delete($user, $notrigger = 0) |
||
434 | { |
||
435 | $error = 0; |
||
436 | |||
437 | $result = $this->checkUsage(); |
||
438 | |||
439 | if ($result > 0) { |
||
440 | $this->db->begin(); |
||
441 | |||
442 | if (!$error) { |
||
443 | $sql = "DELETE FROM " . MAIN_DB_PREFIX . "accounting_account"; |
||
444 | $sql .= " WHERE rowid=" . ((int) $this->id); |
||
445 | |||
446 | dol_syslog(get_only_class($this) . "::delete sql=" . $sql); |
||
447 | $resql = $this->db->query($sql); |
||
448 | if (!$resql) { |
||
449 | $error++; |
||
450 | $this->errors[] = "Error " . $this->db->lasterror(); |
||
451 | } |
||
452 | } |
||
453 | |||
454 | // Commit or rollback |
||
455 | if ($error) { |
||
456 | foreach ($this->errors as $errmsg) { |
||
457 | dol_syslog(get_only_class($this) . "::delete " . $errmsg, LOG_ERR); |
||
458 | $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); |
||
459 | } |
||
460 | $this->db->rollback(); |
||
461 | return -1 * $error; |
||
462 | } else { |
||
463 | $this->db->commit(); |
||
464 | return 1; |
||
465 | } |
||
466 | } else { |
||
467 | return -1; |
||
468 | } |
||
469 | } |
||
470 | |||
471 | /** |
||
472 | * Return clicable name (with picto eventually) |
||
473 | * |
||
474 | * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
||
475 | * @param int $withlabel 0=No label, 1=Include label of account |
||
476 | * @param int $nourl 1=Disable url |
||
477 | * @param string $moretitle Add more text to title tooltip |
||
478 | * @param int $notooltip 1=Disable tooltip |
||
479 | * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
||
480 | * @param int $withcompletelabel 0=Short label (field short label), 1=Complete label (field label) |
||
481 | * @param string $option 'ledger', 'journals', 'accountcard' |
||
482 | * @return string String with URL |
||
483 | */ |
||
484 | public function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle = '', $notooltip = 0, $save_lastsearch_value = -1, $withcompletelabel = 0, $option = '') |
||
485 | { |
||
486 | global $langs, $conf, $hookmanager; |
||
487 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/accounting.lib.php'; |
||
488 | |||
489 | if (!empty($conf->dol_no_mouse_hover)) { |
||
490 | $notooltip = 1; // Force disable tooltips |
||
491 | } |
||
492 | |||
493 | $result = ''; |
||
494 | |||
495 | $url = ''; |
||
496 | $labelurl = ''; |
||
497 | if (empty($option) || $option == 'ledger') { |
||
498 | $url = constant('BASE_URL') . '/accountancy/bookkeeping/listbyaccount.php?search_accountancy_code_start=' . urlencode((isset($this->account_number) ? $this->account_number : '')) . '&search_accountancy_code_end=' . urlencode((isset($this->account_number) ? $this->account_number : '')); |
||
499 | $labelurl = $langs->trans("ShowAccountingAccountInLedger"); |
||
500 | } elseif ($option == 'journals') { |
||
501 | $url = constant('BASE_URL') . '/accountancy/bookkeeping/list.php?search_accountancy_code_start=' . urlencode($this->account_number) . '&search_accountancy_code_end=' . urlencode($this->account_number); |
||
502 | $labelurl = $langs->trans("ShowAccountingAccountInJournals"); |
||
503 | } elseif ($option == 'accountcard') { |
||
504 | $url = constant('BASE_URL') . '/accountancy/admin/card.php?id=' . urlencode((string) ($this->id)); |
||
505 | $labelurl = $langs->trans("ShowAccountingAccount"); |
||
506 | } |
||
507 | |||
508 | // Add param to save lastsearch_values or not |
||
509 | $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); |
||
510 | if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { |
||
511 | $add_save_lastsearch_values = 1; |
||
512 | } |
||
513 | if ($add_save_lastsearch_values) { |
||
514 | $url .= '&save_lastsearch_values=1'; |
||
515 | } |
||
516 | |||
517 | $picto = 'accounting_account'; |
||
518 | $label = ''; |
||
519 | |||
520 | if (empty($this->labelshort) || $withcompletelabel == 1) { |
||
521 | $labeltoshow = $this->label; |
||
522 | } else { |
||
523 | $labeltoshow = $this->labelshort; |
||
524 | } |
||
525 | |||
526 | $label = '<u>' . $labelurl . '</u>'; |
||
527 | if (!empty($this->account_number)) { |
||
528 | $label .= '<br><b>' . $langs->trans('AccountAccounting') . ':</b> ' . length_accountg($this->account_number); |
||
529 | } |
||
530 | if (!empty($labeltoshow)) { |
||
531 | $label .= '<br><b>' . $langs->trans('Label') . ':</b> ' . $labeltoshow; |
||
532 | } |
||
533 | if ($moretitle) { |
||
534 | $label .= ' - ' . $moretitle; |
||
535 | } |
||
536 | |||
537 | $linkclose = ''; |
||
538 | if (empty($notooltip)) { |
||
539 | if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { |
||
540 | $label = $labelurl; |
||
541 | $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"'; |
||
542 | } |
||
543 | $linkclose .= ' title="' . dol_escape_htmltag($label, 1) . '"'; |
||
544 | $linkclose .= ' class="classfortooltip"'; |
||
545 | } |
||
546 | |||
547 | $linkstart = '<a href="' . $url . '"'; |
||
548 | $linkstart .= $linkclose . '>'; |
||
549 | $linkend = '</a>'; |
||
550 | |||
551 | if ($nourl) { |
||
552 | $linkstart = ''; |
||
553 | $linkclose = ''; |
||
554 | $linkend = ''; |
||
555 | } |
||
556 | |||
557 | $label_link = length_accountg($this->account_number); |
||
558 | if ($withlabel) { |
||
559 | $label_link .= ' - ' . ($nourl ? '<span class="opacitymedium">' : '') . $labeltoshow . ($nourl ? '</span>' : ''); |
||
560 | } |
||
561 | |||
562 | if ($withpicto) { |
||
563 | $result .= ($linkstart . img_object(($notooltip ? '' : $label), $picto, ($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1) . $linkend); |
||
564 | } |
||
565 | if ($withpicto && $withpicto != 2) { |
||
566 | $result .= ' '; |
||
567 | } |
||
568 | if ($withpicto != 2) { |
||
569 | $result .= $linkstart . $label_link . $linkend; |
||
570 | } |
||
571 | global $action; |
||
572 | $hookmanager->initHooks(array($this->element . 'dao')); |
||
573 | $parameters = array('id' => $this->id, 'getnomurl' => &$result); |
||
574 | $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
||
575 | if ($reshook > 0) { |
||
576 | $result = $hookmanager->resPrint; |
||
577 | } else { |
||
578 | $result .= $hookmanager->resPrint; |
||
579 | } |
||
580 | return $result; |
||
581 | } |
||
582 | |||
583 | /** |
||
584 | * Information on record |
||
585 | * |
||
586 | * @param int $id ID of record |
||
587 | * @return void |
||
588 | */ |
||
589 | public function info($id) |
||
590 | { |
||
591 | $sql = 'SELECT a.rowid, a.datec, a.fk_user_author, a.fk_user_modif, a.tms as date_modification'; |
||
592 | $sql .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as a'; |
||
593 | $sql .= ' WHERE a.rowid = ' . ((int) $id); |
||
594 | |||
595 | dol_syslog(get_only_class($this) . '::info sql=' . $sql); |
||
596 | $resql = $this->db->query($sql); |
||
597 | |||
598 | if ($resql) { |
||
599 | if ($this->db->num_rows($resql)) { |
||
600 | $obj = $this->db->fetch_object($resql); |
||
601 | |||
602 | $this->id = $obj->rowid; |
||
603 | |||
604 | $this->user_creation_id = $obj->fk_user_author; |
||
605 | $this->user_modification_id = $obj->fk_user_modif; |
||
606 | $this->date_creation = $this->db->jdate($obj->datec); |
||
607 | $this->date_modification = $this->db->jdate($obj->date_modification); |
||
608 | } |
||
609 | $this->db->free($resql); |
||
610 | } else { |
||
611 | dol_print_error($this->db); |
||
612 | } |
||
613 | } |
||
614 | |||
615 | /** |
||
616 | * Deactivate an account (for status active or status reconcilable) |
||
617 | * |
||
618 | * @param int $id Id |
||
619 | * @param int $mode 0=field active, 1=field reconcilable |
||
620 | * @return int Return integer <0 if KO, >0 if OK |
||
621 | */ |
||
622 | public function accountDeactivate($id, $mode = 0) |
||
623 | { |
||
624 | $result = $this->checkUsage(); |
||
625 | |||
626 | $fieldtouse = 'active'; |
||
627 | if ($mode == 1) { |
||
628 | $fieldtouse = 'reconcilable'; |
||
629 | } |
||
630 | |||
631 | if ($result > 0) { |
||
632 | $this->db->begin(); |
||
633 | |||
634 | $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; |
||
635 | $sql .= "SET " . $this->db->sanitize($fieldtouse) . " = 0"; |
||
636 | $sql .= " WHERE rowid = " . ((int) $id); |
||
637 | |||
638 | dol_syslog(get_only_class($this) . "::accountDeactivate " . $fieldtouse, LOG_DEBUG); |
||
639 | $result = $this->db->query($sql); |
||
640 | |||
641 | if ($result) { |
||
642 | $this->db->commit(); |
||
643 | return 1; |
||
644 | } else { |
||
645 | $this->error = $this->db->lasterror(); |
||
646 | $this->db->rollback(); |
||
647 | return -1; |
||
648 | } |
||
649 | } else { |
||
650 | return -1; |
||
651 | } |
||
652 | } |
||
653 | |||
654 | |||
655 | /** |
||
656 | * Account activated |
||
657 | * |
||
658 | * @param int $id Id |
||
659 | * @param int $mode 0=field active, 1=field reconcilable |
||
660 | * @return int Return integer <0 if KO, >0 if OK |
||
661 | */ |
||
662 | public function accountActivate($id, $mode = 0) |
||
685 | } |
||
686 | } |
||
687 | |||
688 | /** |
||
689 | * Return the label of the status |
||
690 | * |
||
691 | * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto |
||
692 | * @return string Label of status |
||
693 | */ |
||
694 | public function getLibStatut($mode = 0) |
||
697 | } |
||
698 | |||
699 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
700 | /** |
||
701 | * Return the label of a given status |
||
702 | * |
||
703 | * @param int $status Id status |
||
704 | * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto |
||
705 | * @return string Label of status |
||
706 | */ |
||
707 | public function LibStatut($status, $mode = 0) |
||
708 | { |
||
709 | // phpcs:enable |
||
710 | if (empty($this->labelStatus) || empty($this->labelStatusShort)) { |
||
711 | global $langs; |
||
712 | $langs->load("users"); |
||
713 | $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled'); |
||
714 | $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled'); |
||
715 | $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled'); |
||
716 | $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled'); |
||
717 | } |
||
718 | |||
719 | $statusType = 'status4'; |
||
720 | if ($status == self::STATUS_DISABLED) { |
||
721 | $statusType = 'status5'; |
||
722 | } |
||
723 | |||
724 | return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); |
||
725 | } |
||
726 | |||
727 | /** |
||
728 | * Return a suggested account (from chart of accounts) to bind |
||
729 | * |
||
730 | * @param Societe $buyer Object buyer |
||
731 | * @param Societe $seller Object seller |
||
732 | * @param Product $product Product object sell or buy |
||
733 | * @param Facture|FactureFournisseur $facture Facture |
||
734 | * @param FactureLigne|SupplierInvoiceLine $factureDet Facture Det |
||
735 | * @param array $accountingAccount Array of Accounting account |
||
736 | * @param string $type Customer / Supplier |
||
737 | * @return array|int Array of accounting accounts suggested or < 0 if technical error. |
||
738 | * 'suggestedaccountingaccountbydefaultfor'=>Will be used for the label to show on tooltip for account by default on any product |
||
739 | * 'suggestedaccountingaccountfor'=>Is the account suggested for this product |
||
740 | */ |
||
741 | public function getAccountingCodeToBind(Societe $buyer, Societe $seller, Product $product, $facture, $factureDet, $accountingAccount = array(), $type = '') |
||
947 | } |
||
948 | } |
||
949 |