refactor: implement error handling and logging in various service methods to enhance transaction safety and improve code robustness
This commit is contained in:
parent
d19bd8000a
commit
58ba7512a5
@ -5,6 +5,8 @@
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class ProfileService
|
class ProfileService
|
||||||
{
|
{
|
||||||
@ -13,6 +15,7 @@ class ProfileService
|
|||||||
*/
|
*/
|
||||||
public function update(array $validated, User $user): void
|
public function update(array $validated, User $user): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($user, $validated): void {
|
DB::transaction(function () use ($user, $validated): void {
|
||||||
$user->update([
|
$user->update([
|
||||||
'email' => $validated['email'],
|
'email' => $validated['email'],
|
||||||
@ -30,6 +33,17 @@ public function update(array $validated, User $user): void
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal memperbarui profil: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class CashService
|
class CashService
|
||||||
@ -71,6 +72,7 @@ public function paginateForIndex(CashAccount $cashAccount, array $tableQuery, st
|
|||||||
*/
|
*/
|
||||||
public function deposit(CashAccount $cashAccount, array $validated, User $user): CashTransaction
|
public function deposit(CashAccount $cashAccount, array $validated, User $user): CashTransaction
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$transaction = DB::transaction(function () use ($cashAccount, $validated, $user): CashTransaction {
|
$transaction = DB::transaction(function () use ($cashAccount, $validated, $user): CashTransaction {
|
||||||
$account = CashAccount::query()->lockForUpdate()->findOrFail($cashAccount->id);
|
$account = CashAccount::query()->lockForUpdate()->findOrFail($cashAccount->id);
|
||||||
$amount = (int) $validated['amount'];
|
$amount = (int) $validated['amount'];
|
||||||
@ -92,6 +94,17 @@ public function deposit(CashAccount $cashAccount, array $validated, User $user):
|
|||||||
|
|
||||||
return $transaction;
|
return $transaction;
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal melakukan setoran kas: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'💰 Setoran Kas',
|
'💰 Setoran Kas',
|
||||||
@ -108,6 +121,7 @@ public function deposit(CashAccount $cashAccount, array $validated, User $user):
|
|||||||
*/
|
*/
|
||||||
public function withdraw(CashAccount $cashAccount, array $validated, User $user): CashTransaction
|
public function withdraw(CashAccount $cashAccount, array $validated, User $user): CashTransaction
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$transaction = DB::transaction(function () use ($cashAccount, $validated, $user): CashTransaction {
|
$transaction = DB::transaction(function () use ($cashAccount, $validated, $user): CashTransaction {
|
||||||
$account = CashAccount::query()->lockForUpdate()->findOrFail($cashAccount->id);
|
$account = CashAccount::query()->lockForUpdate()->findOrFail($cashAccount->id);
|
||||||
$amount = (int) $validated['amount'];
|
$amount = (int) $validated['amount'];
|
||||||
@ -136,6 +150,17 @@ public function withdraw(CashAccount $cashAccount, array $validated, User $user)
|
|||||||
|
|
||||||
return $transaction;
|
return $transaction;
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal melakukan tarik kas: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'🏦 Tarik Kas',
|
'🏦 Tarik Kas',
|
||||||
@ -154,6 +179,7 @@ public function recordOutgoing(
|
|||||||
User $user,
|
User $user,
|
||||||
?CashAccount $cashAccount = null,
|
?CashAccount $cashAccount = null,
|
||||||
): CashTransaction {
|
): CashTransaction {
|
||||||
|
try {
|
||||||
return DB::transaction(function () use ($reference, $amount, $description, $user, $cashAccount): CashTransaction {
|
return DB::transaction(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,
|
||||||
@ -184,6 +210,17 @@ public function recordOutgoing(
|
|||||||
|
|
||||||
return $transaction;
|
return $transaction;
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal mencatat transaksi keluar kas: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function recordIncoming(
|
public function recordIncoming(
|
||||||
@ -193,6 +230,7 @@ public function recordIncoming(
|
|||||||
User $user,
|
User $user,
|
||||||
?CashAccount $cashAccount = null,
|
?CashAccount $cashAccount = null,
|
||||||
): CashTransaction {
|
): CashTransaction {
|
||||||
|
try {
|
||||||
return DB::transaction(function () use ($reference, $amount, $description, $user, $cashAccount): CashTransaction {
|
return DB::transaction(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,
|
||||||
@ -217,6 +255,17 @@ public function recordIncoming(
|
|||||||
|
|
||||||
return $transaction;
|
return $transaction;
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal mencatat transaksi masuk kas: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -226,6 +275,7 @@ public function updateDeposit(CashTransaction $transaction, array $validated): v
|
|||||||
{
|
{
|
||||||
$this->ensureEditable($transaction);
|
$this->ensureEditable($transaction);
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($transaction, $validated): void {
|
DB::transaction(function () use ($transaction, $validated): void {
|
||||||
CashAccount::query()->lockForUpdate()->findOrFail($transaction->cash_account_id);
|
CashAccount::query()->lockForUpdate()->findOrFail($transaction->cash_account_id);
|
||||||
|
|
||||||
@ -245,6 +295,17 @@ public function updateDeposit(CashTransaction $transaction, array $validated): v
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal memperbarui setoran kas: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'✏️ Transaksi Kas Diperbarui',
|
'✏️ Transaksi Kas Diperbarui',
|
||||||
@ -258,6 +319,7 @@ public function deleteTransaction(CashTransaction $transaction): void
|
|||||||
{
|
{
|
||||||
$this->ensureEditable($transaction);
|
$this->ensureEditable($transaction);
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($transaction): void {
|
DB::transaction(function () use ($transaction): void {
|
||||||
CashAccount::query()->lockForUpdate()->findOrFail($transaction->cash_account_id);
|
CashAccount::query()->lockForUpdate()->findOrFail($transaction->cash_account_id);
|
||||||
|
|
||||||
@ -274,6 +336,17 @@ public function deleteTransaction(CashTransaction $transaction): void
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menghapus transaksi kas: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'🗑️ Transaksi Kas Dihapus',
|
'🗑️ Transaksi Kas Dihapus',
|
||||||
@ -288,6 +361,7 @@ public function updateReferencedTransaction(
|
|||||||
int $amount,
|
int $amount,
|
||||||
string $description,
|
string $description,
|
||||||
): void {
|
): void {
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($transaction, $amount, $description): void {
|
DB::transaction(function () use ($transaction, $amount, $description): void {
|
||||||
CashAccount::query()->lockForUpdate()->findOrFail($transaction->cash_account_id);
|
CashAccount::query()->lockForUpdate()->findOrFail($transaction->cash_account_id);
|
||||||
|
|
||||||
@ -305,10 +379,22 @@ public function updateReferencedTransaction(
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal memperbarui transaksi kas referensi: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteReferencedTransaction(CashTransaction $transaction): void
|
public function deleteReferencedTransaction(CashTransaction $transaction): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($transaction): void {
|
DB::transaction(function () use ($transaction): void {
|
||||||
CashAccount::query()->lockForUpdate()->findOrFail($transaction->cash_account_id);
|
CashAccount::query()->lockForUpdate()->findOrFail($transaction->cash_account_id);
|
||||||
$account = $transaction->cashAccount;
|
$account = $transaction->cashAccount;
|
||||||
@ -323,6 +409,17 @@ public function deleteReferencedTransaction(CashTransaction $transaction): void
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menghapus transaksi kas referensi: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -11,6 +11,8 @@
|
|||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class EmployeeAdvanceService
|
class EmployeeAdvanceService
|
||||||
{
|
{
|
||||||
@ -86,8 +88,16 @@ public function create(array $validated, User $user): void
|
|||||||
'status' => EmployeeAdvanceStatus::PENDING,
|
'status' => EmployeeAdvanceStatus::PENDING,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
} catch (\Throwable $e) {
|
} catch (ValidationException $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal membuat pengajuan kasbon: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
@ -111,8 +121,16 @@ public function update(EmployeeAdvance $employeeAdvance, array $validated, User
|
|||||||
'due_date' => $validated['due_date'],
|
'due_date' => $validated['due_date'],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
} catch (\Throwable $e) {
|
} catch (ValidationException $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal memperbarui kasbon: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
@ -163,8 +181,16 @@ public function approve(EmployeeAdvance $employeeAdvance, User $user): void
|
|||||||
'verified_by_id' => $user->id,
|
'verified_by_id' => $user->id,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
} catch (\Throwable $e) {
|
} catch (ValidationException $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menyetujui kasbon: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$employeeAdvance->loadMissing('employee.user');
|
$employeeAdvance->loadMissing('employee.user');
|
||||||
@ -193,8 +219,16 @@ public function reject(EmployeeAdvance $employeeAdvance, string $reason, User $u
|
|||||||
'rejected_by_id' => $user->id,
|
'rejected_by_id' => $user->id,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
} catch (\Throwable $e) {
|
} catch (ValidationException $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menolak kasbon: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$employeeAdvance->loadMissing('employee.user');
|
$employeeAdvance->loadMissing('employee.user');
|
||||||
@ -233,8 +267,16 @@ public function pay(EmployeeAdvance $employeeAdvance, User $user): void
|
|||||||
'status' => EmployeeAdvanceStatus::PAID,
|
'status' => EmployeeAdvanceStatus::PAID,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
} catch (\Throwable $e) {
|
} catch (ValidationException $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal melunasi kasbon: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,8 @@
|
|||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class ExpenseService
|
class ExpenseService
|
||||||
{
|
{
|
||||||
@ -55,6 +57,7 @@ public function paginateForIndex(array $tableQuery): LengthAwarePaginator
|
|||||||
*/
|
*/
|
||||||
public function create(array $validated, User $user): void
|
public function create(array $validated, User $user): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$expense = DB::transaction(function () use ($validated, $user): Expense {
|
$expense = DB::transaction(function () use ($validated, $user): Expense {
|
||||||
$amount = (int) $validated['amount'];
|
$amount = (int) $validated['amount'];
|
||||||
$description = $validated['description'];
|
$description = $validated['description'];
|
||||||
@ -80,6 +83,17 @@ public function create(array $validated, User $user): void
|
|||||||
|
|
||||||
return $expense;
|
return $expense;
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal membuat pengeluaran: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'💸 Pengeluaran Baru',
|
'💸 Pengeluaran Baru',
|
||||||
@ -94,6 +108,7 @@ public function create(array $validated, User $user): void
|
|||||||
*/
|
*/
|
||||||
public function update(Expense $expense, array $validated): void
|
public function update(Expense $expense, array $validated): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($expense, $validated): void {
|
DB::transaction(function () use ($expense, $validated): void {
|
||||||
$amount = (int) $validated['amount'];
|
$amount = (int) $validated['amount'];
|
||||||
$description = $validated['description'];
|
$description = $validated['description'];
|
||||||
@ -113,6 +128,17 @@ public function update(Expense $expense, array $validated): void
|
|||||||
|
|
||||||
$this->syncPhotos($expense, $validated);
|
$this->syncPhotos($expense, $validated);
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal memperbarui pengeluaran: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'✏️ Pengeluaran Diperbarui',
|
'✏️ Pengeluaran Diperbarui',
|
||||||
@ -124,6 +150,7 @@ public function update(Expense $expense, array $validated): void
|
|||||||
|
|
||||||
public function delete(Expense $expense): void
|
public function delete(Expense $expense): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($expense): void {
|
DB::transaction(function () use ($expense): void {
|
||||||
if ($expense->cashTransaction) {
|
if ($expense->cashTransaction) {
|
||||||
$this->cashService->deleteReferencedTransaction($expense->cashTransaction);
|
$this->cashService->deleteReferencedTransaction($expense->cashTransaction);
|
||||||
@ -132,6 +159,17 @@ public function delete(Expense $expense): void
|
|||||||
$expense->clearMediaCollection('photos');
|
$expense->clearMediaCollection('photos');
|
||||||
$expense->delete();
|
$expense->delete();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menghapus pengeluaran: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'🗑️ Pengeluaran Dihapus',
|
'🗑️ Pengeluaran Dihapus',
|
||||||
|
|||||||
@ -19,6 +19,8 @@
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class PayrollService
|
class PayrollService
|
||||||
{
|
{
|
||||||
@ -115,6 +117,7 @@ public function openCurrentPeriod(?User $closedBy = null): PayrollPeriod
|
|||||||
?? User::query()->whereHas('roles', fn (Builder $roleQuery) => $roleQuery->whereIn('name', [Role::DEVELOPER->value, Role::OWNER->value]))->first()
|
?? User::query()->whereHas('roles', fn (Builder $roleQuery) => $roleQuery->whereIn('name', [Role::DEVELOPER->value, Role::OWNER->value]))->first()
|
||||||
?? User::query()->first();
|
?? User::query()->first();
|
||||||
|
|
||||||
|
try {
|
||||||
$period = DB::transaction(function () use ($user): PayrollPeriod {
|
$period = DB::transaction(function () use ($user): PayrollPeriod {
|
||||||
$now = now();
|
$now = now();
|
||||||
$year = $now->year;
|
$year = $now->year;
|
||||||
@ -164,6 +167,17 @@ public function openCurrentPeriod(?User $closedBy = null): PayrollPeriod
|
|||||||
|
|
||||||
return $period->fresh();
|
return $period->fresh();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal membuka periode payroll: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return $period;
|
return $period;
|
||||||
}
|
}
|
||||||
@ -204,6 +218,7 @@ public function generatePayrollsForPeriod(PayrollPeriod $period): void
|
|||||||
public function addAdjustment(Payroll $payroll, array $validated, User $user): void
|
public function addAdjustment(Payroll $payroll, array $validated, User $user): void
|
||||||
{
|
{
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($payroll, $validated, $user): void {
|
DB::transaction(function () use ($payroll, $validated, $user): void {
|
||||||
$payroll->adjustments()->create([
|
$payroll->adjustments()->create([
|
||||||
'type' => PayrollAdjustmentType::from($validated['type']),
|
'type' => PayrollAdjustmentType::from($validated['type']),
|
||||||
@ -216,6 +231,17 @@ public function addAdjustment(Payroll $payroll, array $validated, User $user): v
|
|||||||
$payroll->recalculateAmounts();
|
$payroll->recalculateAmounts();
|
||||||
$payroll->save();
|
$payroll->save();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menambahkan penyesuaian gaji: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($payroll->employee?->user_id) {
|
if ($payroll->employee?->user_id) {
|
||||||
$typeLabel = PayrollAdjustmentType::from($validated['type'])->label();
|
$typeLabel = PayrollAdjustmentType::from($validated['type'])->label();
|
||||||
@ -234,6 +260,7 @@ public function updateAdjustment(PayrollAdjustment $adjustment, array $validated
|
|||||||
$payroll = $adjustment->payroll;
|
$payroll = $adjustment->payroll;
|
||||||
$payroll->loadMissing(['payrollPeriod', 'employee.user']);
|
$payroll->loadMissing(['payrollPeriod', 'employee.user']);
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($payroll, $adjustment, $validated): void {
|
DB::transaction(function () use ($payroll, $adjustment, $validated): void {
|
||||||
$adjustment->type = PayrollAdjustmentType::from($validated['type']);
|
$adjustment->type = PayrollAdjustmentType::from($validated['type']);
|
||||||
$adjustment->amount = (int) $validated['amount'];
|
$adjustment->amount = (int) $validated['amount'];
|
||||||
@ -244,6 +271,17 @@ public function updateAdjustment(PayrollAdjustment $adjustment, array $validated
|
|||||||
$payroll->recalculateAmounts();
|
$payroll->recalculateAmounts();
|
||||||
$payroll->save();
|
$payroll->save();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal memperbarui penyesuaian gaji: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($payroll->employee?->user_id) {
|
if ($payroll->employee?->user_id) {
|
||||||
$typeLabel = PayrollAdjustmentType::from($validated['type'])->label();
|
$typeLabel = PayrollAdjustmentType::from($validated['type'])->label();
|
||||||
@ -262,6 +300,7 @@ public function deleteAdjustment(PayrollAdjustment $adjustment): void
|
|||||||
$payroll = $adjustment->payroll;
|
$payroll = $adjustment->payroll;
|
||||||
$payroll->loadMissing(['payrollPeriod', 'employee.user']);
|
$payroll->loadMissing(['payrollPeriod', 'employee.user']);
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($payroll, $adjustment): void {
|
DB::transaction(function () use ($payroll, $adjustment): void {
|
||||||
$adjustment->delete();
|
$adjustment->delete();
|
||||||
|
|
||||||
@ -269,6 +308,17 @@ public function deleteAdjustment(PayrollAdjustment $adjustment): void
|
|||||||
$payroll->recalculateAmounts();
|
$payroll->recalculateAmounts();
|
||||||
$payroll->save();
|
$payroll->save();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menghapus penyesuaian gaji: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($payroll->employee?->user_id) {
|
if ($payroll->employee?->user_id) {
|
||||||
$this->pushNotificationService->sendToUser(
|
$this->pushNotificationService->sendToUser(
|
||||||
@ -285,6 +335,7 @@ public function pay(Payroll $payroll, User $user): void
|
|||||||
$payroll->loadMissing(['payrollPeriod', 'employee.user.profile']);
|
$payroll->loadMissing(['payrollPeriod', 'employee.user.profile']);
|
||||||
|
|
||||||
if ($payroll->total_amount <= 0) {
|
if ($payroll->total_amount <= 0) {
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($payroll, $user): void {
|
DB::transaction(function () use ($payroll, $user): void {
|
||||||
$payroll->status = PayrollStatus::PAID;
|
$payroll->status = PayrollStatus::PAID;
|
||||||
$payroll->paid_at = now();
|
$payroll->paid_at = now();
|
||||||
@ -293,10 +344,22 @@ public function pay(Payroll $payroll, User $user): void
|
|||||||
|
|
||||||
$this->settleKasbonFromPayroll($payroll, $user);
|
$this->settleKasbonFromPayroll($payroll, $user);
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal membayar gaji (total 0): '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($payroll, $user): void {
|
DB::transaction(function () use ($payroll, $user): void {
|
||||||
$description = sprintf(
|
$description = sprintf(
|
||||||
'Pembayaran gaji: %s (%s)',
|
'Pembayaran gaji: %s (%s)',
|
||||||
@ -319,6 +382,17 @@ public function pay(Payroll $payroll, User $user): void
|
|||||||
|
|
||||||
$this->settleKasbonFromPayroll($payroll, $user);
|
$this->settleKasbonFromPayroll($payroll, $user);
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal membayar gaji: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($payroll->employee?->user_id) {
|
if ($payroll->employee?->user_id) {
|
||||||
$this->pushNotificationService->sendToUser(
|
$this->pushNotificationService->sendToUser(
|
||||||
|
|||||||
@ -10,6 +10,8 @@
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class EmployeeService
|
class EmployeeService
|
||||||
{
|
{
|
||||||
@ -56,6 +58,7 @@ public function paginateForIndex(
|
|||||||
*/
|
*/
|
||||||
public function create(array $validated): void
|
public function create(array $validated): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($validated): void {
|
DB::transaction(function () use ($validated): void {
|
||||||
$user = User::create([
|
$user = User::create([
|
||||||
'email' => $validated['email'],
|
'email' => $validated['email'],
|
||||||
@ -83,6 +86,17 @@ public function create(array $validated): void
|
|||||||
|
|
||||||
$user->syncRoles([$validated['role']]);
|
$user->syncRoles([$validated['role']]);
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal membuat karyawan: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,6 +106,7 @@ public function update(User $user, array $validated): void
|
|||||||
{
|
{
|
||||||
$employee = $user->employee;
|
$employee = $user->employee;
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($validated, $user, $employee): void {
|
DB::transaction(function () use ($validated, $user, $employee): void {
|
||||||
$user->update([
|
$user->update([
|
||||||
'email' => $validated['email'],
|
'email' => $validated['email'],
|
||||||
@ -134,6 +149,17 @@ public function update(User $user, array $validated): void
|
|||||||
|
|
||||||
$user->syncRoles([$validated['role']]);
|
$user->syncRoles([$validated['role']]);
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal memperbarui karyawan: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toggleStatus(User $user, array $validated): void
|
public function toggleStatus(User $user, array $validated): void
|
||||||
@ -158,11 +184,23 @@ public function resetPassword(User $user): void
|
|||||||
|
|
||||||
public function delete(User $user): void
|
public function delete(User $user): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($user): void {
|
DB::transaction(function () use ($user): void {
|
||||||
$user->employee?->delete();
|
$user->employee?->delete();
|
||||||
$user->profile?->delete();
|
$user->profile?->delete();
|
||||||
$user->delete();
|
$user->delete();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menghapus karyawan: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function applySorting(Builder $query, string $sort, string $direction): void
|
private function applySorting(Builder $query, string $sort, string $direction): void
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class LeaveRequestService
|
class LeaveRequestService
|
||||||
@ -128,6 +129,7 @@ public function delete(LeaveRequest $leaveRequest): void
|
|||||||
|
|
||||||
public function approve(LeaveRequest $leaveRequest, User $user): void
|
public function approve(LeaveRequest $leaveRequest, User $user): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($leaveRequest, $user): void {
|
DB::transaction(function () use ($leaveRequest, $user): void {
|
||||||
$leaveRequest->update([
|
$leaveRequest->update([
|
||||||
'status' => LeaveRequestStatus::APPROVED,
|
'status' => LeaveRequestStatus::APPROVED,
|
||||||
@ -135,6 +137,17 @@ public function approve(LeaveRequest $leaveRequest, User $user): void
|
|||||||
'verified_by_id' => $user->id,
|
'verified_by_id' => $user->id,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menyetujui pengajuan cuti: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$leaveRequest->loadMissing('employee.user');
|
$leaveRequest->loadMissing('employee.user');
|
||||||
if ($leaveRequest->employee?->user_id) {
|
if ($leaveRequest->employee?->user_id) {
|
||||||
@ -149,6 +162,7 @@ public function approve(LeaveRequest $leaveRequest, User $user): void
|
|||||||
|
|
||||||
public function reject(LeaveRequest $leaveRequest, string $reason, User $user): void
|
public function reject(LeaveRequest $leaveRequest, string $reason, User $user): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($leaveRequest, $user, $reason): void {
|
DB::transaction(function () use ($leaveRequest, $user, $reason): void {
|
||||||
$leaveRequest->update([
|
$leaveRequest->update([
|
||||||
'status' => LeaveRequestStatus::REJECTED,
|
'status' => LeaveRequestStatus::REJECTED,
|
||||||
@ -161,6 +175,17 @@ public function reject(LeaveRequest $leaveRequest, string $reason, User $user):
|
|||||||
'rejected_by_id' => $user->id,
|
'rejected_by_id' => $user->id,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menolak pengajuan cuti: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$leaveRequest->loadMissing('employee.user');
|
$leaveRequest->loadMissing('employee.user');
|
||||||
if ($leaveRequest->employee?->user_id) {
|
if ($leaveRequest->employee?->user_id) {
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class CuttingService
|
class CuttingService
|
||||||
@ -422,6 +423,7 @@ public function removeDraftResult(User $user, ProductVariant $productVariant): v
|
|||||||
*/
|
*/
|
||||||
public function create(array $validated, User $user): Cutting
|
public function create(array $validated, User $user): Cutting
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$cutting = DB::transaction(function () use ($validated, $user): Cutting {
|
$cutting = DB::transaction(function () use ($validated, $user): Cutting {
|
||||||
/** @var EloquentCollection<int, CuttingMaterial> $draftMaterials */
|
/** @var EloquentCollection<int, CuttingMaterial> $draftMaterials */
|
||||||
$draftMaterials = $this->draftMaterialsQuery($user)
|
$draftMaterials = $this->draftMaterialsQuery($user)
|
||||||
@ -471,6 +473,17 @@ public function create(array $validated, User $user): Cutting
|
|||||||
|
|
||||||
return $cutting;
|
return $cutting;
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal membuat proses cutting: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'✂️ Proses Cutting Baru',
|
'✂️ Proses Cutting Baru',
|
||||||
@ -493,6 +506,7 @@ public function update(Cutting $cutting, array $validated): void
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($cutting, $validated): void {
|
DB::transaction(function () use ($cutting, $validated): void {
|
||||||
$cutting->load(['materials.rawMaterialPrice.rawMaterial', 'results']);
|
$cutting->load(['materials.rawMaterialPrice.rawMaterial', 'results']);
|
||||||
|
|
||||||
@ -530,6 +544,17 @@ public function update(Cutting $cutting, array $validated): void
|
|||||||
$this->deductMaterialStock($cutting);
|
$this->deductMaterialStock($cutting);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal memperbarui proses cutting: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$description = $cutting->description ?? '-';
|
$description = $cutting->description ?? '-';
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
@ -550,6 +575,7 @@ public function delete(Cutting $cutting): void
|
|||||||
|
|
||||||
$description = $cutting->description ?? '-';
|
$description = $cutting->description ?? '-';
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($cutting): void {
|
DB::transaction(function () use ($cutting): void {
|
||||||
$cutting->load(['materials.rawMaterialPrice.rawMaterial']);
|
$cutting->load(['materials.rawMaterialPrice.rawMaterial']);
|
||||||
|
|
||||||
@ -563,6 +589,17 @@ public function delete(Cutting $cutting): void
|
|||||||
$cutting->results()->delete();
|
$cutting->results()->delete();
|
||||||
$cutting->delete();
|
$cutting->delete();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menghapus proses cutting: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'🗑️ Proses Cutting Dihapus',
|
'🗑️ Proses Cutting Dihapus',
|
||||||
@ -587,6 +624,7 @@ public function transitionStatus(
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($cutting, $status, $verificationNote, $results, $resultPrices, $user, $reason): void {
|
DB::transaction(function () use ($cutting, $status, $verificationNote, $results, $resultPrices, $user, $reason): void {
|
||||||
$cutting->load(['materials.rawMaterialPrice', 'results']);
|
$cutting->load(['materials.rawMaterialPrice', 'results']);
|
||||||
|
|
||||||
@ -629,6 +667,17 @@ public function transitionStatus(
|
|||||||
$cutting->status = $status;
|
$cutting->status = $status;
|
||||||
$cutting->save();
|
$cutting->save();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal mengubah status proses cutting: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$description = $cutting->description ?? '-';
|
$description = $cutting->description ?? '-';
|
||||||
$message = match ($status) {
|
$message = match ($status) {
|
||||||
|
|||||||
@ -23,6 +23,7 @@
|
|||||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class OrderService
|
class OrderService
|
||||||
@ -397,6 +398,7 @@ public function resyncDraftPrices(User $user, string $priceTypeValue): array
|
|||||||
*/
|
*/
|
||||||
public function create(array $validated, User $user): Order
|
public function create(array $validated, User $user): Order
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$order = DB::transaction(function () use ($validated, $user): Order {
|
$order = DB::transaction(function () use ($validated, $user): Order {
|
||||||
$priceType = $this->resolvePriceType($validated['channel'], $validated['price_type']);
|
$priceType = $this->resolvePriceType($validated['channel'], $validated['price_type']);
|
||||||
|
|
||||||
@ -478,6 +480,17 @@ public function create(array $validated, User $user): Order
|
|||||||
|
|
||||||
return $order;
|
return $order;
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal membuat pesanan: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'📦 Pesanan Baru',
|
'📦 Pesanan Baru',
|
||||||
@ -500,6 +513,7 @@ public function update(Order $order, array $validated): void
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($order, $validated): void {
|
DB::transaction(function () use ($order, $validated): void {
|
||||||
$order->load('items');
|
$order->load('items');
|
||||||
|
|
||||||
@ -558,6 +572,17 @@ public function update(Order $order, array $validated): void
|
|||||||
$this->decrementStock($orderItem);
|
$this->decrementStock($orderItem);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal memperbarui pesanan: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'✏️ Pesanan Diperbarui',
|
'✏️ Pesanan Diperbarui',
|
||||||
@ -572,6 +597,7 @@ public function delete(Order $order): void
|
|||||||
$orderNumber = $order->order_number;
|
$orderNumber = $order->order_number;
|
||||||
$totalAmount = $order->total_amount;
|
$totalAmount = $order->total_amount;
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($order): void {
|
DB::transaction(function () use ($order): void {
|
||||||
$order->load('items');
|
$order->load('items');
|
||||||
|
|
||||||
@ -588,6 +614,17 @@ public function delete(Order $order): void
|
|||||||
$order->items()->delete();
|
$order->items()->delete();
|
||||||
$order->delete();
|
$order->delete();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menghapus pesanan: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'🗑️ Pesanan Dihapus',
|
'🗑️ Pesanan Dihapus',
|
||||||
@ -605,6 +642,7 @@ public function transitionStatus(Order $order, OrderStatus $status): void
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($order, $status): void {
|
DB::transaction(function () use ($order, $status): void {
|
||||||
if ($status === OrderStatus::CANCELLED) {
|
if ($status === OrderStatus::CANCELLED) {
|
||||||
$order->load('items');
|
$order->load('items');
|
||||||
@ -622,6 +660,17 @@ public function transitionStatus(Order $order, OrderStatus $status): void
|
|||||||
$order->status = $status;
|
$order->status = $status;
|
||||||
$order->save();
|
$order->save();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal mengubah status pesanan: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'📦 Status Pesanan Diubah',
|
'📦 Status Pesanan Diubah',
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class PurchaseService
|
class PurchaseService
|
||||||
@ -209,6 +210,7 @@ public function removeDraftItem(User $user, RawMaterialPrice $rawMaterialPrice):
|
|||||||
*/
|
*/
|
||||||
public function create(array $validated, User $user): Purchase
|
public function create(array $validated, User $user): Purchase
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$purchase = DB::transaction(function () use ($validated, $user): Purchase {
|
$purchase = DB::transaction(function () use ($validated, $user): Purchase {
|
||||||
/** @var EloquentCollection<int, PurchaseItem> $draftItems */
|
/** @var EloquentCollection<int, PurchaseItem> $draftItems */
|
||||||
$draftItems = $this->draftItemsQuery($user)
|
$draftItems = $this->draftItemsQuery($user)
|
||||||
@ -247,6 +249,17 @@ public function create(array $validated, User $user): Purchase
|
|||||||
|
|
||||||
return $purchase;
|
return $purchase;
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal membuat pembelian: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$purchase->load('supplier');
|
$purchase->load('supplier');
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
@ -264,6 +277,7 @@ public function create(array $validated, User $user): Purchase
|
|||||||
*/
|
*/
|
||||||
public function update(Purchase $purchase, array $validated): void
|
public function update(Purchase $purchase, array $validated): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($purchase, $validated): void {
|
DB::transaction(function () use ($purchase, $validated): void {
|
||||||
$purchase->load('items');
|
$purchase->load('items');
|
||||||
|
|
||||||
@ -295,6 +309,17 @@ public function update(Purchase $purchase, array $validated): void
|
|||||||
|
|
||||||
$this->syncPhotos($purchase, $validated);
|
$this->syncPhotos($purchase, $validated);
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal memperbarui pembelian: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$purchase->load('supplier');
|
$purchase->load('supplier');
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
@ -309,6 +334,7 @@ public function delete(Purchase $purchase): void
|
|||||||
{
|
{
|
||||||
$supplierName = $purchase->supplier->name;
|
$supplierName = $purchase->supplier->name;
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($purchase): void {
|
DB::transaction(function () use ($purchase): void {
|
||||||
$purchase->load('items');
|
$purchase->load('items');
|
||||||
|
|
||||||
@ -320,6 +346,17 @@ public function delete(Purchase $purchase): void
|
|||||||
$purchase->items()->delete();
|
$purchase->items()->delete();
|
||||||
$purchase->delete();
|
$purchase->delete();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menghapus pembelian: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
'🗑️ Belanja Dihapus',
|
'🗑️ Belanja Dihapus',
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
use App\Services\System\PushNotificationService;
|
use App\Services\System\PushNotificationService;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class StockService
|
class StockService
|
||||||
@ -85,6 +86,7 @@ public function submitVerification(
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($cutting, $user, $verificationNote, $results, $resultPrices): void {
|
DB::transaction(function () use ($cutting, $user, $verificationNote, $results, $resultPrices): void {
|
||||||
$cutting->load(['materials.rawMaterialPrice', 'results']);
|
$cutting->load(['materials.rawMaterialPrice', 'results']);
|
||||||
|
|
||||||
@ -113,6 +115,17 @@ public function submitVerification(
|
|||||||
$cutting->status = CuttingStatus::PENDING_VERIFICATION;
|
$cutting->status = CuttingStatus::PENDING_VERIFICATION;
|
||||||
$cutting->save();
|
$cutting->save();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal mengajukan verifikasi stok: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$description = $cutting->description ?? '-';
|
$description = $cutting->description ?? '-';
|
||||||
|
|
||||||
@ -138,6 +151,7 @@ public function approveVerification(
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($cutting, $user, $approvalNote): void {
|
DB::transaction(function () use ($cutting, $user, $approvalNote): void {
|
||||||
$cutting->load(['materials.rawMaterialPrice', 'results', 'resultPrices']);
|
$cutting->load(['materials.rawMaterialPrice', 'results', 'resultPrices']);
|
||||||
|
|
||||||
@ -154,6 +168,17 @@ public function approveVerification(
|
|||||||
$cutting->status = CuttingStatus::VERIFIED;
|
$cutting->status = CuttingStatus::VERIFIED;
|
||||||
$cutting->save();
|
$cutting->save();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menyetujui verifikasi stok: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$description = $cutting->description ?? '-';
|
$description = $cutting->description ?? '-';
|
||||||
|
|
||||||
@ -179,6 +204,7 @@ public function rejectVerification(
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($cutting, $user, $reason): void {
|
DB::transaction(function () use ($cutting, $user, $reason): void {
|
||||||
$cutting->rejection()->create([
|
$cutting->rejection()->create([
|
||||||
'reason' => trim($reason),
|
'reason' => trim($reason),
|
||||||
@ -188,6 +214,17 @@ public function rejectVerification(
|
|||||||
$cutting->status = CuttingStatus::COMPLETED;
|
$cutting->status = CuttingStatus::COMPLETED;
|
||||||
$cutting->save();
|
$cutting->save();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menolak verifikasi stok: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$description = $cutting->description ?? '-';
|
$description = $cutting->description ?? '-';
|
||||||
$this->pushNotificationService->sendToRoles(
|
$this->pushNotificationService->sendToRoles(
|
||||||
|
|||||||
@ -9,6 +9,8 @@
|
|||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class ProductService
|
class ProductService
|
||||||
{
|
{
|
||||||
@ -73,6 +75,7 @@ public function paginateForIndex(array $tableQuery, string $isActive, string $ca
|
|||||||
*/
|
*/
|
||||||
public function create(array $validated): void
|
public function create(array $validated): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($validated): void {
|
DB::transaction(function () use ($validated): void {
|
||||||
$product = Product::create([
|
$product = Product::create([
|
||||||
'name' => $validated['name'],
|
'name' => $validated['name'],
|
||||||
@ -86,6 +89,17 @@ public function create(array $validated): void
|
|||||||
$this->createVariant($product, $variantData, $index);
|
$this->createVariant($product, $variantData, $index);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal membuat produk: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,6 +107,7 @@ public function create(array $validated): void
|
|||||||
*/
|
*/
|
||||||
public function update(Product $product, array $validated): void
|
public function update(Product $product, array $validated): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($validated, $product): void {
|
DB::transaction(function () use ($validated, $product): void {
|
||||||
$product->update([
|
$product->update([
|
||||||
'name' => $validated['name'],
|
'name' => $validated['name'],
|
||||||
@ -130,6 +145,17 @@ public function update(Product $product, array $validated): void
|
|||||||
$this->createVariant($product, $variantData, $index);
|
$this->createVariant($product, $variantData, $index);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal memperbarui produk: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toggleStatus(Product $product, array $validated): void
|
public function toggleStatus(Product $product, array $validated): void
|
||||||
@ -141,6 +167,7 @@ public function toggleStatus(Product $product, array $validated): void
|
|||||||
|
|
||||||
public function delete(Product $product): void
|
public function delete(Product $product): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($product): void {
|
DB::transaction(function () use ($product): void {
|
||||||
$product->variants()->each(function (ProductVariant $variant): void {
|
$product->variants()->each(function (ProductVariant $variant): void {
|
||||||
$variant->clearMediaCollection('images');
|
$variant->clearMediaCollection('images');
|
||||||
@ -149,6 +176,17 @@ public function delete(Product $product): void
|
|||||||
$product->categories()->detach();
|
$product->categories()->detach();
|
||||||
$product->delete();
|
$product->delete();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menghapus produk: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function applySorting(Builder $query, string $sort, string $direction): void
|
private function applySorting(Builder $query, string $sort, string $direction): void
|
||||||
|
|||||||
@ -10,6 +10,8 @@
|
|||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class RawMaterialService
|
class RawMaterialService
|
||||||
{
|
{
|
||||||
@ -82,6 +84,7 @@ public function paginateForIndex(array $tableQuery, string $isActive, string $st
|
|||||||
*/
|
*/
|
||||||
public function create(array $validated): void
|
public function create(array $validated): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($validated): void {
|
DB::transaction(function () use ($validated): void {
|
||||||
$rawMaterial = RawMaterial::create([
|
$rawMaterial = RawMaterial::create([
|
||||||
'name' => $validated['name'],
|
'name' => $validated['name'],
|
||||||
@ -92,6 +95,17 @@ public function create(array $validated): void
|
|||||||
$this->createPrice($rawMaterial, $priceData, $index);
|
$this->createPrice($rawMaterial, $priceData, $index);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal membuat bahan baku: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,6 +113,7 @@ public function create(array $validated): void
|
|||||||
*/
|
*/
|
||||||
public function update(RawMaterial $rawMaterial, array $validated): void
|
public function update(RawMaterial $rawMaterial, array $validated): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($validated, $rawMaterial): void {
|
DB::transaction(function () use ($validated, $rawMaterial): void {
|
||||||
$rawMaterial->update([
|
$rawMaterial->update([
|
||||||
'name' => $validated['name'],
|
'name' => $validated['name'],
|
||||||
@ -134,6 +149,17 @@ public function update(RawMaterial $rawMaterial, array $validated): void
|
|||||||
$this->createPrice($rawMaterial, $priceData, $index);
|
$this->createPrice($rawMaterial, $priceData, $index);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal memperbarui bahan baku: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toggleStatus(RawMaterial $rawMaterial, array $validated): void
|
public function toggleStatus(RawMaterial $rawMaterial, array $validated): void
|
||||||
@ -145,6 +171,7 @@ public function toggleStatus(RawMaterial $rawMaterial, array $validated): void
|
|||||||
|
|
||||||
public function delete(RawMaterial $rawMaterial): void
|
public function delete(RawMaterial $rawMaterial): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($rawMaterial): void {
|
DB::transaction(function () use ($rawMaterial): void {
|
||||||
$rawMaterial->prices()->each(function (RawMaterialPrice $price): void {
|
$rawMaterial->prices()->each(function (RawMaterialPrice $price): void {
|
||||||
$price->clearMediaCollection('images');
|
$price->clearMediaCollection('images');
|
||||||
@ -152,6 +179,17 @@ public function delete(RawMaterial $rawMaterial): void
|
|||||||
$rawMaterial->prices()->delete();
|
$rawMaterial->prices()->delete();
|
||||||
$rawMaterial->delete();
|
$rawMaterial->delete();
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal menghapus bahan baku: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function applySorting(Builder $query, string $sort, string $direction): void
|
private function applySorting(Builder $query, string $sort, string $direction): void
|
||||||
|
|||||||
@ -6,7 +6,9 @@
|
|||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
use Spatie\Permission\Models\Role;
|
use Spatie\Permission\Models\Role;
|
||||||
|
|
||||||
class RoleService
|
class RoleService
|
||||||
@ -31,6 +33,7 @@ public function paginateForIndex(array $tableQuery): LengthAwarePaginator
|
|||||||
|
|
||||||
public function create(array $validated): void
|
public function create(array $validated): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($validated): void {
|
DB::transaction(function () use ($validated): void {
|
||||||
$role = Role::create([
|
$role = Role::create([
|
||||||
'name' => Str::slug($validated['name']),
|
'name' => Str::slug($validated['name']),
|
||||||
@ -41,10 +44,22 @@ public function create(array $validated): void
|
|||||||
$role->syncPermissions($validated['permissions']);
|
$role->syncPermissions($validated['permissions']);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal membuat role: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(Role $role, array $validated): void
|
public function update(Role $role, array $validated): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($role, $validated): void {
|
DB::transaction(function () use ($role, $validated): void {
|
||||||
$updateData = [];
|
$updateData = [];
|
||||||
if (! in_array($role->name, [EnumsRole::DEVELOPER->value, EnumsRole::OWNER->value], true)) {
|
if (! in_array($role->name, [EnumsRole::DEVELOPER->value, EnumsRole::OWNER->value], true)) {
|
||||||
@ -54,6 +69,17 @@ public function update(Role $role, array $validated): void
|
|||||||
|
|
||||||
$role->syncPermissions($validated['permissions'] ?? []);
|
$role->syncPermissions($validated['permissions'] ?? []);
|
||||||
});
|
});
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Gagal memperbarui role: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete(Role $role): void
|
public function delete(Role $role): void
|
||||||
|
|||||||
@ -70,6 +70,7 @@ public function run(): void
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($products, $categories): void {
|
DB::transaction(function () use ($products, $categories): void {
|
||||||
foreach ($products as $productData) {
|
foreach ($products as $productData) {
|
||||||
$product = Product::factory()->create([
|
$product = Product::factory()->create([
|
||||||
@ -94,5 +95,8 @@ public function run(): void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,6 +42,7 @@ public function run(): void
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($rawMaterials): void {
|
DB::transaction(function () use ($rawMaterials): void {
|
||||||
foreach ($rawMaterials as $rawMaterialData) {
|
foreach ($rawMaterials as $rawMaterialData) {
|
||||||
$rawMaterial = RawMaterial::factory()->create([
|
$rawMaterial = RawMaterial::factory()->create([
|
||||||
@ -60,5 +61,8 @@ public function run(): void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user