Fix: Function to find last invoice must look only into number
This commit is contained in:
parent
1889059dea
commit
09fc3ba4c5
@ -55,9 +55,9 @@ $projectid=isset($_GET['projectid'])?$_GET['projectid']:0;
|
|||||||
|
|
||||||
// Security check
|
// Security check
|
||||||
$socid=isset($_GET['socid'])?$_GET['socid']:$_POST['socid'];
|
$socid=isset($_GET['socid'])?$_GET['socid']:$_POST['socid'];
|
||||||
$facid = isset($_GET["id"])?$_GET["id"]:$_POST["id"];
|
$facid=GETPOST("id");
|
||||||
if (empty($facid)) $facid=isset($_GET["ref"])?$_GET["ref"]:$_POST["ref"];
|
if (empty($facid)) $facid=GETPOST("facid"); // For backward compatibility
|
||||||
if (empty($facid)) $facid=isset($_GET["facid"])?$_GET["facid"]:$_POST["facid"]; // For backward compatibility
|
$ref=GETPOST("ref");
|
||||||
$fieldid = isset($_GET["ref"])?'facnumber':'rowid';
|
$fieldid = isset($_GET["ref"])?'facnumber':'rowid';
|
||||||
if ($user->societe_id) $socid=$user->societe_id;
|
if ($user->societe_id) $socid=$user->societe_id;
|
||||||
$result = restrictedArea($user, 'facture', $facid,'','','fk_soc',$fieldid);
|
$result = restrictedArea($user, 'facture', $facid,'','','fk_soc',$fieldid);
|
||||||
@ -1937,7 +1937,7 @@ else
|
|||||||
$now=dol_now();
|
$now=dol_now();
|
||||||
|
|
||||||
$id = $facid;
|
$id = $facid;
|
||||||
$ref= $_REQUEST['ref'];
|
$ref= GETPOST('ref');
|
||||||
|
|
||||||
if ($id > 0 || ! empty($ref))
|
if ($id > 0 || ! empty($ref))
|
||||||
{
|
{
|
||||||
@ -2567,35 +2567,6 @@ else
|
|||||||
}
|
}
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Lit lignes de facture pour determiner montant
|
|
||||||
// On s'en sert pas mais ca sert pour debuggage
|
|
||||||
/*
|
|
||||||
$sql = 'SELECT l.price as price, l.qty, l.rowid, l.tva_tx,';
|
|
||||||
$sql .= ' l.remise_percent, l.subprice';
|
|
||||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet as l ';
|
|
||||||
$sql .= ' WHERE l.fk_facture = '.$object->id;
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$num_lignes = $db->num_rows($resql);
|
|
||||||
$i=0;
|
|
||||||
$total_lignes_ht=0;
|
|
||||||
$total_lignes_vat=0;
|
|
||||||
$total_lignes_ttc=0;
|
|
||||||
while ($i < $num_lignes)
|
|
||||||
{
|
|
||||||
$obj=$db->fetch_object($resql);
|
|
||||||
$ligne_ht=($obj->price*$obj->qty);
|
|
||||||
$ligne_vat=($ligne_ht*$obj->tva_tx/100);
|
|
||||||
$ligne_ttc=($ligne_ht+$ligne_vat);
|
|
||||||
$total_lignes_ht+=$ligne_ht;
|
|
||||||
$total_lignes_vat+=$ligne_vat;
|
|
||||||
$total_lignes_ttc+=$ligne_ttc;
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Montants
|
// Montants
|
||||||
print '<tr><td>'.$langs->trans('AmountHT').'</td>';
|
print '<tr><td>'.$langs->trans('AmountHT').'</td>';
|
||||||
print '<td align="right" colspan="2" nowrap>'.price($object->total_ht).'</td>';
|
print '<td align="right" colspan="2" nowrap>'.price($object->total_ht).'</td>';
|
||||||
@ -2714,6 +2685,7 @@ else
|
|||||||
/*
|
/*
|
||||||
* Boutons actions
|
* Boutons actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ($_GET['action'] != 'prerelance' && $_GET['action'] != 'presend')
|
if ($_GET['action'] != 'prerelance' && $_GET['action'] != 'presend')
|
||||||
{
|
{
|
||||||
if ($user->societe_id == 0 && $_GET['action'] <> 'valid' && $_GET['action'] <> 'editline')
|
if ($user->societe_id == 0 && $_GET['action'] <> 'valid' && $_GET['action'] <> 'editline')
|
||||||
|
|||||||
@ -2337,12 +2337,13 @@ class Facture extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Return next reference of invoice not already used
|
* Return next reference of invoice not already used (or last reference)
|
||||||
* according to numbering module defined into constant FACTURE_ADDON
|
* according to numbering module defined into constant FACTURE_ADDON
|
||||||
* \param soc objet company
|
* @param soc objet company
|
||||||
* \return string free ref
|
* @param mode 'next' for next value or 'last' for last value
|
||||||
|
* @return string free ref or last ref
|
||||||
*/
|
*/
|
||||||
function getNextNumRef($soc)
|
function getNextNumRef($soc,$mode='next')
|
||||||
{
|
{
|
||||||
global $conf, $db, $langs;
|
global $conf, $db, $langs;
|
||||||
$langs->load("bills");
|
$langs->load("bills");
|
||||||
@ -2388,7 +2389,7 @@ class Facture extends CommonObject
|
|||||||
$obj = new $classname();
|
$obj = new $classname();
|
||||||
|
|
||||||
$numref = "";
|
$numref = "";
|
||||||
$numref = $obj->getNumRef($soc,$this);
|
$numref = $obj->getNumRef($soc,$this,$mode);
|
||||||
|
|
||||||
if ( $numref != "")
|
if ( $numref != "")
|
||||||
{
|
{
|
||||||
@ -2529,7 +2530,7 @@ class Facture extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* \brief Renvoi si les lignes de facture sont ventilees et/ou exportees en compta
|
* \brief Renvoi si les lignes de facture sont ventilees et/ou exportees en compta
|
||||||
* \param user Utilisateur creant la demande
|
* \param user Utilisateur creant la demande
|
||||||
* \return int <0 si ko, 0=non, 1=oui
|
* \return int <0 if KO, 0=no, 1=yes
|
||||||
*/
|
*/
|
||||||
function getVentilExportCompta()
|
function getVentilExportCompta()
|
||||||
{
|
{
|
||||||
@ -2559,7 +2560,7 @@ class Facture extends CommonObject
|
|||||||
* La regle est la suivante:
|
* La regle est la suivante:
|
||||||
* Si facture derniere, non provisoire, sans paiement et non exporte en compta -> oui fin de regle
|
* Si facture derniere, non provisoire, sans paiement et non exporte en compta -> oui fin de regle
|
||||||
* Si facture brouillon et provisoire -> oui
|
* Si facture brouillon et provisoire -> oui
|
||||||
* @return int <0 si ko, 0=non, 1=oui
|
* @return int <0 if KO, 0=no, 1=yes
|
||||||
*/
|
*/
|
||||||
function is_erasable()
|
function is_erasable()
|
||||||
{
|
{
|
||||||
@ -2568,27 +2569,13 @@ class Facture extends CommonObject
|
|||||||
// on verifie si la facture est en numerotation provisoire
|
// on verifie si la facture est en numerotation provisoire
|
||||||
$facref = substr($this->ref, 1, 4);
|
$facref = substr($this->ref, 1, 4);
|
||||||
|
|
||||||
// Si facture non brouillon et non provisoire
|
// If not a draft invoice and not temporary invoice
|
||||||
if ($facref != 'PROV')
|
if ($facref != 'PROV')
|
||||||
{
|
{
|
||||||
// On ne peut supprimer que la derniere facture validee
|
$maxfacnumber = $this->getNextNumRef($this->client,'last');
|
||||||
// pour ne pas avoir de trou dans la numerotation
|
|
||||||
// FIXME Le dernier num de facture n'est pas forcement le max !
|
|
||||||
// Utiliser le module de numérotation pour trouver le max.
|
|
||||||
$sql = "SELECT MAX(facnumber)";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
|
|
||||||
$sql.= " WHERE entity = ".$conf->entity;
|
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$maxfacnumber = $this->db->fetch_row($resql);
|
|
||||||
}
|
|
||||||
|
|
||||||
$ventilExportCompta = $this->getVentilExportCompta();
|
$ventilExportCompta = $this->getVentilExportCompta();
|
||||||
|
|
||||||
// Si derniere facture et si non ventilee, on peut supprimer
|
// Si derniere facture et si non ventilee, on peut supprimer
|
||||||
if ($maxfacnumber[0] == $this->ref && $ventilExportCompta == 0)
|
if ($maxfacnumber == $this->ref && $ventilExportCompta == 0)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -105,12 +105,13 @@ class mod_facture_mercure extends ModeleNumRefFactures
|
|||||||
return $numExample;
|
return $numExample;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Return next value
|
/** Return next value
|
||||||
* \param objsoc Object third party
|
* @param objsoc Object third party
|
||||||
* \param facture Object invoice
|
* @param facture Object invoice
|
||||||
* \return string Value if OK, 0 if KO
|
* @param mode 'next' for next value or 'last' for last value
|
||||||
|
* @return string Value if OK, 0 if KO
|
||||||
*/
|
*/
|
||||||
function getNextValue($objsoc,$facture)
|
function getNextValue($objsoc,$facture,$mode='next')
|
||||||
{
|
{
|
||||||
global $db,$conf;
|
global $db,$conf;
|
||||||
|
|
||||||
@ -130,20 +131,21 @@ class mod_facture_mercure extends ModeleNumRefFactures
|
|||||||
if ($facture->type == 2) $where.= " AND type = 2";
|
if ($facture->type == 2) $where.= " AND type = 2";
|
||||||
else $where.=" AND type != 2";
|
else $where.=" AND type != 2";
|
||||||
|
|
||||||
$numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc,$facture->date);
|
$numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc,$facture->date,$mode);
|
||||||
|
|
||||||
return $numFinal;
|
return $numFinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** \brief Return next free value
|
/** Return next free value
|
||||||
* \param objsoc Object third party
|
* @param objsoc Object third party
|
||||||
* \param objforref Object for number to search
|
* @param objforref Object for number to search
|
||||||
* \return string Next free value
|
* @param mode 'next' for next value or 'last' for last value
|
||||||
|
* @return string Next free value
|
||||||
*/
|
*/
|
||||||
function getNumRef($objsoc,$objforref)
|
function getNumRef($objsoc,$objforref,$mode='next')
|
||||||
{
|
{
|
||||||
return $this->getNextValue($objsoc,$objforref);
|
return $this->getNextValue($objsoc,$objforref,$mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -110,12 +110,13 @@ class mod_facture_terre extends ModeleNumRefFactures
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Renvoi prochaine valeur attribuee
|
/** Return next value not used or last value used
|
||||||
* \param objsoc Objet societe
|
* @param objsoc Object third party
|
||||||
* \param facture Objet facture
|
* @param facture Object invoice
|
||||||
* \return string Valeur
|
* @param mode 'next' for next value or 'last' for last value
|
||||||
|
* @return string Value
|
||||||
*/
|
*/
|
||||||
function getNextValue($objsoc,$facture)
|
function getNextValue($objsoc,$facture,$mode='next')
|
||||||
{
|
{
|
||||||
global $db,$conf;
|
global $db,$conf;
|
||||||
|
|
||||||
@ -143,6 +144,29 @@ class mod_facture_terre extends ModeleNumRefFactures
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($mode == 'last')
|
||||||
|
{
|
||||||
|
$num = sprintf("%04s",$max);
|
||||||
|
|
||||||
|
$ref='';
|
||||||
|
$sql = "SELECT facnumber as ref";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
|
||||||
|
$sql.= " WHERE facnumber LIKE '".$prefix."____-".$num."'";
|
||||||
|
$sql.= " AND entity = ".$conf->entity;
|
||||||
|
|
||||||
|
dol_syslog("mod_facture_terre::getNextValue sql=".$sql);
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$obj = $db->fetch_object($resql);
|
||||||
|
if ($obj) $ref = $obj->ref;
|
||||||
|
}
|
||||||
|
else dol_print_error($db);
|
||||||
|
|
||||||
|
return $ref;
|
||||||
|
}
|
||||||
|
else if ($mode == 'next')
|
||||||
|
{
|
||||||
$date=$facture->date; // This is invoice date (not creation date)
|
$date=$facture->date; // This is invoice date (not creation date)
|
||||||
$yymm = strftime("%y%m",$date);
|
$yymm = strftime("%y%m",$date);
|
||||||
$num = sprintf("%04s",$max+1);
|
$num = sprintf("%04s",$max+1);
|
||||||
@ -150,15 +174,18 @@ class mod_facture_terre extends ModeleNumRefFactures
|
|||||||
dol_syslog("mod_facture_terre::getNextValue return ".$prefix.$yymm."-".$num);
|
dol_syslog("mod_facture_terre::getNextValue return ".$prefix.$yymm."-".$num);
|
||||||
return $prefix.$yymm."-".$num;
|
return $prefix.$yymm."-".$num;
|
||||||
}
|
}
|
||||||
|
else dol_print_error('','Bad parameter for getNextValue');
|
||||||
|
}
|
||||||
|
|
||||||
/** \brief Return next free value
|
/** Return next free value
|
||||||
* \param objsoc Object third party
|
* @param objsoc Object third party
|
||||||
* \param objforref Object for number to search
|
* @param objforref Object for number to search
|
||||||
* \return string Next free value
|
* @param mode 'next' for next value or 'last' for last value
|
||||||
|
* @return string Next free value
|
||||||
*/
|
*/
|
||||||
function getNumRef($objsoc,$objforref)
|
function getNumRef($objsoc,$objforref,$mode='next')
|
||||||
{
|
{
|
||||||
return $this->getNextValue($objsoc,$objforref);
|
return $this->getNextValue($objsoc,$objforref,$mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user