Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with disp as (
- select
- case when (count(*) over(PARTITION by disp_249."cDLCode") != count(*) over(PARTITION by disp_253."cDLCode") ) then '已补单但条目数不一致' else null end "条目数状态",
- case when Inventory_249."cInvCCode" not like '0304%' and (disp_249."cBatch" != COALESCE(disp_253."cBatch", '')) then '已补单但批次不一致' else null end "批次状态",
- case when (disp_249."iSum" :: FLOAT != COALESCE(disp_253."iSum" :: float, 0) ) then '已补单但原币含税合计不一致' else null end "原币含税合计状态",
- case when (disp_249."iTaxUnitPrice":: FLOAT != COALESCE(disp_253."iTaxUnitPrice" :: FLOAT, 0)) then '已补单但原币含税单价不一致' else null end "原币含税单价状态",
- case when (disp_249."cCusCode") != COALESCE(disp_253."cCusCode", '') then '已补单但客户名称不一致' else null end "客户名称状态",
- case when disp_253."AutoID" is null then '缺发货单' else null end "发货单状态",
- case when (disp_249."iQuantity" != COALESCE(disp_253."iQuantity", '')) then '已补单但数量不一致' else null end "数量状态",
- case when disp_249."dverifydate" !='2021-11-07' and (disp_249."dverifydate" != COALESCE(disp_253."dverifydate", '')) then '已补单但审核日期不一致' else null end "审核日期状态",
- case when disp_253."dDate"!='2021-11-07' and (disp_249."dDate" != COALESCE(disp_253."dDate", '')) then '已补单但单据日期不一致' else null end "单据日期状态",
- disp_249."dDate" "006单据日期",
- disp_253."dDate" "009单据日期",
- disp_249.dverifydate "006dverifydate",
- disp_253.dverifydate "009dverifydate",
- disp_249."AutoID" "006发货单标识",
- so_249."iSOsID" "006销售单标识",
- disp_253."AutoID" "009发货单标识",
- so_253."iSOsID" "009销售单标识",
- disp_249."cBatch" "006发货单批次",
- disp_253."cBatch" "009发货单批次",
- disp_249."iQuantity" "006发货数量",
- disp_253."iQuantity" "009发货数量",
- disp_253."dverifydate" "009审核日期",
- disp_249."cCusName" "006客户名称",
- disp_253."cCusName" "009客户名称",
- disp_249."iSum" "006原币含税合计",
- disp_253."iSum" "009原币含税合计",
- disp_249."iTaxUnitPrice" "006原币含税单价",
- disp_253."iTaxUnitPrice" "009原币含税单价",
- sales."cUser_Name" cUser_Name,
- Inventory_249."cInvCCode",
- count(*) over(PARTITION by disp_249."cDLCode") "006发货条数",
- count(*) over(PARTITION by disp_253."cDLCode") "009发货条数",
- disp_249.*
- from fdw_u8db.disp_249 disp_249
- left join fdw_u8db.so_249 so_249
- on so_249."iSOsID" = disp_249."iSOsID"
- left join fdw_u8db."Inventory_249" Inventory_249
- on so_249."cInvCode" = Inventory_249."cInvCode"
- left join fdw_u8db."UA_User" sales
- on sales."cUser_Id" = so_249."cMainPersonCode"
- left join fdw_u8db.so_253
- on(
- so_249."cSOCode" = so_253."cSOCode"
- and
- so_249."cInvCode" = so_253."cInvCode"
- and
- COALESCE(so_249."cFree1", '') = COALESCE(so_253."cFree1", '')
- and
- so_249."iQuantity"::FLOAT = so_253."iQuantity"::FLOAT
- )
- left join fdw_u8db.disp_253
- on (
- so_253."iSOsID" = disp_253."iSOsID"
- and disp_249."cDLCode" = disp_253."cDLCode"
- )
- ORDER BY disp_249."cDLCode"
- )
- SELECT
- disp."cInvCode",
- COALESCE(
- max(case when pos_sum."cInvCode" != disp."cInvCode" then '货号不一致,缺生产' else null end) over (PARTITION by disp."cDLCode"),
- max(case when disp."009审核日期" is null and pos_sum."iquantity" :: float < disp."006发货数量"::float then '库存数量不足,不能发货' else null end) over (PARTITION by disp."cDLCode"),
- max (disp."发货单状态") over (PARTITION by disp."cDLCode"),
- disp."条目数状态",
- max(disp."原币含税合计状态") over (PARTITION by disp."cDLCode"),
- max(disp."原币含税单价状态") over (PARTITION by disp."cDLCode"),
- max(disp."单据日期状态") over (PARTITION by disp."cDLCode"),
- disp."客户名称状态",
- max(disp."批次状态") over (PARTITION by disp."cDLCode"),
- max(disp."数量状态") over (PARTITION by disp."cDLCode"),
- case when disp."009审核日期" is null then '客服已做单, 数据无误 ,缺审核' else null end,
- max(disp."审核日期状态") over (PARTITION by disp."cDLCode"),
- '正常'
- ) 状态,
- disp."006单据日期",
- disp."009单据日期",
- disp."单据日期状态",
- disp."006dverifydate",
- disp."009dverifydate",
- disp."审核日期状态",
- disp."006发货条数",
- disp."009发货条数",
- disp."条目数状态",
- disp."006原币含税合计",
- disp."009原币含税合计",
- disp."原币含税合计状态",
- disp."006原币含税单价",
- disp."009原币含税单价",
- disp."原币含税单价状态",
- disp."006发货数量",
- disp."009发货数量",
- disp."数量状态",
- disp."006发货单批次",
- disp."009发货单批次",
- disp."批次状态",
- disp."006客户名称",
- disp."009客户名称",
- disp."客户名称状态",
- case when pos_sum."cInvCode" is null then '缺生产' else null end "生产状态",
- case when pos_sum."iquantity" :: float < disp."009发货数量" :: FLOAT then '库存数量不足,不能发货' else null end "发货状态",
- case when disp."009审核日期" is null then '缺审核' else null end "审核状态",
- pos_sum."iquantity" :: FLOAT 现有库存量,
- disp."DLID" ID,
- disp."cDLCode" 发货退货单号,
- disp."cInvCode" "货号",
- disp."cCusName" 客户名称,
- disp."iQuantity" 数量,
- disp."iTaxUnitPrice" 原币含税单价,
- disp."iSum"原币价税合计,
- disp."cBatch" 批号,
- disp."cuser_name" SO业务人员,
- disp."cMaker" 制单人,
- disp."iBatch" 批次,
- disp."cPosition" 货位,
- disp."cVouchType" 单据类型编码,
- disp."cBusType" 业务类型,
- disp."dDate" 单据日期 ,
- disp."cRdCode" 收发类别编码 ,
- disp."cDepCode" 部门编码,
- disp."cPersonCode" 业务员编码,
- disp."cSoCode" 销售订单号,
- disp."cSBVCode" 销售发票号,
- disp."cCusCode" 客户编码 ,
- disp."ccusperson" 客户联系人,
- disp."cShipAddress" 发往地址,
- disp."cexch_name" 币种名称,
- disp."disp_m_iTaxRate" 表头税率,
- disp."disp_m_cMemo" 表头备注,
- disp."dcreatesystime" 制单时间,
- disp."cVerifier" 审核人,
- disp."dverifydate" 审核日期,
- disp."cmodifier" 修改人,
- disp."dmoddate" 修改日期,
- disp."cAccounter" 记账人 ,
- disp."cinvoicecompany" 开票单位编码,
- disp."AutoID" 发货退货单子表标识,
- disp."cWhCode" 仓库编码 ,
- disp."cInvCode" 存货编码,
- disp."cInvName" 存货名称 ,
- disp."disp_d_iTaxRate" 表体税率,
- disp."cFree1" 规格,
- disp."disp_d_cMemo" 表体备注,
- disp."iSOsID" 销售订单子表标识 ,
- disp."iDLsID" "发货退货单子表标识2",
- disp."cSoCode" 表体销售订单号 ,
- disp."cordercode" 订单号,
- disp."cDefine29" 跨表备注,
- disp."cSCloser" 关闭人,
- disp."cbaccounter" 表体记账人,
- disp."cdemandid" 需求跟踪id
- from disp
- left join (
- select
- InvPositionSum_253."cInvCode",
- case when Inventory_249."cInvCCode" like '0304%' then '' else InvPositionSum_253."cBatch" end "cBatch",
- sum(InvPositionSum_253."iQuantity" :: FLOAT) iQuantity
- from fdw_u8db."InvPositionSum_253" InvPositionSum_253
- left join fdw_u8db."Inventory_249" Inventory_249
- on InvPositionSum_253."cInvCode" = Inventory_249."cInvCode"
- group by (InvPositionSum_253."cInvCode"), case when Inventory_249."cInvCCode" like '0304%' then '' else InvPositionSum_253."cBatch" end
- )pos_sum
- on disp."cInvCode" = pos_sum."cInvCode"
- and case when disp."cInvCCode" like '0304%' then '' else disp."cBatch" end = pos_sum."cBatch"
- ORDER BY disp."cDLCode"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement