feat: enhance logging functionality to always include specified fields in update logs
This commit is contained in:
parent
a75fae2233
commit
6a196002fb
@ -442,6 +442,7 @@ public function update(Product $product, array $data): Product
|
||||
module: 'Produk',
|
||||
oldValues: $oldValues,
|
||||
newValues: $this->getProductLogValues($product),
|
||||
alwaysInclude: ['Nama Produk'],
|
||||
);
|
||||
|
||||
return $product;
|
||||
@ -498,7 +499,7 @@ public function toggleStatus(Product $product): void
|
||||
url: route('admin.master.products.index', ['highlight' => $product->id]),
|
||||
);
|
||||
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product));
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product), ['Nama Produk']);
|
||||
}
|
||||
|
||||
public function toggleFeatured(Product $product): void
|
||||
@ -520,7 +521,7 @@ public function toggleFeatured(Product $product): void
|
||||
url: route('admin.master.products.index', ['highlight' => $product->id]),
|
||||
);
|
||||
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product));
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product), ['Nama Produk']);
|
||||
}
|
||||
|
||||
public function approve(Product $product): void
|
||||
@ -539,7 +540,7 @@ public function approve(Product $product): void
|
||||
additionalUser: $product->createdBy ?? null,
|
||||
);
|
||||
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product));
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product), ['Nama Produk']);
|
||||
}
|
||||
|
||||
public function reject(Product $product, string $reason = ''): void
|
||||
@ -559,7 +560,7 @@ public function reject(Product $product, string $reason = ''): void
|
||||
additionalUser: $product->createdBy ?? null,
|
||||
);
|
||||
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product));
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product), ['Nama Produk']);
|
||||
}
|
||||
|
||||
public function resubmit(Product $product): void
|
||||
@ -578,7 +579,7 @@ public function resubmit(Product $product): void
|
||||
url: route('admin.master.products.index', ['highlight' => $product->id]),
|
||||
);
|
||||
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product));
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product), ['Nama Produk']);
|
||||
}
|
||||
|
||||
private function assertNotPending(Product $product): void
|
||||
|
||||
@ -244,7 +244,7 @@ public function update(ProductVariant $variant, array $data): ProductVariant
|
||||
);
|
||||
|
||||
$product = $variant->product()->with(['categories:id,name', 'productVariants.productPrices'])->first();
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product));
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product), ['Nama Produk']);
|
||||
|
||||
return $variant->fresh();
|
||||
}
|
||||
@ -314,7 +314,7 @@ public function transferStock(ProductVariant $variant, array $data): ProductVari
|
||||
);
|
||||
|
||||
$product = $variant->product()->with(['categories:id,name', 'productVariants.productPrices'])->first();
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product));
|
||||
$this->logUpdated($product, 'Produk', $oldValues, $this->getProductLogValues($product), ['Nama Produk']);
|
||||
|
||||
return $variant->fresh();
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ public function update(RawMaterial $rawMaterial, array $data): RawMaterial
|
||||
url: route('admin.master.raw-materials.index', ['highlight' => $rawMaterial->id]),
|
||||
);
|
||||
|
||||
$this->logUpdated($rawMaterial, 'Bahan Baku', $oldValues, $this->getRawMaterialLogValues($rawMaterial));
|
||||
$this->logUpdated($rawMaterial, 'Bahan Baku', $oldValues, $this->getRawMaterialLogValues($rawMaterial), ['Nama Bahan Baku']);
|
||||
|
||||
return $rawMaterial;
|
||||
}
|
||||
@ -331,7 +331,7 @@ public function toggleStatus(RawMaterial $rawMaterial): void
|
||||
url: route('admin.master.raw-materials.index', ['highlight' => $rawMaterial->id]),
|
||||
);
|
||||
|
||||
$this->logUpdated($rawMaterial, 'Bahan Baku', $oldValues, $this->getRawMaterialLogValues($rawMaterial));
|
||||
$this->logUpdated($rawMaterial, 'Bahan Baku', $oldValues, $this->getRawMaterialLogValues($rawMaterial), ['Nama Bahan Baku']);
|
||||
}
|
||||
|
||||
private function getRawMaterialLogValues(RawMaterial $rawMaterial): array
|
||||
|
||||
@ -99,7 +99,7 @@ public function update(RawMaterialPrice $variant, array $data): RawMaterialPrice
|
||||
);
|
||||
|
||||
$rawMaterial->refresh();
|
||||
$this->logUpdated($rawMaterial, 'Bahan Baku', $oldValues, $this->getRawMaterialLogValues($rawMaterial));
|
||||
$this->logUpdated($rawMaterial, 'Bahan Baku', $oldValues, $this->getRawMaterialLogValues($rawMaterial), ['Nama Bahan Baku']);
|
||||
|
||||
return $variant->fresh();
|
||||
}
|
||||
|
||||
@ -21,9 +21,9 @@ private function logCreated(Model $model, string $module, array $newValues): voi
|
||||
]);
|
||||
}
|
||||
|
||||
private function logUpdated(Model $model, string $module, array $oldValues, array $newValues): void
|
||||
private function logUpdated(Model $model, string $module, array $oldValues, array $newValues, array $alwaysInclude = []): void
|
||||
{
|
||||
$changes = $this->buildUpdatedChanges($oldValues, $newValues);
|
||||
$changes = $this->buildUpdatedChanges($oldValues, $newValues, $alwaysInclude);
|
||||
|
||||
FormHistory::create([
|
||||
'causer_id' => Auth::id(),
|
||||
@ -84,7 +84,7 @@ private function buildCreatedChanges(array $newValues): array
|
||||
return $changes;
|
||||
}
|
||||
|
||||
private function buildUpdatedChanges(array $oldValues, array $newValues): array
|
||||
private function buildUpdatedChanges(array $oldValues, array $newValues, array $alwaysInclude = []): array
|
||||
{
|
||||
$changes = [];
|
||||
$allKeys = array_unique(array_merge(array_keys($oldValues), array_keys($newValues)));
|
||||
@ -101,6 +101,8 @@ private function buildUpdatedChanges(array $oldValues, array $newValues): array
|
||||
'old' => $old ?? null,
|
||||
'new' => $new ?? null,
|
||||
]);
|
||||
} elseif (in_array($key, $alwaysInclude, true)) {
|
||||
$changes[$key] = ['old' => $old, 'new' => $new];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user