芝麻web文件管理V1.00
编辑当前文件:/home/sditechnicalteam/public_html/app/Models/Invoice.php
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 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::max('invoice_number'); } 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 getOriginalInvoiceNumberAttribute() { $invoiceSettings = (company()) ? company()->invoiceSetting : $this->company->invoiceSetting; $zero = ''; if (strlen($this->attributes['invoice_number']) < $invoiceSettings->invoice_digit) { $condition = $invoiceSettings->invoice_digit - strlen($this->attributes['invoice_number']); for ($i = 0; $i < $condition; $i++) { $zero = '0' . $zero; } } return $zero . $this->attributes['invoice_number']; } public function getInvoiceNumberAttribute($value) { if (is_null($value)) { return ''; } $invoiceSettings = (company()) ? company()->invoiceSetting : $this->company->invoiceSetting; $zero = ''; if (strlen($value) < $invoiceSettings->invoice_digit) { $condition = $invoiceSettings->invoice_digit - strlen($value); for ($i = 0; $i < $condition; $i++) { $zero = '0' . $zero; } } return $invoiceSettings->invoice_prefix . '#' . $zero . $value; } }