41require_once DOL_DOCUMENT_ROOT.
'/core/class/commoninvoice.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.ligne.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/subtotals/class/commonsubtotal.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
49 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
62 public $element =
'invoice_supplier';
67 public $table_element =
'facture_fourn';
72 public $table_element_line =
'facture_fourn_det';
77 public $class_element_line =
'SupplierInvoiceLine';
81 public $fk_element =
'fk_facture_fourn';
86 public $picto =
'supplier_invoice';
92 public $restrictiononfksoc = 1;
112 public $ref_supplier;
172 public $fk_user_valid;
186 public $date_echeance;
216 public $total_localtax1;
218 public $total_localtax2;
229 public $note_private;
243 public $transport_mode_id;
248 public $vat_reverse_charge;
253 public $extraparams = array();
258 public $lines = array();
270 public $fk_facture_source;
275 public $fk_fac_rec_source;
277 public $fields = array(
278 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
279 'ref' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 15),
280 'ref_supplier' => array(
'type' =>
'varchar(255)',
'label' =>
'RefSupplier',
'enabled' => 1,
'visible' => -1,
'position' => 20),
281 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 25,
'index' => 1),
282 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 30),
283 'type' => array(
'type' =>
'smallint(6)',
'label' =>
'Type',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 35),
284 'subtype' => array(
'type' =>
'smallint(6)',
'label' =>
'InvoiceSubtype',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 36),
285 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'notnull' => 1,
'position' => 40),
286 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 45),
287 'datef' => array(
'type' =>
'date',
'label' =>
'Date',
'enabled' => 1,
'visible' => -1,
'position' => 50),
288 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 55),
289 'libelle' => array(
'type' =>
'varchar(255)',
'label' =>
'Label',
'enabled' => 1,
'visible' => -1,
'position' => 60),
290 'paye' => array(
'type' =>
'smallint(6)',
'label' =>
'Paye',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 65),
291 'amount' => array(
'type' =>
'double(24,8)',
'label' =>
'Amount',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 70),
292 'remise' => array(
'type' =>
'double(24,8)',
'label' =>
'Discount',
'enabled' => 1,
'visible' => -1,
'position' => 75),
293 'close_code' => array(
'type' =>
'varchar(16)',
'label' =>
'CloseCode',
'enabled' => 1,
'visible' => -1,
'position' => 80),
294 'close_note' => array(
'type' =>
'varchar(128)',
'label' =>
'CloseNote',
'enabled' => 1,
'visible' => -1,
'position' => 85),
295 'tva' => array(
'type' =>
'double(24,8)',
'label' =>
'Tva',
'enabled' => 1,
'visible' => -1,
'position' => 90),
296 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'Localtax1',
'enabled' => 1,
'visible' => -1,
'position' => 95),
297 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'Localtax2',
'enabled' => 1,
'visible' => -1,
'position' => 100),
298 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalHT',
'enabled' => 1,
'visible' => -1,
'position' => 105),
299 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalVAT',
'enabled' => 1,
'visible' => -1,
'position' => 110),
300 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalTTC',
'enabled' => 1,
'visible' => -1,
'position' => 115),
301 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -1,
'position' => 125),
302 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 130),
303 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 135),
304 'fk_facture_source' => array(
'type' =>
'integer',
'label' =>
'Fk facture source',
'enabled' => 1,
'visible' => -1,
'position' => 140),
305 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:fk_statut=1',
'label' =>
'Project',
'enabled' =>
"isModEnabled('project')",
'visible' => -1,
'position' => 145),
306 'fk_account' => array(
'type' =>
'integer',
'label' =>
'Account',
'enabled' =>
'isModEnabled("bank")',
'visible' => -1,
'position' => 150),
307 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentTerm',
'enabled' => 1,
'visible' => -1,
'position' => 155),
308 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => -1,
'position' => 160),
309 'date_lim_reglement' => array(
'type' =>
'date',
'label' =>
'DateLimReglement',
'enabled' => 1,
'visible' => -1,
'position' => 165),
310 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 170),
311 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 175),
312 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'ModelPdf',
'enabled' => 1,
'visible' => 0,
'position' => 180),
313 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 190),
314 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'IncotermCode',
'enabled' => 1,
'visible' => -1,
'position' => 195),
315 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'IncotermLocation',
'enabled' => 1,
'visible' => -1,
'position' => 200),
316 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'MulticurrencyId',
'enabled' => 1,
'visible' => -1,
'position' => 205),
317 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'MulticurrencyCode',
'enabled' => 1,
'visible' => -1,
'position' => 210),
318 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyRate',
'enabled' => 1,
'visible' => -1,
'position' => 215),
319 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyTotalHT',
'enabled' => 1,
'visible' => -1,
'position' => 220),
320 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyTotalVAT',
'enabled' => 1,
'visible' => -1,
'position' => 225),
321 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyTotalTTC',
'enabled' => 1,
'visible' => -1,
'position' => 230),
322 'date_pointoftax' => array(
'type' =>
'date',
'label' =>
'Date pointoftax',
'enabled' => 1,
'visible' => -1,
'position' => 235),
323 'date_valid' => array(
'type' =>
'date',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 240),
324 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'Last main doc',
'enabled' => 1,
'visible' => -1,
'position' => 245),
325 'fk_statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 500),
326 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 900),
378 const CLOSECODE_DISCOUNTVAT =
'discount_vat';
379 const CLOSECODE_BADCREDIT =
'badsupplier';
380 const CLOSECODE_ABANDONED =
'abandon';
381 const CLOSECODE_REPLACED =
'replaced';
393 $this->ismultientitymanaged = 1;
404 global $langs,
$conf, $hookmanager;
410 if (isset($this->ref_supplier)) {
411 $this->ref_supplier = trim($this->ref_supplier);
413 if (empty($this->
type)) {
416 if (empty($this->
date)) {
421 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
426 if (empty($this->fk_multicurrency)) {
427 $this->multicurrency_code =
$conf->currency;
428 $this->fk_multicurrency = 0;
429 $this->multicurrency_tx = 1;
436 $originaldatewhen = 0;
438 $previousdaynextdatewhen = 0;
442 if ($this->fac_rec > 0) {
443 $this->fk_fac_rec_source = $this->fac_rec;
445 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture-rec.class.php';
447 $result = $_facrec->fetch($this->fac_rec);
448 $result = $_facrec->fetchObjectLinked(
null,
'',
null,
'',
'OR', 1,
'sourcetype', 0);
451 if (!empty($_facrec->frequency)) {
452 $originaldatewhen = $_facrec->date_when;
453 $nextdatewhen =
dol_time_plus_duree($originaldatewhen, $_facrec->frequency, $_facrec->unit_frequency);
455 $this->socid = $_facrec->socid;
458 $this->entity = $_facrec->entity;
463 $this->fk_project =
GETPOSTINT(
'projectid') > 0 ? (
GETPOSTINT(
'projectid')) : $_facrec->fk_project;
464 $this->note_public =
GETPOST(
'note_public',
'restricthtml') ?
GETPOST(
'note_public',
'restricthtml') : $_facrec->note_public;
465 $this->note_private =
GETPOST(
'note_private',
'restricthtml') ?
GETPOST(
'note_private',
'restricthtml') : $_facrec->note_private;
466 $this->model_pdf =
GETPOST(
'model',
'alpha') ?
GETPOST(
'model',
'alpha') : $_facrec->model_pdf;
467 $this->cond_reglement_id =
GETPOSTINT(
'cond_reglement_id') > 0 ? (
GETPOSTINT(
'cond_reglement_id')) : $_facrec->cond_reglement_id;
468 $this->mode_reglement_id =
GETPOSTINT(
'mode_reglement_id') > 0 ? (
GETPOSTINT(
'mode_reglement_id')) : $_facrec->mode_reglement_id;
469 $this->fk_account =
GETPOST(
'fk_account') > 0 ? ((int)
GETPOST(
'fk_account')) : $_facrec->fk_account;
472 $this->total_ht = $_facrec->total_ht;
473 $this->total_ttc = $_facrec->total_ttc;
476 $this->fk_incoterms = $_facrec->fk_incoterms;
477 $this->location_incoterms = $_facrec->location_incoterms;
483 $this->note_public = trim($this->note_public);
484 $this->note_private = trim($this->note_private);
485 $this->note_private =
dol_concatdesc($this->note_private, $langs->trans(
"GeneratedFromRecurringInvoice", $_facrec->title));
487 $this->array_options = $_facrec->array_options;
489 if (! $this->mode_reglement_id) {
490 $this->mode_reglement_id = 0;
495 $this->linked_objects = $_facrec->linkedObjectsIds;
502 if ($_facrec->frequency > 0) {
503 $this->ref_supplier = trim($this->ref_supplier .
'_' . ($_facrec->nb_gen_done + 1));
504 dol_syslog(
"This is a recurring invoice so we set date_last_gen and next date_when");
505 if (empty($_facrec->date_when)) {
506 $_facrec->date_when = $now;
508 $next_date = $_facrec->getNextDate();
509 $result = $_facrec->setValueFrom(
'date_last_gen', $now,
'', 0,
'date',
'', $user,
'');
511 $result = $_facrec->setNextDate($next_date, 1);
515 $outputlangs = $langs;
518 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($this->thirdparty->default_lang)) {
519 $newlang = $this->thirdparty->default_lang;
521 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && property_exists($this,
'default_lang') && isset($this->default_lang)) {
522 $newlang = $this->default_lang;
524 if (!empty($newlang)) {
526 $outputlangs->setDefaultLang($newlang);
528 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $this);
538 $substitutionarray[
'__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = $originaldatewhen ?
dol_print_date($originaldatewhen,
'dayhour') :
'';
539 $substitutionarray[
'__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = $nextdatewhen ?
dol_print_date($nextdatewhen,
'dayhour') :
'';
540 $substitutionarray[
'__INVOICE_PREVIOUS_DATE_NEXT_INVOICE_AFTER_GEN__'] = $previousdaynextdatewhen ?
dol_print_date($previousdaynextdatewhen,
'dayhour') :
'';
541 $substitutionarray[
'__INVOICE_COUNTER_CURRENT__'] = $_facrec->nb_gen_done;
542 $substitutionarray[
'__INVOICE_COUNTER_MAX__'] = $_facrec->nb_gen_max;
551 if (!empty($forceduedate)) {
552 $this->date_echeance = $forceduedate;
555 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facture_fourn (";
557 $sql .=
", ref_supplier";
566 $sql .=
", vat_reverse_charge";
567 $sql .=
", fk_projet";
568 $sql .=
", fk_cond_reglement";
569 $sql .=
", fk_mode_reglement";
570 $sql .=
", fk_account";
571 $sql .=
", note_private";
572 $sql .=
", note_public";
573 $sql .=
", fk_user_author";
574 $sql .=
", date_lim_reglement";
575 $sql .=
", fk_incoterms, location_incoterms";
576 $sql .=
", fk_multicurrency";
577 $sql .=
", multicurrency_code";
578 $sql .=
", multicurrency_tx";
579 $sql .=
", fk_facture_source";
580 $sql .=
", fk_fac_rec_source";
584 $sql .=
", '".$this->db->escape($this->ref_supplier).
"'";
585 $sql .=
", '".$this->db->escape($this->ref_ext).
"'";
586 $sql .=
", ".((int) $this->entity);
587 $sql .=
", '".$this->db->escape((
string) $this->type).
"'";
588 $sql .=
", ".(isset($this->subtype) ? (int) $this->subtype :
"null");
589 $sql .=
", '".$this->db->escape(isset($this->label) ? $this->label : (isset($this->libelle) ? $this->libelle :
'')).
"'";
590 $sql .=
", ".((int) $this->socid);
591 $sql .=
", '".$this->db->idate($now).
"'";
592 $sql .=
", '".$this->db->idate($this->
date).
"'";
593 $sql .=
", ".($this->vat_reverse_charge !=
'' ? ((int) $this->vat_reverse_charge) : 0);
594 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
595 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
"null");
596 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"null");
597 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
598 $sql .=
", '".$this->db->escape($this->note_private).
"'";
599 $sql .=
", '".$this->db->escape($this->note_public).
"'";
600 $sql .=
", ".((int) $user->id).
",";
601 $sql .= $this->date_echeance !=
'' ?
"'".$this->db->idate($this->date_echeance).
"'" :
"null";
602 $sql .=
", ".(int) $this->fk_incoterms;
603 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
604 $sql .=
", ".(int) $this->fk_multicurrency;
605 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
606 $sql .=
", ".(float) $this->multicurrency_tx;
607 $sql .=
", ".($this->fk_facture_source ? ((int) $this->fk_facture_source) :
"null");
608 $sql .=
", ".(isset($this->fk_fac_rec_source) ? $this->fk_fac_rec_source :
"NULL");
611 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
612 $resql = $this->db->query($sql);
614 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn');
617 $this->
ref =
'(PROV'.$this->id.
')';
618 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"facture_fourn SET ref='".$this->db->escape($this->
ref).
"' WHERE rowid=".((int) $this->
id);
620 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
621 $resql = $this->db->query($sql);
626 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
627 $this->linked_objects = $this->linkedObjectsIds;
631 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
632 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
633 if (is_array($tmp_origin_id)) {
634 foreach ($tmp_origin_id as $origin_id) {
642 $origin_id = $tmp_origin_id;
652 if (!$error && empty($this->fac_rec) && count($this->lines) && is_object($this->lines[0])) {
653 dol_syslog(
"There is ".count($this->lines).
" lines that are invoice lines objects");
654 foreach ($this->lines as $i => $val) {
655 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'facture_fourn_det (fk_facture_fourn, special_code, fk_remise_except)';
656 $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').
')';
658 $resql_insert = $this->db->query($sql);
660 $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn_det');
664 $this->lines[$i]->desc ? $this->lines[$i]->desc : $this->lines[$i]->description,
665 $this->lines[$i]->subprice,
666 $this->lines[$i]->tva_tx.($this->lines[$i]->vat_src_code ?
' ('.$this->lines[$i]->vat_src_code.
')' :
''),
667 $this->lines[$i]->localtax1_tx,
668 $this->lines[$i]->localtax2_tx,
669 $this->lines[$i]->qty,
670 $this->lines[$i]->fk_product,
672 (!empty($this->lines[$i]->info_bits) ? $this->lines[$i]->info_bits :
''),
673 $this->lines[$i]->product_type,
674 $this->lines[$i]->remise_percent,
676 $this->lines[$i]->date_start,
677 $this->lines[$i]->date_end,
678 $this->lines[$i]->array_options,
679 $this->lines[$i]->fk_unit,
680 $this->lines[$i]->multicurrency_subprice,
681 $this->lines[$i]->ref_supplier
684 $this->error = $this->db->lasterror();
685 $this->db->rollback();
689 } elseif (!$error && empty($this->fac_rec)) {
690 dol_syslog(
"There is ".count($this->lines).
" lines that are array lines");
691 foreach ($this->lines as $i => $val) {
692 $line = $this->lines[$i];
696 if (!is_object($line)) {
697 $line = (object) $line;
700 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'facture_fourn_det (fk_facture_fourn, special_code, fk_remise_except)';
701 $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').
')';
703 $resql_insert = $this->db->query($sql);
705 $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn_det');
709 $line->desc ? $line->desc : $line->description,
717 (!empty($line->info_bits) ? $line->info_bits :
''),
719 $line->remise_percent,
723 $line->array_options,
725 $line->multicurrency_subprice,
729 $this->error = $this->db->lasterror();
730 $this->db->rollback();
740 foreach ($_facrec->lines as $i => $val) {
741 $product_type = $_facrec->lines[$i]->product_type;
742 if ($_facrec->lines[$i]->fk_product) {
744 $res =
$prod->fetch($_facrec->lines[$i]->fk_product);
755 $tva_tx = $_facrec->lines[$i]->tva_tx . ($_facrec->lines[$i]->vat_src_code ?
'(' . $_facrec->lines[$i]->vat_src_code .
')' :
'');
756 $tva_npr = $_facrec->lines[$i]->info_bits;
757 if (empty($tva_tx)) {
760 $localtax1_tx = $_facrec->lines[$i]->localtax1_tx;
761 $localtax2_tx = $_facrec->lines[$i]->localtax2_tx;
765 $buyprice = empty($_facrec->lines[$i]->buyprice) ? 0 : $_facrec->lines[$i]->buyprice;
768 if (! $buyprice && $_facrec->lines[$i]->fk_product > 0) {
769 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.product.class.php';
771 $producttmp->fetch($_facrec->lines[$i]->fk_product);
776 if (
getDolGlobalString(
'MARGIN_TYPE') ==
'costprice' && !empty($producttmp->cost_price)) {
777 $buyprice = $producttmp->cost_price;
779 $buyprice = $producttmp->pmp;
781 if ($producttmp->find_min_price_product_fournisseur($_facrec->lines[$i]->fk_product) > 0) {
782 if ($producttmp->product_fourn_price_id > 0) {
783 $buyprice =
price2num($producttmp->fourn_unitprice * (1 - $producttmp->fourn_remise_percent / 100) + $producttmp->fourn_remise,
'MU');
789 $result_insert = $this->
addline(
790 $_facrec->lines[$i]->desc ? $_facrec->lines[$i]->desc : $_facrec->lines[$i]->description,
791 $_facrec->lines[$i]->pu_ht,
795 $_facrec->lines[$i]->qty,
796 $_facrec->lines[$i]->fk_product,
797 $_facrec->lines[$i]->remise_percent,
798 ($_facrec->lines[$i]->date_start == 1 && $this->date) ? $this->
date :
'',
799 ($_facrec->lines[$i]->date_end == 1 && $previousdaynextdatewhen) ? $previousdaynextdatewhen :
'',
801 $_facrec->lines[$i]->info_bits,
804 $_facrec->lines[$i]->rang,
806 $_facrec->lines[$i]->array_options,
807 $_facrec->lines[$i]->fk_unit,
810 $_facrec->lines[$i]->ref_supplier,
811 $_facrec->lines[$i]->special_code,
815 if ($result_insert < 0) {
817 $this->error = $this->db->error();
837 $result = $this->call_trigger(
'BILL_SUPPLIER_CREATE', $user);
848 $this->db->rollback();
852 $this->error = $langs->trans(
'FailedToUpdatePrice');
853 $this->db->rollback();
857 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
858 $this->error = $langs->trans(
'ErrorRefAlreadyExists');
859 $this->db->rollback();
862 $this->error = $this->db->lasterror();
863 $this->db->rollback();
877 public function fetch($id = 0, $ref =
'', $ref_ext =
'')
879 if (empty($id) && empty($ref) && empty($ref_ext)) {
886 $sql .=
" t.ref_supplier,";
887 $sql .=
" t.ref_ext,";
888 $sql .=
" t.entity,";
890 $sql .=
" t.subtype,";
891 $sql .=
" t.fk_soc,";
894 $sql .=
" t.tms as datem,";
895 $sql .=
" t.libelle as label,";
896 $sql .=
" t.paye as paid,";
897 $sql .=
" t.close_code,";
898 $sql .=
" t.close_note,";
900 $sql .=
" t.localtax1,";
901 $sql .=
" t.localtax2,";
902 $sql .=
" t.total_ht,";
903 $sql .=
" t.total_tva,";
904 $sql .=
" t.total_ttc,";
905 $sql .=
" t.fk_statut as status,";
906 $sql .=
" t.fk_user_author,";
907 $sql .=
" t.fk_user_valid,";
908 $sql .=
" t.fk_facture_source,";
909 $sql .=
" t.vat_reverse_charge,";
910 $sql .=
" t.fk_fac_rec_source,";
911 $sql .=
" t.fk_projet as fk_project,";
912 $sql .=
" t.fk_cond_reglement,";
913 $sql .=
" t.fk_account,";
914 $sql .=
" t.fk_mode_reglement,";
915 $sql .=
" t.date_lim_reglement,";
916 $sql .=
" t.note_private,";
917 $sql .=
" t.note_public,";
918 $sql .=
" t.model_pdf,";
919 $sql .=
" t.last_main_doc,";
920 $sql .=
" t.import_key,";
921 $sql .=
" t.extraparams,";
922 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc,";
923 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_label,";
924 $sql .=
' s.nom as socnom, s.rowid as socid,';
925 $sql .=
' t.fk_incoterms, t.location_incoterms,';
926 $sql .=
" i.libelle as label_incoterms,";
927 $sql .=
' t.fk_transport_mode,';
928 $sql .=
' t.fk_multicurrency, t.multicurrency_code, t.multicurrency_tx, t.multicurrency_total_ht, t.multicurrency_total_tva, t.multicurrency_total_ttc';
929 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn as t';
930 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON (t.fk_soc = s.rowid)";
931 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_payment_term as cr ON t.fk_cond_reglement = cr.rowid";
932 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as p ON t.fk_mode_reglement = p.id";
933 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON t.fk_incoterms = i.rowid';
935 $sql .=
" WHERE t.rowid = ".((int) $id);
937 $sql .=
' WHERE t.entity IN ('.getEntity(
'supplier_invoice').
')';
939 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
942 $sql .=
" AND t.ref_ext = '".$this->db->escape($ref_ext).
"'";
946 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
947 $resql = $this->db->query($sql);
949 if ($this->db->num_rows($resql)) {
950 $obj = $this->db->fetch_object($resql);
952 $this->
id = $obj->rowid;
953 $this->
ref = $obj->ref ? $obj->ref : $obj->rowid;
955 $this->ref_supplier = $obj->ref_supplier;
956 $this->ref_ext = $obj->ref_ext;
957 $this->entity = $obj->entity;
959 $this->subtype = $obj->subtype;
960 $this->socid = $obj->fk_soc;
961 $this->
date = $this->db->jdate($obj->datef);
962 $this->date_creation = $this->db->jdate($obj->datec);
963 $this->datec = $this->db->jdate($obj->datec);
964 $this->date_modification = $this->db->jdate($obj->datem);
965 $this->tms = $this->db->jdate($obj->datem);
966 $this->libelle = $obj->label;
967 $this->label = $obj->label;
968 $this->paye = $obj->paid;
969 $this->paid = $obj->paid;
970 $this->close_code = $obj->close_code;
971 $this->close_note = $obj->close_note;
972 $this->total_localtax1 = $obj->localtax1;
973 $this->total_localtax2 = $obj->localtax2;
974 $this->total_ht = $obj->total_ht;
975 $this->total_tva = $obj->total_tva;
976 $this->total_ttc = $obj->total_ttc;
977 $this->
status = $obj->status;
978 $this->statut = $obj->status;
979 $this->fk_statut = $obj->status;
980 $this->user_creation_id = $obj->fk_user_author;
981 $this->author = $obj->fk_user_author;
982 $this->user_validation_id = $obj->fk_user_valid;
983 $this->fk_user_valid = $obj->fk_user_valid;
984 $this->fk_facture_source = $obj->fk_facture_source;
985 $this->vat_reverse_charge = empty($obj->vat_reverse_charge) ? 0 : 1;
986 $this->fk_fac_rec_source = $obj->fk_fac_rec_source;
987 $this->fk_project = $obj->fk_project;
988 $this->cond_reglement_id = $obj->fk_cond_reglement;
989 $this->cond_reglement_code = $obj->cond_reglement_code;
990 $this->cond_reglement = $obj->cond_reglement_label;
991 $this->cond_reglement_label = $obj->cond_reglement_label;
992 $this->cond_reglement_doc = $obj->cond_reglement_doc;
993 $this->fk_account = $obj->fk_account;
994 $this->mode_reglement_id = $obj->fk_mode_reglement;
995 $this->mode_reglement_code = $obj->mode_reglement_code;
996 $this->mode_reglement = $obj->mode_reglement_label;
997 $this->date_echeance = $this->db->jdate($obj->date_lim_reglement);
998 $this->note = $obj->note_private;
999 $this->note_private = $obj->note_private;
1000 $this->note_public = $obj->note_public;
1001 $this->model_pdf = $obj->model_pdf;
1002 $this->last_main_doc = $obj->last_main_doc;
1003 $this->import_key = $obj->import_key;
1006 $this->fk_incoterms = $obj->fk_incoterms;
1007 $this->location_incoterms = $obj->location_incoterms;
1008 $this->label_incoterms = $obj->label_incoterms;
1009 $this->transport_mode_id = $obj->fk_transport_mode;
1012 $this->fk_multicurrency = $obj->fk_multicurrency;
1013 $this->multicurrency_code = $obj->multicurrency_code;
1014 $this->multicurrency_tx = $obj->multicurrency_tx;
1015 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
1016 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
1017 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1019 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
1021 $this->socid = $obj->socid;
1023 $this->thirdparty =
null;
1031 $this->error = $this->db->lasterror();
1035 $this->error =
'Bill with id '.$id.
' not found';
1036 dol_syslog(get_class($this).
'::fetch '.$this->error);
1040 $this->db->free($resql);
1043 $this->error =
"Error ".$this->db->lasterror();
1058 $this->lines = array();
1060 $sql =
'SELECT f.rowid, f.ref as ref_supplier, f.description as line_desc, f.date_start, f.date_end, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.vat_src_code, f.tva_tx';
1061 $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';
1062 $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, f.extraparams';
1063 $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';
1064 $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';
1065 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_det as f';
1066 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON f.fk_product = p.rowid';
1067 $sql .=
' WHERE fk_facture_fourn='.((int) $this->
id);
1068 $sql .=
' ORDER BY f.rang, f.rowid';
1070 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1072 $resql_rows = $this->db->query($sql);
1074 $num_rows = $this->db->num_rows($resql_rows);
1077 while ($i < $num_rows) {
1078 $obj = $this->db->fetch_object($resql_rows);
1082 $line->id = $obj->rowid;
1083 $line->rowid = $obj->rowid;
1085 $line->description = $obj->line_desc;
1086 $line->desc = $obj->line_desc;
1087 $line->date_start = $this->db->jdate($obj->date_start);
1088 $line->date_end = $this->db->jdate($obj->date_end);
1090 $line->product_ref = $obj->product_ref;
1091 $line->ref = $obj->product_ref;
1092 $line->ref_supplier = $obj->ref_supplier;
1093 $line->libelle = $obj->label;
1094 $line->label = $obj->label;
1095 $line->product_barcode = $obj->product_barcode;
1096 $line->product_desc = $obj->product_desc;
1097 $line->subprice = $obj->pu_ht;
1098 $line->pu_ht = $obj->pu_ht;
1099 $line->subprice_ttc = $obj->pu_ttc;
1100 $line->pu_ttc = $obj->pu_ttc;
1101 $line->vat_src_code = $obj->vat_src_code;
1102 $line->tva_tx = $obj->tva_tx;
1103 $line->localtax1_tx = $obj->localtax1_tx;
1104 $line->localtax2_tx = $obj->localtax2_tx;
1105 $line->localtax1_type = $obj->localtax1_type;
1106 $line->localtax2_type = $obj->localtax2_type;
1107 $line->qty = $obj->qty;
1108 $line->remise_percent = $obj->remise_percent;
1109 $line->fk_remise_except = $obj->fk_remise_except;
1111 $line->total_ht = $obj->total_ht;
1112 $line->total_ttc = $obj->total_ttc;
1113 $line->total_tva = $obj->total_tva;
1114 $line->total_localtax1 = $obj->total_localtax1;
1115 $line->total_localtax2 = $obj->total_localtax2;
1116 $line->fk_facture_fourn = $obj->fk_facture_fourn;
1117 $line->fk_product = $obj->fk_product;
1118 $line->product_type = $obj->product_type;
1119 $line->product_label = $obj->label;
1120 $line->info_bits = $obj->info_bits;
1121 $line->fk_parent_line = $obj->fk_parent_line;
1122 $line->special_code = $obj->special_code;
1123 $line->rang = $obj->rang;
1124 $line->fk_unit = $obj->fk_unit;
1126 $line->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
1129 $line->fk_code_ventilation = $obj->fk_code_ventilation;
1132 $line->fk_multicurrency = $obj->fk_multicurrency;
1133 $line->multicurrency_code = $obj->multicurrency_code;
1134 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1135 $line->multicurrency_total_ht = $obj->multicurrency_total_ht;
1136 $line->multicurrency_total_tva = $obj->multicurrency_total_tva;
1137 $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1140 $line->fetch_optionals();
1142 $this->lines[$i] = $line;
1147 $this->db->free($resql_rows);
1150 $this->error = $this->db->error();
1151 dol_syslog(get_class($this).
"::fetch_lines - No lines:{$this->error} Error:{$this->error}", LOG_DEBUG);
1164 public function update($user =
null, $notrigger = 0)
1170 if (empty($this->
type)) {
1173 if (isset($this->
ref)) {
1174 $this->
ref = trim($this->
ref);
1176 if (isset($this->ref_supplier)) {
1177 $this->ref_supplier = trim($this->ref_supplier);
1179 if (isset($this->ref_ext)) {
1180 $this->ref_ext = trim($this->ref_ext);
1182 if (isset($this->entity)) {
1183 $this->entity = (int) $this->entity;
1185 if (isset($this->
type)) {
1188 if (isset($this->subtype)) {
1189 $this->subtype = (int) $this->subtype;
1191 if (isset($this->socid)) {
1192 $this->socid = (int) $this->socid;
1194 if (isset($this->label)) {
1195 $this->label = trim($this->label);
1197 if (isset($this->paid)) {
1198 $this->paid = (int) (
bool) $this->paid;
1199 $this->paye = $this->paid;
1200 } elseif (isset($this->paye)) {
1201 $this->paid = (int) (
bool) $this->paye;
1202 $this->paye = $this->paid;
1204 if (isset($this->close_code)) {
1205 $this->close_code = trim($this->close_code);
1207 if (isset($this->close_note)) {
1208 $this->close_note = trim($this->close_note);
1210 if (empty($this->total_ht)) {
1211 $this->total_ht = 0;
1213 if (empty($this->total_tva)) {
1214 $this->total_tva = 0;
1216 if (empty($this->total_localtax1)) {
1217 $this->total_localtax1 = 0;
1219 if (empty($this->total_localtax2)) {
1220 $this->total_localtax2 = 0;
1222 if (isset($this->total_ttc)) {
1223 $this->total_ttc = (float) $this->total_ttc;
1225 if (isset($this->
status)) {
1227 $this->statut = $this->status;
1228 } elseif (isset($this->statut)) {
1229 $this->
status = (int) $this->statut;
1230 $this->statut = $this->status;
1232 if (isset($this->author)) {
1233 $this->author = (int) $this->author;
1235 if (isset($this->fk_user_valid)) {
1236 $this->fk_user_valid = (int) $this->fk_user_valid;
1238 if (isset($this->fk_facture_source)) {
1239 $this->fk_facture_source = (int) $this->fk_facture_source;
1241 if (isset($this->fk_project)) {
1242 if (empty($this->fk_project)) {
1243 $this->fk_project = 0;
1245 $this->fk_project = (int) $this->fk_project;
1248 if (isset($this->mode_reglement_id)) {
1249 $this->mode_reglement_id = (int) $this->mode_reglement_id;
1251 if (isset($this->cond_reglement_id)) {
1252 $this->cond_reglement_id = (int) $this->cond_reglement_id;
1254 if (isset($this->note_private)) {
1255 $this->note_private = trim($this->note_private);
1256 $this->note = $this->note_private;
1258 if (isset($this->note_public)) {
1259 $this->note_public = trim($this->note_public);
1261 if (isset($this->model_pdf)) {
1262 $this->model_pdf = trim($this->model_pdf);
1264 if (isset($this->import_key)) {
1265 $this->import_key = trim($this->import_key);
1273 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn SET";
1274 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1275 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1276 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1277 $sql .=
" entity=".(isset($this->entity) ? ((int) $this->entity) :
"null").
",";
1278 $sql .=
" type=".(isset($this->
type) ? ((int) $this->
type) :
"null").
",";
1279 $sql .=
" subtype=".(isset($this->subtype) ? (int) $this->subtype :
"null").
",";
1280 $sql .=
" fk_soc=".(isset($this->socid) ? ((int) $this->socid) :
"null").
",";
1281 $sql .=
" datec=".(dol_strlen((
string) $this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
1282 $sql .=
" datef=".(dol_strlen((
string) $this->date) != 0 ?
"'".$this->db->idate($this->date).
"'" :
'null').
",";
1283 if (
dol_strlen((
string) $this->date_modification) != 0) {
1284 $sql .=
" tms=".(dol_strlen((
string) $this->date_modification) != 0 ?
"'".$this->db->idate($this->date_modification).
"'" :
'null').
",";
1285 } elseif (
dol_strlen((
string) $this->tms) != 0) {
1286 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
1288 $sql .=
" libelle=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
1289 $sql .=
" paye=".(isset($this->paid) ? ((int) $this->paid) :
"0").
",";
1290 $sql .=
" close_code=".(isset($this->close_code) ?
"'".$this->db->escape($this->close_code).
"'" :
"null").
",";
1291 $sql .=
" close_note=".(isset($this->close_note) ?
"'".$this->db->escape($this->close_note).
"'" :
"null").
",";
1292 $sql .=
" localtax1=".(isset($this->total_localtax1) ? ((float) $this->total_localtax1) :
"null").
",";
1293 $sql .=
" localtax2=".(isset($this->total_localtax2) ? ((float) $this->total_localtax2) :
"null").
",";
1294 $sql .=
" total_ht=".(isset($this->total_ht) ? ((float) $this->total_ht) :
"null").
",";
1295 $sql .=
" total_tva=".(isset($this->total_tva) ? ((float) $this->total_tva) :
"null").
",";
1296 $sql .=
" total_ttc=".(isset($this->total_ttc) ? ((float) $this->total_ttc) :
"null").
",";
1297 $sql .=
" fk_statut=".(isset($this->
status) ? ((int) $this->
status) : (isset($this->statut) ? ((int) $this->statut) :
"null")).
",";
1298 $sql .=
" fk_user_author=".(isset($this->author) ? ((int) $this->author) :
"null").
",";
1299 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? ((int) $this->fk_user_valid) :
"null").
",";
1300 $sql .=
" fk_facture_source=".($this->fk_facture_source ? ((int) $this->fk_facture_source) :
"null").
",";
1301 $sql .=
" vat_reverse_charge = ".($this->vat_reverse_charge !=
'' ? ((int) $this->vat_reverse_charge) : 0).
",";
1302 $sql .=
" fk_projet=".(!empty($this->fk_project) ? ((int) $this->fk_project) :
"null").
",";
1303 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? ((int) $this->mode_reglement_id) :
"null").
",";
1304 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? ((int) $this->cond_reglement_id) :
"null").
",";
1305 $sql .=
" date_lim_reglement=".(dol_strlen((
string) $this->date_echeance) != 0 ?
"'".$this->db->idate($this->date_echeance).
"'" :
'null').
",";
1306 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1307 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1308 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1309 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1310 $sql .=
" WHERE rowid=".((int) $this->
id);
1314 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1315 $resql = $this->db->query($sql);
1320 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1321 $this->errors[] = $langs->trans(
'ErrorRefAlreadyExists');
1323 $this->errors[] =
"Error ".$this->db->lasterror();
1334 if (!$error && !$notrigger) {
1336 $result = $this->call_trigger(
'BILL_SUPPLIER_MODIFY', $user);
1345 foreach ($this->errors as $errmsg) {
1346 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1347 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1349 $this->db->rollback();
1352 $this->db->commit();
1367 global
$conf, $langs;
1369 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1370 include_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1375 $result = $remise->fetch($idremise);
1378 if ($remise->fk_invoice_supplier) {
1379 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed");
1380 $this->db->rollback();
1385 $facligne->fk_facture_fourn = $this->id;
1386 $facligne->fk_remise_except = $remise->id;
1387 $facligne->desc = $remise->description;
1388 $facligne->vat_src_code = $remise->vat_src_code;
1389 $facligne->tva_tx = $remise->tva_tx;
1390 $facligne->localtax1_tx = $remise->localtax1_tx;
1391 $facligne->localtax1_type = $remise->localtax1_type;
1392 $facligne->localtax2_tx = $remise->localtax1_tx;
1393 $facligne->localtax2_type = $remise->localtax1_type;
1394 $facligne->subprice = -(float) $remise->amount_ht;
1395 $facligne->fk_product = 0;
1396 $facligne->product_type = 0;
1398 $facligne->remise_percent = 0;
1399 $facligne->rang = -1;
1400 $facligne->info_bits = 2;
1403 $facligne->rang = 1;
1404 $linecount = count($this->lines);
1405 for ($ii = 1; $ii <= $linecount; $ii++) {
1411 if ($remise->fk_invoice_supplier_source > 0) {
1413 $srcinvoice->fetch($remise->fk_invoice_supplier_source);
1414 $totalcostpriceofinvoice = 0;
1415 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
1417 $arraytmp = $formmargin->getMarginInfosArray($srcinvoice,
false);
1418 $facligne->pa_ht = $arraytmp[
'pa_total'];
1421 $facligne->total_ht = -(float) $remise->amount_ht;
1422 $facligne->total_tva = -(float) $remise->amount_tva;
1423 $facligne->total_ttc = -(float) $remise->amount_ttc;
1424 $facligne->total_localtax1 = -(float) $remise->total_localtax1;
1425 $facligne->total_localtax2 = -(float) $remise->total_localtax2;
1427 $facligne->multicurrency_subprice = -$remise->multicurrency_subprice;
1428 $facligne->multicurrency_total_ht = -$remise->multicurrency_total_ht;
1429 $facligne->multicurrency_total_tva = -$remise->multicurrency_total_tva;
1430 $facligne->multicurrency_total_ttc = -$remise->multicurrency_total_ttc;
1432 $lineid = $facligne->insert();
1437 $result = $remise->link_to_invoice($lineid, 0);
1439 $this->error = $remise->error;
1440 $this->db->rollback();
1444 $this->db->commit();
1447 $this->error = $facligne->error;
1448 $this->db->rollback();
1452 $this->error = $facligne->error;
1453 $this->db->rollback();
1457 $this->db->rollback();
1470 public function delete(
User $user, $notrigger = 0)
1476 dol_syslog(
"FactureFournisseur::delete rowid=".$rowid, LOG_DEBUG);
1485 $result = $this->call_trigger(
'BILL_SUPPLIER_DELETE', $user);
1487 $this->db->rollback();
1494 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_remise_except';
1495 $sql .=
' WHERE fk_invoice_supplier_source = '.((int) $rowid);
1496 $sql .=
' AND fk_invoice_supplier_line IS NULL';
1497 $resql = $this->db->query($sql);
1501 $list_rowid_det = array();
1502 foreach ($this->lines as $key => $invoiceline) {
1503 $list_rowid_det[] = $invoiceline->id;
1507 if (count($list_rowid_det)) {
1508 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe_remise_except';
1509 $sql .=
' SET fk_invoice_supplier = NULL, fk_invoice_supplier_line = NULL';
1510 $sql .=
' WHERE fk_invoice_supplier_line IN ('.$this->db->sanitize(implode(
',', $list_rowid_det)).
')';
1512 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1513 if (!$this->db->query($sql)) {
1519 $main = MAIN_DB_PREFIX.
'facture_fourn_det';
1520 $ef = $main.
"_extrafields";
1521 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_facture_fourn = ".((int) $rowid).
")";
1522 $resqlef = $this->db->query($sqlef);
1523 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'facture_fourn_det WHERE fk_facture_fourn = '.((int) $rowid);
1524 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1525 $resql = $this->db->query($sql);
1526 if ($resqlef && $resql) {
1527 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'facture_fourn WHERE rowid = '.((int) $rowid);
1528 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1529 $resql2 = $this->db->query($sql);
1552 if ($conf->fournisseur->facture->dir_output) {
1553 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1556 $dir =
$conf->fournisseur->facture->dir_output.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$ref;
1557 $file = $dir.
"/".$ref.
".pdf";
1558 if (file_exists($file)) {
1560 $this->error =
'ErrorFailToDeleteFile';
1564 if (file_exists($dir)) {
1568 $this->error =
'ErrorFailToDeleteDir';
1577 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_invoice";
1578 $sql .=
" WHERE fk_invoice = ".((int) $this->
id);
1580 $result = $this->db->query($sql);
1583 $this->errors[] = $this->db->lasterror();
1592 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
1597 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
1598 $this->db->commit();
1601 $this->error = $this->db->lasterror();
1602 $this->db->rollback();
1619 public function set_paid($user, $close_code =
'', $close_note =
'')
1622 dol_syslog(get_class($this).
"::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
1623 return $this->
setPaid($user, $close_code, $close_note);
1634 public function setPaid($user, $close_code =
'', $close_note =
'')
1638 if ($this->paid != 1) {
1643 dol_syslog(
"FactureFournisseur::setPaid", LOG_DEBUG);
1645 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture_fourn SET';
1646 $sql .=
' fk_statut = '.self::STATUS_CLOSED;
1651 $sql .=
", close_code='".$this->db->escape($close_code).
"'";
1654 $sql .=
", close_note='".$this->db->escape($close_note).
"'";
1656 $sql .=
', fk_user_closing = '.((int) $user->id);
1657 $sql .=
", date_closing = '".$this->db->idate($now).
"'";
1658 $sql .=
' WHERE rowid = '.((int) $this->
id);
1660 $resql = $this->db->query($sql);
1663 $result = $this->call_trigger(
'BILL_SUPPLIER_PAYED', $user);
1670 $this->error = $this->db->error();
1675 $this->db->commit();
1678 $this->db->rollback();
1700 dol_syslog(get_class($this).
"::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE);
1718 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture_fourn';
1719 $sql .=
' SET paye=0, fk_statut='.self::STATUS_VALIDATED.
', close_code=null, close_note=null,';
1720 $sql .=
' date_closing=null,';
1721 $sql .=
' fk_user_closing=null';
1722 $sql .=
' WHERE rowid = '.((int) $this->
id);
1724 dol_syslog(get_class($this).
"::set_unpaid", LOG_DEBUG);
1725 $resql = $this->db->query($sql);
1728 $result = $this->call_trigger(
'BILL_SUPPLIER_UNPAYED', $user);
1735 $this->error = $this->db->error();
1740 $this->db->commit();
1743 $this->db->rollback();
1758 public function setCanceled($user, $close_code =
'', $close_note =
'')
1760 dol_syslog(get_class($this).
"::setCanceled rowid=".((
int) $this->
id), LOG_DEBUG);
1764 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture_fourn SET';
1765 $sql .=
' fk_statut='.self::STATUS_ABANDONED;
1767 $sql .=
", close_code='".$this->db->escape($close_code).
"'";
1770 $sql .=
", close_note='".$this->db->escape($close_note).
"'";
1772 $sql .=
" WHERE rowid = ".((int) $this->
id);
1774 $resql = $this->db->query($sql);
1778 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe_remise_except';
1779 $sql .=
' SET fk_invoice_supplier = NULL';
1780 $sql .=
' WHERE fk_invoice_supplier = '.((int) $this->
id);
1782 $resql = $this->db->query($sql);
1785 $result = $this->call_trigger(
'BILL_SUPPLIER_CANCEL', $user);
1787 $this->db->rollback();
1792 $this->db->commit();
1795 $this->error = $this->db->error().
" sql=".$sql;
1796 $this->db->rollback();
1800 $this->error = $this->db->error().
" sql=".$sql;
1801 $this->db->rollback();
1815 public function validate($user, $force_number =
'', $idwarehouse = 0, $notrigger = 0)
1819 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1824 dol_syslog(get_class($this).
'::validate user='.$user->id.
', force_number='.$force_number.
', idwarehouse='.$idwarehouse);
1831 if ($this->
status > self::STATUS_DRAFT) {
1832 dol_syslog(get_class($this).
"::validate no draft status", LOG_WARNING);
1835 if (preg_match(
'/^'.preg_quote($langs->trans(
"CopyOf").
' ',
'/').
'/', $this->ref_supplier)) {
1836 $langs->load(
"errors");
1837 $this->error = $langs->trans(
"ErrorFieldFormat", $langs->transnoentities(
"RefSupplier")).
'. '.$langs->trans(
'RemoveString', $langs->transnoentitiesnoconv(
"CopyOf"));
1840 if (count($this->lines) <= 0) {
1841 $langs->load(
"errors");
1842 $this->error = $langs->trans(
"ErrorObjectMustHaveLinesToBeValidated", $this->
ref);
1847 if (!empty($this->thirdparty) && is_object($this->thirdparty)) {
1848 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL',
'ACCOUNTANCY_CODE_SUPPLIER');
1849 foreach ($array_to_check as $key) {
1850 $keymin = strtolower($key);
1851 if ($keymin ==
'accountancy_code_supplier') {
1852 $keymin =
'code_compta_fournisseur';
1854 if (!property_exists($this->thirdparty, $keymin)) {
1857 $vallabel = $this->thirdparty->$keymin;
1859 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
1861 if ($this->thirdparty->isACompany()) {
1863 if (
$mysoc->country_id > 0 && $this->thirdparty->country_id ==
$mysoc->country_id) {
1864 $idprof_mandatory =
'SOCIETE_'.$key.
'_INVOICE_MANDATORY';
1866 $langs->load(
"errors");
1867 $this->error = $langs->trans(
'ErrorProdIdIsMandatory', $langs->transcountry(
'ProfId'.$i, $this->thirdparty->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
') ['.$langs->trans(
'Company').
' : '.$this->thirdparty->name.
']';
1868 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
1874 if ($key ==
'EMAIL') {
1877 $langs->load(
"errors");
1878 $this->error = $langs->trans(
"ErrorBadEMail", $this->thirdparty->email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
') ['.$langs->trans(
'Company').
' : '.$this->thirdparty->name.
']';
1879 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
1882 } elseif ($key ==
'ACCOUNTANCY_CODE_SUPPLIER') {
1884 if (
getDolGlobalString(
'SOCIETE_ACCOUNTANCY_CODE_SUPPLIER_INVOICE_MANDATORY') && empty($this->thirdparty->code_compta_fournisseur)) {
1885 $langs->load(
"errors");
1886 $this->error = $langs->trans(
"ErrorAccountancyCodeSupplierIsMandatory", $this->thirdparty->name).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1887 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
1898 if ($force_number) {
1899 $num = $force_number;
1900 } elseif (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1907 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn";
1908 $sql .=
" SET ref='".$this->db->escape($num).
"', fk_statut = 1, fk_user_valid = ".((int) $user->id).
", date_valid = '".$this->db->idate($now).
"'";
1909 $sql .=
" WHERE rowid = ".((int) $this->
id);
1911 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
1912 $resql = $this->db->query($sql);
1916 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1917 $langs->load(
"agenda");
1919 $cpt = count($this->lines);
1920 for ($i = 0; $i < $cpt; $i++) {
1921 if ($this->lines[$i]->fk_product > 0) {
1923 $mouvP->origin = &$this;
1924 $mouvP->setOrigin($this->element, $this->
id);
1926 $up_ht_disc = $this->lines[$i]->subprice;
1927 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1928 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1931 $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"InvoiceValidatedInDolibarr", $num));
1933 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"InvoiceValidatedInDolibarr", $num));
1944 if (empty($notrigger)) {
1946 $result = $this->call_trigger(
'BILL_SUPPLIER_VALIDATE', $user);
1954 $this->oldref = $this->ref;
1957 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1959 $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).
"'";
1960 $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;
1961 $resql = $this->db->query($sql);
1964 $this->error = $this->db->lasterror();
1966 $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).
"'";
1967 $sql .=
" WHERE filepath = 'fournisseur/facture/".get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1968 $resql = $this->db->query($sql);
1971 $this->error = $this->db->lasterror();
1976 $dirsource =
$conf->fournisseur->facture->dir_output.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$oldref;
1977 $dirdest =
$conf->fournisseur->facture->dir_output.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$this->newref;
1978 if (!$error && file_exists($dirsource)) {
1979 dol_syslog(get_class($this).
"::validate rename dir ".$dirsource.
" into ".$dirdest);
1981 if (@rename($dirsource, $dirdest)) {
1984 $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,
'/'));
1985 foreach ($listoffiles as $fileentry) {
1986 $dirsource = $fileentry[
'name'];
1987 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $this->newref, $dirsource);
1988 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1989 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1990 @rename($dirsource, $dirdest);
1999 $this->
ref = $this->newref;
2006 $this->db->commit();
2009 $this->db->rollback();
2013 $this->error = $this->db->error();
2014 $this->db->rollback();
2027 public function setDraft($user, $idwarehouse = -1, $notrigger = 0)
2030 global
$conf, $langs;
2034 if ($this->
status == self::STATUS_DRAFT) {
2035 dol_syslog(__METHOD__.
" already draft status", LOG_WARNING);
2043 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn";
2044 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2045 $sql .=
" WHERE rowid = ".((int) $this->
id);
2047 $result = $this->db->query($sql);
2049 $this->oldcopy = clone $this;
2053 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2054 $langs->load(
"agenda");
2056 $cpt = count($this->lines);
2057 for ($i = 0; $i < $cpt; $i++) {
2058 if ($this->lines[$i]->fk_product > 0) {
2060 $mouvP->origin = &$this;
2061 $mouvP->setOrigin($this->element, $this->
id);
2064 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans(
"InvoiceBackToDraftInDolibarr", $this->ref));
2066 $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans(
"InvoiceBackToDraftInDolibarr", $this->ref));
2072 if (empty($notrigger)) {
2074 $result = $this->call_trigger(
'BILL_SUPPLIER_UNVALIDATE', $user);
2081 $this->db->commit();
2084 $this->db->rollback();
2088 $this->error = $this->db->error();
2089 $this->db->rollback();
2129 public function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product = 0, $remise_percent = 0,
$date_start = 0, $date_end = 0, $fk_code_ventilation = 0, $info_bits = 0, $price_base_type =
'HT', $type = 0, $rang = -1, $notrigger = 0, $array_options = [], $fk_unit =
null, $origin_id = 0, $pu_devise = 0, $ref_supplier =
'', $special_code = 0, $fk_parent_line = 0, $fk_remise_except = 0, $origin_type =
'')
2133 dol_syslog(get_class($this).
"::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$fk_code_ventilation,$info_bits,$price_base_type,$type,$fk_unit,fk_remise_except=$fk_remise_except", LOG_DEBUG);
2134 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2136 if ($this->
status == self::STATUS_DRAFT) {
2138 if (empty($remise_percent)) {
2139 $remise_percent = 0;
2144 if (empty($info_bits)) {
2150 if (empty($fk_code_ventilation)) {
2151 $fk_code_ventilation = 0;
2153 if (empty($txtva)) {
2156 if (empty($txlocaltax1)) {
2159 if (empty($txlocaltax2)) {
2163 $remise_percent =
price2num($remise_percent);
2166 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
2173 $langs->load(
"errors");
2174 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2180 if ($fk_product > 0) {
2181 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY') == 1) {
2183 dol_syslog(get_class($this).
"::addline we check supplier prices fk_product=".$fk_product.
" qty=".$qty.
" ref_supplier=".$ref_supplier);
2185 if (
$prod->fetch($fk_product) > 0) {
2186 $product_type =
$prod->type;
2187 $label =
$prod->label;
2188 $fk_prod_fourn_price = 0;
2192 $result =
$prod->get_buyprice($fk_prod_fourn_price, (
float) $qty, $fk_product,
'none', ($this->fk_soc ? $this->fk_soc : $this->socid));
2195 $pu =
$prod->fourn_pu;
2197 $ref_supplier =
$prod->ref_supplier;
2199 if ($remise_percent == 0 &&
$prod->remise_percent != 0) {
2200 $remise_percent =
$prod->remise_percent;
2204 $langs->load(
"errors");
2205 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2206 $this->db->rollback();
2207 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
2212 if ($result == -1) {
2213 $langs->load(
"errors");
2214 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2215 $this->db->rollback();
2216 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
2220 $this->error =
$prod->error;
2221 $this->db->rollback();
2222 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
2226 $this->error =
$prod->error;
2227 $this->db->rollback();
2232 $product_type = $type;
2244 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2245 $vat_src_code = $reg[1];
2246 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2253 $tabprice =
calcul_price_total((
float) $qty, $pu, (
float) $remise_percent, $txtva, (
float) $txlocaltax1, (
float) $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_devise);
2254 $total_ht = $tabprice[0];
2255 $total_tva = $tabprice[1];
2256 $total_ttc = $tabprice[2];
2257 $total_localtax1 = $tabprice[9];
2258 $total_localtax2 = $tabprice[10];
2259 $pu_ht = $tabprice[3];
2262 $multicurrency_total_ht = $tabprice[16];
2263 $multicurrency_total_tva = $tabprice[17];
2264 $multicurrency_total_ttc = $tabprice[18];
2265 $pu_ht_devise = $tabprice[19];
2274 $rang = $rangmax + 1;
2280 $supplierinvoiceline->context = $this->context;
2282 $supplierinvoiceline->fk_facture_fourn = $this->id;
2284 $supplierinvoiceline->desc = $desc;
2285 $supplierinvoiceline->ref_supplier = $ref_supplier;
2287 $supplierinvoiceline->qty = ($this->
type == self::TYPE_CREDIT_NOTE ? abs((
float) $qty) : (float) $qty);
2288 $supplierinvoiceline->subprice = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs((
float) $pu_ht) : (float) $pu_ht);
2290 $supplierinvoiceline->vat_src_code = $vat_src_code;
2291 $supplierinvoiceline->tva_tx = $txtva;
2292 $supplierinvoiceline->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2293 $supplierinvoiceline->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2294 $supplierinvoiceline->localtax1_type = empty($localtaxes_type[0]) ? 0 : $localtaxes_type[0];
2295 $supplierinvoiceline->localtax2_type = empty($localtaxes_type[2]) ? 0 : $localtaxes_type[2];
2297 $supplierinvoiceline->total_ht = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_ht) : (float) $total_ht);
2298 $supplierinvoiceline->total_tva = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_tva) : (float) $total_tva);
2299 $supplierinvoiceline->total_localtax1 = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_localtax1) : (float) $total_localtax1);
2300 $supplierinvoiceline->total_localtax2 = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_localtax2) : (float) $total_localtax2);
2301 $supplierinvoiceline->total_ttc = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_ttc) : (float) $total_ttc);
2303 $supplierinvoiceline->fk_product = $fk_product;
2304 $supplierinvoiceline->product_type = $type;
2305 $supplierinvoiceline->remise_percent = $remise_percent;
2307 $supplierinvoiceline->date_end = $date_end;
2308 $supplierinvoiceline->fk_code_ventilation = $fk_code_ventilation;
2309 $supplierinvoiceline->rang = $rang;
2310 $supplierinvoiceline->info_bits = $info_bits;
2311 $supplierinvoiceline->fk_remise_except = $fk_remise_except;
2314 $supplierinvoiceline->special_code = (int) $special_code;
2315 $supplierinvoiceline->fk_parent_line = $fk_parent_line;
2316 $supplierinvoiceline->origin = $this->origin;
2317 $supplierinvoiceline->origin_type = $origin_type;
2318 $supplierinvoiceline->origin_id = $origin_id;
2319 $supplierinvoiceline->fk_unit = $fk_unit;
2322 $supplierinvoiceline->fk_multicurrency = $this->fk_multicurrency;
2323 $supplierinvoiceline->multicurrency_code = $this->multicurrency_code;
2324 $supplierinvoiceline->multicurrency_subprice = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs((
float) $pu_ht_devise) : (float) $pu_ht_devise);
2326 $supplierinvoiceline->multicurrency_total_ht = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $multicurrency_total_ht) : (float) $multicurrency_total_ht);
2327 $supplierinvoiceline->multicurrency_total_tva = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $multicurrency_total_tva) : (float) $multicurrency_total_tva);
2328 $supplierinvoiceline->multicurrency_total_ttc = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $multicurrency_total_ttc) : (float) $multicurrency_total_ttc);
2330 if (is_array($array_options) && count($array_options) > 0) {
2331 $supplierinvoiceline->array_options = $array_options;
2334 $result = $supplierinvoiceline->insert($notrigger);
2337 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2340 if (!isset($this->context[
'createfromclone'])) {
2341 if (!empty($fk_parent_line)) {
2344 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2346 $linecount = count($this->lines);
2347 for ($ii = $rang; $ii <= $linecount; $ii++) {
2352 $this->lines[] = $supplierinvoiceline;
2355 $this->db->commit();
2356 return $supplierinvoiceline->id;
2358 $this->error = $this->db->error();
2359 $this->db->rollback();
2363 $this->error = $supplierinvoiceline->error;
2364 $this->errors = $supplierinvoiceline->errors;
2365 $this->db->rollback();
2398 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 = 0,
$date_start =
'', $date_end =
'', $array_options = [], $fk_unit =
null, $pu_devise = 0, $ref_supplier =
'', $rang = 0)
2402 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);
2403 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2407 $remise_percent = (float)
price2num($remise_percent);
2417 $langs->load(
"errors");
2418 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2423 if (empty($vatrate)) {
2426 if (empty($txlocaltax1)) {
2429 if (empty($txlocaltax2)) {
2433 $txlocaltax1 = (float)
price2num($txlocaltax1);
2434 $txlocaltax2 = (float)
price2num($txlocaltax2);
2446 if (preg_match(
'/\((.*)\)/', (
string) $vatrate, $reg)) {
2447 $vat_src_code = $reg[1];
2448 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', (
string) $vatrate);
2451 $tabprice =
calcul_price_total((
float) $qty, (
float) $pu, $remise_percent, $vatrate, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, (
float) $pu_devise);
2452 $total_ht = $tabprice[0];
2453 $total_tva = $tabprice[1];
2454 $total_ttc = $tabprice[2];
2455 $pu_ht = $tabprice[3];
2456 $pu_tva = $tabprice[4];
2457 $pu_ttc = $tabprice[5];
2458 $total_localtax1 = $tabprice[9];
2459 $total_localtax2 = $tabprice[10];
2462 $multicurrency_total_ht = $tabprice[16];
2463 $multicurrency_total_tva = $tabprice[17];
2464 $multicurrency_total_ttc = $tabprice[18];
2465 $pu_ht_devise = $tabprice[19];
2467 if (empty($info_bits)) {
2474 $line->fetch_optionals();
2476 $staticline = clone $line;
2479 $product =
new Product($this->db);
2480 $result = $product->fetch($idproduct);
2481 $product_type = $product->type;
2483 $idproduct = $staticline->fk_product;
2484 $product_type = $type;
2487 $line->oldline = $staticline;
2488 $line->context = $this->context;
2490 $line->description = $desc;
2491 $line->desc = $desc;
2493 $line->qty = ($this->
type == self::TYPE_CREDIT_NOTE ? abs((
float) $qty) : (float) $qty);
2495 $line->subprice = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs((
float) $pu_ht) : (float) $pu_ht);
2496 $line->pu_ht = $line->subprice;
2497 $line->subprice_ttc = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs((
float) $pu_ttc) : (float) $pu_ttc);
2498 $line->pu_ttc = $line->subprice_ttc;
2500 $line->remise_percent = $remise_percent;
2501 $line->ref_supplier = $ref_supplier;
2504 $line->date_end = $date_end;
2506 $line->vat_src_code = $vat_src_code;
2507 $line->tva_tx = $vatrate;
2508 $line->localtax1_tx = $txlocaltax1;
2509 $line->localtax2_tx = $txlocaltax2;
2510 $line->localtax1_type = empty($localtaxes_type[0]) ? 0 : $localtaxes_type[0];
2511 $line->localtax2_type = empty($localtaxes_type[2]) ? 0 : $localtaxes_type[2];
2513 $line->total_ht = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_ht) : (float) $total_ht);
2514 $line->total_tva = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_tva) : (float) $total_tva);
2515 $line->total_localtax1 = (float) $total_localtax1;
2516 $line->total_localtax2 = (float) $total_localtax2;
2517 $line->total_ttc = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_ttc) : (float) $total_ttc);
2519 $line->fk_product = $idproduct;
2520 $line->product_type = $product_type;
2521 $line->info_bits = $info_bits;
2522 $line->fk_unit = $fk_unit;
2523 $line->rang = $rang;
2525 if (is_array($array_options) && count($array_options) > 0) {
2527 foreach ($array_options as $key => $value) {
2528 $line->array_options[$key] = $array_options[$key];
2533 $line->multicurrency_subprice = (float) $pu_ht_devise;
2534 $line->multicurrency_total_ht = (float) $multicurrency_total_ht;
2535 $line->multicurrency_total_tva = (float) $multicurrency_total_tva;
2536 $line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
2538 $res = $line->update($notrigger);
2544 $res = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2566 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe_remise_except';
2567 $sql .=
' SET fk_invoice_supplier_line = NULL';
2568 $sql .=
' WHERE fk_invoice_supplier_line = '.((int) $rowid);
2570 dol_syslog(get_class($this).
"::deleteline", LOG_DEBUG);
2571 $result = $this->db->query($sql);
2573 $this->error = $this->db->error();
2574 $this->db->rollback();
2580 if ($line->fetch($rowid) < 1) {
2584 $res = $line->delete($notrigger);
2587 $this->errors[] = $line->error;
2588 $this->db->rollback();
2594 $this->db->commit();
2597 $this->db->rollback();
2598 $this->error = $this->db->lasterror();
2613 $sql =
'SELECT c.rowid, datec, tms as datem, ';
2614 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid';
2615 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn as c';
2616 $sql .=
' WHERE c.rowid = '.((int) $id);
2618 $result = $this->db->query($sql);
2620 if ($this->db->num_rows($result)) {
2621 $obj = $this->db->fetch_object($result);
2623 $this->
id = $obj->rowid;
2625 $this->user_creation_id = $obj->fk_user_author;
2626 $this->user_validation_id = $obj->fk_user_valid;
2627 $this->user_modification_id = $obj->fk_user_modif;
2628 $this->date_creation = $this->db->jdate($obj->datec);
2629 $this->date_modification = $this->db->jdate($obj->datem);
2632 $this->db->free($result);
2654 $sql =
"SELECT f.rowid as rowid, f.ref, f.fk_statut,";
2655 $sql .=
" ff.rowid as rowidnext";
2656 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
2657 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
2658 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON f.rowid = ff.fk_facture_source";
2659 $sql .=
" WHERE (f.fk_statut = ".self::STATUS_VALIDATED.
" OR (f.fk_statut = ".self::STATUS_ABANDONED.
" AND f.close_code = '".self::CLOSECODE_ABANDONED.
"'))";
2660 $sql .=
" AND f.entity = ".$conf->entity;
2661 $sql .=
" AND f.paye = 0";
2662 $sql .=
" AND pf.fk_paiementfourn IS NULL";
2663 $sql .=
" AND ff.fk_statut IS NULL";
2665 $sql .=
" AND f.fk_soc = ".((int) $socid);
2667 $sql .=
" ORDER BY f.ref";
2669 dol_syslog(get_class($this).
"::list_replacable_supplier_invoices", LOG_DEBUG);
2670 $resql = $this->db->query($sql);
2672 while ($obj = $this->db->fetch_object($resql)) {
2673 $return[$obj->rowid] = array(
2674 'id' => $obj->rowid,
2676 'status' => $obj->fk_statut
2682 $this->error = $this->db->error();
2703 $sql =
"SELECT f.rowid as rowid, f.ref, f.fk_statut, f.type, f.subtype, f.paye as paid, pf.fk_paiementfourn";
2704 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
2705 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
2706 $sql .=
" WHERE f.entity = ".$conf->entity;
2707 $sql .=
" AND f.fk_statut in (".self::STATUS_VALIDATED.
",".self::STATUS_CLOSED.
")";
2708 $sql .=
" AND NOT EXISTS (SELECT rowid from ".MAIN_DB_PREFIX.
"facture_fourn as ff WHERE f.rowid = ff.fk_facture_source";
2709 $sql .=
" AND ff.type=".self::TYPE_REPLACEMENT.
")";
2710 $sql .=
" AND f.type != ".self::TYPE_CREDIT_NOTE;
2712 $sql .=
" AND f.fk_soc = ".((int) $socid);
2714 $sql .=
" ORDER BY f.ref";
2716 dol_syslog(get_class($this).
"::list_qualified_avoir_supplier_invoices", LOG_DEBUG);
2717 $resql = $this->db->query($sql);
2719 while ($obj = $this->db->fetch_object($resql)) {
2721 if ($obj->fk_statut == self::STATUS_VALIDATED) {
2724 if ($obj->fk_statut == self::STATUS_CLOSED) {
2728 $paymentornot = ($obj->fk_paiementfourn ? 1 : 0);
2729 $return[$obj->rowid] = array(
'ref' => (
string) $obj->ref,
'status' => (
int) $obj->fk_statut,
'type' => (
int) $obj->type,
'paid' => (
int) $obj->paid,
'paye' => (
int) $obj->paid,
'paymentornot' => (
int) $paymentornot);
2735 $this->error = $this->db->error();
2750 global
$conf, $langs;
2752 $sql =
'SELECT ff.rowid, ff.date_lim_reglement as datefin, ff.fk_statut as status, ff.total_ht, ff.total_ttc';
2753 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn as ff';
2754 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir")) {
2755 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON ff.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2757 $sql .=
' WHERE ff.paye = 0';
2758 $sql .=
" AND ff.fk_statut IN (".self::STATUS_VALIDATED.
")";
2759 $sql .=
" AND ff.entity = ".$conf->entity;
2761 $sql .=
' AND ff.fk_soc = '.((int) $user->socid);
2764 $resql = $this->db->query($sql);
2766 $langs->load(
"bills");
2770 $response->warning_delay =
$conf->facture->fournisseur->warning_delay / 60 / 60 / 24;
2771 $response->label = $langs->trans(
"SupplierBillsToPay");
2772 $response->labelShort = $langs->trans(
"StatusToPay");
2774 $response->url = DOL_URL_ROOT.
'/fourn/facture/list.php?search_status=1&mainmenu=billing&leftmenu=suppliers_bills';
2775 $response->img =
img_object($langs->trans(
"Bills"),
"bill");
2779 while ($obj = $this->db->fetch_object($resql)) {
2780 $facturestatic->date_echeance = $this->db->jdate($obj->datefin);
2781 $facturestatic->statut = $obj->status;
2782 $facturestatic->status = $obj->status;
2784 $response->nbtodo++;
2785 $response->total += (float) $obj->total_ht;
2787 if ($facturestatic->hasDelay()) {
2788 $response->nbtodolate++;
2789 $response->url_late = DOL_URL_ROOT.
'/fourn/facture/list.php?search_option=late&mainmenu=billing&leftmenu=suppliers_bills';
2793 $this->db->free($resql);
2797 $this->error = $this->db->error();
2813 $langs->load(
'bills');
2816 $moretitle = $params[
'moretitle'] ??
'';
2818 $picto = $this->picto;
2819 if ($this->
type == self::TYPE_REPLACEMENT) {
2822 if ($this->
type == self::TYPE_CREDIT_NOTE) {
2825 if ($this->
type == self::TYPE_DEPOSIT) {
2829 $datas[
'picto'] =
img_picto(
'', $picto).
' <u class="paddingrightonly">'.$langs->trans(
"SupplierInvoice").
'</u>';
2830 if ($this->
type == self::TYPE_REPLACEMENT) {
2831 $datas[
'picto'] .=
'<u class="paddingrightonly">'.$langs->transnoentitiesnoconv(
"InvoiceReplacement").
'</u>';
2832 } elseif ($this->
type == self::TYPE_CREDIT_NOTE) {
2833 $datas[
'picto'] .=
'<u class="paddingrightonly">'.$langs->transnoentitiesnoconv(
"CreditNote").
'</u>';
2834 } elseif ($this->
type == self::TYPE_DEPOSIT) {
2835 $datas[
'picto'] .=
'<u class="paddingrightonly">'.$langs->transnoentitiesnoconv(
"Deposit").
'</u>';
2837 if (isset($this->
status)) {
2839 if (isset($this->totalpaid)) {
2840 $alreadypaid = $this->totalpaid;
2843 $datas[
'picto'] .=
' '.$this->getLibStatut(5, $alreadypaid);
2846 $datas[
'picto'] .=
' - '.$moretitle;
2848 if (!empty($this->
ref)) {
2849 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
2851 if (!empty($this->ref_supplier)) {
2852 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
2854 if (!empty($this->label)) {
2855 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
2857 if (!empty($this->
date)) {
2858 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->
date,
'day');
2860 if (!empty($this->date_echeance)) {
2861 $datas[
'date_echeance'] =
'<br><b>'.$langs->trans(
'DateDue').
':</b> '.
dol_print_date($this->date_echeance,
'day');
2863 if (!empty($this->total_ht)) {
2864 $datas[
'amountht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1,
$conf->currency);
2866 if (!empty($this->total_tva)) {
2867 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'AmountVAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1,
$conf->currency);
2869 if (!empty($this->total_localtax1) && $this->total_localtax1 != 0) {
2871 $datas[
'amountlt1'] =
'<br><b>'.$langs->transcountry(
'AmountLT1',
$mysoc->country_code).
':</b> '.
price($this->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency);
2873 if (!empty($this->total_localtax2) && $this->total_localtax2 != 0) {
2874 $datas[
'amountlt2'] =
'<br><b>'.$langs->transcountry(
'AmountLT2',
$mysoc->country_code).
':</b> '.
price($this->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency);
2876 if (!empty($this->revenuestamp)) {
2877 $datas[
'amountrevenustamp'] =
'<br><b>'.$langs->trans(
'RevenueStamp').
':</b> '.
price($this->revenuestamp, 0, $langs, 0, -1, -1,
$conf->currency);
2879 if (!empty($this->total_ttc)) {
2880 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency);
2898 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
2900 global $langs,
$conf, $user, $hookmanager;
2904 if ($option ==
'withdraw') {
2905 $url = DOL_URL_ROOT.
'/compta/facture/prelevement.php?facid='.$this->
id.
'&type=bank-transfer';
2906 } elseif ($option ==
'document') {
2907 $url = DOL_URL_ROOT.
'/fourn/facture/document.php?facid='.$this->id;
2909 $url = DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$this->id;
2916 if ($option !==
'nolink') {
2918 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2919 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2920 $add_save_lastsearch_values = 1;
2922 if ($add_save_lastsearch_values) {
2923 $url .=
'&save_lastsearch_values=1';
2927 $picto = $this->picto;
2928 if ($this->
type == self::TYPE_REPLACEMENT) {
2931 if ($this->
type == self::TYPE_CREDIT_NOTE) {
2934 if ($this->
type == self::TYPE_DEPOSIT) {
2940 'objecttype' => $this->element,
2941 'option' => $option,
2942 'moretitle' => $moretitle,
2944 $classfortooltip =
'classfortooltip';
2947 $classfortooltip =
'classforajaxtooltip';
2948 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2960 if (empty($notooltip)) {
2962 $label = $langs->trans(
"ShowSupplierInvoice");
2963 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
2965 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
2966 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
2969 $linkstart =
'<a href="'.$url.
'"';
2970 $linkstart .= $linkclose.
'>';
2973 $result .= $linkstart;
2975 $result .=
img_object(($notooltip ?
'' : $label), ($picto ? $picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
2977 if ($withpicto != 2) {
2978 $result .= ($max ?
dol_trunc($ref, $max) : $ref);
2980 $result .= $linkend;
2982 if ($addlinktonotes) {
2983 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
2986 $result .=
' <span class="note inline-block">';
2987 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
2990 $result .=
'</span>';
2994 $hookmanager->initHooks(array($this->element .
'dao'));
2995 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
2996 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2998 $result = $hookmanager->resPrint;
3000 $result .= $hookmanager->resPrint;
3017 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
3018 return parent::setCategoriesCommon($categories, Categorie::TYPE_SUPPLIER_INVOICE);
3031 global $db, $langs,
$conf;
3032 $langs->load(
"orders");
3036 $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER =
'mod_facture_fournisseur_cactus';
3045 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
3047 foreach ($dirmodels as $reldir) {
3048 $dir =
dol_buildpath($reldir.
"core/modules/supplier_invoice/");
3051 $mybool = ((bool) @include_once $dir.$file) || $mybool;
3059 $obj =
new $classname();
3060 '@phan-var-force ModeleNumRefSuppliersInvoices $obj';
3062 $numref = $obj->getNextValue($soc, $this, $mode);
3064 if ($numref !=
"") {
3067 $this->error = $obj->error;
3083 global $langs,
$conf;
3084 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
3092 $sql =
"SELECT rowid";
3093 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
3094 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3095 $sql .= $this->db->plimit(100);
3097 $resql = $this->db->query($sql);
3099 $num_prods = $this->db->num_rows($resql);
3101 while ($i < $num_prods) {
3103 $row = $this->db->fetch_row($resql);
3104 $prodids[$i] = $row[0];
3110 $this->
ref =
'SPECIMEN';
3111 $this->ref_supplier =
'SUPPLIER_REF_SPECIMEN';
3112 $this->specimen = 1;
3115 $this->date_lim_reglement = $this->
date + 3600 * 24 * 30;
3116 $this->cond_reglement_code =
'RECEP';
3117 $this->mode_reglement_code =
'CHQ';
3119 $this->note_public =
'This is a comment (public)';
3120 $this->note_private =
'This is a comment (private)';
3122 $this->multicurrency_tx = 1;
3123 $this->multicurrency_code =
$conf->currency;
3126 if (empty($option) || $option !=
'nolines') {
3129 while ($xnbp < $nbp) {
3131 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3133 $line->subprice = 100;
3135 $line->tva_tx = 19.6;
3136 $line->localtax1_tx = 0;
3137 $line->localtax2_tx = 0;
3139 $line->total_ht = 50;
3140 $line->total_ttc = 59.8;
3141 $line->total_tva = 9.8;
3142 $line->remise_percent = 50;
3144 $line->total_ht = 100;
3145 $line->total_ttc = 119.6;
3146 $line->total_tva = 19.6;
3147 $line->remise_percent = 0;
3150 if ($num_prods > 0) {
3151 $prodid = mt_rand(1, $num_prods);
3152 $line->fk_product = $prodids[$prodid];
3154 $line->product_type = 0;
3156 $this->lines[$xnbp] = $line;
3158 $this->total_ht += $line->total_ht;
3159 $this->total_tva += $line->total_tva;
3160 $this->total_ttc += $line->total_ttc;
3166 $this->total_ht = $xnbp * 100;
3167 $this->total_tva = $xnbp * 19.6;
3168 $this->total_ttc = $xnbp * 119.6;
3180 global
$conf, $user;
3182 $this->nb = array();
3186 $sql =
"SELECT count(f.rowid) as nb";
3187 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
3188 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON f.fk_soc = s.rowid";
3189 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir")) {
3190 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3191 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3194 $sql .=
" ".$clause.
" f.entity = ".((int)
$conf->entity);
3196 $resql = $this->db->query($sql);
3198 while ($obj = $this->db->fetch_object($resql)) {
3199 $this->nb[
"supplier_invoices"] = $obj->nb;
3201 $this->db->free($resql);
3205 $this->error = $this->db->error();
3220 global
$conf, $langs, $hookmanager;
3239 $object->ref_supplier = (empty($this->ref_supplier) ? $langs->trans(
"CopyOf").
' '.
$object->ref_supplier : $this->ref_supplier);
3241 $object->user_validation_id = 0;
3242 $object->fk_facture_source = 0;
3244 $object->date_validation =
'';
3246 $object->ref_client =
'';
3254 $object->date_echeance =
$object->calculate_date_lim_reglement();
3257 foreach (
$object->lines as $i => $line) {
3258 if (isset(
$object->lines[$i]->info_bits) && (
$object->lines[$i]->info_bits & 0x02) == 0x02) {
3264 $object->context[
'createfromclone'] =
'createfromclone';
3265 $result =
$object->create($user);
3269 $this->error =
$object->error;
3270 $this->errors =
$object->errors;
3276 if (is_object($hookmanager)) {
3277 $parameters = array(
'objFrom' => $objFrom);
3279 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
3287 unset(
$object->context[
'createfromclone']);
3291 $this->db->commit();
3294 $this->db->rollback();
3310 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3314 $langs->load(
"suppliers");
3315 $outputlangs->load(
"products");
3318 if (empty($modele)) {
3324 } elseif ($modele ==
'auto') {
3325 $modele =
'canelle';
3328 if (empty($modele)) {
3331 $modelpath =
"core/modules/supplier_invoice/doc/";
3333 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3345 return $user->hasRight(
"fournisseur",
"facture");
3393 if (!$this->date_echeance) {
3397 $status = isset($this->
status) ? $this->
status : $this->statut;
3399 return ($status == self::STATUS_VALIDATED) && ($this->date_echeance < ($now -
$conf->facture->fournisseur->warning_delay));
3411 $sql =
"SELECT fk_invoice_supplier FROM ".MAIN_DB_PREFIX.
"societe_remise_except WHERE fk_invoice_supplier_source = ".((int) $this->
id);
3412 $resql = $this->db->query($sql);
3413 if (!empty($resql)) {
3414 $obj = $this->db->fetch_object($resql);
3415 if (!empty($obj->fk_invoice_supplier)) {
3433 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3435 $picto = $this->picto;
3436 if ($this->
type == self::TYPE_REPLACEMENT) {
3439 if ($this->
type == self::TYPE_CREDIT_NOTE) {
3442 if ($this->
type == self::TYPE_DEPOSIT) {
3446 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3447 $return .=
'<div class="info-box info-box-sm">';
3448 $return .=
'<span class="info-box-icon bg-infobox-action">';
3450 $return .=
'</span>';
3451 $return .=
'<div class="info-box-content">';
3452 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl(1) .
'</span>';
3453 if ($selected >= 0) {
3454 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3456 if (!empty($arraydata[
'thirdparty'])) {
3457 $return .=
'<br><span class="info-box-label">'.$arraydata[
'thirdparty'].
'</span>';
3459 if (!empty($this->
date)) {
3460 $return .=
'<br><span class="info-box-label">'.dol_print_date($this->
date,
'day').
'</span>';
3462 if (!empty($this->total_ht)) {
3463 $return .=
' <span class="info-box-label amount" title="'.dol_escape_htmltag($langs->trans(
"AmountHT")).
'">'.
price($this->total_ht);
3464 $return .=
' '.$langs->trans(
"HT");
3465 $return .=
'</span>';
3467 $alreadypaid = (empty($arraydata[
'alreadypaid']) ? 0 : $arraydata[
'alreadypaid']);
3468 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3, $alreadypaid).
'</div>';
3470 $return .=
'</div>';
3471 $return .=
'</div>';
3472 $return .=
'</div>';
3485 if (!$this->table_element) {
3486 dol_syslog(get_class($this).
"::setVATReverseCharge was called on object with property table_element not defined", LOG_ERR);
3490 dol_syslog(get_class($this).
'::setVATReverseCharge('.$vatreversecharge.
')');
3492 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
3493 $sql .=
" SET vat_reverse_charge = ".((int) $vatreversecharge);
3494 $sql .=
" WHERE rowid=".((int) $this->
id);
3496 if ($this->db->query($sql)) {
3497 $this->vat_reverse_charge = ($vatreversecharge == 0) ? 0 : 1;
3500 dol_syslog(get_class($this).
'::setVATReverseCharge Error ', LOG_DEBUG);
3501 $this->error = $this->db->error();
3519 global
$conf, $langs, $user;
3526 $errorsMsg = array();
3528 $langs->load(
'bills');
3531 $this->output .= $langs->trans(
'ModuleNotEnabled', $langs->transnoentitiesnoconv(
'Suppliers'));
3534 if (!in_array($datetouse, array(
'duedate',
'invoicedate'))) {
3535 $this->output .=
'Bad value for parameter datetouse. Must be "duedate" or "invoicedate"';
3539 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
3540 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
3541 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
3542 $formmail =
new FormMail($this->db);
3552 $sql =
"SELECT rowid as id FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
3553 if (!empty($paymentmode) && $paymentmode !=
'all') {
3554 $sql .=
", ".MAIN_DB_PREFIX.
"c_paiement as cp";
3556 $sql .=
" WHERE f.paye = 0";
3557 $sql .=
" AND f.fk_statut = ".self::STATUS_VALIDATED;
3558 if ($datetouse ==
'invoicedate') {
3559 $sql .=
" AND f.datef = '".$this->db->idate($tmpidate,
'gmt').
"'";
3561 $sql .=
" AND f.date_lim_reglement = '".$this->db->idate($tmpidate,
'gmt').
"'";
3563 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice', 0).
")";
3564 if (!empty($paymentmode) && $paymentmode !=
'all') {
3565 $sql .=
" AND f.fk_mode_reglement = cp.id AND cp.code = '".$this->db->escape($paymentmode).
"'";
3568 if ($datetouse ==
'invoicedate') {
3569 $sql .= $this->db->order(
"datef",
"ASC");
3571 $sql .= $this->db->order(
"date_lim_reglement",
"ASC");
3574 $resql = $this->db->query($sql);
3577 if ($datetouse ==
'invoicedate') {
3578 $this->output .= $langs->transnoentitiesnoconv(
"SearchValidatedSupplierInvoicesWithDate", $stmpidate);
3580 $this->output .= $langs->transnoentitiesnoconv(
"SearchUnpaidSupplierInvoicesWithDueDate", $stmpidate);
3582 if (!empty($paymentmode) && $paymentmode !=
'all') {
3583 $this->output .=
' ('.$langs->transnoentitiesnoconv(
"PaymentMode").
' '.$paymentmode.
')';
3585 $this->output .=
'<br>';
3588 while ($obj = $this->db->fetch_object($resql)) {
3591 $res = $tmpinvoice->fetch($obj->id);
3593 $tmpinvoice->fetch_thirdparty();
3596 if ($tmpinvoice->thirdparty->default_lang) {
3597 $outputlangs->setDefaultLang($tmpinvoice->thirdparty->default_lang);
3598 $outputlangs->loadLangs(array(
"main",
"suppliers"));
3600 $outputlangs = $langs;
3605 $templateLabel =
'';
3606 if (empty($template) || $template ==
'EmailTemplateCode') {
3607 $templateLabel =
'(SendingReminderEmailOnUnpaidSupplierInvoice)';
3609 if (is_numeric($template)) {
3610 $templateId = $template;
3612 $templateLabel = $template;
3616 $arraymessage = $formmail->getEMailTemplate($this->db,
'invoice_supplier_send', $user, $outputlangs, $templateId, 1, $templateLabel);
3617 if (is_numeric($arraymessage) && $arraymessage <= 0) {
3618 $langs->load(
"errors");
3619 $this->output .= $langs->trans(
'ErrorFailedToFindEmailTemplate', $template);
3627 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $tmpinvoice);
3632 $sendTopic =
make_substitutions(empty($arraymessage->topic) ? $outputlangs->transnoentitiesnoconv(
'InformationMessage') : $arraymessage->topic, $substitutionarray, $outputlangs, 1);
3635 $content = $outputlangs->transnoentitiesnoconv($arraymessage->content);
3641 if ($forcerecipient) {
3642 $to = array($forcerecipient);
3644 $res = $tmpinvoice->fetch_thirdparty();
3645 $recipient = $tmpinvoice->thirdparty;
3647 $tmparraycontact = $tmpinvoice->liste_contact(-1,
'internal', 0,
'SALESREPFOLL');
3648 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
3649 foreach ($tmparraycontact as $data_email) {
3650 if (!empty($data_email[
'email'])) {
3651 $to[] = $data_email[
'email'];
3655 if (empty($to) && !empty($recipient->email)) {
3656 $to[] = $recipient->email;
3659 $errormesg =
"Failed to send remind to thirdparty id=".$tmpinvoice->socid.
". No email defined for supplier invoice or customer.";
3663 $errormesg =
"Failed to load recipient with thirdparty id=".$tmpinvoice->socid;
3670 if (!empty($arraymessage->email_from)) {
3671 $from = (
string) $arraymessage->email_from;
3674 $errormesg =
"Failed to get sender into global setup MAIN_MAIL_EMAIL_FROM";
3678 if (!$error && !empty($to)) {
3681 $to = implode(
',', $to);
3682 if (!empty($arraymessage->email_to)) {
3683 $to = $to.
','.$arraymessage->email_to;
3689 $trackid =
'inv'.$tmpinvoice->id;
3690 $sendcontext =
'standard';
3693 if (!empty($arraymessage->email_tocc)) {
3694 $email_tocc = (
string) $arraymessage->email_tocc;
3698 if (!empty($arraymessage->email_tobcc)) {
3699 $email_tobcc = (
string) $arraymessage->email_tobcc;
3703 $cMailFile =
new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), $email_tocc, $email_tobcc, 0, 1, $errors_to,
'', $trackid,
'', $sendcontext,
'');
3706 if ($cMailFile->sendfile()) {
3710 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
3715 $actioncomm->type_code =
'AC_OTH_AUTO';
3716 $actioncomm->socid = $tmpinvoice->thirdparty->id;
3717 $actioncomm->contact_id = 0;
3719 $actioncomm->code =
'AC_EMAIL';
3720 $actioncomm->label =
'sendEmailsRemindersOnInvoiceDueDateOK (nbdays='.$nbdays.
' paymentmode='.$paymentmode.
' template='.$template.
' datetouse='.$datetouse.
' forcerecipient='.$forcerecipient.
')';
3721 $actioncomm->note_private = $sendContent;
3722 $actioncomm->fk_project = $tmpinvoice->fk_project;
3723 $actioncomm->datep =
dol_now();
3724 $actioncomm->datef = $actioncomm->datep;
3725 $actioncomm->percentage = -1;
3726 $actioncomm->authorid = $user->id;
3727 $actioncomm->userownerid = $user->id;
3729 $actioncomm->email_msgid = $cMailFile->msgid;
3730 $actioncomm->email_subject = $sendTopic;
3731 $actioncomm->email_from = $from;
3732 $actioncomm->email_sender =
'';
3733 $actioncomm->email_to = $to;
3737 $actioncomm->errors_to = $errors_to;
3739 $actioncomm->elementtype =
'invoice_supplier';
3740 $actioncomm->elementid = $tmpinvoice->id;
3741 $actioncomm->fk_element = $tmpinvoice->id;
3745 $actioncomm->create($user);
3747 $errormesg = $cMailFile->error.
' : '.$to;
3751 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
3756 $actioncomm->type_code =
'AC_OTH_AUTO';
3757 $actioncomm->socid = $tmpinvoice->thirdparty->id;
3758 $actioncomm->contact_id = 0;
3760 $actioncomm->code =
'AC_EMAIL';
3761 $actioncomm->label =
'sendEmailsRemindersOnInvoiceDueDateKO';
3762 $actioncomm->note_private = $errormesg;
3763 $actioncomm->fk_project = $tmpinvoice->fk_project;
3764 $actioncomm->datep =
dol_now();
3765 $actioncomm->datef = $actioncomm->datep;
3766 $actioncomm->percentage = -1;
3767 $actioncomm->authorid = $user->id;
3768 $actioncomm->userownerid = $user->id;
3770 $actioncomm->email_msgid = $cMailFile->msgid;
3771 $actioncomm->email_from = $from;
3772 $actioncomm->email_sender =
'';
3773 $actioncomm->email_to = $to;
3777 $actioncomm->errors_to = $errors_to;
3781 $actioncomm->create($user);
3784 $this->db->commit();
3788 $errorsMsg[] = $errormesg;
3791 $errorsMsg[] =
'Failed to fetch record invoice with ID = '.$obj->id;
3801 $this->output .=
'Nb of emails sent : '.$nbMailSend;
3803 dol_syslog(__METHOD__.
" end - ".$this->output, LOG_INFO);
3807 $this->error =
'Nb of emails sent : '.$nbMailSend.
', '.(empty($errorsMsg) ? $error : implode(
', ', $errorsMsg));
3809 dol_syslog(__METHOD__.
" end - ".$this->error, LOG_INFO);
if(! $sortfield) if(! $sortorder) $object
Class to manage agenda events (actions)
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Superclass for invoice 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.
update_price($exclspec=0, $roundingadjust='auto', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
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.
setErrorsFromObject($object)
setErrorsFromObject
updateRangOfLine($rowid, $rang)
Update position of line (rang)
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.
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...
deleteLine($rowid, $notrigger=0)
Delete a detail line from database.
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...
fetch($id=0, $ref='', $ref_ext='')
Load object in memory from database.
setCategories($categories)
Sets object to given categories.
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 clickable link of object (with eventually picto)
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='', $notooltip=0, $save_lastsearch_value=-1, $addlinktonotes=0)
Return clickable name (with optional picto)
getTooltipContentArray($params)
getTooltipContentArray
setPaid($user, $close_code='', $close_note='')
Tag invoice as a paid invoice.
update($user=null, $notrigger=0)
Update database.
addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start=0, $date_end=0, $fk_code_ventilation=0, $info_bits=0, $price_base_type='HT', $type=0, $rang=-1, $notrigger=0, $array_options=[], $fk_unit=null, $origin_id=0, $pu_devise=0, $ref_supplier='', $special_code=0, $fk_parent_line=0, $fk_remise_except=0, $origin_type='')
Adds an invoice line (associated with no predefined product/service) The parameters are already suppo...
__construct($db)
Constructor.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
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...
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=0, $date_start='', $date_end='', $array_options=[], $fk_unit=null, $pu_devise=0, $ref_supplier='', $rang=0)
Update a line detail in the database.
sendEmailsRemindersOnSupplierInvoiceDueDate($nbdays=0, $paymentmode='all', $template='', $datetouse='duedate', $forcerecipient='')
Send reminders by emails for supplier invoices validated that are due.
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.
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.
loadStateBoard()
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
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 getIdAndTxFromCode($dbs, $code, $date_document=0)
Get id and rate of currency from code.
static getIdFromCode($dbs, $code)
Get id of currency from code.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage line invoices.
Class to manage translations.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
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_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_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.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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 '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...