Files
GateDge2023_ljy/07.珠海英搏尔/Enpower.Python/POSH_CB_PROCOSTRESULTREC/产品成本还原查询报表_20240819.py
PastSaid 9725ab5376 a
2024-12-05 15:39:19 +08:00

211 lines
9.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import clr
clr.AddReference("System")
clr.AddReference("Kingdee.BOS")
clr.AddReference("Kingdee.BOS.Core")
clr.AddReference("Kingdee.BOS.DataEntity")
clr.AddReference("Kingdee.BOS.App")
clr.AddReference("Kingdee.BOS.Contracts")
clr.AddReference("Kingdee.BOS.ServiceHelper")
from Kingdee.BOS import*
from Kingdee.BOS.Util import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.DependencyRules import *
from Kingdee.BOS.Core.Metadata.EntityElement import *
from Kingdee.BOS.Orm.DataEntity import*
from Kingdee.BOS.Orm.Metadata.DataEntity import*
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.Args import *
from Kingdee.BOS.Core.CommonFilter import *
from System import *
from System.ComponentModel import*
from System.Collections.Generic import*
from System.Text import*
from Kingdee.BOS.ServiceHelper import *
from Kingdee.BOS.KDThread import *
# 产品成本汇总快捷查询
# POSH_PRODUCTCOSTQUICKQUERY
# showParameter = None
_whereSql = ""
def BarItemClick(e):
# 新增过滤窗口
if e.BarItemKey == "tbShowFilterForm":
# global showParameter
# if showParameter == None:
showParameter = FilterShowParameter();
showParameter.FormId = "POSH_PRODUCTCOSTQUICKQUERY_FILTER";
showParameter.ParentPageId = this.View.PageId;
this.View.ShowForm(showParameter,lambda x:ShowReturnData(x));
def GetExecCost(billNo,period,acctgOrgId):
sqlL = """/*dialect*/
EXEC TEST_CB_CPCBHYFXIBB_COMPUTE '{0}',{1},{2}
""".format(billNo,period,acctgOrgId)
res = DBServiceHelper.ExecuteDynamicObject(this.Context, sqlL)
return res;
def ShowReturnData(resultData):
global _whereSql
dateVal = ""
whereSql = ""
if resultData.ReturnData is None:
return
else:
filterString = resultData.ReturnData.FilterString;
if filterString != None and filterString != "":
whereSql += " AND " + filterString.replace("FBILLNO","t0.FPRODUCTNO").replace("FACCTGORGID","t2.FACCTGORGID");
customFilter = resultData.ReturnData.CustomFilter;
if customFilter != None:
FYear = customFilter["FYear"]
FPeriod = customFilter["FPeriod"]
yearVal = 0 if FYear == None or FYear == "" else int(FYear)
periodVal = 0 if FPeriod == None or FPeriod == "" else int(FPeriod)
if yearVal > 0:
if periodVal > 0:
dateVal = str(yearVal * 100 + periodVal)
whereSql += " AND (t2.FYEAR * 100 + t2.FPERIOD) = {0} ".format(dateVal)
else:
whereSql += " AND t2.FYEAR = {0} ".format(yearVal)
FSelMoBillNo = customFilter["FSelMoBillNo"]
moBillNo = "" if FSelMoBillNo == None else FSelMoBillNo
if moBillNo != "":
whereSql += " AND t0.FPRODUCTNO = '{0}' ".format(moBillNo)
# raise Exception(whereSql)
if whereSql == "":
raise Exception("查询条件不能为空!")
else:
_whereSql = whereSql
ShowProgressBar();
def DocCompute(whereSql):
# whereSql = _whereSql
moSqlL = """/*dialect*/
DECLARE @ACCTGORGID int
SET @ACCTGORGID = 1
;WITH #列表数据 AS (
SELECT t0.FPRODUCTNO
,t0.FBILLID
,t0.FBILLENTRYID
,t0.FPRODUCTID
,t0.FFORMID
,t1.FPRODUCTDIMEID
,t3.FQUALIFIEDINQTY AS '本期完工数量'
,t3.FCURRINPUTQTY AS '本期投入数量'
,t3.FSUMCURRINPUTQTY AS '累计投入数量'
,t3.FSUMQUALIFIEDINQTY AS '累计完工数量'
,RANK() OVER (PARTITION BY t0.FBILLID,t0.FBILLENTRYID ORDER BY (t2.FYEAR * 100 + t2.FPERIOD) DESC) 'RN'
,(t2.FYEAR * 100 + t2.FPERIOD) AS 'FPERIOD'
,t2.FACCTGORGID
FROM T_CB_PROORDERDIME t0
INNER JOIN V_CB_PROORDERINFO t1 on t1.FPRODUCTDIMEID = t0.FPRODUCTDIMEID
INNER JOIN V_HS_OUTACCTG t2 on t1.FACCTGID = t2.FID
LEFT JOIN V_CB_COSTCALEXPENSE t3 on t3.FID = t1.FID
WHERE 1 = 1
AND t2.FCOMPUTEID != ''
AND t1.FENDINITKEY = 1
AND t0.FFORMID = 'PRD_MO'
{0}
)
SELECT t0.*,t1.FNUMBER,t1_l.FNAME
FROM #列表数据 t0
INNER JOIN T_BD_MATERIAL t1 on t1.FMATERIALID = t0.FPRODUCTID
INNER jOIN T_BD_MATERIAL_L t1_l on t1_l.FMATERIALID = t0.FPRODUCTID AND t1_l.FLOCALEID = 2052
WHERE t0.RN = 1
""".format(whereSql)
# raise Exception(moSqlL);
proEntity = this.View.Model.BusinessInfo.GetEntryEntity("FEntity")
proRows = this.View.Model.GetEntityDataObject(proEntity)
this.View.Model.BeginIniti();
proRows.Clear()
datas = DBServiceHelper.ExecuteDynamicObject(this.Context, moSqlL);
if datas != None and datas.Count > 0:
# raise Exception(str(datas.Count));
# this.View.Session["ProcessRateValue"] = 1
num = 0;
count = datas.Count
for data in datas:
row = DynamicObject(proEntity.DynamicObjectType)
period = data["FPERIOD"]
billNo = data["FPRODUCTNO"]
acctgOrgId = data["FACCTGORGID"]
# row["FRN"] = data["FRN"]
row["FMoBillNo"] = billNo
row["FProMaterialNumber"] = data["FNUMBER"]
row["FProMaterialName"] = data["FNAME"]
row["FQUALIFIEDINQTY"] = data["本期完工数量"]
_cResult = "错误"
# raise Exception("AAAA2");
num = num + 1
this.View.Session["ProcessRateValue"] = int(num * 100/ count);
this.View.Session["ProcessTips"] = "{0}条数据,已处理{1}条数据,正在处理{2}".format(count,(num-1),billNo);
costDataList = GetExecCost(billNo, period, acctgOrgId)
if costDataList != None and costDataList.Count > 0:
costData = costDataList[0]
_cResult = "完成"
row["FMaterialCostQ"] = float(costData["原材料Q1"])
row["FLaborCostS"] = costData["直接人工S"]
row["FProcessCostO"] = costData["制造费用O"]
row["FQ_O_S_T_R"] = costData["原材料Q1"] + costData["直接人工S"] + costData["制造费用O"]
row["FMaterialCostT"] = costData["间接材料Q2"]
row["FO2"] = costData["制造费用_职工薪酬"]
row["FO3"] = costData["制造费用_股份支付"]
row["FO4"] = costData["制造费用_劳动保护费"]
row["FO5"] = costData["制造费用_差旅费"]
row["FO6"] = costData["制造费用_业务招待费"]
row["FO7"] = costData["制造费用_办公费"]
row["FO8"] = costData["制造费用_折旧与摊销"]
row["FO9"] = costData["制造费用_租赁费"]
row["FO10"] = costData["制造费用_水电费"]
row["FO11"] = costData["制造费用_物料消耗"]
row["FO12"] = costData["制造费用_加工_修理_检测费"]
row["FO13"] = costData["制造费用_车辆使用费"]
row["FO14"] = costData["制造费用_其他"]
row["FO15"] = costData["制造费用_委外加工费"]
row["FALLHRWORKTIME"] = costData["总工时"]
row["FResult"] = _cResult
proRows.Add(row)
# raise Exception("AAAA3");
this.View.UpdateView("FEntity")
this.View.Model.EndIniti();
def showRslt(asynResult):
if (asynResult != None and asynResult.Exception != None):
this.View.ShowErrMessage(asynResult.Exception.Message);
#进度条达到100%之后,关闭进度条弹窗,回调此方法,弹出提示信息
def showFinishMsg(formResult):
this.View.ShowMessage("数据加载完成!");
def ShowProgressBar():
#调试执行任务时,可以先通过这两行调试任务执行代码
#因为启用进度条之后,是在子线程中运行,不方便分析代码问题。调试成功之后,再屏蔽这两行,启用进度条
# setData();
# return;
progressFormParameter = DynamicFormShowParameter();
progressFormParameter.PageId = Guid.NewGuid().ToString();
progressFormParameter.FormId = "BOS_ReportProgressMsg";
progressFormParameter.OpenStyle.ShowType = ShowType.Modal;
progressFormParameter.Caption = "正在加载数据...";
progressFormParameter.HiddenCloseButton = True;
#true表示使用真实进度在执行任务的方法中更新进度值代码示例this.View.Session["ProcessRateValue"] =10
progressFormParameter.CustomParams.Add("UseTruePro", "true");
this.View.ShowForm(progressFormParameter,Action[FormResult](showFinishMsg));
MainWorker.QuequeTask(this.Context,Action(setData),Action[AsynResult](showRslt));
#自定义方法,在这里实现加载数据的任务,需要根据自己的个性化编写代码
def setData():
DocCompute(_whereSql)
#根据代码执行过程大致估算出进度值整数最后一定要有100%,否则进度弹窗无法自动关闭
this.View.Session["ProcessRateValue"] = 100;
#本案例是通过值更新事件,选择年份或者月份的时候,动态加载出对应的数据