diff --git a/app/Models/Payment.php b/app/Models/Payment.php
index 69c61e4..c529193 100644
--- a/app/Models/Payment.php
+++ b/app/Models/Payment.php
@@ -54,7 +54,7 @@ class Payment extends Model
*/
public function invoice(): BelongsTo
{
- return $this->belongsTo(Invoice::class);
+ return $this->belongsTo(Invoice::class)->with(['customer']);
}
}
diff --git a/resources/views/invoice/index.blade.php b/resources/views/invoice/index.blade.php
index 69590fa..f5ecc00 100644
--- a/resources/views/invoice/index.blade.php
+++ b/resources/views/invoice/index.blade.php
@@ -36,11 +36,23 @@
{{ __('invoice.Existing invoices') }}
-
-
-
-
-
+
@@ -53,7 +65,7 @@
{{ __('common.Created at') }}
-
+
@@ -96,6 +108,7 @@
from: "{{ $first }}",
end: "{{ $last }}",
invoices: [],
+ search_invoice: '',
sum: 0,
tax: 0,
@@ -115,6 +128,22 @@
})
},
+ getFilteredInvoices() {
+ if (this.search_invoice === '') {
+ return this.invoices;
+ }
+ return this.invoices.filter((invoice) => {
+ return invoice.customer.name
+ .replace(/ /g, '')
+ .toLowerCase()
+ .includes(this.search_invoice.replace(/ /g, '').toLowerCase())
+ || invoice.number
+ .replace(/ /g, '')
+ .toLowerCase()
+ .includes(this.search_invoice.replace(/ /g, '').toLowerCase())
+ });
+ },
+
calculateSum() {
this.sum = 0;
this.tax = 0;
diff --git a/resources/views/payment/index.blade.php b/resources/views/payment/index.blade.php
index 708132f..bbf5655 100644
--- a/resources/views/payment/index.blade.php
+++ b/resources/views/payment/index.blade.php
@@ -35,28 +35,43 @@
{{ __('invoice.Existing payments') }}
-
-
-
-
-
+
- {{ __('invoice.Invoice Number') }}
+ {{ __('invoice.Invoice Number') }}
+ {{ __('common.Name') }}
{{ __('invoice.State') }}
- {{ __('invoice.Sum') }}
- {{ __('invoice.Paid at') }}
+ {{ __('invoice.Sum') }}
+ {{ __('invoice.Paid at') }}
-
+
-
+
+
-
-
+
+
@@ -90,6 +105,7 @@
from: "{{ $first }}",
end: "{{ $last }}",
payments: [],
+ search_invoice: '',
sum: 0,
tax: 0,
@@ -109,10 +125,26 @@
})
},
+ getFilteredInvoices() {
+ if (this.search_invoice === '') {
+ return this.payments;
+ }
+ return this.payments.filter((payment) => {
+ return payment.invoice.customer.name
+ .replace(/ /g, '')
+ .toLowerCase()
+ .includes(this.search_invoice.replace(/ /g, '').toLowerCase())
+ || payment.invoice.number
+ .replace(/ /g, '')
+ .toLowerCase()
+ .includes(this.search_invoice.replace(/ /g, '').toLowerCase())
+ });
+ },
+
calculateSum() {
this.sum = 0;
this.tax = 0;
- for (const [key, payment] of Object.entries(this.payments)) {
+ for (const [key, payment] of Object.entries(this.getFilteredInvoices())) {
this.sum += parseFloat(payment.paid_amount);
this.tax += payment.invoice.tax * payment.paid_amount / payment.invoice.sum;
}