Skip to content
Snippets Groups Projects
Commit dc547cbb authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

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

parent 09fc3ba4
No related branches found
No related tags found
No related merge requests found
......@@ -3,13 +3,16 @@ CHARSET=UTF-8
Bill=Invoice
Bills=Invoices
BillsCustomers=Customer's invoices
BillsCustomer=Customer's invoice
BillsSuppliers=Supplier's invoices
BillsCustomersUnpaid=Unpaid customer's invoices
BillsCustomersUnpaidForCompany=Unpaid customer's invoices for %s
BillsSuppliersUnpaid=Unpaid supplier's invoices
BillsUnpaid=Unpaid
BillsLate=Late payments
BillsStatistics=Customer's invoices statistics
BillsStatisticsSuppliers=Supplier's invoices statistics
DisabledBecauseNotErasable=Disabled because can not be erased
InvoiceStandard=Standard invoice
InvoiceStandardAsk=Standard invoice
InvoiceStandardDesc=This kind of invoice is the common invoice.
......
......@@ -350,9 +350,10 @@ function array2table($data,$tableMarkup=1,$tableoptions='',$troptions='',$tdopti
* @param $where To add a filter on selection (for exemple to filter on invoice types)
* @param $objsoc The company that own the object we need a counter for
* @param $date Date to use for the {y},{m},{d} tags.
* @param $mode 'next' for next value or 'last' for last value
* @return string New value
*/
function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='')
function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$mode='next')
{
global $conf;
......@@ -490,6 +491,44 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='')
}
else dol_print_error($db);
if (empty($counter) || preg_match('/[^0-9]/i',$counter)) $counter=$maskoffset;
if ($mode == 'last')
{
$counterpadded=str_pad($counter,dol_strlen($maskcounter),"0",STR_PAD_LEFT);
// Define $maskLike
$maskLike = dol_string_nospecial($mask);
$maskLike = str_replace("%","_",$maskLike);
// Replace protected special codes with matching number of _ as wild card caracter
$maskLike = preg_replace('/\{yyyy\}/i','____',$maskLike);
$maskLike = preg_replace('/\{yy\}/i','__',$maskLike);
$maskLike = preg_replace('/\{y\}/i','_',$maskLike);
$maskLike = preg_replace('/\{mm\}/i','__',$maskLike);
$maskLike = preg_replace('/\{dd\}/i','__',$maskLike);
$maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),$counterpadded,$maskLike);
if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike);
//if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),str_pad("",dol_strlen($masktype),"_"),$maskLike);
if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike);
$ref='';
$sql = "SELECT facnumber as ref";
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
$sql.= " WHERE facnumber LIKE '".$maskLike."'";
$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);
$numFinal=$ref;
}
else if ($mode == 'next')
{
$counter++;
if ($maskrefclient_maskcounter)
......@@ -569,6 +608,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='')
$masktype_maskafter=$masktype_value;
$numFinal = str_replace($masktype_maskbefore,$masktype_maskafter,$numFinal);
}
}
dol_syslog("functions2::get_next_value return ".$numFinal,LOG_DEBUG);
return $numFinal;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment