39include_once DOL_DOCUMENT_ROOT.
'/core/class/commoninvoice.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
44if (isModEnabled(
'accounting')) {
45 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
46 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
57 public $element =
'invoice_supplier';
62 public $table_element =
'facture_fourn';
67 public $table_element_line =
'facture_fourn_det';
72 public $fk_element =
'fk_facture_fourn';
77 public $picto =
'supplier_invoice';
83 public $ismultientitymanaged = 1;
89 public $restrictiononfksoc = 1;
109 public $ref_supplier;
183 public $date_echeance;
208 public $total_localtax1;
209 public $total_localtax2;
218 public $note_private;
230 public $transport_mode_id;
235 public $vat_reverse_charge;
237 public $extraparams = array();
243 public $lines = array();
254 public $fk_facture_source;
257 public $fk_fac_rec_source;
259 public $fields = array(
260 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
261 'ref' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>15),
262 'ref_supplier' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefSupplier',
'enabled'=>1,
'visible'=>-1,
'position'=>20),
263 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>25,
'index'=>1),
264 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefExt',
'enabled'=>1,
'visible'=>0,
'position'=>30),
265 'type' =>array(
'type'=>
'smallint(6)',
'label'=>
'Type',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>35),
266 'subtype' =>array(
'type'=>
'smallint(6)',
'label'=>
'InvoiceSubtype',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>36),
267 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'isModEnabled("societe")',
'visible'=>-1,
'notnull'=>1,
'position'=>40),
268 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
269 'datef' =>array(
'type'=>
'date',
'label'=>
'Date',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
270 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>55),
271 'libelle' =>array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
272 'paye' =>array(
'type'=>
'smallint(6)',
'label'=>
'Paye',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>65),
273 'amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'Amount',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>70),
274 'remise' =>array(
'type'=>
'double(24,8)',
'label'=>
'Discount',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
275 'close_code' =>array(
'type'=>
'varchar(16)',
'label'=>
'CloseCode',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
276 'close_note' =>array(
'type'=>
'varchar(128)',
'label'=>
'CloseNote',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
277 'tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Tva',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
278 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax1',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
279 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax2',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
280 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalHT',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
281 'total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalVAT',
'enabled'=>1,
'visible'=>-1,
'position'=>110),
282 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalTTC',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
283 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
284 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>130),
285 'fk_user_valid' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
286 'fk_facture_source' =>array(
'type'=>
'integer',
'label'=>
'Fk facture source',
'enabled'=>1,
'visible'=>-1,
'position'=>140),
287 'fk_projet' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:fk_statut=1',
'label'=>
'Project',
'enabled'=>
"isModEnabled('project')",
'visible'=>-1,
'position'=>145),
288 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'Account',
'enabled'=>
'isModEnabled("banque")',
'visible'=>-1,
'position'=>150),
289 'fk_cond_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentTerm',
'enabled'=>1,
'visible'=>-1,
'position'=>155),
290 'fk_mode_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentMode',
'enabled'=>1,
'visible'=>-1,
'position'=>160),
291 'date_lim_reglement' =>array(
'type'=>
'date',
'label'=>
'DateLimReglement',
'enabled'=>1,
'visible'=>-1,
'position'=>165),
292 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>170),
293 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>175),
294 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'ModelPdf',
'enabled'=>1,
'visible'=>0,
'position'=>180),
295 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>190),
296 'fk_incoterms' =>array(
'type'=>
'integer',
'label'=>
'IncotermCode',
'enabled'=>1,
'visible'=>-1,
'position'=>195),
297 'location_incoterms' =>array(
'type'=>
'varchar(255)',
'label'=>
'IncotermLocation',
'enabled'=>1,
'visible'=>-1,
'position'=>200),
298 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'MulticurrencyId',
'enabled'=>1,
'visible'=>-1,
'position'=>205),
299 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'MulticurrencyCode',
'enabled'=>1,
'visible'=>-1,
'position'=>210),
300 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyRate',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
301 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyTotalHT',
'enabled'=>1,
'visible'=>-1,
'position'=>220),
302 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyTotalVAT',
'enabled'=>1,
'visible'=>-1,
'position'=>225),
303 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyTotalTTC',
'enabled'=>1,
'visible'=>-1,
'position'=>230),
304 'date_pointoftax' =>array(
'type'=>
'date',
'label'=>
'Date pointoftax',
'enabled'=>1,
'visible'=>-1,
'position'=>235),
305 'date_valid' =>array(
'type'=>
'date',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>240),
306 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'Last main doc',
'enabled'=>1,
'visible'=>-1,
'position'=>245),
307 'fk_statut' =>array(
'type'=>
'smallint(6)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>500),
308 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>900),
360 const CLOSECODE_DISCOUNTVAT =
'discount_vat';
361 const CLOSECODE_BADCREDIT =
'badsupplier';
362 const CLOSECODE_ABANDONED =
'abandon';
363 const CLOSECODE_REPLACED =
'replaced';
383 global $langs, $conf, $hookmanager;
389 if (isset($this->ref_supplier)) {
390 $this->ref_supplier = trim($this->ref_supplier);
392 if (empty($this->
type)) {
395 if (empty($this->date)) {
400 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
405 if (empty($this->fk_multicurrency)) {
406 $this->multicurrency_code = $conf->currency;
407 $this->fk_multicurrency = 0;
408 $this->multicurrency_tx = 1;
414 if ($this->fac_rec > 0) {
415 $this->fk_fac_rec_source = $this->fac_rec;
417 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture-rec.class.php';
419 $result = $_facrec->fetch($this->fac_rec);
420 $result = $_facrec->fetchObjectLinked(
null,
'',
null,
'',
'OR', 1,
'sourcetype', 0);
423 if (!empty($_facrec->frequency)) {
424 $originaldatewhen = $_facrec->date_when;
425 $nextdatewhen =
dol_time_plus_duree($originaldatewhen, $_facrec->frequency, $_facrec->unit_frequency);
427 $this->socid = $_facrec->socid;
430 $this->entity = $_facrec->entity;
433 $this->fk_project =
GETPOST(
'projectid',
'int') > 0 ? ((int)
GETPOST(
'projectid',
'int')) : $_facrec->fk_project;
434 $this->note_public =
GETPOST(
'note_public',
'restricthtml') ?
GETPOST(
'note_public',
'restricthtml') : $_facrec->note_public;
435 $this->note_private =
GETPOST(
'note_private',
'restricthtml') ?
GETPOST(
'note_private',
'restricthtml') : $_facrec->note_private;
436 $this->model_pdf =
GETPOST(
'model',
'alpha') ?
GETPOST(
'model',
'alpha') : $_facrec->model_pdf;
437 $this->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int') > 0 ? ((int)
GETPOST(
'cond_reglement_id',
'int')) : $_facrec->cond_reglement_id;
438 $this->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int') > 0 ? ((int)
GETPOST(
'mode_reglement_id',
'int')) : $_facrec->mode_reglement_id;
439 $this->fk_account =
GETPOST(
'fk_account') > 0 ? ((int)
GETPOST(
'fk_account')) : $_facrec->fk_account;
442 $this->total_ht = $_facrec->total_ht;
443 $this->total_ttc = $_facrec->total_ttc;
446 $this->fk_incoterms = $_facrec->fk_incoterms;
447 $this->location_incoterms = $_facrec->location_incoterms;
453 if (!empty(
GETPOST(
'ref_supplier'))) {
454 $this->ref_supplier = trim($this->ref_supplier);
456 $this->ref_supplier = trim($this->ref_supplier .
'_' . ($_facrec->nb_gen_done + 1));
458 $this->note_public = trim($this->note_public);
459 $this->note_private = trim($this->note_private);
460 $this->note_private =
dol_concatdesc($this->note_private, $langs->trans(
"GeneratedFromRecurringInvoice", $_facrec->title));
462 $this->array_options = $_facrec->array_options;
464 if (! $this->mode_reglement_id) {
465 $this->mode_reglement_id = 0;
470 $this->linked_objects = $_facrec->linkedObjectsIds;
477 if ($_facrec->frequency > 0) {
478 dol_syslog(
"This is a recurring invoice so we set date_last_gen and next date_when");
479 if (empty($_facrec->date_when)) {
480 $_facrec->date_when = $now;
482 $next_date = $_facrec->getNextDate();
483 $result = $_facrec->setValueFrom(
'date_last_gen', $now,
'',
null,
'date',
'', $user,
'');
485 $result = $_facrec->setNextDate($next_date, 1);
489 $outputlangs = $langs;
492 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($this->thirdparty->default_lang)) {
493 $newlang = $this->thirdparty->default_lang;
495 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($this->default_lang)) {
496 $newlang = $this->default_lang;
498 if (!empty($newlang)) {
500 $outputlangs->setDefaultLang($newlang);
506 $substitutionarray[
'__INVOICE_MONTH__'] =
dol_print_date($this->date,
'%m');
509 $substitutionarray[
'__INVOICE_MONTH_TEXT__'] =
dol_print_date($this->date,
'%B');
512 $substitutionarray[
'__INVOICE_YEAR__'] =
dol_print_date($this->date,
'%Y');
515 $substitutionarray[
'__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] =
dol_print_date($originaldatewhen,
'dayhour');
516 $substitutionarray[
'__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] =
dol_print_date($nextdatewhen,
'dayhour');
517 $substitutionarray[
'__INVOICE_PREVIOUS_DATE_NEXT_INVOICE_AFTER_GEN__'] =
dol_print_date($previousdaynextdatewhen,
'dayhour');
518 $substitutionarray[
'__INVOICE_COUNTER_CURRENT__'] = $_facrec->nb_gen_done;
519 $substitutionarray[
'__INVOICE_COUNTER_MAX__'] = $_facrec->nb_gen_max;
528 if (!empty($forceduedate)) {
529 $this->date_echeance = $forceduedate;
532 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facture_fourn (";
534 $sql .=
", ref_supplier";
543 $sql .=
", vat_reverse_charge";
544 $sql .=
", fk_projet";
545 $sql .=
", fk_cond_reglement";
546 $sql .=
", fk_mode_reglement";
547 $sql .=
", fk_account";
548 $sql .=
", note_private";
549 $sql .=
", note_public";
550 $sql .=
", fk_user_author";
551 $sql .=
", date_lim_reglement";
552 $sql .=
", fk_incoterms, location_incoterms";
553 $sql .=
", fk_multicurrency";
554 $sql .=
", multicurrency_code";
555 $sql .=
", multicurrency_tx";
556 $sql .=
", fk_facture_source";
557 $sql .=
", fk_fac_rec_source";
561 $sql .=
", '".$this->db->escape($this->ref_supplier).
"'";
562 $sql .=
", '".$this->db->escape($this->ref_ext).
"'";
563 $sql .=
", ".((int) $conf->entity);
564 $sql .=
", '".$this->db->escape($this->
type).
"'";
565 $sql .=
", ".($this->subtype ?
"'".$this->db->escape($this->subtype).
"'" :
"null");
566 $sql .=
", '".$this->db->escape(isset($this->label) ? $this->label : (isset($this->libelle) ? $this->libelle :
'')).
"'";
567 $sql .=
", ".((int) $this->socid);
568 $sql .=
", '".$this->db->idate($now).
"'";
569 $sql .=
", '".$this->db->idate($this->date).
"'";
570 $sql .=
", ".($this->vat_reverse_charge !=
'' ? ((int) $this->db->escape($this->vat_reverse_charge)) : 0);
571 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
572 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
"null");
573 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"null");
574 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
575 $sql .=
", '".$this->db->escape($this->note_private).
"'";
576 $sql .=
", '".$this->db->escape($this->note_public).
"'";
577 $sql .=
", ".((int) $user->id).
",";
578 $sql .= $this->date_echeance !=
'' ?
"'".$this->db->idate($this->date_echeance).
"'" :
"null";
579 $sql .=
", ".(int) $this->fk_incoterms;
580 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
581 $sql .=
", ".(int) $this->fk_multicurrency;
582 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
583 $sql .=
", ".(float) $this->multicurrency_tx;
584 $sql .=
", ".($this->fk_facture_source ? ((int) $this->fk_facture_source) :
"null");
585 $sql .=
", ".(isset($this->fk_fac_rec_source) ? $this->fk_fac_rec_source :
"NULL");
588 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
589 $resql = $this->db->query($sql);
591 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn');
594 $this->
ref =
'(PROV'.$this->id.
')';
595 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"facture_fourn SET ref='".$this->db->escape($this->
ref).
"' WHERE rowid=".((int) $this->
id);
597 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
598 $resql = $this->db->query($sql);
603 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
604 $this->linked_objects = $this->linkedObjectsIds;
608 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
609 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
610 if (is_array($tmp_origin_id)) {
611 foreach ($tmp_origin_id as $origin_id) {
619 $origin_id = $tmp_origin_id;
629 if (!$error && empty($this->fac_rec) && count($this->lines) && is_object($this->lines[0])) {
630 dol_syslog(
"There is ".count($this->lines).
" lines that are invoice lines objects");
631 foreach ($this->lines as $i => $val) {
632 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'facture_fourn_det (fk_facture_fourn, special_code, fk_remise_except)';
633 $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').
')';
635 $resql_insert = $this->db->query($sql);
637 $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn_det');
642 $this->lines[$i]->subprice,
643 $this->lines[$i]->tva_tx.($this->lines[$i]->vat_src_code ?
' ('.$this->lines[$i]->vat_src_code.
')' :
''),
644 $this->lines[$i]->localtax1_tx,
645 $this->lines[$i]->localtax2_tx,
646 $this->lines[$i]->qty,
647 $this->lines[$i]->fk_product,
649 (!empty($this->lines[$i]->info_bits) ? $this->lines[$i]->info_bits :
''),
650 $this->lines[$i]->product_type,
651 $this->lines[$i]->remise_percent,
653 $this->lines[$i]->date_start,
654 $this->lines[$i]->date_end,
655 $this->lines[$i]->array_options,
656 $this->lines[$i]->fk_unit,
657 $this->lines[$i]->multicurrency_subprice,
658 $this->lines[$i]->ref_supplier
661 $this->error = $this->db->lasterror();
662 $this->db->rollback();
666 } elseif (!$error && empty($this->fac_rec)) {
667 dol_syslog(
"There is ".count($this->lines).
" lines that are array lines");
668 foreach ($this->lines as $i => $val) {
669 $line = $this->lines[$i];
673 if (!is_object($line)) {
674 $line = (object) $line;
677 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'facture_fourn_det (fk_facture_fourn, special_code, fk_remise_except)';
678 $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').
')';
680 $resql_insert = $this->db->query($sql);
682 $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn_det');
694 (!empty($line->info_bits) ? $line->info_bits :
''),
696 $line->remise_percent,
700 $line->array_options,
702 $line->multicurrency_subprice,
706 $this->error = $this->db->lasterror();
707 $this->db->rollback();
716 if (! $error && $this->fac_rec > 0) {
717 foreach ($_facrec->lines as $i => $val) {
718 if ($_facrec->lines[$i]->fk_product) {
719 $prod =
new Product($this->db);
720 $res = $prod->fetch($_facrec->lines[$i]->fk_product);
731 $tva_tx = $_facrec->lines[$i]->tva_tx . ($_facrec->lines[$i]->vat_src_code ?
'(' . $_facrec->lines[$i]->vat_src_code .
')' :
'');
732 $tva_npr = $_facrec->lines[$i]->info_bits;
733 if (empty($tva_tx)) {
736 $localtax1_tx = $_facrec->lines[$i]->localtax1_tx;
737 $localtax2_tx = $_facrec->lines[$i]->localtax2_tx;
739 $fk_product_fournisseur_price = empty($_facrec->lines[$i]->fk_product_fournisseur_price) ? null : $_facrec->lines[$i]->fk_product_fournisseur_price;
740 $buyprice = empty($_facrec->lines[$i]->buyprice) ? 0 : $_facrec->lines[$i]->buyprice;
743 if (! $buyprice && $_facrec->lines[$i]->fk_product > 0) {
744 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.product.class.php';
746 $producttmp->fetch($_facrec->lines[$i]->fk_product);
751 if (
getDolGlobalString(
'MARGIN_TYPE') ==
'costprice' && !empty($producttmp->cost_price)) {
752 $buyprice = $producttmp->cost_price;
754 $buyprice = $producttmp->pmp;
756 if ($producttmp->find_min_price_product_fournisseur($_facrec->lines[$i]->fk_product) > 0) {
757 if ($producttmp->product_fourn_price_id > 0) {
758 $buyprice =
price2num($producttmp->fourn_unitprice * (1 - $producttmp->fourn_remise_percent / 100) + $producttmp->fourn_remise,
'MU');
764 $result_insert = $this->
addline(
765 $_facrec->lines[$i]->description,
766 $_facrec->lines[$i]->pu_ht,
770 $_facrec->lines[$i]->qty,
771 $_facrec->lines[$i]->fk_product,
772 $_facrec->lines[$i]->remise_percent,
773 ($_facrec->lines[$i]->date_start == 1 && $this->date) ? $this->date :
'',
774 ($_facrec->lines[$i]->date_end == 1 && $previousdaynextdatewhen) ? $previousdaynextdatewhen :
'',
776 $_facrec->lines[$i]->info_bits,
779 $_facrec->lines[$i]->rang,
781 $_facrec->lines[$i]->array_options,
782 $_facrec->lines[$i]->fk_unit,
785 $_facrec->lines[$i]->ref_supplier,
786 $_facrec->lines[$i]->special_code,
790 if ($result_insert < 0) {
792 $this->error = $this->db->error();
812 $result = $this->
call_trigger(
'BILL_SUPPLIER_CREATE', $user);
823 $this->db->rollback();
827 $this->error = $langs->trans(
'FailedToUpdatePrice');
828 $this->db->rollback();
832 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
833 $this->error = $langs->trans(
'ErrorRefAlreadyExists');
834 $this->db->rollback();
837 $this->error = $this->db->lasterror();
838 $this->db->rollback();
852 public function fetch($id =
'', $ref =
'', $ref_ext =
'')
854 if (empty($id) && empty($ref) && empty($ref_ext)) {
861 $sql .=
" t.ref_supplier,";
862 $sql .=
" t.ref_ext,";
863 $sql .=
" t.entity,";
865 $sql .=
" t.subtype,";
866 $sql .=
" t.fk_soc,";
870 $sql .=
" t.libelle as label,";
872 $sql .=
" t.close_code,";
873 $sql .=
" t.close_note,";
875 $sql .=
" t.localtax1,";
876 $sql .=
" t.localtax2,";
877 $sql .=
" t.total_ht,";
878 $sql .=
" t.total_tva,";
879 $sql .=
" t.total_ttc,";
880 $sql .=
" t.fk_statut as status,";
881 $sql .=
" t.fk_user_author,";
882 $sql .=
" t.fk_user_valid,";
883 $sql .=
" t.fk_facture_source,";
884 $sql .=
" t.vat_reverse_charge,";
885 $sql .=
" t.fk_fac_rec_source,";
886 $sql .=
" t.fk_projet as fk_project,";
887 $sql .=
" t.fk_cond_reglement,";
888 $sql .=
" t.fk_account,";
889 $sql .=
" t.fk_mode_reglement,";
890 $sql .=
" t.date_lim_reglement,";
891 $sql .=
" t.note_private,";
892 $sql .=
" t.note_public,";
893 $sql .=
" t.model_pdf,";
894 $sql .=
" t.import_key,";
895 $sql .=
" t.extraparams,";
896 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc,";
897 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_label,";
898 $sql .=
' s.nom as socnom, s.rowid as socid,';
899 $sql .=
' t.fk_incoterms, t.location_incoterms,';
900 $sql .=
" i.libelle as label_incoterms,";
901 $sql .=
' t.fk_transport_mode,';
902 $sql .=
' t.fk_multicurrency, t.multicurrency_code, t.multicurrency_tx, t.multicurrency_total_ht, t.multicurrency_total_tva, t.multicurrency_total_ttc';
903 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn as t';
904 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON (t.fk_soc = s.rowid)";
905 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_payment_term as cr ON t.fk_cond_reglement = cr.rowid";
906 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as p ON t.fk_mode_reglement = p.id";
907 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON t.fk_incoterms = i.rowid';
909 $sql .=
" WHERE t.rowid = ".((int) $id);
911 $sql .=
' WHERE t.entity IN ('.getEntity(
'supplier_invoice').
')';
913 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
916 $sql .=
" AND t.ref_ext = '".$this->db->escape($ref_ext).
"'";
920 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
921 $resql = $this->db->query($sql);
923 if ($this->db->num_rows($resql)) {
924 $obj = $this->db->fetch_object($resql);
926 $this->
id = $obj->rowid;
927 $this->
ref = $obj->ref ? $obj->ref : $obj->rowid;
929 $this->ref_supplier = $obj->ref_supplier;
930 $this->ref_ext = $obj->ref_ext;
931 $this->entity = $obj->entity;
933 $this->subtype = $obj->subtype;
934 $this->socid = $obj->fk_soc;
935 $this->datec = $this->db->jdate($obj->datec);
936 $this->date = $this->db->jdate($obj->datef);
938 $this->tms = $this->db->jdate($obj->tms);
939 $this->libelle = $obj->label;
940 $this->label = $obj->label;
941 $this->paye = $obj->paye;
942 $this->paid = $obj->paye;
943 $this->close_code = $obj->close_code;
944 $this->close_note = $obj->close_note;
945 $this->total_localtax1 = $obj->localtax1;
946 $this->total_localtax2 = $obj->localtax2;
947 $this->total_ht = $obj->total_ht;
948 $this->total_tva = $obj->total_tva;
949 $this->total_ttc = $obj->total_ttc;
950 $this->
status = $obj->status;
951 $this->
statut = $obj->status;
952 $this->fk_statut = $obj->status;
953 $this->user_creation_id = $obj->fk_user_author;
954 $this->author = $obj->fk_user_author;
955 $this->user_validation_id = $obj->fk_user_valid;
956 $this->fk_facture_source = $obj->fk_facture_source;
957 $this->vat_reverse_charge = empty($obj->vat_reverse_charge) ?
'0' :
'1';
958 $this->fk_fac_rec_source = $obj->fk_fac_rec_source;
959 $this->fk_project = $obj->fk_project;
960 $this->cond_reglement_id = $obj->fk_cond_reglement;
961 $this->cond_reglement_code = $obj->cond_reglement_code;
962 $this->cond_reglement = $obj->cond_reglement_label;
963 $this->cond_reglement_label = $obj->cond_reglement_label;
964 $this->cond_reglement_doc = $obj->cond_reglement_doc;
965 $this->fk_account = $obj->fk_account;
966 $this->mode_reglement_id = $obj->fk_mode_reglement;
967 $this->mode_reglement_code = $obj->mode_reglement_code;
968 $this->mode_reglement = $obj->mode_reglement_label;
969 $this->date_echeance = $this->db->jdate($obj->date_lim_reglement);
970 $this->note = $obj->note_private;
971 $this->note_private = $obj->note_private;
972 $this->note_public = $obj->note_public;
973 $this->model_pdf = $obj->model_pdf;
974 $this->import_key = $obj->import_key;
977 $this->fk_incoterms = $obj->fk_incoterms;
978 $this->location_incoterms = $obj->location_incoterms;
979 $this->label_incoterms = $obj->label_incoterms;
980 $this->transport_mode_id = $obj->fk_transport_mode;
983 $this->fk_multicurrency = $obj->fk_multicurrency;
984 $this->multicurrency_code = $obj->multicurrency_code;
985 $this->multicurrency_tx = $obj->multicurrency_tx;
986 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
987 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
988 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
990 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
992 $this->socid = $obj->socid;
1000 $this->error = $this->db->lasterror();
1004 $this->error =
'Bill with id '.$id.
' not found';
1005 dol_syslog(get_class($this).
'::fetch '.$this->error);
1009 $this->db->free($resql);
1012 $this->error =
"Error ".$this->db->lasterror();
1027 $this->lines = array();
1029 $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';
1030 $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';
1031 $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';
1032 $sql .=
', p.rowid as product_id, p.ref as product_ref, p.label as label, p.barcode as product_barcode, p.description as product_desc';
1033 $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';
1034 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_det as f';
1035 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON f.fk_product = p.rowid';
1036 $sql .=
' WHERE fk_facture_fourn='.((int) $this->
id);
1037 $sql .=
' ORDER BY f.rang, f.rowid';
1039 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1041 $resql_rows = $this->db->query($sql);
1043 $num_rows = $this->db->num_rows($resql_rows);
1046 while ($i < $num_rows) {
1047 $obj = $this->db->fetch_object($resql_rows);
1051 $line->id = $obj->rowid;
1052 $line->rowid = $obj->rowid;
1053 $line->description = $obj->description;
1054 $line->date_start = $obj->date_start;
1055 $line->date_end = $obj->date_end;
1056 $line->product_ref = $obj->product_ref;
1057 $line->ref = $obj->product_ref;
1058 $line->ref_supplier = $obj->ref_supplier;
1059 $line->libelle = $obj->label;
1060 $line->label = $obj->label;
1061 $line->product_barcode = $obj->product_barcode;
1062 $line->product_desc = $obj->product_desc;
1063 $line->subprice = $obj->pu_ht;
1064 $line->pu_ht = $obj->pu_ht;
1065 $line->pu_ttc = $obj->pu_ttc;
1066 $line->vat_src_code = $obj->vat_src_code;
1067 $line->tva_tx = $obj->tva_tx;
1068 $line->localtax1_tx = $obj->localtax1_tx;
1069 $line->localtax2_tx = $obj->localtax2_tx;
1070 $line->localtax1_type = $obj->localtax1_type;
1071 $line->localtax2_type = $obj->localtax2_type;
1072 $line->qty = $obj->qty;
1073 $line->remise_percent = $obj->remise_percent;
1074 $line->fk_remise_except = $obj->fk_remise_except;
1076 $line->total_ht = $obj->total_ht;
1077 $line->total_ttc = $obj->total_ttc;
1078 $line->total_tva = $obj->total_tva;
1079 $line->total_localtax1 = $obj->total_localtax1;
1080 $line->total_localtax2 = $obj->total_localtax2;
1081 $line->fk_facture_fourn = $obj->fk_facture_fourn;
1082 $line->fk_product = $obj->fk_product;
1083 $line->product_type = $obj->product_type;
1084 $line->product_label = $obj->label;
1085 $line->info_bits = $obj->info_bits;
1086 $line->fk_parent_line = $obj->fk_parent_line;
1087 $line->special_code = $obj->special_code;
1088 $line->rang = $obj->rang;
1089 $line->fk_unit = $obj->fk_unit;
1092 $line->code_ventilation = $obj->fk_code_ventilation;
1093 $line->fk_accounting_account = $obj->fk_code_ventilation;
1096 $line->fk_multicurrency = $obj->fk_multicurrency;
1097 $line->multicurrency_code = $obj->multicurrency_code;
1098 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1099 $line->multicurrency_total_ht = $obj->multicurrency_total_ht;
1100 $line->multicurrency_total_tva = $obj->multicurrency_total_tva;
1101 $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1104 $line->fetch_optionals();
1106 $this->lines[$i] = $line;
1111 $this->db->free($resql_rows);
1114 $this->error = $this->db->error();
1115 dol_syslog(get_class($this).
"::fetch_lines - No lines:{$this->error} Error:{$this->error}", LOG_DEBUG);
1128 public function update($user =
null, $notrigger = 0)
1134 if (empty($this->
type)) {
1137 if (isset($this->
ref)) {
1138 $this->
ref = trim($this->
ref);
1140 if (isset($this->ref_supplier)) {
1141 $this->ref_supplier = trim($this->ref_supplier);
1143 if (isset($this->ref_ext)) {
1144 $this->ref_ext = trim($this->ref_ext);
1146 if (isset($this->entity)) {
1147 $this->entity = trim($this->entity);
1149 if (isset($this->
type)) {
1152 if (isset($this->subtype)) {
1153 $this->subtype = trim($this->subtype);
1155 if (isset($this->socid)) {
1156 $this->socid = trim($this->socid);
1158 if (isset($this->label)) {
1159 $this->label = trim($this->label);
1161 if (isset($this->paye)) {
1162 $this->paye = trim($this->paye);
1164 if (isset($this->close_code)) {
1165 $this->close_code = trim($this->close_code);
1167 if (isset($this->close_note)) {
1168 $this->close_note = trim($this->close_note);
1170 if (isset($this->localtax1)) {
1171 $this->localtax1 = trim($this->localtax1);
1173 if (isset($this->localtax2)) {
1174 $this->localtax2 = trim($this->localtax2);
1176 if (empty($this->total_ht)) {
1177 $this->total_ht = 0;
1179 if (empty($this->total_tva)) {
1180 $this->total_tva = 0;
1184 if (isset($this->total_ttc)) {
1185 $this->total_ttc = trim($this->total_ttc);
1187 if (isset($this->
statut)) {
1190 if (isset($this->
status)) {
1193 if (isset($this->author)) {
1194 $this->author = trim($this->author);
1196 if (isset($this->fk_user_valid)) {
1197 $this->fk_user_valid = trim($this->fk_user_valid);
1199 if (isset($this->fk_facture_source)) {
1200 $this->fk_facture_source = trim($this->fk_facture_source);
1202 if (isset($this->fk_project)) {
1203 if (empty($this->fk_project)) {
1204 $this->fk_project =
null;
1206 $this->fk_project = intval($this->fk_project);
1209 if (isset($this->cond_reglement_id)) {
1210 $this->cond_reglement_id = trim($this->cond_reglement_id);
1212 if (isset($this->note_private)) {
1213 $this->note = trim($this->note_private);
1215 if (isset($this->note_public)) {
1216 $this->note_public = trim($this->note_public);
1218 if (isset($this->model_pdf)) {
1219 $this->model_pdf = trim($this->model_pdf);
1221 if (isset($this->import_key)) {
1222 $this->import_key = trim($this->import_key);
1230 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn SET";
1231 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1232 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1233 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1234 $sql .=
" entity=".(isset($this->entity) ? ((int) $this->entity) :
"null").
",";
1235 $sql .=
" type=".(isset($this->
type) ? ((int) $this->
type) :
"null").
",";
1236 $sql .=
" subtype=".(isset($this->subtype) ? $this->db->escape($this->subtype) :
"null").
",";
1237 $sql .=
" fk_soc=".(isset($this->socid) ? ((int) $this->socid) :
"null").
",";
1238 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
1239 $sql .=
" datef=".(dol_strlen($this->date) != 0 ?
"'".$this->db->idate($this->date).
"'" :
'null').
",";
1241 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
1243 $sql .=
" libelle=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
1244 $sql .=
" paye=".(isset($this->paye) ? ((int) $this->paye) :
"0").
",";
1245 $sql .=
" close_code=".(isset($this->close_code) ?
"'".$this->db->escape($this->close_code).
"'" :
"null").
",";
1246 $sql .=
" close_note=".(isset($this->close_note) ?
"'".$this->db->escape($this->close_note).
"'" :
"null").
",";
1247 $sql .=
" localtax1=".(isset($this->localtax1) ? ((float) $this->localtax1) :
"null").
",";
1248 $sql .=
" localtax2=".(isset($this->localtax2) ? ((float) $this->localtax2) :
"null").
",";
1249 $sql .=
" total_ht=".(isset($this->total_ht) ? ((float) $this->total_ht) :
"null").
",";
1250 $sql .=
" total_tva=".(isset($this->total_tva) ? ((float) $this->total_tva) :
"null").
",";
1251 $sql .=
" total_ttc=".(isset($this->total_ttc) ? ((float) $this->total_ttc) :
"null").
",";
1252 $sql .=
" fk_statut=".(isset($this->
status) ? ((int) $this->
status) : (isset($this->
statut) ? ((int) $this->
statut) :
"null")).
",";
1253 $sql .=
" fk_user_author=".(isset($this->author) ? ((int) $this->author) :
"null").
",";
1254 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? ((int) $this->fk_user_valid) :
"null").
",";
1255 $sql .=
" fk_facture_source=".($this->fk_facture_source ? ((int) $this->fk_facture_source) :
"null").
",";
1256 $sql .=
" vat_reverse_charge = ".($this->vat_reverse_charge !=
'' ? ((int) $this->db->escape($this->vat_reverse_charge)) : 0).
",";
1257 $sql .=
" fk_projet=".(!empty($this->fk_project) ? ((int) $this->fk_project) :
"null").
",";
1258 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? ((int) $this->cond_reglement_id) :
"null").
",";
1259 $sql .=
" date_lim_reglement=".(dol_strlen($this->date_echeance) != 0 ?
"'".$this->db->idate($this->date_echeance).
"'" :
'null').
",";
1260 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1261 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1262 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1263 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1264 $sql .=
" WHERE rowid=".((int) $this->
id);
1268 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1269 $resql = $this->db->query($sql);
1274 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1275 $this->errors[] = $langs->trans(
'ErrorRefAlreadyExists');
1277 $this->errors[] =
"Error ".$this->db->lasterror();
1291 $result = $this->
call_trigger(
'BILL_SUPPLIER_MODIFY', $user);
1301 foreach ($this->errors as $errmsg) {
1302 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1303 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1305 $this->db->rollback();
1308 $this->db->commit();
1323 global $conf, $langs;
1325 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1326 include_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1331 $result =
$remise->fetch($idremise);
1334 if (
$remise->fk_invoice_supplier) {
1335 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed");
1336 $this->db->rollback();
1341 $facligne->fk_facture_fourn = $this->id;
1342 $facligne->fk_remise_except =
$remise->id;
1343 $facligne->desc =
$remise->description;
1344 $facligne->vat_src_code =
$remise->vat_src_code;
1345 $facligne->tva_tx =
$remise->tva_tx;
1346 $facligne->subprice = -
$remise->amount_ht;
1347 $facligne->fk_product = 0;
1348 $facligne->product_type = 0;
1350 $facligne->remise_percent = 0;
1351 $facligne->rang = -1;
1352 $facligne->info_bits = 2;
1355 $facligne->rang = 1;
1356 $linecount = count($this->lines);
1357 for ($ii = 1; $ii <= $linecount; $ii++) {
1363 if (
$remise->fk_invoice_supplier_source > 0) {
1365 $srcinvoice->fetch(
$remise->fk_invoice_supplier_source);
1366 $totalcostpriceofinvoice = 0;
1367 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
1369 $arraytmp = $formmargin->getMarginInfosArray($srcinvoice,
false);
1370 $facligne->pa_ht = $arraytmp[
'pa_total'];
1373 $facligne->total_ht = -
$remise->amount_ht;
1374 $facligne->total_tva = -
$remise->amount_tva;
1375 $facligne->total_ttc = -
$remise->amount_ttc;
1377 $facligne->multicurrency_subprice = -
$remise->multicurrency_subprice;
1378 $facligne->multicurrency_total_ht = -
$remise->multicurrency_total_ht;
1379 $facligne->multicurrency_total_tva = -
$remise->multicurrency_total_tva;
1380 $facligne->multicurrency_total_ttc = -
$remise->multicurrency_total_ttc;
1382 $lineid = $facligne->insert();
1387 $result =
$remise->link_to_invoice($lineid, 0);
1389 $this->error =
$remise->error;
1390 $this->db->rollback();
1394 $this->db->commit();
1397 $this->error = $facligne->error;
1398 $this->db->rollback();
1402 $this->error = $facligne->error;
1403 $this->db->rollback();
1407 $this->db->rollback();
1420 public function delete(
User $user, $notrigger = 0)
1426 dol_syslog(
"FactureFournisseur::delete rowid=".$rowid, LOG_DEBUG);
1433 if (!$error && !$notrigger) {
1435 $result = $this->
call_trigger(
'BILL_SUPPLIER_DELETE', $user);
1437 $this->db->rollback();
1445 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_remise_except';
1446 $sql .=
' WHERE fk_invoice_supplier_source = '.((int) $rowid);
1447 $sql .=
' AND fk_invoice_supplier_line IS NULL';
1448 $resql = $this->db->query($sql);
1452 $list_rowid_det = array();
1453 foreach ($this->lines as $key => $invoiceline) {
1454 $list_rowid_det[] = $invoiceline->rowid;
1458 if (count($list_rowid_det)) {
1459 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe_remise_except';
1460 $sql .=
' SET fk_invoice_supplier = NULL, fk_invoice_supplier_line = NULL';
1461 $sql .=
' WHERE fk_invoice_supplier_line IN ('.$this->db->sanitize(join(
',', $list_rowid_det)).
')';
1463 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1464 if (!$this->db->query($sql)) {
1471 $main = MAIN_DB_PREFIX.
'facture_fourn_det';
1472 $ef = $main.
"_extrafields";
1473 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_facture_fourn = ".((int) $rowid).
")";
1474 $resqlef = $this->db->query($sqlef);
1475 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'facture_fourn_det WHERE fk_facture_fourn = '.((int) $rowid);
1476 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1477 $resql = $this->db->query($sql);
1478 if ($resqlef && $resql) {
1479 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'facture_fourn WHERE rowid = '.((int) $rowid);
1480 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1481 $resql2 = $this->db->query($sql);
1504 if ($conf->fournisseur->facture->dir_output) {
1505 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1508 $dir = $conf->fournisseur->facture->dir_output.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$ref;
1509 $file = $dir.
"/".$ref.
".pdf";
1510 if (file_exists($file)) {
1512 $this->error =
'ErrorFailToDeleteFile';
1516 if (file_exists($dir)) {
1520 $this->error =
'ErrorFailToDeleteDir';
1532 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
1537 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
1538 $this->db->commit();
1541 $this->error = $this->db->lasterror();
1542 $this->db->rollback();
1559 public function set_paid($user, $close_code =
'', $close_note =
'')
1562 dol_syslog(get_class($this).
"::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
1563 return $this->
setPaid($user, $close_code, $close_note);
1574 public function setPaid($user, $close_code =
'', $close_note =
'')
1578 if ($this->paye != 1) {
1583 dol_syslog(
"FactureFournisseur::setPaid", LOG_DEBUG);
1585 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture_fourn SET';
1586 $sql .=
' fk_statut = '.self::STATUS_CLOSED;
1591 $sql .=
", close_code='".$this->db->escape($close_code).
"'";
1594 $sql .=
", close_note='".$this->db->escape($close_note).
"'";
1596 $sql .=
', fk_user_closing = '.((int) $user->id);
1597 $sql .=
", date_closing = '".$this->db->idate($now).
"'";
1598 $sql .=
' WHERE rowid = '.((int) $this->
id);
1600 $resql = $this->db->query($sql);
1603 $result = $this->
call_trigger(
'BILL_SUPPLIER_PAYED', $user);
1610 $this->error = $this->db->error();
1615 $this->db->commit();
1618 $this->db->rollback();
1640 dol_syslog(get_class($this).
"::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE);
1658 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture_fourn';
1659 $sql .=
' SET paye=0, fk_statut='.self::STATUS_VALIDATED.
', close_code=null, close_note=null,';
1660 $sql .=
' date_closing=null,';
1661 $sql .=
' fk_user_closing=null';
1662 $sql .=
' WHERE rowid = '.((int) $this->
id);
1664 dol_syslog(get_class($this).
"::set_unpaid", LOG_DEBUG);
1665 $resql = $this->db->query($sql);
1668 $result = $this->
call_trigger(
'BILL_SUPPLIER_UNPAYED', $user);
1675 $this->error = $this->db->error();
1680 $this->db->commit();
1683 $this->db->rollback();
1698 public function setCanceled($user, $close_code =
'', $close_note =
'')
1700 dol_syslog(get_class($this).
"::setCanceled rowid=".((
int) $this->
id), LOG_DEBUG);
1704 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture_fourn SET';
1705 $sql .=
' fk_statut='.self::STATUS_ABANDONED;
1707 $sql .=
", close_code='".$this->db->escape($close_code).
"'";
1710 $sql .=
", close_note='".$this->db->escape($close_note).
"'";
1712 $sql .=
" WHERE rowid = ".((int) $this->
id);
1714 $resql = $this->db->query($sql);
1718 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe_remise_except';
1719 $sql .=
' SET fk_invoice_supplier = NULL';
1720 $sql .=
' WHERE fk_invoice_supplier = '.((int) $this->
id);
1722 $resql = $this->db->query($sql);
1725 $result = $this->
call_trigger(
'BILL_SUPPLIER_CANCEL', $user);
1727 $this->db->rollback();
1732 $this->db->commit();
1735 $this->error = $this->db->error().
" sql=".$sql;
1736 $this->db->rollback();
1740 $this->error = $this->db->error().
" sql=".$sql;
1741 $this->db->rollback();
1755 public function validate($user, $force_number =
'', $idwarehouse = 0, $notrigger = 0)
1757 global $mysoc, $conf, $langs;
1759 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1764 dol_syslog(get_class($this).
'::validate user='.$user->id.
', force_number='.$force_number.
', idwarehouse='.$idwarehouse);
1771 if ($this->
statut > self::STATUS_DRAFT) {
1772 dol_syslog(get_class($this).
"::validate no draft status", LOG_WARNING);
1775 if (preg_match(
'/^'.preg_quote($langs->trans(
"CopyOf").
' ').
'/', $this->ref_supplier)) {
1776 $langs->load(
"errors");
1777 $this->error = $langs->trans(
"ErrorFieldFormat", $langs->transnoentities(
"RefSupplier")).
'. '.$langs->trans(
'RemoveString', $langs->transnoentitiesnoconv(
"CopyOf"));
1780 if (count($this->lines) <= 0) {
1781 $langs->load(
"errors");
1782 $this->error = $langs->trans(
"ErrorObjectMustHaveLinesToBeValidated", $this->
ref);
1787 if (!empty($this->thirdparty) && is_object($this->thirdparty)) {
1788 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL',
'ACCOUNTANCY_CODE_SUPPLIER');
1789 foreach ($array_to_check as $key) {
1790 $keymin = strtolower($key);
1791 if ($keymin ==
'accountancy_code_supplier') {
1792 $keymin =
'code_compta_fournisseur';
1794 if (!property_exists($this->thirdparty, $keymin)) {
1797 $vallabel = $this->thirdparty->$keymin;
1799 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
1801 if ($this->thirdparty->isACompany()) {
1803 if ($mysoc->country_id > 0 && $this->thirdparty->country_id == $mysoc->country_id) {
1804 $idprof_mandatory =
'SOCIETE_'.$key.
'_INVOICE_MANDATORY';
1806 $langs->load(
"errors");
1807 $this->error = $langs->trans(
'ErrorProdIdIsMandatory', $langs->transcountry(
'ProfId'.$i, $this->thirdparty->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
') ['.$langs->trans(
'Company').
' : '.$this->thirdparty->name.
']';
1808 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
1814 if ($key ==
'EMAIL') {
1816 if (
getDolGlobalString(
'SOCIETE_EMAIL_INVOICE_MANDATORY') && !isValidEMail($this->thirdparty->email)) {
1817 $langs->load(
"errors");
1818 $this->error = $langs->trans(
"ErrorBadEMail", $this->thirdparty->email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
') ['.$langs->trans(
'Company').
' : '.$this->thirdparty->name.
']';
1819 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
1822 } elseif ($key ==
'ACCOUNTANCY_CODE_SUPPLIER') {
1824 if (
getDolGlobalString(
'SOCIETE_ACCOUNTANCY_CODE_SUPPLIER_INVOICE_MANDATORY') && empty($this->thirdparty->code_compta_fournisseur)) {
1825 $langs->load(
"errors");
1826 $this->error = $langs->trans(
"ErrorAccountancyCodeSupplierIsMandatory", $this->thirdparty->name).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1827 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
1838 if ($force_number) {
1839 $num = $force_number;
1840 } elseif (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1847 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn";
1848 $sql .=
" SET ref='".$this->db->escape($num).
"', fk_statut = 1, fk_user_valid = ".((int) $user->id).
", date_valid = '".$this->db->idate($now).
"'";
1849 $sql .=
" WHERE rowid = ".((int) $this->
id);
1851 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
1852 $resql = $this->db->query($sql);
1855 if (!$error && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL')) {
1856 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1857 $langs->load(
"agenda");
1859 $cpt = count($this->lines);
1860 for ($i = 0; $i < $cpt; $i++) {
1861 if ($this->lines[$i]->fk_product > 0) {
1863 $mouvP->origin = &$this;
1864 $mouvP->setOrigin($this->element, $this->
id);
1866 $up_ht_disc = $this->lines[$i]->subprice;
1867 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1868 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1871 $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"InvoiceValidatedInDolibarr", $num));
1873 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"InvoiceValidatedInDolibarr", $num));
1876 $this->error = $mouvP->error;
1877 if (count($mouvP->errors)) {
1878 $this->errors = $mouvP->errors;
1887 if (!$error && empty($notrigger)) {
1889 $result = $this->
call_trigger(
'BILL_SUPPLIER_VALIDATE', $user);
1897 $this->oldref = $this->ref;
1900 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1902 $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).
"'";
1903 $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;
1904 $resql = $this->db->query($sql);
1907 $this->error = $this->db->lasterror();
1909 $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).
"'";
1910 $sql .=
" WHERE filepath = 'fournisseur/facture/".get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1911 $resql = $this->db->query($sql);
1914 $this->error = $this->db->lasterror();
1919 $dirsource = $conf->fournisseur->facture->dir_output.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$oldref;
1920 $dirdest = $conf->fournisseur->facture->dir_output.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$this->newref;
1921 if (!$error && file_exists($dirsource)) {
1922 dol_syslog(get_class($this).
"::validate rename dir ".$dirsource.
" into ".$dirdest);
1924 if (@rename($dirsource, $dirdest)) {
1927 $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,
'/'));
1928 foreach ($listoffiles as $fileentry) {
1929 $dirsource = $fileentry[
'name'];
1930 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $this->newref, $dirsource);
1931 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1932 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1933 @rename($dirsource, $dirdest);
1942 $this->
ref = $this->newref;
1948 $this->db->commit();
1951 $this->db->rollback();
1955 $this->error = $this->db->error();
1956 $this->db->rollback();
1969 public function setDraft($user, $idwarehouse = -1, $notrigger = 0)
1972 global $conf, $langs;
1976 if ($this->
statut == self::STATUS_DRAFT) {
1977 dol_syslog(__METHOD__.
" already draft status", LOG_WARNING);
1985 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn";
1986 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1987 $sql .=
" WHERE rowid = ".((int) $this->
id);
1989 $result = $this->db->query($sql);
1992 $this->oldcopy = clone $this;
1996 if ($result >= 0 && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL')) {
1997 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1998 $langs->load(
"agenda");
2000 $cpt = count($this->lines);
2001 for ($i = 0; $i < $cpt; $i++) {
2002 if ($this->lines[$i]->fk_product > 0) {
2004 $mouvP->origin = &$this;
2005 $mouvP->setOrigin($this->element, $this->
id);
2008 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans(
"InvoiceBackToDraftInDolibarr", $this->ref));
2010 $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans(
"InvoiceBackToDraftInDolibarr", $this->ref));
2016 if (!$error && empty($notrigger)) {
2018 $result = $this->
call_trigger(
'BILL_SUPPLIER_UNVALIDATE', $user);
2025 $this->db->commit();
2028 $this->db->rollback();
2032 $this->error = $this->db->error();
2033 $this->db->rollback();
2072 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)
2074 global $langs, $mysoc, $conf;
2076 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);
2077 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2079 if ($this->
statut == self::STATUS_DRAFT) {
2081 if (empty($remise_percent)) {
2082 $remise_percent = 0;
2087 if (empty($info_bits)) {
2093 if (empty($ventil)) {
2096 if (empty($txtva)) {
2099 if (empty($txlocaltax1)) {
2102 if (empty($txlocaltax2)) {
2106 $remise_percent =
price2num($remise_percent);
2109 if (!preg_match(
'/\((.*)\)/', $txtva)) {
2115 if ($date_start && $date_end && $date_start > $date_end) {
2116 $langs->load(
"errors");
2117 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2123 if ($fk_product > 0) {
2126 dol_syslog(get_class($this).
"::addline we check supplier prices fk_product=".$fk_product.
" qty=".$qty.
" ref_supplier=".$ref_supplier);
2128 if ($prod->fetch($fk_product) > 0) {
2129 $product_type = $prod->type;
2130 $label = $prod->label;
2131 $fk_prod_fourn_price = 0;
2135 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', ($this->fk_soc ? $this->fk_soc : $this->socid));
2138 $pu = $prod->fourn_pu;
2140 $ref_supplier = $prod->ref_supplier;
2142 if ($remise_percent == 0 && $prod->remise_percent != 0) {
2143 $remise_percent = $prod->remise_percent;
2147 $langs->load(
"errors");
2148 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2149 $this->db->rollback();
2150 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
2155 if ($result == -1) {
2156 $langs->load(
"errors");
2157 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2158 $this->db->rollback();
2159 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
2163 $this->error = $prod->error;
2164 $this->db->rollback();
2165 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
2169 $this->error = $prod->error;
2170 $this->db->rollback();
2175 $product_type = $type;
2178 if (isModEnabled(
"multicurrency") && $pu_devise > 0) {
2187 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2188 $vat_src_code = $reg[1];
2189 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2197 $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);
2198 $total_ht = $tabprice[0];
2199 $total_tva = $tabprice[1];
2200 $total_ttc = $tabprice[2];
2201 $total_localtax1 = $tabprice[9];
2202 $total_localtax2 = $tabprice[10];
2203 $pu_ht = $tabprice[3];
2206 $multicurrency_total_ht = $tabprice[16];
2207 $multicurrency_total_tva = $tabprice[17];
2208 $multicurrency_total_ttc = $tabprice[18];
2209 $pu_ht_devise = $tabprice[19];
2218 $rang = $rangmax + 1;
2224 $supplierinvoiceline->context = $this->context;
2226 $supplierinvoiceline->fk_facture_fourn = $this->id;
2228 $supplierinvoiceline->desc = $desc;
2229 $supplierinvoiceline->ref_supplier = $ref_supplier;
2231 $supplierinvoiceline->qty = ($this->
type == self::TYPE_CREDIT_NOTE ? abs($qty) : $qty);
2232 $supplierinvoiceline->subprice = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs($pu_ht) : $pu_ht);
2234 $supplierinvoiceline->vat_src_code = $vat_src_code;
2235 $supplierinvoiceline->tva_tx = $txtva;
2236 $supplierinvoiceline->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2237 $supplierinvoiceline->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2238 $supplierinvoiceline->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2239 $supplierinvoiceline->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2241 $supplierinvoiceline->total_ht = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($total_ht) : $total_ht);
2242 $supplierinvoiceline->total_tva = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($total_tva) : $total_tva);
2243 $supplierinvoiceline->total_localtax1 = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($total_localtax1) : $total_localtax1);
2244 $supplierinvoiceline->total_localtax2 = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($total_localtax2) : $total_localtax2);
2245 $supplierinvoiceline->total_ttc = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($total_ttc) : $total_ttc);
2247 $supplierinvoiceline->fk_product = $fk_product;
2248 $supplierinvoiceline->product_type = $type;
2249 $supplierinvoiceline->remise_percent = $remise_percent;
2250 $supplierinvoiceline->date_start = $date_start;
2251 $supplierinvoiceline->date_end = $date_end;
2252 $supplierinvoiceline->fk_code_ventilation = $ventil;
2253 $supplierinvoiceline->rang = $rang;
2254 $supplierinvoiceline->info_bits = $info_bits;
2255 $supplierinvoiceline->fk_remise_except = $fk_remise_except;
2258 $supplierinvoiceline->special_code = (string) $special_code;
2259 $supplierinvoiceline->fk_parent_line = $fk_parent_line;
2260 $supplierinvoiceline->origin = $this->origin;
2261 $supplierinvoiceline->origin_id = $origin_id;
2262 $supplierinvoiceline->fk_unit = $fk_unit;
2265 $supplierinvoiceline->fk_multicurrency = $this->fk_multicurrency;
2266 $supplierinvoiceline->multicurrency_code = $this->multicurrency_code;
2267 $supplierinvoiceline->multicurrency_subprice = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs($pu_ht_devise) : $pu_ht_devise);
2269 $supplierinvoiceline->multicurrency_total_ht = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($multicurrency_total_ht) : $multicurrency_total_ht);
2270 $supplierinvoiceline->multicurrency_total_tva = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($multicurrency_total_tva) : $multicurrency_total_tva);
2271 $supplierinvoiceline->multicurrency_total_ttc = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($multicurrency_total_ttc) : $multicurrency_total_ttc);
2273 if (is_array($array_options) && count($array_options) > 0) {
2274 $supplierinvoiceline->array_options = $array_options;
2277 $result = $supplierinvoiceline->insert($notrigger);
2280 if (!empty($fk_parent_line)) {
2282 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2283 $linecount = count($this->lines);
2284 for ($ii = $rang; $ii <= $linecount; $ii++) {
2290 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2292 $this->db->commit();
2293 return $supplierinvoiceline->id;
2295 $this->error = $this->db->error();
2296 $this->db->rollback();
2300 $this->error = $supplierinvoiceline->error;
2301 $this->errors = $supplierinvoiceline->errors;
2302 $this->db->rollback();
2335 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)
2337 global $mysoc, $langs;
2339 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);
2340 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2344 $remise_percent =
price2num($remise_percent);
2353 if ($date_start && $date_end && $date_start > $date_end) {
2354 $langs->load(
"errors");
2355 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2360 if (empty($vatrate)) {
2363 if (empty($txlocaltax1)) {
2366 if (empty($txlocaltax2)) {
2384 if (preg_match(
'/\((.*)\)/', $vatrate, $reg)) {
2385 $vat_src_code = $reg[1];
2386 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2389 $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);
2390 $total_ht = $tabprice[0];
2391 $total_tva = $tabprice[1];
2392 $total_ttc = $tabprice[2];
2393 $pu_ht = $tabprice[3];
2394 $pu_tva = $tabprice[4];
2395 $pu_ttc = $tabprice[5];
2396 $total_localtax1 = $tabprice[9];
2397 $total_localtax2 = $tabprice[10];
2400 $multicurrency_total_ht = $tabprice[16];
2401 $multicurrency_total_tva = $tabprice[17];
2402 $multicurrency_total_ttc = $tabprice[18];
2403 $pu_ht_devise = $tabprice[19];
2405 if (empty($info_bits)) {
2412 $line->fetch_optionals();
2414 $staticline = clone $line;
2417 $product =
new Product($this->db);
2418 $result = $product->fetch($idproduct);
2419 $product_type = $product->type;
2421 $idproduct = $staticline->fk_product;
2422 $product_type = $type;
2425 $line->oldline = $staticline;
2426 $line->context = $this->context;
2428 $line->description = $desc;
2430 $line->qty = ($this->
type == self::TYPE_CREDIT_NOTE ? abs($qty) : $qty);
2431 $line->subprice = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs($pu_ht) : $pu_ht);
2432 $line->pu_ht = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs($pu_ht) : $pu_ht);
2433 $line->pu_ttc = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs($pu_ttc) : $pu_ttc);
2435 $line->remise_percent = $remise_percent;
2436 $line->ref_supplier = $ref_supplier;
2438 $line->date_start = $date_start;
2439 $line->date_end = $date_end;
2441 $line->vat_src_code = $vat_src_code;
2442 $line->tva_tx = $vatrate;
2443 $line->localtax1_tx = $txlocaltax1;
2444 $line->localtax2_tx = $txlocaltax2;
2445 $line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2446 $line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2448 $line->total_ht = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($total_ht) : $total_ht);
2449 $line->total_tva = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($total_tva) : $total_tva);
2450 $line->total_localtax1 = $total_localtax1;
2451 $line->total_localtax2 = $total_localtax2;
2452 $line->total_ttc = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs($total_ttc) : $total_ttc);
2454 $line->fk_product = $idproduct;
2455 $line->product_type = $product_type;
2456 $line->info_bits = $info_bits;
2457 $line->fk_unit = $fk_unit;
2458 $line->rang = $rang;
2460 if (is_array($array_options) && count($array_options) > 0) {
2462 foreach ($array_options as $key => $value) {
2463 $line->array_options[$key] = $array_options[$key];
2468 $line->multicurrency_subprice = $pu_ht_devise;
2469 $line->multicurrency_total_ht = $multicurrency_total_ht;
2470 $line->multicurrency_total_tva = $multicurrency_total_tva;
2471 $line->multicurrency_total_ttc = $multicurrency_total_ttc;
2473 $res = $line->update($notrigger);
2476 $this->errors[] = $line->error;
2479 $res = $this->
update_price(
'1',
'auto', 0, $this->thirdparty);
2501 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe_remise_except';
2502 $sql .=
' SET fk_invoice_supplier_line = NULL';
2503 $sql .=
' WHERE fk_invoice_supplier_line = '.((int) $rowid);
2505 dol_syslog(get_class($this).
"::deleteline", LOG_DEBUG);
2506 $result = $this->db->query($sql);
2508 $this->error = $this->db->error();
2509 $this->db->rollback();
2515 if ($line->fetch($rowid) < 1) {
2519 $res = $line->delete($notrigger);
2522 $this->errors[] = $line->error;
2523 $this->db->rollback();
2529 $this->db->commit();
2532 $this->db->rollback();
2533 $this->error = $this->db->lasterror();
2548 $sql =
'SELECT c.rowid, datec, tms as datem, ';
2549 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid';
2550 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn as c';
2551 $sql .=
' WHERE c.rowid = '.((int) $id);
2553 $result = $this->db->query($sql);
2555 if ($this->db->num_rows($result)) {
2556 $obj = $this->db->fetch_object($result);
2558 $this->
id = $obj->rowid;
2560 $this->user_creation_id = $obj->fk_user_author;
2561 $this->user_validation_id = $obj->fk_user_valid;
2562 $this->user_modification_id = $obj->fk_user_modif;
2563 $this->date_creation = $this->db->jdate($obj->datec);
2564 $this->date_modification = $this->db->jdate($obj->datem);
2567 $this->db->free($result);
2589 $sql =
"SELECT f.rowid as rowid, f.ref, f.fk_statut,";
2590 $sql .=
" ff.rowid as rowidnext";
2591 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
2592 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
2593 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON f.rowid = ff.fk_facture_source";
2594 $sql .=
" WHERE (f.fk_statut = ".self::STATUS_VALIDATED.
" OR (f.fk_statut = ".self::STATUS_ABANDONED.
" AND f.close_code = '".self::CLOSECODE_ABANDONED.
"'))";
2595 $sql .=
" AND f.entity = ".$conf->entity;
2596 $sql .=
" AND f.paye = 0";
2597 $sql .=
" AND pf.fk_paiementfourn IS NULL";
2598 $sql .=
" AND ff.fk_statut IS NULL";
2600 $sql .=
" AND f.fk_soc = ".((int) $socid);
2602 $sql .=
" ORDER BY f.ref";
2604 dol_syslog(get_class($this).
"::list_replacable_supplier_invoices", LOG_DEBUG);
2605 $resql = $this->db->query($sql);
2607 while ($obj = $this->db->fetch_object($resql)) {
2608 $return[$obj->rowid] = array(
2609 'id' => $obj->rowid,
2611 'status' => $obj->fk_statut
2617 $this->error = $this->db->error();
2639 $sql =
"SELECT f.rowid as rowid, f.ref, f.fk_statut, f.type, f.subtype, f.paye, pf.fk_paiementfourn";
2640 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
2641 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
2642 $sql .=
" WHERE f.entity = ".$conf->entity;
2643 $sql .=
" AND f.fk_statut in (".self::STATUS_VALIDATED.
",".self::STATUS_CLOSED.
")";
2644 $sql .=
" AND NOT EXISTS (SELECT rowid from ".MAIN_DB_PREFIX.
"facture_fourn as ff WHERE f.rowid = ff.fk_facture_source";
2645 $sql .=
" AND ff.type=".self::TYPE_REPLACEMENT.
")";
2646 $sql .=
" AND f.type != ".self::TYPE_CREDIT_NOTE;
2648 $sql .=
" AND f.fk_soc = ".((int) $socid);
2650 $sql .=
" ORDER BY f.ref";
2652 dol_syslog(get_class($this).
"::list_qualified_avoir_supplier_invoices", LOG_DEBUG);
2653 $resql = $this->db->query($sql);
2655 while ($obj = $this->db->fetch_object($resql)) {
2657 if ($obj->fk_statut == self::STATUS_VALIDATED) {
2660 if ($obj->fk_statut == self::STATUS_CLOSED) {
2664 $paymentornot = ($obj->fk_paiementfourn ? 1 : 0);
2665 $return[$obj->rowid] = array(
'ref'=>$obj->ref,
'status'=>$obj->fk_statut,
'type'=>$obj->type,
'paye'=>$obj->paye,
'paymentornot'=>$paymentornot);
2671 $this->error = $this->db->error();
2686 global $conf, $langs;
2688 $sql =
'SELECT ff.rowid, ff.date_lim_reglement as datefin, ff.fk_statut as status, ff.total_ht, ff.total_ttc';
2689 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn as ff';
2690 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
2691 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON ff.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2693 $sql .=
' WHERE ff.paye = 0';
2694 $sql .=
" AND ff.fk_statut IN (".self::STATUS_VALIDATED.
")";
2695 $sql .=
" AND ff.entity = ".$conf->entity;
2697 $sql .=
' AND ff.fk_soc = '.((int) $user->socid);
2700 $resql = $this->db->query($sql);
2702 $langs->load(
"bills");
2706 $response->warning_delay = $conf->facture->fournisseur->warning_delay / 60 / 60 / 24;
2707 $response->label = $langs->trans(
"SupplierBillsToPay");
2708 $response->labelShort = $langs->trans(
"StatusToPay");
2710 $response->url = DOL_URL_ROOT.
'/fourn/facture/list.php?search_status=1&mainmenu=billing&leftmenu=suppliers_bills';
2711 $response->img =
img_object($langs->trans(
"Bills"),
"bill");
2715 while ($obj = $this->db->fetch_object($resql)) {
2716 $facturestatic->date_echeance = $this->db->jdate($obj->datefin);
2717 $facturestatic->statut = $obj->status;
2718 $facturestatic->status = $obj->status;
2720 $response->nbtodo++;
2721 $response->total += $obj->total_ht;
2723 if ($facturestatic->hasDelay()) {
2724 $response->nbtodolate++;
2725 $response->url_late = DOL_URL_ROOT.
'/fourn/facture/list.php?search_option=late&mainmenu=billing&leftmenu=suppliers_bills';
2729 $this->db->free($resql);
2733 $this->error = $this->db->error();
2747 global $conf, $langs, $mysoc;
2749 $langs->load(
'bills');
2752 $moretitle = $params[
'moretitle'] ??
'';
2753 $picto = $this->picto;
2754 if ($this->
type == self::TYPE_REPLACEMENT) {
2757 if ($this->
type == self::TYPE_CREDIT_NOTE) {
2760 if ($this->
type == self::TYPE_DEPOSIT) {
2764 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"SupplierInvoice").
'</u>';
2765 if ($this->
type == self::TYPE_REPLACEMENT) {
2766 $datas[
'picto'] .=
'<u class="paddingrightonly">'.$langs->transnoentitiesnoconv(
"InvoiceReplace").
'</u>';
2767 } elseif ($this->
type == self::TYPE_CREDIT_NOTE) {
2768 $datas[
'picto'] .=
'<u class="paddingrightonly">'.$langs->transnoentitiesnoconv(
"CreditNote").
'</u>';
2769 } elseif ($this->
type == self::TYPE_DEPOSIT) {
2770 $datas[
'picto'] .=
'<u class="paddingrightonly">'.$langs->transnoentitiesnoconv(
"Deposit").
'</u>';
2772 if (isset($this->
status)) {
2774 if (isset($this->alreadypaid)) {
2775 $alreadypaid = $this->alreadypaid;
2778 $datas[
'picto'] .=
' '.$this->getLibStatut(5, $alreadypaid);
2781 $datas[
'picto'] .=
' - '.$moretitle;
2783 if (!empty($this->
ref)) {
2784 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
2786 if (!empty($this->ref_supplier)) {
2787 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
2789 if (!empty($this->label)) {
2790 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
2792 if (!empty($this->date)) {
2793 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
2795 if (!empty($this->date_echeance)) {
2796 $datas[
'date_echeance'] =
'<br><b>'.$langs->trans(
'DateDue').
':</b> '.
dol_print_date($this->date_echeance,
'day');
2798 if (!empty($this->total_ht)) {
2799 $datas[
'amountht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
2801 if (!empty($this->total_tva)) {
2802 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'AmountVAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
2804 if (!empty($this->total_localtax1) && $this->total_localtax1 != 0) {
2806 $datas[
'amountlt1'] =
'<br><b>'.$langs->transcountry(
'AmountLT1', $mysoc->country_code).
':</b> '.
price($this->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency);
2808 if (!empty($this->total_localtax2) && $this->total_localtax2 != 0) {
2809 $datas[
'amountlt2'] =
'<br><b>'.$langs->transcountry(
'AmountLT2', $mysoc->country_code).
':</b> '.
price($this->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency);
2811 if (!empty($this->revenuestamp)) {
2812 $datas[
'amountrevenustamp'] =
'<br><b>'.$langs->trans(
'RevenueStamp').
':</b> '.
price($this->revenuestamp, 0, $langs, 0, -1, -1, $conf->currency);
2814 if (!empty($this->total_ttc)) {
2815 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
2833 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
2835 global $langs, $conf, $user, $hookmanager;
2839 if ($option ==
'withdraw') {
2840 $url = DOL_URL_ROOT.
'/compta/facture/prelevement.php?facid='.$this->
id.
'&type=bank-transfer';
2841 } elseif ($option ==
'document') {
2842 $url = DOL_URL_ROOT.
'/fourn/facture/document.php?facid='.$this->id;
2844 $url = DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$this->id;
2851 if ($option !==
'nolink') {
2853 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2854 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2855 $add_save_lastsearch_values = 1;
2857 if ($add_save_lastsearch_values) {
2858 $url .=
'&save_lastsearch_values=1';
2862 $picto = $this->picto;
2863 if ($this->
type == self::TYPE_REPLACEMENT) {
2866 if ($this->
type == self::TYPE_CREDIT_NOTE) {
2869 if ($this->
type == self::TYPE_DEPOSIT) {
2874 'objecttype' => $this->element,
2875 'option' => $option,
2876 'moretitle' => $moretitle,
2878 $classfortooltip =
'classfortooltip';
2881 $classfortooltip =
'classforajaxtooltip';
2882 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2894 if (empty($notooltip)) {
2896 $label = $langs->trans(
"ShowSupplierInvoice");
2897 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2899 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
2900 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
2903 $linkstart =
'<a href="'.$url.
'"';
2904 $linkstart .= $linkclose.
'>';
2907 $result .= $linkstart;
2909 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
2911 if ($withpicto != 2) {
2912 $result .= ($max ?
dol_trunc($ref, $max) : $ref);
2914 $result .= $linkend;
2916 if ($addlinktonotes) {
2917 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
2920 $result .=
' <span class="note inline-block">';
2921 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
2924 $result .=
'</span>';
2928 $hookmanager->initHooks(array($this->element .
'dao'));
2929 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
2930 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2932 $result = $hookmanager->resPrint;
2934 $result .= $hookmanager->resPrint;
2949 global $db, $langs, $conf;
2950 $langs->load(
"orders");
2954 $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER =
'mod_facture_fournisseur_cactus';
2960 $classname = $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER;
2963 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
2965 foreach ($dirmodels as $reldir) {
2966 $dir =
dol_buildpath($reldir.
"core/modules/supplier_invoice/");
2969 $mybool |= @include_once $dir.$file;
2972 if ($mybool ===
false) {
2977 $obj =
new $classname();
2979 $numref = $obj->getNumRef($soc, $this, $mode);
2981 if ($numref !=
"") {
2984 $this->error = $obj->error;
3000 global $langs, $conf;
3001 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
3009 $sql =
"SELECT rowid";
3010 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
3011 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3012 $sql .= $this->db->plimit(100);
3014 $resql = $this->db->query($sql);
3016 $num_prods = $this->db->num_rows($resql);
3018 while ($i < $num_prods) {
3020 $row = $this->db->fetch_row($resql);
3021 $prodids[$i] = $row[0];
3027 $this->
ref =
'SPECIMEN';
3028 $this->ref_supplier =
'SUPPLIER_REF_SPECIMEN';
3029 $this->specimen = 1;
3032 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3033 $this->cond_reglement_code =
'RECEP';
3034 $this->mode_reglement_code =
'CHQ';
3036 $this->note_public =
'This is a comment (public)';
3037 $this->note_private =
'This is a comment (private)';
3039 $this->multicurrency_tx = 1;
3040 $this->multicurrency_code = $conf->currency;
3043 if (empty($option) || $option !=
'nolines') {
3046 while ($xnbp < $nbp) {
3048 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3050 $line->subprice = 100;
3053 $line->tva_tx = 19.6;
3054 $line->localtax1_tx = 0;
3055 $line->localtax2_tx = 0;
3057 $line->total_ht = 50;
3058 $line->total_ttc = 59.8;
3059 $line->total_tva = 9.8;
3060 $line->remise_percent = 50;
3062 $line->total_ht = 100;
3063 $line->total_ttc = 119.6;
3064 $line->total_tva = 19.6;
3065 $line->remise_percent = 0;
3068 if ($num_prods > 0) {
3069 $prodid = mt_rand(1, $num_prods);
3070 $line->fk_product = $prodids[$prodid];
3072 $line->product_type = 0;
3074 $this->lines[$xnbp] = $line;
3076 $this->total_ht += $line->total_ht;
3077 $this->total_tva += $line->total_tva;
3078 $this->total_ttc += $line->total_ttc;
3084 $this->total_ht = $xnbp * 100;
3085 $this->total_tva = $xnbp * 19.6;
3086 $this->total_ttc = $xnbp * 119.6;
3098 global $conf, $user;
3100 $this->nb = array();
3104 $sql =
"SELECT count(f.rowid) as nb";
3105 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
3106 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON f.fk_soc = s.rowid";
3107 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3108 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3109 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3112 $sql .=
" ".$clause.
" f.entity = ".$conf->entity;
3114 $resql = $this->db->query($sql);
3116 while ($obj = $this->db->fetch_object($resql)) {
3117 $this->nb[
"supplier_invoices"] = $obj->nb;
3119 $this->db->free($resql);
3123 $this->error = $this->db->error();
3138 global $conf, $langs;
3147 $object->fetch($fromid);
3152 $object->fetch_thirdparty();
3155 $object->ref_supplier = (empty($this->ref_supplier) ? $langs->trans(
"CopyOf").
' '.$object->ref_supplier : $this->ref_supplier);
3156 $object->author = $user->id;
3157 $object->user_validation_id = 0;
3158 $object->fk_facture_source = 0;
3159 $object->date_creation =
'';
3160 $object->date_validation =
'';
3161 $object->date = (empty($this->date) ?
dol_now() : $this->date);
3162 $object->ref_client =
'';
3163 $object->close_code =
'';
3164 $object->close_note =
'';
3166 $object->note_private =
'';
3167 $object->note_public =
'';
3170 $object->date_echeance = $object->calculate_date_lim_reglement();
3173 foreach ($object->lines as $i => $line) {
3174 if (isset($object->lines[$i]->info_bits) && ($object->lines[$i]->info_bits & 0x02) == 0x02) {
3175 unset($object->lines[$i]);
3180 $object->context[
'createfromclone'] =
'createfromclone';
3181 $result = $object->create($user);
3185 $this->error = $object->error;
3186 $this->errors = $object->errors;
3193 unset($object->context[
'createfromclone']);
3197 $this->db->commit();
3200 $this->db->rollback();
3216 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3218 global $conf, $user, $langs;
3220 $langs->load(
"suppliers");
3221 $outputlangs->load(
"products");
3224 if (empty($modele)) {
3226 $modele = $conf->global->INVOICE_SUPPLIER_ADDON_PDF;
3232 if (empty($modele)) {
3235 $modelpath =
"core/modules/supplier_invoice/doc/";
3237 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3249 return $user->hasRight(
"fournisseur",
"facture");
3297 if (!$this->date_echeance) {
3301 $status = isset($this->
status) ? $this->
status : $this->statut;
3303 return ($status == self::STATUS_VALIDATED) && ($this->date_echeance < ($now - $conf->facture->fournisseur->warning_delay));
3315 $sql =
"SELECT fk_invoice_supplier FROM ".MAIN_DB_PREFIX.
"societe_remise_except WHERE fk_invoice_supplier_source = ".((int) $this->
id);
3316 $resql = $this->db->query($sql);
3317 if (!empty($resql)) {
3318 $obj = $this->db->fetch_object($resql);
3319 if (!empty($obj->fk_invoice_supplier)) {
3337 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3339 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3340 $return .=
'<div class="info-box info-box-sm">';
3341 $return .=
'<span class="info-box-icon bg-infobox-action">';
3343 $return .=
'</span>';
3344 $return .=
'<div class="info-box-content">';
3345 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
3346 if ($selected >= 0) {
3347 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3349 if (!empty($arraydata[
'thirdparty'])) {
3350 $return .=
'<br><span class="info-box-label">'.$arraydata[
'thirdparty'].
'</span>';
3352 if (property_exists($this,
'date')) {
3353 $return .=
'<br><span class="info-box-label">'.dol_print_date($this->date,
'day').
'</span>';
3355 if (property_exists($this,
'total_ht')) {
3356 $return .=
' <span class="info-box-label amount" title="'.dol_escape_htmltag($langs->trans(
"AmountHT")).
'">'.
price($this->total_ht);
3357 $return .=
' '.$langs->trans(
"HT");
3358 $return .=
'</span>';
3360 if (method_exists($this,
'getLibStatut')) {
3361 $alreadypaid = (empty($arraydata[
'alreadypaid']) ? 0 : $arraydata[
'alreadypaid']);
3362 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3, $alreadypaid).
'</div>';
3364 $return .=
'</div>';
3365 $return .=
'</div>';
3366 $return .=
'</div>';
3378 if (!$this->table_element) {
3379 dol_syslog(get_class($this).
"::setVATReverseCharge was called on objet with property table_element not defined", LOG_ERR);
3383 dol_syslog(get_class($this).
'::setVATReverseCharge('.$vatreversecharge.
')');
3385 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
3386 $sql .=
" SET vat_reverse_charge = ".((int) $vatreversecharge);
3387 $sql .=
" WHERE rowid=".((int) $this->
id);
3389 if ($this->db->query($sql)) {
3390 $this->vat_reverse_charge = ($vatreversecharge == 0) ? 0 : 1;
3393 dol_syslog(get_class($this).
'::setVATReverseCharge Error ', LOG_DEBUG);
3394 $this->error = $this->db->error();
3410 public $element =
'facture_fourn_det';
3415 public $table_element =
'facture_fourn_det';
3429 public $product_ref;
3436 public $ref_supplier;
3442 public $product_desc;
3469 public $fk_facture_fourn;
3482 public $description;
3487 public $skip_update_total;
3492 public $situation_percent;
3503 public $vat_src_code;
3515 public $localtax1_tx;
3521 public $localtax2_tx;
3533 public $remise_percent;
3563 public $total_localtax1;
3569 public $total_localtax2;
3580 public $product_type;
3586 public $product_label;
3600 public $fk_remise_except;
3605 public $fk_parent_line;
3607 public $special_code;
3618 public $localtax1_type;
3624 public $localtax2_type;
3645 $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';
3646 $sql .=
', f.localtax1_type, f.localtax2_type, f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2, f.fk_remise_except';
3647 $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';
3648 $sql .=
', p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.description as product_desc';
3649 $sql .=
', f.multicurrency_subprice, f.multicurrency_total_ht, f.multicurrency_total_tva, multicurrency_total_ttc';
3650 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_det as f';
3651 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON f.fk_product = p.rowid';
3652 $sql .=
' WHERE f.rowid = '.((int) $rowid);
3653 $sql .=
' ORDER BY f.rang, f.rowid';
3655 $query = $this->db->query($sql);
3658 $this->errors[] = $this->db->error();
3662 if (!$this->db->num_rows($query)) {
3666 $obj = $this->db->fetch_object($query);
3668 $this->
id = $obj->rowid;
3669 $this->
rowid = $obj->rowid;
3670 $this->fk_facture_fourn = $obj->fk_facture_fourn;
3672 $this->date_start = $obj->date_start;
3673 $this->date_end = $obj->date_end;
3674 $this->product_ref = $obj->product_ref;
3675 $this->ref_supplier = $obj->ref_supplier;
3676 $this->product_desc = $obj->product_desc;
3678 $this->subprice = $obj->pu_ht;
3679 $this->pu_ht = $obj->pu_ht;
3680 $this->pu_ttc = $obj->pu_ttc;
3681 $this->tva_tx = $obj->tva_tx;
3682 $this->localtax1_tx = $obj->localtax1_tx;
3683 $this->localtax2_tx = $obj->localtax2_tx;
3684 $this->localtax1_type = $obj->localtax1_type;
3685 $this->localtax2_type = $obj->localtax2_type;
3687 $this->qty = $obj->qty;
3688 $this->remise_percent = $obj->remise_percent;
3689 $this->fk_remise_except = $obj->fk_remise_except;
3691 $this->total_ht = $obj->total_ht;
3692 $this->total_tva = $obj->total_tva;
3693 $this->total_localtax1 = $obj->total_localtax1;
3694 $this->total_localtax2 = $obj->total_localtax2;
3695 $this->total_ttc = $obj->total_ttc;
3696 $this->fk_product = $obj->fk_product;
3697 $this->product_type = $obj->product_type;
3698 $this->product_label = $obj->product_label;
3699 $this->info_bits = $obj->info_bits;
3700 $this->fk_parent_line = $obj->fk_parent_line;
3701 $this->special_code = $obj->special_code;
3702 $this->rang = $obj->rang;
3703 $this->fk_unit = $obj->fk_unit;
3705 $this->multicurrency_subprice = $obj->multicurrency_subprice;
3706 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
3707 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
3708 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
3721 public function delete($notrigger = 0)
3725 dol_syslog(get_class($this).
"::deleteline rowid=".((
int) $this->
id), LOG_DEBUG);
3732 if ($this->
call_trigger(
'LINEBILL_SUPPLIER_DELETE', $user) < 0) {
3744 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
3750 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'facture_fourn_det ';
3751 $sql .=
" WHERE rowid = ".((int) $this->
id);
3752 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
3753 $resql = $this->db->query($sql);
3756 $this->error = $this->db->lasterror();
3761 $this->db->commit();
3764 $this->db->rollback();
3783 if (empty($this->qty)) {
3787 if ($this->product_type < 0) {
3792 if (empty($this->remise_percent)) {
3793 $this->remise_percent = 0;
3795 if (empty($this->tva_tx)) {
3798 if (empty($this->localtax1_tx)) {
3799 $this->localtax1_tx = 0;
3801 if (empty($this->localtax2_tx)) {
3802 $this->localtax2_tx = 0;
3805 if (empty($this->pa_ht)) {
3808 if (empty($this->multicurrency_subprice)) {
3809 $this->multicurrency_subprice = 0;
3811 if (empty($this->multicurrency_total_ht)) {
3812 $this->multicurrency_total_ht = 0;
3814 if (empty($this->multicurrency_total_tva)) {
3815 $this->multicurrency_total_tva = 0;
3817 if (empty($this->multicurrency_total_ttc)) {
3818 $this->multicurrency_total_ttc = 0;
3821 $fk_product = (int) $this->fk_product;
3822 $fk_unit = (int) $this->fk_unit;
3826 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn_det SET";
3827 $sql .=
" description = '".$this->db->escape($this->
description).
"'";
3828 $sql .=
", ref = '".$this->db->escape($this->ref_supplier ? $this->ref_supplier :
$this->ref).
"'";
3829 $sql .=
", date_start = ".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
3830 $sql .=
", date_end = ".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
3831 $sql .=
", pu_ht = ".price2num($this->pu_ht);
3832 $sql .=
", pu_ttc = ".price2num($this->pu_ttc);
3833 $sql .=
", qty = ".price2num($this->qty);
3834 $sql .=
", remise_percent = ".price2num($this->remise_percent);
3835 if ($this->fk_remise_except > 0) {
3836 $sql .=
", fk_remise_except=".((int) $this->fk_remise_except);
3838 $sql .=
", fk_remise_except=null";
3840 $sql .=
", vat_src_code = '".$this->db->escape(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
3841 $sql .=
", tva_tx = ".price2num($this->tva_tx);
3842 $sql .=
", localtax1_tx = ".price2num($this->localtax1_tx);
3843 $sql .=
", localtax2_tx = ".price2num($this->localtax2_tx);
3844 $sql .=
", localtax1_type = '".$this->db->escape($this->localtax1_type).
"'";
3845 $sql .=
", localtax2_type = '".$this->db->escape($this->localtax2_type).
"'";
3846 $sql .=
", total_ht = ".price2num($this->total_ht);
3847 $sql .=
", tva= ".price2num($this->total_tva);
3848 $sql .=
", total_localtax1= ".price2num($this->total_localtax1);
3849 $sql .=
", total_localtax2= ".price2num($this->total_localtax2);
3850 $sql .=
", total_ttc = ".price2num($this->total_ttc);
3851 $sql .=
", fk_product = ".($fk_product > 0 ? (int) $fk_product :
'null');
3852 $sql .=
", product_type = ".((int) $this->product_type);
3853 $sql .=
", info_bits = ".((int) $this->info_bits);
3854 $sql .=
", fk_unit = ".($fk_unit > 0 ? (int) $fk_unit :
'null');
3856 if (!empty($this->rang)) {
3857 $sql .=
", rang=".((int) $this->rang);
3861 $sql .=
" , multicurrency_subprice=".price2num($this->multicurrency_subprice);
3862 $sql .=
" , multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
3863 $sql .=
" , multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
3864 $sql .=
" , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
3866 $sql .=
" WHERE rowid = ".((int) $this->
id);
3868 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
3869 $resql = $this->db->query($sql);
3872 $this->db->rollback();
3873 $this->error = $this->db->lasterror();
3877 $this->
rowid = $this->id;
3887 if (!$error && !$notrigger) {
3888 global $langs, $user;
3891 if ($this->
call_trigger(
'LINEBILL_SUPPLIER_MODIFY', $user) < 0) {
3892 $this->db->rollback();
3899 $this->db->rollback();
3903 $this->db->commit();
3914 public function insert($notrigger = 0, $noerrorifdiscountalreadylinked = 0)
3916 global $user, $langs;
3920 dol_syslog(get_class($this).
"::insert rang=".$this->rang, LOG_DEBUG);
3923 $this->desc = trim($this->desc);
3924 if (empty($this->tva_tx)) {
3927 if (empty($this->localtax1_tx)) {
3928 $this->localtax1_tx = 0;
3930 if (empty($this->localtax2_tx)) {
3931 $this->localtax2_tx = 0;
3933 if (empty($this->localtax1_type)) {
3934 $this->localtax1_type =
'0';
3936 if (empty($this->localtax2_type)) {
3937 $this->localtax2_type =
'0';
3939 if (empty($this->total_tva)) {
3940 $this->total_tva = 0;
3942 if (empty($this->total_localtax1)) {
3943 $this->total_localtax1 = 0;
3945 if (empty($this->total_localtax2)) {
3946 $this->total_localtax2 = 0;
3948 if (empty($this->rang)) {
3951 if (empty($this->remise_percent)) {
3952 $this->remise_percent = 0;
3954 if (empty($this->info_bits)) {
3955 $this->info_bits = 0;
3957 if (empty($this->subprice)) {
3958 $this->subprice = 0;
3960 if (empty($this->special_code)) {
3961 $this->special_code = 0;
3963 if (empty($this->fk_parent_line)) {
3964 $this->fk_parent_line = 0;
3966 if (!isset($this->situation_percent) || $this->situation_percent > 100 || (
string) $this->situation_percent ==
'') {
3967 $this->situation_percent = 100;
3970 if (empty($this->pa_ht)) {
3973 if (empty($this->multicurrency_subprice)) {
3974 $this->multicurrency_subprice = 0;
3976 if (empty($this->multicurrency_total_ht)) {
3977 $this->multicurrency_total_ht = 0;
3979 if (empty($this->multicurrency_total_tva)) {
3980 $this->multicurrency_total_tva = 0;
3982 if (empty($this->multicurrency_total_ttc)) {
3983 $this->multicurrency_total_ttc = 0;
3988 if ($this->product_type < 0) {
3989 $this->error =
'ErrorProductTypeMustBe0orMore';
3992 if (!empty($this->fk_product) && $this->fk_product > 0) {
3996 $this->error =
'ErrorProductIdDoesNotExists';
4004 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element;
4005 $sql .=
' (fk_facture_fourn, fk_parent_line, label, description, ref, qty,';
4006 $sql .=
' vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
4007 $sql .=
' fk_product, product_type, remise_percent, fk_remise_except, pu_ht, pu_ttc,';
4008 $sql .=
' date_start, date_end, fk_code_ventilation, rang, special_code,';
4009 $sql .=
' info_bits, total_ht, tva, total_ttc, total_localtax1, total_localtax2, fk_unit';
4010 $sql .=
', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
4012 $sql .=
" VALUES (".$this->fk_facture_fourn.
",";
4013 $sql .=
" ".($this->fk_parent_line > 0 ?
"'".$this->db->escape($this->fk_parent_line).
"'" :
"null").
",";
4014 $sql .=
" ".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
4015 $sql .=
" '".$this->db->escape($this->desc ? $this->desc : $this->description).
"',";
4016 $sql .=
" '".$this->db->escape($this->ref_supplier).
"',";
4017 $sql .=
" ".price2num($this->qty).
",";
4019 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
4020 $sql .=
" ".price2num($this->tva_tx).
",";
4021 $sql .=
" ".price2num($this->localtax1_tx).
",";
4022 $sql .=
" ".price2num($this->localtax2_tx).
",";
4023 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
4024 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
4025 $sql .=
' '.((!empty($this->fk_product) && $this->fk_product > 0) ? $this->fk_product :
"null").
',';
4026 $sql .=
" ".((int) $this->product_type).
",";
4027 $sql .=
" ".price2num($this->remise_percent).
",";
4028 $sql .=
' '.(!empty($this->fk_remise_except) ? ((int) $this->fk_remise_except) :
"null").
',';
4029 $sql .=
" ".price2num($this->subprice).
",";
4030 $sql .=
" ".(!empty($this->qty) ?
price2num($this->total_ttc / $this->qty) :
price2num($this->total_ttc)).
",";
4031 $sql .=
" ".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
4032 $sql .=
" ".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
4033 $sql .=
' '.(!empty($this->fk_code_ventilation) ? $this->fk_code_ventilation : 0).
',';
4034 $sql .=
' '.((int) $this->rang).
',';
4035 $sql .=
' '.((int) $this->special_code).
',';
4036 $sql .=
" ".((int) $this->info_bits).
",";
4037 $sql .=
" ".price2num($this->total_ht).
",";
4038 $sql .=
" ".price2num($this->total_tva).
",";
4039 $sql .=
" ".price2num($this->total_ttc).
",";
4040 $sql .=
" ".price2num($this->total_localtax1).
",";
4041 $sql .=
" ".price2num($this->total_localtax2);
4042 $sql .=
", ".(!$this->fk_unit ?
'NULL' : $this->fk_unit);
4043 $sql .=
", ".(int) $this->fk_multicurrency;
4044 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
4045 $sql .=
", ".price2num($this->multicurrency_subprice);
4046 $sql .=
", ".price2num($this->multicurrency_total_ht);
4047 $sql .=
", ".price2num($this->multicurrency_total_tva);
4048 $sql .=
", ".price2num($this->multicurrency_total_ttc);
4051 $resql = $this->db->query($sql);
4053 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
4054 $this->
rowid = $this->id;
4065 if ($this->fk_remise_except) {
4067 $result = $discount->fetch($this->fk_remise_except);
4072 if ($discount->fk_facture_line > 0) {
4073 if (empty($noerrorifdiscountalreadylinked)) {
4074 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed", $discount->id);
4075 dol_syslog(get_class($this).
"::insert Error ".$this->error, LOG_ERR);
4076 $this->db->rollback();
4080 $result = $discount->link_to_invoice($this->
rowid, 0);
4082 $this->error = $discount->error;
4083 dol_syslog(get_class($this).
"::insert Error ".$this->error, LOG_ERR);
4084 $this->db->rollback();
4089 $this->error = $langs->trans(
"ErrorADiscountThatHasBeenRemovedIsIncluded");
4090 dol_syslog(get_class($this).
"::insert Error ".$this->error, LOG_ERR);
4091 $this->db->rollback();
4095 $this->error = $discount->error;
4096 dol_syslog(get_class($this).
"::insert Error ".$this->error, LOG_ERR);
4097 $this->db->rollback();
4102 if (!$error && !$notrigger) {
4104 $result = $this->
call_trigger(
'LINEBILL_SUPPLIER_CREATE', $user);
4106 $this->db->rollback();
4112 $this->db->commit();
4115 $this->error = $this->db->error();
4116 $this->db->rollback();
4133 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn_det SET";
4134 $sql .=
" total_ht = ".price2num($this->total_ht);
4135 $sql .=
", tva= ".price2num($this->total_tva);
4136 $sql .=
", total_localtax1 = ".price2num($this->total_localtax1);
4137 $sql .=
", total_localtax2 = ".price2num($this->total_localtax2);
4138 $sql .=
", total_ttc = ".price2num($this->total_ttc);
4139 $sql .=
" WHERE rowid = ".((int) $this->
rowid);
4141 dol_syslog(
"FactureFournisseurLigne.class.php::update_total", LOG_DEBUG);
4143 $resql = $this->db->query($sql);
4145 $this->db->commit();
4148 $this->error = $this->db->error();
4149 $this->db->rollback();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
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)
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)
setDraft($user, $idwarehouse=-1, $notrigger=0)
Set draft status.
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.
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.
update($notrigger=0)
Update a supplier invoice line.
insert($notrigger=0, $noerrorifdiscountalreadylinked=0)
Insert line into database.
update_total()
Mise a jour de l'objet ligne de commande en base.
Class to manage translations.
Class to manage Dolibarr users.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_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 a 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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
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