View Single Post
  #9  
Old 06-06-2020, 08:02 AM
  The Knotty Celt's Avatar 
The Knotty Celt The Knotty Celt is offline
 

Advanced Member
  
Join Date: Jan 2020
Posts: 32
 

Default Re: Custom Order Numbering

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.
__________________
X-Cart version 5.4.1.46
PHP version 7.4.33
MySQL version 15.1
Apache version 2.4.56
cURL version 7.74.0
Reply With Quote