---
# System prepended metadata

title: Create PO

---

# Create PO

## tables
### purchase_order_groups
- id
- purchase_basket_id
- organization_id
- production_cost
- shipping_cost
- discount
- status (draft | submitted | cancelled)
- user_id
- total_cost
- deleted_at

### purchase_order_payments
- id
- purchase_order_group_id
- payment_method_id
- expired_at
- data
- status (draft paid settled expired refund cancelled void pending)


### purchase_order_group_collaborators
- id
- purchase_order_group_id
- user_id
- deleted_at

### purchase_orders
- id
- purchase_order_group_id
- partner_id
- number
- file_url
- pdf_url (confirm lagi?)
- billing_address_id
- promotion_id
- status (submitted | approved | rejected | cancelled )
- deleted_at

### purchase_order_items
- id
- purchase_order_id
- inquiry_id
- bidding_submission_id
- name
- expired_at
- quantity
- unit
- design_note
- design_note_attachment
- addresses_count
- zip_url
- designs_count
- deleted_at

### purchase_order_shipment_groups
- id
- purchase_order_id
- shipping_address_id
- courier
- service
- source integer('proof' | 'massal')

### purchase_order_shipments
- id
- purchase_order_shipment_group_id
- purchase_order_item_id
- shipping_address_id
- shipping (jsonb)
- shipping_date
- delivery_date
- quantity
- quantity_available
- quantity_used
- status


---
### po_shipment
- item

### po_package
- po_shipment
- number
- awb

### po_package_item
- po_package
- po_item

### purchase_order_packages
- id
- purchase_order_id
- number
- weight
- dimension
- shipping_address_id
- shipping
- courier
- service
- airwaybill
- shipping_cost
- lead_time
- requested_at
- picked_up_at
- arrived_at
- status (pickup_requested | on_delivery | delivered)


### purchase_order_package_items
- id
- purchase_order_package_id
- purchase_order_shipment_id
- purchase_order_item_id
- quantity
- unit


### purchase_order_timelines
- id
- purchase_order_id
- step (po_issue | pre_production | mass_production | shipment | completed)
- status (pending | onprogress | done)
- estimated_due_date
- current_due_date
- complete_date
- created_at

### purchase_order_timeline_histories
- purchase_order_timeline_id
- prev_due_date
- due_date

### purchase_order_item_timelines
- id
- purchase_order_item_id
- step (po_issue | pre_production | mass_production | shipment | completed)
- status (pending | onprogress | done)
- estimated_due_date
- current_due_date
- complete_date
- created_at

### purchase_order_item_timeline_histories
- purchase_order_item_timeline_id
- prev_due_date
- due_date

### purchase_order_item_designs
- id
- design_type enum: file|url
- url
- name
- size
- uploaded_by
- deleted_at

### purchase_order_approvals
- id
- purchase_order_id
- status (approved|rejected)
- response_by
- response_at
- deleted_at

### purchase_order_rejection_reasons
- id
- code
- name

### purchase_order_rejections
- id
- purchase_order_approval_id
- purchase_order_rejection_reason_id
- reason
- deleted_at

### payment_methods
- id
- name
- icon
- active_at
- inactive_at
- code
- module
- minimum_payment

### promotions
musti confirm dlu dari phoenix atau stark??

### note:
- perlu ada order reference? jika ada apakah order dan order item masih pake yg di prism? atau bikin baru?
- promotion dibuat di phoenix sendiri atau masi dr stark?


## Endpoints

### POST "/phoenix/purchase-order-groups"
### Request:
```json=
{
    purchase_basket_id: ID
}
```
### Response:
```json=
{
    "success"
}
```

### Logic:
- create new po group
- create po
- create po_items
- create po_timelines
- create po_shipments


### GET "/phoenix/purchase-order-groups/:id"
### Response:
```json=
{
    "id": ID,
	"purchase_basket_id": 1,
	"organization_id": 1,
	"production_cost": 10000,
	"shipping_cost": 1000,
	"discount": '',
	"status": 'draft|submitted|cancelled',
	"payment_status": 'unpaid|paid', 
    "total_cost": ''
	"purchase_orders":[{
		"id": 1,
		"purchase_order_group_id": ID,
		"partner_id": 1,
		"number": "PO/ASBAD/1234",
		"file_url": '',
		"pdf_url": '',
		"billing_address_id": 10,
		"status": 'submitted|approved|rejected|cancelled',
		"partner": {
				"id": ID,
				"name": "Printing Jaya",
		},
		"purchase_order_items":[{
				"purchase_order_id": 1,
				"inquiry_id": '',
				"bidding_submission_id": '',
				"name": '',
				"expired_at": '',
				"quantity": '',
				"unit": '',
				"design_note": '',
				"design_note_attachment": '',
				"addresses_count":0,
				"designs_count": 0
		}]
	}]
}
```

### PUT "/phoenix/purchase-order-items/:id"
### Request:
```json=
{
    "design_note":"",
    "design_note_attachment": '',
}
```
### Response:
```json=
{
    "purchase_order_id": 1,
    "inquiry_id": '',
    "bidding_submission_id": '',
    "name": '',
    "expired_at": '',
    "quantity": '',
    "unit": '',
    "design_note": '',
    "design_note_attachment": '',
    "addresses_count":0,
    "designs_count": 0
}
```

### POST "/phoenix/purchase-order-items/:id/designs"
### Request:
```json=
{
    "file_source": "file|url",
	"files":[{
        "url": "",
        "name": "",
        "size": ""
	}]
}
```

### Response:
```json=
[{
    "design_type": "file|url",
    "url": "",
    "name": "",
    "size": ""
}]
```

### PATCH "/phoenix/purchase-orders/:id/file"
### Request:
```json=
{
    "file_url": ""
}
```

### Response:
```json=
{
    "id": 1,
    "purchase_order_group_id": ID,
    "partner_id": 1,
    "number": "PO/ASBAD/1234",
    "file_url": '',
    "pdf_url": '',
    "billing_address_id": 10,
    "status": 'submitted|approved|rejected|cancelled',
    "partner": {
        "id": ID,
        "name": "Printing Jaya",
    }
}
```




Case Shipment: 
PO Partner A | ToP: 14d | BillingID: 12
	PO Item A: 100
	PO Item B: 300

PO Partner B | ToP: 14d | BillingID: 13
	PO Item C: 50

PO Partner A | ToP: 7d | BillingID: 12
	PO Item D: 50


PO Shipments:
	PO Shipment Item: PO Item A
	PO Shipment Item: PO Item B
	PO Shipment Item: PO Item D

PO Shipments:
	PO Shipment Item: PO Item C