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