mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 22:54:25 +01:00
Getters and Setters on Invoice model
This commit is contained in:
parent
7a65ef24d2
commit
0102d1a22b
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Currency;
|
||||||
use App\Models\Filterable;
|
use App\Models\Filterable;
|
||||||
|
use App\Utils\Traits\MakesDates;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use App\Utils\Traits\NumberFormatter;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
@ -12,6 +15,8 @@ class Invoice extends BaseModel
|
|||||||
use MakesHash;
|
use MakesHash;
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
use Filterable;
|
use Filterable;
|
||||||
|
use NumberFormatter;
|
||||||
|
use MakesDates;
|
||||||
|
|
||||||
protected $guarded = [
|
protected $guarded = [
|
||||||
'id',
|
'id',
|
||||||
@ -22,18 +27,19 @@ class Invoice extends BaseModel
|
|||||||
];
|
];
|
||||||
|
|
||||||
protected $with = [
|
protected $with = [
|
||||||
'company'
|
'company',
|
||||||
|
'client',
|
||||||
];
|
];
|
||||||
|
|
||||||
const STATUS_DRAFT = 1;
|
const STATUS_DRAFT = 1;
|
||||||
const STATUS_SENT = 2;
|
const STATUS_SENT = 2;
|
||||||
const STATUS_PARTIAL = 5;
|
const STATUS_PARTIAL = 3;
|
||||||
const STATUS_PAID = 6;
|
const STATUS_PAID = 4;
|
||||||
const STATUS_CANCELLED = 8;
|
const STATUS_CANCELLED = 5;
|
||||||
|
|
||||||
const STATUS_OVERDUE = -1;
|
const STATUS_OVERDUE = -1;
|
||||||
const STATUS_UNPAID = -2;
|
const STATUS_UNPAID = -2;
|
||||||
const STATUS_REVERSED = -7; //new for V2
|
const STATUS_REVERSED = -3;
|
||||||
|
|
||||||
public function company()
|
public function company()
|
||||||
{
|
{
|
||||||
@ -59,4 +65,50 @@ class Invoice extends BaseModel
|
|||||||
{
|
{
|
||||||
return $this->morphMany(Document::class, 'documentable');
|
return $this->morphMany(Document::class, 'documentable');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------- */
|
||||||
|
/* Settings getters */
|
||||||
|
/* ---------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If True, prevents an invoice from being
|
||||||
|
* modified once it has been marked as sent
|
||||||
|
*
|
||||||
|
* @return boolean isLocked
|
||||||
|
*/
|
||||||
|
public function isLocked() : bool
|
||||||
|
{
|
||||||
|
return $this->client->getMergedSettings()->lock_sent_invoices;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the currency from the settings object.
|
||||||
|
*
|
||||||
|
* @return Eloquent Model The currency.
|
||||||
|
*/
|
||||||
|
public function getCurrency()
|
||||||
|
{
|
||||||
|
return Currency::find($this->settings->currency_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if invoice overdue.
|
||||||
|
*
|
||||||
|
* @param float $balance The balance
|
||||||
|
* @param date. $due_date The due date
|
||||||
|
*
|
||||||
|
* @return boolean True if overdue, False otherwise.
|
||||||
|
*/
|
||||||
|
public static function isOverdue($balance, $due_date)
|
||||||
|
{
|
||||||
|
if (! $this->formatValue($balance,2) > 0 || ! $due_date) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// it isn't considered overdue until the end of the day
|
||||||
|
return strtotime($this->createClientDate(date(), $this->client->timezone()->name)) > (strtotime($due_date) + (60 * 60 * 24));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ trait GeneratesNumberCounter
|
|||||||
$format = $matches[1];
|
$format = $matches[1];
|
||||||
$search[] = $matches[0];
|
$search[] = $matches[0];
|
||||||
|
|
||||||
/* The following adjusts for the company timezone */
|
/* The following adjusts for the company timezone - may bork tests depending on the time of day the tests are run!!!!!!*/
|
||||||
$date = Carbon::now($this->company->timezone()->name)->format($format);
|
$date = Carbon::now($this->company->timezone()->name)->format($format);
|
||||||
$replace[] = str_replace($format, $date, $matches[1]);
|
$replace[] = str_replace($format, $date, $matches[1]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user