1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Models/Expense.php

274 lines
11 KiB
PHP
Raw Normal View History

<?php
2019-05-11 05:32:07 +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
*/
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
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
* @property string $amount
* @property string $foreign_amount
* @property string $exchange_rate
* @property string|null $tax_name1
* @property string $tax_rate1
* @property string|null $tax_name2
* @property string $tax_rate2
* @property string|null $tax_name3
* @property string $tax_rate3
* @property string|null $date
* @property string|null $payment_date
* @property string|null $private_notes
* @property string|null $public_notes
* @property string|null $transaction_reference
* @property int $should_be_invoiced
* @property int $invoice_documents
* @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
* @property string $tax_amount1
* @property string $tax_amount2
* @property string $tax_amount3
* @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 whereAmount($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereAssignedUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereBankId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereCalculateTaxByAmount($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereCategoryId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereClientId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereCompanyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereCurrencyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereCustomValue1($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereCustomValue2($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereCustomValue3($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereCustomValue4($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereExchangeRate($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereForeignAmount($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereInvoiceCurrencyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereInvoiceDocuments($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereInvoiceId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereIsDeleted($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense wherePaymentDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense wherePaymentTypeId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense wherePrivateNotes($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereProjectId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense wherePublicNotes($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereRecurringExpenseId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereShouldBeInvoiced($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereTaxAmount1($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereTaxAmount2($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereTaxAmount3($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereTaxName1($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereTaxName2($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereTaxName3($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereTaxRate1($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereTaxRate2($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereTaxRate3($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereTransactionId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereTransactionReference($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereUsesInclusiveTaxes($value)
* @method static \Illuminate\Database\Eloquent\Builder|Expense whereVendorId($value)
* @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-03-29 04:13:50 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
2023-03-29 05:23:06 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
2023-03-21 12:37:06 +01:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
2023-03-24 02:12:12 +01:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
2023-03-24 08:02:34 +01:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
2023-03-27 05:47:01 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
2023-03-27 22:47:07 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
2023-04-10 09:37:40 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* @property-read \App\Models\BankTransaction|null $transaction
2023-04-13 07:39:12 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
2023-04-26 00:43:54 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
2023-04-26 08:55:49 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
2023-03-08 08:33:42 +01:00
* @mixin \Eloquent
*/
class Expense extends BaseModel
{
use SoftDeletes;
use Filterable;
protected $fillable = [
'client_id',
'assigned_user_id',
'vendor_id',
'invoice_id',
'currency_id',
2020-10-13 06:14:13 +02:00
'date',
'invoice_currency_id',
'amount',
'foreign_amount',
'exchange_rate',
'private_notes',
'public_notes',
'bank_id',
'transaction_id',
'category_id',
'tax_rate1',
'tax_name1',
'tax_rate2',
'tax_name2',
'tax_rate3',
'tax_name3',
'payment_date',
'payment_type_id',
'project_id',
'transaction_reference',
'invoice_documents',
'should_be_invoiced',
'custom_value1',
'custom_value2',
'custom_value3',
'custom_value4',
2020-10-29 10:40:13 +01:00
'number',
'tax_amount1',
'tax_amount2',
'tax_amount3',
'uses_inclusive_taxes',
'calculate_tax_by_amount',
'purchase_order_id',
];
protected $casts = [
'is_deleted' => 'boolean',
'updated_at' => 'timestamp',
'created_at' => 'timestamp',
'deleted_at' => 'timestamp',
];
2020-07-23 05:55:11 +02:00
protected $touches = [];
public function getEntityType()
{
return self::class;
}
2019-04-28 07:31:32 +02:00
public function documents()
{
return $this->morphMany(Document::class, 'documentable');
}
2021-01-04 12:22:48 +01:00
public function user()
{
return $this->belongsTo(User::class)->withTrashed();
}
public function assigned_user()
{
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
}
2020-07-16 23:50:02 +02:00
public function company()
{
return $this->belongsTo(Company::class);
}
2020-12-07 11:43:21 +01:00
public function vendor()
{
return $this->belongsTo(Vendor::class);
}
2021-05-15 04:19:36 +02:00
public function client()
{
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
public function currency()
{
return $this->belongsTo(Currency::class);
}
public function category()
{
2022-05-12 02:57:58 +02:00
return $this->belongsTo(ExpenseCategory::class)->withTrashed();
2022-04-08 09:03:03 +02:00
}
public function payment_type()
{
return $this->belongsTo(PaymentType::class);
}
public function project()
{
return $this->belongsTo(Project::class);
}
public function transaction()
{
return $this->belongsTo(BankTransaction::class);
}
}