More fixes for invoice_to, fix PushNew on belongs to relations

This commit is contained in:
Deon George 2020-07-06 16:02:59 +10:00
parent 878277907a
commit b0f9d07af9
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
5 changed files with 20 additions and 11 deletions

View File

@ -2,15 +2,13 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use App\Traits\NextKey;
use App\Traits\PushNew;
class Account extends Model
{
use NextKey,PushNew;
use NextKey;
const RECORD_ID = 'account';
public $incrementing = FALSE;

View File

@ -24,6 +24,9 @@ class Invoice extends Model
protected $dates = ['date_orig','due_date'];
public $dateFormat = 'U';
// Array of items that can be updated with PushNew
protected $pushable = ['items'];
protected $appends = [
'date_due',
'due',

View File

@ -23,6 +23,9 @@ class InvoiceItem extends Model
protected $dates = ['date_start','date_stop'];
public $dateFormat = 'U';
// Array of items that can be updated with PushNew
protected $pushable = ['taxes'];
private $_tax = 0;
public function invoice()

View File

@ -547,37 +547,37 @@ class Service extends Model
switch ($this->recur_schedule) {
// Weekly
case 0:
$d = $this->invoice_next->addWeek()->diff($this->invoice_next_end->startOfWeek())->days;
$d = $this->invoice_next->addWeek()->startOfWeek()->diff($this->invoice_next_end->startOfWeek())->days;
break;
// Monthly
case 1:
$d = $this->invoice_next->addMonth()->diff($this->invoice_next_end->startOfMonth())->days;
$d = $this->invoice_next->addMonth()->startOfMonth()->diff($this->invoice_next_end->startOfMonth())->days;
break;
// Quarterly
case 2:
$d = $this->invoice_next->addQuarter()->diff($this->invoice_next_end->startOfQuarter())->days;
$d = $this->invoice_next->addQuarter()->startOfQuarter()->diff($this->invoice_next_end->startOfQuarter())->days;
break;
// Half Yearly
case 3:
$d = $this->invoice_next->addHalf()->diff($this->invoice_next_end->startOfHalf())->days;
$d = $this->invoice_next->addHalf()->startOfHalf()->diff($this->invoice_next_end->startOfHalf())->days;
break;
// Yearly
case 4:
$d = $this->invoice_next->addYear()->diff($this->invoice_next_end->startOfYear())->days;
$d = $this->invoice_next->addYear()->startOfYear()->diff($this->invoice_next_end->startOfYear())->days;
break;
// Two Yearly
case 5:
$d = $this->invoice_next->addYear(2)->diff($this->invoice_next_end->subyear(2))->days-1;
$d = $this->invoice_next->addYear(2)->startOfYear()->diff($this->invoice_next_end->subyear(2))->days-1;
break;
// Three Yearly
case 6:
$d = $this->invoice_next->addYear(3)->diff($this->invoice_next_end->subyear(3))->days-1;
$d = $this->invoice_next->addYear(3)->startOfYear()->diff($this->invoice_next_end->subyear(3))->days-1;
break;
default: throw new Exception('Unknown recur_schedule');

View File

@ -13,13 +13,18 @@ trait PushNew
{
public function pushNew() {
if (! $this->save()) {
// We dont traverse this models relations
return false;
}
// To sync all of the relationships to the database, we will simply spin through
// the relationships and save each model via this "pushNew" method, which allows
// us to recurse into all of these nested relations for the model instance.
foreach ($this->relations as $models) {
foreach ($this->relations as $key => $models) {
// If we are not pushable, jump to the next item.
if (! is_array($this->pushable) OR ! in_array($key,$this->pushable))
continue;
$models = $models instanceof Collection
? $models->all() : [$models];