Merge pull request #1666 from atm-maxime/develop
Fix : duedate was not auto calculated + move calculation function to com...
This commit is contained in:
commit
8819f3e6e2
@ -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
|
||||
* 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->mode_reglement_id = GETPOST('mode_reglement_id');
|
||||
$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 ($_POST['origin'] && $_POST['originid'])
|
||||
|
||||
@ -48,6 +48,7 @@ $sall = GETPOST('sall', 'alpha');
|
||||
$type = GETPOST('type','int');
|
||||
$tobuy = GETPOST('tobuy', 'int');
|
||||
$salert = GETPOST('salert', 'alpha');
|
||||
$mode = GETPOST('mode','alpha');
|
||||
|
||||
$sortfield = GETPOST('sortfield','alpha');
|
||||
$sortorder = GETPOST('sortorder','alpha');
|
||||
@ -191,8 +192,8 @@ $usevirtualstock=-1;
|
||||
if ($virtualdiffersfromphysical)
|
||||
{
|
||||
$usevirtualstock=($conf->global->STOCK_USE_VIRTUAL_STOCK?1:0);
|
||||
if (GETPOST('mode')=='virtual') $usevirtualstock=1;
|
||||
if (GETPOST('mode')=='physical') $usevirtualstock=0;
|
||||
if ($mode=='virtual') $usevirtualstock=1;
|
||||
if ($mode=='physical') $usevirtualstock=0;
|
||||
}
|
||||
|
||||
$title = $langs->trans('Status');
|
||||
@ -240,8 +241,30 @@ $sql.= ' GROUP BY p.rowid, p.ref, p.label, p.price';
|
||||
$sql.= ', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
|
||||
$sql.= ', p.duration, p.tobuy, p.seuil_stock_alerte';
|
||||
$sql.= ', p.desiredstock, s.fk_product';
|
||||
$sql.= ' HAVING p.desiredstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' AND p.desiredstock > 0';
|
||||
|
||||
if($usevirtualstock) {
|
||||
$sqlCommandesCli = "(SELECT SUM(cd.qty) as qty";
|
||||
$sqlCommandesCli.= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
|
||||
$sqlCommandesCli.= ", ".MAIN_DB_PREFIX."commande as c";
|
||||
$sqlCommandesCli.= " WHERE c.rowid = cd.fk_commande";
|
||||
$sqlCommandesCli.= " AND c.entity = ".$conf->entity;
|
||||
$sqlCommandesCli.= " AND cd.fk_product = p.rowid";
|
||||
$sqlCommandesCli.= " AND c.fk_statut in (1,2))";
|
||||
|
||||
$sqlCommandesFourn = "(SELECT SUM(cd.qty) as qty";
|
||||
$sqlCommandesFourn.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd";
|
||||
$sqlCommandesFourn.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
|
||||
$sqlCommandesFourn.= " WHERE c.rowid = cd.fk_commande";
|
||||
$sqlCommandesFourn.= " AND c.entity = ".$conf->entity;
|
||||
$sqlCommandesFourn.= " AND cd.fk_product = p.rowid";
|
||||
$sqlCommandesFourn.= " AND c.fk_statut in (3))";
|
||||
|
||||
$sql.= ' HAVING p.desiredstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' - '.$db->ifsql($sqlCommandesCli.' IS NULL', '0', $sqlCommandesCli).' + '.$db->ifsql($sqlCommandesFourn.' IS NULL', '0', $sqlCommandesFourn);
|
||||
} else {
|
||||
$sql.= ' HAVING p.desiredstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' AND p.desiredstock > 0';
|
||||
}
|
||||
if ($salert == 'on') // Option to see when stock is lower than alert
|
||||
{
|
||||
$sql .= ' AND SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").') < p.seuil_stock_alerte AND p.seuil_stock_alerte is not NULL';
|
||||
@ -295,6 +318,7 @@ if ($sref || $snom || $sall || $salert || GETPOST('search', 'alpha')) {
|
||||
$filters = '&sref=' . $sref . '&snom=' . $snom;
|
||||
$filters .= '&sall=' . $sall;
|
||||
$filters .= '&salert=' . $salert;
|
||||
$filters .= '&mode=' . $mode;
|
||||
print_barre_liste(
|
||||
$texte,
|
||||
$page,
|
||||
@ -310,6 +334,7 @@ if ($sref || $snom || $sall || $salert || GETPOST('search', 'alpha')) {
|
||||
$filters .= '&fourn_id=' . $fourn_id;
|
||||
$filters .= (isset($type)?'&type=' . $type:'');
|
||||
$filters .= '&salert=' . $salert;
|
||||
$filters .= '&mode=' . $mode;
|
||||
print_barre_liste(
|
||||
$texte,
|
||||
$page,
|
||||
@ -335,6 +360,7 @@ print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">'
|
||||
$param = (isset($type)? '&type=' . $type : '');
|
||||
$param .= '&fourn_id=' . $fourn_id . '&snom='. $snom . '&salert=' . $salert;
|
||||
$param .= '&sref=' . $sref;
|
||||
$param .= '&mode=' . $mode;
|
||||
|
||||
// Lignes des titres
|
||||
print '<tr class="liste_titre">'.
|
||||
@ -589,6 +615,7 @@ if ($num > $conf->liste_limit)
|
||||
$filters = '&sref=' . $sref . '&snom=' . $snom;
|
||||
$filters .= '&sall=' . $sall;
|
||||
$filters .= '&salert=' . $salert;
|
||||
$filters .= '&mode=' . $mode;
|
||||
print_barre_liste(
|
||||
'',
|
||||
$page,
|
||||
@ -606,6 +633,7 @@ if ($num > $conf->liste_limit)
|
||||
$filters .= '&fourn_id=' . $fourn_id;
|
||||
$filters .= (isset($type)? '&type=' . $type : '');
|
||||
$filters .= '&salert=' . $salert;
|
||||
$filters .= '&mode=' . $mode;
|
||||
print_barre_liste(
|
||||
'',
|
||||
$page,
|
||||
|
||||
@ -3058,7 +3058,7 @@ class Societe extends CommonObject
|
||||
|
||||
// Set outstanding amount
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
|
||||
$sql.= " outstanding_limit= ".($outstanding!=''?$outstanding:'null');
|
||||
$sql.= " outstanding_limit= '".($outstanding!=''?$outstanding:'null')."'";
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::set_outstanding sql=".$sql);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user