add new customers list

This commit is contained in:
omair saleh
2021-12-22 16:53:59 +08:00
parent 6013a4e94e
commit a71136db16
4 changed files with 97 additions and 33 deletions
@@ -21,6 +21,6 @@ class WithTotalPayments implements Filter
{
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')])->groupBy(['companies.id']);
})->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')])->groupBy(['companies.id']);
}
}
+2
View File
@@ -12,6 +12,7 @@ use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Currency;
use App\Models\SegmentConstant;
use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Auth;
@@ -39,6 +40,7 @@ class CompanyResource extends JsonResource
'identification' => new DocumentResource($this->documents->whereIn('document_type', DocumentType::IDENTIFICATION_DOCUMENTS)->first()),
'bookings' => $this->whenLoaded('bookings', $this->bookings()->orderBy('id', 'DESC')->get(), []),
'total_payments' => (float) $this->transactions()->where('transactions.type', TransactionType::PAYMENT)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount'),
'average_spending_per_day' => (float) $this->transactions()->where('transactions.type', TransactionType::PAYMENT)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount') / $this->created_at->diff(Carbon::now())->days,
'last_payment' => $lastPayment ? $lastPayment->created_at->diffForHumans() : 'No Payments',
'personal_banks' => BankResource::collection($this->banks->where('type', BankAccountType::PERSONAL)),
'recipient_banks' => [
@@ -1,6 +1,6 @@
<template>
<div class="row m-b-15 align-items-end">
<div class="col">
<div class="col-auto">
<div class="row">
<div class="col">
<div class="font-heading fs-10 muted all-caps">Marking</div>
@@ -24,6 +24,18 @@
</div>
</div>
</div>
<div class="col-2 text-center">
<div class="row">
<div class="col">
<div class="font-heading fs-10 muted all-caps">Avg</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="font-heading fs-11">MYR {{(Math.round((this.item.average_spending_per_day + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}</div>
</div>
</div>
</div>
<div class="col-2 text-center">
<div class="row">
<div class="col">
@@ -36,7 +48,7 @@
</div>
</div>
</div>
<div class="col-2 text-center">
<div class="col-1 text-center">
<div class="row">
<div class="col">
<div class="font-heading fs-10 muted all-caps">Bookings</div>
File diff suppressed because one or more lines are too long