Fix : duedate was not auto calculated + move calculation function to common invoice class
This commit is contained in:
parent
bada082b2b
commit
19a3194b02
@ -1406,75 +1406,6 @@ class Facture extends CommonInvoice
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renvoi une date limite de reglement de facture en fonction des
|
|
||||||
* conditions de reglements de la facture et date de facturation
|
|
||||||
*
|
|
||||||
* @param string $cond_reglement Condition of payment (code or id) to use. If 0, we use current condition.
|
|
||||||
* @return date Date limite de reglement si ok, <0 si ko
|
|
||||||
*/
|
|
||||||
function calculate_date_lim_reglement($cond_reglement=0)
|
|
||||||
{
|
|
||||||
if (! $cond_reglement) $cond_reglement=$this->cond_reglement_code;
|
|
||||||
if (! $cond_reglement) $cond_reglement=$this->cond_reglement_id;
|
|
||||||
|
|
||||||
$cdr_nbjour=0; $cdr_fdm=0; $cdr_decalage=0;
|
|
||||||
|
|
||||||
$sqltemp = 'SELECT c.fdm,c.nbjour,c.decalage';
|
|
||||||
$sqltemp.= ' FROM '.MAIN_DB_PREFIX.'c_payment_term as c';
|
|
||||||
if (is_numeric($cond_reglement)) $sqltemp.= " WHERE c.rowid=".$cond_reglement;
|
|
||||||
else $sqltemp.= " WHERE c.code='".$this->db->escape($cond_reglement)."'";
|
|
||||||
|
|
||||||
dol_syslog(get_class($this).'::calculate_date_lim_reglement sql='.$sqltemp);
|
|
||||||
$resqltemp=$this->db->query($sqltemp);
|
|
||||||
if ($resqltemp)
|
|
||||||
{
|
|
||||||
if ($this->db->num_rows($resqltemp))
|
|
||||||
{
|
|
||||||
$obj = $this->db->fetch_object($resqltemp);
|
|
||||||
$cdr_nbjour = $obj->nbjour;
|
|
||||||
$cdr_fdm = $obj->fdm;
|
|
||||||
$cdr_decalage = $obj->decalage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->error=$this->db->error();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
$this->db->free($resqltemp);
|
|
||||||
|
|
||||||
/* Definition de la date limite */
|
|
||||||
|
|
||||||
// 1 : ajout du nombre de jours
|
|
||||||
$datelim = $this->date + ($cdr_nbjour * 3600 * 24);
|
|
||||||
|
|
||||||
// 2 : application de la regle "fin de mois"
|
|
||||||
if ($cdr_fdm)
|
|
||||||
{
|
|
||||||
$mois=date('m', $datelim);
|
|
||||||
$annee=date('Y', $datelim);
|
|
||||||
if ($mois == 12)
|
|
||||||
{
|
|
||||||
$mois = 1;
|
|
||||||
$annee += 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$mois += 1;
|
|
||||||
}
|
|
||||||
// On se deplace au debut du mois suivant, et on retire un jour
|
|
||||||
$datelim=dol_mktime(12,0,0,$mois,1,$annee);
|
|
||||||
$datelim -= (3600 * 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3 : application du decalage
|
|
||||||
$datelim += ($cdr_decalage * 3600 * 24);
|
|
||||||
|
|
||||||
return $datelim;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tag la facture comme paye completement (si close_code non renseigne) => this->fk_statut=2, this->paye=1
|
* Tag la facture comme paye completement (si close_code non renseigne) => this->fk_statut=2, this->paye=1
|
||||||
* ou partiellement (si close_code renseigne) + appel trigger BILL_PAYED => this->fk_statut=2, this->paye stay 0
|
* ou partiellement (si close_code renseigne) + appel trigger BILL_PAYED => this->fk_statut=2, this->paye stay 0
|
||||||
|
|||||||
@ -288,6 +288,74 @@ abstract class CommonInvoice extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renvoi une date limite de reglement de facture en fonction des
|
||||||
|
* conditions de reglements de la facture et date de facturation
|
||||||
|
*
|
||||||
|
* @param string $cond_reglement Condition of payment (code or id) to use. If 0, we use current condition.
|
||||||
|
* @return date Date limite de reglement si ok, <0 si ko
|
||||||
|
*/
|
||||||
|
function calculate_date_lim_reglement($cond_reglement=0)
|
||||||
|
{
|
||||||
|
if (! $cond_reglement) $cond_reglement=$this->cond_reglement_code;
|
||||||
|
if (! $cond_reglement) $cond_reglement=$this->cond_reglement_id;
|
||||||
|
|
||||||
|
$cdr_nbjour=0; $cdr_fdm=0; $cdr_decalage=0;
|
||||||
|
|
||||||
|
$sqltemp = 'SELECT c.fdm,c.nbjour,c.decalage';
|
||||||
|
$sqltemp.= ' FROM '.MAIN_DB_PREFIX.'c_payment_term as c';
|
||||||
|
if (is_numeric($cond_reglement)) $sqltemp.= " WHERE c.rowid=".$cond_reglement;
|
||||||
|
else $sqltemp.= " WHERE c.code='".$this->db->escape($cond_reglement)."'";
|
||||||
|
|
||||||
|
dol_syslog(get_class($this).'::calculate_date_lim_reglement sql='.$sqltemp);
|
||||||
|
$resqltemp=$this->db->query($sqltemp);
|
||||||
|
if ($resqltemp)
|
||||||
|
{
|
||||||
|
if ($this->db->num_rows($resqltemp))
|
||||||
|
{
|
||||||
|
$obj = $this->db->fetch_object($resqltemp);
|
||||||
|
$cdr_nbjour = $obj->nbjour;
|
||||||
|
$cdr_fdm = $obj->fdm;
|
||||||
|
$cdr_decalage = $obj->decalage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$this->db->error();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
$this->db->free($resqltemp);
|
||||||
|
|
||||||
|
/* Definition de la date limite */
|
||||||
|
|
||||||
|
// 1 : ajout du nombre de jours
|
||||||
|
$datelim = $this->date + ($cdr_nbjour * 3600 * 24);
|
||||||
|
|
||||||
|
// 2 : application de la regle "fin de mois"
|
||||||
|
if ($cdr_fdm)
|
||||||
|
{
|
||||||
|
$mois=date('m', $datelim);
|
||||||
|
$annee=date('Y', $datelim);
|
||||||
|
if ($mois == 12)
|
||||||
|
{
|
||||||
|
$mois = 1;
|
||||||
|
$annee += 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mois += 1;
|
||||||
|
}
|
||||||
|
// On se deplace au debut du mois suivant, et on retire un jour
|
||||||
|
$datelim=dol_mktime(12,0,0,$mois,1,$annee);
|
||||||
|
$datelim -= (3600 * 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3 : application du decalage
|
||||||
|
$datelim += ($cdr_decalage * 3600 * 24);
|
||||||
|
|
||||||
|
return $datelim;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -300,6 +300,9 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer)
|
|||||||
$object->cond_reglement_id = GETPOST('cond_reglement_id');
|
$object->cond_reglement_id = GETPOST('cond_reglement_id');
|
||||||
$object->mode_reglement_id = GETPOST('mode_reglement_id');
|
$object->mode_reglement_id = GETPOST('mode_reglement_id');
|
||||||
$object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
|
$object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
|
||||||
|
|
||||||
|
// Auto calculation of date due if not filled by user
|
||||||
|
if(empty($object->date_echeance)) $object->date_echeance = $object->calculate_date_lim_reglement();
|
||||||
|
|
||||||
// If creation from another object of another module
|
// If creation from another object of another module
|
||||||
if ($_POST['origin'] && $_POST['originid'])
|
if ($_POST['origin'] && $_POST['originid'])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user