Fix: Function to find last invoice must look only into number

This commit is contained in:
Laurent Destailleur 2010-12-13 23:38:47 +00:00
parent 1889059dea
commit 09fc3ba4c5
4 changed files with 3317 additions and 3329 deletions

View File

@ -55,9 +55,9 @@ $projectid=isset($_GET['projectid'])?$_GET['projectid']:0;
// Security check
$socid=isset($_GET['socid'])?$_GET['socid']:$_POST['socid'];
$facid = isset($_GET["id"])?$_GET["id"]:$_POST["id"];
if (empty($facid)) $facid=isset($_GET["ref"])?$_GET["ref"]:$_POST["ref"];
if (empty($facid)) $facid=isset($_GET["facid"])?$_GET["facid"]:$_POST["facid"]; // For backward compatibility
$facid=GETPOST("id");
if (empty($facid)) $facid=GETPOST("facid"); // For backward compatibility
$ref=GETPOST("ref");
$fieldid = isset($_GET["ref"])?'facnumber':'rowid';
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'facture', $facid,'','','fk_soc',$fieldid);
@ -1390,7 +1390,7 @@ if ($_GET['action'] == 'create')
if ($element == 'order') { $element = $subelement = 'commande'; }
if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
if ($element == 'contract') { $element = $subelement = 'contrat'; }
require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php');
$classname = ucfirst($subelement);
$objectsrc = new $classname($db);
@ -1781,7 +1781,7 @@ if ($_GET['action'] == 'create')
if ($_GET['origin'] == 'propal')
{
//$objectsrc->printOriginLinesList();
$title=$langs->trans('ProductsAndServices');
$sql = 'SELECT pt.rowid, pt.description, pt.fk_remise_except,';
@ -1937,7 +1937,7 @@ else
$now=dol_now();
$id = $facid;
$ref= $_REQUEST['ref'];
$ref= GETPOST('ref');
if ($id > 0 || ! empty($ref))
{
@ -2567,35 +2567,6 @@ else
}
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
print '<tr><td>'.$langs->trans('AmountHT').'</td>';
print '<td align="right" colspan="2" nowrap>'.price($object->total_ht).'</td>';
@ -2714,6 +2685,7 @@ else
/*
* Boutons actions
*/
if ($_GET['action'] != 'prerelance' && $_GET['action'] != 'presend')
{
if ($user->societe_id == 0 && $_GET['action'] <> 'valid' && $_GET['action'] <> 'editline')
@ -2888,7 +2860,7 @@ else
// Delete
if ($user->rights->facture->supprimer)
{
if (! $object->is_erasable())
if (! $object->is_erasable())
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans("DisabledBecauseNotErasable").'">'.$langs->trans('Delete').'</a>';
}

File diff suppressed because it is too large Load Diff

View File

@ -35,52 +35,52 @@ require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php")
*/
class mod_facture_mercure extends ModeleNumRefFactures
{
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $error = '';
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $error = '';
/** \brief Renvoi la description du modele de numerotation
* \return string Texte descripif
*/
function info()
function info()
{
global $conf,$langs;
global $conf,$langs;
$langs->load("bills");
$langs->load("bills");
$form = new Form($db);
$form = new Form($db);
$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$texte.= '<input type="hidden" name="action" value="updateMask">';
$texte.= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">';
$texte.= '<input type="hidden" name="maskconstcredit" value="FACTURE_MERCURE_MASK_CREDIT">';
$texte.= '<table class="nobordernopadding" width="100%">';
$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$texte.= '<input type="hidden" name="action" value="updateMask">';
$texte.= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">';
$texte.= '<input type="hidden" name="maskconstcredit" value="FACTURE_MERCURE_MASK_CREDIT">';
$texte.= '<table class="nobordernopadding" width="100%">';
$tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Invoice"));
$tooltip.=$langs->trans("GenericMaskCodes2");
$tooltip.=$langs->trans("GenericMaskCodes3");
$tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Invoice"),$langs->transnoentities("Invoice"));
$tooltip.=$langs->trans("GenericMaskCodes5");
$tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Invoice"));
$tooltip.=$langs->trans("GenericMaskCodes2");
$tooltip.=$langs->trans("GenericMaskCodes3");
$tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Invoice"),$langs->transnoentities("Invoice"));
$tooltip.=$langs->trans("GenericMaskCodes5");
// Parametrage du prefix
$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):</td>';
$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskinvoice" value="'.$conf->global->FACTURE_MERCURE_MASK_INVOICE.'">',$tooltip,1,1).'</td>';
// Parametrage du prefix
$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):</td>';
$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskinvoice" value="'.$conf->global->FACTURE_MERCURE_MASK_INVOICE.'">',$tooltip,1,1).'</td>';
$texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte.= '</tr>';
$texte.= '</tr>';
// Parametrage du prefix des avoirs
$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</td>';
$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskcredit" value="'.$conf->global->FACTURE_MERCURE_MASK_CREDIT.'">',$tooltip,1,1).'</td>';
$texte.= '</tr>';
// Parametrage du prefix des avoirs
$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</td>';
$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskcredit" value="'.$conf->global->FACTURE_MERCURE_MASK_CREDIT.'">',$tooltip,1,1).'</td>';
$texte.= '</tr>';
$texte.= '</table>';
$texte.= '</form>';
$texte.= '</table>';
$texte.= '</form>';
return $texte;
return $texte;
}
/** \brief Return an example of number value
@ -88,62 +88,64 @@ class mod_facture_mercure extends ModeleNumRefFactures
*/
function getExample()
{
global $conf,$langs,$mysoc;
global $conf,$langs,$mysoc;
$old_code_client=$mysoc->code_client;
$old_code_type=$mysoc->typent_code;
$mysoc->code_client='CCCCCCCCCC';
$mysoc->typent_code='TTTTTTTTTT';
$numExample = $this->getNextValue($mysoc,'');
$mysoc->code_client=$old_code_client;
$mysoc->typent_code=$old_code_type;
$old_code_client=$mysoc->code_client;
$old_code_type=$mysoc->typent_code;
$mysoc->code_client='CCCCCCCCCC';
$mysoc->typent_code='TTTTTTTTTT';
$numExample = $this->getNextValue($mysoc,'');
$mysoc->code_client=$old_code_client;
$mysoc->typent_code=$old_code_type;
if (! $numExample)
{
$numExample = $langs->trans('NotConfigured');
}
return $numExample;
if (! $numExample)
{
$numExample = $langs->trans('NotConfigured');
}
return $numExample;
}
/** \brief Return next value
* \param objsoc Object third party
* \param facture Object invoice
* \return string Value if OK, 0 if KO
*/
function getNextValue($objsoc,$facture)
{
global $db,$conf;
require_once(DOL_DOCUMENT_ROOT ."/lib/functions2.lib.php");
// Get Mask value
$mask = '';
if (is_object($facture) && $facture->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT;
else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE;
if (! $mask)
{
$this->error='NotConfigured';
return 0;
}
$where='';
if ($facture->type == 2) $where.= " AND type = 2";
else $where.=" AND type != 2";
$numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc,$facture->date);
return $numFinal;
}
/** \brief Return next free value
* \param objsoc Object third party
* \param objforref Object for number to search
* \return string Next free value
*/
function getNumRef($objsoc,$objforref)
/** Return next value
* @param objsoc Object third party
* @param facture Object invoice
* @param mode 'next' for next value or 'last' for last value
* @return string Value if OK, 0 if KO
*/
function getNextValue($objsoc,$facture,$mode='next')
{
return $this->getNextValue($objsoc,$objforref);
global $db,$conf;
require_once(DOL_DOCUMENT_ROOT ."/lib/functions2.lib.php");
// Get Mask value
$mask = '';
if (is_object($facture) && $facture->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT;
else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE;
if (! $mask)
{
$this->error='NotConfigured';
return 0;
}
$where='';
if ($facture->type == 2) $where.= " AND type = 2";
else $where.=" AND type != 2";
$numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc,$facture->date,$mode);
return $numFinal;
}
/** Return next free value
* @param objsoc Object third party
* @param objforref Object for number to search
* @param mode 'next' for next value or 'last' for last value
* @return string Next free value
*/
function getNumRef($objsoc,$objforref,$mode='next')
{
return $this->getNextValue($objsoc,$objforref,$mode);
}
}

View File

@ -110,12 +110,13 @@ class mod_facture_terre extends ModeleNumRefFactures
return true;
}
/** \brief Renvoi prochaine valeur attribuee
* \param objsoc Objet societe
* \param facture Objet facture
* \return string Valeur
/** Return next value not used or last value used
* @param objsoc Object third party
* @param facture Object invoice
* @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;
@ -143,22 +144,48 @@ class mod_facture_terre extends ModeleNumRefFactures
return -1;
}
$date=$facture->date; // This is invoice date (not creation date)
$yymm = strftime("%y%m",$date);
$num = sprintf("%04s",$max+1);
if ($mode == 'last')
{
$num = sprintf("%04s",$max);
dol_syslog("mod_facture_terre::getNextValue return ".$prefix.$yymm."-".$num);
return $prefix.$yymm."-".$num;
$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)
$yymm = strftime("%y%m",$date);
$num = sprintf("%04s",$max+1);
dol_syslog("mod_facture_terre::getNextValue return ".$prefix.$yymm."-".$num);
return $prefix.$yymm."-".$num;
}
else dol_print_error('','Bad parameter for getNextValue');
}
/** \brief Return next free value
* \param objsoc Object third party
* \param objforref Object for number to search
* \return string Next free value
/** Return next free value
* @param objsoc Object third party
* @param objforref Object for number to search
* @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);
}
}