Compare commits
No commits in common. "a29e6af43085371170485b4536df4db1f998c7b0" and "2e578cd9766459bb414eaed34167dc1e58b4853a" have entirely different histories.
a29e6af430
...
2e578cd976
@ -95,8 +95,6 @@ function () use ($cashAccount, $validated, $user): CashTransaction {
|
||||
'Gagal melakukan setoran kas',
|
||||
);
|
||||
|
||||
$this->cacheForget('finance:default_account');
|
||||
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
'💰 Setoran Kas',
|
||||
"Setoran kas baru {$transaction->amount_formatted} dengan keterangan: {$transaction->description} oleh {$user->profile?->full_name}.",
|
||||
@ -140,8 +138,6 @@ function () use ($cashAccount, $validated, $user): CashTransaction {
|
||||
'Gagal melakukan tarik kas',
|
||||
);
|
||||
|
||||
$this->cacheForget('finance:default_account');
|
||||
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
'🏦 Tarik Kas',
|
||||
"Tarik kas {$transaction->amount_formatted} dengan keterangan: {$transaction->description} oleh {$user->profile?->full_name}.",
|
||||
@ -159,7 +155,7 @@ public function recordOutgoing(
|
||||
User $user,
|
||||
?CashAccount $cashAccount = null,
|
||||
): CashTransaction {
|
||||
$transaction = $this->runInTransaction(
|
||||
return $this->runInTransaction(
|
||||
function () use ($reference, $amount, $description, $user, $cashAccount): CashTransaction {
|
||||
$account = CashAccount::query()->lockForUpdate()->findOrFail(
|
||||
($cashAccount ?? $this->getDefaultAccount())->id,
|
||||
@ -191,10 +187,6 @@ function () use ($reference, $amount, $description, $user, $cashAccount): CashTr
|
||||
},
|
||||
'Gagal mencatat transaksi keluar kas',
|
||||
);
|
||||
|
||||
$this->cacheForget('finance:default_account');
|
||||
|
||||
return $transaction;
|
||||
}
|
||||
|
||||
public function recordIncoming(
|
||||
@ -204,7 +196,7 @@ public function recordIncoming(
|
||||
User $user,
|
||||
?CashAccount $cashAccount = null,
|
||||
): CashTransaction {
|
||||
$transaction = $this->runInTransaction(
|
||||
return $this->runInTransaction(
|
||||
function () use ($reference, $amount, $description, $user, $cashAccount): CashTransaction {
|
||||
$account = CashAccount::query()->lockForUpdate()->findOrFail(
|
||||
($cashAccount ?? $this->getDefaultAccount())->id,
|
||||
@ -230,10 +222,6 @@ function () use ($reference, $amount, $description, $user, $cashAccount): CashTr
|
||||
},
|
||||
'Gagal mencatat transaksi masuk kas',
|
||||
);
|
||||
|
||||
$this->cacheForget('finance:default_account');
|
||||
|
||||
return $transaction;
|
||||
}
|
||||
|
||||
public function updateDeposit(CashTransaction $transaction, array $validated, User $user): void
|
||||
@ -262,8 +250,6 @@ function () use ($transaction, $validated): void {
|
||||
'Gagal memperbarui setoran kas',
|
||||
);
|
||||
|
||||
$this->cacheForget('finance:default_account');
|
||||
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
'✏️ Transaksi Kas Diperbarui',
|
||||
"Transaksi kas dengan keterangan {$transaction->description} diperbarui menjadi senilai {$transaction->amount_formatted} oleh {$user->profile?->full_name}.",
|
||||
@ -283,6 +269,7 @@ function () use ($transaction): void {
|
||||
|
||||
$account = $transaction->cashAccount;
|
||||
|
||||
$transaction->clearMediaCollection('photos');
|
||||
$transaction->delete();
|
||||
|
||||
$this->recalculateBalances($account);
|
||||
@ -296,8 +283,6 @@ function () use ($transaction): void {
|
||||
'Gagal menghapus transaksi kas',
|
||||
);
|
||||
|
||||
$this->cacheForget('finance:default_account');
|
||||
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
'🗑️ Transaksi Kas Dihapus',
|
||||
"Transaksi kas senilai {$amountFormatted} dengan keterangan {$description} telah dihapus oleh {$user->profile?->full_name}.",
|
||||
@ -332,8 +317,6 @@ function () use ($transaction, $amount, $description): void {
|
||||
},
|
||||
'Gagal memperbarui transaksi kas referensi',
|
||||
);
|
||||
|
||||
$this->cacheForget('finance:default_account');
|
||||
}
|
||||
|
||||
public function deleteReferencedTransaction(CashTransaction $transaction): void
|
||||
@ -355,8 +338,6 @@ function () use ($transaction): void {
|
||||
},
|
||||
'Gagal menghapus transaksi kas referensi',
|
||||
);
|
||||
|
||||
$this->cacheForget('finance:default_account');
|
||||
}
|
||||
|
||||
private function recalculateBalances(CashAccount $cashAccount): void
|
||||
|
||||
@ -133,6 +133,7 @@ function () use ($expense): void {
|
||||
$this->cashService->deleteReferencedTransaction($expense->cashTransaction);
|
||||
}
|
||||
|
||||
$expense->clearMediaCollection('photos');
|
||||
$expense->delete();
|
||||
},
|
||||
'Gagal menghapus pengeluaran',
|
||||
|
||||
@ -172,6 +172,8 @@ public function delete(Attendance $attendance, User $user): void
|
||||
|
||||
$this->runInTransaction(
|
||||
function () use ($attendance): void {
|
||||
$attendance->clearMediaCollection('checkin');
|
||||
$attendance->clearMediaCollection('checkout');
|
||||
$attendance->delete();
|
||||
},
|
||||
'Gagal menghapus presensi',
|
||||
|
||||
@ -128,7 +128,6 @@ function () use ($validated): User {
|
||||
'Gagal membuat karyawan',
|
||||
);
|
||||
|
||||
$this->cacheForget('system:assignable_roles');
|
||||
$this->cacheForgetByPattern('hr:employees:*');
|
||||
|
||||
$this->notifyOwner(
|
||||
@ -190,7 +189,6 @@ function () use ($validated, $user, $employee): void {
|
||||
'Gagal memperbarui karyawan',
|
||||
);
|
||||
|
||||
$this->cacheForget('system:assignable_roles');
|
||||
$this->cacheForgetByPattern('hr:employees:*');
|
||||
|
||||
$this->notifyOwner(
|
||||
@ -215,7 +213,6 @@ function () use ($user, $validated): void {
|
||||
'Gagal memperbarui status karyawan',
|
||||
);
|
||||
|
||||
$this->cacheForget('system:assignable_roles');
|
||||
$this->cacheForgetByPattern('hr:employees:*');
|
||||
|
||||
$statusLabel = $validated['is_active'] ? 'aktif' : 'nonaktif';
|
||||
@ -240,7 +237,6 @@ function () use ($user): void {
|
||||
'Gagal mereset kata sandi karyawan',
|
||||
);
|
||||
|
||||
$this->cacheForget('system:assignable_roles');
|
||||
$this->cacheForgetByPattern('hr:employees:*');
|
||||
|
||||
$this->notifyOwner(
|
||||
@ -263,7 +259,6 @@ function () use ($user): void {
|
||||
'Gagal menghapus karyawan',
|
||||
);
|
||||
|
||||
$this->cacheForget('system:assignable_roles');
|
||||
$this->cacheForgetByPattern('hr:employees:*');
|
||||
|
||||
$this->notifyOwner(
|
||||
|
||||
@ -680,6 +680,7 @@ function () use ($cutting): void {
|
||||
|
||||
$cutting->materials()->delete();
|
||||
$cutting->results()->delete();
|
||||
$cutting->clearMediaCollection('images');
|
||||
$cutting->delete();
|
||||
},
|
||||
'Gagal menghapus proses cutting',
|
||||
|
||||
@ -716,6 +716,7 @@ private function rejectCreate(OwnerVerificationRequest $verificationRequest): vo
|
||||
|
||||
$this->runInTransaction(
|
||||
function () use ($purchase): void {
|
||||
$purchase->clearMediaCollection('photos');
|
||||
$purchase->items()->delete();
|
||||
$purchase->delete();
|
||||
},
|
||||
@ -733,6 +734,7 @@ function () use ($purchase): void {
|
||||
$this->decrementStock($item);
|
||||
}
|
||||
|
||||
$purchase->clearMediaCollection('photos');
|
||||
$purchase->items()->delete();
|
||||
$purchase->delete();
|
||||
},
|
||||
|
||||
@ -573,6 +573,7 @@ private function rejectCreate(OwnerVerificationRequest $verificationRequest): vo
|
||||
|
||||
$this->runInTransaction(
|
||||
function () use ($restock): void {
|
||||
$restock->clearMediaCollection('photos');
|
||||
$restock->items()->delete();
|
||||
$restock->delete();
|
||||
},
|
||||
@ -592,6 +593,7 @@ function () use ($restock): void {
|
||||
$this->decrementStock($item, $stockType);
|
||||
}
|
||||
|
||||
$restock->clearMediaCollection('photos');
|
||||
$restock->items()->delete();
|
||||
$restock->delete();
|
||||
},
|
||||
|
||||
@ -156,8 +156,10 @@ public function submitVerification(
|
||||
}
|
||||
|
||||
$this->cacheForgetByPattern('manage:stocks:*');
|
||||
if ($isOwner) {
|
||||
$this->cacheForgetByPattern('prices:*');
|
||||
}
|
||||
}
|
||||
|
||||
public function approveVerification(
|
||||
Cutting $cutting,
|
||||
|
||||
@ -254,7 +254,6 @@ function () use ($validated, $product, $user, $isOwner): void {
|
||||
);
|
||||
|
||||
$this->cacheForgetByPattern('master:products:*');
|
||||
$this->cacheForgetByPattern('prices:*');
|
||||
$this->cacheForget('homepage:page_data');
|
||||
|
||||
if ($isOwner) {
|
||||
@ -329,7 +328,6 @@ public function delete(Product $product, User $user): void
|
||||
$name = $product->name;
|
||||
$this->applyDeleteSubject($product);
|
||||
$this->cacheForgetByPattern('master:products:*');
|
||||
$this->cacheForgetByPattern('prices:*');
|
||||
$this->cacheForget('homepage:page_data');
|
||||
|
||||
$this->notifyOwner(
|
||||
@ -437,7 +435,6 @@ public function applyVerificationRequest(OwnerVerificationRequest $verificationR
|
||||
};
|
||||
|
||||
$this->cacheForgetByPattern('master:products:*');
|
||||
$this->cacheForgetByPattern('prices:*');
|
||||
}
|
||||
|
||||
public function rejectVerificationRequest(OwnerVerificationRequest $verificationRequest): void
|
||||
@ -452,7 +449,6 @@ public function rejectVerificationRequest(OwnerVerificationRequest $verification
|
||||
};
|
||||
|
||||
$this->cacheForgetByPattern('master:products:*');
|
||||
$this->cacheForgetByPattern('prices:*');
|
||||
$this->cacheForget('homepage:page_data');
|
||||
}
|
||||
|
||||
@ -523,6 +519,7 @@ private function applyPayloadToProduct(
|
||||
->whereNotIn('id', $submittedVariantIds)
|
||||
->get()
|
||||
->each(function (ProductVariant $variant): void {
|
||||
$variant->clearMediaCollection('images');
|
||||
$variant->delete();
|
||||
});
|
||||
|
||||
@ -589,6 +586,9 @@ private function applyDeleteSubject(Product $product): void
|
||||
{
|
||||
$this->runInTransaction(
|
||||
function () use ($product): void {
|
||||
$product->variants()->each(function (ProductVariant $variant): void {
|
||||
$variant->clearMediaCollection('images');
|
||||
});
|
||||
$product->variants()->delete();
|
||||
$product->categories()->detach();
|
||||
$product->delete();
|
||||
@ -656,6 +656,9 @@ private function rejectCreate(OwnerVerificationRequest $verificationRequest): vo
|
||||
|
||||
$this->runInTransaction(
|
||||
function () use ($product): void {
|
||||
$product->variants()->each(function (ProductVariant $variant): void {
|
||||
$variant->clearMediaCollection('images');
|
||||
});
|
||||
$product->variants()->delete();
|
||||
$product->categories()->detach();
|
||||
$product->delete();
|
||||
|
||||
@ -37,24 +37,6 @@ public function paginateForIndex(array $tableQuery, string $isActive, string $st
|
||||
->with('media')
|
||||
->when($tableQuery['search'] !== '', function ($query) use ($tableQuery): void {
|
||||
$query->where('variant', 'like', "%{$tableQuery['search']}%");
|
||||
})
|
||||
->when($stockStatus === 'out_of_stock', fn ($q) => $q->where('stock', '<=', 0))
|
||||
->when($stockStatus === 'low_stock', function ($q): void {
|
||||
$q->where('stock', '>', 0)
|
||||
->where(function ($q): void {
|
||||
$q->orWhere(function ($q): void {
|
||||
$q->whereHas('rawMaterial', fn ($q) => $q->where('unit', RawMaterialUnit::YARD->value))
|
||||
->where('stock', '<', 20);
|
||||
})
|
||||
->orWhere(function ($q): void {
|
||||
$q->whereHas('rawMaterial', fn ($q) => $q->where('unit', RawMaterialUnit::METER->value))
|
||||
->where('stock', '<', 10);
|
||||
})
|
||||
->orWhere(function ($q): void {
|
||||
$q->whereHas('rawMaterial', fn ($q) => $q->where('unit', RawMaterialUnit::KILOGRAM->value))
|
||||
->where('stock', '<', 5);
|
||||
});
|
||||
});
|
||||
}),
|
||||
])
|
||||
->when(($tableQuery['search_id'] ?? '') !== '', function (Builder $query) use ($tableQuery): void {
|
||||
@ -70,15 +52,21 @@ public function paginateForIndex(array $tableQuery, string $isActive, string $st
|
||||
$query->whereHas('prices', fn (Builder $priceQuery) => $priceQuery->where('stock', '<=', 0));
|
||||
})
|
||||
->when($stockStatus === 'low_stock', function (Builder $query): void {
|
||||
$query->where(function (Builder $query): void {
|
||||
$query->where('unit', RawMaterialUnit::YARD->value)
|
||||
->whereHas('prices', fn (Builder $q) => $q->where('stock', '>', 0)->where('stock', '<', 20));
|
||||
})->orWhere(function (Builder $query): void {
|
||||
$query->where('unit', RawMaterialUnit::METER->value)
|
||||
->whereHas('prices', fn (Builder $q) => $q->where('stock', '>', 0)->where('stock', '<', 10));
|
||||
})->orWhere(function (Builder $query): void {
|
||||
$query->where('unit', RawMaterialUnit::KILOGRAM->value)
|
||||
->whereHas('prices', fn (Builder $q) => $q->where('stock', '>', 0)->where('stock', '<', 5));
|
||||
$minStock = [
|
||||
RawMaterialUnit::YARD->value => 20,
|
||||
RawMaterialUnit::METER->value => 10,
|
||||
RawMaterialUnit::KILOGRAM->value => 5,
|
||||
];
|
||||
|
||||
$query->whereHas('prices', function (Builder $priceQuery) use ($minStock): void {
|
||||
$priceQuery->where('stock', '>', 0)->where(function (Builder $priceQuery) use ($minStock): void {
|
||||
foreach (RawMaterialUnit::cases() as $unit) {
|
||||
$priceQuery->orWhere(function (Builder $priceQuery) use ($unit, $minStock): void {
|
||||
$priceQuery->whereHas('rawMaterial', fn (Builder $rawMaterialQuery) => $rawMaterialQuery->where('unit', $unit->value))
|
||||
->where('stock', '<', $minStock[$unit->value]);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -286,6 +274,9 @@ private function applyDeleteSubject(RawMaterial $rawMaterial): void
|
||||
{
|
||||
$this->runInTransaction(
|
||||
function () use ($rawMaterial): void {
|
||||
$rawMaterial->prices()->each(function (RawMaterialPrice $price): void {
|
||||
$price->clearMediaCollection('images');
|
||||
});
|
||||
$rawMaterial->prices()->delete();
|
||||
$rawMaterial->delete();
|
||||
},
|
||||
@ -337,6 +328,7 @@ private function applyPayloadToRawMaterial(
|
||||
->whereNotIn('id', $submittedPriceIds)
|
||||
->get()
|
||||
->each(function (RawMaterialPrice $price): void {
|
||||
$price->clearMediaCollection('images');
|
||||
$price->delete();
|
||||
});
|
||||
|
||||
@ -382,6 +374,9 @@ private function rejectCreate(OwnerVerificationRequest $verificationRequest): vo
|
||||
|
||||
$this->runInTransaction(
|
||||
function () use ($rawMaterial): void {
|
||||
$rawMaterial->prices()->each(function (RawMaterialPrice $price): void {
|
||||
$price->clearMediaCollection('images');
|
||||
});
|
||||
$rawMaterial->prices()->delete();
|
||||
$rawMaterial->delete();
|
||||
},
|
||||
|
||||
@ -20,13 +20,17 @@
|
||||
use App\Models\Purchase;
|
||||
use App\Models\RawMaterialPrice;
|
||||
use App\Models\User;
|
||||
use App\Services\Concerns\CachesQuery;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AnalysisService
|
||||
{
|
||||
use CachesQuery;
|
||||
|
||||
public function getAttendance(): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_attendance', 900, function () {
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||
@ -57,10 +61,12 @@ public function getAttendance(): array
|
||||
'absent' => $absent,
|
||||
'on_leave' => $onLeave,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function getMyAttendance(User $user, ?Carbon $startDate = null, ?Carbon $endDate = null): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_my_attendance', 900, function () use ($user, $startDate, $endDate) {
|
||||
$employee = $user->employee;
|
||||
|
||||
if ($employee === null) {
|
||||
@ -120,10 +126,12 @@ public function getMyAttendance(User $user, ?Carbon $startDate = null, ?Carbon $
|
||||
'leave_days' => $leaveDays,
|
||||
'percentage' => $percentage,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function getCashOverview(): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_cash_overview', 900, function () {
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||
@ -151,10 +159,12 @@ public function getCashOverview(): array
|
||||
'total_deposit' => (int) ($summary->total_deposit ?? 0),
|
||||
'total_withdrawal' => (int) ($summary->total_withdrawal ?? 0),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function getTopSuppliers(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_top_suppliers', 900, function () use ($startDate, $endDate) {
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||
@ -174,10 +184,12 @@ public function getTopSuppliers(?Carbon $startDate = null, ?Carbon $endDate = nu
|
||||
'purchase_count' => (int) $item->purchase_count,
|
||||
])
|
||||
->toArray();
|
||||
});
|
||||
}
|
||||
|
||||
public function getTopCustomers(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_top_customers', 900, function () use ($startDate, $endDate) {
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||
@ -200,10 +212,12 @@ public function getTopCustomers(?Carbon $startDate = null, ?Carbon $endDate = nu
|
||||
'order_count' => (int) $item->order_count,
|
||||
])
|
||||
->toArray();
|
||||
});
|
||||
}
|
||||
|
||||
public function getRevenueSummary(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_revenue_summary', 900, function () use ($startDate, $endDate) {
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||
@ -248,10 +262,12 @@ public function getRevenueSummary(?Carbon $startDate = null, ?Carbon $endDate =
|
||||
'total_orders' => (int) ($revenueSummary->total_orders ?? 0),
|
||||
'avg_order' => (int) ($revenueSummary->avg_order ?? 0),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function getMonthlyRevenue(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_monthly_revenue', 900, function () use ($startDate, $endDate) {
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||
@ -365,10 +381,12 @@ public function getMonthlyRevenue(?Carbon $startDate = null, ?Carbon $endDate =
|
||||
}
|
||||
|
||||
return $result;
|
||||
});
|
||||
}
|
||||
|
||||
public function getExpenseSummary(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_expense_summary', 900, function () use ($startDate, $endDate) {
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||
@ -405,10 +423,12 @@ public function getExpenseSummary(?Carbon $startDate = null, ?Carbon $endDate =
|
||||
'expense_total' => $expenseTotal,
|
||||
'advance_total' => $advanceTotal,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function getMonthlyExpense(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_monthly_expense', 900, function () use ($startDate, $endDate) {
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||
@ -478,10 +498,12 @@ public function getMonthlyExpense(?Carbon $startDate = null, ?Carbon $endDate =
|
||||
}
|
||||
|
||||
return $result;
|
||||
});
|
||||
}
|
||||
|
||||
public function getProfitMetrics(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_profit_metrics', 900, function () use ($startDate, $endDate) {
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||
@ -583,10 +605,12 @@ public function getProfitMetrics(?Carbon $startDate = null, ?Carbon $endDate = n
|
||||
'aov' => $aov,
|
||||
'items_per_transaction' => $itemsPerTransaction,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function getRawMaterialStock(): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_raw_material_stock', 900, function () {
|
||||
$prices = RawMaterialPrice::query()
|
||||
->join('raw_materials', 'raw_material_prices.raw_material_id', '=', 'raw_materials.id')
|
||||
->selectRaw('
|
||||
@ -610,10 +634,12 @@ public function getRawMaterialStock(): array
|
||||
'kilogram' => round((float) ($prices->get('kilogram')->total_stock ?? 0), 2),
|
||||
],
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function getProductStock(): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_product_stock', 900, function () {
|
||||
$variants = ProductVariant::query()
|
||||
->join('products', 'product_variants.product_id', '=', 'products.id')
|
||||
->selectRaw('
|
||||
@ -646,10 +672,12 @@ public function getProductStock(): array
|
||||
'total_variants' => (int) ($variants->total_variants ?? 0),
|
||||
'total_categories' => (int) $totalCategories,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function getBusyHours(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_busy_hours', 900, function () use ($startDate, $endDate) {
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||
@ -674,10 +702,12 @@ public function getBusyHours(?Carbon $startDate = null, ?Carbon $endDate = null)
|
||||
}
|
||||
|
||||
return $result;
|
||||
});
|
||||
}
|
||||
|
||||
public function getTopProducts(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_top_products', 900, function () use ($startDate, $endDate) {
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||
@ -702,10 +732,12 @@ public function getTopProducts(?Carbon $startDate = null, ?Carbon $endDate = nul
|
||||
'total_revenue' => (int) $item->total_revenue,
|
||||
])
|
||||
->toArray();
|
||||
});
|
||||
}
|
||||
|
||||
public function getMarketingSales(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
||||
{
|
||||
return $this->cacheRemember('analysis:get_marketing_sales', 900, function () use ($startDate, $endDate) {
|
||||
$qtySubquery = DB::table('order_items')
|
||||
->select('order_id', DB::raw('SUM(quantity) as total_qty'))
|
||||
->whereNull('deleted_at')
|
||||
@ -743,6 +775,7 @@ public function getMarketingSales(?Carbon $startDate = null, ?Carbon $endDate =
|
||||
'avg_order' => (int) $item->avg_order,
|
||||
])
|
||||
->toArray();
|
||||
});
|
||||
}
|
||||
|
||||
public function isManager(?User $user): bool
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
use App\Models\Category;
|
||||
use App\Models\Product;
|
||||
use App\Models\SystemConfiguration;
|
||||
use App\Services\Concerns\CachesQuery;
|
||||
use App\Services\Manage\CuttingResultPriceResolver;
|
||||
use App\Services\System\Setting\HomepageSettingService;
|
||||
use App\Settings\SocialMediaSettings;
|
||||
@ -14,6 +15,8 @@
|
||||
|
||||
class HomepageService
|
||||
{
|
||||
use CachesQuery;
|
||||
|
||||
public function __construct(
|
||||
private readonly CuttingResultPriceResolver $cuttingResultPriceResolver,
|
||||
private readonly HomepageSettingService $homepageSettingService,
|
||||
@ -21,6 +24,7 @@ public function __construct(
|
||||
|
||||
public function pageData(): array
|
||||
{
|
||||
return $this->cacheRemember('homepage:page_data', 900, function () {
|
||||
$categories = Category::getActiveWithProducts();
|
||||
$products = $this->getProducts();
|
||||
|
||||
@ -45,6 +49,7 @@ public function pageData(): array
|
||||
'tiktokUrl' => $socialSettings->tiktok_url ?? null,
|
||||
'homepage' => $this->homepageSettingService->homepageData(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
private function getProducts(): array
|
||||
|
||||
@ -87,8 +87,6 @@ public function create(array $validated): void
|
||||
]);
|
||||
}
|
||||
|
||||
$this->cacheForget('system:permissions');
|
||||
$this->cacheForget('system:assignable_roles');
|
||||
$this->cacheForgetByPattern('system:roles:*');
|
||||
}
|
||||
|
||||
@ -116,8 +114,6 @@ public function update(Role $role, array $validated): void
|
||||
]);
|
||||
}
|
||||
|
||||
$this->cacheForget('system:permissions');
|
||||
$this->cacheForget('system:assignable_roles');
|
||||
$this->cacheForgetByPattern('system:roles:*');
|
||||
}
|
||||
|
||||
@ -125,8 +121,6 @@ public function delete(Role $role): void
|
||||
{
|
||||
$role->delete();
|
||||
|
||||
$this->cacheForget('system:permissions');
|
||||
$this->cacheForget('system:assignable_roles');
|
||||
$this->cacheForgetByPattern('system:roles:*');
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
'ssr' => [
|
||||
'enabled' => false,
|
||||
'enabled' => true,
|
||||
'url' => 'http://127.0.0.1:13714',
|
||||
// 'bundle' => base_path('bootstrap/ssr/ssr.mjs'),
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@ import { Toaster } from '@/components/ui/sonner';
|
||||
import { useFlashToast } from '@/composables/useFlashToast';
|
||||
import { restoreConnection } from '@/lib/thermal-printer/stable-transport';
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker
|
||||
.register('/sw.js', { scope: '/' })
|
||||
@ -23,7 +22,6 @@ if (typeof window !== 'undefined') {
|
||||
});
|
||||
|
||||
void restoreConnection();
|
||||
}
|
||||
|
||||
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
|
||||
|
||||
|
||||
@ -529,11 +529,11 @@ const productBarData = computed<ProductData[]>(() => {
|
||||
|
||||
function applyFilters() {
|
||||
router.get(
|
||||
admin.analysis.url(),
|
||||
{
|
||||
admin.analysis.url({
|
||||
start_date: startDate.value,
|
||||
end_date: endDate.value,
|
||||
},
|
||||
}),
|
||||
{},
|
||||
{
|
||||
preserveState: true,
|
||||
preserveScroll: true,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user