112 |
$this->remise_percent = $_facrec->remise_percent; |
$this->remise_percent = $_facrec->remise_percent; |
113 |
} |
} |
114 |
|
|
|
$sql = "SELECT fdm,nbjour "; |
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."cond_reglement"; |
|
|
$sql.= " WHERE rowid = ".$this->cond_reglement; |
|
|
if ($this->db->query($sql)) |
|
|
{ |
|
|
if ($this->db->num_rows()) |
|
|
{ |
|
|
$obj = $this->db->fetch_object(); |
|
|
$cdr_nbjour = $obj->nbjour; |
|
|
$cdr_fdm = $obj->fdm; |
|
|
} |
|
|
$this->db->free(); |
|
|
} |
|
|
|
|
115 |
// Definition de la date limite |
// Definition de la date limite |
116 |
$datelim = $this->date + ( $cdr_nbjour * 3600 * 24 ); |
$datelim=$this->calculate_date_lim_reglement(); |
|
if ($cdr_fdm) |
|
|
{ |
|
|
$mois=date('m', $datelim); |
|
|
$annee=date('Y', $datelim); |
|
|
$fins=array(31,28,31,30,31,30,31,31,30,31,30,31); |
|
|
$datelim=mktime(0,0,0,$mois,$fins[$mois-1],$annee); |
|
|
} |
|
117 |
|
|
118 |
/* |
/* |
119 |
* Insertion dans la base |
* Insertion dans la base |
124 |
$remise = $this->remise; |
$remise = $this->remise; |
125 |
|
|
126 |
if (! $remise) $remise = 0 ; |
if (! $remise) $remise = 0 ; |
127 |
if (strlen($this->mode_reglement)==0) $this->mode_reglement = 0; |
if (strlen($this->mode_reglement_id)==0) $this->mode_reglement_id = 0; |
128 |
if (! $this->projetid) $this->projetid = "NULL"; |
if (! $this->projetid) $this->projetid = "NULL"; |
129 |
|
|
130 |
$totalht = ($amount - $remise); |
$totalht = ($amount - $remise); |
316 |
//dolibarr_syslog("Facture::Fetch rowid : $rowid, societe_id : $societe_id"); |
//dolibarr_syslog("Facture::Fetch rowid : $rowid, societe_id : $societe_id"); |
317 |
|
|
318 |
$sql = "SELECT f.fk_soc,f.facnumber,f.amount,f.tva,f.total,f.total_ttc,f.remise,f.remise_percent"; |
$sql = "SELECT f.fk_soc,f.facnumber,f.amount,f.tva,f.total,f.total_ttc,f.remise,f.remise_percent"; |
319 |
$sql .= ",".$this->db->pdate("f.datef")." as df,f.fk_projet"; |
$sql .= ",".$this->db->pdate("f.datef")." as df, f.fk_projet"; |
320 |
$sql .= ",".$this->db->pdate("f.date_lim_reglement")." as dlr"; |
$sql .= ",".$this->db->pdate("f.date_lim_reglement")." as dlr"; |
321 |
$sql .= ", f.note, f.paye, f.fk_statut, f.fk_user_author"; |
$sql .= ", f.note, f.paye, f.fk_statut, f.fk_user_author"; |
322 |
$sql .= ", f.fk_mode_reglement, p.code as mode_reglement_code, p.libelle as mode_reglement_libelle"; |
$sql .= ", f.fk_mode_reglement, p.code as mode_reglement_code, p.libelle as mode_reglement_libelle"; |
335 |
if ($this->db->num_rows($result)) |
if ($this->db->num_rows($result)) |
336 |
{ |
{ |
337 |
$obj = $this->db->fetch_object($result); |
$obj = $this->db->fetch_object($result); |
338 |
|
//print strftime("%Y%m%d%H%M%S",$obj->df)." ".$obj->df." ".dolibarr_print_date($obj->df); |
339 |
|
|
340 |
$this->id = $rowid; |
$this->id = $rowid; |
341 |
$this->datep = $obj->dp; |
$this->datep = $obj->dp; |
617 |
} |
} |
618 |
} |
} |
619 |
|
|
620 |
|
|
621 |
/** |
/** |
622 |
* \brief Tag la facture comme payée complètement |
* \brief Renvoi une date limite de reglement de facture en fonction des |
623 |
* \param rowid id de la facture à modifier |
* conditions de reglements de la facture et date de facturation |
624 |
*/ |
* \param cond_reglement_id Condition de reglement à utiliser, 0=Condition actuelle de la facture |
625 |
|
* \return date Date limite de réglement si ok, <0 si ko |
626 |
|
*/ |
627 |
|
function calculate_date_lim_reglement($cond_reglement_id=0) |
628 |
|
{ |
629 |
|
if (! $cond_reglement_id) $cond_reglement_id=$this->cond_reglement_id; |
630 |
|
|
631 |
|
$sqltemp = "SELECT c.fdm,c.nbjour"; |
632 |
|
$sqltemp.= " FROM ".MAIN_DB_PREFIX."cond_reglement as c"; |
633 |
|
$sqltemp.= " WHERE c.rowid=".$cond_reglement_id; |
634 |
|
$resqltemp=$this->db->query($sqltemp); |
635 |
|
if ($resqltemp) |
636 |
|
{ |
637 |
|
if ($this->db->num_rows($resqltemp)) |
638 |
|
{ |
639 |
|
$obj = $this->db->fetch_object($resqltemp); |
640 |
|
$cdr_nbjour = $obj->nbjour; |
641 |
|
$cdr_fdm = $obj->fdm; |
642 |
|
} |
643 |
|
} |
644 |
|
else |
645 |
|
{ |
646 |
|
$this->error=$this->db->error(); |
647 |
|
return -1; |
648 |
|
} |
649 |
|
$this->db->free($resqltemp); |
650 |
|
// Definition de la date limite |
651 |
|
$datelim = $this->date + ( $cdr_nbjour * 3600 * 24 ); |
652 |
|
if ($cdr_fdm) |
653 |
|
{ |
654 |
|
$mois=date('m', $datelim); |
655 |
|
$annee=date('Y', $datelim); |
656 |
|
$fins=array(31,28,31,30,31,30,31,31,30,31,30,31); |
657 |
|
$datelim=mktime(12,0,0,$mois,$fins[$mois-1],$annee); |
658 |
|
} |
659 |
|
|
660 |
|
return $datelim; |
661 |
|
} |
662 |
|
|
663 |
|
|
664 |
|
/** |
665 |
|
* \brief Tag la facture comme payée complètement |
666 |
|
* \param rowid id de la facture à modifier |
667 |
|
*/ |
668 |
function set_payed($rowid) |
function set_payed($rowid) |
669 |
{ |
{ |
670 |
$sql = "UPDATE ".MAIN_DB_PREFIX."facture set paye=1 WHERE rowid = ".$rowid ; |
$sql = "UPDATE ".MAIN_DB_PREFIX."facture set paye=1 WHERE rowid = ".$rowid ; |
771 |
/* Si l'option est activée on force la date de facture */ |
/* Si l'option est activée on force la date de facture */ |
772 |
if (defined("FAC_FORCE_DATE_VALIDATION") && FAC_FORCE_DATE_VALIDATION == "1") |
if (defined("FAC_FORCE_DATE_VALIDATION") && FAC_FORCE_DATE_VALIDATION == "1") |
773 |
{ |
{ |
774 |
$sql .= ", datef=now()"; |
$this->date=time(); |
775 |
// du coup, il faut aussi recalculer la date limite de règlement |
$datelim=$this->calculate_date_lim_reglement(); |
|
$sqltemp = "SELECT c.fdm,c.nbjour,c.rowid,f.fk_cond_reglement,f.rowid"; |
|
|
$sqltemp.= " FROM ".MAIN_DB_PREFIX."cond_reglement as c, ".MAIN_DB_PREFIX."facture as f"; |
|
|
$sqltemp.= " WHERE c.rowid=f.fk_cond_reglement AND f.rowid=".$this->id; |
|
|
if ($this->db->query($sqltemp)) |
|
|
{ |
|
|
if ($this->db->num_rows()) |
|
|
{ |
|
|
$obj = $this->db->fetch_object(); |
|
|
$cdr_nbjour = $obj->nbjour; |
|
|
$cdr_fdm = $obj->fdm; |
|
|
} |
|
|
} |
|
|
$this->db->free(); |
|
|
// Definition de la date limite |
|
|
$datelim = time() + ( $cdr_nbjour * 3600 * 24 ); |
|
|
if ($cdr_fdm) |
|
|
{ |
|
|
$mois=date('m', $datelim); |
|
|
$annee=date('Y', $datelim); |
|
|
$fins=array(31,28,31,30,31,30,31,31,30,31,30,31); |
|
|
$datelim=mktime(0,0,0,$mois,$fins[$mois-1],$annee); |
|
|
} |
|
776 |
|
|
777 |
|
$sql .= ", datef=".$this->db->idate($this->date); |
778 |
$sql .= ", date_lim_reglement=".$this->db->idate($datelim); |
$sql .= ", date_lim_reglement=".$this->db->idate($datelim); |
|
|
|
779 |
} |
} |
780 |
|
|
781 |
$sql .= " WHERE rowid = $rowid ;"; |
$sql .= " WHERE rowid = $rowid ;"; |
782 |
|
|
783 |
$result = $this->db->query( $sql); |
$resql = $this->db->query($sql); |
784 |
if ($result) |
if ($resql) |
785 |
{ |
{ |
786 |
// Appel des triggers |
// Appel des triggers |
787 |
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); |
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); |
1362 |
} |
} |
1363 |
|
|
1364 |
/** |
/** |
1365 |
* \brief Change les conditions de réglement |
* \brief Change les conditions de réglement de la facture |
1366 |
* \param cond_reglement_id Id des nouvelles conditions |
* \param cond_reglement_id Id de la nouvelle condition de réglement |
1367 |
* \return int >0 si ok, <0 si ko |
* \return int >0 si ok, <0 si ko |
1368 |
*/ |
*/ |
1369 |
function cond_reglement($cond_reglement_id) |
function cond_reglement($cond_reglement_id) |
1371 |
dolibarr_syslog("Facture::cond_reglement($cond_reglement_id)"); |
dolibarr_syslog("Facture::cond_reglement($cond_reglement_id)"); |
1372 |
if ($this->statut >= 0 && $this->paye == 0) |
if ($this->statut >= 0 && $this->paye == 0) |
1373 |
{ |
{ |
1374 |
|
$datelim=$this->calculate_date_lim_reglement($cond_reglement_id); |
1375 |
|
|
1376 |
$sql = "UPDATE ".MAIN_DB_PREFIX."facture"; |
$sql = "UPDATE ".MAIN_DB_PREFIX."facture"; |
1377 |
$sql .= " SET fk_cond_reglement = ".$cond_reglement_id; |
$sql .= " SET fk_cond_reglement = ".$cond_reglement_id; |
1378 |
|
$sql .= ", date_lim_reglement=".$this->db->idate($datelim); |
1379 |
$sql .= " WHERE rowid=".$this->id; |
$sql .= " WHERE rowid=".$this->id; |
1380 |
|
|
1381 |
if ( $this->db->query($sql) ) |
if ( $this->db->query($sql) ) |
1725 |
*/ |
*/ |
1726 |
function fetch($rowid, $societe_id=0) |
function fetch($rowid, $societe_id=0) |
1727 |
{ |
{ |
1728 |
$sql = "SELECT fk_product, description, price, qty, rowid, tva_taux, remise, remise_percent, subprice, ".$this->db->pdate("date_start")." as date_start,".$this->db->pdate("date_end")." as date_end"; |
$sql = "SELECT fk_product, description, price, qty, rowid, tva_taux, remise, remise_percent,"; |
1729 |
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$rowid; |
$sql.= " subprice, ".$this->db->pdate("date_start")." as date_start,".$this->db->pdate("date_end")." as date_end"; |
1730 |
|
$sql.= " FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$rowid; |
1731 |
|
|
1732 |
$result = $this->db->query($sql); |
$result = $this->db->query($sql); |
1733 |
if ($result) |
if ($result) |
1734 |
{ |
{ |
1735 |
$objp = $this->db->fetch_object($result); |
$objp = $this->db->fetch_object($result); |
1736 |
|
|
1737 |
$this->desc = stripslashes($objp->description); |
$this->desc = stripslashes($objp->description); |
1738 |
$this->qty = $objp->qty; |
$this->qty = $objp->qty; |
1739 |
$this->price = $objp->price; |
$this->price = $objp->price; |