Refactor Customization Page

This commit is contained in:
radhu587
2019-12-12 13:46:09 +05:30
parent 81739827c0
commit cbf0af2120
16 changed files with 416 additions and 106 deletions

View File

@ -54,10 +54,13 @@ class Estimate extends Model
'sub_total' => 'float'
];
public static function getNextEstimateNumber()
public static function getNextEstimateNumber($value)
{
// Get the last created order
$lastOrder = Estimate::orderBy('created_at', 'desc')->first();
// Get the last created order
$lastOrder = Estimate::where('estimate_number', 'LIKE', $value . '-%')
->orderBy('created_at', 'desc')
->first();
if (!$lastOrder) {
// We get here if there is no order at all
// If there is no number set it to 0, which will be 1 at the end.
@ -99,10 +102,16 @@ class Estimate extends Model
public function getEstimateNumAttribute()
{
$position = $this->strposX($this->estimate_number, "-", 2) + 1;
$position = $this->strposX($this->estimate_number, "-", 1) + 1;
return substr($this->estimate_number, $position);
}
public function getEstimatePrefixAttribute()
{
$prefix = explode("-",$this->estimate_number)[0];
return $prefix;
}
private function strposX($haystack, $needle, $number)
{
if ($number == '1') {