40require_once DOL_DOCUMENT_ROOT.
'/core/class/commoninvoice.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.ligne.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
45if (isModEnabled(
'accounting')) {
46 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
58 public $element =
'invoice_supplier';
63 public $table_element =
'facture_fourn';
68 public $table_element_line =
'facture_fourn_det';
73 public $class_element_line =
'SupplierInvoiceLine';
77 public $fk_element =
'fk_facture_fourn';
82 public $picto =
'supplier_invoice';
88 public $restrictiononfksoc = 1;
108 public $ref_supplier;
176 public $date_echeance;
206 public $total_localtax1;
208 public $total_localtax2;
219 public $note_private;
233 public $transport_mode_id;
238 public $vat_reverse_charge;
243 public $extraparams = array();
249 public $lines = array();
261 public $fk_facture_source;
266 public $fk_fac_rec_source;
268 public $fields = array(
269 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
270 'ref' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 15),
271 'ref_supplier' => array(
'type' =>
'varchar(255)',
'label' =>
'RefSupplier',
'enabled' => 1,
'visible' => -1,
'position' => 20),
272 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 25,
'index' => 1),
273 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 30),
274 'type' => array(
'type' =>
'smallint(6)',
'label' =>
'Type',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 35),
275 'subtype' => array(
'type' =>
'smallint(6)',
'label' =>
'InvoiceSubtype',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 36),
276 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'notnull' => 1,
'position' => 40),
277 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 45),
278 'datef' => array(
'type' =>
'date',
'label' =>
'Date',
'enabled' => 1,
'visible' => -1,
'position' => 50),
279 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 55),
280 'libelle' => array(
'type' =>
'varchar(255)',
'label' =>
'Label',
'enabled' => 1,
'visible' => -1,
'position' => 60),
281 'paye' => array(
'type' =>
'smallint(6)',
'label' =>
'Paye',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 65),
282 'amount' => array(
'type' =>
'double(24,8)',
'label' =>
'Amount',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 70),
283 'remise' => array(
'type' =>
'double(24,8)',
'label' =>
'Discount',
'enabled' => 1,
'visible' => -1,
'position' => 75),
284 'close_code' => array(
'type' =>
'varchar(16)',
'label' =>
'CloseCode',
'enabled' => 1,
'visible' => -1,
'position' => 80),
285 'close_note' => array(
'type' =>
'varchar(128)',
'label' =>
'CloseNote',
'enabled' => 1,
'visible' => -1,
'position' => 85),
286 'tva' => array(
'type' =>
'double(24,8)',
'label' =>
'Tva',
'enabled' => 1,
'visible' => -1,
'position' => 90),
287 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'Localtax1',
'enabled' => 1,
'visible' => -1,
'position' => 95),
288 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'Localtax2',
'enabled' => 1,
'visible' => -1,
'position' => 100),
289 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalHT',
'enabled' => 1,
'visible' => -1,
'position' => 105),
290 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalVAT',
'enabled' => 1,
'visible' => -1,
'position' => 110),
291 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalTTC',
'enabled' => 1,
'visible' => -1,
'position' => 115),
292 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -1,
'position' => 125),
293 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 130),
294 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 135),
295 'fk_facture_source' => array(
'type' =>
'integer',
'label' =>
'Fk facture source',
'enabled' => 1,
'visible' => -1,
'position' => 140),
296 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:fk_statut=1',
'label' =>
'Project',
'enabled' =>
"isModEnabled('project')",
'visible' => -1,
'position' => 145),
297 'fk_account' => array(
'type' =>
'integer',
'label' =>
'Account',
'enabled' =>
'isModEnabled("bank")',
'visible' => -1,
'position' => 150),
298 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentTerm',
'enabled' => 1,
'visible' => -1,
'position' => 155),
299 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => -1,
'position' => 160),
300 'date_lim_reglement' => array(
'type' =>
'date',
'label' =>
'DateLimReglement',
'enabled' => 1,
'visible' => -1,
'position' => 165),
301 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 170),
302 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 175),
303 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'ModelPdf',
'enabled' => 1,
'visible' => 0,
'position' => 180),
304 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 190),
305 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'IncotermCode',
'enabled' => 1,
'visible' => -1,
'position' => 195),
306 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'IncotermLocation',
'enabled' => 1,
'visible' => -1,
'position' => 200),
307 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'MulticurrencyId',
'enabled' => 1,
'visible' => -1,
'position' => 205),
308 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'MulticurrencyCode',
'enabled' => 1,
'visible' => -1,
'position' => 210),
309 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyRate',
'enabled' => 1,
'visible' => -1,
'position' => 215),
310 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyTotalHT',
'enabled' => 1,
'visible' => -1,
'position' => 220),
311 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyTotalVAT',
'enabled' => 1,
'visible' => -1,
'position' => 225),
312 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyTotalTTC',
'enabled' => 1,
'visible' => -1,
'position' => 230),
313 'date_pointoftax' => array(
'type' =>
'date',
'label' =>
'Date pointoftax',
'enabled' => 1,
'visible' => -1,
'position' => 235),
314 'date_valid' => array(
'type' =>
'date',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 240),
315 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'Last main doc',
'enabled' => 1,
'visible' => -1,
'position' => 245),
316 'fk_statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 500),
317 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 900),
324 public $fk_user_valid;
374 const CLOSECODE_DISCOUNTVAT =
'discount_vat';
375 const CLOSECODE_BADCREDIT =
'badsupplier';
376 const CLOSECODE_ABANDONED =
'abandon';
377 const CLOSECODE_REPLACED =
'replaced';
388 $this->ismultientitymanaged = 1;
399 global $langs,
$conf, $hookmanager;
405 if (isset($this->ref_supplier)) {
406 $this->ref_supplier = trim($this->ref_supplier);
408 if (empty($this->
type)) {
411 if (empty($this->date)) {
416 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
421 if (empty($this->fk_multicurrency)) {
422 $this->multicurrency_code =
$conf->currency;
423 $this->fk_multicurrency = 0;
424 $this->multicurrency_tx = 1;
431 $originaldatewhen = 0;
433 $previousdaynextdatewhen = 0;
437 if ($this->fac_rec > 0) {
438 $this->fk_fac_rec_source = $this->fac_rec;
440 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture-rec.class.php';
442 $result = $_facrec->fetch($this->fac_rec);
443 $result = $_facrec->fetchObjectLinked(
null,
'',
null,
'',
'OR', 1,
'sourcetype', 0);
446 if (!empty($_facrec->frequency)) {
447 $originaldatewhen = $_facrec->date_when;
448 $nextdatewhen =
dol_time_plus_duree($originaldatewhen, $_facrec->frequency, $_facrec->unit_frequency);
450 $this->socid = $_facrec->socid;
453 $this->entity = $_facrec->entity;
458 $this->fk_project =
GETPOSTINT(
'projectid') > 0 ? (
GETPOSTINT(
'projectid')) : $_facrec->fk_project;
459 $this->note_public =
GETPOST(
'note_public',
'restricthtml') ?
GETPOST(
'note_public',
'restricthtml') : $_facrec->note_public;
460 $this->note_private =
GETPOST(
'note_private',
'restricthtml') ?
GETPOST(
'note_private',
'restricthtml') : $_facrec->note_private;
461 $this->model_pdf =
GETPOST(
'model',
'alpha') ?
GETPOST(
'model',
'alpha') : $_facrec->model_pdf;
462 $this->cond_reglement_id =
GETPOSTINT(
'cond_reglement_id') > 0 ? (
GETPOSTINT(
'cond_reglement_id')) : $_facrec->cond_reglement_id;
463 $this->mode_reglement_id =
GETPOSTINT(
'mode_reglement_id') > 0 ? (
GETPOSTINT(
'mode_reglement_id')) : $_facrec->mode_reglement_id;
464 $this->fk_account =
GETPOST(
'fk_account') > 0 ? ((int)
GETPOST(
'fk_account')) : $_facrec->fk_account;
467 $this->total_ht = $_facrec->total_ht;
468 $this->total_ttc = $_facrec->total_ttc;
471 $this->fk_incoterms = $_facrec->fk_incoterms;
472 $this->location_incoterms = $_facrec->location_incoterms;
478 $this->note_public = trim($this->note_public);
479 $this->note_private = trim($this->note_private);
480 $this->note_private =
dol_concatdesc($this->note_private, $langs->trans(
"GeneratedFromRecurringInvoice", $_facrec->title));
482 $this->array_options = $_facrec->array_options;
484 if (! $this->mode_reglement_id) {
485 $this->mode_reglement_id = 0;
490 $this->linked_objects = $_facrec->linkedObjectsIds;
497 if ($_facrec->frequency > 0) {
498 $this->ref_supplier = trim($this->ref_supplier .
'_' . ($_facrec->nb_gen_done + 1));
499 dol_syslog(
"This is a recurring invoice so we set date_last_gen and next date_when");
500 if (empty($_facrec->date_when)) {
501 $_facrec->date_when = $now;
503 $next_date = $_facrec->getNextDate();
504 $result = $_facrec->setValueFrom(
'date_last_gen', $now,
'', 0,
'date',
'', $user,
'');
506 $result = $_facrec->setNextDate($next_date, 1);
510 $outputlangs = $langs;
513 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($this->thirdparty->default_lang)) {
514 $newlang = $this->thirdparty->default_lang;
516 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && property_exists($this,
'default_lang') && isset($this->default_lang)) {
517 $newlang = $this->default_lang;
519 if (!empty($newlang)) {
521 $outputlangs->setDefaultLang($newlang);
523 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $this);
525 $substitutionarray[
'__INVOICE_MONTH__'] =
dol_print_date($this->date,
'%m');
528 $substitutionarray[
'__INVOICE_MONTH_TEXT__'] =
dol_print_date($this->date,
'%B');
531 $substitutionarray[
'__INVOICE_YEAR__'] =
dol_print_date($this->date,
'%Y');
533 $substitutionarray[
'__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = $originaldatewhen ?
dol_print_date($originaldatewhen,
'dayhour') :
'';
534 $substitutionarray[
'__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = $nextdatewhen ?
dol_print_date($nextdatewhen,
'dayhour') :
'';
535 $substitutionarray[
'__INVOICE_PREVIOUS_DATE_NEXT_INVOICE_AFTER_GEN__'] = $previousdaynextdatewhen ?
dol_print_date($previousdaynextdatewhen,
'dayhour') :
'';
536 $substitutionarray[
'__INVOICE_COUNTER_CURRENT__'] = $_facrec->nb_gen_done;
537 $substitutionarray[
'__INVOICE_COUNTER_MAX__'] = $_facrec->nb_gen_max;
546 if (!empty($forceduedate)) {
547 $this->date_echeance = $forceduedate;
550 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facture_fourn (";
552 $sql .=
", ref_supplier";
561 $sql .=
", vat_reverse_charge";
562 $sql .=
", fk_projet";
563 $sql .=
", fk_cond_reglement";
564 $sql .=
", fk_mode_reglement";
565 $sql .=
", fk_account";
566 $sql .=
", note_private";
567 $sql .=
", note_public";
568 $sql .=
", fk_user_author";
569 $sql .=
", date_lim_reglement";
570 $sql .=
", fk_incoterms, location_incoterms";
571 $sql .=
", fk_multicurrency";
572 $sql .=
", multicurrency_code";
573 $sql .=
", multicurrency_tx";
574 $sql .=
", fk_facture_source";
575 $sql .=
", fk_fac_rec_source";
579 $sql .=
", '".$this->db->escape($this->ref_supplier).
"'";
580 $sql .=
", '".$this->db->escape($this->ref_ext).
"'";
581 $sql .=
", ".((int) $this->entity);
582 $sql .=
", '".$this->db->escape((
string) $this->type).
"'";
583 $sql .=
", ".((int) $this->subtype);
584 $sql .=
", '".$this->db->escape(isset($this->label) ? $this->label : (isset($this->libelle) ? $this->libelle :
'')).
"'";
585 $sql .=
", ".((int) $this->socid);
586 $sql .=
", '".$this->db->idate($now).
"'";
587 $sql .=
", '".$this->db->idate($this->date).
"'";
588 $sql .=
", ".($this->vat_reverse_charge !=
'' ? ((int) $this->vat_reverse_charge) : 0);
589 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
590 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
"null");
591 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"null");
592 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
593 $sql .=
", '".$this->db->escape($this->note_private).
"'";
594 $sql .=
", '".$this->db->escape($this->note_public).
"'";
595 $sql .=
", ".((int) $user->id).
",";
596 $sql .= $this->date_echeance !=
'' ?
"'".$this->db->idate($this->date_echeance).
"'" :
"null";
597 $sql .=
", ".(int) $this->fk_incoterms;
598 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
599 $sql .=
", ".(int) $this->fk_multicurrency;
600 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
601 $sql .=
", ".(float) $this->multicurrency_tx;
602 $sql .=
", ".($this->fk_facture_source ? ((int) $this->fk_facture_source) :
"null");
603 $sql .=
", ".(isset($this->fk_fac_rec_source) ? $this->fk_fac_rec_source :
"NULL");
606 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
607 $resql = $this->db->query($sql);
609 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn');
612 $this->
ref =
'(PROV'.$this->id.
')';
613 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"facture_fourn SET ref='".$this->db->escape($this->
ref).
"' WHERE rowid=".((int) $this->
id);
615 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
616 $resql = $this->db->query($sql);
621 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
622 $this->linked_objects = $this->linkedObjectsIds;
626 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
627 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
628 if (is_array($tmp_origin_id)) {
629 foreach ($tmp_origin_id as $origin_id) {
637 $origin_id = $tmp_origin_id;
647 if (!$error && empty($this->fac_rec) && count($this->lines) && is_object($this->lines[0])) {
648 dol_syslog(
"There is ".count($this->lines).
" lines that are invoice lines objects");
649 foreach ($this->lines as $i => $val) {
650 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'facture_fourn_det (fk_facture_fourn, special_code, fk_remise_except)';
651 $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').
')';
653 $resql_insert = $this->db->query($sql);
655 $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn_det');
659 $this->lines[$i]->desc ? $this->lines[$i]->desc : $this->lines[$i]->description,
660 $this->lines[$i]->subprice,
661 $this->lines[$i]->tva_tx.($this->lines[$i]->vat_src_code ?
' ('.$this->lines[$i]->vat_src_code.
')' :
''),
662 $this->lines[$i]->localtax1_tx,
663 $this->lines[$i]->localtax2_tx,
664 $this->lines[$i]->qty,
665 $this->lines[$i]->fk_product,
667 (!empty($this->lines[$i]->info_bits) ? $this->lines[$i]->info_bits :
''),
668 $this->lines[$i]->product_type,
669 $this->lines[$i]->remise_percent,
671 $this->lines[$i]->date_start,
672 $this->lines[$i]->date_end,
673 $this->lines[$i]->array_options,
674 $this->lines[$i]->fk_unit,
675 $this->lines[$i]->multicurrency_subprice,
676 $this->lines[$i]->ref_supplier
679 $this->error = $this->db->lasterror();
680 $this->db->rollback();
684 } elseif (!$error && empty($this->fac_rec)) {
685 dol_syslog(
"There is ".count($this->lines).
" lines that are array lines");
686 foreach ($this->lines as $i => $val) {
687 $line = $this->lines[$i];
691 if (!is_object($line)) {
692 $line = (object) $line;
695 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'facture_fourn_det (fk_facture_fourn, special_code, fk_remise_except)';
696 $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').
')';
698 $resql_insert = $this->db->query($sql);
700 $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.
'facture_fourn_det');
704 $line->desc ? $line->desc : $line->description,
712 (!empty($line->info_bits) ? $line->info_bits :
''),
714 $line->remise_percent,
718 $line->array_options,
720 $line->multicurrency_subprice,
724 $this->error = $this->db->lasterror();
725 $this->db->rollback();
735 foreach ($_facrec->lines as $i => $val) {
736 $product_type = $_facrec->lines[$i]->product_type;
737 if ($_facrec->lines[$i]->fk_product) {
738 $prod =
new Product($this->db);
739 $res = $prod->fetch($_facrec->lines[$i]->fk_product);
750 $tva_tx = $_facrec->lines[$i]->tva_tx . ($_facrec->lines[$i]->vat_src_code ?
'(' . $_facrec->lines[$i]->vat_src_code .
')' :
'');
751 $tva_npr = $_facrec->lines[$i]->info_bits;
752 if (empty($tva_tx)) {
755 $localtax1_tx = $_facrec->lines[$i]->localtax1_tx;
756 $localtax2_tx = $_facrec->lines[$i]->localtax2_tx;
760 $buyprice = empty($_facrec->lines[$i]->buyprice) ? 0 : $_facrec->lines[$i]->buyprice;
763 if (! $buyprice && $_facrec->lines[$i]->fk_product > 0) {
764 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.product.class.php';
766 $producttmp->fetch($_facrec->lines[$i]->fk_product);
771 if (
getDolGlobalString(
'MARGIN_TYPE') ==
'costprice' && !empty($producttmp->cost_price)) {
772 $buyprice = $producttmp->cost_price;
774 $buyprice = $producttmp->pmp;
776 if ($producttmp->find_min_price_product_fournisseur($_facrec->lines[$i]->fk_product) > 0) {
777 if ($producttmp->product_fourn_price_id > 0) {
778 $buyprice =
price2num($producttmp->fourn_unitprice * (1 - $producttmp->fourn_remise_percent / 100) + $producttmp->fourn_remise,
'MU');
784 $result_insert = $this->
addline(
785 $_facrec->lines[$i]->desc ? $_facrec->lines[$i]->desc : $_facrec->lines[$i]->description,
786 $_facrec->lines[$i]->pu_ht,
790 $_facrec->lines[$i]->qty,
791 $_facrec->lines[$i]->fk_product,
792 $_facrec->lines[$i]->remise_percent,
793 ($_facrec->lines[$i]->date_start == 1 && $this->date) ? $this->date :
'',
794 ($_facrec->lines[$i]->date_end == 1 && $previousdaynextdatewhen) ? $previousdaynextdatewhen :
'',
796 $_facrec->lines[$i]->info_bits,
799 $_facrec->lines[$i]->rang,
801 $_facrec->lines[$i]->array_options,
802 $_facrec->lines[$i]->fk_unit,
805 $_facrec->lines[$i]->ref_supplier,
806 $_facrec->lines[$i]->special_code,
810 if ($result_insert < 0) {
812 $this->error = $this->db->error();
832 $result = $this->
call_trigger(
'BILL_SUPPLIER_CREATE', $user);
843 $this->db->rollback();
847 $this->error = $langs->trans(
'FailedToUpdatePrice');
848 $this->db->rollback();
852 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
853 $this->error = $langs->trans(
'ErrorRefAlreadyExists');
854 $this->db->rollback();
857 $this->error = $this->db->lasterror();
858 $this->db->rollback();
872 public function fetch($id = 0, $ref =
'', $ref_ext =
'')
874 if (empty($id) && empty($ref) && empty($ref_ext)) {
881 $sql .=
" t.ref_supplier,";
882 $sql .=
" t.ref_ext,";
883 $sql .=
" t.entity,";
885 $sql .=
" t.subtype,";
886 $sql .=
" t.fk_soc,";
890 $sql .=
" t.libelle as label,";
892 $sql .=
" t.close_code,";
893 $sql .=
" t.close_note,";
895 $sql .=
" t.localtax1,";
896 $sql .=
" t.localtax2,";
897 $sql .=
" t.total_ht,";
898 $sql .=
" t.total_tva,";
899 $sql .=
" t.total_ttc,";
900 $sql .=
" t.fk_statut as status,";
901 $sql .=
" t.fk_user_author,";
902 $sql .=
" t.fk_user_valid,";
903 $sql .=
" t.fk_facture_source,";
904 $sql .=
" t.vat_reverse_charge,";
905 $sql .=
" t.fk_fac_rec_source,";
906 $sql .=
" t.fk_projet as fk_project,";
907 $sql .=
" t.fk_cond_reglement,";
908 $sql .=
" t.fk_account,";
909 $sql .=
" t.fk_mode_reglement,";
910 $sql .=
" t.date_lim_reglement,";
911 $sql .=
" t.note_private,";
912 $sql .=
" t.note_public,";
913 $sql .=
" t.model_pdf,";
914 $sql .=
" t.last_main_doc,";
915 $sql .=
" t.import_key,";
916 $sql .=
" t.extraparams,";
917 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc,";
918 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_label,";
919 $sql .=
' s.nom as socnom, s.rowid as socid,';
920 $sql .=
' t.fk_incoterms, t.location_incoterms,';
921 $sql .=
" i.libelle as label_incoterms,";
922 $sql .=
' t.fk_transport_mode,';
923 $sql .=
' t.fk_multicurrency, t.multicurrency_code, t.multicurrency_tx, t.multicurrency_total_ht, t.multicurrency_total_tva, t.multicurrency_total_ttc';
924 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn as t';
925 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON (t.fk_soc = s.rowid)";
926 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_payment_term as cr ON t.fk_cond_reglement = cr.rowid";
927 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as p ON t.fk_mode_reglement = p.id";
928 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON t.fk_incoterms = i.rowid';
930 $sql .=
" WHERE t.rowid = ".((int) $id);
932 $sql .=
' WHERE t.entity IN ('.getEntity(
'supplier_invoice').
')';
934 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
937 $sql .=
" AND t.ref_ext = '".$this->db->escape($ref_ext).
"'";
941 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
942 $resql = $this->db->query($sql);
944 if ($this->db->num_rows($resql)) {
945 $obj = $this->db->fetch_object($resql);
947 $this->
id = $obj->rowid;
948 $this->
ref = $obj->ref ? $obj->ref : $obj->rowid;
950 $this->ref_supplier = $obj->ref_supplier;
951 $this->ref_ext = $obj->ref_ext;
952 $this->entity = $obj->entity;
954 $this->subtype = (int) $obj->subtype;
955 $this->socid = $obj->fk_soc;
956 $this->datec = $this->db->jdate($obj->datec);
957 $this->date = $this->db->jdate($obj->datef);
959 $this->tms = $this->db->jdate($obj->tms);
960 $this->libelle = $obj->label;
961 $this->label = $obj->label;
962 $this->paye = $obj->paye;
963 $this->paid = $obj->paye;
964 $this->close_code = $obj->close_code;
965 $this->close_note = $obj->close_note;
966 $this->total_localtax1 = $obj->localtax1;
967 $this->total_localtax2 = $obj->localtax2;
968 $this->total_ht = $obj->total_ht;
969 $this->total_tva = $obj->total_tva;
970 $this->total_ttc = $obj->total_ttc;
971 $this->
status = $obj->status;
972 $this->statut = $obj->status;
973 $this->fk_statut = $obj->status;
974 $this->user_creation_id = $obj->fk_user_author;
975 $this->author = $obj->fk_user_author;
976 $this->user_validation_id = $obj->fk_user_valid;
977 $this->fk_facture_source = $obj->fk_facture_source;
978 $this->vat_reverse_charge = empty($obj->vat_reverse_charge) ? 0 : 1;
979 $this->fk_fac_rec_source = $obj->fk_fac_rec_source;
980 $this->fk_project = $obj->fk_project;
981 $this->cond_reglement_id = $obj->fk_cond_reglement;
982 $this->cond_reglement_code = $obj->cond_reglement_code;
983 $this->cond_reglement = $obj->cond_reglement_label;
984 $this->cond_reglement_label = $obj->cond_reglement_label;
985 $this->cond_reglement_doc = $obj->cond_reglement_doc;
986 $this->fk_account = $obj->fk_account;
987 $this->mode_reglement_id = $obj->fk_mode_reglement;
988 $this->mode_reglement_code = $obj->mode_reglement_code;
989 $this->mode_reglement = $obj->mode_reglement_label;
990 $this->date_echeance = $this->db->jdate($obj->date_lim_reglement);
991 $this->note = $obj->note_private;
992 $this->note_private = $obj->note_private;
993 $this->note_public = $obj->note_public;
994 $this->model_pdf = $obj->model_pdf;
995 $this->last_main_doc = $obj->last_main_doc;
996 $this->import_key = $obj->import_key;
999 $this->fk_incoterms = $obj->fk_incoterms;
1000 $this->location_incoterms = $obj->location_incoterms;
1001 $this->label_incoterms = $obj->label_incoterms;
1002 $this->transport_mode_id = $obj->fk_transport_mode;
1005 $this->fk_multicurrency = $obj->fk_multicurrency;
1006 $this->multicurrency_code = $obj->multicurrency_code;
1007 $this->multicurrency_tx = $obj->multicurrency_tx;
1008 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
1009 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
1010 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1012 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
1014 $this->socid = $obj->socid;
1016 $this->thirdparty =
null;
1024 $this->error = $this->db->lasterror();
1028 $this->error =
'Bill with id '.$id.
' not found';
1029 dol_syslog(get_class($this).
'::fetch '.$this->error);
1033 $this->db->free($resql);
1036 $this->error =
"Error ".$this->db->lasterror();
1051 $this->lines = array();
1053 $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';
1054 $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';
1055 $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';
1056 $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';
1057 $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';
1058 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_det as f';
1059 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON f.fk_product = p.rowid';
1060 $sql .=
' WHERE fk_facture_fourn='.((int) $this->
id);
1061 $sql .=
' ORDER BY f.rang, f.rowid';
1063 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1065 $resql_rows = $this->db->query($sql);
1067 $num_rows = $this->db->num_rows($resql_rows);
1070 while ($i < $num_rows) {
1071 $obj = $this->db->fetch_object($resql_rows);
1075 $line->id = $obj->rowid;
1076 $line->rowid = $obj->rowid;
1078 $line->description = $obj->line_desc;
1079 $line->desc = $obj->line_desc;
1080 $line->date_start = $this->db->jdate($obj->date_start);
1081 $line->date_end = $this->db->jdate($obj->date_end);
1083 $line->product_ref = $obj->product_ref;
1084 $line->ref = $obj->product_ref;
1085 $line->ref_supplier = $obj->ref_supplier;
1086 $line->libelle = $obj->label;
1087 $line->label = $obj->label;
1088 $line->product_barcode = $obj->product_barcode;
1089 $line->product_desc = $obj->product_desc;
1090 $line->subprice = $obj->pu_ht;
1091 $line->pu_ht = $obj->pu_ht;
1092 $line->pu_ttc = $obj->pu_ttc;
1093 $line->vat_src_code = $obj->vat_src_code;
1094 $line->tva_tx = $obj->tva_tx;
1095 $line->localtax1_tx = $obj->localtax1_tx;
1096 $line->localtax2_tx = $obj->localtax2_tx;
1097 $line->localtax1_type = $obj->localtax1_type;
1098 $line->localtax2_type = $obj->localtax2_type;
1099 $line->qty = $obj->qty;
1100 $line->remise_percent = $obj->remise_percent;
1101 $line->fk_remise_except = $obj->fk_remise_except;
1103 $line->total_ht = $obj->total_ht;
1104 $line->total_ttc = $obj->total_ttc;
1105 $line->total_tva = $obj->total_tva;
1106 $line->total_localtax1 = $obj->total_localtax1;
1107 $line->total_localtax2 = $obj->total_localtax2;
1108 $line->fk_facture_fourn = $obj->fk_facture_fourn;
1109 $line->fk_product = $obj->fk_product;
1110 $line->product_type = $obj->product_type;
1111 $line->product_label = $obj->label;
1112 $line->info_bits = $obj->info_bits;
1113 $line->fk_parent_line = $obj->fk_parent_line;
1114 $line->special_code = $obj->special_code;
1115 $line->rang = $obj->rang;
1116 $line->fk_unit = $obj->fk_unit;
1118 $line->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
1121 $line->fk_code_ventilation = $obj->fk_code_ventilation;
1124 $line->fk_multicurrency = $obj->fk_multicurrency;
1125 $line->multicurrency_code = $obj->multicurrency_code;
1126 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1127 $line->multicurrency_total_ht = $obj->multicurrency_total_ht;
1128 $line->multicurrency_total_tva = $obj->multicurrency_total_tva;
1129 $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1132 $line->fetch_optionals();
1134 $this->lines[$i] = $line;
1139 $this->db->free($resql_rows);
1142 $this->error = $this->db->error();
1143 dol_syslog(get_class($this).
"::fetch_lines - No lines:{$this->error} Error:{$this->error}", LOG_DEBUG);
1156 public function update($user =
null, $notrigger = 0)
1162 if (empty($this->
type)) {
1165 if (isset($this->
ref)) {
1166 $this->
ref = trim($this->
ref);
1168 if (isset($this->ref_supplier)) {
1169 $this->ref_supplier = trim($this->ref_supplier);
1171 if (isset($this->ref_ext)) {
1172 $this->ref_ext = trim($this->ref_ext);
1174 if (isset($this->entity)) {
1175 $this->entity = (int) $this->entity;
1177 if (isset($this->
type)) {
1180 if (isset($this->subtype)) {
1181 $this->subtype = (int) $this->subtype;
1183 if (isset($this->socid)) {
1184 $this->socid = (int) $this->socid;
1186 if (isset($this->label)) {
1187 $this->label = trim($this->label);
1189 if (isset($this->paid)) {
1190 $this->paid = (int) (
bool) $this->paye;
1191 $this->paye = $this->paid;
1192 } elseif (isset($this->paye)) {
1193 $this->paid = (int) (
bool) $this->paye;
1194 $this->paye = $this->paid;
1196 if (isset($this->close_code)) {
1197 $this->close_code = trim($this->close_code);
1199 if (isset($this->close_note)) {
1200 $this->close_note = trim($this->close_note);
1202 if (empty($this->total_ht)) {
1203 $this->total_ht = 0;
1205 if (empty($this->total_tva)) {
1206 $this->total_tva = 0;
1208 if (empty($this->total_localtax1)) {
1209 $this->total_localtax1 = 0;
1211 if (empty($this->total_localtax2)) {
1212 $this->total_localtax2 = 0;
1214 if (isset($this->total_ttc)) {
1215 $this->total_ttc = (float) $this->total_ttc;
1217 if (isset($this->
status)) {
1219 $this->statut = $this->status;
1220 } elseif (isset($this->statut)) {
1221 $this->
status = (int) $this->statut;
1222 $this->statut = $this->status;
1224 if (isset($this->author)) {
1225 $this->author = (int) $this->author;
1227 if (isset($this->fk_user_valid)) {
1228 $this->fk_user_valid = (int) $this->fk_user_valid;
1230 if (isset($this->fk_facture_source)) {
1231 $this->fk_facture_source = (int) $this->fk_facture_source;
1233 if (isset($this->fk_project)) {
1234 if (empty($this->fk_project)) {
1235 $this->fk_project = 0;
1237 $this->fk_project = (int) $this->fk_project;
1240 if (isset($this->mode_reglement_id)) {
1241 $this->mode_reglement_id = (int) $this->mode_reglement_id;
1243 if (isset($this->cond_reglement_id)) {
1244 $this->cond_reglement_id = (int) $this->cond_reglement_id;
1246 if (isset($this->note_private)) {
1247 $this->note_private = trim($this->note_private);
1248 $this->note = $this->note_private;
1250 if (isset($this->note_public)) {
1251 $this->note_public = trim($this->note_public);
1253 if (isset($this->model_pdf)) {
1254 $this->model_pdf = trim($this->model_pdf);
1256 if (isset($this->import_key)) {
1257 $this->import_key = trim($this->import_key);
1265 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn SET";
1266 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1267 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1268 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1269 $sql .=
" entity=".(isset($this->entity) ? ((int) $this->entity) :
"null").
",";
1270 $sql .=
" type=".(isset($this->
type) ? ((int) $this->
type) :
"null").
",";
1271 $sql .=
" subtype=".((int) $this->subtype).
",";
1272 $sql .=
" fk_soc=".(isset($this->socid) ? ((int) $this->socid) :
"null").
",";
1273 $sql .=
" datec=".(dol_strlen((
string) $this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
1274 $sql .=
" datef=".(dol_strlen((
string) $this->date) != 0 ?
"'".$this->db->idate($this->date).
"'" :
'null').
",";
1276 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
1278 $sql .=
" libelle=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
1279 $sql .=
" paye=".(isset($this->paid) ? ((int) $this->paid) :
"0").
",";
1280 $sql .=
" close_code=".(isset($this->close_code) ?
"'".$this->db->escape($this->close_code).
"'" :
"null").
",";
1281 $sql .=
" close_note=".(isset($this->close_note) ?
"'".$this->db->escape($this->close_note).
"'" :
"null").
",";
1282 $sql .=
" localtax1=".(isset($this->total_localtax1) ? ((float) $this->total_localtax1) :
"null").
",";
1283 $sql .=
" localtax2=".(isset($this->total_localtax2) ? ((float) $this->total_localtax2) :
"null").
",";
1284 $sql .=
" total_ht=".(isset($this->total_ht) ? ((float) $this->total_ht) :
"null").
",";
1285 $sql .=
" total_tva=".(isset($this->total_tva) ? ((float) $this->total_tva) :
"null").
",";
1286 $sql .=
" total_ttc=".(isset($this->total_ttc) ? ((float) $this->total_ttc) :
"null").
",";
1287 $sql .=
" fk_statut=".(isset($this->
status) ? ((int) $this->
status) : (isset($this->statut) ? ((int) $this->statut) :
"null")).
",";
1288 $sql .=
" fk_user_author=".(isset($this->author) ? ((int) $this->author) :
"null").
",";
1289 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? ((int) $this->fk_user_valid) :
"null").
",";
1290 $sql .=
" fk_facture_source=".($this->fk_facture_source ? ((int) $this->fk_facture_source) :
"null").
",";
1291 $sql .=
" vat_reverse_charge = ".($this->vat_reverse_charge !=
'' ? ((int) $this->vat_reverse_charge) : 0).
",";
1292 $sql .=
" fk_projet=".(!empty($this->fk_project) ? ((int) $this->fk_project) :
"null").
",";
1293 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? ((int) $this->mode_reglement_id) :
"null").
",";
1294 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? ((int) $this->cond_reglement_id) :
"null").
",";
1295 $sql .=
" date_lim_reglement=".(dol_strlen((
string) $this->date_echeance) != 0 ?
"'".$this->db->idate($this->date_echeance).
"'" :
'null').
",";
1296 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1297 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1298 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1299 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1300 $sql .=
" WHERE rowid=".((int) $this->
id);
1304 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1305 $resql = $this->db->query($sql);
1310 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1311 $this->errors[] = $langs->trans(
'ErrorRefAlreadyExists');
1313 $this->errors[] =
"Error ".$this->db->lasterror();
1327 $result = $this->
call_trigger(
'BILL_SUPPLIER_MODIFY', $user);
1337 foreach ($this->errors as $errmsg) {
1338 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1339 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1341 $this->db->rollback();
1344 $this->db->commit();
1359 global
$conf, $langs;
1361 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1362 include_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1367 $result = $remise->fetch($idremise);
1370 if ($this->socid > 0 && $remise->fk_soc != $this->socid) {
1371 $this->error = $langs->trans(
"ErrorDiscountNotSameCompany");
1372 $this->db->rollback();
1375 if ($remise->fk_invoice_supplier) {
1376 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed");
1377 $this->db->rollback();
1382 $facligne->fk_facture_fourn = $this->id;
1383 $facligne->fk_remise_except = $remise->id;
1384 $facligne->desc = $remise->description;
1385 $facligne->vat_src_code = $remise->vat_src_code;
1386 $facligne->tva_tx = $remise->tva_tx;
1387 $facligne->subprice = -(float) $remise->amount_ht;
1388 $facligne->fk_product = 0;
1389 $facligne->product_type = 0;
1391 $facligne->remise_percent = 0;
1392 $facligne->rang = -1;
1393 $facligne->info_bits = 2;
1396 $facligne->rang = 1;
1397 $linecount = count($this->lines);
1398 for ($ii = 1; $ii <= $linecount; $ii++) {
1404 if ($remise->fk_invoice_supplier_source > 0) {
1406 $srcinvoice->fetch($remise->fk_invoice_supplier_source);
1407 $totalcostpriceofinvoice = 0;
1408 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
1410 $arraytmp = $formmargin->getMarginInfosArray($srcinvoice,
false);
1411 $facligne->pa_ht = $arraytmp[
'pa_total'];
1414 $facligne->total_ht = -(float) $remise->amount_ht;
1415 $facligne->total_tva = -(float) $remise->amount_tva;
1416 $facligne->total_ttc = -(float) $remise->amount_ttc;
1418 $facligne->multicurrency_subprice = -$remise->multicurrency_subprice;
1419 $facligne->multicurrency_total_ht = -$remise->multicurrency_total_ht;
1420 $facligne->multicurrency_total_tva = -$remise->multicurrency_total_tva;
1421 $facligne->multicurrency_total_ttc = -$remise->multicurrency_total_ttc;
1423 $lineid = $facligne->insert();
1428 $result = $remise->link_to_invoice($lineid, 0);
1430 $this->error = $remise->error;
1431 $this->db->rollback();
1435 $this->db->commit();
1438 $this->error = $facligne->error;
1439 $this->db->rollback();
1443 $this->error = $facligne->error;
1444 $this->db->rollback();
1448 $this->db->rollback();
1461 public function delete(
User $user, $notrigger = 0)
1467 dol_syslog(
"FactureFournisseur::delete rowid=".$rowid, LOG_DEBUG);
1472 dol_syslog(get_class($this).
"::delete refused, invoice is not erasable (code ".$result.
")", LOG_DEBUG);
1479 if (!$error && !$notrigger) {
1481 $result = $this->
call_trigger(
'BILL_SUPPLIER_DELETE', $user);
1483 $this->db->rollback();
1491 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'societe_remise_except';
1492 $sql .=
' WHERE fk_invoice_supplier_source = '.((int) $rowid);
1493 $sql .=
' AND fk_invoice_supplier_line IS NULL';
1494 $resql = $this->db->query($sql);
1498 $list_rowid_det = array();
1499 foreach ($this->lines as $key => $invoiceline) {
1500 $list_rowid_det[] = $invoiceline->id;
1504 if (count($list_rowid_det)) {
1505 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe_remise_except';
1506 $sql .=
' SET fk_invoice_supplier = NULL, fk_invoice_supplier_line = NULL';
1507 $sql .=
' WHERE fk_invoice_supplier_line IN ('.$this->db->sanitize(implode(
',', $list_rowid_det)).
')';
1509 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1510 if (!$this->db->query($sql)) {
1517 $main = MAIN_DB_PREFIX.
'facture_fourn_det';
1518 $ef = $main.
"_extrafields";
1519 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_facture_fourn = ".((int) $rowid).
")";
1520 $resqlef = $this->db->query($sqlef);
1521 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'facture_fourn_det WHERE fk_facture_fourn = '.((int) $rowid);
1522 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1523 $resql = $this->db->query($sql);
1524 if ($resqlef && $resql) {
1525 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'facture_fourn WHERE rowid = '.((int) $rowid);
1526 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1527 $resql2 = $this->db->query($sql);
1551 if ($conf->fournisseur->facture->dir_output && !empty($ref)) {
1552 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1554 $dir =
$conf->fournisseur->facture->dir_output.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$ref;
1555 $file = $dir.
"/".$ref.
".pdf";
1556 if (file_exists($file)) {
1558 $this->error =
'ErrorFailToDeleteFile';
1562 if (file_exists($dir)) {
1566 $this->error =
'ErrorFailToDeleteDir';
1575 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_invoice";
1576 $sql .=
" WHERE fk_invoice = ".((int) $this->
id);
1578 $result = $this->db->query($sql);
1581 $this->errors[] = $this->db->lasterror();
1590 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
1595 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
1596 $this->db->commit();
1599 $this->error = $this->db->lasterror();
1600 $this->db->rollback();
1617 public function set_paid($user, $close_code =
'', $close_note =
'')
1620 dol_syslog(get_class($this).
"::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
1621 return $this->
setPaid($user, $close_code, $close_note);
1632 public function setPaid($user, $close_code =
'', $close_note =
'')
1636 if ($this->paid != 1) {
1641 dol_syslog(
"FactureFournisseur::setPaid", LOG_DEBUG);
1643 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture_fourn SET';
1644 $sql .=
' fk_statut = '.self::STATUS_CLOSED;
1649 $sql .=
", close_code='".$this->db->escape($close_code).
"'";
1652 $sql .=
", close_note='".$this->db->escape($close_note).
"'";
1654 $sql .=
', fk_user_closing = '.((int) $user->id);
1655 $sql .=
", date_closing = '".$this->db->idate($now).
"'";
1656 $sql .=
' WHERE rowid = '.((int) $this->
id);
1658 $resql = $this->db->query($sql);
1661 $result = $this->
call_trigger(
'BILL_SUPPLIER_PAYED', $user);
1668 $this->error = $this->db->error();
1673 $this->db->commit();
1676 $this->db->rollback();
1698 dol_syslog(get_class($this).
"::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE);
1716 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture_fourn';
1717 $sql .=
' SET paye=0, fk_statut='.self::STATUS_VALIDATED.
', close_code=null, close_note=null,';
1718 $sql .=
' date_closing=null,';
1719 $sql .=
' fk_user_closing=null';
1720 $sql .=
' WHERE rowid = '.((int) $this->
id);
1722 dol_syslog(get_class($this).
"::set_unpaid", LOG_DEBUG);
1723 $resql = $this->db->query($sql);
1726 $result = $this->
call_trigger(
'BILL_SUPPLIER_UNPAYED', $user);
1733 $this->error = $this->db->error();
1738 $this->db->commit();
1741 $this->db->rollback();
1756 public function setCanceled($user, $close_code =
'', $close_note =
'')
1758 dol_syslog(get_class($this).
"::setCanceled rowid=".((
int) $this->
id), LOG_DEBUG);
1762 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture_fourn SET';
1763 $sql .=
' fk_statut='.self::STATUS_ABANDONED;
1765 $sql .=
", close_code='".$this->db->escape($close_code).
"'";
1768 $sql .=
", close_note='".$this->db->escape($close_note).
"'";
1770 $sql .=
" WHERE rowid = ".((int) $this->
id);
1772 $resql = $this->db->query($sql);
1776 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe_remise_except';
1777 $sql .=
' SET fk_invoice_supplier = NULL';
1778 $sql .=
' WHERE fk_invoice_supplier = '.((int) $this->
id);
1780 $resql = $this->db->query($sql);
1783 $result = $this->
call_trigger(
'BILL_SUPPLIER_CANCEL', $user);
1785 $this->db->rollback();
1790 $this->db->commit();
1793 $this->error = $this->db->error().
" sql=".$sql;
1794 $this->db->rollback();
1798 $this->error = $this->db->error().
" sql=".$sql;
1799 $this->db->rollback();
1813 public function validate($user, $force_number =
'', $idwarehouse = 0, $notrigger = 0)
1815 global $mysoc,
$conf, $langs;
1817 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1822 dol_syslog(get_class($this).
'::validate user='.$user->id.
', force_number='.$force_number.
', idwarehouse='.$idwarehouse);
1829 if ($this->
status > self::STATUS_DRAFT) {
1830 dol_syslog(get_class($this).
"::validate no draft status", LOG_WARNING);
1833 if (preg_match(
'/^'.preg_quote($langs->trans(
"CopyOf").
' ').
'/', $this->ref_supplier)) {
1834 $langs->load(
"errors");
1835 $this->error = $langs->trans(
"ErrorFieldFormat", $langs->transnoentities(
"RefSupplier")).
'. '.$langs->trans(
'RemoveString', $langs->transnoentitiesnoconv(
"CopyOf"));
1838 if (count($this->lines) <= 0) {
1839 $langs->load(
"errors");
1840 $this->error = $langs->trans(
"ErrorObjectMustHaveLinesToBeValidated", $this->
ref);
1845 if (!empty($this->thirdparty) && is_object($this->thirdparty)) {
1846 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL',
'ACCOUNTANCY_CODE_SUPPLIER');
1847 foreach ($array_to_check as $key) {
1848 $keymin = strtolower($key);
1849 if ($keymin ==
'accountancy_code_supplier') {
1850 $keymin =
'code_compta_fournisseur';
1852 if (!property_exists($this->thirdparty, $keymin)) {
1855 $vallabel = $this->thirdparty->$keymin;
1857 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
1859 if ($this->thirdparty->isACompany()) {
1861 if ($mysoc->country_id > 0 && $this->thirdparty->country_id == $mysoc->country_id) {
1862 $idprof_mandatory =
'SOCIETE_'.$key.
'_INVOICE_MANDATORY';
1864 $langs->load(
"errors");
1865 $this->error = $langs->trans(
'ErrorProdIdIsMandatory', $langs->transcountry(
'ProfId'.$i, $this->thirdparty->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
') ['.$langs->trans(
'Company').
' : '.$this->thirdparty->name.
']';
1866 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
1872 if ($key ==
'EMAIL') {
1875 $langs->load(
"errors");
1876 $this->error = $langs->trans(
"ErrorBadEMail", $this->thirdparty->email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
') ['.$langs->trans(
'Company').
' : '.$this->thirdparty->name.
']';
1877 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
1880 } elseif ($key ==
'ACCOUNTANCY_CODE_SUPPLIER') {
1882 if (
getDolGlobalString(
'SOCIETE_ACCOUNTANCY_CODE_SUPPLIER_INVOICE_MANDATORY') && empty($this->thirdparty->code_compta_fournisseur)) {
1883 $langs->load(
"errors");
1884 $this->error = $langs->trans(
"ErrorAccountancyCodeSupplierIsMandatory", $this->thirdparty->name).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')';
1885 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
1896 if ($force_number) {
1897 $num = $force_number;
1898 } elseif (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1905 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn";
1906 $sql .=
" SET ref='".$this->db->escape($num).
"', fk_statut = 1, fk_user_valid = ".((int) $user->id).
", date_valid = '".$this->db->idate($now).
"'";
1907 $sql .=
" WHERE rowid = ".((int) $this->
id);
1909 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
1910 $resql = $this->db->query($sql);
1913 if (!$error && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL')) {
1914 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1915 $langs->load(
"agenda");
1917 $cpt = count($this->lines);
1918 for ($i = 0; $i < $cpt; $i++) {
1919 if ($this->lines[$i]->fk_product > 0) {
1921 $mouvP->origin = &$this;
1922 $mouvP->setOrigin($this->element, $this->
id);
1924 $up_ht_disc = $this->lines[$i]->subprice;
1925 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1926 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1929 $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"InvoiceValidatedInDolibarr", $num));
1931 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"InvoiceValidatedInDolibarr", $num));
1934 $this->error = $mouvP->error;
1935 if (count($mouvP->errors)) {
1936 $this->errors = $mouvP->errors;
1945 if (!$error && empty($notrigger)) {
1947 $result = $this->
call_trigger(
'BILL_SUPPLIER_VALIDATE', $user);
1955 $this->oldref = $this->ref;
1958 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1960 $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).
"'";
1961 $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;
1962 $resql = $this->db->query($sql);
1965 $this->error = $this->db->lasterror();
1967 $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).
"'";
1968 $sql .=
" WHERE filepath = 'fournisseur/facture/".get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1969 $resql = $this->db->query($sql);
1972 $this->error = $this->db->lasterror();
1977 $dirsource =
$conf->fournisseur->facture->dir_output.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$oldref;
1978 $dirdest =
$conf->fournisseur->facture->dir_output.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'invoice_supplier').$this->newref;
1979 if (!$error && file_exists($dirsource)) {
1980 dol_syslog(get_class($this).
"::validate rename dir ".$dirsource.
" into ".$dirdest);
1982 if (@rename($dirsource, $dirdest)) {
1985 $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,
'/'));
1986 foreach ($listoffiles as $fileentry) {
1987 $dirsource = $fileentry[
'name'];
1988 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $this->newref, $dirsource);
1989 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1990 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1991 @rename($dirsource, $dirdest);
2000 $this->
ref = $this->newref;
2007 $this->db->commit();
2010 $this->db->rollback();
2014 $this->error = $this->db->error();
2015 $this->db->rollback();
2028 public function setDraft($user, $idwarehouse = -1, $notrigger = 0)
2031 global
$conf, $langs;
2035 if ($this->
status == self::STATUS_DRAFT) {
2036 dol_syslog(__METHOD__.
" already draft status", LOG_WARNING);
2044 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn";
2045 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2046 $sql .=
" WHERE rowid = ".((int) $this->
id);
2048 $result = $this->db->query($sql);
2051 $this->oldcopy = clone $this;
2055 if ($result >= 0 && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL')) {
2056 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2057 $langs->load(
"agenda");
2059 $cpt = count($this->lines);
2060 for ($i = 0; $i < $cpt; $i++) {
2061 if ($this->lines[$i]->fk_product > 0) {
2063 $mouvP->origin = &$this;
2064 $mouvP->setOrigin($this->element, $this->
id);
2067 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans(
"InvoiceBackToDraftInDolibarr", $this->ref));
2069 $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans(
"InvoiceBackToDraftInDolibarr", $this->ref));
2075 if (!$error && empty($notrigger)) {
2077 $result = $this->
call_trigger(
'BILL_SUPPLIER_UNVALIDATE', $user);
2084 $this->db->commit();
2087 $this->db->rollback();
2091 $this->error = $this->db->error();
2092 $this->db->rollback();
2131 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)
2133 global $langs, $mysoc;
2135 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);
2136 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2138 if ($this->
status == self::STATUS_DRAFT) {
2140 if (empty($remise_percent)) {
2141 $remise_percent = 0;
2146 if (empty($info_bits)) {
2152 if (empty($fk_code_ventilation)) {
2153 $fk_code_ventilation = 0;
2155 if (empty($txtva)) {
2158 if (empty($txlocaltax1)) {
2161 if (empty($txlocaltax2)) {
2165 $remise_percent =
price2num($remise_percent);
2168 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
2174 if ($date_start && $date_end && $date_start > $date_end) {
2175 $langs->load(
"errors");
2176 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2182 if ($fk_product > 0) {
2183 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY') == 1) {
2185 dol_syslog(get_class($this).
"::addline we check supplier prices fk_product=".$fk_product.
" qty=".$qty.
" ref_supplier=".$ref_supplier);
2187 if ($prod->fetch($fk_product) > 0) {
2188 $product_type = $prod->type;
2189 $label = $prod->label;
2190 $fk_prod_fourn_price = 0;
2194 $result = $prod->get_buyprice($fk_prod_fourn_price, (
float) $qty, $fk_product,
'none', ($this->fk_soc ? $this->fk_soc : $this->socid));
2197 $pu = $prod->fourn_pu;
2199 $ref_supplier = $prod->ref_supplier;
2201 if ($remise_percent == 0 && $prod->remise_percent != 0) {
2202 $remise_percent = $prod->remise_percent;
2206 $langs->load(
"errors");
2207 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2208 $this->db->rollback();
2209 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
2214 if ($result == -1) {
2215 $langs->load(
"errors");
2216 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2217 $this->db->rollback();
2218 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
2222 $this->error = $prod->error;
2223 $this->db->rollback();
2224 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
2228 $this->error = $prod->error;
2229 $this->db->rollback();
2234 $product_type = $type;
2237 if (isModEnabled(
"multicurrency") && $pu_devise > 0) {
2246 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2247 $vat_src_code = $reg[1];
2248 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2256 $tabprice =
calcul_price_total((
float) $qty, $pu, $remise_percent, $txtva, (
float) $txlocaltax1, (
float) $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_devise);
2257 $total_ht = $tabprice[0];
2258 $total_tva = $tabprice[1];
2259 $total_ttc = $tabprice[2];
2260 $total_localtax1 = $tabprice[9];
2261 $total_localtax2 = $tabprice[10];
2262 $pu_ht = $tabprice[3];
2265 $multicurrency_total_ht = $tabprice[16];
2266 $multicurrency_total_tva = $tabprice[17];
2267 $multicurrency_total_ttc = $tabprice[18];
2268 $pu_ht_devise = $tabprice[19];
2277 $rang = $rangmax + 1;
2283 $supplierinvoiceline->context = $this->context;
2285 $supplierinvoiceline->fk_facture_fourn = $this->id;
2287 $supplierinvoiceline->desc = $desc;
2288 $supplierinvoiceline->ref_supplier = $ref_supplier;
2290 $supplierinvoiceline->qty = ($this->
type == self::TYPE_CREDIT_NOTE ? abs((
float) $qty) : (float) $qty);
2291 $supplierinvoiceline->subprice = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs((
float) $pu_ht) : (float) $pu_ht);
2293 $supplierinvoiceline->vat_src_code = $vat_src_code;
2294 $supplierinvoiceline->tva_tx = $txtva;
2295 $supplierinvoiceline->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2296 $supplierinvoiceline->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2297 $supplierinvoiceline->localtax1_type = empty($localtaxes_type[0]) ? 0 : $localtaxes_type[0];
2298 $supplierinvoiceline->localtax2_type = empty($localtaxes_type[2]) ? 0 : $localtaxes_type[2];
2300 $supplierinvoiceline->total_ht = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_ht) : (float) $total_ht);
2301 $supplierinvoiceline->total_tva = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_tva) : (float) $total_tva);
2302 $supplierinvoiceline->total_localtax1 = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_localtax1) : (float) $total_localtax1);
2303 $supplierinvoiceline->total_localtax2 = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_localtax2) : (float) $total_localtax2);
2304 $supplierinvoiceline->total_ttc = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_ttc) : (float) $total_ttc);
2306 $supplierinvoiceline->fk_product = $fk_product;
2307 $supplierinvoiceline->product_type = $type;
2308 $supplierinvoiceline->remise_percent = $remise_percent;
2309 $supplierinvoiceline->date_start = $date_start;
2310 $supplierinvoiceline->date_end = $date_end;
2311 $supplierinvoiceline->fk_code_ventilation = $fk_code_ventilation;
2312 $supplierinvoiceline->rang = $rang;
2313 $supplierinvoiceline->info_bits = $info_bits;
2314 $supplierinvoiceline->fk_remise_except = $fk_remise_except;
2317 $supplierinvoiceline->special_code = (int) $special_code;
2318 $supplierinvoiceline->fk_parent_line = $fk_parent_line;
2319 $supplierinvoiceline->origin = $this->origin;
2320 $supplierinvoiceline->origin_id = $origin_id;
2321 $supplierinvoiceline->fk_unit = $fk_unit;
2324 $supplierinvoiceline->fk_multicurrency = $this->fk_multicurrency;
2325 $supplierinvoiceline->multicurrency_code = $this->multicurrency_code;
2326 $supplierinvoiceline->multicurrency_subprice = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs((
float) $pu_ht_devise) : (float) $pu_ht_devise);
2328 $supplierinvoiceline->multicurrency_total_ht = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $multicurrency_total_ht) : (float) $multicurrency_total_ht);
2329 $supplierinvoiceline->multicurrency_total_tva = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $multicurrency_total_tva) : (float) $multicurrency_total_tva);
2330 $supplierinvoiceline->multicurrency_total_ttc = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $multicurrency_total_ttc) : (float) $multicurrency_total_ttc);
2332 if (is_array($array_options) && count($array_options) > 0) {
2333 $supplierinvoiceline->array_options = $array_options;
2336 $result = $supplierinvoiceline->insert($notrigger);
2339 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2342 if (!isset($this->context[
'createfromclone'])) {
2343 if (!empty($fk_parent_line)) {
2346 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2348 $linecount = count($this->lines);
2349 for ($ii = $rang; $ii <= $linecount; $ii++) {
2354 $this->lines[] = $supplierinvoiceline;
2357 $this->db->commit();
2358 return $supplierinvoiceline->id;
2360 $this->error = $this->db->error();
2361 $this->db->rollback();
2365 $this->error = $supplierinvoiceline->error;
2366 $this->errors = $supplierinvoiceline->errors;
2367 $this->db->rollback();
2400 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 global $mysoc, $langs;
2404 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);
2405 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2409 $remise_percent = (float)
price2num($remise_percent);
2418 if ($date_start && $date_end && $date_start > $date_end) {
2419 $langs->load(
"errors");
2420 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2425 if (empty($vatrate)) {
2428 if (empty($txlocaltax1)) {
2431 if (empty($txlocaltax2)) {
2435 $txlocaltax1 = (float)
price2num($txlocaltax1);
2436 $txlocaltax2 = (float)
price2num($txlocaltax2);
2449 if (preg_match(
'/\((.*)\)/', (
string) $vatrate, $reg)) {
2450 $vat_src_code = $reg[1];
2451 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', (
string) $vatrate);
2454 $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);
2455 $total_ht = $tabprice[0];
2456 $total_tva = $tabprice[1];
2457 $total_ttc = $tabprice[2];
2458 $pu_ht = $tabprice[3];
2459 $pu_tva = $tabprice[4];
2460 $pu_ttc = $tabprice[5];
2461 $total_localtax1 = $tabprice[9];
2462 $total_localtax2 = $tabprice[10];
2465 $multicurrency_total_ht = $tabprice[16];
2466 $multicurrency_total_tva = $tabprice[17];
2467 $multicurrency_total_ttc = $tabprice[18];
2468 $pu_ht_devise = $tabprice[19];
2470 if (empty($info_bits)) {
2477 $line->fetch_optionals();
2479 $staticline = clone $line;
2482 $product =
new Product($this->db);
2483 $result = $product->fetch($idproduct);
2484 $product_type = $product->type;
2486 $idproduct = $staticline->fk_product;
2487 $product_type = $type;
2490 $line->oldline = $staticline;
2491 $line->context = $this->context;
2493 $line->description = $desc;
2494 $line->desc = $desc;
2496 $line->qty = ($this->
type == self::TYPE_CREDIT_NOTE ? abs((
float) $qty) : (float) $qty);
2497 $line->subprice = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs((
float) $pu_ht) : (float) $pu_ht);
2498 $line->pu_ht = $line->subprice;
2499 $line->pu_ttc = ($this->
type == self::TYPE_CREDIT_NOTE ? -abs((
float) $pu_ttc) : (float) $pu_ttc);
2501 $line->remise_percent = $remise_percent;
2502 $line->ref_supplier = $ref_supplier;
2504 $line->date_start = $date_start;
2505 $line->date_end = $date_end;
2507 $line->vat_src_code = $vat_src_code;
2508 $line->tva_tx = $vatrate;
2509 $line->localtax1_tx = $txlocaltax1;
2510 $line->localtax2_tx = $txlocaltax2;
2511 $line->localtax1_type = empty($localtaxes_type[0]) ? 0 : $localtaxes_type[0];
2512 $line->localtax2_type = empty($localtaxes_type[2]) ? 0 : $localtaxes_type[2];
2514 $line->total_ht = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_ht) : (float) $total_ht);
2515 $line->total_tva = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_tva) : (float) $total_tva);
2516 $line->total_localtax1 = (float) $total_localtax1;
2517 $line->total_localtax2 = (float) $total_localtax2;
2518 $line->total_ttc = (($this->
type == self::TYPE_CREDIT_NOTE || $qty < 0) ? -abs((
float) $total_ttc) : (float) $total_ttc);
2520 $line->fk_product = $idproduct;
2521 $line->product_type = $product_type;
2522 $line->info_bits = $info_bits;
2523 $line->fk_unit = $fk_unit;
2524 $line->rang = $rang;
2526 if (is_array($array_options) && count($array_options) > 0) {
2528 foreach ($array_options as $key => $value) {
2529 $line->array_options[$key] = $array_options[$key];
2534 $line->multicurrency_subprice = (float) $pu_ht_devise;
2535 $line->multicurrency_total_ht = (float) $multicurrency_total_ht;
2536 $line->multicurrency_total_tva = (float) $multicurrency_total_tva;
2537 $line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
2539 $res = $line->update($notrigger);
2542 $this->errors[] = $line->error;
2543 $this->errors = array_merge($this->errors, $line->errors);
2546 $res = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2567 if ($line->fetch($rowid) < 1) {
2570 if ($this->
id > 0 && (
int) $line->fk_facture_fourn !== (
int) $this->id) {
2571 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
2578 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'societe_remise_except';
2579 $sql .=
' SET fk_invoice_supplier_line = NULL';
2580 $sql .=
' WHERE fk_invoice_supplier_line = '.((int) $rowid);
2582 dol_syslog(get_class($this).
"::deleteline", LOG_DEBUG);
2583 $result = $this->db->query($sql);
2585 $this->error = $this->db->error();
2586 $this->db->rollback();
2590 $res = $line->delete($notrigger);
2593 $this->errors[] = $line->error;
2594 $this->db->rollback();
2600 $this->db->commit();
2603 $this->db->rollback();
2604 $this->error = $this->db->lasterror();
2619 $sql =
'SELECT c.rowid, datec, tms as datem, ';
2620 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid';
2621 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn as c';
2622 $sql .=
' WHERE c.rowid = '.((int) $id);
2624 $result = $this->db->query($sql);
2626 if ($this->db->num_rows($result)) {
2627 $obj = $this->db->fetch_object($result);
2629 $this->
id = $obj->rowid;
2631 $this->user_creation_id = $obj->fk_user_author;
2632 $this->user_validation_id = $obj->fk_user_valid;
2633 $this->user_modification_id = $obj->fk_user_modif;
2634 $this->date_creation = $this->db->jdate($obj->datec);
2635 $this->date_modification = $this->db->jdate($obj->datem);
2638 $this->db->free($result);
2660 $sql =
"SELECT f.rowid as rowid, f.ref, f.fk_statut,";
2661 $sql .=
" ff.rowid as rowidnext";
2662 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
2663 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
2664 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON f.rowid = ff.fk_facture_source";
2665 $sql .=
" WHERE (f.fk_statut = ".self::STATUS_VALIDATED.
" OR (f.fk_statut = ".self::STATUS_ABANDONED.
" AND f.close_code = '".self::CLOSECODE_ABANDONED.
"'))";
2666 $sql .=
" AND f.entity = ".$conf->entity;
2667 $sql .=
" AND f.paye = 0";
2668 $sql .=
" AND pf.fk_paiementfourn IS NULL";
2669 $sql .=
" AND ff.fk_statut IS NULL";
2671 $sql .=
" AND f.fk_soc = ".((int) $socid);
2673 $sql .=
" ORDER BY f.ref";
2675 dol_syslog(get_class($this).
"::list_replacable_supplier_invoices", LOG_DEBUG);
2676 $resql = $this->db->query($sql);
2678 while ($obj = $this->db->fetch_object($resql)) {
2679 $return[$obj->rowid] = array(
2680 'id' => $obj->rowid,
2682 'status' => $obj->fk_statut
2688 $this->error = $this->db->error();
2710 $sql =
"SELECT f.rowid as rowid, f.ref, f.fk_statut, f.type, f.subtype, f.paye, pf.fk_paiementfourn";
2711 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
2712 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
2713 $sql .=
" WHERE f.entity = ".$conf->entity;
2714 $sql .=
" AND f.fk_statut in (".self::STATUS_VALIDATED.
",".self::STATUS_CLOSED.
")";
2715 $sql .=
" AND NOT EXISTS (SELECT rowid from ".MAIN_DB_PREFIX.
"facture_fourn as ff WHERE f.rowid = ff.fk_facture_source";
2716 $sql .=
" AND ff.type=".self::TYPE_REPLACEMENT.
")";
2717 $sql .=
" AND f.type != ".self::TYPE_CREDIT_NOTE;
2719 $sql .=
" AND f.fk_soc = ".((int) $socid);
2721 $sql .=
" ORDER BY f.ref";
2723 dol_syslog(get_class($this).
"::list_qualified_avoir_supplier_invoices", LOG_DEBUG);
2724 $resql = $this->db->query($sql);
2726 while ($obj = $this->db->fetch_object($resql)) {
2728 if ($obj->fk_statut == self::STATUS_VALIDATED) {
2731 if ($obj->fk_statut == self::STATUS_CLOSED) {
2735 $paymentornot = ($obj->fk_paiementfourn ? 1 : 0);
2736 $return[$obj->rowid] = array(
'ref' => (
string) $obj->ref,
'status' => (
int) $obj->fk_statut,
'type' => (
int) $obj->type,
'paye' => (
int) $obj->paye,
'paymentornot' => (
int) $paymentornot);
2742 $this->error = $this->db->error();
2757 global
$conf, $langs;
2759 $sql =
'SELECT ff.rowid, ff.date_lim_reglement as datefin, ff.fk_statut as status, ff.total_ht, ff.total_ttc';
2760 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn as ff';
2761 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir")) {
2762 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON ff.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2764 $sql .=
' WHERE ff.paye = 0';
2765 $sql .=
" AND ff.fk_statut IN (".self::STATUS_VALIDATED.
")";
2766 $sql .=
" AND ff.entity = ".$conf->entity;
2768 $sql .=
' AND ff.fk_soc = '.((int) $user->socid);
2771 $resql = $this->db->query($sql);
2773 $langs->load(
"bills");
2777 $response->warning_delay =
$conf->facture->fournisseur->warning_delay / 60 / 60 / 24;
2778 $response->label = $langs->trans(
"SupplierBillsToPay");
2779 $response->labelShort = $langs->trans(
"StatusToPay");
2781 $response->url = DOL_URL_ROOT.
'/fourn/facture/list.php?search_status=1&mainmenu=billing&leftmenu=suppliers_bills';
2782 $response->img =
img_object($langs->trans(
"Bills"),
"bill");
2786 while ($obj = $this->db->fetch_object($resql)) {
2787 $facturestatic->date_echeance = $this->db->jdate($obj->datefin);
2788 $facturestatic->statut = $obj->status;
2789 $facturestatic->status = $obj->status;
2791 $response->nbtodo++;
2792 $response->total += $obj->total_ht;
2794 if ($facturestatic->hasDelay()) {
2795 $response->nbtodolate++;
2796 $response->url_late = DOL_URL_ROOT.
'/fourn/facture/list.php?search_option=late&mainmenu=billing&leftmenu=suppliers_bills';
2800 $this->db->free($resql);
2804 $this->error = $this->db->error();
2818 global
$conf, $langs, $mysoc;
2820 $langs->load(
'bills');
2823 $moretitle = $params[
'moretitle'] ??
'';
2825 $picto = $this->picto;
2826 if ($this->
type == self::TYPE_REPLACEMENT) {
2829 if ($this->
type == self::TYPE_CREDIT_NOTE) {
2832 if ($this->
type == self::TYPE_DEPOSIT) {
2836 $datas[
'picto'] =
img_picto(
'', $picto).
' <u class="paddingrightonly">'.$langs->trans(
"SupplierInvoice").
'</u>';
2837 if ($this->
type == self::TYPE_REPLACEMENT) {
2838 $datas[
'picto'] .=
'<u class="paddingrightonly">'.$langs->transnoentitiesnoconv(
"InvoiceReplacement").
'</u>';
2839 } elseif ($this->
type == self::TYPE_CREDIT_NOTE) {
2840 $datas[
'picto'] .=
'<u class="paddingrightonly">'.$langs->transnoentitiesnoconv(
"CreditNote").
'</u>';
2841 } elseif ($this->
type == self::TYPE_DEPOSIT) {
2842 $datas[
'picto'] .=
'<u class="paddingrightonly">'.$langs->transnoentitiesnoconv(
"Deposit").
'</u>';
2844 if (isset($this->
status)) {
2846 if (isset($this->totalpaid)) {
2847 $alreadypaid = $this->totalpaid;
2850 $datas[
'picto'] .=
' '.$this->getLibStatut(5, $alreadypaid);
2853 $datas[
'picto'] .=
' - '.$moretitle;
2855 if (!empty($this->
ref)) {
2856 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
2858 if (!empty($this->ref_supplier)) {
2859 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
2861 if (!empty($this->label)) {
2862 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
2864 if (!empty($this->date)) {
2865 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
2867 if (!empty($this->date_echeance)) {
2868 $datas[
'date_echeance'] =
'<br><b>'.$langs->trans(
'DateDue').
':</b> '.
dol_print_date($this->date_echeance,
'day');
2870 if (!empty($this->total_ht)) {
2871 $datas[
'amountht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1,
$conf->currency);
2873 if (!empty($this->total_tva)) {
2874 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'AmountVAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1,
$conf->currency);
2876 if (!empty($this->total_localtax1) && $this->total_localtax1 != 0) {
2878 $datas[
'amountlt1'] =
'<br><b>'.$langs->transcountry(
'AmountLT1', $mysoc->country_code).
':</b> '.
price($this->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency);
2880 if (!empty($this->total_localtax2) && $this->total_localtax2 != 0) {
2881 $datas[
'amountlt2'] =
'<br><b>'.$langs->transcountry(
'AmountLT2', $mysoc->country_code).
':</b> '.
price($this->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency);
2883 if (!empty($this->revenuestamp)) {
2884 $datas[
'amountrevenustamp'] =
'<br><b>'.$langs->trans(
'RevenueStamp').
':</b> '.
price($this->revenuestamp, 0, $langs, 0, -1, -1,
$conf->currency);
2886 if (!empty($this->total_ttc)) {
2887 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency);
2905 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
2907 global $langs,
$conf, $user, $hookmanager;
2911 if ($option ==
'withdraw') {
2912 $url = DOL_URL_ROOT.
'/compta/facture/prelevement.php?facid='.$this->
id.
'&type=bank-transfer';
2913 } elseif ($option ==
'document') {
2914 $url = DOL_URL_ROOT.
'/fourn/facture/document.php?facid='.$this->id;
2916 $url = DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$this->id;
2923 if ($option !==
'nolink') {
2925 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2926 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2927 $add_save_lastsearch_values = 1;
2929 if ($add_save_lastsearch_values) {
2930 $url .=
'&save_lastsearch_values=1';
2934 $picto = $this->picto;
2935 if ($this->
type == self::TYPE_REPLACEMENT) {
2938 if ($this->
type == self::TYPE_CREDIT_NOTE) {
2941 if ($this->
type == self::TYPE_DEPOSIT) {
2947 'objecttype' => $this->element,
2948 'option' => $option,
2949 'moretitle' => $moretitle,
2951 $classfortooltip =
'classfortooltip';
2954 $classfortooltip =
'classforajaxtooltip';
2955 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2967 if (empty($notooltip)) {
2969 $label = $langs->trans(
"ShowSupplierInvoice");
2970 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
2972 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
2973 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
2976 $linkstart =
'<a href="'.$url.
'"';
2977 $linkstart .= $linkclose.
'>';
2980 $result .= $linkstart;
2982 $result .=
img_object(($notooltip ?
'' : $label), ($picto ? $picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
2984 if ($withpicto != 2) {
2985 $result .= ($max ?
dol_trunc($ref, $max) : $ref);
2987 $result .= $linkend;
2989 if ($addlinktonotes) {
2990 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
2993 $result .=
' <span class="note inline-block">';
2994 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
2997 $result .=
'</span>';
3001 $hookmanager->initHooks(array($this->element .
'dao'));
3002 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3003 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3005 $result = $hookmanager->resPrint;
3007 $result .= $hookmanager->resPrint;
3024 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
3025 return parent::setCategoriesCommon($categories, Categorie::TYPE_SUPPLIER_INVOICE);
3038 global $db, $langs,
$conf;
3039 $langs->load(
"orders");
3043 $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER =
'mod_facture_fournisseur_cactus';
3052 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
3054 foreach ($dirmodels as $reldir) {
3055 $dir =
dol_buildpath($reldir.
"core/modules/supplier_invoice/");
3058 $mybool = ((bool) @include_once $dir.$file) || $mybool;
3066 $obj =
new $classname();
3067 '@phan-var-force ModeleNumRefSuppliersInvoices $obj';
3069 $numref = $obj->getNextValue($soc, $this, $mode);
3071 if ($numref !=
"") {
3074 $this->error = $obj->error;
3090 global $langs,
$conf;
3091 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
3099 $sql =
"SELECT rowid";
3100 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
3101 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3102 $sql .= $this->db->plimit(100);
3104 $resql = $this->db->query($sql);
3106 $num_prods = $this->db->num_rows($resql);
3108 while ($i < $num_prods) {
3110 $row = $this->db->fetch_row($resql);
3111 $prodids[$i] = $row[0];
3117 $this->
ref =
'SPECIMEN';
3118 $this->ref_supplier =
'SUPPLIER_REF_SPECIMEN';
3119 $this->specimen = 1;
3122 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3123 $this->cond_reglement_code =
'RECEP';
3124 $this->mode_reglement_code =
'CHQ';
3126 $this->note_public =
'This is a comment (public)';
3127 $this->note_private =
'This is a comment (private)';
3129 $this->multicurrency_tx = 1;
3130 $this->multicurrency_code =
$conf->currency;
3133 if (empty($option) || $option !=
'nolines') {
3136 while ($xnbp < $nbp) {
3138 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3140 $line->subprice = 100;
3141 $line->pu_ht = $line->subprice;
3143 $line->tva_tx = 19.6;
3144 $line->localtax1_tx = 0;
3145 $line->localtax2_tx = 0;
3147 $line->total_ht = 50;
3148 $line->total_ttc = 59.8;
3149 $line->total_tva = 9.8;
3150 $line->remise_percent = 50;
3152 $line->total_ht = 100;
3153 $line->total_ttc = 119.6;
3154 $line->total_tva = 19.6;
3155 $line->remise_percent = 0;
3158 if ($num_prods > 0) {
3159 $prodid = mt_rand(1, $num_prods);
3160 $line->fk_product = $prodids[$prodid];
3162 $line->product_type = 0;
3164 $this->lines[$xnbp] = $line;
3166 $this->total_ht += $line->total_ht;
3167 $this->total_tva += $line->total_tva;
3168 $this->total_ttc += $line->total_ttc;
3174 $this->total_ht = $xnbp * 100;
3175 $this->total_tva = $xnbp * 19.6;
3176 $this->total_ttc = $xnbp * 119.6;
3188 global
$conf, $user;
3190 $this->nb = array();
3194 $sql =
"SELECT count(f.rowid) as nb";
3195 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
3196 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON f.fk_soc = s.rowid";
3197 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir")) {
3198 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3199 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3202 $sql .=
" ".$clause.
" f.entity = ".((int)
$conf->entity);
3204 $resql = $this->db->query($sql);
3206 while ($obj = $this->db->fetch_object($resql)) {
3207 $this->nb[
"supplier_invoices"] = $obj->nb;
3209 $this->db->free($resql);
3213 $this->error = $this->db->error();
3228 global
$conf, $langs;
3245 $object->ref_supplier = (empty($this->ref_supplier) ? $langs->trans(
"CopyOf").
' '.
$object->ref_supplier : $this->ref_supplier);
3247 $object->user_validation_id = 0;
3248 $object->fk_facture_source = 0;
3250 $object->date_validation =
'';
3260 $object->date_echeance =
$object->calculate_date_lim_reglement();
3263 foreach (
$object->lines as $i => $line) {
3264 if (isset(
$object->lines[$i]->info_bits) && (
$object->lines[$i]->info_bits & 0x02) == 0x02) {
3270 $object->context[
'createfromclone'] =
'createfromclone';
3271 $result =
$object->create($user);
3275 $this->error =
$object->error;
3276 $this->errors =
$object->errors;
3283 unset(
$object->context[
'createfromclone']);
3287 $this->db->commit();
3290 $this->db->rollback();
3306 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3310 $langs->load(
"suppliers");
3311 $outputlangs->load(
"products");
3314 if (empty($modele)) {
3320 } elseif ($modele ==
'auto') {
3321 $modele =
'canelle';
3324 if (empty($modele)) {
3327 $modelpath =
"core/modules/supplier_invoice/doc/";
3329 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3341 return $user->hasRight(
"fournisseur",
"facture");
3389 if (!$this->date_echeance) {
3393 $status = isset($this->
status) ? $this->
status : $this->statut;
3395 return ($status == self::STATUS_VALIDATED) && ($this->date_echeance < ($now -
$conf->facture->fournisseur->warning_delay));
3407 $sql =
"SELECT fk_invoice_supplier FROM ".MAIN_DB_PREFIX.
"societe_remise_except WHERE fk_invoice_supplier_source = ".((int) $this->
id);
3408 $resql = $this->db->query($sql);
3409 if (!empty($resql)) {
3410 $obj = $this->db->fetch_object($resql);
3411 if (!empty($obj->fk_invoice_supplier)) {
3429 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3431 $picto = $this->picto;
3432 if ($this->
type == self::TYPE_REPLACEMENT) {
3435 if ($this->
type == self::TYPE_CREDIT_NOTE) {
3438 if ($this->
type == self::TYPE_DEPOSIT) {
3442 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3443 $return .=
'<div class="info-box info-box-sm">';
3444 $return .=
'<span class="info-box-icon bg-infobox-action">';
3446 $return .=
'</span>';
3447 $return .=
'<div class="info-box-content">';
3448 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
3449 if ($selected >= 0) {
3450 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3452 if (!empty($arraydata[
'thirdparty'])) {
3453 $return .=
'<br><span class="info-box-label">'.$arraydata[
'thirdparty'].
'</span>';
3455 if (property_exists($this,
'date')) {
3456 $return .=
'<br><span class="info-box-label">'.dol_print_date($this->date,
'day').
'</span>';
3458 if (property_exists($this,
'total_ht')) {
3459 $return .=
' <span class="info-box-label amount" title="'.dol_escape_htmltag($langs->trans(
"AmountHT")).
'">'.
price($this->total_ht);
3460 $return .=
' '.$langs->trans(
"HT");
3461 $return .=
'</span>';
3463 if (method_exists($this,
'getLibStatut')) {
3464 $alreadypaid = (empty($arraydata[
'alreadypaid']) ? 0 : $arraydata[
'alreadypaid']);
3465 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3, $alreadypaid).
'</div>';
3467 $return .=
'</div>';
3468 $return .=
'</div>';
3469 $return .=
'</div>';
3481 if (!$this->table_element) {
3482 dol_syslog(get_class($this).
"::setVATReverseCharge was called on object with property table_element not defined", LOG_ERR);
3486 dol_syslog(get_class($this).
'::setVATReverseCharge('.$vatreversecharge.
')');
3488 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
3489 $sql .=
" SET vat_reverse_charge = ".((int) $vatreversecharge);
3490 $sql .=
" WHERE rowid=".((int) $this->
id);
3492 if ($this->db->query($sql)) {
3493 $this->vat_reverse_charge = ($vatreversecharge == 0) ? 0 : 1;
3496 dol_syslog(get_class($this).
'::setVATReverseCharge Error ', LOG_DEBUG);
3497 $this->error = $this->db->error();
3515 global
$conf, $langs, $user;
3522 $errorsMsg = array();
3524 $langs->load(
'bills');
3526 if (!isModEnabled(empty(
$conf->global->MAIN_USE_NEW_SUPPLIERMOD) ?
'fournisseur' :
'supplier_invoice')) {
3527 $this->output .= $langs->trans(
'ModuleNotEnabled', $langs->transnoentitiesnoconv(
'Suppliers'));
3530 if (!in_array($datetouse, array(
'duedate',
'invoicedate'))) {
3531 $this->output .=
'Bad value for parameter datetouse. Must be "duedate" or "invoicedate"';
3535 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
3536 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
3537 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
3538 $formmail =
new FormMail($this->db);
3548 $sql =
"SELECT rowid as id FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
3549 if (!empty($paymentmode) && $paymentmode !=
'all') {
3550 $sql .=
", ".MAIN_DB_PREFIX.
"c_paiement as cp";
3552 $sql .=
" WHERE f.paye = 0";
3553 $sql .=
" AND f.fk_statut = ".self::STATUS_VALIDATED;
3554 if ($datetouse ==
'invoicedate') {
3555 $sql .=
" AND f.datef = '".$this->db->idate($tmpidate,
'gmt').
"'";
3557 $sql .=
" AND f.date_lim_reglement = '".$this->db->idate($tmpidate,
'gmt').
"'";
3559 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice', 0).
")";
3560 if (!empty($paymentmode) && $paymentmode !=
'all') {
3561 $sql .=
" AND f.fk_mode_reglement = cp.id AND cp.code = '".$this->db->escape($paymentmode).
"'";
3564 if ($datetouse ==
'invoicedate') {
3565 $sql .= $this->db->order(
"datef",
"ASC");
3567 $sql .= $this->db->order(
"date_lim_reglement",
"ASC");
3570 $resql = $this->db->query($sql);
3573 if ($datetouse ==
'invoicedate') {
3574 $this->output .= $langs->transnoentitiesnoconv(
"SearchValidatedSupplierInvoicesWithDate", $stmpidate);
3576 $this->output .= $langs->transnoentitiesnoconv(
"SearchUnpaidSupplierInvoicesWithDueDate", $stmpidate);
3578 if (!empty($paymentmode) && $paymentmode !=
'all') {
3579 $this->output .=
' ('.$langs->transnoentitiesnoconv(
"PaymentMode").
' '.$paymentmode.
')';
3581 $this->output .=
'<br>';
3584 while ($obj = $this->db->fetch_object($resql)) {
3587 $res = $tmpinvoice->fetch($obj->id);
3589 $tmpinvoice->fetch_thirdparty();
3592 if ($tmpinvoice->thirdparty->default_lang) {
3593 $outputlangs->setDefaultLang($tmpinvoice->thirdparty->default_lang);
3594 $outputlangs->loadLangs(array(
"main",
"suppliers"));
3596 $outputlangs = $langs;
3601 $templateLabel =
'';
3602 if (empty($template) || $template ==
'EmailTemplateCode') {
3603 $templateLabel =
'(SendingReminderEmailOnUnpaidSupplierInvoice)';
3605 if (is_numeric($template)) {
3606 $templateId = $template;
3608 $templateLabel = $template;
3612 $arraymessage = $formmail->getEMailTemplate($this->db,
'invoice_supplier_send', $user, $outputlangs, $templateId, 1, $templateLabel);
3613 if (is_numeric($arraymessage) && $arraymessage <= 0) {
3614 $langs->load(
"errors");
3615 $this->output .= $langs->trans(
'ErrorFailedToFindEmailTemplate', $template);
3623 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $tmpinvoice);
3628 $sendTopic =
make_substitutions(empty($arraymessage->topic) ? $outputlangs->transnoentitiesnoconv(
'InformationMessage') : $arraymessage->topic, $substitutionarray, $outputlangs, 1);
3631 $content = $outputlangs->transnoentitiesnoconv($arraymessage->content);
3637 if ($forcerecipient) {
3638 $to = array($forcerecipient);
3640 $res = $tmpinvoice->fetch_thirdparty();
3641 $recipient = $tmpinvoice->thirdparty;
3643 $tmparraycontact = $tmpinvoice->liste_contact(-1,
'internal', 0,
'SALESREPFOLL');
3644 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
3645 foreach ($tmparraycontact as $data_email) {
3646 if (!empty($data_email[
'email'])) {
3647 $to[] = $data_email[
'email'];
3651 if (empty($to) && !empty($recipient->email)) {
3652 $to[] = $recipient->email;
3655 $errormesg =
"Failed to send remind to thirdparty id=".$tmpinvoice->socid.
". No email defined for supplier invoice or customer.";
3659 $errormesg =
"Failed to load recipient with thirdparty id=".$tmpinvoice->socid;
3666 if (!empty($arraymessage->email_from)) {
3667 $from = (string) $arraymessage->email_from;
3670 $errormesg =
"Failed to get sender into global setup MAIN_MAIL_EMAIL_FROM";
3674 if (!$error && !empty($to)) {
3677 $to = implode(
',', $to);
3678 if (!empty($arraymessage->email_to)) {
3679 $to = $to.
','.$arraymessage->email_to;
3683 $errors_to =
$conf->global->MAIN_MAIL_ERRORS_TO;
3685 $trackid =
'inv'.$tmpinvoice->id;
3686 $sendcontext =
'standard';
3689 if (!empty($arraymessage->email_tocc)) {
3690 $email_tocc = (string) $arraymessage->email_tocc;
3694 if (!empty($arraymessage->email_tobcc)) {
3695 $email_tobcc = (string) $arraymessage->email_tobcc;
3699 $cMailFile =
new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), $email_tocc, $email_tobcc, 0, 1, $errors_to,
'', $trackid,
'', $sendcontext,
'');
3702 if ($cMailFile->sendfile()) {
3706 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
3711 $actioncomm->type_code =
'AC_OTH_AUTO';
3712 $actioncomm->socid = $tmpinvoice->thirdparty->id;
3713 $actioncomm->contact_id = 0;
3715 $actioncomm->code =
'AC_EMAIL';
3716 $actioncomm->label =
'sendEmailsRemindersOnInvoiceDueDateOK (nbdays='.$nbdays.
' paymentmode='.$paymentmode.
' template='.$template.
' datetouse='.$datetouse.
' forcerecipient='.$forcerecipient.
')';
3717 $actioncomm->note_private = $sendContent;
3718 $actioncomm->fk_project = $tmpinvoice->fk_project;
3719 $actioncomm->datep =
dol_now();
3720 $actioncomm->datef = $actioncomm->datep;
3721 $actioncomm->percentage = -1;
3722 $actioncomm->authorid = $user->id;
3723 $actioncomm->userownerid = $user->id;
3725 $actioncomm->email_msgid = $cMailFile->msgid;
3726 $actioncomm->email_subject = $sendTopic;
3727 $actioncomm->email_from = $from;
3728 $actioncomm->email_sender =
'';
3729 $actioncomm->email_to = $to;
3733 $actioncomm->errors_to = $errors_to;
3735 $actioncomm->elementtype =
'invoice_supplier';
3736 $actioncomm->elementid = $tmpinvoice->id;
3737 $actioncomm->fk_element = $tmpinvoice->id;
3741 $actioncomm->create($user);
3743 $errormesg = $cMailFile->error.
' : '.$to;
3747 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
3752 $actioncomm->type_code =
'AC_OTH_AUTO';
3753 $actioncomm->socid = $tmpinvoice->thirdparty->id;
3754 $actioncomm->contact_id = 0;
3756 $actioncomm->code =
'AC_EMAIL';
3757 $actioncomm->label =
'sendEmailsRemindersOnInvoiceDueDateKO';
3758 $actioncomm->note_private = $errormesg;
3759 $actioncomm->fk_project = $tmpinvoice->fk_project;
3760 $actioncomm->datep =
dol_now();
3761 $actioncomm->datef = $actioncomm->datep;
3762 $actioncomm->percentage = -1;
3763 $actioncomm->authorid = $user->id;
3764 $actioncomm->userownerid = $user->id;
3766 $actioncomm->email_msgid = $cMailFile->msgid;
3767 $actioncomm->email_from = $from;
3768 $actioncomm->email_sender =
'';
3769 $actioncomm->email_to = $to;
3773 $actioncomm->errors_to = $errors_to;
3777 $actioncomm->create($user);
3780 $this->db->commit();
3784 $errorsMsg[] = $errormesg;
3787 $errorsMsg[] =
'Failed to fetch record invoice with ID = '.$obj->id;
3797 $this->output .=
'Nb of emails sent : '.$nbMailSend;
3799 dol_syslog(__METHOD__.
" end - ".$this->output, LOG_INFO);
3803 $this->error =
'Nb of emails sent : '.$nbMailSend.
', '.(empty($errorsMsg) ? $error : implode(
', ', $errorsMsg));
3805 dol_syslog(__METHOD__.
" end - ".$this->error, LOG_INFO);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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.
is_erasable()
Return if an invoice can be deleted Rule is: If invoice is draft and has a temporary ref -> yes (1) I...
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.
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
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)
Adds an invoice line (associated with no predefined product/service) The parameters are already suppo...
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.
__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.
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_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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_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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type