[关闭]
@Wahson 2018-10-18T10:44:15.000000Z 字数 12769 阅读 787

PurchaseOrder2

工作


数据模型:

  1. create table purchase_order2(
  2. id bigint not null primary key comment '主键',
  3. code varchar(30) not null default '' comment '单号',
  4. seq_no tinyint(2) not null default 0 comment '财务序号,财务结账后再进行更正时,原单不变,新建一张红冲单、一张更正单,序号相应增加',
  5. source tinyint(2) NOT NULL DEFAULT '0' COMMENT '单据来源,1:PC(pc);2:PDA(pda);3:人工补录(manual_record)',
  6. is_force tinyint(2) not null default 0 comment '是否强配: 1是,0否',
  7. ticket_type tinyint(3) not null default 1 comment '单据类型:1:进货单(stock);2:退货单(refund);3:调拨单(transfer);4:缺货修正单(absence_correct);5:拒收修正单(rejection_correct)',
  8. ticket_type_code varchar(5) not null default '' comment '单据类型编码',
  9. origin_id bigint default null comment '修正单源单id',
  10. parent_id bigint default null comment '父单id,针对总部采购多次预约拆单逻辑',
  11. supplier_order_id bigint default null comment '直纳订单,关联的供应商订单id',
  12. 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)',
  13. purchaser_type tinyint(3) not null default 1 comment '采购方类型,1:门店(store);2:仓库(storage)',
  14. supply_type tinyint(3) not null default 1 comment '供应方类型,1:门店(store);2:仓库(storage);3:供应商(supplier)',
  15. purchaser_id varchar(20) not null default '' comment '采购方编号,门店财务店号/仓库编号',
  16. purchaser_name varchar(100) not null default '' comment '采购方名称',
  17. supply_id varchar(20) not null default '' comment '供应方编号,门店财务店号/仓库编号/供应商编号(厂编)',
  18. supply_name varchar(100) not null default '' comment '供应方名称',
  19. shipping_method varchar(10) not null default '01' comment '温层',
  20. logistics_type tinyint(3) not null default 1 comment '配送方式,1:寄库(deposit);2:经由(via);3:巡回(tour);4:直纳(nonstop);5:直送(direct)',
  21. purchase_at datetime not null default current_timestamp() comment '订购日',
  22. delivery_time int not null default 0 comment '配送时长,单位天',
  23. expected_arrival_at datetime not null default current_timestamp() comment '预计到货日',
  24. actual_arrival_at datetime default null comment '实际到货日',
  25. accept_at datetime default null comment '验收日',
  26. purchase_total_num int not null default 0 comment '订购总数',
  27. buying_total_amount decimal(16, 4) not null default 0 comment '进价总额(未税)',
  28. buying_total_amount_with_tax decimal(16, 4) not null default 0 comment '进价总额(含税)',
  29. selling_total_amount_with_tax decimal(16, 4) not null default 0 comment '门店售价总额(含税)',
  30. district_code varchar(10) not null default '4201' comment '采购方所在区域, 城市编码',
  31. audit_fail_reason varchar(100) default null comment '审核失败原因',
  32. audited_by int default null comment '审核人',
  33. created_at datetime not null comment '创建时间',
  34. created_by int not null comment '特指后台创建人(公司员工 id)',
  35. updated_at timestamp default CURRENT_TIMESTAMP not null comment '更新时间',
  36. updated_by int not null comment '特指后台更新人(公司员工 id)',
  37. remark varchar(255) default null comment '备注',
  38. old_po_id bigint default 0 comment '关联的老采购单id',
  39. old_do_id bigint default 0 comment '关联的老配送单id',
  40. key idx_ticket_type(ticket_type),
  41. key idx_purchase_status(purchase_status),
  42. key idx_purchaser_supply_type(purchaser_type, supply_type),
  43. key idx_purchaser_id(purchaser_id),
  44. key idx_supply_id(supply_id),
  45. key idx_created_at(created_at),
  46. key idx_parent_id(parent_id),
  47. unique key idx_po2_code(code, seq_no)
  48. ) comment '采购单主表' charset = utf8mb4;
  49. drop table purchase_order_item2;
  50. create table purchase_order_item2(
  51. id bigint not null primary key comment '主键',
  52. is_deleted tinyint(2) not null default 0 comment '是否已删除,1是,0否',
  53. is_absence_distributed tinyint(2) not null default 0 comment '是否进行过缺货分配,1是,0否',
  54. purchase_order_id bigint default 0 not null comment '关联的主单id',
  55. upriver_purchase_item_id bigint default null comment '经由时,供应商到仓库端的采购子单id',
  56. status tinyint(3) not null default 10 comment '采购子单状态,10:待验收(to_be_received);20:已验收(received);',
  57. sku_no varchar(32) default '' not null comment '货号',
  58. buying_price decimal(16, 4) not null default 0 comment '进价单价(未税),供应方为仓库时为供应商进价,供应方为仓库时为物流销价',
  59. buying_tax decimal(6, 4) not null default 0 comment '进项税率,供应方为仓库时为进项税率,供应方为仓库时为物流销项税率',
  60. selling_price decimal(16, 4) not null default 0 comment '售价单价(含税),采购方为门店时为门店售价,采购方为仓库时为物流销价',
  61. selling_tax decimal(6, 4) not null default 0 comment '销项税率,采购方为门店时为门店售价,采购方为仓库时为物流销价',
  62. buying_amount decimal(16, 4) default 0 not null comment '进价总金额(未税)',
  63. buying_amount_with_tax decimal(16, 4) default 0 not null comment '进价总金额(含税)',
  64. selling_amount decimal(16, 4) default 0 not null comment '售价总金额(未税)',
  65. selling_amount_with_tax decimal(16, 4) default 0 not null comment '售价总金额(含税)',
  66. purchase_total_num int default 0 not null comment '商品订购总数',
  67. delivery_num int default 0 not null comment '发货数量',
  68. receive_num int default 0 not null comment '收货数量',
  69. adjust_delivery_num int not null comment '裁决发货数量',
  70. adjust_receive_num int not null comment '裁决收货数量',
  71. rejection_reason_type tinyint(3) default null comment '拒收原因类型,1:破损(broken);2:过期(time_out)',
  72. sku_name varchar(64) default '' not null comment '商品名称',
  73. shipping_method_value varchar(255) not null default '01' comment '温层',
  74. spec varchar(64) default '' not null comment '规格',
  75. sale_unit varchar(64) default '' not null comment '计价单位',
  76. shelflife int default 0 not null comment '保质期',
  77. shelflife_unit tinyint(2) default 5 not null comment '保质期单位,1:小时(hour);2:日(day);3:月(month);4:年(year);5:永久有效(for_ever)',
  78. brand varchar(255) default '' not null comment '品牌',
  79. category_code varchar(32) default '' not null comment '新类目code',
  80. master_barcode varchar(32) not null default '' comment '国际条码(主)',
  81. min_order_num int not null default 1 comment '最小订购数',
  82. min_order_times int not null default 1 comment '最小订购倍数',
  83. max_order_times int not null default 1 comment '最大订购倍数',
  84. created_at datetime not null comment '创建时间',
  85. created_by int not null comment '特指后台创建人(公司员工 id)',
  86. updated_at timestamp default CURRENT_TIMESTAMP not null comment '更新时间',
  87. updated_by int not null comment '特指后台更新人(公司员工 id)',
  88. remark varchar(255) default null comment '备注',
  89. old_poi_id bigint default 0 comment '关联的老采购子单id',
  90. old_doi_id bigint default 0 comment '关联的老配送子单id',
  91. key idx_purchase_order_id(purchase_order_id),
  92. key idx_sku_no(sku_no)
  93. ) comment '采购单明细' charset = utf8mb4;
  94. create table purchase_delivery(
  95. id bigint not null primary key comment '主键,与关联的采购单id一致',
  96. external_code varchar(50) default null comment '外部编号,如有供应商生成的编号,或仓库配送单编号',
  97. reserve_status tinyint(3) default null comment '预约状态,10:待审核(to_be_audited);20:审核通过(audit_success);21:审核不通过(audit_fail)',
  98. delivery_address varchar(255) default null default '' comment '配送地址',
  99. car_no varchar(25) default null comment '车牌号',
  100. driver_name varchar(15) default null comment '司机姓名',
  101. driver_tel varchar(15) default null comment '司机电话',
  102. delivery_start_at datetime default null comment '到仓时间区间开始',
  103. delivery_end_at datetime default null comment '到仓时间区间结束',
  104. storage_transfer_id bigint default null comment '关联的仓库调拨单',
  105. contact_name varchar(100) default null comment '联系人名称,配送单到达方的联系人',
  106. contact_tel char(15) default null comment '联系人电话',
  107. created_at datetime not null comment '创建时间',
  108. created_by int not null comment '特指后台创建人(公司员工 id)',
  109. updated_at timestamp default CURRENT_TIMESTAMP not null comment '更新时间',
  110. updated_by int not null comment '特指后台更新人(公司员工 id)',
  111. remark varchar(255) default null comment '备注'
  112. )comment '采购单物流附表' charset = utf8mb4;
  113. create table purchase_finance(
  114. id bigint not null primary key comment '主键,与关联的采购单id一致',
  115. confirm_status tinyint(2) NOT NULL DEFAULT '1' COMMENT '确认状态,1:未确认(unsettled);2:已确认(settled);3:已锁定(locked)',
  116. modify_status tinyint(2) NOT NULL DEFAULT '1' COMMENT '更正状态(财务结账后更正),1:未更正(uncorrected);2:已更正(corrected);3:红冲记录(red_corrected)',
  117. check_date date DEFAULT NULL COMMENT '账表日',
  118. closing_at datetime DEFAULT NULL COMMENT '结账日期',
  119. closing_by int(11) DEFAULT NULL COMMENT '结账人',
  120. finance_confirm_at datetime default null comment '财务确认日',
  121. finance_confirm_by int default null comment '财务确认人',
  122. created_at datetime not null comment '创建时间',
  123. created_by int not null comment '特指后台创建人(公司员工 id)',
  124. updated_at timestamp default CURRENT_TIMESTAMP not null comment '更新时间',
  125. updated_by int not null comment '特指后台更新人(公司员工 id)',
  126. remark varchar(255) default null comment '备注'
  127. )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. 1. 点验
  2. receive_num = 实际收货数量, 没有修正单
  3. 2. 先收货,后验收
  4. receive_num = delivery_num
  5. rejectionNum > 0 有修正单,receiveNum = -rejectionNum adjustReceiveNum = -rejectionNum
  6. absenceNum > 0 有修正单 receiveNum = -absenceNum

自动发货逻辑:

  1. 1. 经由:预计到货日发货,发货数量 = 订购数量
  2. SELECT po2.* FROM purchase_order2 po2
  3. WHERE po2.logistics_type = 2
  4. AND po2.ticket_type = 1
  5. AND po2.purchaser_type = 2
  6. AND po2.supply_type = 3
  7. AND po2.purchase_status = 30
  8. AND TO_DAYS(po2.expected_arrival_at) = TO_DAYS(current_date);
  9. 2. 直纳:预计到货日发货,if(进行完纳分配) 发货数量 = 分配数量 else 发货数量 = 订购数量 (子单上增加缺货分配的标识)
  10. 3. 寄库:到仓日发货
  11. 发货数量 = 预约数量
  12. 待处理数据查询:
  13. SELECT po2.* FROM purchase_order2 po2 LEFT JOIN purchase_delivery pd ON po2.id = pd.id
  14. WHERE po2.logistics_type = 1
  15. AND po2.ticket_type = 1
  16. AND po2.purchaser_type = 2
  17. AND po2.supply_type = 3
  18. AND po2.purchase_status = 30
  19. AND pd.reserve_status = 20
  20. AND TO_DAYS(pd.delivery_start_at) = TO_DAYS(current_date);
  1. 预约单审核查询:
  2. select po2.*, pd.* from purchase_order2 po2 left join purchase_delivery pd on po2.id = pd.id
  3. where pd.reserve_status = 10;
  1. 预约逻辑:
  2. 1. 供应商发起预约,传入预约的主单(po2),预约的货物及数量
  3. 2.
  4. 已预约查询
  5. if(预约货物少于剩余未预约数量 || po2 已预约过) {
  6. 创建po2,详情为预约的货物及对应数量(商品金额跟原po2保持一致)
  7. 自动审核,确认
  8. if(po2 未预约) po2.status = 拆单关闭中
  9. else if(预约货物等于剩余未预约数量) po2.status = 拆单关闭完成
  10. }
  11. // 发起预约
  12. 3. new StartDepositReservationAction(purchaseOrderId).execute
  1. 预约单审核:
  2. if(审核通过) {
  3. reserve_status = 审核通过
  4. } else {
  5. purchase_delivery.reserve_status = 审核失败
  6. purchase_order2.purchase_status = 取消 cancelPurchaseOrder
  7. }
预约次数 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. 寄库仓库收货回调:
  2. 1. 查询po2
  3. 2. po2原子方法收货
  4. 3. po2关联的原单据,如何处理?

对于寄库和经由:超期关闭,到了预计到货日仓库未验收

状态:
进货单:

Created with Raphaël 2.1.2开始待审核审核?待确认24小时内确认?待供应方发货待验收部分验收,已验收End超时关闭审核不通过yesnoyesno

门店转移:

Created with Raphaël 2.1.2开始待验收已验收End
Created with Raphaël 2.1.2开始待确认撤销?已取消End已报废yesno
Created with Raphaël 2.1.2开始待供应方发货待验收已验收End
Created with Raphaël 2.1.2开始待确认裁决中已完结End
原子方法:严格按照基本的状态图设计。

原子方法 28h

  1. status = ticketType match {
  2. case 进货单 => 待审核
  3. case 退货单 => 待验收
  4. case 调拨单 => 待供应方发货
  5. case 修正单 => 待确认
  6. }
  7. 1. 合计子单上的总金额字段
  8. buying_amount = PurchaseUtil.setScale(buyingPrice * purchaseTotalNum)
  9. buying_amount_with_tax = PurchaseUtil.setScale(buyingPrice * purchaseTotalNum * (1 + buyingTax))
  10. selling_amount_with_tax = PurchaseUtil.setScale(sellingPrice * purchaseTotalNum)
  11. 2. 合计主单上的总金额字段
  12. purchase_total_num = items.map(_.purchaseTotalNum).sum
  13. buying_total_amount = items.map(_.buyingAmount).sum
  14. buying_total_amount_with_tax = item.map(_.buyingAmountWithTax).sum
  15. selling_total_amount_with_tax = items.map(_.sellingAmountWithTax).sum
  16. 3. insert into purchase_order2
  17. 4. insert purchase_order_item2
  18. status = 待验收
  1. 前置检查: status = 待审核
  2. 逻辑处理:
  3. 1. status = if(审核通过) 待确认 else 审核不通过
  1. 前置检查: status = 待确认
  2. 逻辑处理:
  3. 1. status = 待供应方发货
  1. 以下5种情况会调用发货
  2. 1. 仓库发货
  3. 2. 供应商发货
  4. 3. 门店转移转出发货
  5. 4. 仓库退货发货
  6. 5. 门店退仓货发货
  7. 6. 门店退供应商发货
  8. 前置检查:status = 待供应方发货
  9. deliveryDetails.forall(发货数量 <= 订购数量)
  10. 逻辑处理:
  11. 1. status = 待验收
  12. 2. delivery_num = 发货数量
  13. // 出库,调用库存原子方法
  14. 库存事件类型 = (ticketType, purchaserType, supplyType) match {
  15. case (进货单, _, 仓库) =>
  16. case (进货单, _, 门店) =>
  17. case (退货单, 仓库, _) =>
  18. case (退货单, 门店, 仓库) =>
  19. case (退货单, 门店, 供应商) =>
  20. case _ =>
  21. }
  1. 以下5种情况会调用收货
  2. 1. 门店收货
  3. 2. 仓库收货
  4. 3. 店间转移转入收货
  5. 4. 门店退仓,仓库收货
  6. 5. 门店退货供应商收货
  7. 6. 仓库退货供应商收货
  8. 前置检查:status = 待验收,部分验收
  9. receiveDetails.forall(收货数量 <= 发货数量)
  10. 已日结不能收货
  11. 逻辑处理:
  12. 1. receive_num = 收货数量
  13. 2. 子单status = 已验收
  14. 3. 主单status = 子单.forall(delivery_num == receive_num) 已验收 else 部分验收
  15. // 第一次验收(主单==待验收)
  16. // 如果存在拒收和缺货, 产生修正单,
  17. 拒收修正单详情 = 子单.filter(_.rejectionNum > 0).map { item =>
  18. BeanBuild.build[PurchaseOrderItem2](item)(
  19. "deliveryNum" -> 0,
  20. "receiveNum" -> -item.rejectionNum
  21. )
  22. }
  23. 缺货修正单详情 = 子单.filter(_.absenceNum > 0).map { item =>
  24. BeanBuild.build[PurchaseOrderItem2](item)(
  25. "deliveryNum" -> 0,
  26. "receiveNum" -> -item.absenceNum
  27. )
  28. }
  29. // 非第一次验收(主单=部分验收|已验收)
  30. // 更新修正单
  31. // 库存更新同样区分是否初次
  32. // 入库,调用库存原子方法
  33. 库存事件类型 = (ticketType, purchaserType, supplyType) match {
  34. case (进货单, 门店, _) =>
  35. case (进货单, 仓库, _) =>
  36. case (退货单, 门店, 仓库) =>
  37. case _ =>
  38. }
  1. 前置检查:status = 待审核
  2. 逻辑处理:
  3. 1. 增删品项,修改数量
  4. 2. 更新主单对应数量,金额
  1. 前置检查:status != 部分验收,已验收
  2. 1. status = 已取消
  3. 2. 通知仓库单据取消
  1. 前置检查:status = 待确认
  2. 1. update deliveryNum = - 确认数量
  3. 2. status = items.forall(receiveNum == deliveryNum) 已完结 else 裁决中
  1. 前置检查:status = 裁决中
  2. 1. update adjustDeliveryNum = - 裁决数量, adjustReceiveNum = - 裁决数量
  3. 2. status = 已完结

遗留待解决:

UI层接口:https://www.zybuluo.com/Wahson/note/1206560

推进计划:
人员:曹璐,朱鹏
时间:7月16号(下周一)-7月25号 8天
1. 定义原子方法
2. 2天时间开发完原子方法
3. 开发UI接口
4. 设计开发数据比对程序

下周完成的业务线:
1.门店直纳叫货

  1. 门店叫货:
  2. navi下直纳商品 => 生成直纳采购单(自动审核) => 定时器按照条件合并采购单 => 供应商平台接单 => 供应商发货(到了预计到货日自动发货) => 门店收货
  3. 涉及到的老接口:
  4. 1. 提交叫货单 CreateCallOrderAction
  5. 2. 自动汇总直纳采购单 AutoCreateSupplierOrderAction
  6. 3. 供应商接单 AcceptNonStopSupplierOrderAction
  7. 4. 供应商发货 AutoDeliveryAction
  8. 5. 门店收货 StoreReceiptAction

2.门店寄库

  1. navi下寄库采购单 => 生成寄库采购单(自动审核、确认) => 数据推送wms => 仓库发货回抛 => 门店收货
  2. 涉及到的老接口:
  3. 1. 提交叫货单 CreateCallOrderAction
  4. 2. 推送wms PostDeliveryOrderToWmsAction
  5. 3. 仓库发货回抛 CreateStorageOutStockOrderForWMSAction
  6. 4. 门店收货 StoreReceiptAction

3.总部寄库

  1. eywa下总部采购单 => 总部审核 => 数据推送wms => 供应商接单 => 供应商预约 => 预约单审核 => 供应商发货(到了预计到货日自动发货) => 仓库收货回抛
  2. 涉及到的老接口:
  3. 1. 提交采购单 CreateDepositPurchaseOrderAction
  4. 2. 审核采购单 AuditPurchaseOrderAction
  5. 3. 供应商接单 AcceptPurchaseOrderAction
  6. 4. 供应商预约 BookForDepositPurchaseOrderSubmitAction
  7. 5. 预约单审核 AuditDeliveryReservOrderAction
  8. 6. 供应商发货 AutoDeliveryAction
  9. 7. 仓库收货回抛 CreateStorageInStockOrderForWMSAction

4.巡回叫货(补单据)

  1. navi 巡回收货 => 生成巡回采购单 => 自动审核 => 自动确认 => 自动发货 => 自动收货
  2. 涉及到的老接口:
  3. 1. 提交巡回叫货单 CreateTourCallOrderAction
  1. code 编码生成规则整理
  2. 总部预约逻辑整理
  3. 报废单逻辑
  4. 数据比对
  5. 原单据中裁决发货和收货数量应该是多少

    • 经由叫货 6h
  1. AutoCreateViaPurchaseOrderAction
  1. CreateSmokePurchaseOrderAction
  1. CreateStoreNonStopRefundOrderAction
  2. 1. 创建退货单
  3. 2. 自动审核
  1. 1. 创建退货单
  2. 2. 自动审核
  3. 3. 自动确认
  1. 1. 创建退货单
  1. 1. 创建退货单
  2. 2. 自动审核
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注