结算清单-保存重算单价
在结算清单保存时,需要重算单价。根据销售出库单上自定义的一个单价,替代结算清单上的单价。
话不多说,贴代码:
public override void OnPreparePropertys(PreparePropertysEventArgs e)
{
base.OnPreparePropertys(e);
e.FieldKeys.Add("FAcctOrgId"); //核算组织
e.FieldKeys.Add("FMapAcctOrgId"); //供货方(核算组织)
e.FieldKeys.Add("FBizFormId"); //业务单据名称
e.FieldKeys.Add("FBizEntryId"); //业务单据分录内码
e.FieldKeys.Add("FBizID"); //业务单据内码
e.FieldKeys.Add("FCurrencyId"); //结算币别
e.FieldKeys.Add("FQty"); //计价单位数量
e.FieldKeys.Add("FPrice"); //结算价格
e.FieldKeys.Add("FAllAmount"); //价税合计
e.FieldKeys.Add("FAmount"); //结算金额
e.FieldKeys.Add("FTaxAmount"); //税额
e.FieldKeys.Add("FSettleReconciliationAmount"); //结算对账金额
e.FieldKeys.Add("FSettleReconciliationAllAmount"); //结算对账价税合计
e.FieldKeys.Add("FSettleReconciliationTaxAmount"); //结算对账税额
e.FieldKeys.Add("FSumAcount"); //应收结算汇总金额
e.FieldKeys.Add("FSUMALLACOUNT"); //结算价税合计
e.FieldKeys.Add("FTaxPrice"); //含税单价
}
public override void EndOperationTransaction(EndOperationTransactionArgs e)
{
base.EndOperationTransaction(e);
foreach (var item in e.DataEntitys)
{
DynamicObject AcctOrgId = item["AcctOrgId"] as DynamicObject;
DynamicObject MapAcctOrgId = item["MapAcctOrgId"] as DynamicObject;
string fromId = this.BusinessInfo.GetForm().Id;
if (AcctOrgId != null && MapAcctOrgId != null)
{
string AcctOrgIdNumber = AcctOrgId["Number"].ToString();
string MapAcctOrgIdNumber = MapAcctOrgId["Number"].ToString();
bool PD1 = fromId.Equals("IOS_ARSettlement") && AcctOrgIdNumber.Equals("100") && MapAcctOrgIdNumber.Equals("105");
bool PD2 = fromId.Equals("IOS_APSettlement") && AcctOrgIdNumber.Equals("105") && MapAcctOrgIdNumber.Equals("100");
//核算组织 100,供货方组织105
if (PD1 || PD2)
{
DynamicObjectCollection DetailEntity = item["DetailEntity"] as DynamicObjectCollection;
object FSETTLECURRID = null;
foreach (var entityRow in DetailEntity)
{
DynamicObject BizFormId = entityRow["BizFormId"] as DynamicObject;
if (BizFormId != null && BizFormId["Name"].ToString().Equals("销售出库单"))
{
//根据SQL拿到
// string querySQL = string.Format(@" select t1.FTAXPRICE,t2.FSETTLECURRID,t1.FPRICE,t1.FPRICE*t1.FTAXRATE/100 SJ from
// T_SAL_OUTSTOCKENTRY_LK t
//left join T_SAL_DELIVERYNOTICEENTRY_LK TZDLK on TZDLK.FENTRYID=t.FSID and TZDLK.FSTABLENAME='T_SAL_ORDERENTRY'
// left join T_SAL_ORDERENTRY_F t1 on TZDLK.FSID=t1.FENTRYID
// left join T_SAL_ORDERFIN t2 on t1.FID=t2.FID
// where t.FENTRYID={0} and t.FSTABLENAME='T_SAL_DELIVERYNOTICEENTRY'", entityRow["BizEntryId"]);
string querySQL = string.Format(@"select t1.FTAXRATE/100 FTAXRATE,t2.FSETTLECURRID,F_BGPrice FTAXPRICE from
T_SAL_OUTSTOCKENTRY t
left join T_SAL_OUTSTOCKENTRY_F t1 on t.FENTRYID=t1.FENTRYID
left join T_SAL_OUTSTOCKFIN t2 on t1.FID=t2.FID where t.FENTRYID={0}", entityRow["BizEntryId"]);
DynamicObjectCollection queryResult = DBUtils.ExecuteDynamicObject(Context, querySQL);
//重新赋值
if (queryResult.Count > 0)
{
DynamicObject findRow = queryResult[0];
//结算币别
FSETTLECURRID = findRow["FSETTLECURRID"];
//单据体值赋值
decimal taxPrice = Convert.ToDecimal(findRow["FTAXPRICE"]);
decimal taxReate = Convert.ToDecimal(findRow["FTAXRATE"]);
decimal price = taxPrice / (1 + taxReate);
decimal SJ = price * taxReate; //税金
decimal count = Convert.ToDecimal(entityRow["Qty"]); //计价单位数量
entityRow["TaxPrice"] = taxPrice; //含税单价
entityRow["Price"] = price; //结算单价
entityRow["AllAmount"] = taxPrice * count; //价税合计
entityRow["Amount"] = price * count; //结算总额
entityRow["TaxAmount"] = SJ * count; //单价*税率*数量
entityRow["SettleReconciliationAmount"] = price * count; //结算对账总额
entityRow["SettleReconciliationAllAmount"] = taxPrice * count; //价税合计
entityRow["SettleReconciliationTaxAmount"] = SJ * count; //结算对账税额
}
}
}
//结算币别赋值
if (FSETTLECURRID != null)
{
var queryData = Common.CommonHelper.GetDynamicObject(Context, "BD_Currency", string.Format("FCURRENCYID={0}", FSETTLECURRID));
if (queryData.isSuccess)
{
item["CurrencyId_Id"] = FSETTLECURRID;
item["CurrencyId"] = queryData.data;
}
}
DynamicObjectCollection SumEntity = item["SumEntity"] as DynamicObjectCollection;
if (SumEntity.Count > 0)
{
SumEntity[0]["SumAcount"] = DetailEntity.Sum(x => Convert.ToDecimal(x["Amount"]));
SumEntity[0]["FSUMALLACOUNT"] = DetailEntity.Sum(x => Convert.ToDecimal(x["AllAmount"]));
}
new BusinessDataWriter(Context).Save(e.DataEntitys);
}
}
}
}
结算清单-保存重算单价
本文2024-09-16 17:40:19发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-17219.html