芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/Models/CreditNotes.php
'datetime', 'due_date' => 'datetime', ]; protected $appends = ['total_amount', 'issue_on']; protected $with = ['currency']; public function project(): BelongsTo { return $this->belongsTo(Project::class, 'project_id'); } 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 invoice(): BelongsTo { return $this->belongsTo(Invoice::class, 'invoice_id', 'id'); } public function unit(): BelongsTo { return $this->belongsTo(UnitType::class, 'unit_id'); } public function invoices(): HasMany { return $this->hasMany(Invoice::class); } public function items(): HasMany { return $this->hasMany(CreditNoteItem::class, 'credit_note_id'); } public function payment(): HasMany { return $this->hasMany(Payment::class, 'invoice_id', 'invoice_id')->orderBy('paid_on', 'desc'); } public function currency(): BelongsTo { return $this->belongsTo(Currency::class, 'currency_id'); } public static function clientInvoices($clientId) { return CreditNotes::join('projects', 'projects.id', '=', 'credit_notes.project_id') ->select('projects.project_name', 'credit_notes.*') ->where('projects.client_id', $clientId) ->get(); } public function getPaidAmount() { return $this->payment->sum('amount'); } public function creditAmountUsed() { $payment = Payment::where('credit_notes_id', $this->id)->get(); return ($payment) ? $payment->sum('amount') : 0; } /* This is overall amount, cannot be used for particular credit note */ public function creditAmountRemaining() { return ($this->total) - $this->creditAmountUsed(); } public function getTotalAmountAttribute() { return $this->total + $this->adjustment_amount; } public function getIssueOnAttribute() { if (!is_null($this->issue_date)) { return Carbon::parse($this->issue_date)->format('d F, Y'); } return ''; } public function setIssueDateAttribute($issue_date) { $issue_date = Carbon::createFromFormat(company()->date_format, $issue_date, company()->timezone)->format('Y-m-d'); $issue_date = Carbon::parse($issue_date)->setTimezone('UTC'); $this->attributes['issue_date'] = $issue_date; } public function setDueDateAttribute($due_date) { if (!is_null($due_date)) { $due_date = Carbon::createFromFormat(company()->date_format, $due_date, company()->timezone)->format('Y-m-d'); $due_date = Carbon::parse($due_date)->setTimezone('UTC'); $this->attributes['due_date'] = $due_date; } } public function formatCreditNoteNumber() { $invoiceSettings = company() ? company()->invoiceSetting : $this->company->invoiceSetting; return \App\Helper\NumberFormat::creditNote($this->cn_number, $invoiceSettings); } public static function lastEstimateNumber() { return (int)CreditNotes::latest()->first()?->original_credit_note_number ?? 0; } }