Compare commits
5 Commits
2e578cd976
...
a29e6af430
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a29e6af430 | ||
|
|
ba01039b41 | ||
|
|
ef90f8361f | ||
|
|
c16cfac861 | ||
|
|
bb17bf6ad4 |
@ -95,6 +95,8 @@ function () use ($cashAccount, $validated, $user): CashTransaction {
|
|||||||
'Gagal melakukan setoran kas',
|
'Gagal melakukan setoran kas',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->cacheForget('finance:default_account');
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'💰 Setoran Kas',
|
'💰 Setoran Kas',
|
||||||
"Setoran kas baru {$transaction->amount_formatted} dengan keterangan: {$transaction->description} oleh {$user->profile?->full_name}.",
|
"Setoran kas baru {$transaction->amount_formatted} dengan keterangan: {$transaction->description} oleh {$user->profile?->full_name}.",
|
||||||
@ -138,6 +140,8 @@ function () use ($cashAccount, $validated, $user): CashTransaction {
|
|||||||
'Gagal melakukan tarik kas',
|
'Gagal melakukan tarik kas',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->cacheForget('finance:default_account');
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'🏦 Tarik Kas',
|
'🏦 Tarik Kas',
|
||||||
"Tarik kas {$transaction->amount_formatted} dengan keterangan: {$transaction->description} oleh {$user->profile?->full_name}.",
|
"Tarik kas {$transaction->amount_formatted} dengan keterangan: {$transaction->description} oleh {$user->profile?->full_name}.",
|
||||||
@ -155,7 +159,7 @@ public function recordOutgoing(
|
|||||||
User $user,
|
User $user,
|
||||||
?CashAccount $cashAccount = null,
|
?CashAccount $cashAccount = null,
|
||||||
): CashTransaction {
|
): CashTransaction {
|
||||||
return $this->runInTransaction(
|
$transaction = $this->runInTransaction(
|
||||||
function () use ($reference, $amount, $description, $user, $cashAccount): CashTransaction {
|
function () use ($reference, $amount, $description, $user, $cashAccount): CashTransaction {
|
||||||
$account = CashAccount::query()->lockForUpdate()->findOrFail(
|
$account = CashAccount::query()->lockForUpdate()->findOrFail(
|
||||||
($cashAccount ?? $this->getDefaultAccount())->id,
|
($cashAccount ?? $this->getDefaultAccount())->id,
|
||||||
@ -187,6 +191,10 @@ function () use ($reference, $amount, $description, $user, $cashAccount): CashTr
|
|||||||
},
|
},
|
||||||
'Gagal mencatat transaksi keluar kas',
|
'Gagal mencatat transaksi keluar kas',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->cacheForget('finance:default_account');
|
||||||
|
|
||||||
|
return $transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function recordIncoming(
|
public function recordIncoming(
|
||||||
@ -196,7 +204,7 @@ public function recordIncoming(
|
|||||||
User $user,
|
User $user,
|
||||||
?CashAccount $cashAccount = null,
|
?CashAccount $cashAccount = null,
|
||||||
): CashTransaction {
|
): CashTransaction {
|
||||||
return $this->runInTransaction(
|
$transaction = $this->runInTransaction(
|
||||||
function () use ($reference, $amount, $description, $user, $cashAccount): CashTransaction {
|
function () use ($reference, $amount, $description, $user, $cashAccount): CashTransaction {
|
||||||
$account = CashAccount::query()->lockForUpdate()->findOrFail(
|
$account = CashAccount::query()->lockForUpdate()->findOrFail(
|
||||||
($cashAccount ?? $this->getDefaultAccount())->id,
|
($cashAccount ?? $this->getDefaultAccount())->id,
|
||||||
@ -222,6 +230,10 @@ function () use ($reference, $amount, $description, $user, $cashAccount): CashTr
|
|||||||
},
|
},
|
||||||
'Gagal mencatat transaksi masuk kas',
|
'Gagal mencatat transaksi masuk kas',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->cacheForget('finance:default_account');
|
||||||
|
|
||||||
|
return $transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateDeposit(CashTransaction $transaction, array $validated, User $user): void
|
public function updateDeposit(CashTransaction $transaction, array $validated, User $user): void
|
||||||
@ -250,6 +262,8 @@ function () use ($transaction, $validated): void {
|
|||||||
'Gagal memperbarui setoran kas',
|
'Gagal memperbarui setoran kas',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->cacheForget('finance:default_account');
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'✏️ Transaksi Kas Diperbarui',
|
'✏️ Transaksi Kas Diperbarui',
|
||||||
"Transaksi kas dengan keterangan {$transaction->description} diperbarui menjadi senilai {$transaction->amount_formatted} oleh {$user->profile?->full_name}.",
|
"Transaksi kas dengan keterangan {$transaction->description} diperbarui menjadi senilai {$transaction->amount_formatted} oleh {$user->profile?->full_name}.",
|
||||||
@ -269,7 +283,6 @@ function () use ($transaction): void {
|
|||||||
|
|
||||||
$account = $transaction->cashAccount;
|
$account = $transaction->cashAccount;
|
||||||
|
|
||||||
$transaction->clearMediaCollection('photos');
|
|
||||||
$transaction->delete();
|
$transaction->delete();
|
||||||
|
|
||||||
$this->recalculateBalances($account);
|
$this->recalculateBalances($account);
|
||||||
@ -283,6 +296,8 @@ function () use ($transaction): void {
|
|||||||
'Gagal menghapus transaksi kas',
|
'Gagal menghapus transaksi kas',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->cacheForget('finance:default_account');
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'🗑️ Transaksi Kas Dihapus',
|
'🗑️ Transaksi Kas Dihapus',
|
||||||
"Transaksi kas senilai {$amountFormatted} dengan keterangan {$description} telah dihapus oleh {$user->profile?->full_name}.",
|
"Transaksi kas senilai {$amountFormatted} dengan keterangan {$description} telah dihapus oleh {$user->profile?->full_name}.",
|
||||||
@ -317,6 +332,8 @@ function () use ($transaction, $amount, $description): void {
|
|||||||
},
|
},
|
||||||
'Gagal memperbarui transaksi kas referensi',
|
'Gagal memperbarui transaksi kas referensi',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->cacheForget('finance:default_account');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteReferencedTransaction(CashTransaction $transaction): void
|
public function deleteReferencedTransaction(CashTransaction $transaction): void
|
||||||
@ -338,6 +355,8 @@ function () use ($transaction): void {
|
|||||||
},
|
},
|
||||||
'Gagal menghapus transaksi kas referensi',
|
'Gagal menghapus transaksi kas referensi',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->cacheForget('finance:default_account');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function recalculateBalances(CashAccount $cashAccount): void
|
private function recalculateBalances(CashAccount $cashAccount): void
|
||||||
|
|||||||
@ -133,7 +133,6 @@ function () use ($expense): void {
|
|||||||
$this->cashService->deleteReferencedTransaction($expense->cashTransaction);
|
$this->cashService->deleteReferencedTransaction($expense->cashTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
$expense->clearMediaCollection('photos');
|
|
||||||
$expense->delete();
|
$expense->delete();
|
||||||
},
|
},
|
||||||
'Gagal menghapus pengeluaran',
|
'Gagal menghapus pengeluaran',
|
||||||
|
|||||||
@ -172,8 +172,6 @@ public function delete(Attendance $attendance, User $user): void
|
|||||||
|
|
||||||
$this->runInTransaction(
|
$this->runInTransaction(
|
||||||
function () use ($attendance): void {
|
function () use ($attendance): void {
|
||||||
$attendance->clearMediaCollection('checkin');
|
|
||||||
$attendance->clearMediaCollection('checkout');
|
|
||||||
$attendance->delete();
|
$attendance->delete();
|
||||||
},
|
},
|
||||||
'Gagal menghapus presensi',
|
'Gagal menghapus presensi',
|
||||||
|
|||||||
@ -128,6 +128,7 @@ function () use ($validated): User {
|
|||||||
'Gagal membuat karyawan',
|
'Gagal membuat karyawan',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->cacheForget('system:assignable_roles');
|
||||||
$this->cacheForgetByPattern('hr:employees:*');
|
$this->cacheForgetByPattern('hr:employees:*');
|
||||||
|
|
||||||
$this->notifyOwner(
|
$this->notifyOwner(
|
||||||
@ -189,6 +190,7 @@ function () use ($validated, $user, $employee): void {
|
|||||||
'Gagal memperbarui karyawan',
|
'Gagal memperbarui karyawan',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->cacheForget('system:assignable_roles');
|
||||||
$this->cacheForgetByPattern('hr:employees:*');
|
$this->cacheForgetByPattern('hr:employees:*');
|
||||||
|
|
||||||
$this->notifyOwner(
|
$this->notifyOwner(
|
||||||
@ -213,6 +215,7 @@ function () use ($user, $validated): void {
|
|||||||
'Gagal memperbarui status karyawan',
|
'Gagal memperbarui status karyawan',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->cacheForget('system:assignable_roles');
|
||||||
$this->cacheForgetByPattern('hr:employees:*');
|
$this->cacheForgetByPattern('hr:employees:*');
|
||||||
|
|
||||||
$statusLabel = $validated['is_active'] ? 'aktif' : 'nonaktif';
|
$statusLabel = $validated['is_active'] ? 'aktif' : 'nonaktif';
|
||||||
@ -237,6 +240,7 @@ function () use ($user): void {
|
|||||||
'Gagal mereset kata sandi karyawan',
|
'Gagal mereset kata sandi karyawan',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->cacheForget('system:assignable_roles');
|
||||||
$this->cacheForgetByPattern('hr:employees:*');
|
$this->cacheForgetByPattern('hr:employees:*');
|
||||||
|
|
||||||
$this->notifyOwner(
|
$this->notifyOwner(
|
||||||
@ -259,6 +263,7 @@ function () use ($user): void {
|
|||||||
'Gagal menghapus karyawan',
|
'Gagal menghapus karyawan',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->cacheForget('system:assignable_roles');
|
||||||
$this->cacheForgetByPattern('hr:employees:*');
|
$this->cacheForgetByPattern('hr:employees:*');
|
||||||
|
|
||||||
$this->notifyOwner(
|
$this->notifyOwner(
|
||||||
|
|||||||
@ -680,7 +680,6 @@ function () use ($cutting): void {
|
|||||||
|
|
||||||
$cutting->materials()->delete();
|
$cutting->materials()->delete();
|
||||||
$cutting->results()->delete();
|
$cutting->results()->delete();
|
||||||
$cutting->clearMediaCollection('images');
|
|
||||||
$cutting->delete();
|
$cutting->delete();
|
||||||
},
|
},
|
||||||
'Gagal menghapus proses cutting',
|
'Gagal menghapus proses cutting',
|
||||||
|
|||||||
@ -716,7 +716,6 @@ private function rejectCreate(OwnerVerificationRequest $verificationRequest): vo
|
|||||||
|
|
||||||
$this->runInTransaction(
|
$this->runInTransaction(
|
||||||
function () use ($purchase): void {
|
function () use ($purchase): void {
|
||||||
$purchase->clearMediaCollection('photos');
|
|
||||||
$purchase->items()->delete();
|
$purchase->items()->delete();
|
||||||
$purchase->delete();
|
$purchase->delete();
|
||||||
},
|
},
|
||||||
@ -734,7 +733,6 @@ function () use ($purchase): void {
|
|||||||
$this->decrementStock($item);
|
$this->decrementStock($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
$purchase->clearMediaCollection('photos');
|
|
||||||
$purchase->items()->delete();
|
$purchase->items()->delete();
|
||||||
$purchase->delete();
|
$purchase->delete();
|
||||||
},
|
},
|
||||||
|
|||||||
@ -573,7 +573,6 @@ private function rejectCreate(OwnerVerificationRequest $verificationRequest): vo
|
|||||||
|
|
||||||
$this->runInTransaction(
|
$this->runInTransaction(
|
||||||
function () use ($restock): void {
|
function () use ($restock): void {
|
||||||
$restock->clearMediaCollection('photos');
|
|
||||||
$restock->items()->delete();
|
$restock->items()->delete();
|
||||||
$restock->delete();
|
$restock->delete();
|
||||||
},
|
},
|
||||||
@ -593,7 +592,6 @@ function () use ($restock): void {
|
|||||||
$this->decrementStock($item, $stockType);
|
$this->decrementStock($item, $stockType);
|
||||||
}
|
}
|
||||||
|
|
||||||
$restock->clearMediaCollection('photos');
|
|
||||||
$restock->items()->delete();
|
$restock->items()->delete();
|
||||||
$restock->delete();
|
$restock->delete();
|
||||||
},
|
},
|
||||||
|
|||||||
@ -156,10 +156,8 @@ public function submitVerification(
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->cacheForgetByPattern('manage:stocks:*');
|
$this->cacheForgetByPattern('manage:stocks:*');
|
||||||
if ($isOwner) {
|
|
||||||
$this->cacheForgetByPattern('prices:*');
|
$this->cacheForgetByPattern('prices:*');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function approveVerification(
|
public function approveVerification(
|
||||||
Cutting $cutting,
|
Cutting $cutting,
|
||||||
|
|||||||
@ -254,6 +254,7 @@ function () use ($validated, $product, $user, $isOwner): void {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->cacheForgetByPattern('master:products:*');
|
$this->cacheForgetByPattern('master:products:*');
|
||||||
|
$this->cacheForgetByPattern('prices:*');
|
||||||
$this->cacheForget('homepage:page_data');
|
$this->cacheForget('homepage:page_data');
|
||||||
|
|
||||||
if ($isOwner) {
|
if ($isOwner) {
|
||||||
@ -328,6 +329,7 @@ public function delete(Product $product, User $user): void
|
|||||||
$name = $product->name;
|
$name = $product->name;
|
||||||
$this->applyDeleteSubject($product);
|
$this->applyDeleteSubject($product);
|
||||||
$this->cacheForgetByPattern('master:products:*');
|
$this->cacheForgetByPattern('master:products:*');
|
||||||
|
$this->cacheForgetByPattern('prices:*');
|
||||||
$this->cacheForget('homepage:page_data');
|
$this->cacheForget('homepage:page_data');
|
||||||
|
|
||||||
$this->notifyOwner(
|
$this->notifyOwner(
|
||||||
@ -435,6 +437,7 @@ public function applyVerificationRequest(OwnerVerificationRequest $verificationR
|
|||||||
};
|
};
|
||||||
|
|
||||||
$this->cacheForgetByPattern('master:products:*');
|
$this->cacheForgetByPattern('master:products:*');
|
||||||
|
$this->cacheForgetByPattern('prices:*');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rejectVerificationRequest(OwnerVerificationRequest $verificationRequest): void
|
public function rejectVerificationRequest(OwnerVerificationRequest $verificationRequest): void
|
||||||
@ -449,6 +452,7 @@ public function rejectVerificationRequest(OwnerVerificationRequest $verification
|
|||||||
};
|
};
|
||||||
|
|
||||||
$this->cacheForgetByPattern('master:products:*');
|
$this->cacheForgetByPattern('master:products:*');
|
||||||
|
$this->cacheForgetByPattern('prices:*');
|
||||||
$this->cacheForget('homepage:page_data');
|
$this->cacheForget('homepage:page_data');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,7 +523,6 @@ private function applyPayloadToProduct(
|
|||||||
->whereNotIn('id', $submittedVariantIds)
|
->whereNotIn('id', $submittedVariantIds)
|
||||||
->get()
|
->get()
|
||||||
->each(function (ProductVariant $variant): void {
|
->each(function (ProductVariant $variant): void {
|
||||||
$variant->clearMediaCollection('images');
|
|
||||||
$variant->delete();
|
$variant->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -586,9 +589,6 @@ private function applyDeleteSubject(Product $product): void
|
|||||||
{
|
{
|
||||||
$this->runInTransaction(
|
$this->runInTransaction(
|
||||||
function () use ($product): void {
|
function () use ($product): void {
|
||||||
$product->variants()->each(function (ProductVariant $variant): void {
|
|
||||||
$variant->clearMediaCollection('images');
|
|
||||||
});
|
|
||||||
$product->variants()->delete();
|
$product->variants()->delete();
|
||||||
$product->categories()->detach();
|
$product->categories()->detach();
|
||||||
$product->delete();
|
$product->delete();
|
||||||
@ -656,9 +656,6 @@ private function rejectCreate(OwnerVerificationRequest $verificationRequest): vo
|
|||||||
|
|
||||||
$this->runInTransaction(
|
$this->runInTransaction(
|
||||||
function () use ($product): void {
|
function () use ($product): void {
|
||||||
$product->variants()->each(function (ProductVariant $variant): void {
|
|
||||||
$variant->clearMediaCollection('images');
|
|
||||||
});
|
|
||||||
$product->variants()->delete();
|
$product->variants()->delete();
|
||||||
$product->categories()->detach();
|
$product->categories()->detach();
|
||||||
$product->delete();
|
$product->delete();
|
||||||
|
|||||||
@ -37,6 +37,24 @@ public function paginateForIndex(array $tableQuery, string $isActive, string $st
|
|||||||
->with('media')
|
->with('media')
|
||||||
->when($tableQuery['search'] !== '', function ($query) use ($tableQuery): void {
|
->when($tableQuery['search'] !== '', function ($query) use ($tableQuery): void {
|
||||||
$query->where('variant', 'like', "%{$tableQuery['search']}%");
|
$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 {
|
->when(($tableQuery['search_id'] ?? '') !== '', function (Builder $query) use ($tableQuery): void {
|
||||||
@ -52,21 +70,15 @@ public function paginateForIndex(array $tableQuery, string $isActive, string $st
|
|||||||
$query->whereHas('prices', fn (Builder $priceQuery) => $priceQuery->where('stock', '<=', 0));
|
$query->whereHas('prices', fn (Builder $priceQuery) => $priceQuery->where('stock', '<=', 0));
|
||||||
})
|
})
|
||||||
->when($stockStatus === 'low_stock', function (Builder $query): void {
|
->when($stockStatus === 'low_stock', function (Builder $query): void {
|
||||||
$minStock = [
|
$query->where(function (Builder $query): void {
|
||||||
RawMaterialUnit::YARD->value => 20,
|
$query->where('unit', RawMaterialUnit::YARD->value)
|
||||||
RawMaterialUnit::METER->value => 10,
|
->whereHas('prices', fn (Builder $q) => $q->where('stock', '>', 0)->where('stock', '<', 20));
|
||||||
RawMaterialUnit::KILOGRAM->value => 5,
|
})->orWhere(function (Builder $query): void {
|
||||||
];
|
$query->where('unit', RawMaterialUnit::METER->value)
|
||||||
|
->whereHas('prices', fn (Builder $q) => $q->where('stock', '>', 0)->where('stock', '<', 10));
|
||||||
$query->whereHas('prices', function (Builder $priceQuery) use ($minStock): void {
|
})->orWhere(function (Builder $query): void {
|
||||||
$priceQuery->where('stock', '>', 0)->where(function (Builder $priceQuery) use ($minStock): void {
|
$query->where('unit', RawMaterialUnit::KILOGRAM->value)
|
||||||
foreach (RawMaterialUnit::cases() as $unit) {
|
->whereHas('prices', fn (Builder $q) => $q->where('stock', '>', 0)->where('stock', '<', 5));
|
||||||
$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]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -274,9 +286,6 @@ private function applyDeleteSubject(RawMaterial $rawMaterial): void
|
|||||||
{
|
{
|
||||||
$this->runInTransaction(
|
$this->runInTransaction(
|
||||||
function () use ($rawMaterial): void {
|
function () use ($rawMaterial): void {
|
||||||
$rawMaterial->prices()->each(function (RawMaterialPrice $price): void {
|
|
||||||
$price->clearMediaCollection('images');
|
|
||||||
});
|
|
||||||
$rawMaterial->prices()->delete();
|
$rawMaterial->prices()->delete();
|
||||||
$rawMaterial->delete();
|
$rawMaterial->delete();
|
||||||
},
|
},
|
||||||
@ -328,7 +337,6 @@ private function applyPayloadToRawMaterial(
|
|||||||
->whereNotIn('id', $submittedPriceIds)
|
->whereNotIn('id', $submittedPriceIds)
|
||||||
->get()
|
->get()
|
||||||
->each(function (RawMaterialPrice $price): void {
|
->each(function (RawMaterialPrice $price): void {
|
||||||
$price->clearMediaCollection('images');
|
|
||||||
$price->delete();
|
$price->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -374,9 +382,6 @@ private function rejectCreate(OwnerVerificationRequest $verificationRequest): vo
|
|||||||
|
|
||||||
$this->runInTransaction(
|
$this->runInTransaction(
|
||||||
function () use ($rawMaterial): void {
|
function () use ($rawMaterial): void {
|
||||||
$rawMaterial->prices()->each(function (RawMaterialPrice $price): void {
|
|
||||||
$price->clearMediaCollection('images');
|
|
||||||
});
|
|
||||||
$rawMaterial->prices()->delete();
|
$rawMaterial->prices()->delete();
|
||||||
$rawMaterial->delete();
|
$rawMaterial->delete();
|
||||||
},
|
},
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -87,6 +87,8 @@ public function create(array $validated): void
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->cacheForget('system:permissions');
|
||||||
|
$this->cacheForget('system:assignable_roles');
|
||||||
$this->cacheForgetByPattern('system:roles:*');
|
$this->cacheForgetByPattern('system:roles:*');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +116,8 @@ public function update(Role $role, array $validated): void
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->cacheForget('system:permissions');
|
||||||
|
$this->cacheForget('system:assignable_roles');
|
||||||
$this->cacheForgetByPattern('system:roles:*');
|
$this->cacheForgetByPattern('system:roles:*');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +125,8 @@ public function delete(Role $role): void
|
|||||||
{
|
{
|
||||||
$role->delete();
|
$role->delete();
|
||||||
|
|
||||||
|
$this->cacheForget('system:permissions');
|
||||||
|
$this->cacheForget('system:assignable_roles');
|
||||||
$this->cacheForgetByPattern('system:roles:*');
|
$this->cacheForgetByPattern('system:roles:*');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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