芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/Models/Invoice.php
$files * @property-read int|null $files_count * @property-read mixed $download_file_url * @method static \Illuminate\Database\Eloquent\Builder|Invoice whereGateway($value) * @method static \Illuminate\Database\Eloquent\Builder|Invoice whereOfflineMethodId($value) * @method static \Illuminate\Database\Eloquent\Builder|Invoice wherePaymentStatus($value) * @method static \Illuminate\Database\Eloquent\Builder|Invoice whereTransactionId($value) * @mixin \Eloquent */ class Invoice extends BaseModel { use Notifiable; use CustomFieldsTrait; use HasCompany; protected $casts = [ 'issue_date' => 'datetime', 'due_date' => 'datetime', 'last_viewed' => 'datetime', ]; protected $appends = ['total_amount', 'issue_on']; protected $with = ['currency', 'address']; const CUSTOM_FIELD_MODEL = 'App\Models\Invoice'; public function project(): BelongsTo { return $this->belongsTo(Project::class, 'project_id')->withTrashed(); } public function client(): BelongsTo { return $this->belongsTo(User::class, 'client_id')->withoutGlobalScope(ActiveScope::class); } public function clientdetails(): BelongsTo { return $this->belongsTo(ClientDetails::class, 'client_id', 'user_id'); } public function creditNotes(): HasMany { return $this->hasMany(CreditNotes::class); } public function recurrings(): HasMany { return $this->hasMany(Invoice::class, 'parent_id'); } public function items(): HasMany { return $this->hasMany(InvoiceItems::class, 'invoice_id'); } public function payment(): HasMany { return $this->hasMany(Payment::class, 'invoice_id')->orderBy('paid_on', 'desc'); } public function currency(): BelongsTo { return $this->belongsTo(Currency::class, 'currency_id'); } public function order(): BelongsTo { return $this->belongsTo(Order::class, 'order_id'); } public function estimate(): BelongsTo { return $this->belongsTo(Estimate::class, 'estimate_id'); } public function address(): BelongsTo { return $this->belongsTo(CompanyAddress::class, 'company_address_id'); } public function bankAccount(): belongsTo { return $this->belongsTo(BankAccount::class, 'bank_account_id'); } public function scopePending($query) { return $query->where(function ($q) { $q->where('invoices.status', 'unpaid') ->orWhere('invoices.status', 'partial'); }); } public static function clientInvoices($clientId) { return Invoice::join('projects', 'projects.id', '=', 'invoices.project_id') ->select('projects.project_name', 'invoices.*') ->where('projects.client_id', $clientId) ->get(); } public static function lastInvoiceNumber() { return (int)Invoice::latest()->first()?->original_invoice_number ?? 0; } public function appliedCredits() { return Payment::where('invoice_id', $this->id)->sum('amount'); } public function amountDue() { $due = $this->total - ($this->amountPaid()); return $due < 0 ? 0 : $due; } public function amountPaid() { return $this->payment->where('status', 'complete')->sum('amount'); } public function getPaidAmount() { return $this->payment->sum('amount'); } public function getTotalAmountAttribute() { if (!is_null($this->total) && !is_null($this->currency->currency_symbol)) { return $this->currency->currency_symbol . $this->total; } return ''; } public function getIssueOnAttribute() { if (is_null($this->issue_date)) { return ''; } return Carbon::parse($this->issue_date)->format('d F, Y'); } public function formatInvoiceNumber() { $invoiceSettings = company() ? company()->invoiceSetting : $this->company->invoiceSetting; return \App\Helper\NumberFormat::invoice($this->invoice_number, $invoiceSettings); } public function getDownloadFileUrlAttribute() { return ($this->downloadable_file) ? asset_url_local_s3(InvoiceFiles::FILE_PATH . '/' . $this->downloadable_file) : null; } public function files(): HasMany { return $this->hasMany(InvoiceFiles::class, 'invoice_id')->orderBy('id', 'desc'); } }