@Wahson
2018-10-18T02:44:15.000000Z
字数 12769
阅读 816
工作
create table purchase_order2(
id bigint not null primary key comment '主键',
code varchar(30) not null default '' comment '单号',
seq_no tinyint(2) not null default 0 comment '财务序号,财务结账后再进行更正时,原单不变,新建一张红冲单、一张更正单,序号相应增加',
source tinyint(2) NOT NULL DEFAULT '0' COMMENT '单据来源,1:PC(pc);2:PDA(pda);3:人工补录(manual_record)',
is_force tinyint(2) not null default 0 comment '是否强配: 1是,0否',
ticket_type tinyint(3) not null default 1 comment '单据类型:1:进货单(stock);2:退货单(refund);3:调拨单(transfer);4:缺货修正单(absence_correct);5:拒收修正单(rejection_correct)',
ticket_type_code varchar(5) not null default '' comment '单据类型编码',
origin_id bigint default null comment '修正单源单id',
parent_id bigint default null comment '父单id,针对总部采购多次预约拆单逻辑',
supplier_order_id bigint default null comment '直纳订单,关联的供应商订单id',
purchase_status tinyint(3) not null default 1 comment '采购单状态,10:待审核(to_be_audited);11:审核不通过(audit_fail);20:待确认(to_be_confirmed);30:待供应方发货(to_be_deliveried);40:待验收(to_be_received);41:部分验收(partial_received);42:已验收(received);43:已自动验收(auto_received);90:超时关闭(closed_for_timeout);91:拆单关闭中(splitting);92:拆单关闭完成(split);99:已取消(canceled)',
purchaser_type tinyint(3) not null default 1 comment '采购方类型,1:门店(store);2:仓库(storage)',
supply_type tinyint(3) not null default 1 comment '供应方类型,1:门店(store);2:仓库(storage);3:供应商(supplier)',
purchaser_id varchar(20) not null default '' comment '采购方编号,门店财务店号/仓库编号',
purchaser_name varchar(100) not null default '' comment '采购方名称',
supply_id varchar(20) not null default '' comment '供应方编号,门店财务店号/仓库编号/供应商编号(厂编)',
supply_name varchar(100) not null default '' comment '供应方名称',
shipping_method varchar(10) not null default '01' comment '温层',
logistics_type tinyint(3) not null default 1 comment '配送方式,1:寄库(deposit);2:经由(via);3:巡回(tour);4:直纳(nonstop);5:直送(direct)',
purchase_at datetime not null default current_timestamp() comment '订购日',
delivery_time int not null default 0 comment '配送时长,单位天',
expected_arrival_at datetime not null default current_timestamp() comment '预计到货日',
actual_arrival_at datetime default null comment '实际到货日',
accept_at datetime default null comment '验收日',
purchase_total_num int not null default 0 comment '订购总数',
buying_total_amount decimal(16, 4) not null default 0 comment '进价总额(未税)',
buying_total_amount_with_tax decimal(16, 4) not null default 0 comment '进价总额(含税)',
selling_total_amount_with_tax decimal(16, 4) not null default 0 comment '门店售价总额(含税)',
district_code varchar(10) not null default '4201' comment '采购方所在区域, 城市编码',
audit_fail_reason varchar(100) default null comment '审核失败原因',
audited_by int default null comment '审核人',
created_at datetime not null comment '创建时间',
created_by int not null comment '特指后台创建人(公司员工 id)',
updated_at timestamp default CURRENT_TIMESTAMP not null comment '更新时间',
updated_by int not null comment '特指后台更新人(公司员工 id)',
remark varchar(255) default null comment '备注',
old_po_id bigint default 0 comment '关联的老采购单id',
old_do_id bigint default 0 comment '关联的老配送单id',
key idx_ticket_type(ticket_type),
key idx_purchase_status(purchase_status),
key idx_purchaser_supply_type(purchaser_type, supply_type),
key idx_purchaser_id(purchaser_id),
key idx_supply_id(supply_id),
key idx_created_at(created_at),
key idx_parent_id(parent_id),
unique key idx_po2_code(code, seq_no)
) comment '采购单主表' charset = utf8mb4;
drop table purchase_order_item2;
create table purchase_order_item2(
id bigint not null primary key comment '主键',
is_deleted tinyint(2) not null default 0 comment '是否已删除,1是,0否',
is_absence_distributed tinyint(2) not null default 0 comment '是否进行过缺货分配,1是,0否',
purchase_order_id bigint default 0 not null comment '关联的主单id',
upriver_purchase_item_id bigint default null comment '经由时,供应商到仓库端的采购子单id',
status tinyint(3) not null default 10 comment '采购子单状态,10:待验收(to_be_received);20:已验收(received);',
sku_no varchar(32) default '' not null comment '货号',
buying_price decimal(16, 4) not null default 0 comment '进价单价(未税),供应方为仓库时为供应商进价,供应方为仓库时为物流销价',
buying_tax decimal(6, 4) not null default 0 comment '进项税率,供应方为仓库时为进项税率,供应方为仓库时为物流销项税率',
selling_price decimal(16, 4) not null default 0 comment '售价单价(含税),采购方为门店时为门店售价,采购方为仓库时为物流销价',
selling_tax decimal(6, 4) not null default 0 comment '销项税率,采购方为门店时为门店售价,采购方为仓库时为物流销价',
buying_amount decimal(16, 4) default 0 not null comment '进价总金额(未税)',
buying_amount_with_tax decimal(16, 4) default 0 not null comment '进价总金额(含税)',
selling_amount decimal(16, 4) default 0 not null comment '售价总金额(未税)',
selling_amount_with_tax decimal(16, 4) default 0 not null comment '售价总金额(含税)',
purchase_total_num int default 0 not null comment '商品订购总数',
delivery_num int default 0 not null comment '发货数量',
receive_num int default 0 not null comment '收货数量',
adjust_delivery_num int not null comment '裁决发货数量',
adjust_receive_num int not null comment '裁决收货数量',
rejection_reason_type tinyint(3) default null comment '拒收原因类型,1:破损(broken);2:过期(time_out)',
sku_name varchar(64) default '' not null comment '商品名称',
shipping_method_value varchar(255) not null default '01' comment '温层',
spec varchar(64) default '' not null comment '规格',
sale_unit varchar(64) default '' not null comment '计价单位',
shelflife int default 0 not null comment '保质期',
shelflife_unit tinyint(2) default 5 not null comment '保质期单位,1:小时(hour);2:日(day);3:月(month);4:年(year);5:永久有效(for_ever)',
brand varchar(255) default '' not null comment '品牌',
category_code varchar(32) default '' not null comment '新类目code',
master_barcode varchar(32) not null default '' comment '国际条码(主)',
min_order_num int not null default 1 comment '最小订购数',
min_order_times int not null default 1 comment '最小订购倍数',
max_order_times int not null default 1 comment '最大订购倍数',
created_at datetime not null comment '创建时间',
created_by int not null comment '特指后台创建人(公司员工 id)',
updated_at timestamp default CURRENT_TIMESTAMP not null comment '更新时间',
updated_by int not null comment '特指后台更新人(公司员工 id)',
remark varchar(255) default null comment '备注',
old_poi_id bigint default 0 comment '关联的老采购子单id',
old_doi_id bigint default 0 comment '关联的老配送子单id',
key idx_purchase_order_id(purchase_order_id),
key idx_sku_no(sku_no)
) comment '采购单明细' charset = utf8mb4;
create table purchase_delivery(
id bigint not null primary key comment '主键,与关联的采购单id一致',
external_code varchar(50) default null comment '外部编号,如有供应商生成的编号,或仓库配送单编号',
reserve_status tinyint(3) default null comment '预约状态,10:待审核(to_be_audited);20:审核通过(audit_success);21:审核不通过(audit_fail)',
delivery_address varchar(255) default null default '' comment '配送地址',
car_no varchar(25) default null comment '车牌号',
driver_name varchar(15) default null comment '司机姓名',
driver_tel varchar(15) default null comment '司机电话',
delivery_start_at datetime default null comment '到仓时间区间开始',
delivery_end_at datetime default null comment '到仓时间区间结束',
storage_transfer_id bigint default null comment '关联的仓库调拨单',
contact_name varchar(100) default null comment '联系人名称,配送单到达方的联系人',
contact_tel char(15) default null comment '联系人电话',
created_at datetime not null comment '创建时间',
created_by int not null comment '特指后台创建人(公司员工 id)',
updated_at timestamp default CURRENT_TIMESTAMP not null comment '更新时间',
updated_by int not null comment '特指后台更新人(公司员工 id)',
remark varchar(255) default null comment '备注'
)comment '采购单物流附表' charset = utf8mb4;
create table purchase_finance(
id bigint not null primary key comment '主键,与关联的采购单id一致',
confirm_status tinyint(2) NOT NULL DEFAULT '1' COMMENT '确认状态,1:未确认(unsettled);2:已确认(settled);3:已锁定(locked)',
modify_status tinyint(2) NOT NULL DEFAULT '1' COMMENT '更正状态(财务结账后更正),1:未更正(uncorrected);2:已更正(corrected);3:红冲记录(red_corrected)',
check_date date DEFAULT NULL COMMENT '账表日',
closing_at datetime DEFAULT NULL COMMENT '结账日期',
closing_by int(11) DEFAULT NULL COMMENT '结账人',
finance_confirm_at datetime default null comment '财务确认日',
finance_confirm_by int default null comment '财务确认人',
created_at datetime not null comment '创建时间',
created_by int not null comment '特指后台创建人(公司员工 id)',
updated_at timestamp default CURRENT_TIMESTAMP not null comment '更新时间',
updated_by int not null comment '特指后台更新人(公司员工 id)',
remark varchar(255) default null comment '备注'
)comment '采购单财务附表' charset = utf8mb4;
修正单处理:
1. 收货,创建新的PO(缺货、拒收) recv_num = -2, delivery_num = 0
2. 仓库确认: delivery_num = -2
3. 裁决: adjust_recv, adjust_delivey。
操作 | receiveNum | deliveryNum | adjustReceiveNum | adjustDeliveryNum | purchaseTotalNum |
---|---|---|---|---|---|
创建 | -3 | 0 | -3 | 0 | 10 |
确认 | -3 | -1 | -3 | -1 | 10 |
裁决 | -3 | -1 | -2 | -2 | 10 |
收货模式:
1. 点验
receive_num = 实际收货数量, 没有修正单
2. 先收货,后验收
receive_num = delivery_num
rejectionNum > 0 有修正单,receiveNum = -rejectionNum adjustReceiveNum = -rejectionNum
absenceNum > 0 有修正单 receiveNum = -absenceNum
自动发货逻辑:
1. 经由:预计到货日发货,发货数量 = 订购数量
SELECT po2.* FROM purchase_order2 po2
WHERE po2.logistics_type = 2
AND po2.ticket_type = 1
AND po2.purchaser_type = 2
AND po2.supply_type = 3
AND po2.purchase_status = 30
AND TO_DAYS(po2.expected_arrival_at) = TO_DAYS(current_date);
2. 直纳:预计到货日发货,if(进行完纳分配) 发货数量 = 分配数量 else 发货数量 = 订购数量 (子单上增加缺货分配的标识)
3. 寄库:到仓日发货
发货数量 = 预约数量
待处理数据查询:
SELECT po2.* FROM purchase_order2 po2 LEFT JOIN purchase_delivery pd ON po2.id = pd.id
WHERE po2.logistics_type = 1
AND po2.ticket_type = 1
AND po2.purchaser_type = 2
AND po2.supply_type = 3
AND po2.purchase_status = 30
AND pd.reserve_status = 20
AND TO_DAYS(pd.delivery_start_at) = TO_DAYS(current_date);
预约单审核查询:
select po2.*, pd.* from purchase_order2 po2 left join purchase_delivery pd on po2.id = pd.id
where pd.reserve_status = 10;
预约逻辑:
1. 供应商发起预约,传入预约的主单(po2),预约的货物及数量
2.
已预约查询
if(预约货物少于剩余未预约数量 || po2 已预约过) {
创建po2,详情为预约的货物及对应数量(商品金额跟原po2保持一致)
自动审核,确认
if(po2 未预约) 原po2.status = 拆单关闭中
else if(预约货物等于剩余未预约数量) 原po2.status = 拆单关闭完成
}
// 发起预约
3. new StartDepositReservationAction(purchaseOrderId).execute
预约单审核:
if(审核通过) {
reserve_status = 审核通过
} else {
purchase_delivery.reserve_status = 审核失败
purchase_order2.purchase_status = 取消 (cancelPurchaseOrder)
}
预约次数 | po2 |
---|---|
po2(原) | |
1(部分预约) | po2(原),po2(新1) |
2(剩余部分预约) | po2(原),po2(新1),po2(新2) |
3(剩余全部预约) | po2(原),po2(新1),po2(新2),po2(新3) |
预约次数 | po2 |
---|---|
po2(原) | |
1(全部预约) | po2(原) |
po2(新1),po2(新2),po2(新3)的 parent_id
关联的是po2(原)的id,
寄库仓库收货回调:
1. 查询po2
2. po2原子方法收货
3. po2关联的原单据,如何处理?
对于寄库和经由:超期关闭,到了预计到货日仓库未验收
状态:
进货单:
门店转移:
退货单
自主退货需要审核
退供应商需要确认
报废单:
原子方法:严格按照基本的状态图设计。
status = ticketType match {
case 进货单 => 待审核
case 退货单 => 待验收
case 调拨单 => 待供应方发货
case 修正单 => 待确认
}
1. 合计子单上的总金额字段
buying_amount = PurchaseUtil.setScale(buyingPrice * purchaseTotalNum)
buying_amount_with_tax = PurchaseUtil.setScale(buyingPrice * purchaseTotalNum * (1 + buyingTax))
selling_amount_with_tax = PurchaseUtil.setScale(sellingPrice * purchaseTotalNum)
2. 合计主单上的总金额字段
purchase_total_num = items.map(_.purchaseTotalNum).sum
buying_total_amount = items.map(_.buyingAmount).sum
buying_total_amount_with_tax = item.map(_.buyingAmountWithTax).sum
selling_total_amount_with_tax = items.map(_.sellingAmountWithTax).sum
3. insert into purchase_order2
4. insert purchase_order_item2
status = 待验收
前置检查: status = 待审核
逻辑处理:
1. status = if(审核通过) 待确认 else 审核不通过
前置检查: status = 待确认
逻辑处理:
1. status = 待供应方发货
以下5种情况会调用发货
1. 仓库发货
2. 供应商发货
3. 门店转移转出发货
4. 仓库退货发货
5. 门店退仓货发货
6. 门店退供应商发货
前置检查:status = 待供应方发货
deliveryDetails.forall(发货数量 <= 订购数量)
逻辑处理:
1. status = 待验收
2. delivery_num = 发货数量
// 出库,调用库存原子方法
库存事件类型 = (ticketType, purchaserType, supplyType) match {
case (进货单, _, 仓库) =>
case (进货单, _, 门店) =>
case (退货单, 仓库, _) =>
case (退货单, 门店, 仓库) =>
case (退货单, 门店, 供应商) =>
case _ =>
}
以下5种情况会调用收货
1. 门店收货
2. 仓库收货
3. 店间转移转入收货
4. 门店退仓,仓库收货
5. 门店退货供应商收货
6. 仓库退货供应商收货
前置检查:status = 待验收,部分验收
receiveDetails.forall(收货数量 <= 发货数量)
已日结不能收货
逻辑处理:
1. receive_num = 收货数量
2. 子单status = 已验收
3. 主单status = 子单.forall(delivery_num == receive_num) 已验收 else 部分验收
// 第一次验收(主单==待验收)
// 如果存在拒收和缺货, 产生修正单,
拒收修正单详情 = 子单.filter(_.rejectionNum > 0).map { item =>
BeanBuild.build[PurchaseOrderItem2](item)(
"deliveryNum" -> 0,
"receiveNum" -> -item.rejectionNum
)
}
缺货修正单详情 = 子单.filter(_.absenceNum > 0).map { item =>
BeanBuild.build[PurchaseOrderItem2](item)(
"deliveryNum" -> 0,
"receiveNum" -> -item.absenceNum
)
}
// 非第一次验收(主单=部分验收|已验收)
// 更新修正单
// 库存更新同样区分是否初次
// 入库,调用库存原子方法
库存事件类型 = (ticketType, purchaserType, supplyType) match {
case (进货单, 门店, _) =>
case (进货单, 仓库, _) =>
case (退货单, 门店, 仓库) =>
case _ =>
}
前置检查:status = 待审核
逻辑处理:
1. 增删品项,修改数量
2. 更新主单对应数量,金额
前置检查:status != 部分验收,已验收
1. status = 已取消
2. 通知仓库单据取消
前置检查:status = 待确认
1. update deliveryNum = - 确认数量
2. status = items.forall(receiveNum == deliveryNum) 已完结 else 裁决中
前置检查:status = 裁决中
1. update adjustDeliveryNum = - 裁决数量, adjustReceiveNum = - 裁决数量
2. status = 已完结
遗留待解决:
UI层接口:https://www.zybuluo.com/Wahson/note/1206560
推进计划:
人员:曹璐,朱鹏
时间:7月16号(下周一)-7月25号 8天
1. 定义原子方法
2. 2天时间开发完原子方法
3. 开发UI接口
4. 设计开发数据比对程序
下周完成的业务线:
1.门店直纳叫货
门店叫货:
navi下直纳商品 => 生成直纳采购单(自动审核) => 定时器按照条件合并采购单 => 供应商平台接单 => 供应商发货(到了预计到货日自动发货) => 门店收货
涉及到的老接口:
1. 提交叫货单 CreateCallOrderAction
2. 自动汇总直纳采购单 AutoCreateSupplierOrderAction
3. 供应商接单 AcceptNonStopSupplierOrderAction
4. 供应商发货 AutoDeliveryAction
5. 门店收货 StoreReceiptAction
2.门店寄库
navi下寄库采购单 => 生成寄库采购单(自动审核、确认) => 数据推送wms => 仓库发货回抛 => 门店收货
涉及到的老接口:
1. 提交叫货单 CreateCallOrderAction
2. 推送wms PostDeliveryOrderToWmsAction
3. 仓库发货回抛 CreateStorageOutStockOrderForWMSAction
4. 门店收货 StoreReceiptAction
3.总部寄库
eywa下总部采购单 => 总部审核 => 数据推送wms => 供应商接单 => 供应商预约 => 预约单审核 => 供应商发货(到了预计到货日自动发货) => 仓库收货回抛
涉及到的老接口:
1. 提交采购单 CreateDepositPurchaseOrderAction
2. 审核采购单 AuditPurchaseOrderAction
3. 供应商接单 AcceptPurchaseOrderAction
4. 供应商预约 BookForDepositPurchaseOrderSubmitAction
5. 预约单审核 AuditDeliveryReservOrderAction
6. 供应商发货 AutoDeliveryAction
7. 仓库收货回抛 CreateStorageInStockOrderForWMSAction
4.巡回叫货(补单据)
navi 巡回收货 => 生成巡回采购单 => 自动审核 => 自动确认 => 自动发货 => 自动收货
涉及到的老接口:
1. 提交巡回叫货单 CreateTourCallOrderAction
原单据中裁决发货和收货数量应该是多少
AutoCreateViaPurchaseOrderAction
CreateSmokePurchaseOrderAction
CreateStoreNonStopRefundOrderAction
1. 创建退货单
2. 自动审核
1. 创建退货单
2. 自动审核
3. 自动确认
1. 创建退货单
1. 创建退货单
2. 自动审核
报废单(创建,撤销)
总部裁决