@apmuthu
you can see my changes on my fork over
here
update is on 2.4.6 /includes/references.inc file
1. line no 55 updated the placeholder array to
$refline_placeholders = array(
'MM' => 'date',
'Y' => 'date',
'YY' => 'date',
'YYY' => 'date',
'YYYY' => 'date',
'UU' => 'user',
'P' => 'pos',
// FIXME: for placeholders below all the code should work, but as the ref length is variable,
// length specification in placeholder format should be implemented.
// 'C' => 'customer',
// 'B' => 'branch',
// 'S' => 'supplier',
// 'L' => 'location'
);
2. added new template in switch case line no 124
case 'Y':
case 'YYY':
list($begin_day, $begin_month, $begin_year) = explode_date_to_dmy(begin_fiscalyear());
list($end_day, $end_month, $end_year) = explode_date_to_dmy(end_fiscalyear());
$out .= $ph == 'Y' ? sprintf('%04d', $begin_year) : sprintf('%04d', $begin_year) . "-" . sprintf('%02d', $end_year % 100);
break;
3. updated is_valid function line no 266
function is_valid($reference, $type, $context=null, $line=null)
{
if (!isset($line))
$line = $this->reflines->find_refline_id($reference, $type, true);
if (!isset($line))
return false;
$refline = $this->reflines->get($line);
if ($this->_legacy_line($refline)) //legacy non-templated line
return strlen(trim($reference)) > 0;
$regex = preg_quote($refline['prefix'].$refline['pattern']);
if (!is_array($context))
$context = array('date'=>$context);
$context['pos'] = $_SESSION["wa_current_user"]->pos;
if (is_date(@$context['date']))
{
list($year4, $month, $day) = explode("-", date2sql($context['date']));
list($begin_year, $begin_month, $begin_day) = explode("-", date2sql(begin_fiscalyear()));
list($end_year, $end_month, $end_day) = explode("-", date2sql(end_fiscalyear()));
$year2 = substr($year4, 2);
$year3 = $begin_year."-".substr($end_year, 2);
} else
{
$month = '\d{2,}';
$year2 = '\d{2,}';
$year4 = '\d{4,}';
$begin_year = '\d{4,}';
$year3 = '\d{4,}-\d{2,}';
}
$cust = @$context['customer'] ? $context['customer'] : '\d+';
$supp = @$context['supplier'] ? $context['supplier'] : '\d+';
$branch = @$context['branch'] ? $context['branch'] : '\d+';
$location = @$context['location'] ? $context['location'] : '[a-z0-9]+';
$pos = @$context['pos'] ? $context['pos'] : '\d+';
$user = sprintf("%02d", $_SESSION['wa_current_user']->user);
$regex = preg_replace(
array(
'/\\\{/', // unquote placeholders
'/\\\}/',
'/\{MM\}/',
'/\{Y\}/',
'/\{YY\}/',
'/\{YYY\}/',
'/\{YYYY\}/',
'/\{C\}/',
'/\{B\}/',
'/\{S\}/',
'/\{L\}/',
'/\{UU\}/',
'/\{P\}/',
'/\{\d+}/',
),
array(
'{',
'}',
$month,
$begin_year,
$year2,
$year3,
$year4,
$cust,
$branch,
$supp,
$location,
$user,
$pos,
'\d+',
), $regex);
$regex = '"^'.$regex.'"i';
return preg_match($regex, $reference, $match) ? 1 : 0;
}