mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 06:45:43 +00:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3e34da7385 | |||
| e781115390 | |||
| 6bbab2f1d5 | |||
| 621d0d2bfd | |||
| 32c34be2c6 | |||
| d2aa3ebac7 | |||
| 1fd3f96038 | |||
| cf0fc9e7e6 | |||
| d9041a89bb | |||
| c75281ebd9 | |||
| ca3ad810c6 | |||
| 655b1ad5fe | |||
| 84db5fe37a | |||
| 63a78da18d | |||
| ac50c06cd7 | |||
| b60649f59d | |||
| 6acc9416c1 | |||
| bb4e5d6e3e | |||
| 170c221957 | |||
| 812327f148 | |||
| cd192128f1 | |||
| a5d4d6c11d | |||
| 1452f8d083 | |||
| 33c6706181 | |||
| c9618e1095 | |||
| cae7f3ef63 | |||
| 42793d94bd | |||
| 1369bf0e36 | |||
| 361d14bd3e | |||
| 7923352535 | |||
| 010240066a |
@@ -0,0 +1,4 @@
|
||||
UPDATE adjustment_stocks
|
||||
SET price = 9535,
|
||||
grand_total = ROUND(8700 * 9535, 3)
|
||||
WHERE id = 532 AND adj_number = 'ADJ-00507';
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
UPDATE adjustment_stocks
|
||||
SET price = 12635,
|
||||
grand_total = ROUND(8700 * 12635, 3)
|
||||
WHERE id = 532 AND adj_number = 'ADJ-00507';
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
BEGIN;
|
||||
|
||||
-- Rollback konsolidasi: kembalikan data ke loc 18 / 25 sesuai snapshot pre-migration.
|
||||
-- Order: un-soft-delete locations dulu agar FK tidak gagal saat UPDATE child.
|
||||
|
||||
-- 1. Un-soft-delete locations
|
||||
UPDATE locations SET deleted_at = NULL WHERE id IN (18, 25);
|
||||
|
||||
-- 2. project_flocks: PF 30 -> 18, PF 25 & 31 -> 25
|
||||
UPDATE project_flocks SET location_id = 18, updated_at = NOW() WHERE id = 30;
|
||||
UPDATE project_flocks SET location_id = 25, updated_at = NOW() WHERE id IN (25, 31);
|
||||
|
||||
-- 3. kandangs: K9, K72, K117 -> 18; K10, K73, K116 -> 25
|
||||
UPDATE kandangs SET location_id = 18, updated_at = NOW() WHERE id IN (9, 72, 117);
|
||||
UPDATE kandangs SET location_id = 25, updated_at = NOW() WHERE id IN (10, 73, 116);
|
||||
|
||||
-- 4. kandang_groups: KG 26, 68 -> 18; KG 27, 67 -> 25
|
||||
UPDATE kandang_groups SET location_id = 18, updated_at = NOW() WHERE id IN (26, 68);
|
||||
UPDATE kandang_groups SET location_id = 25, updated_at = NOW() WHERE id IN (27, 67);
|
||||
|
||||
-- 5. warehouses: W27, W145, W152 -> 18; W3, W146, W153 -> 25
|
||||
UPDATE warehouses SET location_id = 18, updated_at = NOW() WHERE id IN (27, 145, 152);
|
||||
UPDATE warehouses SET location_id = 25, updated_at = NOW() WHERE id IN (3, 146, 153);
|
||||
|
||||
-- 6. expenses: list eksplisit per location
|
||||
UPDATE expenses SET location_id = 18, updated_at = NOW()
|
||||
WHERE id IN (36, 345, 500, 501, 502, 503, 504, 505, 506, 507, 508);
|
||||
UPDATE expenses SET location_id = 25, updated_at = NOW()
|
||||
WHERE id IN (9, 37, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518);
|
||||
|
||||
COMMIT;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
BEGIN;
|
||||
|
||||
-- Konsolidasi 3 lokasi "Pullet Cikaum" jadi 1.
|
||||
-- Pindahkan semua data di loc 18 (Pullet Cikaum 1) & 25 (Pullet Cikaum 2) ke loc 2 (Pullet Cikaum).
|
||||
-- Urutan wajib: semua UPDATE child harus selesai SEBELUM soft-delete locations,
|
||||
-- karena trigger trg_soft_delete_fk_locations akan RAISE EXCEPTION untuk FK
|
||||
-- RESTRICT (project_flocks, kandangs, kandang_groups, expenses) atau SET NULL
|
||||
-- untuk warehouses kalau masih ada child yang reference.
|
||||
|
||||
-- 1. project_flocks (PF 25, 30, 31)
|
||||
UPDATE project_flocks SET location_id = 2, updated_at = NOW()
|
||||
WHERE location_id IN (18, 25);
|
||||
|
||||
-- 2. kandangs (K9, K72, K117, K10, K73, K116)
|
||||
UPDATE kandangs SET location_id = 2, updated_at = NOW()
|
||||
WHERE location_id IN (18, 25);
|
||||
|
||||
-- 3. kandang_groups (KG 26, 68, 27, 67)
|
||||
UPDATE kandang_groups SET location_id = 2, updated_at = NOW()
|
||||
WHERE location_id IN (18, 25);
|
||||
|
||||
-- 4. warehouses (W3, W27, W145, W146, W152, W153)
|
||||
UPDATE warehouses SET location_id = 2, updated_at = NOW()
|
||||
WHERE location_id IN (18, 25);
|
||||
|
||||
-- 5. expenses (23 row BOP)
|
||||
UPDATE expenses SET location_id = 2, updated_at = NOW()
|
||||
WHERE location_id IN (18, 25);
|
||||
|
||||
-- 6. Soft-delete locations 18 & 25 (kosong, aman karena semua child sudah pindah)
|
||||
UPDATE locations SET deleted_at = NOW()
|
||||
WHERE id IN (18, 25) AND deleted_at IS NULL;
|
||||
|
||||
COMMIT;
|
||||
@@ -542,9 +542,15 @@ func (s deliveryOrdersService) UpdateOne(c *fiber.Ctx, req *validation.DeliveryO
|
||||
return nil, err
|
||||
}
|
||||
|
||||
latestApproval, err := s.ApprovalSvc.LatestByTarget(c.Context(), utils.ApprovalWorkflowMarketing, id, nil)
|
||||
if err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to check approval status")
|
||||
}
|
||||
|
||||
err = s.MarketingRepo.DB().WithContext(c.Context()).Transaction(func(dbTransaction *gorm.DB) error {
|
||||
marketingProductRepositoryTx := marketingRepo.NewMarketingProductRepository(dbTransaction)
|
||||
marketingDeliveryProductRepositoryTx := marketingRepo.NewMarketingDeliveryProductRepository(dbTransaction)
|
||||
approvalSvcTx := commonSvc.NewApprovalService(commonRepo.NewApprovalRepository(dbTransaction))
|
||||
marketingRepoTx := marketingRepo.NewMarketingRepository(dbTransaction)
|
||||
|
||||
marketing, err := marketingRepoTx.GetByID(c.Context(), id, nil)
|
||||
@@ -630,6 +636,23 @@ func (s deliveryOrdersService) UpdateOne(c *fiber.Ctx, req *validation.DeliveryO
|
||||
}
|
||||
}
|
||||
|
||||
if latestApproval != nil && latestApproval.StepNumber == uint16(utils.MarketingDeliveryOrder) {
|
||||
action := entity.ApprovalActionUpdated
|
||||
_, err := approvalSvcTx.CreateApproval(
|
||||
c.Context(),
|
||||
utils.ApprovalWorkflowMarketing,
|
||||
id,
|
||||
utils.MarketingStepSalesOrder,
|
||||
&action,
|
||||
actorID,
|
||||
nil)
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to reset approval to Sales Order")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -516,7 +516,7 @@ func (s salesOrdersService) UpdateOne(c *fiber.Ctx, req *validation.Update, id u
|
||||
c.Context(),
|
||||
utils.ApprovalWorkflowMarketing,
|
||||
id,
|
||||
approvalutils.ApprovalStep(latestApproval.StepNumber),
|
||||
utils.MarketingStepPengajuan,
|
||||
&action,
|
||||
actorID,
|
||||
nil)
|
||||
|
||||
Reference in New Issue
Block a user