Exemplo n.º 1
0
 /**
  * generate unique number
  * 
  * @param model of sale
  * @return unique_number
  */
 public function generateUniqueNumber($sale)
 {
     if (!is_null($sale['unique_number'])) {
         $i = 0;
         $amount = true;
         while ($amount) {
             $prev_number = Sale::orderBy('id', 'DESC')->status('wait')->first();
             $limit = StoreSetting::type('limit_unique_number')->ondate('now')->first();
             if ($prev_number['unique_number'] < $limit['value']) {
                 $unique_number = $i + $prev_number['unique_number'] + 1;
             } else {
                 $unique_number = $i + 1;
             }
             $amount = Sale::amount($sale->amount - $unique_number)->status('wait')->notid($sale->id)->first();
             $i = $i + 1;
         }
         return $unique_number;
     } else {
         return $sale['unique_number'];
     }
 }