---
# System prepended metadata

title: TMS Logistic Workflow
tags: [fulfillment, logistic, last-mile, partners]

---

# TMS Logistic Workflow

These are the requirements when integrating partners in the field of logistics.

:tada: Agenda
---
- [Add partners](/s)
- [Add warehouse (optional)](/s)
- [Config partner integrated](/s)
- [Config **order statuses** mapping](/s)
- [Config **location mapping** (optional)](/s)

:memo:  Where do I start?
---

:::info
:busts_in_silhouette: IP Department
:::

### Step 1: Add partners

> Use SQL

- If the partner is **fulfillment**

```sql=
INSERT INTO "bp_partner" (
	"pn_id",
	"pn_type",
	"name",
	"shortname",
	"contact",
	"phone",
	"email",
	"address",
	"modifyby",
	"modifydate",
	"logo_path_01",
	"logo_path_02",
	"type",
	"skill_level" 
)
VALUES
	(
		( SELECT MAX ( pn_id ) FROM bp_partner ) + 1,
		122,
		'Baspro',
		'Baspro',
		NULL,
		NULL,
		NULL,
		NULL,
		0,
		now( ),
		NULL,
		NULL,
		NULL,
		NULL 
	);
```

- If the partner is **last-mile**

```sql=
INSERT INTO "bp_partner" (
	"pn_id",
	"pn_type",
	"name",
	"shortname",
	"contact",
	"phone",
	"email",
	"address",
	"modifyby",
	"modifydate",
	"logo_path_01",
	"logo_path_02",
	"type",
	"skill_level" 
)
VALUES
	(
		( SELECT MAX ( pn_id ) FROM bp_partner ) + 1,
		121,
		'Topship',
		'Topship',
		NULL,
		NULL,
		NULL,
		NULL,
		0,
		now( ),
		NULL,
		NULL,
		NULL,
		NULL 
	);
```

### Step 2: Add warehouse (optional)

> Use SQL

```sql=
INSERT INTO "bp_warehouse" (
	"org_id",
	"partner_id",
	"warehouse_id",
	"warehouse_name",
	"warehouse_shortname",
	"contact_name",
	"contact_phone",
	"address",
	"full_address",
	"wards_id",
	"wards_code",
	"wards_name",
	"district_id",
	"district_code",
	"district_name",
	"province_id",
	"province_code",
	"province_name",
	"email",
	"is_edit_wh",
	"ismain",
	"latitude",
	"longitude",
	"is_active",
	"createby",
	"createdate",
	"modifyby",
	"modifydate",
	"wh_code_inpartner" 
)
VALUES
	(
		4,
		173,
		( SELECT MAX ( warehouse_id ) FROM bp_warehouse ) + 1,
		'Baspro Fulfillment Ho Chi Minh',
		'BASPRO FFM HCM',
		NULL,
		'',
		'Lô C7/2 đường 2E, KCN Vĩnh Lộc, Vĩnh Lộc A, Bình Chánh, TP HCM',
		'Lô C7/2 đường 2E, KCN Vĩnh Lộc, Vĩnh Lộc A, Bình Chánh, TP HCM',
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		'Hồ Chí Minh',
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		0,
		now( ),
	NULL 
	);

```

### Step 3: Config partner integrated

:::warning
:pencil: Set fulfilment integrated with last-mile
:::

> Use SQL

```sql=
INSERT INTO "od_so_mapping_warehouse" ( "id", "ffm_partner_id", "lm_partner_id", "createby", "createdate", "modifyby", "modifydate" )
VALUES
	(
		( SELECT MAX ( ID ) FROM od_so_mapping_warehouse ) + 1,
		173,
		4,
		NULL,
		now( ),
		NULL,
		now( ) 
	),
	(
		( SELECT MAX ( ID ) FROM od_so_mapping_warehouse ) + 2,
		173,
		5,
		NULL,
		now( ),
		NULL,
		now( ) 
	),
	(
		( SELECT MAX ( ID ) FROM od_so_mapping_warehouse ) + 3,
		173,
		6,
		NULL,
		now( ),
		NULL,
		now( ) 
	),
	(
		( SELECT MAX ( ID ) FROM od_so_mapping_warehouse ) + 4,
		173,
		140,
		NULL,
		now( ),
		NULL,
		now( ) 
	),
	(
		( SELECT MAX ( ID ) FROM od_so_mapping_warehouse ) + 5,
		173,
		160,
		NULL,
		now( ),
		NULL,
		now( ) 
	),
	(
		( SELECT MAX ( ID ) FROM od_so_mapping_warehouse ) + 6,
		173,
		172,
		NULL,
		now( ),
		NULL,
		now( ) 
	),
	(
		( SELECT MAX ( ID ) FROM od_so_mapping_warehouse ) + 7,
		1,
		172,
		NULL,
		now( ),
		NULL,
	now( ) 
	);
```

### Step 4: Config **order statuses** mapping

Get all delivery order status:

```sql=
SELECT * FROM "cf_synonym" WHERE type_id = 5 ORDER BY "value" DESC;
```

> Use SQL

```sql=
INSERT INTO "cf_status_mapping" ( "stt_mapping_id", "org_id", "partner_id", "pn_status_code", "pn_status_name", "pn_status_description", "tms_status", "tms_status_name" )
VALUES
	( ( SELECT MAX ( stt_mapping_id ) FROM cf_status_mapping ) + 1, 4, 172, 'Z', 'default', 'Mới tạo (chưa thông báo đơn vị vận chuyển hoặc gặp lỗi khi thông báo)', 51, 'new' ),
	( ( SELECT MAX ( stt_mapping_id ) FROM cf_status_mapping ) + 2, 4, 172, 'Z', 'created', 'Mới tạo (đã thông báo đơn vị vận chuyển)', 51, 'new' ),
	( ( SELECT MAX ( stt_mapping_id ) FROM cf_status_mapping ) + 3, 4, 172, 'S', 'picking', 'Đang lấy hàng', 66, 'ready to pick' ),
	( ( SELECT MAX ( stt_mapping_id ) FROM cf_status_mapping ) + 4, 4, 172, 'S', 'holding', 'Đang luân chuyển hoặc lưu kho', 62, 'delivering' ),
	( ( SELECT MAX ( stt_mapping_id ) FROM cf_status_mapping ) + 5, 4, 172, 'S', 'returning', 'Đang trả hàng', 56, 'returning' ),
	( ( SELECT MAX ( stt_mapping_id ) FROM cf_status_mapping ) + 6, 4, 172, 'NS', 'returned', 'Đã trả hàng', 61, 'returned' ),
	( ( SELECT MAX ( stt_mapping_id ) FROM cf_status_mapping ) + 7, 4, 172, 'S', 'delivering', 'Đang giao hàng', 62, 'delivering' ),
	( ( SELECT MAX ( stt_mapping_id ) FROM cf_status_mapping ) + 8, 4, 172, 'P', 'delivered', 'Đã giao hàng', 59, 'delivered' ),
	( ( SELECT MAX ( stt_mapping_id ) FROM cf_status_mapping ) + 9, 4, 172, 'S', 'unknown', 'Không xác định', 55, 'intransit' ),
	( ( SELECT MAX ( stt_mapping_id ) FROM cf_status_mapping ) + 10, 4, 172, 'S', 'undeliverable', 'Đơn hàng bị mất hoặc bị giữ lại', 55, 'intransit' ),
	( ( SELECT MAX ( stt_mapping_id ) FROM cf_status_mapping ) + 11, 4, 172, 'N', 'cancelled', 'Đã hủy', 53, 'cancel' );
```

### Step 5: Config **location mapping** (optional)

> Use SQL

Table: `lc_province_map`, `lc_district_map`, `lc_subdistrict_map`, `lc_neighborhood_map`


:construction: Workflow
---

![Logistics workflow](https://i.imgur.com/Jz7uG5B.png)





###### tags: `logistic` `fulfillment` `last-mile` `partners`
