K/3 Cloud 产品报价单_表单插件开发示例

Posted lxh168

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了K/3 Cloud 产品报价单_表单插件开发示例相关的知识,希望对你有一定的参考价值。

using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace MyPlugIn.PRODUCTQUOTE.PlugIn
{
    [Description("产品报价单表单插件")]
    public class PlugIn : AbstractDynamicFormPlugIn
    {
        /// <summary>
        /// 数据变更时
        /// </summary>
        /// <param name="e"></param>
        public override void DataChanged(DataChangedEventArgs e)
        {
            List<string> lstField = new List<string>
            {
                "F_KD_SHL",         // 材料损耗率%
                "F_KD_BZGS",        // 标准工时
                "F_KD_GFL",         // 工费率(元/H)
                "F_KD_ZZFYL",       // 制造费用率%
                "F_KD_FTSL",        // 模具分摊数量
                "F_KD_MLL",         // 毛利率
                "F_KD_WBREBATE",    // 外币(Rebate)/客户佣金
                "F_KD_WBHL",        // 汇率
                "F_KD_RMBREBATE",   // 人民币(Rebate)
                "F_KD_TAXRATE",     // 增值税率
                "F_KD_GXFL",        // 管销费率
                "FTAXPRICE",        // 材料含税单价
                "FUSAGE",           // 材料用量
                "FTAXAMOUNT",       // 材料含税金额
                "FMDPRICE"          // 模具单价
            };
            string strKey = e.Field.FieldName.Trim().ToUpper();
            if (lstField.Contains(strKey))
            {
                Compute();
            }
            else if ((strKey == "FSUBMATERIALID") || (strKey == "FBASEUNIT"))
            {
                DynamicObject dynobj = (DynamicObject)this.View.Model.GetValue("FSUBMATERIALID", e.Row);
                DynamicObject dynobjunit = (DynamicObject)this.View.Model.GetValue("FBASEUNIT", e.Row);
                System.Int64 intUnitId = (dynobjunit.IsNullOrEmptyOrWhiteSpace()) ? 0 : (System.Int64)dynobjunit["Id"];

                Boolean blnIsNewMat = true;
                int intFSUPPLIERID = 0;
                Decimal decFCONPRICE = 0;
                Decimal decFMAXTAXPRICE = 0;
                Decimal decFMINTAXPRICE = 0;
                Decimal decFQTAXPRICE = 0;
                System.DateTime? dtFORDEERDATE = null;
                Decimal decFUSAGE = (Decimal)this.Model.GetValue("FUSAGE", e.Row);
                Decimal decAmount = 0;
                if (dynobj.IsNullOrEmptyOrWhiteSpace() == false)
                {
                    System.Int64 intMatId = (System.Int64)dynobj["Id"];
                    string strSql = @"SELECT TOP 1 1 FROM T_PUR_PRICELISTENTRY WHERE [email protected] ";
                    List<SqlParam> lstParams = new List<SqlParam>();
                    lstParams.Add(new SqlParam("@MATID", KDDbType.Int64, intMatId));
                    DynamicObjectCollection objcol = DBUtils.ExecuteDynamicObject(this.Context, strSql, null, null, System.Data.CommandType.Text, lstParams.ToArray());
                    if ((objcol.IsNullOrEmptyOrWhiteSpace() == false) && (objcol.Count > 0))
                    {
                        blnIsNewMat = false;
                    }
                    lstParams.Clear();
                    strSql = @"/*dialect*/GetPurPrice @MATID,@UNITID ";
                    lstParams.Add(new SqlParam("@MATID", KDDbType.Int64, intMatId));
                    lstParams.Add(new SqlParam("@UNITID", KDDbType.Int64, intUnitId));
                    DynamicObjectCollection objcol2 = DBUtils.ExecuteDynamicObject(this.Context, strSql, null, null, System.Data.CommandType.Text, lstParams.ToArray());
                    if ((objcol2.IsNullOrEmptyOrWhiteSpace() == false) && (objcol2.Count > 0))
                    {
                        DynamicObject dyn1 = objcol2[0];
                        if (dyn1.IsNullOrEmptyOrWhiteSpace() == false)
                        {
                            intFSUPPLIERID = (int)dyn1["FSUPPLIERID"];
                            decFCONPRICE = (Decimal)dyn1["FCONPRICE"];
                            decFMAXTAXPRICE = (Decimal)dyn1["FMAXTAXPRICE"];
                            decFMINTAXPRICE = (Decimal)dyn1["FMINTAXPRICE"];
                            decFQTAXPRICE = (Decimal)dyn1["FQTAXPRICE"];
                            decAmount = decFUSAGE * decFCONPRICE;
                            dtFORDEERDATE = (DateTime?)dyn1["FDATE"];
                        }
                    }
                }
                this.Model.SetValue("FISNEWMAT", blnIsNewMat, e.Row);
                this.Model.SetValue("FSUPPLIERID", intFSUPPLIERID, e.Row);
                this.Model.SetValue("FTAXPRICE", decFCONPRICE, e.Row);
                this.Model.SetValue("FTAXAMOUNT", decAmount, e.Row);
                this.Model.SetValue("FMAXPRICE", decFMAXTAXPRICE, e.Row);
                this.Model.SetValue("FMINPRICE", decFMINTAXPRICE, e.Row);
                this.Model.SetValue("FQPRICE", decFQTAXPRICE, e.Row);
                this.Model.SetValue("FORDERDATE", dtFORDEERDATE, e.Row);
            }
            base.DataChanged(e);
        }

        /// <summary>
        /// 财务计算
        /// </summary>
        private void Compute()
        {
            DynamicObjectCollection dyncolobj = (DynamicObjectCollection)this.Model.DataObject["FEntity"];
            DynamicObjectCollection dyncolmdobj = (DynamicObjectCollection)this.Model.DataObject["FMDEntity"];
            String strFMJFY=(String)this.Model.DataObject["FMJFY"];
            Decimal decSumMatAmount = 0;
            Decimal decSumMdAmount = 0;
            Decimal decAmount = 0;
            Decimal decUsage = 0;
            Decimal decPRICE = 0;
            if (dyncolobj.IsNullOrEmptyOrWhiteSpace() == false && dyncolobj.Count > 0)
            {
                int intRow = 0;
                foreach (DynamicObject dynobj in dyncolobj)
                {
                    decUsage = (Decimal)dynobj["FUSAGE"];
                    decPRICE = (Decimal)dynobj["FTAXPRICE"];
                    decAmount = decUsage * decPRICE;
                    decSumMatAmount = decSumMatAmount + decAmount;
                    dynobj["FTAXAMOUNT"] = decAmount;
                    this.View.UpdateView("FTAXAMOUNT", intRow++);
                }
            }
            if (dyncolmdobj.IsNullOrEmptyOrWhiteSpace() == false && dyncolmdobj.Count > 0)
            {
                foreach (DynamicObject dynobj in dyncolmdobj)
                {
                    decAmount = (Decimal)dynobj["FMDPRICE"];
                    decSumMdAmount = decSumMdAmount + decAmount;
                }
            }

            Decimal decFMATCOST = decSumMatAmount;    // 材料成本
            Decimal decF_KD_SHL = (Decimal)this.Model.DataObject["F_KD_SHL"];  // 材料损耗率%
            Decimal decF_KD_SH = decFMATCOST * decF_KD_SHL / 100;  // 材料损耗=材料成本*材料损耗率%/100
            Decimal decF_KD_HSCLXJ = decFMATCOST + decF_KD_SH;    // 含税材料小计=材料成本+材料损耗
            Decimal decF_KD_WSCLXJ = decF_KD_HSCLXJ * 100 / ((Decimal)this.Model.DataObject["F_KD_TAXRATE"]+100);  // 未税材料小计

            Decimal decF_KD_BZGS = (Decimal)this.Model.DataObject["F_KD_BZGS"];      // 标准工时
            Decimal decF_KD_GFL = (Decimal)this.Model.DataObject["F_KD_GFL"];       // 工费率(元/H)
            Decimal decF_KD_RGCBXJ = decF_KD_BZGS * decF_KD_GFL / 3600;           // 人工成本小计=标准工时*工费率(元/H)/3600

            Decimal decF_KD_ZZFYL = (Decimal)this.Model.DataObject["F_KD_ZZFYL"];   // 制造费用率%
            Decimal decF_KD_SCCBXJ = (decF_KD_ZZFYL == 100) ? 0 : ((decF_KD_WSCLXJ + decF_KD_RGCBXJ) * 100 / (100 - decF_KD_ZZFYL));     // 生产成本小计=(未税材料小计+人工成本小计)*100/(100-制造费用率)

            Decimal decF_KD_MJFY = decSumMdAmount;   // 模具费用
            Decimal decF_KD_FTSL = (Decimal)this.Model.DataObject["F_KD_FTSL"]; // 模具分摊数量
            Decimal decF_KD_MJFTCB = 0;
            if (strFMJFY.IsNullOrEmptyOrWhiteSpace() == false && strFMJFY == "1")  // 模具费用为公司承担时,进行模具成本分摊
            {
                decF_KD_MJFTCB = (decF_KD_FTSL == 0) ? decF_KD_MJFY : (decF_KD_MJFY / decF_KD_FTSL); // 模具分摊成本=模具费用/模具分摊数量
            }
            Decimal decF_KD_MLL = (Decimal)this.Model.DataObject["F_KD_MLL"];    // 毛利率
            Decimal decF_KD_WBREBATE = (Decimal)this.Model.DataObject["F_KD_WBREBATE"]; // 外币(Rebate)/客户佣金
            Decimal decF_KD_WBHL = (Decimal)this.Model.DataObject["F_KD_WBHL"];   // 汇率
           // 外币报价=(生产成本合计 / (1 - 毛利率) + 模具分摊成本 + 外币Rebate) / 汇率
            Decimal decF_KD_WBBJ = ((decF_KD_MLL == 100) || (decF_KD_WBHL == 0)) ? 0 : ((decF_KD_SCCBXJ * 100 / (100 - decF_KD_MLL) + decF_KD_MJFTCB + decF_KD_WBREBATE) / decF_KD_WBHL);
            Decimal decF_KD_RMBREBATE = (Decimal)this.Model.DataObject["F_KD_RMBREBATE"];                   // 人民币(Rebate)
            Decimal decF_KD_TAXRATE = (Decimal)this.Model.DataObject["F_KD_TAXRATE"];                       // 增值税率
           // 人民币报价(含税)=(生产成本合计/(1-毛利率)+模具分摊成本+人民币Rebate)*(1+增值税率)
            Decimal decF_KD_RMBBJ = (decF_KD_MLL == 100) ? 0 : ((decF_KD_SCCBXJ * 100 / (100 - decF_KD_MLL) + decF_KD_MJFTCB + decF_KD_RMBREBATE) * (100 + decF_KD_TAXRATE) / 100);     // 人民币报价(含税)=(生产成本合计/(1-毛利率)+模具分摊成本+人民币Rebate)*(1+增值税率)
            Decimal decF_KD_WBJSR = (decF_KD_WBBJ - decF_KD_WBREBATE) * decF_KD_WBHL;                       // 外币净收入=(外币报价 - 外币Rebate) * 汇率
            Decimal decF_KD_RMBJSR = decF_KD_RMBBJ * 100 / (100 + decF_KD_TAXRATE) - decF_KD_RMBREBATE;     // 人民币净收入=人民币报价(含税)/(1+增值税率)-人民币Rebate
            Decimal decF_KD_BWBJSR = (decF_KD_RMBJSR > 0) ? decF_KD_RMBJSR : decF_KD_WBJSR; // 本位币净收入 //取值(人民币净收入 > 0, 人民币净收入, 外币净收入)
            Decimal decF_KD_MLR = decF_KD_BWBJSR * decF_KD_MLL / 100;     // 毛利润=本位币净收入*毛利率 
            Decimal decF_KD_GXFL = (Decimal)this.Model.DataObject["F_KD_GXFL"];  // 管销费率
            Decimal decF_KD_GXFY = decF_KD_BWBJSR * decF_KD_GXFL / 100;    // 管销费用=本位币净收入*管销费率
            Decimal decF_KD_SQLR = decF_KD_MLR - decF_KD_GXFY;      // 税前利润=毛利润-管销费用
            Decimal decF_KD_SQLRL = (decF_KD_BWBJSR == 0) ? 0 : (decF_KD_SQLR / decF_KD_BWBJSR * 100);      // 税前利润率=税前利润/本位币净收入

            this.Model.SetValue("FMATCOST", decFMATCOST);    // 材料成本
            this.Model.SetValue("F_KD_SH", decF_KD_SH);    // 材料损耗
            this.Model.SetValue("F_KD_HSCLXJ", decF_KD_HSCLXJ);  // 含税材料小计
            this.Model.SetValue("F_KD_WSCLXJ", decF_KD_WSCLXJ);  // 未税材料小计
            this.Model.SetValue("F_KD_RGCBXJ", decF_KD_RGCBXJ);  // 人工成本小计
            this.Model.SetValue("F_KD_MJFY", decF_KD_MJFY);      // 模具费用
            this.Model.SetValue("F_KD_MJFTCB", decF_KD_MJFTCB);  // 模具分摊成本
            this.Model.SetValue("F_KD_SCCBXJ", decF_KD_SCCBXJ); // 生产成本小计
            this.Model.SetValue("F_KD_WBBJ", decF_KD_WBBJ);      // 外币报价
            this.Model.SetValue("F_KD_RMBBJ", decF_KD_RMBBJ);    // 人民币报价(含税)
            this.Model.SetValue("F_KD_WBJSR", decF_KD_WBJSR);    // 外币净收入
            this.Model.SetValue("F_KD_RMBJSR", decF_KD_RMBJSR);  // 人民币净收入
            this.Model.SetValue("F_KD_BWBJSR", decF_KD_BWBJSR);  // 本位币净收入
            this.Model.SetValue("F_KD_MLR", decF_KD_MLR);        // 毛利润
            this.Model.SetValue("F_KD_GXFY", decF_KD_GXFY);      // 管销费用
            this.Model.SetValue("F_KD_SQLR", decF_KD_SQLR);      // 税前利润
            this.Model.SetValue("F_KD_SQLRL", decF_KD_SQLRL);    // 税前利润率
        }
    }
}
 

 

以上是关于K/3 Cloud 产品报价单_表单插件开发示例的主要内容,如果未能解决你的问题,请参考以下文章

中关村产品报价网

中关村产品报价网

Access 2010 - 一个报价 ID 拥有多个产品

手把手搭建K3cloud插件开发环境

Applied Cloud Deep Semantic Recognition: Advanced Anomaly Detection(应用云深层语义识别:高级异态检测)——Chapter 1(示例代

VB6上新增金蝶 K/3插件