| Total Complexity | 87 |
| Total Lines | 843 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like FichinterRec 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 FichinterRec, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 39 | class FichinterRec extends Fichinter |
||
| 40 | { |
||
| 41 | public $element = 'fichinterrec'; |
||
| 42 | public $table_element = 'fichinter_rec'; |
||
| 43 | public $table_element_line = 'fichinterdet_rec'; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var string Fieldname with ID of parent key if this field has a parent |
||
| 47 | */ |
||
| 48 | public $fk_element = 'fk_fichinter'; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * {@inheritdoc} |
||
| 52 | */ |
||
| 53 | protected $table_ref_field = 'titre'; |
||
| 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 = 'intervention'; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var string title |
||
| 62 | */ |
||
| 63 | public $title; |
||
| 64 | public $number; |
||
| 65 | public $date; |
||
| 66 | public $amount; |
||
| 67 | public $remise; |
||
| 68 | public $tva; |
||
| 69 | public $total; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var int Proposal Id |
||
| 73 | */ |
||
| 74 | public $propalid; |
||
| 75 | |||
| 76 | public $date_last_gen; |
||
| 77 | public $date_when; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var int number of generation done |
||
| 81 | */ |
||
| 82 | public $nb_gen_done; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var int number of maximum generation |
||
| 86 | */ |
||
| 87 | public $nb_gen_max; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * int rank |
||
| 91 | */ |
||
| 92 | public $rang; |
||
| 93 | public $special_code; |
||
| 94 | |||
| 95 | public $usenewprice = 0; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Constructor |
||
| 99 | * |
||
| 100 | * @param DoliDB $db Database handler |
||
| 101 | */ |
||
| 102 | public function __construct($db) |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Returns the label status |
||
| 119 | * |
||
| 120 | * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto |
||
| 121 | * @return string Label |
||
| 122 | */ |
||
| 123 | public function getLibStatut($mode = 0) |
||
| 126 | } |
||
| 127 | |||
| 128 | |||
| 129 | /** |
||
| 130 | * Create a predefined fichinter |
||
| 131 | * |
||
| 132 | * @param User $user User object |
||
| 133 | * @param int $notrigger no trigger |
||
| 134 | * @return int <0 if KO, id of fichinter if OK |
||
| 135 | */ |
||
| 136 | public function create($user, $notrigger = 0) |
||
| 137 | { |
||
| 138 | global $conf; |
||
| 139 | |||
| 140 | $error = 0; |
||
| 141 | $now = dol_now(); |
||
| 142 | |||
| 143 | // Clean parameters |
||
| 144 | $this->title = trim($this->title); |
||
| 145 | $this->description = trim($this->description); |
||
| 146 | |||
| 147 | |||
| 148 | $this->db->begin(); |
||
| 149 | |||
| 150 | // Load fichinter model |
||
| 151 | $fichintsrc = new Fichinter($this->db); |
||
| 152 | |||
| 153 | $result = $fichintsrc->fetch($this->id_origin); |
||
|
|
|||
| 154 | $result = $fichintsrc->fetch_lines(1); // to get all lines |
||
| 155 | |||
| 156 | |||
| 157 | if ($result > 0) { |
||
| 158 | // On positionne en mode brouillon la facture |
||
| 159 | $this->brouillon = 1; |
||
| 160 | |||
| 161 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter_rec ("; |
||
| 162 | $sql .= "titre"; |
||
| 163 | $sql .= ", fk_soc"; |
||
| 164 | $sql .= ", entity"; |
||
| 165 | $sql .= ", datec"; |
||
| 166 | $sql .= ", duree"; |
||
| 167 | $sql .= ", description"; |
||
| 168 | $sql .= ", note_private"; |
||
| 169 | $sql .= ", note_public"; |
||
| 170 | $sql .= ", fk_user_author"; |
||
| 171 | $sql .= ", fk_projet"; |
||
| 172 | $sql .= ", fk_contrat"; |
||
| 173 | $sql .= ", modelpdf"; |
||
| 174 | |||
| 175 | $sql .= ", frequency"; |
||
| 176 | $sql .= ", unit_frequency"; |
||
| 177 | $sql .= ", date_when"; |
||
| 178 | $sql .= ", date_last_gen"; |
||
| 179 | $sql .= ", nb_gen_done"; |
||
| 180 | $sql .= ", nb_gen_max"; |
||
| 181 | // $sql.= ", auto_validate"; |
||
| 182 | |||
| 183 | $sql .= ") VALUES ("; |
||
| 184 | $sql .= "'".$this->db->escape($this->title)."'"; |
||
| 185 | $sql .= ", ".($this->socid > 0 ? ((int) $this->socid) : 'null'); |
||
| 186 | $sql .= ", ".((int) $conf->entity); |
||
| 187 | $sql .= ", '".$this->db->idate($now)."'"; |
||
| 188 | $sql .= ", ".(!empty($fichintsrc->duration) ? ((int) $fichintsrc->duration) : '0'); |
||
| 189 | $sql .= ", ".(!empty($this->description) ? ("'".$this->db->escape($this->description)."'") : "null"); |
||
| 190 | $sql .= ", ".(!empty($fichintsrc->note_private) ? ("'".$this->db->escape($fichintsrc->note_private)."'") : "null"); |
||
| 191 | $sql .= ", ".(!empty($fichintsrc->note_public) ? ("'".$this->db->escape($fichintsrc->note_public)."'") : "null"); |
||
| 192 | $sql .= ", ".((int) $user->id); |
||
| 193 | // si c'est la même société on conserve les liens vers le projet et le contrat |
||
| 194 | if ($this->socid == $fichintsrc->socid) { |
||
| 195 | $sql .= ", ".(!empty($fichintsrc->fk_project) ? ((int) $fichintsrc->fk_project) : "null"); |
||
| 196 | $sql .= ", ".(!empty($fichintsrc->fk_contrat) ? ((int) $fichintsrc->fk_contrat) : "null"); |
||
| 197 | } else { |
||
| 198 | $sql .= ", null, null"; |
||
| 199 | } |
||
| 200 | |||
| 201 | $sql .= ", ".(!empty($fichintsrc->model_pdf) ? "'".$this->db->escape($fichintsrc->model_pdf)."'" : "''"); |
||
| 202 | |||
| 203 | // récurrence |
||
| 204 | $sql .= ", ".(!empty($this->frequency) ? ((int) $this->frequency) : "null"); |
||
| 205 | $sql .= ", '".$this->db->escape($this->unit_frequency)."'"; |
||
| 206 | $sql .= ", ".(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'null'); |
||
| 207 | $sql .= ", ".(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'null'); |
||
| 208 | $sql .= ", 0"; // we start à 0 |
||
| 209 | $sql .= ", ".((int) $this->nb_gen_max); |
||
| 210 | // $sql.= ", ".$this->auto_validate; |
||
| 211 | $sql .= ")"; |
||
| 212 | |||
| 213 | if ($this->db->query($sql)) { |
||
| 214 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); |
||
| 215 | |||
| 216 | /* |
||
| 217 | * Lines |
||
| 218 | */ |
||
| 219 | $num = count($fichintsrc->lines); |
||
| 220 | for ($i = 0; $i < $num; $i++) { |
||
| 221 | //var_dump($fichintsrc->lines[$i]); |
||
| 222 | $result_insert = $this->addline( |
||
| 223 | $fichintsrc->lines[$i]->desc, |
||
| 224 | $fichintsrc->lines[$i]->duration, |
||
| 225 | $fichintsrc->lines[$i]->datei, |
||
| 226 | $fichintsrc->lines[$i]->rang, |
||
| 227 | $fichintsrc->lines[$i]->subprice, |
||
| 228 | $fichintsrc->lines[$i]->qty, |
||
| 229 | $fichintsrc->lines[$i]->tva_tx, |
||
| 230 | $fichintsrc->lines[$i]->fk_product, |
||
| 231 | $fichintsrc->lines[$i]->remise_percent, |
||
| 232 | 'HT', |
||
| 233 | 0, |
||
| 234 | '', |
||
| 235 | 0, |
||
| 236 | $fichintsrc->lines[$i]->product_type, |
||
| 237 | $fichintsrc->lines[$i]->special_code, |
||
| 238 | $fichintsrc->lines[$i]->label, |
||
| 239 | $fichintsrc->lines[$i]->fk_unit |
||
| 240 | ); |
||
| 241 | |||
| 242 | if ($result_insert < 0) { |
||
| 243 | $error++; |
||
| 244 | } |
||
| 245 | } |
||
| 246 | |||
| 247 | if ($error) { |
||
| 248 | $this->db->rollback(); |
||
| 249 | } else { |
||
| 250 | $this->db->commit(); |
||
| 251 | return $this->id; |
||
| 252 | } |
||
| 253 | } else { |
||
| 254 | $this->error = $this->db->error().' sql='.$sql; |
||
| 255 | $this->db->rollback(); |
||
| 256 | return -2; |
||
| 257 | } |
||
| 258 | } else { |
||
| 259 | $this->db->rollback(); |
||
| 260 | return -1; |
||
| 261 | } |
||
| 262 | } |
||
| 263 | |||
| 264 | |||
| 265 | /** |
||
| 266 | * Get the template of intervention object and lines |
||
| 267 | * |
||
| 268 | * @param int $rowid Id of object to load |
||
| 269 | * @param string $ref Reference of fichinter |
||
| 270 | * @param string $ref_ext External reference of fichinter |
||
| 271 | * @return int >0 if OK, <0 if KO, 0 if not found |
||
| 272 | */ |
||
| 273 | public function fetch($rowid = 0, $ref = '', $ref_ext = '') |
||
| 274 | { |
||
| 275 | $sql = 'SELECT f.titre as title, f.fk_soc'; |
||
| 276 | $sql .= ', f.datec, f.duree, f.fk_projet, f.fk_contrat, f.description'; |
||
| 277 | $sql .= ', f.note_private, f.note_public, f.fk_user_author'; |
||
| 278 | $sql .= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.auto_validate'; |
||
| 279 | $sql .= ', f.note_private, f.note_public, f.fk_user_author'; |
||
| 280 | $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinter_rec as f'; |
||
| 281 | if ($rowid > 0) { |
||
| 282 | $sql .= " WHERE f.rowid = ".((int) $rowid); |
||
| 283 | } elseif ($ref) { |
||
| 284 | $sql .= " WHERE f.titre = '".$this->db->escape($ref)."'"; |
||
| 285 | } |
||
| 286 | |||
| 287 | dol_syslog(get_class($this)."::fetch rowid=".$rowid, LOG_DEBUG); |
||
| 288 | |||
| 289 | $result = $this->db->query($sql); |
||
| 290 | if ($result) { |
||
| 291 | if ($this->db->num_rows($result)) { |
||
| 292 | $obj = $this->db->fetch_object($result); |
||
| 293 | |||
| 294 | $this->id = $rowid; |
||
| 295 | $this->titre = $obj->title; |
||
| 296 | $this->title = $obj->title; |
||
| 297 | $this->ref = $obj->title; |
||
| 298 | $this->description = $obj->description; |
||
| 299 | $this->datec = $obj->datec; |
||
| 300 | $this->duration = $obj->duree; |
||
| 301 | $this->socid = $obj->fk_soc; |
||
| 302 | $this->statut = 0; |
||
| 303 | $this->fk_project = $obj->fk_projet; |
||
| 304 | $this->fk_contrat = $obj->fk_contrat; |
||
| 305 | $this->note_private = $obj->note_private; |
||
| 306 | $this->note_public = $obj->note_public; |
||
| 307 | $this->user_author = $obj->fk_user_author; |
||
| 308 | $this->model_pdf = $obj->model_pdf; |
||
| 309 | $this->modelpdf = $obj->model_pdf; // deprecated |
||
| 310 | $this->rang = $obj->rang; |
||
| 311 | $this->special_code = $obj->special_code; |
||
| 312 | $this->frequency = $obj->frequency; |
||
| 313 | $this->unit_frequency = $obj->unit_frequency; |
||
| 314 | $this->date_when = $this->db->jdate($obj->date_when); |
||
| 315 | $this->date_last_gen = $this->db->jdate($obj->date_last_gen); |
||
| 316 | $this->nb_gen_done = $obj->nb_gen_done; |
||
| 317 | $this->nb_gen_max = $obj->nb_gen_max; |
||
| 318 | $this->auto_validate = $obj->auto_validate; |
||
| 319 | |||
| 320 | $this->brouillon = 1; |
||
| 321 | |||
| 322 | // Lines |
||
| 323 | $result = $this->fetch_lines(); |
||
| 324 | if ($result < 0) { |
||
| 325 | $this->error = $this->db->error(); |
||
| 326 | return -3; |
||
| 327 | } |
||
| 328 | return 1; |
||
| 329 | } else { |
||
| 330 | $this->error = 'Interventional with id '.$rowid.' not found sql='.$sql; |
||
| 331 | dol_syslog(get_class($this).'::Fetch Error '.$this->error, LOG_ERR); |
||
| 332 | return -2; |
||
| 333 | } |
||
| 334 | } else { |
||
| 335 | $this->error = $this->db->error(); |
||
| 336 | return -1; |
||
| 337 | } |
||
| 338 | } |
||
| 339 | |||
| 340 | |||
| 341 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 342 | /** |
||
| 343 | * Load all lines of template of intervention into this->lines |
||
| 344 | * |
||
| 345 | * @param int $sall sall |
||
| 346 | * @return int 1 if OK, < 0 if KO |
||
| 347 | */ |
||
| 348 | public function fetch_lines($sall = 0) |
||
| 349 | { |
||
| 350 | // phpcs:enable |
||
| 351 | $this->lines = array(); |
||
| 352 | |||
| 353 | $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, '; |
||
| 354 | $sql .= ' l.price, l.qty, l.tva_tx, l.remise, l.remise_percent, l.subprice, l.duree, '; |
||
| 355 | $sql .= ' l.total_ht, l.total_tva, l.total_ttc,'; |
||
| 356 | $sql .= ' l.rang, l.special_code,'; |
||
| 357 | $sql .= ' l.fk_unit, p.ref as product_ref, p.fk_product_type as fk_product_type,'; |
||
| 358 | $sql .= ' p.label as product_label, p.description as product_desc'; |
||
| 359 | $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet_rec as l'; |
||
| 360 | $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; |
||
| 361 | $sql .= ' WHERE l.fk_fichinter = '.((int) $this->id); |
||
| 362 | |||
| 363 | dol_syslog('FichinterRec::fetch_lines', LOG_DEBUG); |
||
| 364 | |||
| 365 | $result = $this->db->query($sql); |
||
| 366 | if ($result) { |
||
| 367 | $num = $this->db->num_rows($result); |
||
| 368 | $i = 0; |
||
| 369 | while ($i < $num) { |
||
| 370 | $objp = $this->db->fetch_object($result); |
||
| 371 | |||
| 372 | $line = new FichinterLigne($this->db); |
||
| 373 | |||
| 374 | $line->id = $objp->rowid; |
||
| 375 | $line->label = $objp->custom_label; // Label line |
||
| 376 | $line->desc = $objp->description; // Description line |
||
| 377 | $line->product_type = $objp->product_type; // Type of line |
||
| 378 | $line->product_ref = $objp->product_ref; // Ref product |
||
| 379 | $line->product_label = $objp->product_label; // Label product |
||
| 380 | $line->product_desc = $objp->product_desc; // Description product |
||
| 381 | $line->fk_product_type = $objp->fk_product_type; // Type of product |
||
| 382 | $line->qty = $objp->qty; |
||
| 383 | $line->duree = $objp->duree; |
||
| 384 | $line->duration = $objp->duree; |
||
| 385 | $line->datei = $objp->date; |
||
| 386 | $line->subprice = $objp->subprice; |
||
| 387 | $line->tva_tx = $objp->tva_tx; |
||
| 388 | $line->remise_percent = $objp->remise_percent; |
||
| 389 | $line->fk_remise_except = $objp->fk_remise_except; |
||
| 390 | $line->fk_product = $objp->fk_product; |
||
| 391 | $line->date_start = $objp->date_start; |
||
| 392 | $line->date_end = $objp->date_end; |
||
| 393 | $line->date_start = $objp->date_start; |
||
| 394 | $line->date_end = $objp->date_end; |
||
| 395 | $line->info_bits = $objp->info_bits; |
||
| 396 | $line->total_ht = $objp->total_ht; |
||
| 397 | $line->total_tva = $objp->total_tva; |
||
| 398 | $line->total_ttc = $objp->total_ttc; |
||
| 399 | $line->code_ventilation = $objp->fk_code_ventilation; |
||
| 400 | $line->rang = $objp->rang; |
||
| 401 | $line->special_code = $objp->special_code; |
||
| 402 | $line->fk_unit = $objp->fk_unit; |
||
| 403 | |||
| 404 | $this->lines[$i] = $line; |
||
| 405 | |||
| 406 | $i++; |
||
| 407 | } |
||
| 408 | |||
| 409 | $this->db->free($result); |
||
| 410 | return 1; |
||
| 411 | } else { |
||
| 412 | $this->error = $this->db->error(); |
||
| 413 | return -3; |
||
| 414 | } |
||
| 415 | } |
||
| 416 | |||
| 417 | |||
| 418 | /** |
||
| 419 | * Delete template fichinter rec |
||
| 420 | * |
||
| 421 | * @param int $rowid Id of fichinter rec to delete. If empty, we delete current instance of fichinter rec |
||
| 422 | * @param int $notrigger 1=Does not execute triggers, 0= execute triggers |
||
| 423 | * @param int $idwarehouse Id warehouse to use for stock change. |
||
| 424 | * @return int <0 if KO, >0 if OK |
||
| 425 | */ |
||
| 426 | public function delete($rowid = 0, $notrigger = 0, $idwarehouse = -1) |
||
| 457 | } |
||
| 458 | } |
||
| 459 | |||
| 460 | |||
| 461 | /** |
||
| 462 | * Add a line to fichinter rec |
||
| 463 | * |
||
| 464 | * @param string $desc Description de la ligne |
||
| 465 | * @param integer $duration Durée |
||
| 466 | * @param string $datei Date |
||
| 467 | * @param int $rang Position of line |
||
| 468 | * @param double $pu_ht Unit price without tax (> 0 even for credit note) |
||
| 469 | * @param double $qty Quantity |
||
| 470 | * @param double $txtva Forced VAT rate, otherwise -1 |
||
| 471 | * @param int $fk_product Id of predefined product/service |
||
| 472 | * @param double $remise_percent Percentage of discount on line |
||
| 473 | * @param string $price_base_type HT or TTC |
||
| 474 | * @param int $info_bits Bits for type of lines |
||
| 475 | * @param int $fk_remise_except Id discount |
||
| 476 | * @param double $pu_ttc Unit price with tax (> 0 even for credit note) |
||
| 477 | * @param int $type Type of line (0=product, 1=service) |
||
| 478 | * @param int $special_code Special code |
||
| 479 | * @param string $label Label of the line |
||
| 480 | * @param string $fk_unit Unit |
||
| 481 | * @return int <0 if KO, Id of line if OK |
||
| 482 | */ |
||
| 483 | public function addline($desc, $duration, $datei, $rang = -1, $pu_ht = 0, $qty = 0, $txtva = 0, $fk_product = 0, $remise_percent = 0, $price_base_type = 'HT', $info_bits = 0, $fk_remise_except = '', $pu_ttc = 0, $type = 0, $special_code = 0, $label = '', $fk_unit = null) |
||
| 581 | } |
||
| 582 | } |
||
| 583 | } |
||
| 584 | |||
| 585 | |||
| 586 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 587 | /** |
||
| 588 | * Rend la fichinter automatique |
||
| 589 | * |
||
| 590 | * @param User $user User object |
||
| 591 | * @param int $freq Freq |
||
| 592 | * @param string $courant Courant |
||
| 593 | * @return int 0 if OK, <0 if KO |
||
| 594 | */ |
||
| 595 | public function set_auto($user, $freq, $courant) |
||
| 616 | } |
||
| 617 | } |
||
| 618 | |||
| 619 | /** |
||
| 620 | * Return clicable name (with picto eventually) |
||
| 621 | * |
||
| 622 | * @param int $withpicto Add picto into link |
||
| 623 | * @param string $option Where point the link |
||
| 624 | * @param int $max Maxlength of ref |
||
| 625 | * @param int $short 1=Return just URL |
||
| 626 | * @param string $moretitle Add more text to title tooltip |
||
| 627 | * @return string String with URL |
||
| 628 | */ |
||
| 629 | public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '') |
||
| 630 | { |
||
| 631 | global $langs, $hookmanager; |
||
| 632 | |||
| 633 | $result = ''; |
||
| 634 | $label = $langs->trans("ShowInterventionModel").': '.$this->ref; |
||
| 635 | |||
| 636 | $url = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$this->id; |
||
| 637 | |||
| 638 | if ($short) { |
||
| 639 | return $url; |
||
| 640 | } |
||
| 641 | |||
| 642 | $picto = 'intervention'; |
||
| 643 | |||
| 644 | $link = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
||
| 645 | $linkend = '</a>'; |
||
| 646 | |||
| 647 | if ($withpicto) { |
||
| 648 | $result .= $link.img_object($label, $picto, 'class="classfortooltip"').$linkend; |
||
| 649 | } |
||
| 650 | if ($withpicto && $withpicto != 2) { |
||
| 651 | $result .= ' '; |
||
| 652 | } |
||
| 653 | if ($withpicto != 2) { |
||
| 654 | $result .= $link.$this->ref.$linkend; |
||
| 655 | } |
||
| 656 | global $action; |
||
| 657 | $hookmanager->initHooks(array($this->element . 'dao')); |
||
| 658 | $parameters = array('id'=>$this->id, 'getnomurl' => &$result); |
||
| 659 | $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
||
| 660 | if ($reshook > 0) { |
||
| 661 | $result = $hookmanager->resPrint; |
||
| 662 | } else { |
||
| 663 | $result .= $hookmanager->resPrint; |
||
| 664 | } |
||
| 665 | return $result; |
||
| 666 | } |
||
| 667 | |||
| 668 | |||
| 669 | /** |
||
| 670 | * Initialise an instance with random values. |
||
| 671 | * Used to build previews or test instances. |
||
| 672 | * id must be 0 if object instance is a specimen. |
||
| 673 | * |
||
| 674 | * @param string $option ''=Create a specimen fichinter with lines, 'nolines'=No lines |
||
| 675 | * @return void |
||
| 676 | */ |
||
| 677 | public function initAsSpecimen($option = '') |
||
| 688 | } |
||
| 689 | |||
| 690 | /** |
||
| 691 | * Function used to replace a thirdparty id with another one. |
||
| 692 | * |
||
| 693 | * @param DoliDB $db Database handler |
||
| 694 | * @param int $origin_id Old thirdparty id |
||
| 695 | * @param int $dest_id New thirdparty id |
||
| 696 | * @return bool |
||
| 697 | */ |
||
| 698 | public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id) |
||
| 703 | } |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Function used to replace a product id with another one. |
||
| 707 | * |
||
| 708 | * @param DoliDB $db Database handler |
||
| 709 | * @param int $origin_id Old product id |
||
| 710 | * @param int $dest_id New product id |
||
| 711 | * @return bool |
||
| 712 | */ |
||
| 713 | public static function replaceProduct(DoliDB $db, $origin_id, $dest_id) |
||
| 714 | { |
||
| 715 | $tables = array( |
||
| 716 | 'fichinterdet_rec' |
||
| 717 | ); |
||
| 718 | |||
| 719 | return CommonObject::commonReplaceProduct($db, $origin_id, $dest_id, $tables); |
||
| 720 | } |
||
| 721 | |||
| 722 | /** |
||
| 723 | * Update frequency and unit |
||
| 724 | * |
||
| 725 | * @param int $frequency value of frequency |
||
| 726 | * @param string $unit unit of frequency (d, m, y) |
||
| 727 | * @return int <0 if KO, >0 if OK |
||
| 728 | */ |
||
| 729 | public function setFrequencyAndUnit($frequency, $unit) |
||
| 730 | { |
||
| 731 | if (!$this->table_element) { |
||
| 732 | dol_syslog(get_class($this)."::setFrequencyAndUnit called with table_element not defined", LOG_ERR); |
||
| 733 | return -1; |
||
| 734 | } |
||
| 735 | |||
| 736 | if (!empty($frequency) && empty($unit)) { |
||
| 737 | dol_syslog(get_class($this)."::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR); |
||
| 738 | return -2; |
||
| 739 | } |
||
| 740 | |||
| 741 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
||
| 742 | $sql .= ' SET frequency = '.($frequency ? $this->db->escape($frequency) : 'null'); |
||
| 743 | if (!empty($unit)) { |
||
| 744 | $sql .= ', unit_frequency = "'.$this->db->escape($unit).'"'; |
||
| 745 | } |
||
| 746 | $sql .= " WHERE rowid = ".((int) $this->id); |
||
| 747 | |||
| 748 | dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG); |
||
| 749 | if ($this->db->query($sql)) { |
||
| 750 | $this->frequency = $frequency; |
||
| 751 | if (!empty($unit)) { |
||
| 752 | $this->unit_frequency = $unit; |
||
| 753 | } |
||
| 754 | return 1; |
||
| 755 | } else { |
||
| 756 | dol_print_error($this->db); |
||
| 757 | return -1; |
||
| 758 | } |
||
| 759 | } |
||
| 760 | |||
| 761 | /** |
||
| 762 | * Update the next date of execution |
||
| 763 | * |
||
| 764 | * @param datetime $date date of execution |
||
| 765 | * @param int $increment_nb_gen_done 0 do nothing more, >0 increment nb_gen_done |
||
| 766 | * @return int <0 if KO, >0 if OK |
||
| 767 | */ |
||
| 768 | public function setNextDate($date, $increment_nb_gen_done = 0) |
||
| 791 | } |
||
| 792 | } |
||
| 793 | |||
| 794 | /** |
||
| 795 | * Update the maximum period |
||
| 796 | * |
||
| 797 | * @param int $nb number of maximum period |
||
| 798 | * @return int <0 if KO, >0 if OK |
||
| 799 | */ |
||
| 800 | public function setMaxPeriod($nb) |
||
| 822 | } |
||
| 823 | } |
||
| 824 | |||
| 825 | /** |
||
| 826 | * Update the auto validate fichinter |
||
| 827 | * |
||
| 828 | * @param int $validate 0 to create in draft, 1 to create and validate fichinter |
||
| 829 | * @return int <0 if KO, >0 if OK |
||
| 830 | */ |
||
| 831 | public function setAutoValidate($validate) |
||
| 832 | { |
||
| 833 | if (!$this->table_element) { |
||
| 834 | dol_syslog(get_class($this)."::setAutoValidate called with property table_element not defined", LOG_ERR); |
||
| 835 | return -1; |
||
| 836 | } |
||
| 837 | |||
| 838 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
||
| 839 | $sql .= ' SET auto_validate = '.((int) $validate); |
||
| 840 | $sql .= ' WHERE rowid = '.((int) $this->id); |
||
| 841 | |||
| 842 | dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG); |
||
| 843 | if ($this->db->query($sql)) { |
||
| 844 | $this->auto_validate = $validate; |
||
| 845 | return 1; |
||
| 846 | } else { |
||
| 847 | dol_print_error($this->db); |
||
| 848 | return -1; |
||
| 849 | } |
||
| 850 | } |
||
| 851 | |||
| 852 | /** |
||
| 853 | * Update the Number of Generation Done |
||
| 854 | * |
||
| 855 | * @return int <0 if KO, >0 if OK |
||
| 856 | */ |
||
| 857 | public function updateNbGenDone() |
||
| 882 | } |
||
| 883 | } |
||
| 884 | } |
||
| 885 |