(轉)https://www.hefeiyu.com/?p=1329
成本阶:99 原料无工单(采购料件) ima08=P/V/Z
- 原料有工单有BOM
- 成品或半成品有工单无BOM
cca_file 库存成本期初
ccb_file 库存成本当月入库调整金额
ccc_file 库存月加权成本
ccg_file 每月工单主件在制成本(依工单别的分批在制成本) 即工单上阶成本
cch_file 每月工单元件在制成本 即工单下阶成本
cct_file 拆件单头
ccu_file 拆件单身
先进先出
Cxa_file
Cxb_file
计算范围:
有下列情况之一的料件,均纳入计算范围:
1 tlf档当期有异动的料件 tlf
2当期有投入工时的料件 ccj
3有工单备料且有投入工时的料件 sfa/sfb/ccj
4当期有上阶在制成本的料件(ccg有余额)
5当期有下阶在制成本的料件(cch未余额)
6有库存期初开帐的料件cca
7当期工单有期初在制开帐金额的料件 ccf
8当期工单有在制调整金额的料件ccl
9当期工单有工单发退料异动的料件sfb/tlf
select 成本阶ima57, 料号ima01,须计算重工否ccd03,低阶码ima16,来源码ima08,分群码ima06,其他分群码ima09-11,成本分群码ima12,
where ima料号=tlf 料号 and tlf异动日期为当前期间 and tlf902仓库不为JIT仓库 and 仓库不为0 ##tlf档当期有异动的料件
UNION
Where ima料号=工单档sfb料号 and 投入工时ccj01在当期期间 and ccj04工单号=工单档工单号sfb01 ##当期有投入工时的料件
UNION
Where ima料号=备料档料号sfa03 and 投入工时ccj01在当期期间 and ccj04工单号=工单档工单号sfb01 and sfa备料档料号=sfb工单档料号 ##有工单备料且有投入工时的料件
UNION
Where ima料号=在制成本档料号ccg and 在制成本为当期 and ccg91/92当期在制成本数量或单价不为零 ##当期有上阶在制成本的料件
UNION
Where ima料号=在制成本元件档cch料号 and 在制成本为当期 and cch91/92当期在制成本数量或单价不为零 ##当期有下阶在制成本的料件
UNION
Where ima料号=库存期初开帐料号cca ##有库存期初开帐的料件
UNION
Where ccf 期初在制开帐金额档料号=工单档料号sfb and ima料号=sfb工单料号 and 期初在制开帐金额不为零 ##当期工单有期初在制开帐金额的料件
UNION
Where ccl当期在制调整金额料号=工单料号ima and ima 料号=工单料号sfb
##当期工单有在制调整金额的料件
UNION
Where (未结案工单sfb38 is null or结案日在当前期间内) and ima料号=工单料号sfb05 and tlf单据日期在当前期间内 and tlf工单单号=sfb工单单号 and tlf13异动命令代号为“asfi5*” ##当期工单有工单发退料异动的料件
例如:
SELECT ima57,ima01,ccd03,ima16,ima08,ima06, ima09,ima10,ima11,ima12
FROM ima_file,tlf_file,OUTER ccd_file
WHERE ima57=ccd01 AND ima01 matches ‘*’ AND ima01 NOT MATCHES ‘MISC*’
AND ima01 = tlf01 AND tlf06 BETWEEN ’00/01/01′ AND ’00/01/31′
AND tlf902 NOT IN (SELECT jce02 FROM jce_file) AND tlf907 != 0
GROUP BY 1,2,3,4,5,6,7,8,9,10
UNION
SELECT ima57,ima01,ccd03,ima16,ima08,ima06, ima09,ima10,ima11,ima12
FROM ima_file, ccj_file,sfb_file,OUTER ccd_file
WHERE ima57=ccd01 AND ima01 matches ‘*’ AND ima01 NOT MATCHES ‘MISC*’
AND ima01 = sfb05 AND ccj01 BETWEEN ’00/01/01′ AND ’00/01/31′
AND ccj04 = sfb01
GROUP BY 1,2,3,4,5,6,7,8,9,10
UNION
SELECT ima57,ima01,ccd03,ima16,ima08,ima06, ima09,ima10,ima11,ima12
FROM ima_file, ccj_file,sfb_file,sfa_file,OUTER ccd_file
WHERE ima57=ccd01 AND ima01 matches ‘*’ AND ima01 NOT MATCHES ‘MISC*’
AND ima01 = sfa03 AND ccj01 BETWEEN ’00/01/01′ AND ’00/01/31′
AND ccj04 = sfb01 AND sfb01 = sfa01
GROUP BY 1,2,3,4,5,6,7, 8,9,10
UNION
SELECT ima57,ima01,ccd03,ima16,ima08,ima06, ima09,ima10,ima11,ima12
FROM ima_file, ccg_file,OUTER ccd_file
WHERE ima57=ccd01 AND ima01 matches ‘*’ AND ima01 NOT MATCHES ‘MISC*’
AND ima01 = ccg04 AND ccg02= 1999 AND ccg03= 12
AND (ccg91 !=0 OR ccg92 !=0 OR ccg92a !=0 OR ccg92b !=0
OR ccg92c!=0 OR ccg92d !=0 OR ccg92e !=0 )
GROUP BY 1,2,3,4,5,6,7,8,9,10
UNION
SELECT ima57,ima01,ccd03,ima16,ima08,ima06, ima09,ima10,ima11,ima12
FROM ima_file,cch_file,OUTER ccd_file
WHERE ima57=ccd01 AND ima01 matches ‘*’ AND ima01 NOT MATCHES ‘MISC*’
AND ima01 = cch04 AND cch02=1999 AND cch03=12
AND (cch91!=0 OR cch92 !=0 OR cch92a!=0 OR cch92b !=0 OR cch92c!=0
OR cch92d !=0 OR cch92e !=0 )
GROUP BY 1,2,3,4,5,6,7,8,9,10
UNION
SELECT ima57,ima01,ccd03,ima16,ima08,ima06, ima09,ima10,ima11,ima12
FROM ima_file,cca_file,OUTER ccd_file
WHERE ima57=ccd01 AND ima01 matches ‘*’ AND ima01 NOT MATCHES ‘MISC*’
AND ima01=cca01 AND cca02= 1999 AND cca03= 12
GROUP BY 1,2,3,4,5,6,7,8,9,10
UNION
SELECT ima57,ima01,ccd03,ima16,ima08,ima06, ima09,ima10,ima11,ima12
FROM ima_file,ccf_file,sfb_file,OUTER ccd_file
WHERE ima57=ccd01 AND ima01 matches ‘*’ AND ima01 NOT MATCHES ‘MISC*’
AND ccf01=sfb01 AND ima01 = sfb05 AND ccf02=1999 AND ccf03=12
AND (ccf11 !=0 OR ccf12!=0 OR ccf12a !=0 OR ccf12b !=0 OR ccf12c !=0
OR ccf12d !=0 OR ccf12e !=0 )
GROUP BY 1,2,3,4,5,6,7,8,9,10
UNION
SELECT ima57,ima01,ccd03,ima16,ima08,ima06, ima09,ima10,ima11,ima12
FROM ima_file,ccl_file,sfb_file,OUTER ccd_file
WHERE ima57=ccd01 AND ima01 matches ‘*’ AND ima01 NOT MATCHES ‘MISC*’
AND ccl01 = sfb01 AND ima01 = sfb05 AND ccl02= 2000 AND ccl03= 1
GROUP BY 1,2,3,4,5,6,7,8,9,10
UNION
SELECT ima57,ima01,ccd03,ima16,ima08,ima06,ima09,ima10,ima11,ima12
FROM ima_file,tlf_file,sfb_file,OUTER ccd_file
WHERE ima57=ccd01 AND ima01 matches ‘*’ AND ima01 NOT MATCHES ‘MISC*’
AND (sfb38 BETWEEN ’00/01/01′ AND ’00/01/31′ OR sfb38 IS NULL )
AND ima01 = sfb05 AND tlf06 BETWEEN ’00/01/01′ AND ’00/01/31′
AND tlf62 = sfb01 and tlf13[1,5] = ‘asfi5’
GROUP BY 1,2,3,4,5,6,7,8,9,10
INTO TEMP tlf_temp WITH NO LOG
计算过程:
排序方式:UNIQUE ima57,ima01,ccd03,ima16 ima57 desc/ima16/ima01
成本阶为99 :1、ccc清零,取上期结存转本期期初
2、由tlf 计算入出库数量,由apb101计算入库(采购)成本
3、加上入库调整金额
4、计算所有出库成本及结存
5、更新ccc-file
成本阶不为99:1、处理当前成本阶所有料件重工
2、ccc清零,取上期结存转本期期初
3、处理WIP在制成本
4、由tlf 计算入出库数量,入库成本(外购料件)
5、加上入库调整金额
6、加上WIP入库金额
7、计算所有出库成本及结存
8、更新ccc-file
处理重工
重工处理过程:
以当前成本阶的所有料件为计算范围,
1、p500_rework1先处理重工WIP及完成品入库,
p500_wip_rework处理重工在制成本(以重工工单sfb99=Y为范围),步骤与处理一般在制相同:wip_1计算主件部分成本;wip_2计算元件投入成本;wip_3计算元件转出成本;wip_4处理主件SUM成本。
2、p500_rework2计算所有重工出库成本及结存,
p500_ccg2_cost加上WIP重工入库成本(ccg32在制转出金额àccc28);
p500_ccc_tot(2) 计算所有出库成本及结存;
3、记录拆件式工单的投入及转出 (sfb02=11)
找所有拆件式工单;
wipx_1计算拆件式WIP主件部分成本;
wipx_2计算拆件式WIP元件投入成本;
wipx_3计算拆件式WIP元件转出成本;
wipx_4计算拆件式WIP主件SUM成本;
p500_ccc_tot(2)计算所有出库成本及结存;
MAIN
删除本期已有资料,取上期结存转本期期初p500_last0
找计算范围(取本期有异动之资料计算tlf)
抓资料到 tlf_tmp
fetch 成本阶/料号/重工否/低阶码 (按成本阶降序排列) 来计算
FOR EACH
IF 当前料件成本阶不同
PUSH 料号
P500_rework 重工处理 (本成本阶所有料件)
POP 料号
END IF
保存当前料件料号g_ima01_t
将当前料件当期成本档归零 ccc_file p500_ccc_0
取料件上期结存p500_last
IF 当前料件不是原料(成本阶数不为99)
处理WIP在制成本 p500_wip
END IF
由tlf_file 计算入出库数量及采购成本 p500_tlf
加入出库调整金额 p500_ccb_cost
IF 当前料件不是原料(成本阶数不为99)
加上WIP入库金额 p500_ccg_cost
END IF
计算所有出库成本及结存 p500_ccc_tot(1)
计算结果写入当期成本档p500_ccc_ins
END FOREACH
IF 上一料号为NULL 则 上一料号置零
IF 上一成本阶为NULL 则上一成本阶置零
第二次处理重工p500_rework
END MAIN
P500_last0()
Delete 本期成本资料
DELETE FROM ccc_file WHERE ccc02= 2000 AND ccc03= 1 AND ccc01 IN(SELECT ima01 FROM ima_file WHERE ima01 matches ‘*’ AND ima01 NOT MATCHES ‘MISC*’)
取上期及开帐成本
SELECT ima01 FROM ccc_file,ima_file WHERE ccc02=1999 AND ccc03=12 AND ccc01=ima01 AND ima01 matches ‘*’ AND ima01 NOT MATCHES ‘MISC*’
UNION SELECT ima01 FROM cca_file,ima_file WHERE cca02= 1999 AND cca03= 12 AND cca01=ima01 AND ima01 matches ‘*’ AND ima01 NOT MATCHES ‘MISC*’
CALL p500_ccc_0() 清零
SELECT * INTO g_ccc.* FROM ccc_file WHERE ccc01 = l_ima01 AND ccc02=last_yy AND ccc03=last_mm 先取上月结存
SELECT * INTO l_cca.* FROM cca_file WHERE cca01=g_ccc.ccc01 AND cca02=last_yy AND cca03=last_mm 再取期初开帐
P500_rework()
取当前料件成本阶的ccd03 (须计算重工否)
IF须重工
先计算WIP及完成品入库p500_rework1
再计算所有出库成本及结存p500_rework2
记录WIP-拆件式工单在制成本(工单性质为11)目的为取重工后单价 p500_wipx0
END IF
END p500_rework2
P500_rework1()
在须计算的资料中抓当前料件异动资料 tlf_tmp
FOREACH 料件
从ccc_file 中抓当期资料,否则置零
处理WIP重工成本(重工 sfb99=y —工单档sfb_file 重工否) p500_wip_rework
end foreach
end p500_rework1
p500_rework2()
在须计算的资料中抓当前成本阶所有料件异动资料 tlf_tmp
FOREACH 料件
从ccc_file 中抓当期资料,否则置零
加上WIP重工入库金额p500_ccg2_cost
计算所有出库成本及结存 p500_ccc_tot(2)
更新ccc_file p500_ccc_upd
end
end
p500_wipx0()
在须计算的资料中抓当前料件异动资料 tlf_tmp
FOREACH 料件
从ccc_file 中抓当期资料,否则置零
p500_wipx
end
end
p500_last0()
取上期结存转本月期初
p500_tlf
对某一料件由tlf档分类统计入出库数量
并分别取入库成本,出库成本暂未处理
( 由tlf 取异动单类型XXX/单号XXX1/项次XXX2)
WHEN tlf13[1,4]=’axmt’ OR tlf13 = ‘aomt800′ 销货领出
LET g_ccc.ccc61=g_ccc.ccc61+q_tlf.tlf10*u_sign
CALL p500_ccc63_cost(u_sign)
IF u_sign = 1 THEN
LET g_ccc.ccc64=g_ccc.ccc64+q_tlf.tlf10*u_sign
END IF
WHEN q_tlf.tlf13=’aimt301′ OR q_tlf.tlf13=’aimt311’
##报废异动(aimt303,aimt313)应列入杂项异动中
OR q_tlf.tlf13 = ‘aimt303′ OR q_tlf.tlf13 =’aimt313′
LET g_ccc.ccc41=g_ccc.ccc41+q_tlf.tlf10*u_sign
WHEN q_tlf.tlf13[1,5]=’asfi5′ #工单发料
IF g_sfb99=’Y’ THEN #重工领出
LET g_ccc.ccc25=g_ccc.ccc25+q_tlf.tlf10*u_sign
ELSE #一般工单领出
LET g_ccc.ccc31=g_ccc.ccc31+q_tlf.tlf10*u_sign
END IF
WHEN q_tlf.tlf13[1,5]=’asft6′ #工单入库
IF q_tlf.tlf02 = 65 OR q_tlf.tlf03 = 65 THEN #拆件工单(成本由WIP处理)
LET g_ccc.ccc31=g_ccc.ccc31+q_tlf.tlf10*u_sign
ELSE
IF g_sfb99=’Y’ THEN #重工入库(成本由重工WIP转出)
LET g_ccc.ccc27=g_ccc.ccc27+q_tlf.tlf10*u_sign
ELSE #一般入库
LET g_ccc.ccc21=g_ccc.ccc21+q_tlf.tlf10*u_sign
CALL p500_ccc22_cost() #取成本
END IF
END IF
WHEN q_tlf.tlf13 = ‘aimt302’ OR q_tlf.tlf13 = ‘aimt312′
LET g_ccc.ccc21=g_ccc.ccc21+q_tlf.tlf10
LET g_ccc.ccc43=g_ccc.ccc43+q_tlf.tlf10
CALL p500_ccc22_cost()
U_flag为入出库标志
WHEN u_flag=’1′ #一般工单入库、采购入、仓退
LET g_ccc.ccc21=g_ccc.ccc21+q_tlf.tlf10*u_sign
CALL p500_ccc22_cost() #取入库成本
WHEN u_flag=’5′ #调整
LET g_ccc.ccc51=g_ccc.ccc51+q_tlf.tlf10*u_sign
WHEN u_flag=’6’ #盘差
LET g_ccc.ccc71=g_ccc.ccc71+q_tlf.tlf10*u_sign
OTHERWISE CONTINUE FOREACH
p500_ccc22_cost()
取入库成本
工单入库成本暂不处理 (tlf13 MATCHES ‘asf*’)
工单入库成本应由WIP转入,故加工费于wip_2_22()归入投入成本,再转入库
如为委外退库暂不处理
IF q_tlf.tlf13 matches ‘apmt107*’ THEN
LET l_pmm02=NULL
SELECT pmm02 INTO l_pmm02 FROM pmm_file WHERE pmm01=q_tlf.tlf036
AND pmm18 <> ‘X’
IF l_pmm02=’SUB’ THEN RETURN END IF #–>委外退库亦由WIP转出
END IF
WHEN q_tlf.tlf13 MATCHES ‘aimt30*’ #杂项入zzz
CALL p500_ccc44_cost()
LET amt=l_ccc23 * q_tlf.tlf10 * u_sign
WHEN q_tlf.tlf13 = ‘aimt720’ OR #调拨入zzz
q_tlf.tlf13 = ‘aimp700’ OR q_tlf.tlf13 = ‘aimp701′
LET amt = g_ccc.ccc23 * q_tlf.tlf10 #直接取上月平均单价
OTHERWISE #取发发票请款立帐金额
SELECT apa44,SUM(apb101) #帐款单身成本分摊本币金额
为了配合成本分摊作业aapt900 故改apb10为取apb101
FROM apb_file,apa_file
WHERE apb21=xxx1 AND apb22=xxx2 ##xxx1为tlf单据号,xxx2为项次
AND apb01=apa01 AND apa00 = ’11’ #帐款性质为进货发票
AND apa75 != ‘Y’ AND apa42 = ‘N’ #非外购资料且未作废帐款
AND apa02 BETWEEN g_bdate AND g_edate
GROUP BY 1
问题:为何不判断确认否???apa41=Y
SELECT apa44,SUM(apb101) # 扣除折让部分(退货)
FROM apb_file,apa_file
WHERE apb21=xxx1 AND apb22=xxx2 AND apb01=apa01
AND apa00 = ’21’ AND apa58 = ‘2’ AND apa75 != ‘Y’ #帐款为退货折让
AND apa42 = ‘N’
AND apa02 BETWEEN g_bdate AND g_edate
GROUP BY 1
金额取绝对值
若为外购信用状入库则取到货分摊后金额 sum(ale09)
SELECT alk72,SUM(ale09)
FROM ale_file ,alk_file
WHERE ale16=xxx1 AND ale17=xxx2 AND ale01=alk01
GROUP BY 1
更新tlf 档,其中杂收不更新,由axct500确定
IF q_tlf.tlf13 != ‘aimt302’ and q_tlf.tlf13 != ‘aimt312′ THEN
UPDATE tlf_file SET (tlf21,tlf221,tlf222,tlf2231,tlf2232,tlf224,
tlf211,tlf212,tlf65)
=(amt,amta,amtb,amtc,amtd,amte,TODAY,g_time,l_apa44)
WHERE ROWID=q_tlf_rowed
p500_ccc44_cost()
取杂项入库成本
先取本月杂项入库金额档inb_file (手工维护)
如无单价则取期初开帐金额 cca_file
仍无单价则取上月平均ccc_file ccc23
p500_ccc63_cost()
本月销货收入
p500_ccb_cost()
加入库库调整金额
p500_ccg_cost()
加上WIP入库金额(工单主件在制成本)
非重工的、非预测工单、非拆件式工单的工单主件在制成本
p500_ccg2_cost()
加上WIP重工入库金额
重工的、非预测工单、非拆件式工单的工单主件在制成本
p500_ccc_tot(1 or 2)
计算所有出库成本及结存
1à第一阶段,先不处理重工
2à第二阶段,处理重工
if 2 则处理重工 p500_ccc_ccc26 ccc26重工领出金额
p500_ccc_ccc23 ccc23本月平均单价
IF 第一阶段且当前成本阶不须计算重工 或 第二阶段
LET 本月工单领用成本=0 g_ccc_ccc32
LET 本月杂项领用成本=0 42
LET 本月其他领用成本=0 52
LET 本月销货成本=0 62/62a/62b/62c/62d/62e
LET 本月盘盈亏金额=0 72
LET 本月销退成本=0 66/66a-e
P500_tlf21_upd
END IF
LET 本月结存数量ccc91=上月结存数量ccc11+本月入库数量ccc21(采购入+工单入+委外入)+本月重工领出ccc25+本月重工入库数量ccc27+本月工单领用数量ccc31+本月杂项领用数量ccc41+本月其他调整数量ccc51+本月销货数量ccc61+本月盘盈亏数量ccc71
LET 本月结存金额ccc92=上月结存金额ccc12+本月入库金额ccc22(材料22a+人工22b+制费22c+加工22d+其他22e)+本月重工领出金额ccc26+本月重工入库金额ccc28+本月工单领用成本ccc32+本月杂项领用成本ccc42+本月其他调整成本ccc52+本月销货成本ccc62+本月盘盈亏金额ccc72
销退数量ccc64和销退成本ccc66未考虑???
LET 本月结存材料金额=本月结存数量ccc91*本月平均单价-材料ccc223a
人工
制费
委外
其他
差异金额ccc93
p500_ccc_ccc26
处理重工领出金额
p500_ccc_ccc23()
计算本月重工工单部分的平均单价
先取期初开帐,再取上月余额进行计算平均单价
p500_tlf_upd()
更新tlf 档单价
p500_ccc_ins()
更新ccc档成本金额
p500_cch_0()
将工单元件在在制成本档按上月期末转本月期初,其余归零
p500_cch_01()
将工单元件在在制成本档全部归零
wip_del()
删除工单在制成本档(ccg/cch)
p500_wip()
处理WIP工单在制成本(工单性质1/7)
SELECT * FROM sfb_file #找当前料件在制工单(非重工)
WHERE sfb05 =g_ima01
AND sfb02!= ’13’ AND sfb02 != ’11’
AND (sfb99 IS NULL OR sfb99 = ‘ ‘ OR sfb99=’N’)
AND (sfb38 IS NULL OR sfb38 >= g_bdate) # 工单成会结帐日
AND (sfb81 IS NULL OR sfb81 <= g_edate) # 工单开立日期
ORDER BY sfb01
先delete ccg/cch wip_del
计算每张工单的WIP主件部分成本(ccg) wip_1()
计算每张工单的WIP元件投入成本(cch) wip_2()
计算每张工单的WIP元件转出成本(cch) wip_3()
计算每张工单的WIP主件SUM成本(ccg) wip_4()
p500_wip_rework()
处理WIP-REWORK在制成本(重工sfb99=’Y’)
先delete ccg/cch wip_del2
计算每张工单的WIP主件部分成本(ccg) wip_1()
计算每张工单的WIP元件投入成本(cch) wip_2()
计算每张工单的WIP元件转出成本(cch) wip_3()
计算每张工单的WIP主件SUM成本(ccg) wip_4()
wip_1()
计算每张工单的WIP主件部分成本(ccg)
将mccg归零p500_mccg_0
wip上期期末数量转本期期初(先取在制工单成本数量ccg91,再取在制开帐档数量ccf11)
工时统计wip_ccg20(取ccj档工单合计工时)
计算每张工单WIP主件转出数量wip_ccg31 (取tlf档成品入库-成品退库)
更新ccg_file
wip_ccg20()
SELECT SUM(ccj05) INTO mccg.ccg20 FROM ccj_file #取ccj档工单合计工时
WHERE ccj04=g_sfb.sfb01 AND ccj01 BETWEEN g_bdate AND g_edate
Wip_ccg31()
计算工单WIP主件转出数量
SELECT SUM(tlf10*tlf60) INTO g_make_qty FROM tlf_file # 当月成品入库量
WHERE tlf62=g_sfb.sfb01 AND tlf06 BETWEEN g_bdate AND g_edate
AND (tlf03 = 50)
AND tlf13 MATCHES ‘asft6*’
AND (tlf01 = g_sfb.sfb05)
SELECT SUM(tlf10*tlf60) INTO g_make_qty2 FROM tlf_file #当月成品退库量
WHERE tlf62=g_sfb.sfb01 AND tlf06 BETWEEN g_bdate AND g_edate
AND (tlf02 = 50)
AND tlf13 MATCHES ‘asft6*’
AND (tlf01 = g_sfb.sfb05)
转出数量(以负数表示)=退库量-入库量
wip_ccg21()
计算每张工单的WIP主件投入数量
抓工单发料底稿sfq的成套发料(sfp=1)-成套退料(sfp=6)
wip_2()
计算每张工单的WIP元件‘期初/本期投入成本’cch
step1. WIP元件上期末转本期期初 wip_2_1
step2-1 WIP元件本期投入材料(依工单发料/退料档) wip_2_21
计算每张工单的WIP主件投入数量 wip_ccg21
step2-2 WIP元件 本期投入人工制费 wip_2_22
step2-3 WIP元件 本期投入调整成本 wip_2_23
wip_2_1()
先取cch档上期转本期期初
再取ccf在制开帐档转本期期初
wip_2_21()
WIP元件 本期投入材料(依工单发/退料档) 同时结出投入金额
SELECT tlf01,ima08,ima57,tlf02,tlf03,tlf13,SUM(tlf10*tlf60*tlf907*-1),
SUM(tlf21*tlf907*-1),SUM(tlf221*tlf907*-1),SUM(tlf222*tlf907*-1),
SUM(tlf2231*tlf907*-1)
FROM tlf_file,ima_file
WHERE tlf62=g_sfb.sfb01 AND tlf06 BETWEEN g_bdate AND g_edate
AND ((tlf02=50 AND tlf03 BETWEEN 60 AND 69) OR
(tlf03=50 AND tlf02 BETWEEN 60 AND 69))
AND tlf01=ima01 AND tlf10<>0
AND tlf13 MATCHES ‘asfi5*’ #工单发退料
AND tlf907 != 0
GROUP BY 1,2,3,4,5,6
主件料号=元件料号 表示重工
成本阶相等ima57 =ima57_t表示重工
成本阶较小ima57<ima57_t 表示重工
取发料单价
本阶重工者取重工前库存月平均 (本月ccc12+ccc22)
上阶重工者取上月库存月平均
无单价取上月库存月平均 (上月ccc23)
仍无单价取上期库存开帐单价(上月cca23)
非重工则取本月库存月平均 (当月ccc23)
wip_2_22()
WIP元件 本期投入人工制费
由cck每月人工/制费/工时档抓取
委外加工成本=委外入库(apb101)-委外退库(apb101)
wip_2_23()
WIP元件 本期投入调整成本
由ccl 在制调整成本档抓取
wip_32()
WIP元件 本期转出成本(实际成本)
先判断本期转出元件数量(依标准QPA计算)
按工时分配人工制费
若本期仅发生加工费且已完工入库,则全数转出
若当期未转出即结案,则归入差异成本
计算本期结存成本
p500_sub()
替代件转出
wip_4()
计算每张工单WIP主件成本ccg
取cch-àccg ,取半成品cch-à ccg , 所有cch-半成品cch(元件转出成本) = 本阶主件投入成本
p500_wipx() 拆件式工单投入及拆件转出
处理WIP在制成本
wipx_1 计算每张工单的WIP 主件部分成本(cct)
wipx_2 计算每张工单的WIP 元件投入成本(ccu)
wipx_3计算每张工单的WIP 元件转出成本(ccu)
wipx_4 计算每张工单的WIP 主件SUM成本(cct)
p500_ccc_tot(2) 计算所有出库成本及结存
p500_ccc_upd update ccc_file
wipx_1()
计算每张拆件式工单的WIP主件部分成本
将mcct清零
wipx_cct20 统计工时
wipx_2()
计算每张拆件式工单的WIP元件‘期初/本期投入’成本(ccu)
wipx2_1 WIP元件 上期期末转本期期初
wipx2_21 WIP元件 本期投入材料(依拆件式工单发/退料单)
wipx2_22 WIP元件 本期投入人工制费
wipx2_23 WIP元件 本期投入调整成本
wipx_3()
WIP元件 本期转出成本
取当月库存月平均档,拆出元件取本月算出加权平均单价
wipx_2_24() 计算期末(工单未结案)或差异(工单已结案)
wipx_4()
计算每张拆件式工单WIP主件成本(cct)
沒有留言:
張貼留言