
#Get list of order status
curl --location --request POST 'https://land.dbiz.com//api/method/building_material.building_material.api.sales_order.get_order_status_list' \
--header 'Cookie: sid=a98c0b426abd8af3b0fd92407ef96937acda888a9a63bf3c580447d4; full_name=Hsadqdqwed; sid=42d89a7465571e04e0ee47a5bb1dd73563ff4f30ef9f7370ed490275; system_user=no; user_id=123%40gmail.com; user_image=/files/avatar_0987654321_1763631288.jpg' \
--header 'X-Frappe-Csrf-Token: a2bc5e9342441ff895ad2781e99a4c3fae4cad1250ae40c51f90067a' \
--header 'Content-Type: application/json' \
--data ''

#Response list of order status
{
    "message": [
        {
            "status": "Pending approval",
            "label": "Chờ phê duyệt",
            "color": "Warning",
            "index": 1
        },
        {
            "status": "Processing",
            "label": "Đang xử lý",
            "color": "Warning",
            "index": 2
        },
        {
            "status": "Completed",
            "label": "Hoàn thành",
            "color": "Success",
            "index": 3
        },
        {
            "status": "Rejected",
            "label": "Từ chối",
            "color": "Danger",
            "index": 4
        },
        {
            "status": "Cancelled",
            "label": "HỦY BỎ",
            "color": "Danger",
            "index": 5
        }
    ]
}

#get payment list
curl --location 'https://land.dbiz.com//api/method/frappe.client.get_list' \
--header 'X-Frappe-Csrf-Token: a2bc5e9342441ff895ad2781e99a4c3fae4cad1250ae40c51f90067a' \
--header 'Cookie: sid=a98c0b426abd8af3b0fd92407ef96937acda888a9a63bf3c580447d4; full_name=phuoc; sid=a98c0b426abd8af3b0fd92407ef96937acda888a9a63bf3c580447d4; system_user=no; user_id=vodanh.2901%40gmail.com; user_image=https%3A//secure.gravatar.com/avatar/753a0e2601b9bd87aed417e2ad123bf8%3Fd%3D404%26s%3D200' \
--header 'Content-Type: application/json' \
--data '{
  "doctype": "Payment Terms Template",
  "fields": ["name","custom_description"],
  "limit_page_length": 0
}'

#response payment list
{
    "message": [
        {
            "name": "Thanh toán hoàn toàn",
            "custom_description": "Thanh toán ngay được chiết khấu 2%"
        },
        {
            "name": "Thanh toán trả trước",
            "custom_description": "Trả trước (≥20%), còn lại thanh toán trong vòng 30 ngày"
        }
    ]
}

#create order
curl --location 'https://land.dbiz.com//api/method/building_material.building_material.api.sales_order.save' \
--header 'Cookie: sid=a98c0b426abd8af3b0fd92407ef96937acda888a9a63bf3c580447d4; full_name=phuoc; sid=c0f46dc2ed23d58c013daa7d1813b36caf04555472b792cdb74e0d61; system_user=no; user_id=vodanh.2901%40gmail.com; user_image=https%3A//secure.gravatar.com/avatar/753a0e2601b9bd87aed417e2ad123bf8%3Fd%3D404%26s%3D200' \
--header 'X-Frappe-Csrf-Token: a2bc5e9342441ff895ad2781e99a4c3fae4cad1250ae40c51f90067a' \
--header 'Content-Type: application/json' \
--data '{
          "transaction_date": "2025-11-20", // Ngày tạo
          "delivery_date": "2025-11-20",    // Ngày dự kiến giao
          "shipping_address_name": "Lam Address-Billing",
          "customer_address": "Lam Address-Billing",
          "description": "Order description", // Ghi chú
          "payment_terms" : "Thanh toán hoàn toàn", // Lấy name từ GET PAYMENT TERM
          "items": [
            {
              "item_id": "HOA E02",
              "qty_entered": 2, // SỐ lượng User tự nhập
              "primary_qty" : 2.56,  // SỐ lượng sau khi quy đổi
              "price_entered": 10000 // Đơn giá
            }
          ]
        }'

        #create order response
 Response: {message: {success: true, message: Sales Order created successfully, data: {name: SAL-ORD-2025-00078, status_color: Warning, status: Chờ phê duyệt, grand_total: 589824.0}}}



#gen qrcode
curl --location 'https://land.dbiz.com//api/method/building_material.building_material.api.v1.qrcode.generate' \
--header 'X-Frappe-Csrf-Token: 6ff3be4d1f887dbebf86ba4502b05d94b30c0b0569de49b74a7171a9' \
--header 'Cookie: sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d; sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d' \
--header 'Content-Type: application/json' \
--data '{
 "order_id" : "SAL-ORD-2025-00048"
}'

#gen qrcode response
{
    "message": {
        "qr_code": "00020101021238540010A00000072701240006970422011008490428160208QRIBFTTA53037045802VN62220818SAL-ORD-2025-00048630430F4",
        "amount": null,
        "transaction_id": "SAL-ORD-2025-00048",
        "bank_info": {
            "bank_name": "MB Bank",
            "account_no": "0849042816",
            "account_name": "NGUYEN MINH CHAU"
        }
    }
}

#upload bill
curl --location 'https://land.dbiz.com//api/method/upload_file' \
--header 'Cookie: sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d; sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d' \
--header 'X-Frappe-Csrf-Token: 6ff3be4d1f887dbebf86ba4502b05d94b30c0b0569de49b74a7171a9' \
--form 'file=@"/C:/Users/tiennld/Downloads/logo_crm.png"' \
--form 'is_private="1"' \
--form 'folder="Home/Attachments"' \
--form 'doctype="Sales Order"' \
--form 'docname="SAL-ORD-2025-00058-1"' \
--form 'optimize="true"'


#get list order
curl --location 'https://land.dbiz.com//api/method/building_material.building_material.api.sales_order.get_list' \
--header 'Cookie: sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d; full_name=Ha%20Duy%20Lam; sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d; system_user=yes; user_id=lamhd%40gmail.com; user_image=/files/avatar_0986788766_1763627962.jpg' \
--header 'X-Frappe-Csrf-Token: 6ff3be4d1f887dbebf86ba4502b05d94b30c0b0569de49b74a7171a9' \
--header 'Content-Type: application/json' \
--data '{
    "limit_start" : 0,
    "limit_page_length" : 0

}'

#response list order
{
    "message": [
        {
            "name": "SAL-ORD-2025-00107",
            "transaction_date": "2025-11-24",
            "delivery_date": "2025-11-24",
            "address": "123 add dad",
            "grand_total": 3355443.2,
            "status": "Chờ phê duyệt",
            "status_color": "Warning"
        },
        {
            "name": "SAL-ORD-2025-00106",
            "transaction_date": "2025-11-24",
            "delivery_date": "2025-11-24",
            "address": "123 add dad",
            "grand_total": 3355443.2,
            "status": "Chờ phê duyệt",
            "status_color": "Warning"
        },
        ...
    ]
}

#order detail
curl --location 'https://land.dbiz.com//api/method/building_material.building_material.api.sales_order.get_detail' \
--header 'Cookie: sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d; sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d' \
--header 'X-Frappe-Csrf-Token: 6ff3be4d1f887dbebf86ba4502b05d94b30c0b0569de49b74a7171a9' \
--header 'Content-Type: application/json' \
--data '{
    "name" : "SAL-ORD-2025-00058-1"
}'

#response order detail
{
    "message": {
        "order": {
            "name": "SAL-ORD-2025-00107",
            "customer": "test - 1",
            "transaction_date": "2025-11-24",
            "delivery_date": "2025-11-24",
            "status": "Chờ phê duyệt",
            "status_color": "Warning",
            "total_qty": 2.56,
            "total": 3355443.2,
            "grand_total": 3355443.2,
            "total_remaining": 0,
            "description": "Order from mobile app",
            "contract_request": false,
            "ignore_pricing_rule": false,
            "rejection_reason": null,
            "is_allow_cancel": true
        },
        "billing_address": {
            "name": "phuoc-Billing-3",
            "address_title": "phuoc",
            "address_line1": "123 add dad",
            "phone": "0123123123",
            "email": "123@gmail.com",
            "fax": null,
            "tax_code": "064521840",
            "city_code": "19",
            "ward_code": "01936",
            "city_name": "Tỉnh Thái Nguyên",
            "ward_name": "Xã Nà Phặc",
            "is_allow_edit": true
        },
        "shipping_address": {
            "name": "phuoc-Billing-3",
            "address_title": "phuoc",
            "address_line1": "123 add dad",
            "phone": "0123123123",
            "email": "123@gmail.com",
            "fax": null,
            "tax_code": "064521840",
            "city_code": "19",
            "ward_code": "01936",
            "city_name": "Tỉnh Thái Nguyên",
            "ward_name": "Xã Nà Phặc",
            "is_allow_edit": true
        },
        "items": [
            {
                "name": "9crv0j6d4t",
                "item_code": "HOA E01",
                "item_name": "Hội An HOA E01",
                "description": "Hội An HOA E01",
                "qty_entered": 0.0,
                "qty_of_sm": 2.56,
                "qty_of_nos": 4.0,
                "conversion_factor": 1.5625,
                "price": 1310720.0,
                "total_amount": 3355443.2,
                "delivery_date": "2025-11-24",
                "thumbnail": "https://land.dbiz.com/files/HOA-E01-f1.jpg"
            }
        ],
        "payment_terms": {
            "name": "Thanh toán hoàn toàn",
            "description": "Thanh toán ngay được chiết khấu 2%"
        },
        "timeline": [
            {
                "label": "Đã tạo đơn",
                "value": "2025-11-24 14:46:07",
                "status": "Success"
            },
            {
                "label": "Chờ phê duyệt",
                "value": null,
                "status": "Warning"
            },
            {
                "label": "Đơn đang xử lý",
                "value": "Prepare goods and transport",
                "status": "Secondary"
            },
            {
                "label": "Hoàn thành",
                "value": null,
                "status": "Secondary"
            }
        ],
        "payments": [],
        "invoices": []
    }
}

#update address order
curl --location 'https://land.dbiz.com//api/method/building_material.building_material.api.sales_order.update' \
--header 'Cookie: sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d; full_name=Ha%20Duy%20Lam; sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d; system_user=yes; user_id=lamhd%40gmail.com; user_image=/files/avatar_0986788766_1763627962.jpg' \
--header 'X-Frappe-Csrf-Token: 6ff3be4d1f887dbebf86ba4502b05d94b30c0b0569de49b74a7171a9' \
--header 'Content-Type: application/json' \
--data '{
  "name" : "SAL-ORD-2025-00053",
  "shipping_address_name": "Công ty Tiến Nguyễn 2-thanh toán",
  "customer_address": "Nguyễn Lê Duy Ti-Billing"
}'

#cancel order
curl --location 'https://land.dbiz.com//api/method/building_material.building_material.api.sales_order.cancel' \
--header 'Cookie: sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d; full_name=Ha%20Duy%20Lam; sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d; system_user=yes; user_id=lamhd%40gmail.com; user_image=/files/avatar_0986788766_1763627962.jpg' \
--header 'X-Frappe-Csrf-Token: 6ff3be4d1f887dbebf86ba4502b05d94b30c0b0569de49b74a7171a9' \
--header 'Content-Type: application/json' \
--data '{
    "name" : "SAL-ORD-2025-00054"
}'