Enabled console invoice generation

This commit is contained in:
Deon George
2020-04-01 23:35:06 +11:00
parent fb9ccd927d
commit 23dc668c65
11 changed files with 273 additions and 166 deletions

View File

@@ -2,12 +2,24 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use App\Traits\NextKey;
use App\Traits\PushNew;
class Invoice extends Model
{
use NextKey,PushNew;
const RECORD_ID = 'invoice';
public $incrementing = FALSE;
protected $table = 'ab_invoice';
const CREATED_AT = 'date_orig';
const UPDATED_AT = 'date_last';
protected $dates = ['date_orig','due_date'];
public $dateFormat = 'U';
protected $appends = [
'date_due',
@@ -183,4 +195,23 @@ class Invoice extends Model
return $item->product_id == $po->id AND $item->service_id == $so->id;
})->filter()->sortBy('item_type');
}
/**
* Automatically set our due_date at save time.
*
* @param array $options
* @return bool
*/
public function save(array $options = []) {
// Automatically set the date_due attribute for new records.
if (! $this->exists AND ! $this->due_date) {
$this->due_date = $this->items->min('date_start');
// @todo This 7 days should be sysetm configurable
if (($x=Carbon::now()->addDay(7)) > $this->due_date)
$this->due_date = $x;
}
return parent::save($options);
}
}