# Purchase Analysis Mapping

Dokumen ini memetakan sheet analisis pembelian ke modul sistem.

## Letak proses

- `Purchases`: berat beli, kadar beli, harga referensi, modal barang awal.
- `Receipts`: berat masuk, kadar masuk, perbandingan beli vs masuk.
- `Lots / Sorting`: berat akhir, kadar akhir, rasio barang atas rata-rata.
- `Purchase Analysis`: biaya operasional, valuasi market, laba rugi total, laba rugi agen.

## Mapping field

| Field sheet | Sumber utama | Implementasi |
| --- | --- | --- |
| Berat beli | Purchase lines | `purchase_lines.qty_ordered` atau override di `purchase_analyses.weight_buy` |
| Berat masuk | Receipt lines | agregat `receipt_lines.qty_received` atau override di `purchase_analyses.weight_received` |
| Berat akhir | Lots / sorting | agregat `inventory_lots.original_qty` atau override di `purchase_analyses.weight_final` |
| Kadar beli | Purchase | rata-rata `purchase_lines.purchase_moisture_percent` atau override |
| Kadar masuk | Receipt | rata-rata `receipt_lines.moisture_percent` atau override |
| Kadar akhir | Lot final | rata-rata `inventory_lots.final_moisture_percent` atau override |
| Barang atas rata-rata | QC / sorting | rata-rata `inventory_lots.above_average_ratio_percent` atau override |
| Harga MK A/R | Purchasing / owner | `purchase_lines.market_reference_price` atau override |
| Operasional | Costing | `purchase_analysis_cost_entries` |
| Laba/rugi agen | Costing | `purchase_analyses.agent_profit_share_total` |

## Rumus sistem

- `berat_naik_percent = (berat_masuk - berat_beli) / berat_beli * 100`
- `susut_tambah = berat_akhir - berat_masuk`
- `modal_barang = sum(purchase_lines.subtotal)`
- `operasional = sum(cost_entries.amount)`
- `total_modal_beli = modal_barang + operasional`
- `modal_beli_per_kg = modal_barang / berat_beli`
- `modal_masuk_per_kg = modal_barang / berat_masuk`
- `modal_jual_per_kg = modal_barang / berat_akhir`
- `total_modal_mal = manual market valuation atau harga_mk_ar * berat_akhir`
- `total_laba_rugi = total_modal_mal - total_modal_beli`
- `laba_total_per_kg = (total_laba_rugi - laba_rugi_agen) / berat_akhir`
- `laba_agen_per_kg = laba_rugi_agen / berat_akhir`

## Catatan

- Istilah `TOTAL MODAL MAL` di sheet sumber belum sepenuhnya baku. Di sistem, field ini diwakili sebagai `market valuation total`, supaya tetap fleksibel.
- Semua angka hasil hitung tetap bisa dioverride lewat modul `Purchase Analysis` bila perusahaan ingin mengikuti angka manual owner.
