31require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
42 const TRIGGER_PREFIX =
'SUPPLIERBILLREC';
46 public $element =
'invoice_supplier_rec';
51 public $table_element =
'facture_fourn_rec';
56 public $table_element_line =
'facture_fourn_det_rec';
61 public $fk_element =
'fk_facture_fourn';
66 public $picto =
'bill';
114 public $vat_src_code;
122 public $mode_reglement_id;
123 public $mode_reglement_code;
124 public $cond_reglement_code;
125 public $cond_reglement_doc;
126 public $cond_reglement_id;
128 public $date_lim_reglement;
130 public $usenewprice = 0;
132 public $unit_frequency;
134 public $date_last_gen;
137 public $auto_validate;
138 public $generate_pdf;
146 public $lines = array();
191 public $fields = array(
192 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
193 'titre' =>array(
'type'=>
'varchar(100)',
'label'=>
'Titre',
'enabled'=>1,
'showoncombobox' => 1,
'visible'=>-1,
'position'=>15),
194 'ref_supplier' =>array(
'type'=>
'varchar(180)',
'label'=>
'RefSupplier',
'enabled'=>1,
'showoncombobox' => 1,
'visible'=>-1,
'position'=>20),
195 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>25,
'index'=>1),
196 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'isModEnabled("societe")',
'visible'=>-1,
'notnull'=>1,
'position'=>30),
197 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>35),
198 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>40),
199 'suspended' =>array(
'type'=>
'integer',
'label'=>
'Suspended',
'enabled'=>1,
'visible'=>-1,
'position'=>225),
200 'libelle' =>array(
'type'=>
'varchar(100)',
'label'=>
'Libelle',
'enabled'=>1,
'showoncombobox' => 0,
'visible'=>-1,
'position'=>15),
202 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax1',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'isameasure'=>1),
203 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax2',
'enabled'=>1,
'visible'=>-1,
'position'=>65,
'isameasure'=>1),
204 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'Total',
'enabled'=>1,
'visible'=>-1,
'position'=>70,
'isameasure'=>1),
205 'total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Tva',
'enabled'=>1,
'visible'=>-1,
'position'=>55,
'isameasure'=>1),
206 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'Total ttc',
'enabled'=>1,
'visible'=>-1,
'position'=>75,
'isameasure'=>1),
208 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
209 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>210),
210 'fk_projet' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:fk_statut=1',
'label'=>
'Fk projet',
'enabled'=>
"isModEnabled('project')",
'visible'=>-1,
'position'=>85),
211 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'Fk account',
'enabled'=>
'isModEnabled("banque")',
'visible'=>-1,
'position'=>175),
212 'fk_cond_reglement' =>array(
'type'=>
'integer',
'label'=>
'Fk cond reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
213 'fk_mode_reglement' =>array(
'type'=>
'integer',
'label'=>
'Fk mode reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
214 'date_lim_reglement' =>array(
'type'=>
'date',
'label'=>
'Date lim reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
216 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>105),
217 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>110),
218 'modelpdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Modelpdf',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
220 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
221 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Multicurrency code',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
222 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency tx',
'enabled'=>1,
'visible'=>-1,
'position'=>190,
'isameasure'=>1),
223 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total ht',
'enabled'=>1,
'visible'=>-1,
'position'=>195,
'isameasure'=>1),
224 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total tva',
'enabled'=>1,
'visible'=>-1,
'position'=>200,
'isameasure'=>1),
225 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total ttc',
'enabled'=>1,
'visible'=>-1,
'position'=>205,
'isameasure'=>1),
227 'usenewprice' =>array(
'type'=>
'integer',
'label'=>
'UseNewPrice',
'enabled'=>1,
'visible'=>0,
'position'=>155),
228 'frequency' =>array(
'type'=>
'integer',
'label'=>
'Frequency',
'enabled'=>1,
'visible'=>-1,
'position'=>150),
229 'unit_frequency' =>array(
'type'=>
'varchar(2)',
'label'=>
'Unit frequency',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
231 'date_when' =>array(
'type'=>
'datetime',
'label'=>
'Date when',
'enabled'=>1,
'visible'=>-1,
'position'=>130),
232 'date_last_gen' =>array(
'type'=>
'datetime',
'label'=>
'Date last gen',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
233 'nb_gen_done' =>array(
'type'=>
'integer',
'label'=>
'Nb gen done',
'enabled'=>1,
'visible'=>-1,
'position'=>140),
234 'nb_gen_max' =>array(
'type'=>
'integer',
'label'=>
'Nb gen max',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
235 'revenuestamp' =>array(
'type'=>
'double(24,8)',
'label'=>
'RevenueStamp',
'enabled'=>1,
'visible'=>-1,
'position'=>160,
'isameasure'=>1),
236 'auto_validate' =>array(
'type'=>
'integer',
'label'=>
'Auto validate',
'enabled'=>1,
'visible'=>-1,
'position'=>165),
237 'generate_pdf' =>array(
'type'=>
'integer',
'label'=>
'Generate pdf',
'enabled'=>1,
'visible'=>-1,
'position'=>170),
242 const STATUS_NOTSUSPENDED = 0;
243 const STATUS_SUSPENDED = 1;
265 public function create($user, $facFournId, $notrigger = 0)
273 $this->titre = empty($this->titre) ?
'' : $this->titre;
274 $this->title = empty($this->title) ?
'' : $this->title;
276 $this->
ref = $this->$keyforref;
277 $this->ref_supplier = empty($this->ref_supplier) ?
'' : $this->ref_supplier;
278 $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
279 $this->suspended = empty($this->suspended) ? 0 : $this->suspended;
281 if (empty($this->frequency)) {
282 $this->frequency = 0;
283 $this->date_when =
null;
285 $this->frequency = abs($this->frequency);
286 $this->nb_gen_done = 0;
287 $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
288 $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
289 $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
295 $result = $facfourn_src->fetch($facFournId);
297 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'facture_fourn_rec (';
299 $sql .=
', ref_supplier';
303 $sql .=
', suspended';
305 $sql .=
', total_ttc';
306 $sql .=
', fk_user_author';
307 $sql .=
', fk_projet';
308 $sql .=
', fk_account';
309 $sql .=
', fk_cond_reglement';
310 $sql .=
', fk_mode_reglement';
311 $sql .=
', date_lim_reglement';
312 $sql .=
', note_private';
313 $sql .=
', note_public';
314 $sql .=
', modelpdf';
315 $sql .=
', fk_multicurrency';
316 $sql .=
', multicurrency_code';
317 $sql .=
', multicurrency_tx';
318 $sql .=
', usenewprice';
319 $sql .=
', frequency';
320 $sql .=
', unit_frequency';
321 $sql .=
', date_when';
322 $sql .=
', date_last_gen';
323 $sql .=
', nb_gen_done';
324 $sql .=
', nb_gen_max';
325 $sql .=
', auto_validate';
326 $sql .=
', generate_pdf';
327 $sql .=
') VALUES (';
328 $sql .=
"'".$this->db->escape($this->title).
"'";
329 $sql .=
", '".$this->db->escape($this->ref_supplier).
"'";
330 $sql .=
", ".((int) $conf->entity);
331 $sql .=
", ".((int) $facfourn_src->socid);
332 $sql .=
", '".$this->db->idate($now).
"'";
333 $sql .=
", ".((int) $this->suspended);
334 $sql .=
", '".$this->db->escape($this->libelle).
"'";
335 $sql .=
", " .(!empty($facfourn_src->total_ttc) ? (float) $facfourn_src->total_ttc :
'0');
336 $sql .=
", " .((int) $user->id);
337 $sql .=
", " .(!empty($this->fk_project) ? ((int) $this->fk_project) :
'NULL');
338 $sql .=
", " .(!empty($facfourn_src->fk_account) ? ((int) $facfourn_src->fk_account) :
'NULL');
339 $sql .=
", " .($this->cond_reglement_id > 0 ? (int) $this->cond_reglement_id :
'NULL');
340 $sql .=
", " .($this->mode_reglement_id > 0 ? (int) $this->mode_reglement_id :
'NULL');
341 $sql .=
", ".($facfourn_src->date_echeance > 0 ?
"'".$this->db->idate($facfourn_src->date_echeance).
"'" :
'NULL');
342 $sql .=
", " .(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
'NULL');
343 $sql .=
", " .(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
'NULL');
344 $sql .=
", " .(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
'NULL');
345 $sql .=
", " . (int) $facfourn_src->fk_multicurrency;
346 $sql .=
", '".$this->db->escape($facfourn_src->multicurrency_code).
"'";
347 $sql .=
", " . (float) $facfourn_src->multicurrency_tx;
348 $sql .=
", " . (int) $this->usenewprice;
349 $sql .=
", " . (int) $this->frequency;
350 $sql .=
", '".$this->db->escape($this->unit_frequency).
"'";
351 $sql .=
", " .(!empty($this->date_when) ?
"'".$this->db->idate($this->date_when).
"'" :
'NULL');
352 $sql .=
", " .(!empty($this->date_last_gen) ?
"'".$this->db->idate($this->date_last_gen).
"'" :
'NULL');
353 $sql .=
", " . (int) $this->nb_gen_done;
354 $sql .=
", " . (int) $this->nb_gen_max;
355 $sql .=
", " . (int) $this->auto_validate;
356 $sql .=
", " . (int) $this->generate_pdf;
359 if ($this->db->query($sql)) {
360 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn_rec');
363 $this->fk_multicurrency = $facfourn_src->fk_multicurrency;
365 $this->multicurrency_code = $facfourn_src->multicurrency_code;
366 $this->multicurrency_tx = $facfourn_src->multicurrency_tx;
369 $num = count($facfourn_src->lines);
370 for ($i = 0; $i < $num; $i++) {
371 $tva_tx = $facfourn_src->lines[$i]->tva_tx;
372 if (!empty($facfourn_src->lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
373 $tva_tx .=
' ('.$facfourn_src->lines[$i]->vat_src_code.
')';
376 $result_insert = $this->
addline(
377 $facfourn_src->lines[$i]->fk_product,
378 $facfourn_src->lines[$i]->ref_supplier,
379 $facfourn_src->lines[$i]->label,
380 $facfourn_src->lines[$i]->description,
381 $facfourn_src->lines[$i]->pu_ht,
382 $facfourn_src->lines[$i]->pu_ttc,
383 $facfourn_src->lines[$i]->qty,
384 $facfourn_src->lines[$i]->remise_percent,
386 $facfourn_src->lines[$i]->localtax1_tx,
387 $facfourn_src->lines[$i]->localtax2_tx,
389 $facfourn_src->lines[$i]->product_type,
390 $facfourn_src->lines[$i]->date_start,
391 $facfourn_src->lines[$i]->date_end,
392 $facfourn_src->lines[$i]->info_bits,
393 $facfourn_src->lines[$i]->special_code,
394 $facfourn_src->lines[$i]->rang,
395 $facfourn_src->lines[$i]->fk_unit
398 if ($result_insert < 0) {
403 $result2 = $objectline->fetch($result_insert);
406 if (method_exists($facfourn_src->lines[$i],
'fetch_optionals')) {
407 $facfourn_src->lines[$i]->fetch_optionals($facfourn_src->lines[$i]->id);
408 $objectline->array_options = $facfourn_src->lines[$i]->array_options;
411 $result = $objectline->insertExtraFields();
415 } elseif ($result2 < 0) {
416 $this->errors[] = $objectline->error;
422 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
423 $this->linked_objects = $this->linkedObjectsIds;
427 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
428 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
429 if (is_array($tmp_origin_id)) {
430 foreach ($tmp_origin_id as $origin_id) {
433 $this->error = $this->db->lasterror();
438 $origin_id = $tmp_origin_id;
441 $this->error = $this->db->lasterror();
455 if (!$error && !$notrigger) {
457 $result = $this->
call_trigger(
'SUPPLIERBILLREC_CREATE', $user);
459 $this->db->rollback();
466 $this->db->rollback();
473 $this->error = $this->db->lasterror();
474 $this->db->rollback();
478 $this->db->rollback();
495 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn_rec SET";
496 $sql .=
" titre = '" . (!empty($this->title) ? $this->db->escape($this->title) :
"").
"'," ;
497 $sql .=
" ref_supplier = '". (!empty($this->ref_supplier) ? $this->db->escape($this->ref_supplier) :
"").
"',";
498 $sql .=
" entity = ". (!empty($this->entity) ? ((int) $this->entity) : 1) .
',';
499 if (!empty($this->socid) && $this->socid > 0) {
500 $sql .=
" fk_soc = ". ((int) $this->socid).
',';
501 } elseif (!empty($this->fk_soc) && $this->fk_soc > 0) {
502 $sql .=
" fk_soc = ". ((int) $this->fk_soc).
',';
504 $sql .=
" suspended = ". (!empty($this->suspended) ? ((int) $this->suspended) : 0) .
',';
505 $sql .=
" libelle = ". (!empty($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
'NULL') .
",";
506 $sql .=
" vat_src_code = ". (!empty($this->vat_src_code) ?
"'".$this->db->escape($this->vat_src_code).
"'" :
'NULL') .
',';
507 $sql .=
" localtax1 = ". (!empty($this->localtax1) ? ((float) $this->localtax1) : 0.00) .
',';
508 $sql .=
" localtax2 = ". (!empty($this->localtax2) ? ((float) $this->localtax2) : 0.00) .
',';
509 $sql .=
" total_ht = ". (!empty($this->total_ht) ? ((float) $this->total_ht) : 0.00) .
',';
510 $sql .=
" total_tva = ". (!empty($this->total_tva) ? ((float) $this->total_tva) : 0.00) .
',';
511 $sql .=
" total_ttc = ". (!empty($this->total_ttc) ? ((float) $this->total_ttc) : 0.00) .
',';
512 $sql .=
" fk_user_modif = ". ((int) $user->id) .
',';
513 $sql .=
" fk_projet = ". (!empty($this->fk_project) ? ((int) $this->fk_project) :
'NULL') .
',';
514 $sql .=
" fk_account = ". (!empty($this->fk_account) ? ((int) $this->fk_account) :
'NULL') .
',';
515 $sql .=
" fk_mode_reglement = ". (!empty($this->mode_reglement_id) ? ((int) $this->mode_reglement_id) :
'NULL') .
',';
516 $sql .=
" fk_cond_reglement = ". (!empty($this->cond_reglement_id) ? ((int) $this->cond_reglement_id) :
'NULL') .
',';
517 $sql .=
" date_lim_reglement = ". (!empty($this->date_lim_reglement) ?
"'".$this->db->idate($this->date_lim_reglement).
"'" :
'NULL') .
',';
518 $sql .=
" note_private = '". (!empty($this->note_private) ? $this->db->escape($this->note_private) :
'') .
"',";
519 $sql .=
" note_public = '". (!empty($this->note_public) ? $this->db->escape($this->note_public) :
'') .
"',";
520 $sql .=
" modelpdf = ". (!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
'NULL') .
",";
521 $sql .=
" fk_multicurrency = ". (!empty($this->fk_multicurrency) ? ((int) $this->fk_multicurrency) :
'NULL') .
',';
522 $sql .=
" multicurrency_code = ". (!empty($this->multicurrency_code) ?
"'".$this->db->escape($this->multicurrency_code).
"'" :
'NULL') .
",";
523 $sql .=
" multicurrency_tx = ". (!empty($this->multicurrency_tx) ? ((float) $this->multicurrency_tx) : 1) .
',';
524 $sql .=
" multicurrency_total_ht = ". (!empty($this->multicurrency_total_ht) ? ((float) $this->multicurrency_total_ht) : 0.00) .
',';
525 $sql .=
" multicurrency_total_tva = ". (!empty($this->multicurrency_total_tva) ? ((float) $this->multicurrency_total_tva) : 0.00) .
',';
526 $sql .=
" multicurrency_total_ttc = ". (!empty($this->multicurrency_total_ttc) ? ((float) $this->multicurrency_total_ttc) : 0.00) .
',';
527 $sql .=
" usenewprice = ". (!empty($this->usenewprice) ? ((int) $this->usenewprice) : 0) .
',';
528 $sql .=
" frequency = ". (!empty($this->frequency) ? ((int) $this->frequency) : 0).
',';
529 $sql .=
" unit_frequency = '". (!empty($this->unit_frequency) ? $this->db->escape($this->unit_frequency) :
'').
"',";
530 $sql .=
" date_when = ". (!empty($this->date_when) ?
"'".$this->db->idate($this->date_when).
"'" :
'NULL') .
',';
531 $sql .=
" date_last_gen = ". (!empty($this->date_last_gen) ?
"'".$this->db->idate($this->date_last_gen).
"'" :
'NULL') .
',';
532 $sql .=
" nb_gen_done = ". (!empty($this->nb_gen_done) ? ((int) $this->nb_gen_done) : 0) .
',';
533 $sql .=
" nb_gen_max = ". (!empty($this->nb_gen_max) ? ((int) $this->nb_gen_max) : 0) .
',';
534 $sql .=
" auto_validate = ". (!empty($this->auto_validate) ? ((int) $this->auto_validate) : 0);
535 $sql .=
" WHERE rowid = ". (int) $this->
id;
539 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
540 $resql = $this->db->query($sql);
549 if (!$error && !$notrigger) {
551 $result = $this->
call_trigger(
'SUPPLIERBILLREC_MODIFY', $user);
553 $this->db->rollback();
561 $this->error = $this->db->lasterror();
562 $this->db->rollback();
575 public function fetch($rowid, $ref =
'', $ref_ext =
'')
577 $sql =
'SELECT f.rowid, f.titre as title, f.ref_supplier, f.entity, f.fk_soc';
578 $sql .=
', f.datec, f.tms, f.suspended';
579 $sql .=
', f.libelle as label';
580 $sql .=
', f.vat_src_code, f.localtax1, f.localtax2';
581 $sql .=
', f.total_tva, f.total_ht, f.total_ttc';
582 $sql .=
', f.fk_user_author, f.fk_user_modif';
583 $sql .=
', f.fk_projet as fk_project, f.fk_account';
584 $sql .=
', f.fk_mode_reglement, p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
585 $sql .=
', f.fk_cond_reglement, c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
586 $sql .=
', f.date_lim_reglement';
587 $sql .=
', f.note_private, f.note_public, f.modelpdf as model_pdf';
588 $sql .=
', f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc';
589 $sql .=
', f.usenewprice, f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.auto_validate';
590 $sql .=
', f.generate_pdf';
591 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as f';
592 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
593 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON f.fk_mode_reglement = p.id';
594 $sql .=
' WHERE f.entity IN ('.getEntity(
'invoice').
')';
596 $sql .=
' AND f.rowid='. (int) $rowid;
598 $sql .=
" AND f.titre='".$this->db->escape($ref).
"'";
600 $sql .=
' AND f.rowid = 0';
603 $result = $this->db->query($sql);
605 if ($this->db->num_rows($result)) {
606 $obj = $this->db->fetch_object($result);
610 $this->
id = $obj->rowid;
611 $this->titre = $obj->title;
612 $this->title = $obj->title;
613 $this->
ref = $obj->title;
614 $this->ref_supplier = $obj->ref_supplier;
615 $this->entity = $obj->entity;
616 $this->socid = $obj->fk_soc;
617 $this->date_creation = $obj->datec;
618 $this->date_modification = $obj->tms;
619 $this->suspended = $obj->suspended;
620 $this->libelle = $obj->label;
621 $this->label = $obj->label;
622 $this->vat_src_code = $obj->vat_src_code;
623 $this->total_localtax1 = $obj->localtax1;
624 $this->total_localtax2 = $obj->localtax2;
625 $this->total_ht = $obj->total_ht;
626 $this->total_tva = $obj->total_tva;
627 $this->total_ttc = $obj->total_ttc;
628 $this->user_author = $obj->fk_user_author;
629 $this->user_modif = $obj->fk_user_modif;
630 $this->fk_project = $obj->fk_project;
631 $this->fk_account = $obj->fk_account;
632 $this->mode_reglement_id = $obj->fk_mode_reglement;
633 $this->mode_reglement_code = $obj->mode_reglement_code;
634 $this->mode_reglement = $obj->mode_reglement_libelle;
635 $this->cond_reglement_id = $obj->fk_cond_reglement;
636 $this->cond_reglement_code = $obj->cond_reglement_code;
637 $this->cond_reglement = $obj->cond_reglement_libelle;
638 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
639 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
640 $this->note_private = $obj->note_private;
641 $this->note_public = $obj->note_public;
642 $this->model_pdf = $obj->model_pdf;
645 $this->fk_multicurrency = $obj->fk_multicurrency;
646 $this->multicurrency_code = $obj->multicurrency_code;
647 $this->multicurrency_tx = $obj->multicurrency_tx;
648 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
649 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
650 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
652 $this->usenewprice = $obj->usenewprice;
653 $this->frequency = $obj->frequency;
654 $this->unit_frequency = $obj->unit_frequency;
655 $this->date_when = $this->db->jdate($obj->date_when);
656 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
657 $this->nb_gen_done = $obj->nb_gen_done;
658 $this->nb_gen_max = $obj->nb_gen_max;
659 $this->auto_validate = $obj->auto_validate;
660 $this->generate_pdf = $obj->generate_pdf;
671 $this->error = $this->db->lasterror();
676 $this->error =
'Bill with id '.$rowid.
' or ref '.$ref.
' not found';
677 dol_syslog(
'Facture::Fetch Error '.$this->error, LOG_ERR);
681 $this->error = $this->db->error();
706 $this->lines = array();
717 $sql =
'SELECT l.rowid,';
718 $sql .=
' l.fk_facture_fourn, l.fk_parent_line, l.fk_product, l.ref, l.label, l.description,';
719 $sql .=
' l.pu_ht, l.pu_ttc, l.qty, l.remise_percent, l.fk_remise_except, l.vat_src_code, l.tva_tx,';
720 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type,';
721 $sql .=
' l.total_ht, l.total_tva, l.total_ttc, total_localtax1, total_localtax2,';
722 $sql .=
' l.product_type, l.date_start, l.date_end,';
723 $sql .=
' l.info_bits, l.special_code, l.rang,';
724 $sql .=
' l.fk_unit, l.import_key, l.fk_user_author, l.fk_user_modif,';
725 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
726 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
727 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_det_rec as l';
728 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
729 $sql .=
' WHERE l.fk_facture_fourn = '. (int) $this->
id;
730 $sql .=
' ORDER BY l.rang';
732 dol_syslog(
'FactureFournisseurRec::fetch_lines', LOG_DEBUG);
734 $result = $this->db->query($sql);
736 $num = $this->db->num_rows($result);
739 $objp = $this->db->fetch_object($result);
743 $line->id = $objp->rowid;
744 $line->fk_facture_fourn = $objp->fk_facture_fourn;
745 $line->fk_parent = $objp->fk_parent_line;
746 $line->fk_product = $objp->fk_product;
747 $line->ref_supplier = $objp->ref;
748 $line->label = $objp->label;
749 $line->description = $objp->description;
750 $line->pu_ht = $objp->pu_ht;
751 $line->pu_ttc = $objp->pu_ttc;
752 $line->qty = $objp->qty;
753 $line->remise_percent = $objp->remise_percent;
754 $line->fk_remise_except = $objp->fk_remise_except;
755 $line->vat_src_code = $objp->vat_src_code;
756 $line->tva_tx = $objp->tva_tx;
757 $line->localtax1_tx = $objp->localtax1_tx;
758 $line->localtax1_type = $objp->localtax1_type;
759 $line->localtax2_tx = $objp->localtax2_tx;
760 $line->localtax2_type = $objp->localtax2_type;
761 $line->total_ht = $objp->total_ht;
762 $line->total_tva = $objp->total_tva;
763 $line->total_localtax1 = $objp->total_localtax1;
764 $line->total_localtax2 = $objp->total_localtax2;
765 $line->total_ttc = $objp->total_ttc;
766 $line->product_type = $objp->product_type;
767 $line->date_start = $objp->date_start;
768 $line->date_end = $objp->date_end;
769 $line->info_bits = $objp->info_bits ;
770 $line->special_code = $objp->special_code;
771 $line->rang = $objp->rang;
772 $line->fk_unit = $objp->fk_unit;
773 $line->import_key = $objp->import_key;
774 $line->fk_user_author = $objp->fk_user_author;
775 $line->fk_user_modif = $objp->fk_user_modif;
776 $line->fk_multicurrency = $objp->fk_multicurrency;
777 $line->multicurrency_code = $objp->multicurrency_code;
778 $line->multicurrency_subprice = $objp->multicurrency_subprice;
779 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
780 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
781 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
783 $line->fetch_optionals();
785 $this->lines[$i] = $line;
790 $this->db->free($result);
793 $this->error = $this->db->lasterror();
807 public function delete(
User $user, $notrigger = 0, $idwarehouse = -1)
811 dol_syslog(get_class($this).
"::delete rowid=".((
int) $rowid), LOG_DEBUG);
816 $main = MAIN_DB_PREFIX.
'facture_fourn_det_rec';
817 $ef = $main.
"_extrafields";
819 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_facture_fourn = ". (int) $rowid .
")";
820 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facture_fourn_det_rec WHERE fk_facture_fourn = ". (int) $rowid;
822 if ($this->db->query($sqlef) && $this->db->query($sql)) {
823 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facture_fourn_rec WHERE rowid = ". (int) $rowid;
825 if ($this->db->query($sql)) {
837 $this->error = $this->db->lasterror();
841 $this->error = $this->db->lasterror();
844 if (!$error && !$notrigger) {
846 $result = $this->
call_trigger(
'SUPPLIERBILLREC_DELETE', $user);
856 $this->db->rollback();
887 public function addline($fk_product, $ref, $label, $desc, $pu_ht, $pu_ttc, $qty, $remise_percent, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $price_base_type =
'HT', $type = 0, $date_start = 0, $date_end = 0, $info_bits = 0, $special_code = 0, $rang = -1, $fk_unit =
null, $pu_ht_devise = 0)
889 global $mysoc, $user;
891 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
895 dol_syslog(get_class($this).
"::addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit,pu_ht_devise=$pu_ht_devise,date_start_fill=$date_start,date_end_fill=$date_end", LOG_DEBUG);
902 if ($this->suspended == self::STATUS_NOTSUSPENDED) {
908 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
909 $vat_src_code = $reg[1];
910 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
914 $fk_product = empty($fk_product) ? 0 : $fk_product;
915 $label = empty($label) ?
'' : $label;
916 $remise_percent = empty($remise_percent) ? 0 :
price2num($remise_percent);
920 if (!preg_match(
'/\((.*)\)/', $txtva)) {
925 $txtva = !empty($txtva) ? $txtva : 0;
926 $txlocaltax1 = !empty($txlocaltax1) ? $txlocaltax1 : 0;
927 $txlocaltax2 = !empty($txlocaltax2) ? $txlocaltax2 : 0;
928 $info_bits = !empty($info_bits) ? $info_bits : 0;
929 $info_bits = !empty($info_bits) ? $info_bits : 0;
930 $pu = $price_base_type ==
'HT' ? $pu_ht : $pu_ttc;
936 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
937 $total_ht = $tabprice[0];
938 $total_tva = $tabprice[1];
939 $total_ttc = $tabprice[2];
940 $total_localtax1 = $tabprice[9];
941 $total_localtax2 = $tabprice[10];
942 $pu_ht = $tabprice[3];
945 $multicurrency_total_ht = $tabprice[16];
946 $multicurrency_total_tva = $tabprice[17];
947 $multicurrency_total_ttc = $tabprice[18];
948 $pu_ht_devise = $tabprice[19];
951 $product_type = $type;
953 $product =
new Product($this->db);
954 $result = $product->fetch($fk_product);
958 $product_type = $product->type;
960 $label = $product->label;
964 $sql =
'INSERT INTO ' . MAIN_DB_PREFIX .
'facture_fourn_det_rec (';
965 $sql .=
'fk_facture_fourn';
966 $sql .=
', fk_product';
969 $sql .=
', description';
973 $sql .=
', remise_percent';
974 $sql .=
', fk_remise_except';
975 $sql .=
', vat_src_code';
977 $sql .=
', localtax1_tx';
978 $sql .=
', localtax1_type';
979 $sql .=
', localtax2_tx';
980 $sql .=
', localtax2_type';
981 $sql .=
', total_ht';
982 $sql .=
', total_tva';
983 $sql .=
', total_localtax1';
984 $sql .=
', total_localtax2';
985 $sql .=
', total_ttc';
986 $sql .=
', product_type';
987 $sql .=
', date_start';
988 $sql .=
', date_end';
989 $sql .=
', info_bits';
990 $sql .=
', special_code';
993 $sql .=
', fk_user_author';
994 $sql .=
', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
995 $sql .=
') VALUES (';
996 $sql .=
' ' . (int) $facid;
997 $sql .=
', ' . (!empty($fk_product) ?
"'" . $this->db->escape($fk_product) .
"'" :
'null');
998 $sql .=
', ' . (!empty($ref) ?
"'" . $this->db->escape($ref) .
"'" :
'null');
999 $sql .=
', ' . (!empty($label) ?
"'" . $this->db->escape($label) .
"'" :
'null');
1000 $sql .=
", '" . $this->db->escape($desc) .
"'";
1004 $sql .=
', ' .
price2num($remise_percent);
1006 $sql .=
", '" . $this->db->escape($vat_src_code) .
"'";
1009 $sql .=
", '" . $this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] :
'') .
"'";
1011 $sql .=
", '" . $this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] :
'') .
"'";
1014 $sql .=
', ' .
price2num($total_localtax1);
1015 $sql .=
', ' .
price2num($total_localtax2);
1017 $sql .=
', ' . (int) $product_type;
1018 $sql .=
', ' . ($date_start > 0 ? (int) $date_start :
'NULL');
1019 $sql .=
', ' . ($date_end > 0 ? (int) $date_end :
'NULL');
1020 $sql .=
', ' . (int) $info_bits;
1021 $sql .=
', ' . (int) $special_code;
1022 $sql .=
', ' . (int) $rang;
1023 $sql .=
', ' . ($fk_unit ? (int) $fk_unit :
'NULL');
1024 $sql .=
', ' . (int) $user->id;
1025 $sql .=
', ' . (int) $this->fk_multicurrency;
1026 $sql .=
", '" . $this->db->escape($this->multicurrency_code) .
"'";
1027 $sql .=
', ' .
price2num($pu_ht_devise,
'CU');
1028 $sql .=
', ' .
price2num($multicurrency_total_ht,
'CT');
1029 $sql .=
', ' .
price2num($multicurrency_total_tva,
'CT');
1030 $sql .=
', ' .
price2num($multicurrency_total_ttc,
'CT');
1033 dol_syslog(get_class($this).
'::addline', LOG_DEBUG);
1034 if ($this->db->query($sql)) {
1035 $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn_det_rec');
1038 $this->db->commit();
1041 $this->db->rollback();
1042 $this->error = $this->db->lasterror();
1047 $this->error =
'Recurring Invoice is suspended. adding lines not allowed.';
1080 public function updateline($rowid, $fk_product, $ref, $label, $desc, $pu_ht, $qty, $remise_percent, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $price_base_type =
'HT', $type = 0, $date_start = 0, $date_end = 0, $info_bits = 0, $special_code = 0, $rang = -1, $fk_unit =
null, $pu_ht_devise = 0, $pu_ttc = 0)
1082 global $mysoc, $user;
1086 dol_syslog(get_class($this).
'::updateline facid=' .$facid.
" rowid=$rowid, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, price_base_type=$price_base_type, pu_ttc=$pu_ttc, type=$type, fk_unit=$fk_unit, pu_ht_devise=$pu_ht_devise", LOG_DEBUG);
1087 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1094 if ($this->
status == self::STATUS_SUSPENDED) {
1096 $fk_product = empty($fk_product) ? 0 : $fk_product;
1097 $label = empty($label) ?
'' : $label;
1098 $remise_percent = empty($remise_percent) ? 0 :
price2num($remise_percent);
1100 $info_bits = empty($info_bits) ? 0 : $info_bits;
1103 $pu_ht_devise =
price2num($pu_ht_devise);
1105 if (!preg_match(
'/\((.*)\)/', $txtva)) {
1109 $txlocaltax1 = empty($txlocaltax1) ? 0 :
price2num($txlocaltax1);
1110 $txlocaltax2 = empty($txlocaltax2) ? 0 :
price2num($txlocaltax2);
1111 $this->multicurrency_total_ht = empty($this->multicurrency_total_ht) ? 0 : $this->multicurrency_total_ht;
1112 $this->multicurrency_total_tva = empty($this->multicurrency_total_tva) ? 0 : $this->multicurrency_total_tva;
1113 $this->multicurrency_total_ttc = empty($this->multicurrency_total_ttc) ? 0 : $this->multicurrency_total_ttc;
1115 $pu = $price_base_type ==
'HT' ? $pu_ht : $pu_ttc;
1127 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1128 $vat_src_code = $reg[1];
1129 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1132 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
1134 $total_ht = $tabprice[0];
1135 $total_tva = $tabprice[1];
1136 $total_ttc = $tabprice[2];
1137 $total_localtax1 = $tabprice[9];
1138 $total_localtax2 = $tabprice[10];
1139 $pu_ht = $tabprice[3];
1140 $pu_tva = $tabprice[4];
1141 $pu_ttc = $tabprice[5];
1144 $multicurrency_total_ht = $tabprice[16];
1145 $multicurrency_total_tva = $tabprice[17];
1146 $multicurrency_total_ttc = $tabprice[18];
1147 $pu_ht_devise = $tabprice[19];
1149 $product_type = $type;
1151 $product =
new Product($this->db);
1152 $result = $product->fetch($fk_product);
1153 $product_type = $product->type;
1156 $sql =
'UPDATE ' . MAIN_DB_PREFIX .
'facture_fourn_det_rec SET';
1157 $sql .=
' fk_facture_fourn = ' . ((int) $facid);
1158 $sql .=
', fk_product = ' . ($fk_product > 0 ? ((int) $fk_product) :
'null');
1159 $sql .=
", ref = '" . $this->db->escape($ref) .
"'";
1160 $sql .=
", label = '" . $this->db->escape($label) .
"'";
1161 $sql .=
", description = '" . $this->db->escape($desc) .
"'";
1162 $sql .=
', pu_ht = ' .
price2num($pu_ht);
1164 $sql .=
", remise_percent = '" .
price2num($remise_percent) .
"'";
1165 $sql .=
", vat_src_code = '" . $this->db->escape($vat_src_code) .
"'";
1166 $sql .=
', tva_tx = ' .
price2num($txtva);
1167 $sql .=
', localtax1_tx = ' . (float) $txlocaltax1;
1168 $sql .=
", localtax1_type = '" . $this->db->escape($localtaxes_type[0]) .
"'";
1169 $sql .=
', localtax2_tx = ' . (float) $txlocaltax2;
1170 $sql .=
", localtax2_type = '" . $this->db->escape($localtaxes_type[2]) .
"'";
1171 $sql .=
", total_ht = '" .
price2num($total_ht) .
"'";
1172 $sql .=
", total_tva = '" .
price2num($total_tva) .
"'";
1173 $sql .=
", total_localtax1 = '" .
price2num($total_localtax1) .
"'";
1174 $sql .=
", total_localtax2 = '" .
price2num($total_localtax2) .
"'";
1175 $sql .=
", total_ttc = '" .
price2num($total_ttc) .
"'";
1176 $sql .=
', product_type = ' . (int) $product_type;
1177 $sql .=
', date_start = ' . (empty($date_start) ?
'NULL' : (int) $date_start);
1178 $sql .=
', date_end = ' . (empty($date_end) ?
'NULL' : (int) $date_end);
1179 $sql .=
', info_bits = ' . (int) $info_bits;
1180 $sql .=
', special_code = ' . (int) $special_code;
1181 $sql .=
', rang = ' . (int) $rang;
1182 $sql .=
', fk_unit = ' . ($fk_unit ?
"'" . $this->db->escape($fk_unit) .
"'" :
'null');
1183 $sql .=
', fk_user_modif = ' . (int) $user;
1184 $sql .=
', multicurrency_subprice = '.price2num($pu_ht_devise);
1185 $sql .=
', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1186 $sql .=
', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1187 $sql .=
', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1188 $sql .=
' WHERE rowid = ' . (int) $rowid;
1190 dol_syslog(get_class($this).
'::updateline', LOG_DEBUG);
1191 if ($this->db->query($sql)) {
1196 $this->error = $this->db->lasterror();
1224 if (empty($this->date_when)) {
1238 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1253 return ($this->
isMaxNbGenReached() ?
'<strike>' :
'').$ret.($this->isMaxNbGenReached() ?
'</strike>' :
'');
1268 global $conf, $langs, $db, $user, $hookmanager;
1274 $langs->loadLangs(array(
'main',
'bills'));
1278 $today =
dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
1280 dol_syslog(
'createRecurringInvoices restrictioninvoiceid=' .$restrictioninvoiceid.
' forcevalidation=' .$forcevalidation);
1282 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec';
1283 $sql .=
' WHERE frequency > 0';
1284 $sql .=
" AND (date_when IS NULL OR date_when <= '".$this->db->idate($today).
"')";
1285 $sql .=
' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1286 $sql .=
' AND suspended = 0';
1287 $sql .=
' AND entity = '. (int) $conf->entity;
1288 if ($restrictioninvoiceid > 0) {
1289 $sql .=
' AND rowid = '. (int) $restrictioninvoiceid;
1291 $sql .= $this->db->order(
'entity',
'ASC');
1293 $parameters = array(
1294 'restrictioninvoiceid' => $restrictioninvoiceid,
1295 'forcevalidation' => $forcevalidation,
1297 $reshook = $hookmanager->executeHooks(
'beforeCreationOfRecurringInvoices', $parameters, $sql);
1299 $resql = $this->db->query($sql);
1302 $num = $this->db->num_rows($resql);
1305 $this->output .= $langs->trans(
'FoundXQualifiedRecurringInvoiceTemplate', $num).
"\n";
1307 $this->output .= $langs->trans(
'NoQualifiedRecurringInvoiceTemplateFound');
1310 $saventity = $conf->entity;
1314 $line = $this->db->fetch_object($resql);
1318 $invoiceidgenerated = 0;
1320 $new_fac_fourn =
null;
1322 $laststep=
"Fetch {$line->rowid}";
1323 $facturerec->fetch($line->rowid);
1325 if ($facturerec->id > 0) {
1327 $conf->entity = $facturerec->entity;
1329 dol_syslog(
'createRecurringInvoices Process invoice template id=' .$facturerec->id.
', ref=' .$facturerec->ref.
', entity=' .$facturerec->entity);
1332 $new_fac_fourn->fac_rec = $facturerec->id;
1333 $new_fac_fourn->fk_fac_rec_source = $facturerec->id;
1338 $new_fac_fourn->date = empty($facturerec->date_when) ? $now : $facturerec->date_when;
1339 $new_fac_fourn->socid = $facturerec->socid;
1340 $new_fac_fourn->lines = $facturerec->lines;
1341 $new_fac_fourn->ref_supplier = $facturerec->ref_supplier;
1342 $new_fac_fourn->model_pdf = $facturerec->model_pdf;
1343 $new_fac_fourn->fk_project = $facturerec->fk_project;
1344 $new_fac_fourn->label = $facturerec->label;
1345 $new_fac_fourn->libelle = $facturerec->label;
1347 $invoiceidgenerated = $new_fac_fourn->create($user);
1348 $laststep=
"Create invoiceidgenerated $invoiceidgenerated";
1349 if ($invoiceidgenerated <= 0) {
1350 $this->errors = $new_fac_fourn->errors;
1351 $this->error = $new_fac_fourn->error;
1354 if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
1355 $result = $new_fac_fourn->validate($user);
1356 $laststep =
"Validate by user {$user->login}";
1358 $this->errors = $new_fac_fourn->errors;
1359 $this->error = $new_fac_fourn->error;
1364 if (!$error && $facturerec->generate_pdf) {
1366 $laststep =
"Refresh ".$new_fac_fourn->id;
1367 $new_fac_fourn->fetch($new_fac_fourn->id);
1368 $laststep =
"GenerateDocument ".$new_fac_fourn->id;
1369 $result = $new_fac_fourn->generateDocument($facturerec->model_pdf, $langs);
1371 $this->errors = $new_fac_fourn->errors;
1372 $this->error = $new_fac_fourn->error;
1378 $this->error =
'Failed to load invoice template with id=' .$line->rowid.
', entity=' .$conf->entity.
"\n";
1379 $this->errors[] =
'Failed to load invoice template with id=' .$line->rowid.
', entity=' .$conf->entity;
1380 dol_syslog(
'createRecurringInvoices Failed to load invoice template with id=' .$line->rowid.
', entity=' .$conf->entity);
1383 if (!$error && $invoiceidgenerated >= 0) {
1384 $facturerec->nb_gen_done++;
1385 $facturerec->date_last_gen =
dol_now();
1386 $facturerec->date_when= $facturerec->getNextDate();
1387 $facturerec->update($user);
1388 $this->db->commit(
'createRecurringInvoices Process invoice template id=' .$facturerec->id.
', title=' .$facturerec->title);
1389 dol_syslog(
'createRecurringInvoices Process invoice template ' .$facturerec->title.
' is finished with a success generation');
1391 $this->output .= $langs->trans(
'InvoiceGeneratedFromTemplate', $new_fac_fourn->ref, $facturerec->title).
"\n";
1393 $this->db->rollback(
'createRecurringInvoices Process invoice template error='.$error.
' invoiceidgenerated='.$invoiceidgenerated.
' LastStep='.$laststep.
' id=' .$facturerec->id.
', title=' .$facturerec->title);
1396 $parameters = array(
1399 'errorCount' => $error,
1400 'invoiceidgenerated' => $invoiceidgenerated,
1401 'facturerec' => $facturerec,
1404 $reshook = $hookmanager->executeHooks(
'afterCreationOfRecurringInvoice', $parameters, $new_fac_fourn);
1409 $conf->entity = $saventity;
1414 $this->output = trim($this->output);
1416 return $error ? $error : 0;
1431 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1)
1433 global $langs, $hookmanager;
1437 $label =
'<u>'.$langs->trans(
'RepeatableInvoice').
'</u>';
1438 if (!empty($this->
ref)) {
1439 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1441 if ($this->frequency > 0) {
1442 $label .=
'<br><b>'.$langs->trans(
'Frequency').
':</b> '.$langs->trans(
'FrequencyPer_'.$this->unit_frequency, $this->frequency);
1444 if (!empty($this->date_last_gen)) {
1445 $label .=
'<br><b>'.$langs->trans(
'DateLastGeneration').
':</b> '.
dol_print_date($this->date_last_gen,
'dayhour');
1447 if ($this->frequency > 0) {
1448 if (!empty($this->date_when)) {
1449 $label .=
'<br><b>'.$langs->trans(
'NextDateToExecution').
':</b> ';
1450 $label .= (empty($this->suspended) ?
'' :
'<strike>').
dol_print_date($this->date_when,
'day').(empty($this->suspended) ?
'' :
'</strike>');
1451 if (!empty($this->suspended)) {
1452 $label .=
' ('.$langs->trans(
'Disabled').
')';
1457 $url = DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$this->id;
1463 if ($option !=
'nolink') {
1465 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1466 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
'PHP_SELF'])) {
1467 $add_save_lastsearch_values = 1;
1469 if ($add_save_lastsearch_values) {
1470 $url .=
'&save_lastsearch_values=1';
1474 $linkstart =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
1477 $result .= $linkstart;
1479 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1481 if ($withpicto != 2) {
1482 $result .= $this->ref;
1484 $result .= $linkend;
1486 $hookmanager->initHooks(array($this->element .
'dao'));
1487 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1488 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1490 $result = $hookmanager->resPrint;
1492 $result .= $hookmanager->resPrint;
1506 return $this->
LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->
type) ? 0 : $this->type);
1520 public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1524 $langs->load(
'bills');
1526 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1527 $statusType =
'status0';
1532 if ($status == self::STATUS_SUSPENDED) {
1533 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1535 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1538 if ($status == self::STATUS_SUSPENDED) {
1539 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1541 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1544 } elseif ($mode == 1) {
1547 if ($status == self::STATUS_SUSPENDED) {
1548 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1550 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1553 if ($status == self::STATUS_SUSPENDED) {
1554 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1556 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1559 } elseif ($mode == 2) {
1561 if ($status == self::STATUS_SUSPENDED) {
1562 $statusType =
'status6';
1563 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1565 $statusType =
'status4';
1566 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1569 if ($status == self::STATUS_SUSPENDED) {
1570 $statusType =
'status6';
1571 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1573 $statusType =
'status0';
1574 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1577 } elseif ($mode == 3) {
1580 if ($status == self::STATUS_SUSPENDED) {
1581 $statusType =
'status6';
1582 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1584 $statusType =
'status4';
1585 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1588 if ($status == self::STATUS_SUSPENDED) {
1589 $statusType =
'status6';
1590 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1592 $statusType =
'status0';
1593 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1596 } elseif ($mode == 4) {
1599 if ($status == self::STATUS_SUSPENDED) {
1600 $statusType =
'status6';
1601 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1603 $statusType =
'status4';
1604 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1607 if ($status == self::STATUS_SUSPENDED) {
1608 $statusType =
'status6';
1609 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1611 $statusType =
'status0';
1612 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1615 } elseif ($mode == 5 || $mode == 6) {
1621 if ($status == self::STATUS_SUSPENDED) {
1622 $statusType =
'status6';
1623 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1625 $statusType =
'status4';
1626 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1629 if ($status == self::STATUS_SUSPENDED) {
1630 $statusType =
'status6';
1631 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1633 $statusType =
'status0';
1634 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1639 $labelStatusShort = $labelStatus;
1641 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1654 global $user, $langs, $conf;
1658 $nownotime =
dol_mktime(0, 0, 0, $arraynow[
'mon'], $arraynow[
'mday'], $arraynow[
'year']);
1664 $sql =
'SELECT rowid';
1665 $sql .=
' FROM ' .MAIN_DB_PREFIX.
'product';
1666 $sql .=
' WHERE entity IN (' .getEntity(
'product').
')';
1667 $sql .= $this->db->plimit(100);
1669 $resql = $this->db->query($sql);
1671 $num_prods = $this->db->num_rows($resql);
1673 while ($i < $num_prods) {
1675 $row = $this->db->fetch_row($resql);
1676 $prodids[$i] = $row[0];
1682 $this->
ref =
'SPECIMEN';
1683 $this->title =
'SPECIMEN';
1684 $this->specimen = 1;
1686 $this->date = $nownotime;
1687 $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1688 $this->cond_reglement_id = 1;
1689 $this->cond_reglement_code =
'RECEP';
1691 $this->mode_reglement_id = 0;
1692 $this->mode_reglement_code =
'';
1693 $this->note_public =
'This is a comment (public)';
1694 $this->note_private =
'This is a comment (private)';
1695 $this->note =
'This is a comment (private)';
1696 $this->fk_incoterms = 0;
1697 $this->location_incoterms =
'';
1699 if (empty($option) || $option !=
'nolines') {
1703 while ($xnbp < $nbp) {
1705 $line->desc = $langs->trans(
'Description').
' ' .$xnbp;
1707 $line->subprice = 100;
1708 $line->tva_tx = 19.6;
1709 $line->localtax1_tx = 0;
1710 $line->localtax2_tx = 0;
1711 $line->remise_percent = 0;
1713 $prodid = mt_rand(1, $num_prods);
1714 $line->fk_product = $prodids[$prodid];
1716 $line->total_ht = -100;
1717 $line->total_ttc = -119.6;
1718 $line->total_tva = -19.6;
1719 } elseif ($xnbp == 2) {
1720 $line->subprice = -100;
1721 $line->total_ht = -100;
1722 $line->total_ttc = -119.6;
1723 $line->total_tva = -19.6;
1724 $line->remise_percent = 0;
1725 } elseif ($xnbp == 3) {
1726 $prodid = mt_rand(1, $num_prods);
1727 $line->fk_product = $prodids[$prodid];
1728 $line->total_ht = 50;
1729 $line->total_ttc = 59.8;
1730 $line->total_tva = 9.8;
1731 $line->remise_percent = 50;
1733 $prodid = mt_rand(1, $num_prods);
1734 $line->fk_product = $prodids[$prodid];
1735 $line->total_ht = 100;
1736 $line->total_ttc = 119.6;
1737 $line->total_tva = 19.6;
1738 $line->remise_percent = 00;
1741 $this->lines[$xnbp] = $line;
1744 $this->total_ht += $line->total_ht;
1745 $this->total_tva += $line->total_tva;
1746 $this->total_ttc += $line->total_ttc;
1748 $this->revenuestamp = 0;
1752 $line->desc = $langs->trans(
'Description').
' (offered line)';
1754 $line->subprice = 100;
1755 $line->tva_tx = 19.6;
1756 $line->localtax1_tx = 0;
1757 $line->localtax2_tx = 0;
1758 $line->remise_percent = 100;
1759 $line->total_ht = 0;
1760 $line->total_ttc = 0;
1761 $line->total_tva = 0;
1762 $prodid = mt_rand(1, $num_prods);
1763 $line->fk_product = $prodids[$prodid];
1765 $this->lines[$xnbp] = $line;
1769 $this->usenewprice = 0;
1798 if (!$this->table_element) {
1799 dol_syslog(get_class($this).
'::setFrequencyAndUnit was called on objet with property table_element not defined', LOG_ERR);
1803 if (!empty($frequency) && empty($unit)) {
1804 dol_syslog(get_class($this).
'::setFrequencyAndUnit was called on objet with params frequency defined but unit not defined', LOG_ERR);
1808 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1809 $sql .=
" SET frequency = ".($frequency ? ((int) $frequency) :
"NULL");
1810 if (!empty($unit)) {
1811 $sql .=
", unit_frequency = '".$this->db->escape($unit).
"'";
1813 $sql .=
" WHERE rowid = ".((int) $this->
id);
1815 dol_syslog(get_class($this).
'::setFrequencyAndUnit', LOG_DEBUG);
1817 if ($this->db->query($sql)) {
1818 $this->frequency = $frequency;
1819 if (!empty($unit)) {
1820 $this->unit_frequency = $unit;
1824 $this->error = $this->db->lasterror();
1838 if (!$this->table_element) {
1839 dol_syslog(get_class($this).
'::setNextDate was called on objet with property table_element not defined', LOG_ERR);
1842 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1843 $sql .=
" SET date_when = " .($date ?
"'".$this->db->idate($date).
"'" :
"NULL");
1844 if ($increment_nb_gen_done > 0) {
1845 $sql .=
", nb_gen_done = nb_gen_done + 1";
1847 $sql .=
" WHERE rowid = " . (int) $this->
id;
1849 dol_syslog(get_class($this).
'::setNextDate', LOG_DEBUG);
1851 if ($this->db->query($sql)) {
1852 $this->date_when = $date;
1853 if ($increment_nb_gen_done > 0) {
1854 $this->nb_gen_done++;
1858 $this->error = $this->db->lasterror();
1871 if (!$this->table_element) {
1872 dol_syslog(get_class($this).
'::setMaxPeriod was called on objet with property table_element not defined', LOG_ERR);
1880 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1881 $sql .=
" SET nb_gen_max = ". (int) $nb;
1882 $sql .=
" WHERE rowid = " . (int) $this->
id;
1884 dol_syslog(get_class($this).
'::setMaxPeriod', LOG_DEBUG);
1886 if ($this->db->query($sql)) {
1887 $this->nb_gen_max = $nb;
1903 if (!$this->table_element) {
1904 dol_syslog(get_class($this).
'::setAutoValidate was called on objet with property table_element not defined', LOG_ERR);
1908 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1909 $sql .=
" SET auto_validate = ".((int) $validate);
1910 $sql .=
" WHERE rowid = " . (int) $this->
id;
1912 dol_syslog(get_class($this).
'::setAutoValidate', LOG_DEBUG);
1914 if ($this->db->query($sql)) {
1915 $this->auto_validate = $validate;
1931 if (!$this->table_element) {
1932 dol_syslog(get_class($this).
'::setGeneratePdf was called on objet with property table_element not defined', LOG_ERR);
1936 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1937 $sql .=
" SET generate_pdf = ". (int) $validate;
1938 $sql .=
" WHERE rowid = " . (int) $this->
id;
1940 dol_syslog(get_class($this).
'::setGeneratePdf', LOG_DEBUG);
1942 if ($this->db->query($sql)) {
1943 $this->generate_pdf = $validate;
1959 if (!$this->table_element) {
1960 dol_syslog(get_class($this).
'::setModelPdf was called on objet with property table_element not defined', LOG_ERR);
1964 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1965 $sql .=
" SET modelpdf = '".$this->db->escape($model).
"'";
1966 $sql .=
" WHERE rowid = " . (int) $this->
id;
1968 dol_syslog(get_class($this).
'::setModelPdf', LOG_DEBUG);
1970 if ($this->db->query($sql)) {
1971 $this->model_pdf = $model;
1991 public $element =
'invoice_supplier_det_rec';
1996 public $table_element =
'facture_fourn_det_rec';
1998 public $fk_facture_fourn;
2001 public $ref_supplier;
2003 public $description;
2007 public $remise_percent;
2008 public $fk_remise_except;
2009 public $vat_src_code;
2011 public $localtax1_tx;
2012 public $localtax1_type;
2013 public $localtax2_tx;
2014 public $localtax2_type;
2016 public $product_type;
2020 public $special_code;
2023 public $fk_user_author;
2024 public $fk_user_modif;
2034 public function delete(
User $user, $notrigger = 0)
2042 $result = $this->
call_trigger(
'LINESUPPLIERBILLREC_DELETE', $user);
2058 $sql =
'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element .
' WHERE rowid=' . (int) $this->
id;
2060 $res = $this->db->query($sql);
2061 if ($res ===
false) {
2063 $this->errors[] = $this->db->lasterror();
2069 $this->db->rollback();
2072 $this->db->commit();
2086 $sql =
'SELECT l.rowid,';
2087 $sql .=
' l.fk_facture_fourn, l.fk_parent_line, l.fk_product,';
2088 $sql .=
' l.ref as ref_supplier, l.label, l.description, l.pu_ht, l.pu_ttc, l.qty, l.remise_percent, l.fk_remise_except,';
2089 $sql .=
' l.vat_src_code, l.tva_tx, l.localtax1_tx, l.localtax1_type, l.localtax2_tx, l.localtax2_type,';
2090 $sql .=
' l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc,';
2091 $sql .=
' l.product_type, l.date_start, l.date_end,';
2092 $sql .=
' l.info_bits, l.special_code, l.rang, l.fk_unit, l.import_key,';
2093 $sql .=
' l.fk_user_author, l.fk_user_modif, l.fk_multicurrency,';
2094 $sql .=
' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2095 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2096 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_det_rec as l';
2097 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
2098 $sql .=
' WHERE l.rowid = '. (int) $rowid;
2099 $sql .=
' ORDER BY l.rang';
2102 $result = $this->db->query($sql);
2104 $objp = $this->db->fetch_object($result);
2106 $this->
id = $objp->rowid;
2107 $this->fk_facture_fourn = $objp->fk_facture_fourn;
2108 $this->fk_parent = $objp->fk_parent_line;
2109 $this->fk_product = $objp->fk_product;
2110 $this->ref_supplier = $objp->ref_supplier;
2111 $this->label = $objp->label;
2113 $this->pu_ht = $objp->pu_ht;
2114 $this->pu_ttc = $objp->pu_ttc;
2115 $this->qty = $objp->qty;
2116 $this->remise_percent = $objp->remise_percent;
2117 $this->fk_remise_except = $objp->fk_remise_except;
2118 $this->vat_src_code = $objp->vat_src_code;
2119 $this->tva_tx = $objp->tva_tx;
2120 $this->localtax1_tx = $objp->localtax1_tx;
2121 $this->localtax1_type = $objp->localtax1_type;
2122 $this->localtax2_tx = $objp->localtax2_tx;
2123 $this->localtax2_type = $objp->localtax2_type;
2124 $this->total_ht = $objp->total_ht;
2125 $this->total_tva = $objp->total_tva;
2126 $this->total_localtax1 = $objp->total_localtax1;
2127 $this->total_localtax2 = $objp->total_localtax2;
2128 $this->total_ttc = $objp->total_ttc;
2129 $this->product_type = $objp->product_type;
2130 $this->date_start = $objp->date_start;
2131 $this->date_end = $objp->date_end;
2132 $this->info_bits = $objp->info_bits;
2133 $this->special_code = $objp->special_code;
2134 $this->rang = $objp->rang;
2135 $this->fk_unit = $objp->fk_unit;
2136 $this->import_key = $objp->import_key;
2137 $this->fk_user_author = $objp->fk_user_author;
2138 $this->fk_user_modif = $objp->fk_user_modif;
2139 $this->fk_multicurrency = $objp->fk_multicurrency;
2140 $this->multicurrency_code = $objp->multicurrency_code;
2141 $this->multicurrency_subprice = $objp->multicurrency_subprice;
2142 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2143 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2144 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2146 $this->db->free($result);
2149 $this->error = $this->db->lasterror();
2168 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2170 $sql =
'UPDATE ' . MAIN_DB_PREFIX .
'facture_fourn_det_rec SET';
2171 $sql .=
' fk_facture_fourn = ' . (int) $this->fk_facture_fourn;
2172 $sql .=
', fk_parent_line = ' . (int) $this->fk_parent;
2173 $sql .=
', fk_product = ' . (int) $this->fk_product;
2174 $sql .=
', ref = ' . (!empty($this->
ref) ?
"'" . $this->db->escape($this->
ref) .
"'" :
'NULL');
2175 $sql .=
", label = " . (!empty($this->label) ?
"'" . $this->db->escape($this->label) .
"'" :
'NULL');
2176 $sql .=
", description = '" . $this->db->escape($this->
description) .
"'";
2177 $sql .=
', pu_ht = ' .
price2num($this->pu_ht);
2178 $sql .=
', pu_ttc = ' .
price2num($this->pu_ttc);
2179 $sql .=
', qty = ' .
price2num($this->qty);
2180 $sql .=
", remise_percent = '" .
price2num($this->remise_percent) .
"'";
2181 $sql .=
', fk_remise_except = ' . (int) $this->fk_remise_except;
2182 $sql .=
", vat_src_code = '" . $this->db->escape($this->vat_src_code) .
"'";
2183 $sql .=
', tva_tx = ' .
price2num($this->tva_tx);
2184 $sql .=
', localtax1_tx = ' .
price2num($this->localtax1_tx);
2185 $sql .=
", localtax1_type = '" . $this->db->escape($this->localtax1_type) .
"'";
2186 $sql .=
', localtax2_tx = ' .
price2num($this->localtax2_tx);
2187 $sql .=
", localtax2_type = '" . $this->db->escape($this->localtax2_type) .
"'";
2188 if (empty($this->skip_update_total)) {
2189 $sql .=
', total_ht = ' .
price2num($this->total_ht);
2190 $sql .=
', total_tva = ' .
price2num($this->total_tva);
2191 $sql .=
', total_localtax1 = ' .
price2num($this->total_localtax1);
2192 $sql .=
', total_localtax2 = ' .
price2num($this->total_localtax2);
2193 $sql .=
', total_ttc = ' .
price2num($this->total_ttc);
2195 $sql .=
', product_type = ' . (int) $this->product_type;
2196 $sql .=
', date_start = ' . (int) $this->date_start;
2197 $sql .=
', date_end = ' . (int) $this->date_end;
2198 $sql .=
", info_bits = " . ((int) $this->info_bits);
2199 $sql .=
', special_code =' . (int) $this->special_code;
2200 $sql .=
', rang = ' . (int) $this->rang;
2201 $sql .=
', fk_unit = ' .($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
'null');
2202 $sql .=
', fk_user_modif = ' . (int) $user->id;
2203 $sql .=
' WHERE rowid = ' . (int) $this->
id;
2207 dol_syslog(get_class($this).
'::updateline', LOG_DEBUG);
2208 $resql = $this->db->query($sql);
2217 if (!$error && !$notrigger) {
2219 $result = $this->
call_trigger(
'LINESUPPLIERBILLREC_MODIFY', $user);
2227 $this->db->rollback();
2230 $this->db->commit();
2234 $this->error = $this->db->lasterror();
2235 $this->db->rollback();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Superclass for invoices classes.
const TYPE_STANDARD
Standard invoice.
calculate_date_lim_reglement($cond_reglement=0)
Returns an invoice payment deadline based on the invoice settlement conditions and billing date.
const STATUS_DRAFT
Draft status.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
update_price($exclspec=0, $roundingadjust='none', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage suppliers invoices.
Class to manage supplier invoice lines of templates.
fetch($rowid)
Get line of template invoice.
update(User $user, $notrigger=0)
Update a line to supplier invoice template .
Class to manage invoice templates.
setModelPdf($model)
Update the model for documents.
fetch($rowid, $ref='', $ref_ext='')
Load object and lines.
strikeIfMaxNbGenReached($ret)
Format string to output with by striking the string if max number of generation was reached.
setFrequencyAndUnit($frequency, $unit)
Update frequency and unit.
getNextNumRef($soc, $mode='next')
Return next reference of invoice not already used (or last reference)
create($user, $facFournId, $notrigger=0)
Create a predefined supplier invoice.
setGeneratePdf($validate)
Update the auto generate documents.
getLinesArray()
Create an array of invoice lines.
initAsSpecimen($option='')
Initialise an instance with random values.
LibStatut($recur, $status, $mode=0, $alreadypaid=-1, $type=0)
Return label of a status.
updateline($rowid, $fk_product, $ref, $label, $desc, $pu_ht, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $type=0, $date_start=0, $date_end=0, $info_bits=0, $special_code=0, $rang=-1, $fk_unit=null, $pu_ht_devise=0, $pu_ttc=0)
Update a line to supplier invoice template.
isMaxNbGenReached()
Return if maximum number of generation is reached.
setAutoValidate($validate)
Update the auto validate flag of invoice.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getNextDate()
Return the next date of.
__construct($db)
Constructor.
fetch_lines()
Get lines of template invoices into this->lines.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of object status.
setNextDate($date, $increment_nb_gen_done=0)
Update the next date of execution.
setMaxPeriod($nb)
Update the maximum period.
createRecurringInvoices($restrictioninvoiceid=0, $forcevalidation=0)
Create all recurrents supplier invoices (for all entities if multicompany is used).
update(User $user, $notrigger=0)
Update fourn_invoice_rec.
addline($fk_product, $ref, $label, $desc, $pu_ht, $pu_ttc, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $type=0, $date_start=0, $date_end=0, $info_bits=0, $special_code=0, $rang=-1, $fk_unit=null, $pu_ht_devise=0)
Add a line to recursive supplier invoice.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='', $notooltip=0, $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
Class to manage invoice lines.
Class to manage products or services.
Class to manage Dolibarr users.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type