2018-10-15 14:40:34 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 05:32:07 +02:00
|
|
|
*/
|
2018-10-15 14:40:34 +02:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2018-10-15 14:40:34 +02:00
|
|
|
|
2023-03-08 08:33:42 +01:00
|
|
|
/**
|
|
|
|
* App\Models\Expense
|
|
|
|
*
|
|
|
|
* @property int $id
|
|
|
|
* @property int|null $created_at
|
|
|
|
* @property int|null $updated_at
|
|
|
|
* @property int|null $deleted_at
|
|
|
|
* @property int $company_id
|
|
|
|
* @property int|null $vendor_id
|
|
|
|
* @property int $user_id
|
|
|
|
* @property int|null $assigned_user_id
|
|
|
|
* @property int|null $invoice_id
|
|
|
|
* @property int|null $client_id
|
|
|
|
* @property int|null $bank_id
|
|
|
|
* @property int|null $invoice_currency_id
|
|
|
|
* @property int|null $currency_id
|
|
|
|
* @property int|null $category_id
|
|
|
|
* @property int|null $payment_type_id
|
|
|
|
* @property int|null $recurring_expense_id
|
|
|
|
* @property bool $is_deleted
|
2023-10-13 12:35:22 +02:00
|
|
|
* @property float $amount
|
|
|
|
* @property float $foreign_amount
|
2023-03-08 08:33:42 +01:00
|
|
|
* @property string $exchange_rate
|
|
|
|
* @property string|null $tax_name1
|
2023-10-13 12:35:22 +02:00
|
|
|
* @property float $tax_rate1
|
2023-03-08 08:33:42 +01:00
|
|
|
* @property string|null $tax_name2
|
2023-10-13 12:35:22 +02:00
|
|
|
* @property float $tax_rate2
|
2023-03-08 08:33:42 +01:00
|
|
|
* @property string|null $tax_name3
|
2023-10-13 12:35:22 +02:00
|
|
|
* @property float $tax_rate3
|
2023-03-08 08:33:42 +01:00
|
|
|
* @property string|null $date
|
|
|
|
* @property string|null $payment_date
|
|
|
|
* @property string|null $private_notes
|
|
|
|
* @property string|null $public_notes
|
|
|
|
* @property string|null $transaction_reference
|
2023-10-13 12:35:22 +02:00
|
|
|
* @property bool $should_be_invoiced
|
|
|
|
* @property bool $invoice_documents
|
2023-03-08 08:33:42 +01:00
|
|
|
* @property int|null $transaction_id
|
|
|
|
* @property string|null $custom_value1
|
|
|
|
* @property string|null $custom_value2
|
|
|
|
* @property string|null $custom_value3
|
|
|
|
* @property string|null $custom_value4
|
|
|
|
* @property string|null $number
|
|
|
|
* @property int|null $project_id
|
2023-10-13 12:35:22 +02:00
|
|
|
* @property float $tax_amount1
|
|
|
|
* @property float $tax_amount2
|
|
|
|
* @property float $tax_amount3
|
2023-03-08 08:33:42 +01:00
|
|
|
* @property int $uses_inclusive_taxes
|
|
|
|
* @property int $calculate_tax_by_amount
|
|
|
|
* @property-read \App\Models\User|null $assigned_user
|
|
|
|
* @property-read \App\Models\ExpenseCategory|null $category
|
|
|
|
* @property-read \App\Models\Client|null $client
|
|
|
|
* @property-read \App\Models\Company $company
|
|
|
|
* @property-read \App\Models\Currency|null $currency
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
|
|
|
* @property-read int|null $documents_count
|
|
|
|
* @property-read mixed $hashed_id
|
|
|
|
* @property-read \App\Models\PaymentType|null $payment_type
|
|
|
|
* @property-read \App\Models\Project|null $project
|
|
|
|
* @property-read \App\Models\PurchaseOrder|null $purchase_order
|
|
|
|
* @property-read \App\Models\User $user
|
|
|
|
* @property-read \App\Models\Vendor|null $vendor
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel company()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns)
|
|
|
|
* @method static \Database\Factories\ExpenseFactory factory($count = null, $state = [])
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Expense filter(\App\Filters\QueryFilters $filters)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Expense newModelQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Expense newQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Expense onlyTrashed()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Expense query()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel scope()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Expense withTrashed()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Expense withoutTrashed()
|
2023-03-16 05:20:38 +01:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
2023-08-01 15:53:10 +02:00
|
|
|
* @property-read \App\Models\Invoice|null $invoice
|
2023-04-10 09:37:40 +02:00
|
|
|
* @property-read \App\Models\BankTransaction|null $transaction
|
2023-03-08 08:33:42 +01:00
|
|
|
* @mixin \Eloquent
|
|
|
|
*/
|
2018-11-02 11:54:46 +01:00
|
|
|
class Expense extends BaseModel
|
2018-10-15 14:40:34 +02:00
|
|
|
{
|
2020-01-20 02:31:58 +01:00
|
|
|
use SoftDeletes;
|
2020-01-20 05:53:40 +01:00
|
|
|
use Filterable;
|
2018-11-20 05:36:56 +01:00
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
protected $fillable = [
|
|
|
|
'client_id',
|
2020-10-22 08:46:02 +02:00
|
|
|
'assigned_user_id',
|
2020-01-20 02:31:58 +01:00
|
|
|
'vendor_id',
|
2020-10-22 08:46:02 +02:00
|
|
|
'invoice_id',
|
2020-10-30 10:17:29 +01:00
|
|
|
'currency_id',
|
2020-10-13 06:14:13 +02:00
|
|
|
'date',
|
2020-01-20 02:31:58 +01:00
|
|
|
'invoice_currency_id',
|
|
|
|
'amount',
|
|
|
|
'foreign_amount',
|
|
|
|
'exchange_rate',
|
|
|
|
'private_notes',
|
|
|
|
'public_notes',
|
|
|
|
'bank_id',
|
|
|
|
'transaction_id',
|
2020-10-22 08:46:02 +02:00
|
|
|
'category_id',
|
2020-01-20 02:31:58 +01:00
|
|
|
'tax_rate1',
|
|
|
|
'tax_name1',
|
|
|
|
'tax_rate2',
|
|
|
|
'tax_name2',
|
|
|
|
'tax_rate3',
|
|
|
|
'tax_name3',
|
|
|
|
'payment_date',
|
|
|
|
'payment_type_id',
|
2020-10-14 22:58:20 +02:00
|
|
|
'project_id',
|
2020-01-20 02:31:58 +01:00
|
|
|
'transaction_reference',
|
|
|
|
'invoice_documents',
|
|
|
|
'should_be_invoiced',
|
|
|
|
'custom_value1',
|
|
|
|
'custom_value2',
|
|
|
|
'custom_value3',
|
|
|
|
'custom_value4',
|
2020-10-29 10:40:13 +01:00
|
|
|
'number',
|
2021-01-08 11:27:49 +01:00
|
|
|
'tax_amount1',
|
|
|
|
'tax_amount2',
|
|
|
|
'tax_amount3',
|
|
|
|
'uses_inclusive_taxes',
|
2021-01-11 22:57:48 +01:00
|
|
|
'calculate_tax_by_amount',
|
2022-07-06 12:04:59 +02:00
|
|
|
'purchase_order_id',
|
2018-11-20 05:36:56 +01:00
|
|
|
];
|
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
protected $casts = [
|
|
|
|
'is_deleted' => 'boolean',
|
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
'deleted_at' => 'timestamp',
|
|
|
|
];
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-07-23 05:55:11 +02:00
|
|
|
protected $touches = [];
|
2018-11-20 05:36:56 +01:00
|
|
|
|
2020-05-06 13:49:42 +02:00
|
|
|
public function getEntityType()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
return self::class;
|
2020-05-06 13:49:42 +02:00
|
|
|
}
|
2019-04-28 07:31:32 +02:00
|
|
|
|
2023-08-11 09:58:43 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany<Document>
|
|
|
|
*/
|
|
|
|
public function documents(): \Illuminate\Database\Eloquent\Relations\MorphMany
|
2019-04-28 07:31:32 +02:00
|
|
|
{
|
|
|
|
return $this->morphMany(Document::class, 'documentable');
|
|
|
|
}
|
2019-11-05 11:16:38 +01:00
|
|
|
|
2023-08-01 15:53:10 +02:00
|
|
|
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2021-01-04 12:22:48 +01:00
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
2023-08-01 15:53:10 +02:00
|
|
|
public function assigned_user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2019-11-05 11:16:38 +01:00
|
|
|
{
|
2021-09-08 01:29:20 +02:00
|
|
|
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
2019-11-05 11:16:38 +01:00
|
|
|
}
|
2020-07-16 23:50:02 +02:00
|
|
|
|
|
|
|
public function company()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
}
|
2020-12-07 11:43:21 +01:00
|
|
|
|
2023-08-01 15:53:10 +02:00
|
|
|
public function invoice(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2023-06-27 13:31:21 +02:00
|
|
|
{
|
|
|
|
return $this->belongsTo(Invoice::class);
|
|
|
|
}
|
|
|
|
|
2023-08-01 15:53:10 +02:00
|
|
|
public function vendor(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2020-12-07 11:43:21 +01:00
|
|
|
{
|
|
|
|
return $this->belongsTo(Vendor::class);
|
|
|
|
}
|
2021-05-15 04:19:36 +02:00
|
|
|
|
2023-08-01 15:53:10 +02:00
|
|
|
public function client(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2021-05-15 04:19:36 +02:00
|
|
|
{
|
|
|
|
return $this->belongsTo(Client::class);
|
|
|
|
}
|
2022-04-06 02:38:01 +02:00
|
|
|
|
2022-07-06 11:25:22 +02:00
|
|
|
public function purchase_order()
|
|
|
|
{
|
2022-07-07 08:13:37 +02:00
|
|
|
return $this->hasOne(PurchaseOrder::class);
|
2022-07-06 11:25:22 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 02:38:01 +02:00
|
|
|
public function translate_entity()
|
|
|
|
{
|
|
|
|
return ctrans('texts.expense');
|
|
|
|
}
|
2022-04-08 09:03:03 +02:00
|
|
|
|
2023-08-01 15:53:10 +02:00
|
|
|
public function currency(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2022-04-08 09:03:03 +02:00
|
|
|
{
|
|
|
|
return $this->belongsTo(Currency::class);
|
|
|
|
}
|
|
|
|
|
2023-08-01 15:53:10 +02:00
|
|
|
public function category(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2022-04-08 09:03:03 +02:00
|
|
|
{
|
2022-05-12 02:57:58 +02:00
|
|
|
return $this->belongsTo(ExpenseCategory::class)->withTrashed();
|
2022-04-08 09:03:03 +02:00
|
|
|
}
|
|
|
|
|
2023-08-01 15:53:10 +02:00
|
|
|
public function payment_type(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2022-04-08 09:03:03 +02:00
|
|
|
{
|
|
|
|
return $this->belongsTo(PaymentType::class);
|
|
|
|
}
|
|
|
|
|
2023-08-01 15:53:10 +02:00
|
|
|
public function project(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2022-04-08 09:03:03 +02:00
|
|
|
{
|
|
|
|
return $this->belongsTo(Project::class);
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2023-04-05 08:13:42 +02:00
|
|
|
|
2023-08-01 15:53:10 +02:00
|
|
|
public function transaction(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2023-04-05 08:13:42 +02:00
|
|
|
{
|
2023-10-09 06:16:35 +02:00
|
|
|
return $this->belongsTo(BankTransaction::class)->withTrashed();
|
2023-04-05 08:13:42 +02:00
|
|
|
}
|
|
|
|
|
2023-07-13 13:10:54 +02:00
|
|
|
public function stringStatus()
|
|
|
|
{
|
2023-10-26 04:57:44 +02:00
|
|
|
if($this->is_deleted) {
|
2023-07-13 13:10:54 +02:00
|
|
|
return ctrans('texts.deleted');
|
2023-10-26 04:57:44 +02:00
|
|
|
} elseif($this->payment_date) {
|
|
|
|
return ctrans('texts.paid');
|
|
|
|
} elseif($this->invoice_id) {
|
2023-07-13 13:10:54 +02:00
|
|
|
return ctrans('texts.invoiced');
|
2023-10-26 04:57:44 +02:00
|
|
|
} elseif($this->should_be_invoiced) {
|
2023-07-13 13:10:54 +02:00
|
|
|
return ctrans('texts.pending');
|
2023-10-26 04:57:44 +02:00
|
|
|
} elseif($this->trashed()) {
|
2023-07-13 13:10:54 +02:00
|
|
|
return ctrans('texts.archived');
|
2023-10-26 04:57:44 +02:00
|
|
|
}
|
2023-07-13 13:10:54 +02:00
|
|
|
|
|
|
|
return ctrans('texts.logged');
|
|
|
|
}
|
2018-10-15 14:40:34 +02:00
|
|
|
}
|