---
# System prepended metadata

title: Untitled

---

Coverage Options Source:
Adjustment:
Buka Modal
POCoverage + (CandidateAdjustmentCoverage || AdjustmentCoverage)

Buka Modal, Update Data, Klik Back
POCoverage + (CandidateAdjustmentCoverage || AdjustmentCoverage)

```ruby=
adj = adj_massal.purchase_order_adjustment
po = adj.parent

adj_item = adj_massal.purchase_order_adjustment_item

candidate_adj_massal = Phoenix::PurchaseOrderAdjustmentItemMassal.not_default
																																 .where(candidate: true)
																																 .where(purchase_order_adjustment_item_id: adj_item.id)
																																 .first

adj_coverages = (candidate_adj_massal || adj_massal).purchase_order_adjustment_item_massal_coverages
po_coverages = po.purchase_order_item_massal_coverages

# Simple
coverage_options = po_coverages + adj_coverages

# Advance
po_coverages.each do |cov|
	adj_covs = adj_coverages.select { |adj| adj.purchase_order_item_massal_coverage_id == cov.id }
  adj_cov = adj_covs.detect { |adj| adj.shipping_address_id == cov.shipping_address_id }
  next if adj_cov.present? || cov.quantity_available.zero?
	new_cov = build_coverage(cov)
	adj_coverages << new_cov
end

coverage_options = adj_coverages


# Adjustment
# Adjustment Item
# Adjustment Item Massal (default_scope to hide candidate object)
# Adjustment Item Massal Shipping
# Adjustment Item Massal Coverage

Simulasi 1 tambah alamat, klik next, submit
Ori
A: 50 (PO)

Coverage Option:
A: 50 (PO)

Adjust Item:
A: 50 (PO)
B: 60 (Candidate Massal)
C: 70 (Candidate Massal)

Coverage Option:
A: 50 (PO)
B: 60 (Candidate Massal)
C: 70 (Candidate Massal)


Simulasi 2: Tambah alamat, klik next, klik back, hapus alamat, klik next
Ori
A: 50 (PO)

Coverage Option:
A: 50 (PO)

Adjust Item:
A: 50 (PO)
B: 60 (Candidate Massal)
C: 70 (Candidate Massal)

Coverage Option:
A: 50 (PO)
B: 60 (Candidate Massal)
C: 70 (Candidate Massal)

Adjust Item:
A: 50 (PO)
B: 60 (Candidate Massal)

Coverage Option:
A: 50 (PO)
B: 60 (Candidate Massal)


Simulasi 3: Ubah qty dari alamat asli, klik next, klik back
Ori
A: 50 (PO)

Coverage Option:
A: 50 (PO)

Adjust Item:
A: 50 (PO) (POIMC)

A: 60 (Candidate Massal) (POAIMC)
B: 90 (Candidate Massal) (POAIMC)

Coverage Option:
A: 60 (Candidate Massal) (POAIMC)
B: 90 (Candidate Massal) (POAIMC)
```

Readjustment:
Buka Modal
PO Coverage + Parent Adjustment Coverage + (CandidateAdjustmentCoverage || AdjustmentCoverage)

Buka Modal, Update Data, Klik Back
PO Coverage + Parent Adjustment Coverage + (CandidateAdjustmentCoverage || AdjustmentCoverage)

======

======

Coverages:


candidate
null = jika bukan object PurchaseOrderAdjustmentItemMassalCoverage
true = jika PurchaseOrderAdjustmentItemMassalCoverage masih belum di-finalisasi
false = jika PurchaseOrderAdjustmentItemMassalCoverage sudah di-finalisasi

will_be_deleted


User Melihat Adjusted Coverage
- Tampilkan PurchaseOrderAdjustmentItemMassalCoverage where candidate=false

Sample:
A - 100 (ori) {candidate: null}
B - 2 (adjusted) {candidate: false}
C - 3 (adjusted) {candidate: false}
D - 10 (adjusted) {candidate: false, will_be_deleted= true} x

Code:
- Officer Render Coverage Options -> Exclude coverage will_be_deleted=true
- Officer Submit Step 1 -> Flag Obsolete Coverage with will_be_deleted=true
- Officer Delete Candidate Data -> Tambah code untuk update will_be_deleted=false

User Buka Modal Adjust Item
- Hapus PurchaseOrderAdjustmentItemMassalCoverage where candidate=true
- Update all PurchaseOrderAdjustmentItemMassalCoverage set will_be_deleted=false
- Tampilkan coverage options: (render coverage options)
	- Original Coverage from PO
	- Adjustment Coverage from Parent Adjustment if any
	- Adjustment Coverage Not Default where will_be_deleted=false

User klik next First Step (Save Coverage)
- Create Coverage with candidate=true
- Flag Obsolete Coverage with will_be_deleted=true
- Tampilkan coverage options (render coverage options)


User reload/close modal/matot
- Do nothing

User klik submit Last Step (Save Price)
- Delete coverage will_be_deleted=true OR candidate=false
- 



status: {candidate, will_be_deleted, active}
Luar: where(status: :active)

Step 1: where(status: [:active, :candidate])

Submit Next Step 1:
status: :active => update(status: :will_be_deleted)

Reload






## readjust

User Melihat Adjusted Coverage
- Tampilkan PurchaseOrderAdjustmentItemMassalCoverage where candidate=false

Sample:
A - 100 (ori) {candidate: null}
B - 2 (adjusted) {candidate: false , will_be_deleted= false}
C - 3 (adjusted) {candidate: false , will_be_deleted= false}
D - 10 (adjusted) {candidate: false, will_be_deleted= false}

Code:
- Officer Render Coverage Options -> Exclude coverage will_be_deleted=true
- Officer Submit Step 1 -> Flag Obsolete Coverage with will_be_deleted=true
- Officer Delete Candidate Data -> Tambah code untuk update will_be_deleted=false

User Buka Modal Adjust Item
- Hapus PurchaseOrderAdjustmentItemMassalCoverage where candidate=true
- Update all PurchaseOrderAdjustmentItemMassalCoverage set will_be_deleted=false
- Tampilkan coverage options: (render coverage options)
	- Original Coverage from PO
	- Adjustment Coverage from Parent Adjustment if any
	- Adjustment Coverage Not Default where will_be_deleted=false


Sample:
A - 100 (ori) {candidate: null}
B - 2 (adjusted) {candidate: false , will_be_deleted= false}
C - 3 (adjusted) {candidate: false , will_be_deleted= false}
D - 10 => 15 (readjust) {candidate: false, will_be_deleted=false}


User klik next First Step (Save Coverage)
- Create Coverage with candidate=true
- Flag Obsolete Coverage with will_be_deleted=true
- Tampilkan coverage options (render coverage options)


User reload/close modal/matot
- Do nothing

User klik submit Last Step (Save Price)
- Delete coverage will_be_deleted=true OR candidate=false
- 



Adj 1 - client
Adj 1a for Supplier
  + Cov 1a CANDIDATE = false
  - Ketika readjust (buka modal)
    - Tampilkan 1b jika ada, atau 1a jika 1b tidak ada.
  - Ketika click "Selanjutnya" (Step 1)
    - Find or Create new Cov 1b dengan CANDIDATE = true
    - cov.find_or_intialize(shipping_address_id, adj_shipping_id)

  - Jika Step 2 - Submit
    - Cari yang CANDIDATE false (Cov 1a) dan Hapus
    - Cov 1b = Find record yang CANDIDATE true
    - Save params & Update Cov 1b CANDIDATE = false

  - Jika close, reload, refresh setelah Step 1
    - DO NOTHING

  - Ketika Reset
    - Create new Cov 1c dari Adj 1 CANDIDATE false

---

Adj 1b for Supplier 
  + Cov 1b CANDIDATE = false
  - Ketika readjust (buka modal)
    - Find child dari Adj 1 yang CANDIDATE = true (ekspektasinya dapet 1c)
    - Tampilkan 1c jika ada, atau 1b jika 1c tidak ada.
      BE memberikan response Cov 1c jika ada, atau Cov 1b

  - Ketika click "Selanjutnya" (Step 1)
    - Find or Create new Cov 1c dengan CANDIDATE = true
    - cov.find_or_intialize(shipping_address_id, adj_shipping_id)

  - Jika Step 2 - Submit
    - Cari yang CANDIDATE false (Cov 1b) dan Hapus
    - Cov 1c = Find record yang CANDIDATE true
    - Save params & Update Cov 1c CANDIDATE = false

  - Jika close, reload, refresh setelah Step 1
    - DO NOTHING

  - Ketika Reset
    - Create new Cov 1d dari Adj 1 CANDIDATE false


Setelah Client Propose atau Supplier Pertama kali Buka Adjustment:
Adj 1 {source: client, client_status: waiting_approval, partner_status: on_review}
Adj 1a {source: supplier, client_status: null, partner_status: candidate}

Supplier Buka Modal Adjust Item:
Adj 1 {source: client, client_status: waiting_approval, partner_status: on_review}
Adj 1a {source: supplier, client_status: null, partner_status: candidate}

Supplier tambah alamat baru
Adj 1 {source: client, client_status: waiting_approval, partner_status: on_review}
Adj 1a {parent: adj1, source: supplier, client_status: null, partner_status: candidate}

Adj 1b {parent: adj1, source: supplier, client_status: null, partner_status: candidate}






step awal
- po ori
1. cikande 100
2. pvj 50

client adjust (propose)
1. cikande 100
2. pvj 55


supplier readjust item => modal step 1
1. cikande 100
2. pvj 60 {id: null}
3. bekasi 50 {id: null}

case 1
supplier modal step 2 di reload
expected nya menjadi
1. cikande 100 
2. pvj 55 {id: 5}


case 2
supplier modal step 2 di back
expected nya menjadi
1. cikande 100
2. pvj 60 {id: 7, candidate: true, will_be_deleted: false}
3. bekasi 50 {id: 8 , candidate: true, will_be_deleted: false} 


supplier di step 1 hapus 
3. bekasi 50 {id: 8, candidate: true, will_be_deleted: true} 

di step 1 supplier ternyata menghapus / ubah data ke semula
expected nya menjadi
1. cikande 100
2. pvj 60 {id: 7, candidate: true, will_be_deleted: false}
3. bekasi 50 {id: 8, candidate: true, will_be_deleted: true} 




next ke step 1


submit
- Delete coverage will_be_deleted=true OR candidate=false



existing data yg sudah ke save
3. bekasi 50 {candidate: false, will_be_deleted: true}




====== 8 Juli 2022 ======





```