Thank you for your assistance and tips.
Quote:
Originally Posted by cflsystems
And since I assume you will always want to get the max number which will be current year anyway there is no need of min and max timestamp.
|
The reason I filter the year of the orders is to reset the 4-digit sequence. When the query returns an empty result, the integer value of Null becomes 0, to which 1 is added, thus having an automatic reset of the numbering. I recognize what you mean by my range missing the last 23 hours, 59 minutes and 59 seconds of the year, so I added a year column to streamline the query.
Code:
/**
*
* @var string
* @Column (type="string", length=4)
*/
protected $year = '';
/**
* Set Date
*
* @param integer $date
* @return Order
*/
public function setDate($date)
{
$this->date = $date;
$this->setYear();
return $this;
}
/**
* Set year
*
* @return void
*/
public function setYear()
{
$this->year = date("Y");
}
/**
* Get year
*
* @return string
*/
public function getYear()
{
return $this->year;
}
/**
* Generate new Order Reference Number in the form SO/2020/0001
*
* @return string
*/
public function generateReference()
{
$reference = "SO/"
.date("Y")
."/"
.substr(str_repeat(0,4)
.((int)substr(\XLite\Core\Database::getRepo('\XLite\Model\Order')
->createQueryBuilder('o')
->select('MAX(o.reference)')
->where('o.year = :year')
->setParameter('year', date("Y"))
->getSingleResult()[1],-4)+1), -4);
return $result;
}
After these alterations based of your feedback, the reference numbers are being generated, and the site no longer hangs after payment is processed.