diff --git a/app/Classes/General/Eloquent/Filters/Frequency.php b/app/Classes/General/Eloquent/Filters/Frequency.php
new file mode 100644
index 00000000..3eb74340
--- /dev/null
+++ b/app/Classes/General/Eloquent/Filters/Frequency.php
@@ -0,0 +1,19 @@
+whereHas('bookings', function ($query){}, '>=', $value);
+ }
+}
\ No newline at end of file
diff --git a/app/Classes/General/Eloquent/Filters/Monetary.php b/app/Classes/General/Eloquent/Filters/Monetary.php
new file mode 100644
index 00000000..5c91b248
--- /dev/null
+++ b/app/Classes/General/Eloquent/Filters/Monetary.php
@@ -0,0 +1,25 @@
+whereHas('transactions', function ($query) use ($value){
+ $query->where('transactions.type', TransactionType::PAYMENT)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
+ $query->havingRaw('SUM(amount) >= ' . $value);
+ });
+ }
+}
\ No newline at end of file
diff --git a/app/Classes/General/Eloquent/Filters/Recency.php b/app/Classes/General/Eloquent/Filters/Recency.php
new file mode 100644
index 00000000..75e9ea34
--- /dev/null
+++ b/app/Classes/General/Eloquent/Filters/Recency.php
@@ -0,0 +1,22 @@
+where('transactions.created_at', '>=', $value);
+ }
+}
\ No newline at end of file
diff --git a/app/Classes/General/Eloquent/Filters/WithTotalPayments.php b/app/Classes/General/Eloquent/Filters/WithTotalPayments.php
index 9721f8d7..015221fd 100644
--- a/app/Classes/General/Eloquent/Filters/WithTotalPayments.php
+++ b/app/Classes/General/Eloquent/Filters/WithTotalPayments.php
@@ -19,8 +19,18 @@ class WithTotalPayments implements Filter
*/
public static function apply(Builder $builder, $value)
{
- return $builder->leftJoin('bookings', 'companies.id', '=', 'bookings.company_id')->rightJoin('transactions', function ($join) {
- $join->on('bookings.id', '=', 'transactions.owner_id')->where('owner_type', '=', Booking::class)->where('transactions.type', TransactionType::PAYMENT)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
- })->addSelect(['companies.*', DB::raw('SUM(transactions.amount) as total_payments'), DB::raw('SUM(transactions.amount / DATEDIFF(companies.created_at, CURRENT_DATE)) as spending_average_per_day'), DB::raw('SUM(transactions.amount) / count(distinct bookings.id) as spending_average_booking')])->groupBy(['companies.id']);
+ return $builder->leftJoin('bookings', 'companies.id', '=', 'bookings.company_id')
+ ->rightJoin('transactions', function ($join) {
+ $join->on('bookings.id', '=', 'transactions.owner_id')
+ ->where('owner_type', '=', Booking::class)
+ ->where('transactions.type', TransactionType::PAYMENT)
+ ->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
+ })->addSelect([
+ 'companies.*',
+ DB::raw('SUM(transactions.amount) as total_payments'),
+ DB::raw('SUM(transactions.amount / DATEDIFF(companies.created_at, CURRENT_DATE)) as spending_average_per_day'),
+ DB::raw('SUM(transactions.amount) / count(distinct bookings.id) as spending_average_booking')
+ ])
+ ->groupBy(['companies.id']);
}
}
\ No newline at end of file
diff --git a/app/Classes/Modules/Companies/ControllersLogic/ListCompaniesLogic.php b/app/Classes/Modules/Companies/ControllersLogic/ListCompaniesLogic.php
index 80b15c1c..8e19c737 100644
--- a/app/Classes/Modules/Companies/ControllersLogic/ListCompaniesLogic.php
+++ b/app/Classes/Modules/Companies/ControllersLogic/ListCompaniesLogic.php
@@ -53,9 +53,12 @@ class ListCompaniesLogic extends AbstractControllerLogic
{
$this->canListCompanies->passes();
+ // dd($request->input('filters'));
+ // frequency = active bookings
+ // monetary = total spending/payment
$query = $this->listsCompanies->execute($this->listsCompanies->deserializeFilters($request->input('filters')));
+
+ // dd($query);
return $this->collectionResponse(CompanyResource::collection($query));
-
}
-
}
\ No newline at end of file
diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php
index ee1b96a0..80ae4a57 100644
--- a/app/Http/Resources/CompanyResource.php
+++ b/app/Http/Resources/CompanyResource.php
@@ -28,6 +28,7 @@ class CompanyResource extends JsonResource
{
$lastPayment = $this->transactions()->where('transactions.type', TransactionType::PAYMENT)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->orderBy('id', 'DESC')->first();
$totalPayments = $this->transactions()->where('transactions.type', TransactionType::PAYMENT)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount');
+
return [
'id' => $this->id,
'name' => $this->name,
diff --git a/resources/assets/vue/components/companies/sections/CustomerSectionComponent.vue b/resources/assets/vue/components/companies/sections/CustomerSectionComponent.vue
new file mode 100644
index 00000000..be864c9a
--- /dev/null
+++ b/resources/assets/vue/components/companies/sections/CustomerSectionComponent.vue
@@ -0,0 +1,77 @@
+
+