Compare commits
No commits in common. "5d11741f1d89955fdce239862d9990e10f2db909" and "a29e6af43085371170485b4536df4db1f998c7b0" have entirely different histories.
5d11741f1d
...
a29e6af430
@ -26,10 +26,10 @@ public function index(Request $request): Response
|
||||
'start_date' => $request->query('start_date', ''),
|
||||
'end_date' => $request->query('end_date', ''),
|
||||
],
|
||||
'attendance' => $this->analysisService->getAttendance($startDate, $endDate),
|
||||
'attendance' => $this->analysisService->getAttendance(),
|
||||
'myAttendance' => $user ? $this->analysisService->getMyAttendance($user, $startDate, $endDate) : null,
|
||||
'isManager' => $this->analysisService->isManager($user),
|
||||
'cashOverview' => $this->analysisService->getCashOverview($startDate, $endDate),
|
||||
'cashOverview' => $this->analysisService->getCashOverview(),
|
||||
'rawMaterialStock' => $this->analysisService->getRawMaterialStock(),
|
||||
'productStock' => $this->analysisService->getProductStock(),
|
||||
'revenueSummary' => $this->analysisService->getRevenueSummary($startDate, $endDate),
|
||||
|
||||
@ -278,7 +278,7 @@ private function notifyOwner(string $typeLabel, string $body, string $url): void
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
"📦 {$typeLabel}",
|
||||
$body,
|
||||
['owner', 'developer'],
|
||||
['owner', 'developer', 'direktur'],
|
||||
$url,
|
||||
);
|
||||
}
|
||||
|
||||
@ -234,7 +234,7 @@ public function createVariantAndDraft(array $validated, User $user): array
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
'🆕 Varian Baru Ditambahkan',
|
||||
"{$user->name} menambahkan varian \"{$price->variant}\" ke bahan baku \"{$rawMaterial->name}\".",
|
||||
['owner', 'developer'],
|
||||
['owner', 'developer', 'direktur'],
|
||||
route('admin.master.raw_materials.index', ['search_id' => $rawMaterial->id]),
|
||||
);
|
||||
|
||||
@ -694,7 +694,7 @@ private function notifyForPendingRequest(User $user, string $typeLabel, string $
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
"📦 {$typeLabel} Menunggu Persetujuan Owner",
|
||||
$body,
|
||||
['owner', 'developer'],
|
||||
['owner', 'developer', 'direktur'],
|
||||
$ownerUrl,
|
||||
);
|
||||
|
||||
|
||||
@ -551,7 +551,7 @@ private function notifyForPendingRequest(User $user, string $typeLabel, string $
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
"📦 {$typeLabel} Menunggu Persetujuan Owner",
|
||||
$body,
|
||||
['owner', 'developer'],
|
||||
['owner', 'developer', 'direktur'],
|
||||
$ownerUrl,
|
||||
);
|
||||
|
||||
|
||||
@ -619,7 +619,7 @@ private function notifyOwner(string $typeLabel, string $body, string $url): void
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
"📦 {$typeLabel}",
|
||||
$body,
|
||||
['owner', 'developer'],
|
||||
['owner', 'developer', 'direktur'],
|
||||
$url,
|
||||
);
|
||||
}
|
||||
@ -634,7 +634,7 @@ private function notifyForPendingRequest(User $user, string $typeLabel, string $
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
"📦 {$typeLabel} Menunggu Persetujuan Owner",
|
||||
$body,
|
||||
['owner', 'developer'],
|
||||
['owner', 'developer', 'direktur'],
|
||||
$ownerUrl,
|
||||
);
|
||||
|
||||
|
||||
@ -236,7 +236,7 @@ private function notifyOwner(string $typeLabel, string $body, string $url): void
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
"📦 {$typeLabel}",
|
||||
$body,
|
||||
['owner', 'developer'],
|
||||
['owner', 'developer', 'direktur'],
|
||||
$url,
|
||||
);
|
||||
}
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
|
||||
use App\Enums\EmployeeAdvanceStatus;
|
||||
use App\Enums\OrderStatus;
|
||||
use App\Enums\Permission;
|
||||
use App\Enums\PriceType;
|
||||
use App\Enums\ProductStockQuality;
|
||||
use App\Enums\Role;
|
||||
@ -22,32 +21,22 @@
|
||||
use App\Models\RawMaterialPrice;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AnalysisService
|
||||
{
|
||||
public function getAttendance(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
||||
public function getAttendance(): array
|
||||
{
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||
|
||||
$attendanceRoles = collect(Role::cases())
|
||||
->filter(fn (Role $role) => in_array(Permission::ATTENDANCES_VIEW, $role->permissions()))
|
||||
->map(fn (Role $role) => $role->value)
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$employeeQuery = Employee::query();
|
||||
$attendanceQuery = Attendance::query();
|
||||
$leaveRequestQuery = LeaveRequest::query()->approved();
|
||||
|
||||
if ($startDate && $endDate) {
|
||||
$attendanceQuery->whereBetween('attendance_date', [$startDate, $endDate]);
|
||||
$leaveRequestQuery->where('start_date', '<=', $endDate)->where('end_date', '>=', $startDate);
|
||||
$employeeQuery->where('join_date', '<=', $endDate);
|
||||
}
|
||||
$attendanceQuery = Attendance::query()->where('attendance_date', Carbon::today());
|
||||
$leaveRequestQuery = LeaveRequest::query()
|
||||
->approved()
|
||||
->where('start_date', '<=', Carbon::today())
|
||||
->where('end_date', '>=', Carbon::today());
|
||||
|
||||
if (! $isSuper) {
|
||||
$employeeId = $user?->employee?->id;
|
||||
@ -56,7 +45,6 @@ public function getAttendance(?Carbon $startDate = null, ?Carbon $endDate = null
|
||||
$leaveRequestQuery->where('employee_id', $employeeId);
|
||||
}
|
||||
|
||||
$employeeQuery->whereHas('user.roles', fn ($q) => $q->whereIn('name', $attendanceRoles));
|
||||
$totalEmployees = $employeeQuery->count();
|
||||
$present = $attendanceQuery->distinct('employee_id')->count('employee_id');
|
||||
$onLeave = $leaveRequestQuery->distinct('employee_id')->count('employee_id');
|
||||
@ -134,39 +122,21 @@ public function getMyAttendance(User $user, ?Carbon $startDate = null, ?Carbon $
|
||||
];
|
||||
}
|
||||
|
||||
public function getCashOverview(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
||||
public function getCashOverview(): array
|
||||
{
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||
|
||||
/** @var Builder $transactionQuery */
|
||||
$transactionQuery = CashTransaction::query();
|
||||
if ($startDate && $endDate) {
|
||||
$transactionQuery->whereBetween('created_at', [$startDate, $endDate]);
|
||||
}
|
||||
$totalBalanceQuery = CashAccount::query();
|
||||
$transactionQuery = CashTransaction::query()->whereDate('created_at', Carbon::today());
|
||||
|
||||
if (! $isSuper) {
|
||||
$transactionQuery->where('created_by_id', $user->id);
|
||||
$totalBalanceQuery->whereHas('transactions', fn ($q) => $q->where('created_by_id', $user->id));
|
||||
}
|
||||
|
||||
$totalBalance = 0;
|
||||
if ($startDate && $endDate) {
|
||||
$balanceSummary = (clone $transactionQuery)
|
||||
->selectRaw("
|
||||
COALESCE(SUM(CASE WHEN type = 'deposit' THEN amount ELSE 0 END), 0) as total_deposit,
|
||||
COALESCE(SUM(CASE WHEN type = 'withdrawal' THEN amount ELSE 0 END), 0) as total_withdrawal
|
||||
")
|
||||
->first();
|
||||
$totalBalance = (int) (($balanceSummary->total_deposit ?? 0) - ($balanceSummary->total_withdrawal ?? 0));
|
||||
} else {
|
||||
$totalBalanceQuery = CashAccount::query();
|
||||
if (! $isSuper) {
|
||||
$totalBalanceQuery->whereHas('transactions', fn ($q) => $q->where('created_by_id', $user->id));
|
||||
}
|
||||
$totalBalance = (int) $totalBalanceQuery->sum('balance');
|
||||
}
|
||||
|
||||
$totalBalance = $totalBalanceQuery->sum('balance');
|
||||
$summary = $transactionQuery
|
||||
->selectRaw("
|
||||
COUNT(*) as total_transactions,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user