38include_once DOL_DOCUMENT_ROOT.
'/core/class/commoninvoice.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
43if (isModEnabled(
'accounting')) {
44 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
56 public $element =
'invoice_supplier';
61 public $table_element =
'facture_fourn';
66 public $table_element_line =
'facture_fourn_det';
71 public $fk_element =
'fk_facture_fourn';
76 public $picto =
'supplier_invoice';
82 public $ismultientitymanaged = 1;
88 public $restrictiononfksoc = 1;
108 public $ref_supplier;
181 public $date_echeance;
206 public $total_localtax1;
207 public $total_localtax2;
216 public $note_private;
220 public $cond_reglement_id;
221 public $cond_reglement_code;
222 public $cond_reglement_label;
223 public $cond_reglement_doc;
230 public $mode_reglement_id;
231 public $mode_reglement_code;
236 public $transport_mode_id;
241 public $vat_reverse_charge;
243 public $extraparams = array();
249 public $lines = array();
260 public $fk_multicurrency;
262 public $multicurrency_code;
263 public $multicurrency_tx;
264 public $multicurrency_total_ht;
265 public $multicurrency_total_tva;
266 public $multicurrency_total_ttc;
271 public $fk_facture_source;
276 public $fields = array(
277 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
278 'ref' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>15),
279 'ref_supplier' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefSupplier',
'enabled'=>1,
'visible'=>-1,
'position'=>20),
280 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>25,
'index'=>1),
281 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefExt',
'enabled'=>1,
'visible'=>0,
'position'=>30),
282 'type' =>array(
'type'=>
'smallint(6)',
'label'=>
'Type',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>35),
283 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'isModEnabled("societe")',
'visible'=>-1,
'notnull'=>1,
'position'=>40),
284 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
285 'datef' =>array(
'type'=>
'date',
'label'=>
'Date',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
286 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>55),
287 'libelle' =>array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
288 'paye' =>array(
'type'=>
'smallint(6)',
'label'=>
'Paye',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>65),
289 'amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'Amount',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>70),
290 'remise' =>array(
'type'=>
'double(24,8)',
'label'=>
'Discount',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
291 'close_code' =>array(
'type'=>
'varchar(16)',
'label'=>
'CloseCode',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
292 'close_note' =>array(
'type'=>
'varchar(128)',
'label'=>
'CloseNote',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
293 'tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Tva',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
294 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax1',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
295 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax2',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
296 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalHT',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
297 'total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalVAT',
'enabled'=>1,
'visible'=>-1,
'position'=>110),
298 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalTTC',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
299 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
300 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>130),
301 'fk_user_valid' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
302 'fk_facture_source' =>array(
'type'=>
'integer',
'label'=>
'Fk facture source',
'enabled'=>1,
'visible'=>-1,
'position'=>140),
303 'fk_projet' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:fk_statut=1',
'label'=>
'Project',
'enabled'=>
"isModEnabled('project')",
'visible'=>-1,
'position'=>145),
304 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'Account',
'enabled'=>
'isModEnabled("banque")',
'visible'=>-1,
'position'=>150),
305 'fk_cond_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentTerm',
'enabled'=>1,
'visible'=>-1,
'position'=>155),
306 'fk_mode_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentMode',
'enabled'=>1,
'visible'=>-1,
'position'=>160),
307 'date_lim_reglement' =>array(
'type'=>
'date',
'label'=>
'DateLimReglement',
'enabled'=>1,
'visible'=>-1,
'position'=>165),
308 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>170),
309 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>175),
310 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'ModelPdf',
'enabled'=>1,
'visible'=>0,
'position'=>180),
311 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>190),
312 'fk_incoterms' =>array(
'type'=>
'integer',
'label'=>
'IncotermCode',
'enabled'=>1,
'visible'=>-1,
'position'=>195),
313 'location_incoterms' =>array(
'type'=>
'varchar(255)',
'label'=>
'IncotermLocation',
'enabled'=>1,
'visible'=>-1,
'position'=>200),
314 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'MulticurrencyId',
'enabled'=>1,
'visible'=>-1,
'position'=>205),
315 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'MulticurrencyCode',
'enabled'=>1,
'visible'=>-1,
'position'=>210),
316 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyRate',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
317 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyTotalHT',
'enabled'=>1,
'visible'=>-1,
'position'=>220),
318 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyTotalVAT',
'enabled'=>1,
'visible'=>-1,
'position'=>225),
319 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyTotalTTC',
'enabled'=>1,
'visible'=>-1,
'position'=>230),
320 'date_pointoftax' =>array(
'type'=>
'date',
'label'=>
'Date pointoftax',
'enabled'=>1,
'visible'=>-1,
'position'=>235),
321 'date_valid' =>array(
'type'=>
'date',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>240),
322 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'Last main doc',
'enabled'=>1,
'visible'=>-1,
'position'=>245),
323 'fk_statut' =>array(
'type'=>
'smallint(6)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>500),
324 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>900),
376 const CLOSECODE_DISCOUNTVAT =
'discount_vat';
377 const CLOSECODE_BADCREDIT =
'badsupplier';
378 const CLOSECODE_ABANDONED =
'abandon';
379 const CLOSECODE_REPLACED =
'replaced';
399 global $langs, $conf, $hookmanager;
405 if (isset($this->ref_supplier)) {
406 $this->ref_supplier = trim($this->ref_supplier);
408 if (empty($this->
type)) {
411 if (empty($this->date)) {
416 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
421 if (empty($this->fk_multicurrency)) {
422 $this->multicurrency_code = $conf->currency;
423 $this->fk_multicurrency = 0;
424 $this->multicurrency_tx = 1;
430 if ($this->fac_rec > 0) {
431 $this->fk_fac_rec_source = $this->fac_rec;
433 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture-rec.class.php';
435 $result = $_facrec->fetch($this->fac_rec);
436 $result = $_facrec->fetchObjectLinked(
null,
'',
null,
'',
'OR', 1,
'sourcetype', 0);
439 if (!empty($_facrec->frequency)) {
440 $originaldatewhen = $_facrec->date_when;
441 $nextdatewhen =
dol_time_plus_duree($originaldatewhen, $_facrec->frequency, $_facrec->unit_frequency);
443 $this->socid = $_facrec->socid;
446 $this->entity = $_facrec->entity;
449 $this->fk_project =
GETPOST(
'projectid',
'int') > 0 ? ((int)
GETPOST(
'projectid',
'int')) : $_facrec->fk_projet;
450 $this->fk_projet = $this->fk_project;
451 $this->note_public =
GETPOST(
'note_public',
'restricthtml') ?
GETPOST(
'note_public',
'restricthtml') : $_facrec->note_public;
452 $this->note_private =
GETPOST(
'note_private',
'restricthtml') ?
GETPOST(
'note_private',
'restricthtml') : $_facrec->note_private;
453 $this->model_pdf =
GETPOST(
'model',
'alpha') ?
GETPOST(
'model',
'alpha') : $_facrec->model_pdf;
454 $this->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int') > 0 ? ((int)
GETPOST(
'cond_reglement_id',
'int')) : $_facrec->cond_reglement_id;
455 $this->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int') > 0 ? ((int)
GETPOST(
'mode_reglement_id',
'int')) : $_facrec->mode_reglement_id;
456 $this->fk_account =
GETPOST(
'fk_account') > 0 ? ((int)
GETPOST(
'fk_account')) : $_facrec->fk_account;
459 $this->total_ht = $_facrec->total_ht;
460 $this->total_ttc = $_facrec->total_ttc;
463 $this->fk_incoterms = $_facrec->fk_incoterms;
464 $this->location_incoterms = $_facrec->location_incoterms;
470 if (!empty(
GETPOST(
'ref_supplier'))) {
471 $this->ref_supplier = trim($this->ref_supplier);
473 $this->ref_supplier = trim($this->ref_supplier .
'_' . ($_facrec->nb_gen_done + 1));
475 $this->note_public = trim($this->note_public);
476 $this->note_private = trim($this->note_private);
477 $this->note_private =
dol_concatdesc($this->note_private, $langs->trans(
"GeneratedFromRecurringInvoice", $_facrec->titre));
479 $this->array_options = $_facrec->array_options;
481 if (! $this->mode_reglement_id) {
482 $this->mode_reglement_id = 0;
484 $this->brouillon = 1;
488 $this->linked_objects = $_facrec->linkedObjectsIds;
495 if ($_facrec->frequency > 0) {
496 dol_syslog(
"This is a recurring invoice so we set date_last_gen and next date_when");
497 if (empty($_facrec->date_when)) {
498 $_facrec->date_when = $now;
500 $next_date = $_facrec->getNextDate();
501 $result = $_facrec->setValueFrom(
'date_last_gen', $now,
'',
null,
'date',
'', $user,
'');
503 $result = $_facrec->setNextDate($next_date, 1);
507 $outputlangs = $langs;
510 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($this->thirdparty->default_lang)) {
511 $newlang = $this->thirdparty->default_lang;
513 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($this->default_lang)) {
514 $newlang = $this->default_lang;
516 if (!empty($newlang)) {
518 $outputlangs->setDefaultLang($newlang);
524 $substitutionarray[
'__INVOICE_MONTH__'] =
dol_print_date($this->date,
'%m');
527 $substitutionarray[
'__INVOICE_MONTH_TEXT__'] =
dol_print_date($this->date,
'%B');
530 $substitutionarray[
'__INVOICE_YEAR__'] =
dol_print_date($this->date,
'%Y');
533 $substitutionarray[
'__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] =
dol_print_date($originaldatewhen,
'dayhour');
534 $substitutionarray[
'__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] =
dol_print_date($nextdatewhen,
'dayhour');
535 $substitutionarray[
'__INVOICE_PREVIOUS_DATE_NEXT_INVOICE_AFTER_GEN__'] =
dol_print_date($previousdaynextdatewhen,
'dayhour');
536 $substitutionarray[
'__INVOICE_COUNTER_CURRENT__'] = $_facrec->nb_gen_done;
537 $substitutionarray[
'__INVOICE_COUNTER_MAX__'] = $_facrec->nb_gen_max;
546 if (!empty($forceduedate)) {
547 $this->date_echeance = $forceduedate;
550 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facture_fourn (";
552 $sql .=
", ref_supplier";
560 $sql .=
", vat_reverse_charge";
561 $sql .=
", fk_projet";
562 $sql .=
", fk_cond_reglement";
563 $sql .=
", fk_mode_reglement";
564 $sql .=
", fk_account";
565 $sql .=
", note_private";
566 $sql .=
", note_public";
567 $sql .=
", fk_user_author";
568 $sql .=
", date_lim_reglement";
569 $sql .=
", fk_incoterms, location_incoterms";
570 $sql .=
", fk_multicurrency";
571 $sql .=
", multicurrency_code";
572 $sql .=
", multicurrency_tx";
573 $sql .=
", fk_facture_source";
574 $sql .=
", fk_fac_rec_source";
578 $sql .=
", '".$this->db->escape($this->ref_supplier).
"'";
579 $sql .=
", '".$this->db->escape($this->ref_ext).
"'";
580 $sql .=
", ".((int) $conf->entity);
581 $sql .=
", '".$this->db->escape($this->
type).
"'";
582 $sql .=
", '".$this->db->escape(isset($this->label) ? $this->label : (isset($this->libelle) ? $this->libelle :
'')).
"'";
583 $sql .=
", ".((int) $this->socid);
584 $sql .=
", '".$this->db->idate($now).
"'";
585 $sql .=
", '".$this->db->idate($this->date).
"'";
586 $sql .=
", ".($this->vat_reverse_charge !=
'' ? ((int) $this->db->escape($this->vat_reverse_charge)) : 0);
587 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
588 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
"null");
589 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"null");
590 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
591 $sql .=
", '".$this->db->escape($this->note_private).
"'";
592 $sql .=
", '".$this->db->escape($this->note_public).
"'";
593 $sql .=
", ".((int) $user->id).
",";
594 $sql .= $this->date_echeance !=
'' ?
"'".$this->db->idate($this->date_echeance).
"'" :
"null";
595 $sql .=
", ".(int) $this->fk_incoterms;
596 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
597 $sql .=
", ".(int) $this->fk_multicurrency;
598 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
599 $sql .=
", ".(double) $this->multicurrency_tx;
600 $sql .=
", ".($this->fk_facture_source ? ((int) $this->fk_facture_source) :
"null");
601 $sql .=
", ".(isset($this->fk_fac_rec_source) ? $this->fk_fac_rec_source :
"NULL");
604 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
605 $resql = $this->db->query($sql);
607 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn');
610 $this->
ref =
'(PROV'.$this->id.
')';
611 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"facture_fourn SET ref='".$this->db->escape($this->
ref).
"' WHERE rowid=".((int) $this->
id);
613 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
614 $resql = $this->db->query($sql);
619 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
620 $this->linked_objects = $this->linkedObjectsIds;
624 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
625 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
626 if (is_array($tmp_origin_id)) {
627 foreach ($tmp_origin_id as $origin_id) {
636 $origin_id = $tmp_origin_id;
646 if (!$error && empty($this->fac_rec) && count($this->lines) && is_object($this->lines[0])) {
647 dol_syslog(
"There is ".count($this->lines).
" lines that are invoice lines objects");
648 foreach ($this->lines as $i => $val) {
649 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'facture_fourn_det (fk_facture_fourn, special_code, fk_remise_except)';
650 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $this->lines[$i]->special_code).
", ".($this->lines[$i]->fk_remise_except > 0 ? ((int) $this->lines[$i]->fk_remise_except) :
'NULL').
')';
652 $resql_insert = $this->db->query($sql);
654 $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn_det');
659 $this->lines[$i]->subprice,
660 $this->lines[$i]->tva_tx.($this->lines[$i]->vat_src_code ?
' ('.$this->lines[$i]->vat_src_code.
')' :
''),
661 $this->lines[$i]->localtax1_tx,
662 $this->lines[$i]->localtax2_tx,
663 $this->lines[$i]->qty,
664 $this->lines[$i]->fk_product,
666 (!empty($this->lines[$i]->info_bits) ? $this->lines[$i]->info_bits :
''),
667 $this->lines[$i]->product_type,
668 $this->lines[$i]->remise_percent,
670 $this->lines[$i]->date_start,
671 $this->lines[$i]->date_end,
672 $this->lines[$i]->array_options,
673 $this->lines[$i]->fk_unit,
674 $this->lines[$i]->multicurrency_subprice,
675 $this->lines[$i]->ref_supplier
678 $this->error = $this->db->lasterror();
679 $this->db->rollback();
683 } elseif (!$error && empty($this->fac_rec)) {
684 dol_syslog(
"There is ".count($this->lines).
" lines that are array lines");
685 foreach ($this->lines as $i => $val) {
686 $line = $this->lines[$i];
690 if (!is_object($line)) {
691 $line = (object) $line;
694 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'facture_fourn_det (fk_facture_fourn, special_code, fk_remise_except)';
695 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $this->lines[$i]->special_code).
", ".($this->lines[$i]->fk_remise_except > 0 ? ((int) $this->lines[$i]->fk_remise_except) :
'NULL').
')';
697 $resql_insert = $this->db->query($sql);
699 $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn_det');
711 (!empty($line->info_bits) ? $line->info_bits :
''),
713 $line->remise_percent,
717 $line->array_options,
719 $line->multicurrency_subprice,
723 $this->error = $this->db->lasterror();
724 $this->db->rollback();
733 if (! $error && $this->fac_rec > 0) {
734 foreach ($_facrec->lines as $i => $val) {
735 if ($_facrec->lines[$i]->fk_product) {
736 $prod =
new Product($this->db);
737 $res = $prod->fetch($_facrec->lines[$i]->fk_product);
748 $tva_tx = $_facrec->lines[$i]->tva_tx . ($_facrec->lines[$i]->vat_src_code ?
'(' . $_facrec->lines[$i]->vat_src_code .
')' :
'');
749 $tva_npr = $_facrec->lines[$i]->info_bits;
750 if (empty($tva_tx)) {
753 $localtax1_tx = $_facrec->lines[$i]->localtax1_tx;
754 $localtax2_tx = $_facrec->lines[$i]->localtax2_tx;
756 $fk_product_fournisseur_price = empty($_facrec->lines[$i]->fk_product_fournisseur_price) ? null : $_facrec->lines[$i]->fk_product_fournisseur_price;
757 $buyprice = empty($_facrec->lines[$i]->buyprice) ? 0 : $_facrec->lines[$i]->buyprice;
760 if (! $buyprice && $_facrec->lines[$i]->fk_product > 0) {
761 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.product.class.php';
763 $producttmp->fetch($_facrec->lines[$i]->fk_product);
768 if ($conf->global->MARGIN_TYPE ==
'costprice' && !empty($producttmp->cost_price)) {
769 $buyprice = $producttmp->cost_price;
770 } elseif (isModEnabled(
'stock') && ($conf->global->MARGIN_TYPE ==
'costprice' || $conf->global->MARGIN_TYPE ==
'pmp') && !empty($producttmp->pmp)) {
771 $buyprice = $producttmp->pmp;
773 if ($producttmp->find_min_price_product_fournisseur($_facrec->lines[$i]->fk_product) > 0) {
774 if ($producttmp->product_fourn_price_id > 0) {
775 $buyprice =
price2num($producttmp->fourn_unitprice * (1 - $producttmp->fourn_remise_percent / 100) + $producttmp->fourn_remise,
'MU');
781 $result_insert = $this->
addline(
782 $_facrec->lines[$i]->description,
783 $_facrec->lines[$i]->pu_ht,
787 $_facrec->lines[$i]->qty,
788 $_facrec->lines[$i]->fk_product,
789 $_facrec->lines[$i]->remise_percent,
790 ($_facrec->lines[$i]->date_start == 1 && $this->date) ? $this->date :
'',
791 ($_facrec->lines[$i]->date_end == 1 && $previousdaynextdatewhen) ? $previousdaynextdatewhen :
'',
793 $_facrec->lines[$i]->info_bits,
796 $_facrec->lines[$i]->rang,
798 $_facrec->lines[$i]->array_options,
799 $_facrec->lines[$i]->fk_unit,
802 $_facrec->lines[$i]->ref_supplier,
803 $_facrec->lines[$i]->special_code,
807 if ($result_insert < 0) {
809 $this->error = $this->db->error();
829 $result = $this->
call_trigger(
'BILL_SUPPLIER_CREATE', $user);
840 $this->db->rollback();
844 $this->error = $langs->trans(
'FailedToUpdatePrice');
845 $this->db->rollback();
849 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
850 $this->error = $langs->trans(
'ErrorRefAlreadyExists');
851 $this->db->rollback();
854 $this->error = $this->db->lasterror();
855 $this->db->rollback();
869 public function fetch($id =
'', $ref =
'', $ref_ext =
'')
871 if (empty($id) && empty($ref) && empty($ref_ext)) {
878 $sql .=
" t.ref_supplier,";
879 $sql .=
" t.ref_ext,";
880 $sql .=
" t.entity,";
882 $sql .=
" t.fk_soc,";
886 $sql .=
" t.libelle as label,";
888 $sql .=
" t.close_code,";
889 $sql .=
" t.close_note,";
891 $sql .=
" t.localtax1,";
892 $sql .=
" t.localtax2,";
893 $sql .=
" t.total_ht,";
894 $sql .=
" t.total_tva,";
895 $sql .=
" t.total_ttc,";
896 $sql .=
" t.fk_statut as status,";
897 $sql .=
" t.fk_user_author,";
898 $sql .=
" t.fk_user_valid,";
899 $sql .=
" t.fk_facture_source,";
900 $sql .=
" t.vat_reverse_charge,";
901 $sql .=
" t.fk_fac_rec_source,";
902 $sql .=
" t.fk_projet as fk_project,";
903 $sql .=
" t.fk_cond_reglement,";
904 $sql .=
" t.fk_account,";
905 $sql .=
" t.fk_mode_reglement,";
906 $sql .=
" t.date_lim_reglement,";
907 $sql .=
" t.note_private,";
908 $sql .=
" t.note_public,";
909 $sql .=
" t.model_pdf,";
910 $sql .=
" t.import_key,";
911 $sql .=
" t.extraparams,";
912 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc,";
913 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_label,";
914 $sql .=
' s.nom as socnom, s.rowid as socid,';
915 $sql .=
' t.fk_incoterms, t.location_incoterms,';
916 $sql .=
" i.libelle as label_incoterms,";
917 $sql .=
' t.fk_transport_mode,';
918 $sql .=
' t.fk_multicurrency, t.multicurrency_code, t.multicurrency_tx, t.multicurrency_total_ht, t.multicurrency_total_tva, t.multicurrency_total_ttc';
919 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn as t';
920 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON (t.fk_soc = s.rowid)";
921 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_payment_term as cr ON t.fk_cond_reglement = cr.rowid";
922 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as p ON t.fk_mode_reglement = p.id";
923 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON t.fk_incoterms = i.rowid';
925 $sql .=
" WHERE t.rowid = ".((int) $id);
927 $sql .=
' WHERE t.entity IN ('.getEntity(
'supplier_invoice').
')';
929 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
932 $sql .=
" AND t.ref_ext = '".$this->db->escape($ref_ext).
"'";
936 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
937 $resql = $this->db->query($sql);
939 if ($this->db->num_rows($resql)) {
940 $obj = $this->db->fetch_object($resql);
942 $this->
id = $obj->rowid;
943 $this->
ref = $obj->ref ? $obj->ref : $obj->rowid;
945 $this->ref_supplier = $obj->ref_supplier;
946 $this->ref_ext = $obj->ref_ext;
947 $this->entity = $obj->entity;
949 $this->socid = $obj->fk_soc;
950 $this->datec = $this->db->jdate($obj->datec);
951 $this->date = $this->db->jdate($obj->datef);
952 $this->datep = $this->db->jdate($obj->datef);
953 $this->tms = $this->db->jdate($obj->tms);
954 $this->libelle = $obj->label;
955 $this->label = $obj->label;
956 $this->paye = $obj->paye;
957 $this->paid = $obj->paye;
958 $this->close_code = $obj->close_code;
959 $this->close_note = $obj->close_note;
960 $this->total_localtax1 = $obj->localtax1;
961 $this->total_localtax2 = $obj->localtax2;
962 $this->total_ht = $obj->total_ht;
963 $this->total_tva = $obj->total_tva;
964 $this->total_ttc = $obj->total_ttc;
965 $this->status = $obj->status;
966 $this->
statut = $obj->status;
967 $this->fk_statut = $obj->status;
968 $this->fk_user_author = $obj->fk_user_author;
969 $this->author = $obj->fk_user_author;
970 $this->fk_user_valid = $obj->fk_user_valid;
971 $this->fk_facture_source = $obj->fk_facture_source;
972 $this->vat_reverse_charge = empty($obj->vat_reverse_charge) ?
'0' :
'1';
973 $this->fk_fac_rec_source = $obj->fk_fac_rec_source;
974 $this->fk_project = $obj->fk_project;
975 $this->cond_reglement_id = $obj->fk_cond_reglement;
976 $this->cond_reglement_code = $obj->cond_reglement_code;
977 $this->cond_reglement = $obj->cond_reglement_label;
978 $this->cond_reglement_label = $obj->cond_reglement_label;
979 $this->cond_reglement_doc = $obj->cond_reglement_doc;
980 $this->fk_account = $obj->fk_account;
981 $this->mode_reglement_id = $obj->fk_mode_reglement;
982 $this->mode_reglement_code = $obj->mode_reglement_code;
983 $this->mode_reglement = $obj->mode_reglement_label;
984 $this->date_echeance = $this->db->jdate($obj->date_lim_reglement);
985 $this->note = $obj->note_private;
986 $this->note_private = $obj->note_private;
987 $this->note_public = $obj->note_public;
988 $this->model_pdf = $obj->model_pdf;
989 $this->modelpdf = $obj->model_pdf;
990 $this->import_key = $obj->import_key;
993 $this->fk_incoterms = $obj->fk_incoterms;
994 $this->location_incoterms = $obj->location_incoterms;
995 $this->label_incoterms = $obj->label_incoterms;
996 $this->transport_mode_id = $obj->fk_transport_mode;
999 $this->fk_multicurrency = $obj->fk_multicurrency;
1000 $this->multicurrency_code = $obj->multicurrency_code;
1001 $this->multicurrency_tx = $obj->multicurrency_tx;
1002 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
1003 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
1004 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1006 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
1008 $this->socid = $obj->socid;
1009 $this->socnom = $obj->socnom;
1015 if ($this->
statut == self::STATUS_DRAFT) {
1016 $this->brouillon = 1;
1021 $this->error = $this->db->lasterror();
1025 $this->error =
'Bill with id '.$id.
' not found';
1026 dol_syslog(get_class($this).
'::fetch '.$this->error);
1030 $this->db->free($resql);
1033 $this->error =
"Error ".$this->db->lasterror();
1048 $this->lines = array();
1050 $sql =
'SELECT f.rowid, f.ref as ref_supplier, f.description, f.date_start, f.date_end, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.vat_src_code, f.tva_tx';
1051 $sql .=
', f.localtax1_tx, f.localtax2_tx, f.localtax1_type, f.localtax2_type, f.total_localtax1, f.total_localtax2, f.fk_facture_fourn, f.fk_remise_except';
1052 $sql .=
', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line, f.fk_unit';
1053 $sql .=
', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc';
1054 $sql .=
', f.fk_code_ventilation, f.fk_multicurrency, f.multicurrency_code, f.multicurrency_subprice, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc';
1055 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_det as f';
1056 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON f.fk_product = p.rowid';
1057 $sql .=
' WHERE fk_facture_fourn='.((int) $this->
id);
1058 $sql .=
' ORDER BY f.rang, f.rowid';
1060 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1062 $resql_rows = $this->db->query($sql);
1064 $num_rows = $this->db->num_rows($resql_rows);
1067 while ($i < $num_rows) {
1068 $obj = $this->db->fetch_object($resql_rows);
1072 $line->id = $obj->rowid;
1073 $line->rowid = $obj->rowid;
1074 $line->description = $obj->description;
1075 $line->date_start = $this->db->jdate($obj->date_start);
1076 $line->date_end = $this->db->jdate($obj->date_end);
1078 $line->product_ref = $obj->product_ref;
1079 $line->ref = $obj->product_ref;
1080 $line->ref_supplier = $obj->ref_supplier;
1081 $line->libelle = $obj->label;
1082 $line->label = $obj->label;
1083 $line->product_desc = $obj->product_desc;
1084 $line->subprice = $obj->pu_ht;
1085 $line->pu_ht = $obj->pu_ht;
1086 $line->pu_ttc = $obj->pu_ttc;
1088 $line->vat_src_code = $obj->vat_src_code;
1089 $line->tva_tx = $obj->tva_tx;
1090 $line->localtax1_tx = $obj->localtax1_tx;
1091 $line->localtax2_tx = $obj->localtax2_tx;
1092 $line->localtax1_type = $obj->localtax1_type;
1093 $line->localtax2_type = $obj->localtax2_type;
1094 $line->qty = $obj->qty;
1095 $line->remise_percent = $obj->remise_percent;
1096 $line->fk_remise_except = $obj->fk_remise_except;
1098 $line->total_ht = $obj->total_ht;
1099 $line->total_ttc = $obj->total_ttc;
1100 $line->total_tva = $obj->total_tva;
1101 $line->total_localtax1 = $obj->total_localtax1;
1102 $line->total_localtax2 = $obj->total_localtax2;
1103 $line->fk_facture_fourn = $obj->fk_facture_fourn;
1104 $line->fk_product = $obj->fk_product;
1105 $line->product_type = $obj->product_type;
1106 $line->product_label = $obj->label;
1107 $line->info_bits = $obj->info_bits;
1108 $line->fk_parent_line = $obj->fk_parent_line;
1109 $line->special_code = $obj->special_code;
1110 $line->rang = $obj->rang;
1111 $line->fk_unit = $obj->fk_unit;
1114 $line->code_ventilation = $obj->fk_code_ventilation;
1115 $line->fk_accounting_account = $obj->fk_code_ventilation;
1118 $line->fk_multicurrency = $obj->fk_multicurrency;
1119 $line->multicurrency_code = $obj->multicurrency_code;
1120 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1121 $line->multicurrency_total_ht = $obj->multicurrency_total_ht;
1122 $line->multicurrency_total_tva = $obj->multicurrency_total_tva;
1123 $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1126 $line->fetch_optionals();
1128 $this->lines[$i] = $line;
1133 $this->db->free($resql_rows);
1136 $this->error = $this->db->error();
1137 dol_syslog(get_class($this).
"::fetch_lines - No lines:{$this->error} Error:{$this->error}", LOG_DEBUG);
1150 public function update($user =
null, $notrigger = 0)
1152 global $conf, $langs;
1156 if (empty($this->
type)) {
1159 if (isset($this->
ref)) {
1160 $this->
ref = trim($this->
ref);
1162 if (isset($this->ref_supplier)) {
1163 $this->ref_supplier = trim($this->ref_supplier);
1165 if (isset($this->ref_ext)) {
1166 $this->ref_ext = trim($this->ref_ext);
1168 if (isset($this->entity)) {
1169 $this->entity = trim($this->entity);
1171 if (isset($this->
type)) {
1174 if (isset($this->socid)) {
1175 $this->socid = trim($this->socid);
1177 if (isset($this->label)) {
1178 $this->label = trim($this->label);
1180 if (isset($this->libelle)) {
1181 $this->libelle = trim($this->libelle);
1183 if (isset($this->paye)) {
1184 $this->paye = trim($this->paye);
1186 if (isset($this->close_code)) {
1187 $this->close_code = trim($this->close_code);
1189 if (isset($this->close_note)) {
1190 $this->close_note = trim($this->close_note);
1192 if (isset($this->localtax1)) {
1193 $this->localtax1 = trim($this->localtax1);
1195 if (isset($this->localtax2)) {
1196 $this->localtax2 = trim($this->localtax2);
1198 if (empty($this->total_ht)) {
1199 $this->total_ht = 0;
1201 if (empty($this->total_tva)) {
1202 $this->total_tva = 0;
1204 if (empty($this->total_localtax1)) {
1205 $this->total_localtax1 = 0;
1207 if (empty($this->total_localtax2)) {
1208 $this->total_localtax2 = 0;
1210 if (isset($this->total_ttc)) {
1211 $this->total_ttc = (float) $this->total_ttc;
1213 if (isset($this->
statut)) {
1216 if (isset($this->status)) {
1217 $this->status = (int) $this->status;
1219 if (isset($this->author)) {
1220 $this->author = trim($this->author);
1222 if (isset($this->fk_user_valid)) {
1223 $this->fk_user_valid = trim($this->fk_user_valid);
1225 if (isset($this->fk_facture_source)) {
1226 $this->fk_facture_source = trim($this->fk_facture_source);
1228 if (isset($this->fk_project)) {
1229 if (empty($this->fk_project)) $this->fk_project =
null;
1230 else $this->fk_project = intval($this->fk_project);
1232 if (isset($this->mode_reglement_id)) {
1233 $this->mode_reglement_id = (int) $this->mode_reglement_id;
1235 if (isset($this->cond_reglement_id)) {
1236 $this->cond_reglement_id = (int) $this->cond_reglement_id;
1238 if (isset($this->note_private)) {
1239 $this->note = trim($this->note_private);
1241 if (isset($this->note_public)) {
1242 $this->note_public = trim($this->note_public);
1244 if (isset($this->model_pdf)) {
1245 $this->model_pdf = trim($this->model_pdf);
1247 if (isset($this->import_key)) {
1248 $this->import_key = trim($this->import_key);
1256 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn SET";
1257 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1258 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1259 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1260 $sql .=
" entity=".(isset($this->entity) ? ((int) $this->entity) :
"null").
",";
1261 $sql .=
" type=".(isset($this->
type) ? ((int) $this->
type) :
"null").
",";
1262 $sql .=
" fk_soc=".(isset($this->socid) ? ((int) $this->socid) :
"null").
",";
1263 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
1264 $sql .=
" datef=".(dol_strlen($this->date) != 0 ?
"'".$this->db->idate($this->date).
"'" :
'null').
",";
1266 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
1268 $sql .=
" libelle=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
1269 $sql .=
" paye=".(isset($this->paye) ? ((int) $this->paye) :
"0").
",";
1270 $sql .=
" close_code=".(isset($this->close_code) ?
"'".$this->db->escape($this->close_code).
"'" :
"null").
",";
1271 $sql .=
" close_note=".(isset($this->close_note) ?
"'".$this->db->escape($this->close_note).
"'" :
"null").
",";
1272 $sql .=
" localtax1=".(isset($this->total_localtax1) ? ((float) $this->total_localtax1) :
"null").
",";
1273 $sql .=
" localtax2=".(isset($this->total_localtax2) ? ((float) $this->total_localtax2) :
"null").
",";
1274 $sql .=
" total_ht=".(isset($this->total_ht) ? ((float) $this->total_ht) :
"null").
",";
1275 $sql .=
" total_tva=".(isset($this->total_tva) ? ((float) $this->total_tva) :
"null").
",";
1276 $sql .=
" total_ttc=".(isset($this->total_ttc) ? ((float) $this->total_ttc) :
"null").
",";
1277 $sql .=
" fk_statut=".(isset($this->status) ? ((int) $this->status) : (isset($this->
statut) ? ((int) $this->
statut) :
"null")).
",";
1278 $sql .=
" fk_user_author=".(isset($this->author) ? ((int) $this->author) :
"null").
",";
1279 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? ((int) $this->fk_user_valid) :
"null").
",";
1280 $sql .=
" fk_facture_source=".($this->fk_facture_source ? ((int) $this->fk_facture_source) :
"null").
",";
1281 $sql .=
" vat_reverse_charge = ".($this->vat_reverse_charge !=
'' ? ((int) $this->db->escape($this->vat_reverse_charge)) : 0).
",";
1282 $sql .=
" fk_projet=".(!empty($this->fk_project) ? ((int) $this->fk_project) :
"null").
",";
1283 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? ((int) $this->mode_reglement_id) :
"null").
",";
1284 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? ((int) $this->cond_reglement_id) :
"null").
",";
1285 $sql .=
" date_lim_reglement=".(dol_strlen($this->date_echeance) != 0 ?
"'".$this->db->idate($this->date_echeance).
"'" :
'null').
",";
1286 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1287 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1288 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1289 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1290 $sql .=
" WHERE rowid=".((int) $this->
id);
1294 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1295 $resql = $this->db->query($sql);
1300 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1301 $this->errors[] = $langs->trans(
'ErrorRefAlreadyExists');
1303 $this->errors[] =
"Error ".$this->db->lasterror();
1317 $result = $this->
call_trigger(
'BILL_SUPPLIER_MODIFY', $user);
1327 foreach ($this->errors as $errmsg) {
1328 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1329 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1331 $this->db->rollback();
1334 $this->db->commit();
1349 global $conf, $langs;
1351 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1352 include_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1357 $result =
$remise->fetch($idremise);
1360 if (
$remise->fk_invoice_supplier) {
1361 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed");
1362 $this->db->rollback();
1367 $facligne->fk_facture_fourn = $this->id;
1368 $facligne->fk_remise_except =
$remise->id;
1369 $facligne->desc =
$remise->description;
1370 $facligne->vat_src_code =
$remise->vat_src_code;
1371 $facligne->tva_tx =
$remise->tva_tx;
1372 $facligne->subprice = -
$remise->amount_ht;
1373 $facligne->fk_product = 0;
1374 $facligne->product_type = 0;
1376 $facligne->remise_percent = 0;
1377 $facligne->rang = -1;
1378 $facligne->info_bits = 2;
1380 if (!empty($conf->global->MAIN_ADD_LINE_AT_POSITION)) {
1381 $facligne->rang = 1;
1382 $linecount = count($this->lines);
1383 for ($ii = 1; $ii <= $linecount; $ii++) {
1389 if (
$remise->fk_invoice_supplier_source > 0) {
1391 $srcinvoice->fetch(
$remise->fk_invoice_supplier_source);
1392 $totalcostpriceofinvoice = 0;
1393 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
1395 $arraytmp = $formmargin->getMarginInfosArray($srcinvoice,
false);
1396 $facligne->pa_ht = $arraytmp[
'pa_total'];
1399 $facligne->total_ht = -
$remise->amount_ht;
1400 $facligne->total_tva = -
$remise->amount_tva;
1401 $facligne->total_ttc = -
$remise->amount_ttc;
1403 $facligne->multicurrency_subprice = -
$remise->multicurrency_subprice;
1404 $facligne->multicurrency_total_ht = -
$remise->multicurrency_total_ht;
1405 $facligne->multicurrency_total_tva = -
$remise->multicurrency_total_tva;
1406 $facligne->multicurrency_total_ttc = -
$remise->multicurrency_total_ttc;
1408 $lineid = $facligne->insert();
1413 $result =
$remise->link_to_invoice($lineid, 0);
1415 $this->error =
$remise->error;
1416 $this->db->rollback();
1420 $this->db->commit();
1423 $this->error = $facligne->error;
1424 $this->db->rollback();
1428 $this->error = $facligne->error;
1429 $this->db->rollback();
1433 $this->db->rollback();
1446 public function delete(
User $user, $notrigger = 0)
1448 global $langs, $conf;
1452 dol_syslog(
"FactureFournisseur::delete rowid=".$rowid, LOG_DEBUG);
1459 if (!$error && !$notrigger) {
1461 $result = $this->
call_trigger(
'BILL_SUPPLIER_DELETE', $user);
1463 $this->db->rollback();
1471 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_remise_except';
1472 $sql .=
' WHERE fk_invoice_supplier_source = '.((int) $rowid);
1473 $sql .=
' AND fk_invoice_supplier_line IS NULL';
1474 $resql = $this->db->query($sql);
1478 $list_rowid_det = array();
1479 foreach ($this->lines as $key => $invoiceline) {
1480 $list_rowid_det[] = $invoiceline->rowid;
1484 if (count($list_rowid_det)) {
1485 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe_remise_except';
1486 $sql .=
' SET fk_invoice_supplier = NULL, fk_invoice_supplier_line = NULL';
1487 $sql .=
' WHERE fk_invoice_supplier_line IN ('.$this->db->sanitize(join(
',', $list_rowid_det)).
')';
1489 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1490 if (!$this->db->query($sql)) {
1497 $main = MAIN_DB_PREFIX.
'facture_fourn_det';
1498 $ef = $main.
"_extrafields";
1499 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_facture_fourn = ".((int) $rowid).
")";
1500 $resqlef = $this->db->query($sqlef);
1501 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'facture_fourn_det WHERE fk_facture_fourn = '.((int) $rowid);
1502 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1503 $resql = $this->db->query($sql);
1504 if ($resqlef && $resql) {
1505 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'facture_fourn WHERE rowid = '.((int) $rowid);
1506 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1507 $resql2 = $this->db->query($sql);
1529 if ($conf->fournisseur->facture->dir_output) {
1530 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1533 $dir = $conf->fournisseur->facture->dir_output.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$ref;
1534 $file = $dir.
"/".$ref.
".pdf";
1535 if (file_exists($file)) {
1537 $this->error =
'ErrorFailToDeleteFile';
1541 if (file_exists($dir)) {
1545 $this->error =
'ErrorFailToDeleteDir';
1557 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
1562 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
1563 $this->db->commit();
1566 $this->error = $this->db->lasterror();
1567 $this->db->rollback();
1584 public function set_paid($user, $close_code =
'', $close_note =
'')
1587 dol_syslog(get_class($this).
"::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
1588 return $this->
setPaid($user, $close_code, $close_note);
1599 public function setPaid($user, $close_code =
'', $close_note =
'')
1603 if ($this->paye != 1) {
1608 dol_syslog(
"FactureFournisseur::set_paid", LOG_DEBUG);
1610 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture_fourn SET';
1611 $sql .=
' fk_statut = '.self::STATUS_CLOSED;
1616 $sql .=
", close_code='".$this->db->escape($close_code).
"'";
1619 $sql .=
", close_note='".$this->db->escape($close_note).
"'";
1621 $sql .=
', fk_user_closing = '.((int) $user->id);
1622 $sql .=
", date_closing = '".$this->db->idate($now).
"'";
1623 $sql .=
' WHERE rowid = '.((int) $this->
id);
1625 $resql = $this->db->query($sql);
1628 $result = $this->
call_trigger(
'BILL_SUPPLIER_PAYED', $user);
1635 $this->error = $this->db->error();
1640 $this->db->commit();
1643 $this->db->rollback();
1665 dol_syslog(get_class($this).
"::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE);
1683 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture_fourn';
1684 $sql .=
' SET paye=0, fk_statut='.self::STATUS_VALIDATED.
', close_code=null, close_note=null,';
1685 $sql .=
' date_closing=null,';
1686 $sql .=
' fk_user_closing=null';
1687 $sql .=
' WHERE rowid = '.((int) $this->
id);
1689 dol_syslog(get_class($this).
"::set_unpaid", LOG_DEBUG);
1690 $resql = $this->db->query($sql);
1693 $result = $this->
call_trigger(
'BILL_SUPPLIER_UNPAYED', $user);
1700 $this->error = $this->db->error();
1705 $this->db->commit();
1708 $this->db->rollback();
1723 public function setCanceled($user, $close_code =
'', $close_note =
'')
1725 dol_syslog(get_class($this).
"::setCanceled rowid=".((
int) $this->
id), LOG_DEBUG);
1729 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture_fourn SET';
1730 $sql .=
' fk_statut='.self::STATUS_ABANDONED;
1732 $sql .=
", close_code='".$this->db->escape($close_code).
"'";
1735 $sql .=
", close_note='".$this->db->escape($close_note).
"'";
1737 $sql .=
" WHERE rowid = ".((int) $this->
id);
1739 $resql = $this->db->query($sql);
1743 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe_remise_except';
1744 $sql .=
' SET fk_invoice_supplier = NULL';
1745 $sql .=
' WHERE fk_invoice_supplier = '.((int) $this->
id);
1747 $resql = $this->db->query($sql);
1750 $result = $this->
call_trigger(
'BILL_SUPPLIER_CANCEL', $user);
1752 $this->db->rollback();
1757 $this->db->commit();
1760 $this->error = $this->db->error().
" sql=".$sql;
1761 $this->db->rollback();
1765 $this->error = $this->db->error().
" sql=".$sql;
1766 $this->db->rollback();
1780 public function validate($user, $force_number =
'', $idwarehouse = 0, $notrigger = 0)
1782 global $conf, $langs;
1784 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1789 dol_syslog(get_class($this).
'::validate user='.$user->id.
', force_number='.$force_number.
', idwarehouse='.$idwarehouse);
1796 if ($this->
statut > self::STATUS_DRAFT) {
1797 dol_syslog(get_class($this).
"::validate no draft status", LOG_WARNING);
1800 if (preg_match(
'/^'.preg_quote($langs->trans(
"CopyOf").
' ').
'/', $this->ref_supplier)) {
1801 $langs->load(
"errors");
1802 $this->error = $langs->trans(
"ErrorFieldFormat", $langs->transnoentities(
"RefSupplier")).
'. '.$langs->trans(
'RemoveString', $langs->transnoentitiesnoconv(
"CopyOf"));
1805 if (count($this->lines) <= 0) {
1806 $langs->load(
"errors");
1807 $this->error = $langs->trans(
"ErrorObjectMustHaveLinesToBeValidated", $this->
ref);
1814 if ($force_number) {
1815 $num = $force_number;
1816 } elseif (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1823 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn";
1824 $sql .=
" SET ref='".$this->db->escape($num).
"', fk_statut = 1, fk_user_valid = ".((int) $user->id).
", date_valid = '".$this->db->idate($now).
"'";
1825 $sql .=
" WHERE rowid = ".((int) $this->
id);
1827 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
1828 $resql = $this->db->query($sql);
1831 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) {
1832 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1833 $langs->load(
"agenda");
1835 $cpt = count($this->lines);
1836 for ($i = 0; $i < $cpt; $i++) {
1837 if ($this->lines[$i]->fk_product > 0) {
1839 $mouvP->origin = &$this;
1840 $mouvP->setOrigin($this->element, $this->
id);
1842 $up_ht_disc = $this->lines[$i]->subprice;
1843 if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) {
1844 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1847 $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"InvoiceValidatedInDolibarr", $num));
1849 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"InvoiceValidatedInDolibarr", $num));
1859 if (!$error && empty($notrigger)) {
1861 $result = $this->
call_trigger(
'BILL_SUPPLIER_VALIDATE', $user);
1869 $this->oldref = $this->ref;
1872 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1874 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'fournisseur/facture/".
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$this->db->escape($this->newref).
"'";
1875 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'fournisseur/facture/".
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1876 $resql = $this->db->query($sql);
1878 $error++; $this->error = $this->db->lasterror();
1880 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'fournisseur/facture/".
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$this->db->escape($this->newref).
"'";
1881 $sql .=
" WHERE filepath = 'fournisseur/facture/".get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1882 $resql = $this->db->query($sql);
1884 $error++; $this->error = $this->db->lasterror();
1889 $dirsource = $conf->fournisseur->facture->dir_output.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$oldref;
1890 $dirdest = $conf->fournisseur->facture->dir_output.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$this->newref;
1891 if (!$error && file_exists($dirsource)) {
1892 dol_syslog(get_class($this).
"::validate rename dir ".$dirsource.
" into ".$dirdest);
1894 if (@rename($dirsource, $dirdest)) {
1897 $listoffiles =
dol_dir_list($conf->fournisseur->facture->dir_output.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$this->newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1898 foreach ($listoffiles as $fileentry) {
1899 $dirsource = $fileentry[
'name'];
1900 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $this->newref, $dirsource);
1901 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1902 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1903 @rename($dirsource, $dirdest);
1912 $this->
ref = $this->newref;
1918 $this->db->commit();
1921 $this->db->rollback();
1925 $this->error = $this->db->error();
1926 $this->db->rollback();
1941 global $conf, $langs;
1945 if ($this->
statut == self::STATUS_DRAFT) {
1946 dol_syslog(__METHOD__.
" already draft status", LOG_WARNING);
1954 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn";
1955 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1956 $sql .=
" WHERE rowid = ".((int) $this->
id);
1958 $result = $this->db->query($sql);
1961 $this->oldcopy = clone $this;
1965 if ($result >= 0 && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) {
1966 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1967 $langs->load(
"agenda");
1969 $cpt = count($this->lines);
1970 for ($i = 0; $i < $cpt; $i++) {
1971 if ($this->lines[$i]->fk_product > 0) {
1973 $mouvP->origin = &$this;
1974 $mouvP->setOrigin($this->element, $this->
id);
1977 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans(
"InvoiceBackToDraftInDolibarr", $this->ref));
1979 $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans(
"InvoiceBackToDraftInDolibarr", $this->ref));
1985 if (!$error && empty($notrigger)) {
1987 $result = $this->
call_trigger(
'BILL_SUPPLIER_UNVALIDATE', $user);
1994 $this->db->commit();
1997 $this->db->rollback();
2001 $this->error = $this->db->error();
2002 $this->db->rollback();
2041 public function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product = 0, $remise_percent = 0, $date_start =
'', $date_end =
'', $ventil = 0, $info_bits =
'', $price_base_type =
'HT', $type = 0, $rang = -1, $notrigger =
false, $array_options = 0, $fk_unit =
null, $origin_id = 0, $pu_devise = 0, $ref_supplier =
'', $special_code =
'', $fk_parent_line = 0, $fk_remise_except = 0)
2043 global $langs, $mysoc, $conf;
2045 dol_syslog(get_class($this).
"::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type,$fk_unit,fk_remise_except=$fk_remise_except", LOG_DEBUG);
2046 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2048 if ($this->
statut == self::STATUS_DRAFT) {
2050 if (empty($remise_percent)) {
2051 $remise_percent = 0;
2056 if (empty($info_bits)) {
2062 if (empty($ventil)) {
2065 if (empty($txtva)) {
2068 if (empty($txlocaltax1)) {
2071 if (empty($txlocaltax2)) {
2075 $remise_percent =
price2num($remise_percent);
2078 if (!preg_match(
'/\((.*)\)/', $txtva)) {
2084 if ($date_start && $date_end && $date_start > $date_end) {
2085 $langs->load(
"errors");
2086 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2092 if ($fk_product > 0) {
2093 if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
2095 dol_syslog(get_class($this).
"::addline we check supplier prices fk_product=".$fk_product.
" qty=".$qty.
" ref_supplier=".$ref_supplier);
2097 if ($prod->fetch($fk_product) > 0) {
2098 $product_type = $prod->type;
2099 $label = $prod->label;
2100 $fk_prod_fourn_price = 0;
2104 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', ($this->fk_soc ? $this->fk_soc : $this->socid));
2107 $pu = $prod->fourn_pu;
2109 $ref_supplier = $prod->ref_supplier;
2111 if ($remise_percent == 0 && $prod->remise_percent != 0) {
2112 $remise_percent = $prod->remise_percent;
2116 $langs->load(
"errors");
2117 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2118 $this->db->rollback();
2119 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
2124 if ($result == -1) {
2125 $langs->load(
"errors");
2126 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2127 $this->db->rollback();
2128 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
2132 $this->error = $prod->error;
2133 $this->db->rollback();
2134 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
2138 $this->error = $prod->error;
2139 $this->db->rollback();
2144 $product_type = $type;
2147 if (isModEnabled(
"multicurrency") && $pu_devise > 0) {
2156 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2157 $vat_src_code = $reg[1];
2158 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2166 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_devise);
2167 $total_ht = $tabprice[0];
2168 $total_tva = $tabprice[1];
2169 $total_ttc = $tabprice[2];
2170 $total_localtax1 = $tabprice[9];
2171 $total_localtax2 = $tabprice[10];
2172 $pu_ht = $tabprice[3];
2175 $multicurrency_total_ht = $tabprice[16];
2176 $multicurrency_total_tva = $tabprice[17];
2177 $multicurrency_total_ttc = $tabprice[18];
2178 $pu_ht_devise = $tabprice[19];
2187 $rang = $rangmax + 1;
2193 $supplierinvoiceline->context = $this->context;
2195 $supplierinvoiceline->fk_facture_fourn = $this->id;
2197 $supplierinvoiceline->desc = $desc;
2198 $supplierinvoiceline->ref_supplier = $ref_supplier;
2200 $supplierinvoiceline->qty = ($this->
type == self::TYPE_CREDIT_NOTE ? abs($qty) : $qty);
2201 $supplierinvoiceline->subprice = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs($pu_ht) : $pu_ht);
2203 $supplierinvoiceline->vat_src_code = $vat_src_code;
2204 $supplierinvoiceline->tva_tx = $txtva;
2205 $supplierinvoiceline->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2206 $supplierinvoiceline->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2207 $supplierinvoiceline->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2208 $supplierinvoiceline->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2210 $supplierinvoiceline->total_ht = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($total_ht) : $total_ht);
2211 $supplierinvoiceline->total_tva = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($total_tva) : $total_tva);
2212 $supplierinvoiceline->total_localtax1 = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($total_localtax1) : $total_localtax1);
2213 $supplierinvoiceline->total_localtax2 = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($total_localtax2) : $total_localtax2);
2214 $supplierinvoiceline->total_ttc = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($total_ttc) : $total_ttc);
2216 $supplierinvoiceline->fk_product = $fk_product;
2217 $supplierinvoiceline->product_type = $type;
2218 $supplierinvoiceline->remise_percent = $remise_percent;
2219 $supplierinvoiceline->date_start = $date_start;
2220 $supplierinvoiceline->date_end = $date_end;
2221 $supplierinvoiceline->fk_code_ventilation = $ventil;
2222 $supplierinvoiceline->rang = $rang;
2223 $supplierinvoiceline->info_bits = $info_bits;
2224 $supplierinvoiceline->fk_remise_except = $fk_remise_except;
2227 $supplierinvoiceline->special_code = ((string) $special_code !=
'' ? $special_code : $this->special_code);
2228 $supplierinvoiceline->fk_parent_line = $fk_parent_line;
2229 $supplierinvoiceline->origin = $this->origin;
2230 $supplierinvoiceline->origin_id = $origin_id;
2231 $supplierinvoiceline->fk_unit = $fk_unit;
2234 $supplierinvoiceline->fk_multicurrency = $this->fk_multicurrency;
2235 $supplierinvoiceline->multicurrency_code = $this->multicurrency_code;
2236 $supplierinvoiceline->multicurrency_subprice = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs($pu_ht_devise) : $pu_ht_devise);
2238 $supplierinvoiceline->multicurrency_total_ht = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($multicurrency_total_ht) : $multicurrency_total_ht);
2239 $supplierinvoiceline->multicurrency_total_tva = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($multicurrency_total_tva) : $multicurrency_total_tva);
2240 $supplierinvoiceline->multicurrency_total_ttc = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($multicurrency_total_ttc) : $multicurrency_total_ttc);
2242 if (is_array($array_options) && count($array_options) > 0) {
2243 $supplierinvoiceline->array_options = $array_options;
2246 $result = $supplierinvoiceline->insert($notrigger);
2249 if (!empty($fk_parent_line)) {
2251 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2252 $linecount = count($this->lines);
2253 for ($ii = $rang; $ii <= $linecount; $ii++) {
2259 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2261 $this->db->commit();
2262 return $supplierinvoiceline->id;
2264 $this->error = $this->db->error();
2265 $this->db->rollback();
2269 $this->error = $supplierinvoiceline->error;
2270 $this->errors = $supplierinvoiceline->errors;
2271 $this->db->rollback();
2304 public function updateline($id, $desc, $pu, $vatrate, $txlocaltax1 = 0, $txlocaltax2 = 0, $qty = 1, $idproduct = 0, $price_base_type =
'HT', $info_bits = 0, $type = 0, $remise_percent = 0, $notrigger =
false, $date_start =
'', $date_end =
'', $array_options = 0, $fk_unit =
null, $pu_devise = 0, $ref_supplier =
'', $rang = 0)
2306 global $mysoc, $langs;
2308 dol_syslog(get_class($this).
"::updateline $id,$desc,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent,$notrigger,$date_start,$date_end,$fk_unit,$pu_devise,$ref_supplier", LOG_DEBUG);
2309 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2313 $remise_percent =
price2num($remise_percent);
2322 if ($date_start && $date_end && $date_start > $date_end) {
2323 $langs->load(
"errors");
2324 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2329 if (empty($vatrate)) {
2332 if (empty($txlocaltax1)) {
2335 if (empty($txlocaltax2)) {
2353 if (preg_match(
'/\((.*)\)/', $vatrate, $reg)) {
2354 $vat_src_code = $reg[1];
2355 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2358 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_devise);
2359 $total_ht = $tabprice[0];
2360 $total_tva = $tabprice[1];
2361 $total_ttc = $tabprice[2];
2362 $pu_ht = $tabprice[3];
2363 $pu_tva = $tabprice[4];
2364 $pu_ttc = $tabprice[5];
2365 $total_localtax1 = $tabprice[9];
2366 $total_localtax2 = $tabprice[10];
2369 $multicurrency_total_ht = $tabprice[16];
2370 $multicurrency_total_tva = $tabprice[17];
2371 $multicurrency_total_ttc = $tabprice[18];
2372 $pu_ht_devise = $tabprice[19];
2374 if (empty($info_bits)) {
2381 $line->fetch_optionals();
2383 $staticline = clone $line;
2386 $product =
new Product($this->db);
2387 $result = $product->fetch($idproduct);
2388 $product_type = $product->type;
2390 $idproduct = $staticline->fk_product;
2391 $product_type = $type;
2394 $line->oldline = $staticline;
2395 $line->context = $this->context;
2397 $line->description = $desc;
2399 $line->qty = ($this->
type == self::TYPE_CREDIT_NOTE ? abs($qty) : $qty);
2400 $line->subprice = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs($pu_ht) : $pu_ht);
2401 $line->pu_ht = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs($pu_ht) : $pu_ht);
2402 $line->pu_ttc = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs($pu_ttc) : $pu_ttc);
2404 $line->remise_percent = $remise_percent;
2405 $line->ref_supplier = $ref_supplier;
2407 $line->date_start = $date_start;
2408 $line->date_end = $date_end;
2410 $line->vat_src_code = $vat_src_code;
2411 $line->tva_tx = $vatrate;
2412 $line->localtax1_tx = $txlocaltax1;
2413 $line->localtax2_tx = $txlocaltax2;
2414 $line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2415 $line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2417 $line->total_ht = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ?-abs($total_ht) : $total_ht);
2418 $line->total_tva = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ?-abs($total_tva) : $total_tva);
2419 $line->total_localtax1 = $total_localtax1;
2420 $line->total_localtax2 = $total_localtax2;
2421 $line->total_ttc = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ?-abs($total_ttc) : $total_ttc);
2423 $line->fk_product = $idproduct;
2424 $line->product_type = $product_type;
2425 $line->info_bits = $info_bits;
2426 $line->fk_unit = $fk_unit;
2427 $line->rang = $rang;
2429 if (is_array($array_options) && count($array_options) > 0) {
2431 foreach ($array_options as $key => $value) {
2432 $line->array_options[$key] = $array_options[$key];
2437 $line->multicurrency_subprice = $pu_ht_devise;
2438 $line->multicurrency_total_ht = $multicurrency_total_ht;
2439 $line->multicurrency_total_tva = $multicurrency_total_tva;
2440 $line->multicurrency_total_ttc = $multicurrency_total_ttc;
2442 $res = $line->update($notrigger);
2445 $this->errors[] = $line->error;
2446 $this->errors = array_merge($this->errors, $line->errors);
2449 $res = $this->
update_price(
'1',
'auto', 0, $this->thirdparty);
2471 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe_remise_except';
2472 $sql .=
' SET fk_invoice_supplier_line = NULL';
2473 $sql .=
' WHERE fk_invoice_supplier_line = '.((int) $rowid);
2475 dol_syslog(get_class($this).
"::deleteline", LOG_DEBUG);
2476 $result = $this->db->query($sql);
2478 $this->error = $this->db->error();
2479 $this->db->rollback();
2485 if ($line->fetch($rowid) < 1) {
2489 $res = $line->delete($notrigger);
2492 $this->errors[] = $line->error;
2493 $this->db->rollback();
2499 $this->db->commit();
2502 $this->db->rollback();
2503 $this->error = $this->db->lasterror();
2518 $sql =
'SELECT c.rowid, datec, tms as datem, ';
2519 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid';
2520 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn as c';
2521 $sql .=
' WHERE c.rowid = '.((int) $id);
2523 $result = $this->db->query($sql);
2525 if ($this->db->num_rows($result)) {
2526 $obj = $this->db->fetch_object($result);
2528 $this->
id = $obj->rowid;
2529 if ($obj->fk_user_author) {
2530 $cuser =
new User($this->db);
2531 $cuser->fetch($obj->fk_user_author);
2532 $this->user_creation = $cuser;
2534 if ($obj->fk_user_valid) {
2535 $vuser =
new User($this->db);
2536 $vuser->fetch($obj->fk_user_valid);
2537 $this->user_validation = $vuser;
2539 if ($obj->fk_user_modif) {
2540 $muser =
new User($this->db);
2541 $muser->fetch($obj->fk_user_modif);
2542 $this->user_modification = $muser;
2544 $this->date_creation = $this->db->jdate($obj->datec);
2545 $this->date_modification = $this->db->jdate($obj->datem);
2548 $this->db->free($result);
2570 $sql =
"SELECT f.rowid as rowid, f.ref, f.fk_statut,";
2571 $sql .=
" ff.rowid as rowidnext";
2572 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
2573 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
2574 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON f.rowid = ff.fk_facture_source";
2575 $sql .=
" WHERE (f.fk_statut = ".self::STATUS_VALIDATED.
" OR (f.fk_statut = ".self::STATUS_ABANDONED.
" AND f.close_code = '".self::CLOSECODE_ABANDONED.
"'))";
2576 $sql .=
" AND f.entity = ".$conf->entity;
2577 $sql .=
" AND f.paye = 0";
2578 $sql .=
" AND pf.fk_paiementfourn IS NULL";
2579 $sql .=
" AND ff.fk_statut IS NULL";
2581 $sql .=
" AND f.fk_soc = ".((int) $socid);
2583 $sql .=
" ORDER BY f.ref";
2585 dol_syslog(get_class($this).
"::list_replacable_supplier_invoices", LOG_DEBUG);
2586 $resql = $this->db->query($sql);
2588 while ($obj = $this->db->fetch_object($resql)) {
2589 $return[$obj->rowid] = array(
2590 'id' => $obj->rowid,
2592 'status' => $obj->fk_statut
2598 $this->error = $this->db->error();
2620 $sql =
"SELECT f.rowid as rowid, f.ref, f.fk_statut, f.type, f.paye, pf.fk_paiementfourn";
2621 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
2622 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
2623 $sql .=
" WHERE f.entity = ".$conf->entity;
2624 $sql .=
" AND f.fk_statut in (".self::STATUS_VALIDATED.
",".self::STATUS_CLOSED.
")";
2625 $sql .=
" AND NOT EXISTS (SELECT rowid from ".MAIN_DB_PREFIX.
"facture_fourn as ff WHERE f.rowid = ff.fk_facture_source";
2626 $sql .=
" AND ff.type=".self::TYPE_REPLACEMENT.
")";
2627 $sql .=
" AND f.type != ".self::TYPE_CREDIT_NOTE;
2629 $sql .=
" AND f.fk_soc = ".((int) $socid);
2631 $sql .=
" ORDER BY f.ref";
2633 dol_syslog(get_class($this).
"::list_qualified_avoir_supplier_invoices", LOG_DEBUG);
2634 $resql = $this->db->query($sql);
2636 while ($obj = $this->db->fetch_object($resql)) {
2638 if ($obj->fk_statut == self::STATUS_VALIDATED) {
2641 if ($obj->fk_statut == self::STATUS_CLOSED) {
2645 $paymentornot = ($obj->fk_paiementfourn ? 1 : 0);
2646 $return[$obj->rowid] = array(
'ref'=>$obj->ref,
'status'=>$obj->fk_statut,
'type'=>$obj->type,
'paye'=>$obj->paye,
'paymentornot'=>$paymentornot);
2652 $this->error = $this->db->error();
2667 global $conf, $langs;
2669 $sql =
'SELECT ff.rowid, ff.date_lim_reglement as datefin, ff.fk_statut as status, ff.total_ht, ff.total_ttc';
2670 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn as ff';
2671 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
2672 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON ff.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2674 $sql .=
' WHERE ff.paye = 0';
2675 $sql .=
' AND ff.fk_statut > 0';
2676 $sql .=
" AND ff.entity = ".$conf->entity;
2678 $sql .=
' AND ff.fk_soc = '.((int) $user->socid);
2681 $resql = $this->db->query($sql);
2683 $langs->load(
"bills");
2687 $response->warning_delay = $conf->facture->fournisseur->warning_delay / 60 / 60 / 24;
2688 $response->label = $langs->trans(
"SupplierBillsToPay");
2689 $response->labelShort = $langs->trans(
"StatusToPay");
2691 $response->url = DOL_URL_ROOT.
'/fourn/facture/list.php?search_status=1&mainmenu=billing&leftmenu=suppliers_bills';
2692 $response->img =
img_object($langs->trans(
"Bills"),
"bill");
2696 while ($obj = $this->db->fetch_object($resql)) {
2697 $facturestatic->date_echeance = $this->db->jdate($obj->datefin);
2698 $facturestatic->statut = $obj->status;
2699 $facturestatic->status = $obj->status;
2701 $response->nbtodo++;
2702 $response->total += $obj->total_ht;
2704 if ($facturestatic->hasDelay()) {
2705 $response->nbtodolate++;
2706 $response->url_late = DOL_URL_ROOT.
'/fourn/facture/list.php?search_option=late&mainmenu=billing&leftmenu=suppliers_bills';
2710 $this->db->free($resql);
2714 $this->error = $this->db->error();
2728 global $conf, $langs;
2730 $langs->load(
'bills');
2733 $moretitle = $params[
'moretitle'] ??
'';
2734 $picto = $this->picto;
2735 if ($this->
type == self::TYPE_REPLACEMENT) {
2738 if ($this->
type == self::TYPE_CREDIT_NOTE) {
2741 if ($this->
type == self::TYPE_DEPOSIT) {
2745 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"SupplierInvoice").
'</u>';
2746 if ($this->
type == self::TYPE_REPLACEMENT) {
2747 $datas[
'picto'] .=
'<u class="paddingrightonly">'.$langs->transnoentitiesnoconv(
"InvoiceReplace").
'</u>';
2748 } elseif ($this->
type == self::TYPE_CREDIT_NOTE) {
2749 $datas[
'picto'] .=
'<u class="paddingrightonly">'.$langs->transnoentitiesnoconv(
"CreditNote").
'</u>';
2750 } elseif ($this->
type == self::TYPE_DEPOSIT) {
2751 $datas[
'picto'] .=
'<u class="paddingrightonly">'.$langs->transnoentitiesnoconv(
"Deposit").
'</u>';
2753 if (isset($this->status)) {
2755 if (isset($this->alreadypaid)) {
2756 $alreadypaid = $this->alreadypaid;
2759 $datas[
'picto'] .=
' '.$this->getLibStatut(5, $alreadypaid);
2762 $datas[
'picto'] .=
' - '.$moretitle;
2764 if (!empty($this->
ref)) {
2765 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
2767 if (!empty($this->ref_supplier)) {
2768 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
2770 if (!empty($this->label)) {
2771 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
2773 if (!empty($this->date)) {
2774 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
2776 if (!empty($this->date_echeance)) {
2777 $datas[
'date_echeance'] =
'<br><b>'.$langs->trans(
'DateDue').
':</b> '.
dol_print_date($this->date_echeance,
'day');
2779 if (!empty($this->total_ht)) {
2780 $datas[
'amountht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
2782 if (!empty($this->total_tva)) {
2783 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'AmountVAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
2785 if (!empty($this->total_localtax1) && $this->total_localtax1 != 0) {
2787 $datas[
'amountlt1'] =
'<br><b>'.$langs->transcountry(
'AmountLT1', $mysoc->country_code).
':</b> '.
price($this->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency);
2789 if (!empty($this->total_localtax2) && $this->total_localtax2 != 0) {
2790 $datas[
'amountlt2'] =
'<br><b>'.$langs->transcountry(
'AmountLT2', $mysoc->country_code).
':</b> '.
price($this->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency);
2792 if (!empty($this->revenuestamp)) {
2793 $datas[
'amountrevenustamp'] =
'<br><b>'.$langs->trans(
'RevenueStamp').
':</b> '.
price($this->revenuestamp, 0, $langs, 0, -1, -1, $conf->currency);
2795 if (!empty($this->total_ttc)) {
2796 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
2814 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
2816 global $langs, $conf, $user, $hookmanager;
2820 if ($option ==
'withdraw') {
2821 $url = DOL_URL_ROOT.
'/compta/facture/prelevement.php?facid='.$this->
id.
'&type=bank-transfer';
2822 } elseif ($option ==
'document') {
2823 $url = DOL_URL_ROOT.
'/fourn/facture/document.php?facid='.$this->id;
2825 $url = DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$this->id;
2832 if ($option !==
'nolink') {
2834 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2835 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2836 $add_save_lastsearch_values = 1;
2838 if ($add_save_lastsearch_values) {
2839 $url .=
'&save_lastsearch_values=1';
2843 $picto = $this->picto;
2844 if ($this->
type == self::TYPE_REPLACEMENT) {
2847 if ($this->
type == self::TYPE_CREDIT_NOTE) {
2850 if ($this->
type == self::TYPE_DEPOSIT) {
2855 'objecttype' => $this->element,
2856 'option' => $option,
2857 'moretitle' => $moretitle,
2859 $classfortooltip =
'classfortooltip';
2862 $classfortooltip =
'classforajaxtooltip';
2863 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2875 if (empty($notooltip)) {
2876 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2877 $label = $langs->trans(
"ShowSupplierInvoice");
2878 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2880 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
2881 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
2884 $linkstart =
'<a href="'.$url.
'"';
2885 $linkstart .= $linkclose.
'>';
2888 $result .= $linkstart;
2890 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
2892 if ($withpicto != 2) {
2893 $result .= ($max ?
dol_trunc($ref, $max) : $ref);
2895 $result .= $linkend;
2897 if ($addlinktonotes) {
2898 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
2901 $result .=
' <span class="note inline-block">';
2902 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
2905 $result .=
'</span>';
2909 $hookmanager->initHooks(array($this->element .
'dao'));
2910 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
2911 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2913 $result = $hookmanager->resPrint;
2915 $result .= $hookmanager->resPrint;
2930 global $db, $langs, $conf;
2931 $langs->load(
"orders");
2934 if (empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER)) {
2935 $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER =
'mod_facture_fournisseur_cactus';
2940 $file = $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER.
".php";
2941 $classname = $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER;
2944 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
2946 foreach ($dirmodels as $reldir) {
2947 $dir =
dol_buildpath($reldir.
"core/modules/supplier_invoice/");
2950 $mybool |= @include_once $dir.$file;
2953 if ($mybool ===
false) {
2958 $obj =
new $classname();
2960 $numref = $obj->getNumRef($soc, $this, $mode);
2962 if ($numref !=
"") {
2965 $this->error = $obj->error;
2981 global $langs, $conf;
2982 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
2990 $sql =
"SELECT rowid";
2991 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
2992 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
2993 $sql .= $this->db->plimit(100);
2995 $resql = $this->db->query($sql);
2997 $num_prods = $this->db->num_rows($resql);
2999 while ($i < $num_prods) {
3001 $row = $this->db->fetch_row($resql);
3002 $prodids[$i] = $row[0];
3008 $this->
ref =
'SPECIMEN';
3009 $this->ref_supplier =
'SUPPLIER_REF_SPECIMEN';
3010 $this->specimen = 1;
3013 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3014 $this->cond_reglement_code =
'RECEP';
3015 $this->mode_reglement_code =
'CHQ';
3017 $this->note_public =
'This is a comment (public)';
3018 $this->note_private =
'This is a comment (private)';
3020 $this->multicurrency_tx = 1;
3021 $this->multicurrency_code = $conf->currency;
3024 if (empty($option) || $option !=
'nolines') {
3027 while ($xnbp < $nbp) {
3029 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3031 $line->subprice = 100;
3034 $line->tva_tx = 19.6;
3035 $line->localtax1_tx = 0;
3036 $line->localtax2_tx = 0;
3038 $line->total_ht = 50;
3039 $line->total_ttc = 59.8;
3040 $line->total_tva = 9.8;
3041 $line->remise_percent = 50;
3043 $line->total_ht = 100;
3044 $line->total_ttc = 119.6;
3045 $line->total_tva = 19.6;
3046 $line->remise_percent = 0;
3049 if ($num_prods > 0) {
3050 $prodid = mt_rand(1, $num_prods);
3051 $line->fk_product = $prodids[$prodid];
3053 $line->product_type = 0;
3055 $this->lines[$xnbp] = $line;
3057 $this->total_ht += $line->total_ht;
3058 $this->total_tva += $line->total_tva;
3059 $this->total_ttc += $line->total_ttc;
3065 $this->amount_ht = $xnbp * 100;
3066 $this->total_ht = $xnbp * 100;
3067 $this->total_tva = $xnbp * 19.6;
3068 $this->total_ttc = $xnbp * 119.6;
3080 global $conf, $user;
3082 $this->nb = array();
3086 $sql =
"SELECT count(f.rowid) as nb";
3087 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
3088 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON f.fk_soc = s.rowid";
3089 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3090 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3091 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3094 $sql .=
" ".$clause.
" f.entity = ".$conf->entity;
3096 $resql = $this->db->query($sql);
3098 while ($obj = $this->db->fetch_object($resql)) {
3099 $this->nb[
"supplier_invoices"] = $obj->nb;
3101 $this->db->free($resql);
3105 $this->error = $this->db->error();
3120 global $conf, $langs;
3129 $object->fetch($fromid);
3134 $object->fetch_thirdparty();
3137 $object->ref_supplier = (empty($this->ref_supplier) ? $langs->trans(
"CopyOf").
' '.$object->ref_supplier : $this->ref_supplier);
3138 $object->author = $user->id;
3139 $object->user_valid = 0;
3140 $object->fk_facture_source = 0;
3141 $object->date_creation =
'';
3142 $object->date_validation =
'';
3143 $object->date = (empty($this->date) ?
dol_now() : $this->date);
3144 $object->ref_client =
'';
3145 $object->close_code =
'';
3146 $object->close_note =
'';
3148 $object->note_private =
'';
3149 $object->note_public =
'';
3152 $object->date_echeance = $object->calculate_date_lim_reglement();
3155 foreach ($object->lines as $i => $line) {
3156 if (isset($object->lines[$i]->info_bits) && ($object->lines[$i]->info_bits & 0x02) == 0x02) {
3157 unset($object->lines[$i]);
3162 $object->context[
'createfromclone'] =
'createfromclone';
3163 $result = $object->create($user);
3167 $this->error = $object->error;
3168 $this->errors = $object->errors;
3175 unset($object->context[
'createfromclone']);
3179 $this->db->commit();
3182 $this->db->rollback();
3198 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3200 global $conf, $user, $langs;
3202 $langs->load(
"suppliers");
3203 $outputlangs->load(
"products");
3206 if (empty($modele)) {
3207 if (!empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF)) {
3208 $modele = $conf->global->INVOICE_SUPPLIER_ADDON_PDF;
3214 if (empty($modele)) {
3217 $modelpath =
"core/modules/supplier_invoice/doc/";
3219 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3231 return $user->hasRight(
"fournisseur",
"facture");
3279 if (!$this->date_echeance) {
3283 $status = isset($this->status) ? $this->status : $this->statut;
3285 return ($status == self::STATUS_VALIDATED) && ($this->date_echeance < ($now - $conf->facture->fournisseur->warning_delay));
3297 $sql =
"SELECT fk_invoice_supplier FROM ".MAIN_DB_PREFIX.
"societe_remise_except WHERE fk_invoice_supplier_source = ".((int) $this->
id);
3298 $resql = $this->db->query($sql);
3299 if (!empty($resql)) {
3300 $obj = $this->db->fetch_object($resql);
3301 if (!empty($obj->fk_invoice_supplier)) {
3319 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3321 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3322 $return .=
'<div class="info-box info-box-sm">';
3323 $return .=
'<span class="info-box-icon bg-infobox-action">';
3325 $return .=
'</span>';
3326 $return .=
'<div class="info-box-content">';
3327 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
3328 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3329 if (!empty($arraydata[
'thirdparty'])) {
3330 $return .=
'<br><span class="info-box-label">'.$arraydata[
'thirdparty'].
'</span>';
3332 if (property_exists($this,
'date')) {
3333 $return .=
'<br><span class="info-box-label">'.dol_print_date($this->date,
'day').
'</span>';
3335 if (property_exists($this,
'total_ht')) {
3336 $return .=
' <span class="info-box-label amount" title="'.dol_escape_htmltag($langs->trans(
"AmountHT")).
'">'.
price($this->total_ht);
3337 $return .=
' '.$langs->trans(
"HT");
3338 $return .=
'</span>';
3340 if (method_exists($this,
'getLibStatut')) {
3341 $alreadypaid = (empty($arraydata[
'alreadypaid']) ? 0 : $arraydata[
'alreadypaid']);
3342 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3, $alreadypaid).
'</div>';
3344 $return .=
'</div>';
3345 $return .=
'</div>';
3346 $return .=
'</div>';
3358 if (!$this->table_element) {
3359 dol_syslog(get_class($this).
"::setVATReverseCharge was called on objet with property table_element not defined", LOG_ERR);
3363 dol_syslog(get_class($this).
'::setVATReverseCharge('.$vatreversecharge.
')');
3365 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
3366 $sql .=
" SET vat_reverse_charge = ".((int) $vatreversecharge);
3367 $sql .=
" WHERE rowid=".((int) $this->
id);
3369 if ($this->db->query($sql)) {
3370 $this->vat_reverse_charge = ($vatreversecharge == 0) ? 0 : 1;
3373 dol_syslog(get_class($this).
'::setVATReverseCharge Error ', LOG_DEBUG);
3374 $this->error = $this->db->error();
3390 public $element =
'facture_fourn_det';
3395 public $table_element =
'facture_fourn_det';
3409 public $product_ref;
3416 public $ref_supplier;
3422 public $product_desc;
3449 public $fk_facture_fourn;
3462 public $description;
3467 public $skip_update_total;
3472 public $situation_percent;
3483 public $vat_src_code;
3495 public $localtax1_tx;
3501 public $localtax2_tx;
3513 public $remise_percent;
3543 public $total_localtax1;
3549 public $total_localtax2;
3560 public $product_type;
3566 public $product_label;
3580 public $fk_remise_except;
3585 public $fk_parent_line;
3587 public $special_code;
3598 public $localtax1_type;
3604 public $localtax2_type;
3610 public $fk_multicurrency;
3612 public $multicurrency_code;
3613 public $multicurrency_subprice;
3614 public $multicurrency_total_ht;
3615 public $multicurrency_total_tva;
3616 public $multicurrency_total_ttc;
3637 $sql =
'SELECT f.rowid, f.ref as ref_supplier, f.description, f.date_start, f.date_end, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx';
3638 $sql .=
', f.localtax1_type, f.localtax2_type, f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2, f.fk_remise_except';
3639 $sql .=
', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_facture_fourn, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line, f.fk_unit';
3640 $sql .=
', p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.description as product_desc';
3641 $sql .=
', f.multicurrency_subprice, f.multicurrency_total_ht, f.multicurrency_total_tva, multicurrency_total_ttc';
3642 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_det as f';
3643 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON f.fk_product = p.rowid';
3644 $sql .=
' WHERE f.rowid = '.((int) $rowid);
3645 $sql .=
' ORDER BY f.rang, f.rowid';
3647 $query = $this->db->query($sql);
3650 $this->errors[] = $this->db->error();
3654 if (!$this->db->num_rows($query)) {
3658 $obj = $this->db->fetch_object($query);
3660 $this->
id = $obj->rowid;
3661 $this->
rowid = $obj->rowid;
3662 $this->fk_facture_fourn = $obj->fk_facture_fourn;
3664 $this->date_start = $this->db->jdate($obj->date_start);
3665 $this->date_end = $this->db->jdate($obj->date_end);
3666 $this->product_ref = $obj->product_ref;
3667 $this->ref_supplier = $obj->ref_supplier;
3668 $this->product_desc = $obj->product_desc;
3670 $this->subprice = $obj->pu_ht;
3671 $this->pu_ht = $obj->pu_ht;
3672 $this->pu_ttc = $obj->pu_ttc;
3673 $this->tva_tx = $obj->tva_tx;
3674 $this->localtax1_tx = $obj->localtax1_tx;
3675 $this->localtax2_tx = $obj->localtax2_tx;
3676 $this->localtax1_type = $obj->localtax1_type;
3677 $this->localtax2_type = $obj->localtax2_type;
3679 $this->qty = $obj->qty;
3680 $this->remise_percent = $obj->remise_percent;
3681 $this->fk_remise_except = $obj->fk_remise_except;
3683 $this->total_ht = $obj->total_ht;
3684 $this->total_tva = $obj->total_tva;
3685 $this->total_localtax1 = $obj->total_localtax1;
3686 $this->total_localtax2 = $obj->total_localtax2;
3687 $this->total_ttc = $obj->total_ttc;
3688 $this->fk_product = $obj->fk_product;
3689 $this->product_type = $obj->product_type;
3690 $this->product_label = $obj->product_label;
3691 $this->info_bits = $obj->info_bits;
3692 $this->tva_npr = ($obj->info_bits & 1 == 1) ? 1 : 0;
3693 $this->fk_parent_line = $obj->fk_parent_line;
3694 $this->special_code = $obj->special_code;
3695 $this->rang = $obj->rang;
3696 $this->fk_unit = $obj->fk_unit;
3698 $this->multicurrency_subprice = $obj->multicurrency_subprice;
3699 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
3700 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
3701 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
3714 public function delete($notrigger = 0)
3716 global $user, $conf;
3718 dol_syslog(get_class($this).
"::deleteline rowid=".((
int) $this->
id), LOG_DEBUG);
3725 if ($this->
call_trigger(
'LINEBILL_SUPPLIER_DELETE', $user) < 0) {
3737 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
3743 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'facture_fourn_det ';
3744 $sql .=
" WHERE rowid = ".((int) $this->
id);
3745 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
3746 $resql = $this->db->query($sql);
3749 $this->error = $this->db->lasterror();
3754 $this->db->commit();
3757 $this->db->rollback();
3776 if (empty($this->qty)) {
3780 if ($this->product_type < 0) {
3785 if (empty($this->remise_percent)) {
3786 $this->remise_percent = 0;
3788 if (empty($this->tva_tx)) {
3791 if (empty($this->localtax1_tx)) {
3792 $this->localtax1_tx = 0;
3794 if (empty($this->localtax2_tx)) {
3795 $this->localtax2_tx = 0;
3798 if (empty($this->pa_ht)) {
3801 if (empty($this->multicurrency_subprice)) {
3802 $this->multicurrency_subprice = 0;
3804 if (empty($this->multicurrency_total_ht)) {
3805 $this->multicurrency_total_ht = 0;
3807 if (empty($this->multicurrency_total_tva)) {
3808 $this->multicurrency_total_tva = 0;
3810 if (empty($this->multicurrency_total_ttc)) {
3811 $this->multicurrency_total_ttc = 0;
3814 $fk_product = (int) $this->fk_product;
3815 $fk_unit = (int) $this->fk_unit;
3819 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn_det SET";
3820 $sql .=
" description = '".$this->db->escape($this->
description).
"'";
3821 $sql .=
", ref = '".$this->db->escape($this->ref_supplier ? $this->ref_supplier :
$this->ref).
"'";
3822 $sql .=
", date_start = ".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
3823 $sql .=
", date_end = ".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
3824 $sql .=
", pu_ht = ".price2num($this->pu_ht);
3825 $sql .=
", pu_ttc = ".price2num($this->pu_ttc);
3826 $sql .=
", qty = ".price2num($this->qty);
3827 $sql .=
", remise_percent = ".price2num($this->remise_percent);
3828 if ($this->fk_remise_except > 0) $sql .=
", fk_remise_except=".((int) $this->fk_remise_except);
3829 else $sql .=
", fk_remise_except=null";
3830 $sql .=
", vat_src_code = '".$this->db->escape(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
3831 $sql .=
", tva_tx = ".price2num($this->tva_tx);
3832 $sql .=
", localtax1_tx = ".price2num($this->localtax1_tx);
3833 $sql .=
", localtax2_tx = ".price2num($this->localtax2_tx);
3834 $sql .=
", localtax1_type = '".$this->db->escape($this->localtax1_type).
"'";
3835 $sql .=
", localtax2_type = '".$this->db->escape($this->localtax2_type).
"'";
3836 $sql .=
", total_ht = ".price2num($this->total_ht);
3837 $sql .=
", tva= ".price2num($this->total_tva);
3838 $sql .=
", total_localtax1= ".price2num($this->total_localtax1);
3839 $sql .=
", total_localtax2= ".price2num($this->total_localtax2);
3840 $sql .=
", total_ttc = ".price2num($this->total_ttc);
3841 $sql .=
", fk_product = ".($fk_product > 0 ? (int) $fk_product :
'null');
3842 $sql .=
", product_type = ".((int) $this->product_type);
3843 $sql .=
", info_bits = ".((int) $this->info_bits);
3844 $sql .=
", fk_unit = ".($fk_unit > 0 ? (int) $fk_unit :
'null');
3846 if (!empty($this->rang)) {
3847 $sql .=
", rang=".((int) $this->rang);
3851 $sql .=
" , multicurrency_subprice=".price2num($this->multicurrency_subprice);
3852 $sql .=
" , multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
3853 $sql .=
" , multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
3854 $sql .=
" , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
3856 $sql .=
" WHERE rowid = ".((int) $this->
id);
3858 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
3859 $resql = $this->db->query($sql);
3862 $this->db->rollback();
3863 $this->error = $this->db->lasterror();
3867 $this->
rowid = $this->id;
3877 if (!$error && !$notrigger) {
3878 global $langs, $user;
3881 if ($this->
call_trigger(
'LINEBILL_SUPPLIER_MODIFY', $user) < 0) {
3882 $this->db->rollback();
3889 $this->db->rollback();
3893 $this->db->commit();
3905 global $user, $conf, $langs;
3909 dol_syslog(get_class($this).
"::insert rang=".$this->rang, LOG_DEBUG);
3912 $this->desc = trim($this->desc);
3913 if (empty($this->tva_tx)) {
3916 if (empty($this->localtax1_tx)) {
3917 $this->localtax1_tx = 0;
3919 if (empty($this->localtax2_tx)) {
3920 $this->localtax2_tx = 0;
3922 if (empty($this->localtax1_type)) {
3923 $this->localtax1_type =
'0';
3925 if (empty($this->localtax2_type)) {
3926 $this->localtax2_type =
'0';
3928 if (empty($this->total_tva)) {
3929 $this->total_tva = 0;
3931 if (empty($this->total_localtax1)) {
3932 $this->total_localtax1 = 0;
3934 if (empty($this->total_localtax2)) {
3935 $this->total_localtax2 = 0;
3937 if (empty($this->rang)) {
3940 if (empty($this->remise_percent)) {
3941 $this->remise_percent = 0;
3943 if (empty($this->info_bits)) {
3944 $this->info_bits = 0;
3946 if (empty($this->subprice)) {
3947 $this->subprice = 0;
3949 if (empty($this->special_code)) {
3950 $this->special_code = 0;
3952 if (empty($this->fk_parent_line)) {
3953 $this->fk_parent_line = 0;
3955 if (!isset($this->situation_percent) || $this->situation_percent > 100 || (
string) $this->situation_percent ==
'') {
3956 $this->situation_percent = 100;
3959 if (empty($this->pa_ht)) {
3962 if (empty($this->multicurrency_subprice)) {
3963 $this->multicurrency_subprice = 0;
3965 if (empty($this->multicurrency_total_ht)) {
3966 $this->multicurrency_total_ht = 0;
3968 if (empty($this->multicurrency_total_tva)) {
3969 $this->multicurrency_total_tva = 0;
3971 if (empty($this->multicurrency_total_ttc)) {
3972 $this->multicurrency_total_ttc = 0;
3977 if ($this->product_type < 0) {
3978 $this->error =
'ErrorProductTypeMustBe0orMore';
3981 if (!empty($this->fk_product) && $this->fk_product > 0) {
3985 $this->error =
'ErrorProductIdDoesNotExists';
3993 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element;
3994 $sql .=
' (fk_facture_fourn, fk_parent_line, label, description, ref, qty,';
3995 $sql .=
' vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
3996 $sql .=
' fk_product, product_type, remise_percent, fk_remise_except, pu_ht, pu_ttc,';
3997 $sql .=
' date_start, date_end, fk_code_ventilation, rang, special_code,';
3998 $sql .=
' info_bits, total_ht, tva, total_ttc, total_localtax1, total_localtax2, fk_unit';
3999 $sql .=
', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
4001 $sql .=
" VALUES (".$this->fk_facture_fourn.
",";
4002 $sql .=
" ".($this->fk_parent_line > 0 ?
"'".$this->db->escape($this->fk_parent_line).
"'" :
"null").
",";
4003 $sql .=
" ".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
4004 $sql .=
" '".$this->db->escape($this->desc ? $this->desc : $this->description).
"',";
4005 $sql .=
" '".$this->db->escape($this->ref_supplier).
"',";
4006 $sql .=
" ".price2num($this->qty).
",";
4008 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
4009 $sql .=
" ".price2num($this->tva_tx).
",";
4010 $sql .=
" ".price2num($this->localtax1_tx).
",";
4011 $sql .=
" ".price2num($this->localtax2_tx).
",";
4012 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
4013 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
4014 $sql .=
' '.((!empty($this->fk_product) && $this->fk_product > 0) ? $this->fk_product :
"null").
',';
4015 $sql .=
" ".((int) $this->product_type).
",";
4016 $sql .=
" ".price2num($this->remise_percent).
",";
4017 $sql .=
' '.(!empty($this->fk_remise_except) ? ((int) $this->fk_remise_except) :
"null").
',';
4018 $sql .=
" ".price2num($this->subprice).
",";
4019 $sql .=
" ".(!empty($this->qty) ?
price2num($this->total_ttc / $this->qty) :
price2num($this->total_ttc)).
",";
4020 $sql .=
" ".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
4021 $sql .=
" ".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
4022 $sql .=
' '.(!empty($this->fk_code_ventilation) ? $this->fk_code_ventilation : 0).
',';
4023 $sql .=
' '.((int) $this->rang).
',';
4024 $sql .=
' '.((int) $this->special_code).
',';
4025 $sql .=
" ".((int) $this->info_bits).
",";
4026 $sql .=
" ".price2num($this->total_ht).
",";
4027 $sql .=
" ".price2num($this->total_tva).
",";
4028 $sql .=
" ".price2num($this->total_ttc).
",";
4029 $sql .=
" ".price2num($this->total_localtax1).
",";
4030 $sql .=
" ".price2num($this->total_localtax2);
4031 $sql .=
", ".(!$this->fk_unit ?
'NULL' : $this->fk_unit);
4032 $sql .=
", ".(int) $this->fk_multicurrency;
4033 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
4034 $sql .=
", ".price2num($this->multicurrency_subprice);
4035 $sql .=
", ".price2num($this->multicurrency_total_ht);
4036 $sql .=
", ".price2num($this->multicurrency_total_tva);
4037 $sql .=
", ".price2num($this->multicurrency_total_ttc);
4040 $resql = $this->db->query($sql);
4042 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
4043 $this->
rowid = $this->id;
4054 if ($this->fk_remise_except) {
4056 $result = $discount->fetch($this->fk_remise_except);
4061 if ($discount->fk_facture_line > 0) {
4062 if (empty($noerrorifdiscountalreadylinked)) {
4063 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed", $discount->id);
4064 dol_syslog(get_class($this).
"::insert Error ".$this->error, LOG_ERR);
4065 $this->db->rollback();
4069 $result = $discount->link_to_invoice($this->
rowid, 0);
4071 $this->error = $discount->error;
4072 dol_syslog(get_class($this).
"::insert Error ".$this->error, LOG_ERR);
4073 $this->db->rollback();
4078 $this->error = $langs->trans(
"ErrorADiscountThatHasBeenRemovedIsIncluded");
4079 dol_syslog(get_class($this).
"::insert Error ".$this->error, LOG_ERR);
4080 $this->db->rollback();
4084 $this->error = $discount->error;
4085 dol_syslog(get_class($this).
"::insert Error ".$this->error, LOG_ERR);
4086 $this->db->rollback();
4091 if (!$error && !$notrigger) {
4093 $result = $this->
call_trigger(
'LINEBILL_SUPPLIER_CREATE', $user);
4095 $this->db->rollback();
4102 $this->db->commit();
4106 foreach ($this->errors as $errmsg) {
4107 dol_syslog(get_class($this).
"::insert ".$errmsg, LOG_ERR);
4108 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
4111 $this->db->rollback();
4114 $this->error = $this->db->error();
4115 $this->db->rollback();
4132 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn_det SET";
4133 $sql .=
" total_ht = ".price2num($this->total_ht);
4134 $sql .=
", tva= ".price2num($this->total_tva);
4135 $sql .=
", total_localtax1 = ".price2num($this->total_localtax1);
4136 $sql .=
", total_localtax2 = ".price2num($this->total_localtax2);
4137 $sql .=
", total_ttc = ".price2num($this->total_ttc);
4138 $sql .=
" WHERE rowid = ".((int) $this->
rowid);
4140 dol_syslog(
"FactureFournisseurLigne.class.php::update_total", LOG_DEBUG);
4142 $resql = $this->db->query($sql);
4144 $this->db->commit();
4147 $this->error = $this->db->error();
4148 $this->db->rollback();
Superclass for invoices classes.
calculate_date_lim_reglement($cond_reglement=0)
Returns an invoice payment deadline based on the invoice settlement conditions and billing date.
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...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
deleteEcmFiles($mode=0)
Delete related files of object in database.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
static isExistingObject($element, $id, $ref='', $ref_ext='')
Check an object id/ref exists If you don't need/want to instantiate object and just need to know if o...
updateRangOfLine($rowid, $rang)
Update position of line (rang)
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='', $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.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
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 absolute discounts.
Class to manage Dolibarr database access.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
create($user)
Create supplier invoice into database.
list_qualified_avoir_supplier_invoices($socid=0)
Return list of qualifying invoices for correction by credit note Invoices that respect the following ...
list_replacable_supplier_invoices($socid=0)
Return list of replaceable invoices Status valid or abandoned for other reason + not paid + no paymen...
addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false, $array_options=0, $fk_unit=null, $origin_id=0, $pu_devise=0, $ref_supplier='', $special_code='', $fk_parent_line=0, $fk_remise_except=0)
Adds an invoice line (associated with no predefined product/service) The parameters are already suppo...
set_unpaid($user)
Tag the invoice as not fully paid + trigger call BILL_UNPAYED Function used when a direct debit payme...
setCanceled($user, $close_code='', $close_note='')
Tag invoice as canceled, with no payment on it (example for replacement invoice or payment never rece...
updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit=null, $pu_devise=0, $ref_supplier='', $rang=0)
Update a line detail into database.
info($id)
Loads the info order information into the invoice object.
const TYPE_CREDIT_NOTE
Credit note invoice.
isCreditNoteUsed()
Is credit note used.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
deleteline($rowid, $notrigger=0)
Delete a detail line from database.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='', $notooltip=0, $save_lastsearch_value=-1, $addlinktonotes=0)
Return clicable name (with picto eventually)
getTooltipContentArray($params)
getTooltipContentArray
setPaid($user, $close_code='', $close_note='')
Tag invoice as a paid invoice.
update($user=null, $notrigger=0)
Update database.
__construct($db)
Constructor.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
load_state_board()
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
const TYPE_REPLACEMENT
Replacement invoice.
setUnpaid($user)
Tag the invoice as not fully paid + trigger call BILL_UNPAYED Function used when a direct debit payme...
const STATUS_VALIDATED
Validated (need to be paid)
getNextNumRef($soc, $mode='next')
Return next reference of supplier invoice not already used (or last reference) according to numbering...
insert_discount($idremise)
Add a discount line into an invoice (as an invoice line) using an existing absolute discount (Consume...
initAsSpecimen($option='')
Initialise an instance with random values.
fetch($id='', $ref='', $ref_ext='')
Load object in memory from database.
const TYPE_STANDARD
Standard invoice.
validate($user, $force_number='', $idwarehouse=0, $notrigger=0)
Tag invoice as validated + call trigger BILL_VALIDATE.
set_paid($user, $close_code='', $close_note='')
Tag invoice as a paid invoice.
createFromClone(User $user, $fromid, $invertdetail=0)
Load an object from its id and create a new one in database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template model.
setDraft($user, $idwarehouse=-1)
Set draft status.
getRights()
Returns the rights used for this class.
const STATUS_ABANDONED
Classified abandoned and no payment done.
hasDelay()
Is the payment of the supplier invoice having a delay?
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
fetch_lines()
Load this->lines.
const STATUS_CLOSED
Classified paid.
setVATReverseCharge($vatreversecharge)
Change the option VAT reverse charge.
Class to manage invoice templates.
Class to manage stock movements.
static getIdFromCode($dbs, $code)
Get id of currency from code.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage line invoices.
fetch($rowid)
Retrieves a supplier invoice line.
__construct($db)
Constructor.
insert($notrigger=0)
Insert line into database.
update($notrigger=0)
Update a supplier invoice line.
update_total()
Mise a jour de l'objet ligne de commande en base.
Class to manage translations.
Class to manage Dolibarr users.
print $langs trans("Ref").' m m m statut
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_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
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.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
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