diff --git a/app/Filters/QuoteFilters.php b/app/Filters/QuoteFilters.php index 26a6b3f0ae2e..0a8c549af609 100644 --- a/app/Filters/QuoteFilters.php +++ b/app/Filters/QuoteFilters.php @@ -112,6 +112,12 @@ class QuoteFilters extends QueryFilters ->orderBy('due_date', 'DESC'); }); } + + if(in_array('convert', $status_parameters)) { + $query->orWhere(function ($q) { + $q->whereNotNull('invoice_id'); + }); + } }); return $this->builder; diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 687cde690ebc..c9754a1fc006 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -316,7 +316,7 @@ class Invoice extends BaseModel */ public function payments(): \Illuminate\Database\Eloquent\Relations\MorphToMany { - return $this->morphToMany(Payment::class, 'paymentable')->withTrashed()->withPivot('amount', 'refunded')->withTimestamps(); + return $this->morphToMany(Payment::class, 'paymentable')->withTrashed()->withPivot('amount', 'refunded', 'deleted_at')->withTimestamps(); } /** diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 6df4fbc0dbaf..e264482048eb 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -220,7 +220,7 @@ class Payment extends BaseModel */ public function invoices(): \Illuminate\Database\Eloquent\Relations\MorphToMany { - return $this->morphedByMany(Invoice::class, 'paymentable')->withTrashed()->withPivot('amount', 'refunded')->withTimestamps(); + return $this->morphedByMany(Invoice::class, 'paymentable')->withTrashed()->withPivot('amount', 'refunded', 'deleted_at')->withTimestamps(); } /** @@ -228,7 +228,7 @@ class Payment extends BaseModel */ public function credits(): \Illuminate\Database\Eloquent\Relations\MorphToMany { - return $this->morphedByMany(Credit::class, 'paymentable')->withTrashed()->withPivot('amount', 'refunded')->withTimestamps(); + return $this->morphedByMany(Credit::class, 'paymentable')->withTrashed()->withPivot('amount', 'refunded', 'deleted_at')->withTimestamps(); } /** diff --git a/app/Services/Email/EmailMailable.php b/app/Services/Email/EmailMailable.php index 399b0629e90b..8c7c2c5e4362 100644 --- a/app/Services/Email/EmailMailable.php +++ b/app/Services/Email/EmailMailable.php @@ -96,6 +96,7 @@ class EmailMailable extends Mailable $documents = Document::query()->whereIn('id', $this->email_object->documents) ->where('size', '<', $this->max_attachment_size) + ->where('is_public',1) ->cursor() ->map(function ($document) { return Attachment::fromData(fn () => $document->getFile(), $document->name); diff --git a/app/Services/Invoice/ApplyPayment.php b/app/Services/Invoice/ApplyPayment.php index de4e5791b594..058d9949c597 100644 --- a/app/Services/Invoice/ApplyPayment.php +++ b/app/Services/Invoice/ApplyPayment.php @@ -35,37 +35,37 @@ class ApplyPayment extends AbstractService $amount_paid = $this->payment_amount * -1; - $this->invoice->service()->clearPartial()->setDueDate()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($amount_paid)->save(); + $this->invoice->service()->clearPartial()->setDueDate()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($amount_paid)->updatePaidToDate($amount_paid*-1)->save(); } elseif ($this->invoice->partial > 0 && $this->invoice->partial > $this->payment_amount) { //partial amount exists, but the amount is less than the partial amount $amount_paid = $this->payment_amount * -1; - $this->invoice->service()->updatePartial($amount_paid)->updateBalance($amount_paid)->save(); + $this->invoice->service()->updatePartial($amount_paid)->updateBalance($amount_paid)->updatePaidToDate($amount_paid*-1)->save(); } elseif ($this->invoice->partial > 0 && $this->invoice->partial < $this->payment_amount) { //partial exists and the amount paid is GREATER than the partial amount $amount_paid = $this->payment_amount * -1; - $this->invoice->service()->clearPartial()->setDueDate()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($amount_paid)->save(); + $this->invoice->service()->clearPartial()->setDueDate()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($amount_paid)->updatePaidToDate($amount_paid*-1)->save(); } } else { if ($this->payment_amount == $this->invoice->balance) { $amount_paid = $this->payment_amount * -1; - $this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PAID)->updateBalance($amount_paid)->save(); + $this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PAID)->updateBalance($amount_paid)->updatePaidToDate($amount_paid*-1)->save(); } elseif ($this->payment_amount < $this->invoice->balance) { //partial invoice payment made $amount_paid = $this->payment_amount * -1; - $this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($amount_paid)->save(); + $this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($amount_paid)->updatePaidToDate($amount_paid*-1)->save(); } elseif ($this->payment_amount > $this->invoice->balance) { //partial invoice payment made $amount_paid = $this->invoice->balance * -1; - $this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PAID)->updateBalance($amount_paid)->save(); + $this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PAID)->updateBalance($amount_paid)->updatePaidToDate($amount_paid*-1)->save(); } } @@ -73,30 +73,16 @@ class ApplyPayment extends AbstractService ->ledger() ->updatePaymentBalance($amount_paid); - // nlog("updating client balance by amount {$amount_paid}"); - $this->invoice ->client ->service() ->updateBalance($amount_paid) ->save(); - /* Update Pivot Record amount */ - $this->payment->invoices->each(function ($inv) use ($amount_paid) { - if ($inv->id == $this->invoice->id) { - // $inv->pivot->amount = ($amount_paid * -1); - // $inv->pivot->save(); - //25-06-2023 - $inv->paid_to_date += floatval($amount_paid * -1); - $inv->save(); - } - }); - $this->invoice ->service() ->applyNumber() ->workFlow() - // ->deletePdf() ->save(); return $this->invoice; diff --git a/resources/views/portal/ninja2020/components/entity-documents.blade.php b/resources/views/portal/ninja2020/components/entity-documents.blade.php index 989203b5adcf..ce2c51790418 100644 --- a/resources/views/portal/ninja2020/components/entity-documents.blade.php +++ b/resources/views/portal/ninja2020/components/entity-documents.blade.php @@ -4,7 +4,7 @@
{{ ctrans('texts.attachments') }}:
- @foreach ($entity->documents as $document) + @foreach ($entity->documents()->where('is_public',1)->get() as $document)