diff --git a/app/Services/PurchaseOrder/ApplyNumber.php b/app/Services/PurchaseOrder/ApplyNumber.php new file mode 100644 index 000000000000..c3fd4d5df078 --- /dev/null +++ b/app/Services/PurchaseOrder/ApplyNumber.php @@ -0,0 +1,59 @@ +client = $client; + + $this->purchase_order = $purchase_order; + } + + public function run() + { + if ($this->purchase_order->number != '') { + return $this->purchase_order; + } + + $this->trySaving(); + + return $this->purchase_order; + } + private function trySaving() + { + $x=1; + do{ + try{ + $this->purchase_order->number = $this->getNextPurchaseOrderNumber($this->client, $this->purchase_order); + $this->purchase_order->saveQuietly(); + $this->completed = false; + } + catch(QueryException $e){ + $x++; + if($x>10) + $this->completed = false; + } + } + while($this->completed); + + } +}