26 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
110 $remaintopay =
price2num($this->total_ttc - $alreadypaid,
'MT');
111 if ($this->
statut == self::STATUS_CLOSED && $this->close_code ==
'discount_vat') {
126 $table =
'paiement_facture';
127 $field =
'fk_facture';
128 if ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier')
130 $table =
'paiementfourn_facturefourn';
131 $field =
'fk_facturefourn';
134 $sql =
'SELECT sum(amount) as amount, sum(multicurrency_amount) as multicurrency_amount';
135 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
136 $sql .=
' WHERE '.$field.
' = '.$this->id;
138 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
142 $obj = $this->
db->fetch_object(
$resql);
144 if ($multicurrency)
return $obj->multicurrency_amount;
145 else return $obj->amount;
147 $this->error = $this->
db->lasterror();
161 if ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier')
167 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
170 $result = $discountstatic->getSumDepositsUsed($this, $multicurrency);
174 $this->error = $discountstatic->error;
187 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
190 $result = $discountstatic->getSumCreditNotesUsed($this, $multicurrency);
194 $this->error = $discountstatic->error;
207 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
210 $result = $discountstatic->getSumFromThisCreditNotesNotUsed($this, $multicurrency);
214 $this->error = $discountstatic->error;
228 $sql =
'SELECT rowid';
229 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element;
230 $sql .=
' WHERE fk_facture_source = '.$this->id;
231 $sql .=
' AND type = 2';
239 $row = $this->
db->fetch_row(
$resql);
240 $idarray[] = $row[0];
257 $sql =
'SELECT rowid';
258 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element;
259 $sql .=
' WHERE fk_facture_source = '.$this->id;
260 $sql .=
' AND type < 2';
261 if ($option ==
'validated') $sql .=
' AND fk_statut = 1';
267 $sql .=
' ORDER BY fk_statut DESC';
272 $obj = $this->
db->fetch_object(
$resql);
296 $table =
'paiement_facture';
297 $table2 =
'paiement';
298 $field =
'fk_facture';
299 $field2 =
'fk_paiement';
300 $field3 =
', p.ref_ext';
301 $sharedentity =
'facture';
302 if ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier')
304 $table =
'paiementfourn_facturefourn';
305 $table2 =
'paiementfourn';
306 $field =
'fk_facturefourn';
307 $field2 =
'fk_paiementfourn';
309 $sharedentity =
'facture_fourn';
312 $sql =
'SELECT p.ref, pf.amount, pf.multicurrency_amount, p.fk_paiement, p.datep, p.num_paiement as num, t.code'.$field3;
313 $sql .=
' FROM '.MAIN_DB_PREFIX.$table.
' as pf, '.MAIN_DB_PREFIX.$table2.
' as p, '.MAIN_DB_PREFIX.
'c_paiement as t';
314 $sql .=
' WHERE pf.'.$field.
' = '.$this->id;
316 $sql .=
' AND pf.'.$field2.
' = p.rowid';
317 $sql .=
' AND p.fk_paiement = t.id';
318 $sql .=
' AND p.entity IN ('.getEntity($sharedentity).
')';
319 if ($filtertype) $sql .=
" AND t.code='PRE'";
321 dol_syslog(get_class($this).
"::getListOfPayments", LOG_DEBUG);
329 $obj = $this->
db->fetch_object(
$resql);
330 $tmp = array(
'amount'=>$obj->amount,
'type'=>$obj->code,
'date'=>$obj->datep,
'num'=>$obj->num,
'ref'=>$obj->ref);
331 if (!empty($field3)) {
332 $tmp[
'ref_ext'] = $obj->ref_ext;
341 if ($this->element ==
'facture' || $this->element ==
'invoice')
343 $sql =
'SELECT rc.amount_ttc as amount, rc.multicurrency_amount_ttc as multicurrency_amount, rc.datec as date, f.ref as ref, rc.description as type';
344 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe_remise_except as rc, '.MAIN_DB_PREFIX.
'facture as f';
345 $sql .=
' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$this->id;
346 $sql .=
' AND (f.type = 2 OR f.type = 0 OR f.type = 3)';
347 } elseif ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier')
349 $sql =
'SELECT rc.amount_ttc as amount, rc.multicurrency_amount_ttc as multicurrency_amount, rc.datec as date, f.ref as ref, rc.description as type';
350 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe_remise_except as rc, '.MAIN_DB_PREFIX.
'facture_fourn as f';
351 $sql .=
' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$this->id;
352 $sql .=
' AND (f.type = 2 OR f.type = 0 OR f.type = 3)';
363 $obj = $this->
db->fetch_object(
$resql);
364 if ($multicurrency) {
365 $retarray[] = array(
'amount'=>$obj->multicurrency_amount,
'type'=>$obj->type,
'date'=>$obj->date,
'num'=>
'0',
'ref'=>$obj->ref);
367 $retarray[] = array(
'amount'=>$obj->amount,
'type'=>$obj->type,
'date'=>$obj->date,
'num'=>
'',
'ref'=>$obj->ref);
372 $this->error = $this->
db->lasterror();
381 $this->error = $this->
db->lasterror();
408 $tmppart = substr($this->ref, 1, 4);
410 if ($this->
statut == self::STATUS_DRAFT && $tmppart ===
'PROV')
415 if (!empty($conf->global->INVOICE_CAN_NEVER_BE_REMOVED))
return 0;
418 if ($tmppart !==
'PROV')
421 if ($ventilExportCompta != 0)
return -1;
424 if ($this->element !=
'invoice_supplier')
427 $maxref = $this->getNextNumRef($this->thirdparty,
'last');
431 if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $maxref !=
'' && $maxref != $this->ref)
return -2;
436 if ($this->situation_cycle_ref && method_exists($this,
'is_last_in_cycle'))
438 $last = $this->is_last_in_cycle();
439 if (!$last)
return -3;
445 if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $this->getSommePaiement() > 0)
return -4;
457 $alreadydispatched = 0;
459 $type =
'customer_invoice';
460 if ($this->element ==
'invoice_supplier') $type =
'supplier_invoice';
462 $sql =
" SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='".$this->
db->escape($type).
"' AND ab.fk_doc = ".$this->id;
466 $obj = $this->
db->fetch_object(
$resql);
469 $alreadydispatched = $obj->nb;
472 $this->error = $this->
db->lasterror();
476 if ($alreadydispatched)
498 return $langs->trans(
"Unknown");
524 public function LibStatut($paye, $status, $mode = 0, $alreadypaid = -1, $type = -1)
528 $langs->load(
'bills');
530 if ($type == -1) $type = $this->type;
532 $statusType =
'status0';
536 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusDraft');
537 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusDraft');
538 } elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) {
539 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusClosedUnpaid');
540 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusClosedUnpaid');
541 $statusType =
'status5';
542 } elseif (($status == 3 || $status == 2) && $alreadypaid > 0) {
543 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusClosedPaidPartially');
544 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusClosedPaidPartially');
545 $statusType =
'status9';
546 } elseif ($alreadypaid == 0) {
547 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
548 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusNotPaid');
549 $statusType =
'status1';
551 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusStarted');
552 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusStarted');
553 $statusType =
'status3';
556 $statusType =
'status6';
558 if ($type == self::TYPE_CREDIT_NOTE) {
559 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusPaidBackOrConverted');
560 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusPaidBackOrConverted');
561 } elseif ($type == self::TYPE_DEPOSIT) {
562 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusConverted');
563 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusConverted');
565 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusPaid');
566 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusPaid');
570 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
584 if (!$cond_reglement) $cond_reglement = $this->cond_reglement_code;
585 if (!$cond_reglement) $cond_reglement = $this->cond_reglement_id;
591 $sqltemp =
'SELECT c.type_cdr, c.nbjour, c.decalage';
592 $sqltemp .=
' FROM '.MAIN_DB_PREFIX.
'c_payment_term as c';
593 if (is_numeric($cond_reglement)) $sqltemp .=
" WHERE c.rowid=".$cond_reglement;
595 $sqltemp .=
" WHERE c.entity IN (".getEntity(
'c_payment_term').
")";
596 $sqltemp .=
" AND c.code='".$this->db->escape($cond_reglement).
"'";
599 dol_syslog(get_class($this).
'::calculate_date_lim_reglement', LOG_DEBUG);
600 $resqltemp = $this->
db->query($sqltemp);
603 if ($this->
db->num_rows($resqltemp))
605 $obj = $this->
db->fetch_object($resqltemp);
606 $cdr_nbjour = $obj->nbjour;
607 $cdr_type = $obj->type_cdr;
608 $cdr_decalage = $obj->decalage;
611 $this->error = $this->
db->error();
614 $this->
db->free($resqltemp);
621 $datelim = $this->date + ($cdr_nbjour * 3600 * 24);
623 $datelim += ($cdr_decalage * 3600 * 24);
626 elseif ($cdr_type == 1)
628 $datelim = $this->date + ($cdr_nbjour * 3600 * 24);
630 $mois = date(
'm', $datelim);
631 $annee = date(
'Y', $datelim);
640 $datelim =
dol_mktime(12, 0, 0, $mois, 1, $annee);
641 $datelim -= (3600 * 24);
643 $datelim += ($cdr_decalage * 3600 * 24);
646 elseif ($cdr_type == 2 && !empty($cdr_decalage))
648 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
649 $datelim = $this->date + ($cdr_nbjour * 3600 * 24);
651 $date_piece =
dol_mktime(0, 0, 0, date(
'm', $datelim), date(
'd', $datelim), date(
'Y', $datelim));
652 $date_lim_current =
dol_mktime(0, 0, 0, date(
'm', $datelim), $cdr_decalage, date(
'Y', $datelim));
655 $diff = $date_piece - $date_lim_current;
657 if ($diff < 0) $datelim = $date_lim_current;
658 else $datelim = $date_lim_next;
660 return 'Bad value for type_cdr in database for record cond_reglement = '.$cond_reglement;
684 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
686 if ($this->
statut > self::STATUS_DRAFT && $this->paye == 0)
688 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
690 $bac->fetch(0, $this->socid);
692 $sql =
'SELECT count(*)';
693 $sql .=
' FROM '.MAIN_DB_PREFIX.
'prelevement_facture_demande';
694 if ($type ==
'bank-transfer') {
695 $sql .=
' WHERE fk_facture_fourn = '.$this->id;
697 $sql .=
' WHERE fk_facture = '.$this->id;
699 $sql .=
' AND ext_payment_id IS NULL';
700 $sql .=
' AND traite = 0';
702 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
706 $row = $this->
db->fetch_row(
$resql);
720 if (empty($amount)) $amount =
price2num($this->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,
'MT');
722 if (is_numeric($amount) && $amount != 0)
724 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'prelevement_facture_demande(';
725 if ($type ==
'bank-transfer') {
726 $sql .=
'fk_facture_fourn, ';
728 $sql .=
'fk_facture, ';
730 $sql .=
' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, entity)';
731 $sql .=
' VALUES ('.$this->id;
732 $sql .=
",'".price2num($amount).
"'";
733 $sql .=
",'".$this->db->idate($now).
"'";
734 $sql .=
",".$fuser->id;
735 $sql .=
",'".$this->db->escape($bac->code_banque).
"'";
736 $sql .=
",'".$this->db->escape($bac->code_guichet).
"'";
737 $sql .=
",'".$this->db->escape($bac->number).
"'";
738 $sql .=
",'".$this->db->escape($bac->cle_rib).
"'";
739 $sql .=
",'".$this->db->escape($sourcetype).
"'";
740 $sql .=
",".$conf->entity;
743 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
746 $this->error = $this->
db->lasterror();
747 dol_syslog(get_class($this).
'::demandeprelevement Erreur');
751 $this->error =
'WithdrawRequestErrorNilAmount';
752 dol_syslog(get_class($this).
'::demandeprelevement WithdrawRequestErrorNilAmount');
758 $payment_mode_id =
dol_getIdFromCode($this->
db, ($type ==
'bank-transfer' ?
'VIR' :
'PRE'),
'c_paiement',
'code',
'id', 1);
759 if ($payment_mode_id > 0) {
764 if ($error)
return -1;
767 $this->error =
"A request already exists";
768 dol_syslog(get_class($this).
'::demandeprelevement Impossible de creer une demande, demande deja en cours');
772 $this->error = $this->
db->error();
773 dol_syslog(get_class($this).
'::demandeprelevement Erreur -2');
777 $this->error =
"Status of invoice does not allow this";
778 dol_syslog(get_class($this).
"::demandeprelevement ".$this->error.
" $this->statut, $this->paye, $this->mode_reglement_id");
794 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'prelevement_facture_demande';
795 $sql .=
' WHERE rowid = '.$did;
796 $sql .=
' AND traite = 0';
797 if ($this->
db->query($sql))
801 $this->error = $this->
db->lasterror();
802 dol_syslog(get_class($this).
'::demande_prelevement_delete Error '.$this->error);
810 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
838 public $product_type = 0;
850 public $product_label;
856 public $product_desc;
880 public $vat_src_code;
892 public $localtax1_tx;
898 public $localtax2_tx;
904 public $remise_percent;
922 public $total_localtax1;
928 public $total_localtax2;
936 public $date_start_fill;
937 public $date_end_fill;
945 public $info_bits = 0;
947 public $special_code = 0;
949 public $fk_multicurrency;
950 public $multicurrency_code;
951 public $multicurrency_subprice;
952 public $multicurrency_total_ht;
953 public $multicurrency_total_tva;
954 public $multicurrency_total_ttc;
calculate_date_lim_reglement($cond_reglement=0)
Returns an invoice payment deadline based on the invoice settlement conditions and billing date...
const STATUS_CLOSED
Classified paid.
const TYPE_STANDARD
Standard invoice.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
getSumFromThisCreditNotesNotUsed($multicurrency=0)
Return amount (with tax) of all converted amount for this credit note.
is_erasable()
Return if an invoice can be deleted Rule is: If invoice is draft and has a temporary ref -> yes (1) I...
getListOfPayments($filtertype= '')
Return list of payments.
dol_now($mode= 'auto')
Return date for now.
demande_prelevement_delete($fuser, $did)
Remove a direct debit request or a credit transfer request.
Class to manage bank accounts description of third parties.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of object status.
$label
Custom label of line.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
Parent class of all other business classes for details of elements (invoices, contracts, proposals, orders, ...)
$conf db
API class for accounts.
getListIdAvoirFromInvoice()
Returns array of credit note ids from the invoice.
const TYPE_PROFORMA
Proforma invoice.
demande_prelevement($fuser, $amount=0, $type= 'direct-debit', $sourcetype= 'facture')
Create a withdrawal request for a direct debit order or a credit transfer order.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
getLibType()
Return label of type of invoice.
const TYPE_REPLACEMENT
Replacement invoice.
getRemainToPay($multicurrency=0)
Return remain amount to pay.
getSommePaiement($multicurrency=0)
Return amount of payments already done.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
getSumCreditNotesUsed($multicurrency=0)
Return amount (with tax) of all credit notes invoices + excess received used by invoice.
const STATUS_DRAFT
Draft status.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Superclass for invoices classes.
setPaymentMethods($id)
Change the payments methods.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
trait CommonIncoterm
Superclass for incoterm classes.
const STATUS_ABANDONED
Classified abandoned and no payment done.
getSumDepositsUsed($multicurrency=0)
Return amount (with tax) of all deposits invoices used by invoice.
const TYPE_SITUATION
Situation invoice.
getIdReplacingInvoice($option= '')
Returns the id of the invoice that replaces it.
getVentilExportCompta()
Return if an invoice was dispatched into bookkeeping.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Class to manage absolute discounts.
const STATUS_VALIDATED
Validated (need to be paid)
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
const TYPE_DEPOSIT
Deposit invoice.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
LibStatut($paye, $status, $mode=0, $alreadypaid=-1, $type=-1)
Return label of a status.
const TYPE_CREDIT_NOTE
Credit note invoice.