Refactor HomepageService to remove caching and simplify pageData method; disable SSR in Inertia config; improve service worker registration in app.ts; fix URL parameters in Analysis.vue router call.
This commit is contained in:
parent
2e578cd976
commit
bb17bf6ad4
@ -20,17 +20,13 @@
|
|||||||
use App\Models\Purchase;
|
use App\Models\Purchase;
|
||||||
use App\Models\RawMaterialPrice;
|
use App\Models\RawMaterialPrice;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Services\Concerns\CachesQuery;
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class AnalysisService
|
class AnalysisService
|
||||||
{
|
{
|
||||||
use CachesQuery;
|
|
||||||
|
|
||||||
public function getAttendance(): array
|
public function getAttendance(): array
|
||||||
{
|
{
|
||||||
return $this->cacheRemember('analysis:get_attendance', 900, function () {
|
|
||||||
/** @var User|null $user */
|
/** @var User|null $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||||
@ -61,12 +57,10 @@ public function getAttendance(): array
|
|||||||
'absent' => $absent,
|
'absent' => $absent,
|
||||||
'on_leave' => $onLeave,
|
'on_leave' => $onLeave,
|
||||||
];
|
];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMyAttendance(User $user, ?Carbon $startDate = null, ?Carbon $endDate = null): array
|
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;
|
$employee = $user->employee;
|
||||||
|
|
||||||
if ($employee === null) {
|
if ($employee === null) {
|
||||||
@ -126,12 +120,10 @@ public function getMyAttendance(User $user, ?Carbon $startDate = null, ?Carbon $
|
|||||||
'leave_days' => $leaveDays,
|
'leave_days' => $leaveDays,
|
||||||
'percentage' => $percentage,
|
'percentage' => $percentage,
|
||||||
];
|
];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCashOverview(): array
|
public function getCashOverview(): array
|
||||||
{
|
{
|
||||||
return $this->cacheRemember('analysis:get_cash_overview', 900, function () {
|
|
||||||
/** @var User|null $user */
|
/** @var User|null $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||||
@ -159,12 +151,10 @@ public function getCashOverview(): array
|
|||||||
'total_deposit' => (int) ($summary->total_deposit ?? 0),
|
'total_deposit' => (int) ($summary->total_deposit ?? 0),
|
||||||
'total_withdrawal' => (int) ($summary->total_withdrawal ?? 0),
|
'total_withdrawal' => (int) ($summary->total_withdrawal ?? 0),
|
||||||
];
|
];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTopSuppliers(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
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 */
|
/** @var User|null $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||||
@ -184,12 +174,10 @@ public function getTopSuppliers(?Carbon $startDate = null, ?Carbon $endDate = nu
|
|||||||
'purchase_count' => (int) $item->purchase_count,
|
'purchase_count' => (int) $item->purchase_count,
|
||||||
])
|
])
|
||||||
->toArray();
|
->toArray();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTopCustomers(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
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 */
|
/** @var User|null $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||||
@ -212,12 +200,10 @@ public function getTopCustomers(?Carbon $startDate = null, ?Carbon $endDate = nu
|
|||||||
'order_count' => (int) $item->order_count,
|
'order_count' => (int) $item->order_count,
|
||||||
])
|
])
|
||||||
->toArray();
|
->toArray();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRevenueSummary(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
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 */
|
/** @var User|null $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||||
@ -262,12 +248,10 @@ public function getRevenueSummary(?Carbon $startDate = null, ?Carbon $endDate =
|
|||||||
'total_orders' => (int) ($revenueSummary->total_orders ?? 0),
|
'total_orders' => (int) ($revenueSummary->total_orders ?? 0),
|
||||||
'avg_order' => (int) ($revenueSummary->avg_order ?? 0),
|
'avg_order' => (int) ($revenueSummary->avg_order ?? 0),
|
||||||
];
|
];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMonthlyRevenue(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
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 */
|
/** @var User|null $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||||
@ -381,12 +365,10 @@ public function getMonthlyRevenue(?Carbon $startDate = null, ?Carbon $endDate =
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getExpenseSummary(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
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 */
|
/** @var User|null $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||||
@ -423,12 +405,10 @@ public function getExpenseSummary(?Carbon $startDate = null, ?Carbon $endDate =
|
|||||||
'expense_total' => $expenseTotal,
|
'expense_total' => $expenseTotal,
|
||||||
'advance_total' => $advanceTotal,
|
'advance_total' => $advanceTotal,
|
||||||
];
|
];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMonthlyExpense(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
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 */
|
/** @var User|null $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||||
@ -498,12 +478,10 @@ public function getMonthlyExpense(?Carbon $startDate = null, ?Carbon $endDate =
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getProfitMetrics(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
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 */
|
/** @var User|null $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||||
@ -605,12 +583,10 @@ public function getProfitMetrics(?Carbon $startDate = null, ?Carbon $endDate = n
|
|||||||
'aov' => $aov,
|
'aov' => $aov,
|
||||||
'items_per_transaction' => $itemsPerTransaction,
|
'items_per_transaction' => $itemsPerTransaction,
|
||||||
];
|
];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRawMaterialStock(): array
|
public function getRawMaterialStock(): array
|
||||||
{
|
{
|
||||||
return $this->cacheRemember('analysis:get_raw_material_stock', 900, function () {
|
|
||||||
$prices = RawMaterialPrice::query()
|
$prices = RawMaterialPrice::query()
|
||||||
->join('raw_materials', 'raw_material_prices.raw_material_id', '=', 'raw_materials.id')
|
->join('raw_materials', 'raw_material_prices.raw_material_id', '=', 'raw_materials.id')
|
||||||
->selectRaw('
|
->selectRaw('
|
||||||
@ -634,12 +610,10 @@ public function getRawMaterialStock(): array
|
|||||||
'kilogram' => round((float) ($prices->get('kilogram')->total_stock ?? 0), 2),
|
'kilogram' => round((float) ($prices->get('kilogram')->total_stock ?? 0), 2),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getProductStock(): array
|
public function getProductStock(): array
|
||||||
{
|
{
|
||||||
return $this->cacheRemember('analysis:get_product_stock', 900, function () {
|
|
||||||
$variants = ProductVariant::query()
|
$variants = ProductVariant::query()
|
||||||
->join('products', 'product_variants.product_id', '=', 'products.id')
|
->join('products', 'product_variants.product_id', '=', 'products.id')
|
||||||
->selectRaw('
|
->selectRaw('
|
||||||
@ -672,12 +646,10 @@ public function getProductStock(): array
|
|||||||
'total_variants' => (int) ($variants->total_variants ?? 0),
|
'total_variants' => (int) ($variants->total_variants ?? 0),
|
||||||
'total_categories' => (int) $totalCategories,
|
'total_categories' => (int) $totalCategories,
|
||||||
];
|
];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBusyHours(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
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 */
|
/** @var User|null $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||||
@ -702,12 +674,10 @@ public function getBusyHours(?Carbon $startDate = null, ?Carbon $endDate = null)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTopProducts(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
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 */
|
/** @var User|null $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
$isSuper = $user?->hasAnyRole(['developer', 'owner', 'direktur']) ?? false;
|
||||||
@ -732,12 +702,10 @@ public function getTopProducts(?Carbon $startDate = null, ?Carbon $endDate = nul
|
|||||||
'total_revenue' => (int) $item->total_revenue,
|
'total_revenue' => (int) $item->total_revenue,
|
||||||
])
|
])
|
||||||
->toArray();
|
->toArray();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMarketingSales(?Carbon $startDate = null, ?Carbon $endDate = null): array
|
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')
|
$qtySubquery = DB::table('order_items')
|
||||||
->select('order_id', DB::raw('SUM(quantity) as total_qty'))
|
->select('order_id', DB::raw('SUM(quantity) as total_qty'))
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
@ -775,7 +743,6 @@ public function getMarketingSales(?Carbon $startDate = null, ?Carbon $endDate =
|
|||||||
'avg_order' => (int) $item->avg_order,
|
'avg_order' => (int) $item->avg_order,
|
||||||
])
|
])
|
||||||
->toArray();
|
->toArray();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isManager(?User $user): bool
|
public function isManager(?User $user): bool
|
||||||
|
|||||||
@ -6,7 +6,6 @@
|
|||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Models\SystemConfiguration;
|
use App\Models\SystemConfiguration;
|
||||||
use App\Services\Concerns\CachesQuery;
|
|
||||||
use App\Services\Manage\CuttingResultPriceResolver;
|
use App\Services\Manage\CuttingResultPriceResolver;
|
||||||
use App\Services\System\Setting\HomepageSettingService;
|
use App\Services\System\Setting\HomepageSettingService;
|
||||||
use App\Settings\SocialMediaSettings;
|
use App\Settings\SocialMediaSettings;
|
||||||
@ -15,8 +14,6 @@
|
|||||||
|
|
||||||
class HomepageService
|
class HomepageService
|
||||||
{
|
{
|
||||||
use CachesQuery;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly CuttingResultPriceResolver $cuttingResultPriceResolver,
|
private readonly CuttingResultPriceResolver $cuttingResultPriceResolver,
|
||||||
private readonly HomepageSettingService $homepageSettingService,
|
private readonly HomepageSettingService $homepageSettingService,
|
||||||
@ -24,7 +21,6 @@ public function __construct(
|
|||||||
|
|
||||||
public function pageData(): array
|
public function pageData(): array
|
||||||
{
|
{
|
||||||
return $this->cacheRemember('homepage:page_data', 900, function () {
|
|
||||||
$categories = Category::getActiveWithProducts();
|
$categories = Category::getActiveWithProducts();
|
||||||
$products = $this->getProducts();
|
$products = $this->getProducts();
|
||||||
|
|
||||||
@ -49,7 +45,6 @@ public function pageData(): array
|
|||||||
'tiktokUrl' => $socialSettings->tiktok_url ?? null,
|
'tiktokUrl' => $socialSettings->tiktok_url ?? null,
|
||||||
'homepage' => $this->homepageSettingService->homepageData(),
|
'homepage' => $this->homepageSettingService->homepageData(),
|
||||||
];
|
];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getProducts(): array
|
private function getProducts(): array
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
'ssr' => [
|
'ssr' => [
|
||||||
'enabled' => true,
|
'enabled' => false,
|
||||||
'url' => 'http://127.0.0.1:13714',
|
'url' => 'http://127.0.0.1:13714',
|
||||||
// 'bundle' => base_path('bootstrap/ssr/ssr.mjs'),
|
// 'bundle' => base_path('bootstrap/ssr/ssr.mjs'),
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { Toaster } from '@/components/ui/sonner';
|
|||||||
import { useFlashToast } from '@/composables/useFlashToast';
|
import { useFlashToast } from '@/composables/useFlashToast';
|
||||||
import { restoreConnection } from '@/lib/thermal-printer/stable-transport';
|
import { restoreConnection } from '@/lib/thermal-printer/stable-transport';
|
||||||
|
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker
|
navigator.serviceWorker
|
||||||
.register('/sw.js', { scope: '/' })
|
.register('/sw.js', { scope: '/' })
|
||||||
@ -22,6 +23,7 @@ window.addEventListener('beforeinstallprompt', (e) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
void restoreConnection();
|
void restoreConnection();
|
||||||
|
}
|
||||||
|
|
||||||
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
|
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
|
||||||
|
|
||||||
|
|||||||
@ -529,11 +529,11 @@ const productBarData = computed<ProductData[]>(() => {
|
|||||||
|
|
||||||
function applyFilters() {
|
function applyFilters() {
|
||||||
router.get(
|
router.get(
|
||||||
admin.analysis.url({
|
admin.analysis.url(),
|
||||||
|
{
|
||||||
start_date: startDate.value,
|
start_date: startDate.value,
|
||||||
end_date: endDate.value,
|
end_date: endDate.value,
|
||||||
}),
|
},
|
||||||
{},
|
|
||||||
{
|
{
|
||||||
preserveState: true,
|
preserveState: true,
|
||||||
preserveScroll: true,
|
preserveScroll: true,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user