Procházet zdrojové kódy

1、新增软床报价配置换料代码
2、优化软床报价部分UI
3、新增软床报价规格,类别XML
4、优化软床报价公式计算类

MY před 1 měsícem
rodič
revize
450f5d3e16

+ 34 - 0
JLHHJSvr/Com/GetChangeSoftBedMxList.cs

@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using JLHHJSvr.Com.Model;
+using LJLib.Net.SPI.Com;
+
+namespace JLHHJSvr.Com
+{
+    public sealed class GetChangeSoftBedMxListRequest : ILJRequest<GetChangeSoftBedMxListResponse>
+    {
+        public override string GetApiName()
+        {
+            return "GetChangeSoftBedMxList";
+        }
+        /// <summary>
+        /// 登录token
+        /// </summary>
+        public string token { get; set; }
+        /// <summary>
+        /// 单据id
+        /// </summary>
+        public int billid { get; set; }
+        /// <summary>
+        /// 配置项值
+        /// </summary>
+        public List<u_configure_codemx> codeList { get; set; }
+    }
+
+    public sealed class GetChangeSoftBedMxListResponse : LJResponse
+    {
+        public List<u_softbed_mx> mxList { get; set; }
+    }
+}

+ 0 - 4
JLHHJSvr/Com/GetSoftBedMxList.cs

@@ -21,10 +21,6 @@ namespace JLHHJSvr.Com
         /// 单据id
         /// </summary>
         public int billid { get; set; }
-        /// <summary>
-        /// 配置项值
-        /// </summary>
-        public List<u_configure_codemx> codeList { get; set; }
     }
 
     public sealed class GetSoftBedMxListResponse : LJResponse

+ 5 - 1
JLHHJSvr/Com/Model/CalCulationFormula.cs

@@ -23,7 +23,11 @@ namespace JLHHJSvr.Com.Model
         /// <summary>
         /// 计算后值
         /// </summary>
-        public object value { get; set; }
+        public decimal value { get; set; }
+        /// <summary>
+        /// 是否为常量
+        /// </summary>
+        public bool isConst { get; set; }
         /// <summary>
         /// 是否使用sql进行计算
         /// </summary>

+ 1 - 0
JLHHJSvr/Com/Model/u_configure_codemx.cs

@@ -71,6 +71,7 @@ namespace JLHHJSvr.Com.Model
         public string pzname { get; set; }
         public string pzcode { get; set; }
         public int? typeid { get; set; }
+        public byte? has_type { get; set; }
         public string contfigtypename { get; set; }
         #endregion
     }

+ 5 - 0
JLHHJSvr/Com/Model/u_softbed.cs

@@ -46,6 +46,11 @@ namespace JLHHJSvr.Com.Model
         public DateTime? update_date { get; set; }
         public string update_emp { get; set; }
 
+        public decimal total_mtrl_cost { get; set; }
+        public decimal total_hr_cost { get; set; }
+        public decimal total_cost { get; set; }
+        public int? version { get; set; }
+
         public List<u_softbed_mx> mxList { get; set; }
         /// <summary>
         /// 生成标准配置值

+ 15 - 0
JLHHJSvr/DataStore/_Mapper_softbed_mtrlmode.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<data>
+	<json>
+		[
+			{
+				"label": "40*70*2000",
+				"value": "40*70*2000"
+			},
+			{
+				"label": "20*30*200",
+				"value": "20*30*200"
+			}
+		]
+	</json>
+</data>

+ 15 - 0
JLHHJSvr/DataStore/_Mapper_softbed_mtrltype.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<data>
+	<json>
+		[
+			{
+				"label": "海绵",
+				"value": "海绵"
+			},
+			{
+				"label": "外套",
+				"value": "外套"
+			}
+		]
+	</json>
+</data>

+ 4 - 0
JLHHJSvr/DataStore/web_softbed_list.xml

@@ -33,6 +33,10 @@ SELECT u_softbed.softbed_id
 	,u_softbed.audit_emp
 	,u_softbed.update_date
 	,u_softbed.update_emp
+	,u_softbed.total_mtrl_cost
+	,u_softbed.total_hr_cost
+	,u_softbed.total_cost
+	,u_softbed.version
 FROM u_softbed
   </selectstr>
   <where>

+ 43 - 0
JLHHJSvr/Excutor/GetChangeSoftBedMxListExcutor.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Data.SqlClient;
+using System.Linq;
+using DirectService.Tools;
+using JLHHJSvr.BLL;
+using JLHHJSvr.Com;
+using JLHHJSvr.Com.Model;
+using JLHHJSvr.Helper;
+using JLHHJSvr.LJException;
+using LJLib.DAL.SQL;
+using LJLib.Net.SPI.Server;
+using LJLib.SQLEX;
+
+namespace JLHHJSvr.Excutor
+{
+    internal sealed class GetChangeSoftBedMxListExcutor : ExcutorBase<GetChangeSoftBedMxListRequest, GetChangeSoftBedMxListResponse>
+    {
+        protected override void ExcuteInternal(GetChangeSoftBedMxListRequest request, object state, GetChangeSoftBedMxListResponse rslt)
+        {
+            var tokendata = BllHelper.GetToken(request.token);
+            if (tokendata == null)
+            {
+                rslt.ErrMsg = "会话已经中断,请重新登录";
+                return;
+            }
+            if (request.billid <= 0)
+            {
+                rslt.ErrMsg = "软床id有误,请检查!";
+                return;
+            }
+
+            using (var con = GlobalVar.ConnectionString.NewSqlConnection())
+            using (var cmd = con.CreateCommand())
+            {
+                con.Open();
+
+                var softbedHelpr = HelperBase.GetHelper<SoftBedHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
+                rslt.mxList = softbedHelpr.GetChangeSoftBedMxList(request.billid,request.codeList);
+            }
+        }
+    }
+}

+ 1 - 1
JLHHJSvr/Excutor/GetSoftBedConfigureListExcutor.cs

@@ -31,7 +31,7 @@ namespace JLHHJSvr.Excutor
                 con.Open();
 
                 var softBedHelper = HelperBase.GetHelper<SoftBedHelper>(cmd);
-                rslt.typeList = softBedHelper.GetSoftBedConfigureList(request.softbed);
+                rslt.typeList = softBedHelper.GetSoftBedConfigureList(request.softbed,null);
             }
         }
     }

+ 4 - 11
JLHHJSvr/Excutor/GetSoftBedMxListExcutor.cs

@@ -24,7 +24,7 @@ namespace JLHHJSvr.Excutor
                 rslt.ErrMsg = "会话已经中断,请重新登录";
                 return;
             }
-            if (request.billid < 0)
+            if (request.billid <= 0)
             {
                 rslt.ErrMsg = "软床id有误,请检查!";
                 return;
@@ -39,16 +39,9 @@ namespace JLHHJSvr.Excutor
                 rslt.softbed = new u_softbed();
                 rslt.mxList = new List<u_softbed_mx>();
 
-                if (request.billid > 0)
-                {
-                    // 根据ID获取明细
-                    rslt.softbed = softbedHelpr.GetSoftBed(request.billid);
-                    rslt.mxList = softbedHelpr.GetSoftBedMxList(request.billid);
-                } else if(request.codeList != null && request.codeList.Count > 0)
-                {
-                    // 根据配置获取明细
-                    rslt.mxList = softbedHelpr.GetSoftBedMxBomList(request.codeList);
-                }
+                // 根据ID获取明细
+                rslt.softbed = softbedHelpr.GetSoftBed(request.billid);
+                rslt.mxList = softbedHelpr.GetSoftBedMxList(request.billid);
             }
         }
     }

+ 2 - 2
JLHHJSvr/GlobalVar/GlobalVar.cs

@@ -258,12 +258,12 @@ namespace JLHHJSvr
                 excutorManager.AddMap("SaveSoftBedQuote", typeof(SaveSoftBedQuoteRequest), new SaveSoftBedQuoteExcutor()); // 保存/修改软床报价
                 excutorManager.AddMap("DeleteSoftBedQuote", typeof(DeleteSoftBedQuoteRequest), new DeleteSoftBedQuoteExcutor()); // 删除软床报价
                 excutorManager.AddMap("AuditSoftBedQuote", typeof(AuditSoftBedQuoteRequest), new AuditSoftBedQuoteExcutor()); // 审核软床报价
-                excutorManager.AddMap("GetSoftBedMxList", typeof(GetSoftBedMxListRequest), new GetSoftBedMxListExcutor()); // 审核软床报价
+                excutorManager.AddMap("GetSoftBedMxList", typeof(GetSoftBedMxListRequest), new GetSoftBedMxListExcutor()); // 获取软床报价明细
                 excutorManager.AddMap("GetSoftBedConfigureList", typeof(GetSoftBedConfigureListRequest), new GetSoftBedConfigureListExcutor()); // 获取软床报价部件选配
                 excutorManager.AddMap("SaveSoftBedFormula", typeof(SaveSoftBedFormulaRequest), new SaveSoftBedFormulaExcutor()); // 保存软床公式定义
                 excutorManager.AddMap("SaveErpMtrlPriceList", typeof(SaveErpMtrlPriceListRequest), new SaveErpMtrlPriceListExcutor()); // 保存物料价格
                 excutorManager.AddMap("GetErpMtrlPriceList", typeof(GetErpMtrlPriceListRequest), new GetErpMtrlPriceListExcutor()); // 获取ERP物料资料定义
-
+                excutorManager.AddMap("GetChangeSoftBedMxList", typeof(GetChangeSoftBedMxListRequest), new GetChangeSoftBedMxListExcutor()); // 获取软床报价换料后明细
             }
             catch (Exception ex)
             {

+ 193 - 38
JLHHJSvr/Helper/SoftBedHelper.cs

@@ -11,6 +11,7 @@ using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using System.Web;
 using static JLHHJSvr.Helper.CacheHelper;
@@ -29,7 +30,7 @@ namespace JLHHJSvr.Helper
         {
             fields = fields ?? @"softbed_id,softbed_code,softbed_relcode,softbed_name,deptid,create_date,create_emp,mtrlmode,mtrltype,has_headboard,has_nightstand,has_bedframe,is_template,
                                 template_id,template_code,template_name,commission,taxes,taxrate,other_rate,extras_cost,money_type,moneyrate,dscrp,costamt,nottax_factory_cost,nottax_dept_cost,
-                                dept_cost,foreign_cost";
+                                dept_cost,foreign_cost,total_mtrl_cost,total_hr_cost,total_cost,version";
             var bill = new u_softbed() { softbed_id = billid };
 			if (DbSqlHelper.SelectOne(cmd, bill, fields) == 0) return null;
 			return bill;
@@ -76,9 +77,121 @@ namespace JLHHJSvr.Helper
 								LEFT JOIN u_configure_code ON u_softbed_mx.pzid = u_configure_code.pzid
 								";
 
-            DbSqlHelper.SelectJoin(cmd, selectStr, "softbed_id = @billid", new Dictionary<string, object>() { { "@billid", billid } }, "printid", fields, 0, 0, mxlist);
+            DbSqlHelper.SelectJoin(cmd, selectStr, "softbed_id = @billid", new Dictionary<string, object>() { { "@billid", billid } }, "has_type,printid", fields, 0, 0, mxlist);
 
 			return mxlist;
+        }
+		public List<u_softbed_mx> GetChangeSoftBedMxList(int billid,List<u_configure_codemx> codeMxList)
+		{
+			var newList = new List<u_softbed_mx>();
+
+			var softbed = GetSoftBed(billid, "billid,softbed_code,has_headboard,has_nightstand,has_bedframe");
+			if (softbed == null) return newList;
+
+			// 物料清单
+			var mxList = GetSoftBedMxList(billid);
+			// 换料清单
+			var bomList = GetSoftBedMxBomList(codeMxList);
+            // 排除不存在配置的物料
+            var skipList = new List<int>();
+            var mxMtrlIds = mxList.Select(t => t.mtrlid).ToList();
+            if (mxMtrlIds.Count > 0)
+            {
+                cmd.CommandText = $@"SELECT mtrlid FROM u_configure_codemxbom WHERE mtrlid NOT IN {ListEx.getString(mxMtrlIds)}";
+                cmd.Parameters.Clear();
+                using (var reader = cmd.ExecuteReader())
+                {
+                    while (reader.Read())
+                    {
+                        skipList.Add(Convert.ToInt32(reader["mtrlid"]));
+                    }
+                }
+            }
+
+			foreach (var mx in mxList)
+			{
+				if(skipList.Contains(mx.mtrlid))
+				{
+					mx.printid = newList.Count + 1;
+					newList.Add(mx);
+					continue;
+				}
+
+				if (mx.pzid > 0)
+				{
+					// 部件
+					var tmp_bomList = bomList.FindAll(t => t.has_type == mx.has_type && t.pzid == mx.pzid);
+					if (tmp_bomList.Count > 0)
+					{
+						// add
+						foreach (var temp in tmp_bomList)
+						{
+							if (temp.mtrlid == mx.mtrlid)
+							{
+								mx.printid = newList.Count + 1;
+								newList.Add(mx);
+							}
+							else
+							{
+								temp.printid = newList.Count + 1;
+								newList.Add(temp);
+							}
+						}
+					}
+				}
+				else
+				{
+                    // 非部件
+                    string contfigtypename = string.Empty;
+                    string prefix = $"{softbed.softbed_code}|";
+                    if (mx.has_type == 1) contfigtypename = $"{prefix}床头";
+                    else if (mx.has_type == 2) contfigtypename = $"{prefix}床头柜";
+                    else contfigtypename = $"{prefix}床架";
+
+                    cmd.CommandText = @"SELECT u_configure_code.pzid
+										FROM u_configure_codemxbom
+										INNER JOIN u_configure_codemx ON u_configure_codemxbom.pzid = u_configure_codemx.pzid
+											AND u_configure_codemxbom.printid = u_configure_codemx.printid
+										INNER JOIN u_configure_code ON u_configure_codemx.pzid = u_configure_code.pzid
+										INNER JOIN u_configure_type ON u_configure_code.typeid = u_configure_type.contfigtypeid
+										WHERE u_configure_codemxbom.mtrlid = @mtrlid AND LTRIM(RTRIM(u_configure_type.contfigtypename)) = @contfigtypename";
+					cmd.Parameters.Clear();
+					cmd.Parameters.AddWithValue("@mtrlid",mx.mtrlid);
+                    cmd.Parameters.AddWithValue("@contfigtypename", contfigtypename);
+					int pzid = 0, cnt = 0; 
+					using(var reader = cmd.ExecuteReader())
+					{
+						while(reader.Read())
+						{
+							pzid = Convert.ToInt32(reader["pzid"]);
+							cnt++;
+						}
+					}
+
+					if (pzid > 1) throw new LJCommonException($"换料失败,原因:{contfigtypename}的{mx.mtrlname}存在多个清单,但没有部件!");
+
+					var tmp_bomList = bomList.FindAll(t => t.pzid == pzid);
+                    if (tmp_bomList.Count > 0)
+                    {
+                        // add
+                        foreach (var temp in tmp_bomList)
+                        {
+                            if (temp.mtrlid == mx.mtrlid)
+                            {
+                                mx.printid = newList.Count + 1;
+                                newList.Add(mx);
+                            }
+                            else
+                            {
+                                temp.printid = newList.Count + 1;
+                                newList.Add(temp);
+                            }
+                        }
+                    }
+                }
+			}
+
+			return newList;
         }
         /// <summary>
         /// 根据部件配置项值获取对应BOM明细
@@ -93,7 +206,7 @@ namespace JLHHJSvr.Helper
 				var resultList = new List<u_configure_codemxbom>();
 				var outputFields = @"pzid,printid,pid,mtrlid,sonscale,sonscale_formula,mng_cost_rate,profit_rate,realqty,cost,cost_emp,cost_date,sonloss,sonloss_formula,
 									sondecloss,sondecloss_formula,deptid_scll,default_length,default_width,default_qty,mtrlcode,mtrlname,mtrlmode,unit,
-									mtrlsectype,zxmtrlmode,usermtrlmode";
+									mtrlsectype,zxmtrlmode,usermtrlmode,price";
 				var selectStr = @"SELECT u_configure_codemxbom.pzid
 										,u_configure_codemxbom.printid
 										,u_configure_codemxbom.pid
@@ -121,8 +234,10 @@ namespace JLHHJSvr.Helper
 										,u_mtrldef.mtrlsectype
 										,u_mtrldef.zxmtrlmode
 										,u_mtrldef.usermtrlmode
+										,u_erpmtrl_price.price
 									FROM u_configure_codemxbom
-									INNER JOIN u_mtrldef ON u_configure_codemxbom.mtrlid = u_mtrldef.mtrlid";
+									INNER JOIN u_mtrldef ON u_configure_codemxbom.mtrlid = u_mtrldef.mtrlid
+									LEFT OUTER JOIN u_erpmtrl_price ON u_configure_codemxbom.mtrlid = u_erpmtrl_price.mtrlid";
 				DbSqlHelper.SelectJoin(cmd,selectStr, 
 					"u_configure_codemxbom.pzid = @pzid AND u_configure_codemxbom.printid = @printid",
 					new Dictionary<string, object>() { { "@pzid", code.pzid }, { "@printid",code.printid} }, 
@@ -130,7 +245,7 @@ namespace JLHHJSvr.Helper
 
 				foreach(var item in resultList)
 				{
-					mxlist.Add(InitSoftBedMxFromBom(item));
+					mxlist.Add(InitSoftBedMxFromBom(item, code.has_type.Value));
 				}
 			}
 			return mxlist;
@@ -140,7 +255,7 @@ namespace JLHHJSvr.Helper
 		/// </summary>
 		/// <param name="bomItem"></param>
 		/// <returns></returns>
-		public u_softbed_mx InitSoftBedMxFromBom(u_configure_codemxbom bomItem)
+		public u_softbed_mx InitSoftBedMxFromBom(u_configure_codemxbom bomItem,byte has_type)
 		{
 			var mx = new u_softbed_mx()
 			{
@@ -151,28 +266,23 @@ namespace JLHHJSvr.Helper
 				mtrlmode = bomItem.mtrlmode,
 				unit = bomItem.unit,
 				allow_edit = 0,
-				has_type = bomItem.has_type, // 1-床头、2-床头柜、4-床架
+				has_type = has_type, // 1-床头、2-床头柜、4-床架
 				cutting_length = bomItem.default_length,
 				cutting_width = bomItem.default_width,
 				cutting_qty = bomItem.default_qty,
+				price = bomItem.price,
+				price_formula = "",
+				price_formula_str = "",
 				useqty = bomItem.sonscale,
 				use_formula = "",
-				use_formula_str = bomItem.sonscale_formula,
+				use_formula_str = "",
 				actual_useqty = 0,
 				loss_rate = bomItem.sonloss,
-				cost_price = bomItem.cost,
+				cost_price = 0,
 				cost_amt = 0
 			};
-
-			// 用量
-
-			// 实际用量: 用量 * 损耗
-			mx.actual_useqty = mx.useqty * mx.loss_rate;
-			// 成本金额: 实际用量 * 成本单价
-			mx.cost_amt = mx.actual_useqty * mx.cost_price;
 			return mx;
         }
-
 		/// <summary>
 		/// 新建/修改 软床报价
 		/// </summary>
@@ -180,24 +290,21 @@ namespace JLHHJSvr.Helper
 		/// <exception cref="LJCommonException"></exception>
 		public void SaveSoftBed(u_softbed softbed)
 		{
-			if (softbed == null) throw new LJCommonException("软床报价保存失败,数据异常!");
-			if (softbed.is_template == 0 && (softbed.mxList == null || softbed.mxList.Count <= 0)) throw new LJCommonException("软床报价保存失败,明细内容为空!");
-
-			// 初始化属性
-			AutoInit.AutoInitS(softbed);
-
+			SaveCheck(softbed);
+            // 初始化属性
+            AutoInit.AutoInitS(softbed);
 			foreach(var mx in softbed.mxList)
 			{
 				AutoInit.AutoInitS(mx);
 			}
 
-			// TODO:计算价格
+			// 计算价格
 			CalCulateFormula(softbed);
             //
             var dtNow = context.opdate;
 			var fields = @"softbed_relcode,softbed_name,deptid,mtrlmode,mtrltype,has_headboard,has_nightstand,has_bedframe,is_template,
                             template_id,template_code,template_name,commission,taxes,taxrate,other_rate,extras_cost,money_type,moneyrate,dscrp,costamt,nottax_factory_cost,nottax_dept_cost,
-                            dept_cost,foreign_cost";
+                            dept_cost,foreign_cost,total_mtrl_cost,total_hr_cost,total_cost,version";
 
 			var mx_fields = @"softbed_id,printid,pzid,mtrlid,mtrlname,mtrlcode,mtrlmode,unit,has_type,allow_edit,cutting_length,cutting_width,cutting_qty,
 							useqty,use_formula,use_formula_str,actual_useqty,loss_rate,price,price_formula,price_formula_str,cost_price,cost_amt,pzname,pzmxname";
@@ -210,6 +317,7 @@ namespace JLHHJSvr.Helper
                 softbed.softbed_id = BllHelper.GetID(cmd, "u_softbed");
                 softbed.create_date = dtNow;
                 softbed.create_emp = context.tokendata.username;
+				softbed.version = 1;
 
                 if (string.IsNullOrEmpty(softbed.softbed_code))
                 {
@@ -223,6 +331,7 @@ namespace JLHHJSvr.Helper
 				// 修改
 				softbed.update_date = dtNow;
 				softbed.update_emp = context.tokendata.username;
+				softbed.version++;
                 fields += ",update_date,update_emp";
 
                 cmd.CommandText = @"DELETE FROM u_softbed_mx WHERE softbed_id = @softbed_id";
@@ -245,11 +354,23 @@ namespace JLHHJSvr.Helper
 
 			SaveSoftBedTemplate(softbed);
         }
-		/// <summary>
-		/// 新建软床报价模板
-		/// </summary>
-		/// <param name="softbed"></param>
-		private void SaveSoftBedTemplate(u_softbed softbed)
+		private void SaveCheck(u_softbed softbed)
+		{
+            if (softbed == null) throw new LJCommonException("软床报价保存失败,数据异常!");
+            if (softbed.is_template == 0 && (softbed.mxList == null || softbed.mxList.Count <= 0)) throw new LJCommonException("软床报价保存失败,明细内容为空!");
+
+			if(softbed.softbed_id > 0)
+			{
+				// 检测版本控制
+				var _softbed = GetSoftBed(softbed.softbed_id, "softbed_id,softbed_code,version,update_emp");
+				if (_softbed.version != softbed.version) throw new LJCommonException($"单据:{_softbed.softbed_code}已被{_softbed.update_emp}修改,请重新加载最新数据再操作!");
+			}
+        }
+        /// <summary>
+        /// 新建软床报价模板
+        /// </summary>
+        /// <param name="softbed"></param>
+        private void SaveSoftBedTemplate(u_softbed softbed)
 		{
 			if (softbed.is_template == 0) return;
 
@@ -333,7 +454,13 @@ namespace JLHHJSvr.Helper
                 }
             }
         }
-		public List<u_configure_type> GetSoftBedConfigureList(u_softbed softbed)
+		/// <summary>
+		/// 获取软床报价配置
+		/// </summary>
+		/// <param name="softbed"></param>
+		/// <param name="extraWheres"></param>
+		/// <returns></returns>
+		public List<u_configure_type> GetSoftBedConfigureList(u_softbed softbed,List<string> extraWheres)
 		{
 			var codeMxList = new List<u_configure_codemx>();
 
@@ -351,11 +478,11 @@ namespace JLHHJSvr.Helper
 							INNER JOIN u_configure_type ON u_configure_code.typeid = u_configure_type.contfigtypeid";
 			var whereList = new List<string>();
 			var nameList = new List<string>();
-            if (softbed.softbed_id > 0)
+            if (softbed.softbed_id > 0 || softbed.template_id > 0)
             {
                 // 模版配置获取
-                var _softbed = GetSoftBed(softbed.softbed_id, "softbed_id,softbed_code,has_headboard,has_nightstand,has_bedframe");
-
+				int billid = softbed.softbed_id > 0 ? softbed.softbed_id : softbed.template_id;
+                var _softbed = GetSoftBed(billid, "softbed_id,softbed_code,has_headboard,has_nightstand,has_bedframe");
                 string prefix = $"{_softbed.softbed_code}|";
 
 				if(_softbed.has_headboard == 1)
@@ -378,6 +505,10 @@ namespace JLHHJSvr.Helper
 			{
 				whereList.Add($"LTRIM(RTRIM(u_configure_type.contfigtypename)) IN {ListEx.getString(nameList)}");
 			}
+			if(extraWheres != null && extraWheres.Count > 0)
+			{
+				whereList.AddRange(extraWheres);
+			}
 			DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), null, "typeid,pzid,printid", "typeid,pzid,printid,pzcodemx,namemx,pzname,pzcode,contfigtypename", 0, 0, codeMxList);
 
 			// 部件选配项
@@ -515,7 +646,22 @@ namespace JLHHJSvr.Helper
             foreach (var mx in softbed.mxList)
 			{
 				InitMxReplaceMents(softbed, mx);
-			}
+
+				formula.CalculateAll();
+
+				// 成本单价
+				mx.cost_price = formula.GetFormulaItem("【成本单价】").value;
+				// 实际用量
+				mx.actual_useqty = formula.GetFormulaItem("【实际用量】").value;
+                // 成本金额
+                mx.cost_amt = formula.GetFormulaItem("【成本金额】").value;
+				// 总材料成本
+				softbed.total_mtrl_cost += mx.cost_amt;
+				// 总人力成本
+				softbed.total_hr_cost += 0;
+            }
+
+			softbed.total_cost = formula.GetFormulaItem("【车间成本】").value;
         }
 
 		private void InitSoftBed(u_softbed softbed)
@@ -575,15 +721,24 @@ namespace JLHHJSvr.Helper
 			formula.AddFormulaItem("【佣金点数】", softbed.commission);
 			formula.AddFormulaItem("【额外点数】", softbed.other_rate);
 			formula.AddFormulaItem("【额外费用】", softbed.extras_cost);
-			formula.AddFormulaItem("【FOB】", 0);
 			formula.AddFormulaItem("【汇率】", softbed.moneyrate);
 			formula.AddFormulaItem("【税率】", softbed.taxrate);
+			formula.AddFormulaItem("【FOB】", 0);
+			formula.AddFormulaItem("【外销加点】", 0);
+            formula.AddFormulaItem("【总材料成本】", softbed.total_mtrl_cost);
+            formula.AddFormulaItem("【总人力成本】", softbed.total_hr_cost);
+            formula.AddFormulaItem("【车间成本】", softbed.total_cost);
         }
 
         private void InitMxReplaceMents(u_softbed softbed,u_softbed_mx mx)
         {
-            // 默认公式变量
-            formula.AddFormulaItem("【实际用量】", "【用料量】*【1 + 损耗率】");
+			// 默认公式变量
+            formula.AddFormulaItem("【总材料成本】", 0);
+            formula.AddFormulaItem("【总人力费用】",0);
+            formula.AddFormulaItem("【额外费用】", 0);
+			formula.AddFormulaItem("【车间成本】", "【总材料成本】 + 【总人力费用】 + 【额外费用】");
+            formula.AddFormulaItem("【成本单价】", "【材料单价】*1");
+            formula.AddFormulaItem("【实际用量】", "【用料量】*(1 + 【损耗率】)");
             formula.AddFormulaItem("【成本金额】", "【实际用量】 * 【成本单价】");
 
             // 常量变量

+ 2 - 0
JLHHJSvr/JLHHJSvr.csproj

@@ -108,6 +108,7 @@
     <Compile Include="Com\DeleteMattressExtra.cs" />
     <Compile Include="Com\DeleteSoftBedQuote.cs" />
     <Compile Include="Com\GetBedNetInterfaceList.cs" />
+    <Compile Include="Com\GetChangeSoftBedMxList.cs" />
     <Compile Include="Com\GetComputeMattressById.cs" />
     <Compile Include="Com\GetErpMtrlPriceList.cs" />
     <Compile Include="Com\GetResetWiptype.cs" />
@@ -342,6 +343,7 @@
     <Compile Include="Excutor\DeleteSoftBedQuoteExcutor.cs" />
     <Compile Include="Excutor\FormulaCheckExcutor.cs" />
     <Compile Include="Excutor\GetBedNetInterfaceListExcutor.cs" />
+    <Compile Include="Excutor\GetChangeSoftBedMxListExcutor.cs" />
     <Compile Include="Excutor\GetComputeMattressByIdExcutor.cs" />
     <Compile Include="Excutor\GetErpMtrlPriceListExcutor.cs" />
     <Compile Include="Excutor\GetFormulaVarListExcutor.cs" />

+ 27 - 33
JLHHJSvr/Tools/CalculateFormula.cs

@@ -12,63 +12,60 @@ namespace JLHHJSvr.Tools
 {
     public class CalculateFormula
     {
-        private HashSet<FormulaItem> _formula; // 公式
-        private HashSet<FormulaItem> _const; // 常量
+        private Dictionary<string,FormulaItem> _formula; // 公式
 
         public CalculateFormula() 
         {
-            _formula = new HashSet<FormulaItem>();
-            _const = new HashSet<FormulaItem>();
+            _formula = new Dictionary<string, FormulaItem>();
         }
 
         public void AddFormulaItem(FormulaItem item) 
         {
-            if(!_formula.Add(item))
+            if(_formula.ContainsKey(item.formula_name))
             {
-                _formula.Remove(item);
-                _formula.Add(item);
-            }
-        }
-        public void AddConstFormulaItem(FormulaItem item)
-        {
-            if (!_const.Add(item))
-            {
-                _const.Remove(item);
-                _const.Add(item);
+                _formula.Remove(item.formula_name);
+                _formula.Add(item.formula_name,item);
             }
         }
 
-        public void AddFormulaItem(string name,object value)
+        public void AddFormulaItem(string name,decimal value)
         {
-            AddConstFormulaItem(new FormulaItem() { formula_name = name, value = value });
+            AddFormulaItem(new FormulaItem() { formula_name = name, value = value,isConst = true });
         }
 
         public void AddFormulaItem(string name, string formula)
         {
-            var formulaItem = new FormulaItem() { formula_name = name, formula = formula };
+            var formulaItem = new FormulaItem() { formula_name = name, formula = formula,isConst = false };
             AddFormulaItem(formulaItem);
         }
 
+        public FormulaItem GetFormulaItem(string name,bool isConst = false)
+        {
+            return _formula[name];
+        }
+
         /// <summary>
         /// 主计算入口
         /// </summary>
         public void CalculateAll()
         {
-            var dict = _formula.ToDictionary(f => f.formula_name, f => f);
-            foreach (var c in _const)
-            {
-                dict[c.formula_name] = c;
-            }
-
-            var graph = BuildDependencyGraph(dict);
+            var graph = BuildDependencyGraph(_formula);
             var sorted = TopologicalSort(graph);
             foreach (var name in sorted)
             {
-                var item = dict[name];
+                var item = _formula[name];
                 item.formula = ConvertToEnglishSymbols(item.formula);
-                // 展开
-                string expanded = ExpandFormula(item.formula, dict);
+                // 常量直接赋值
+                if (item.isConst)
+                {
+                    item.formula_transform = item.formula;
+                    item.value = Convert.ToDecimal(item.formula);
+                    continue;
+                }
+                // 变量公式
+                string expanded = ExpandFormula(item.formula, _formula);
                 item.formula_transform = expanded;
+
                 // 计算
                 if (item.isSql) SqlCalculate(item);
                 else Calculate(item);
@@ -143,10 +140,7 @@ namespace JLHHJSvr.Tools
         {
             foreach (var kv in dict)
             {
-                if (kv.Value.value != null) // 已经算过
-                {
-                    formula = Regex.Replace(formula, $"【{kv.Key}】", kv.Value.value.ToString());
-                }
+                formula = Regex.Replace(formula, $"【{kv.Key}】", kv.Value.value.ToString());
             }
             return formula;
         }
@@ -176,7 +170,7 @@ namespace JLHHJSvr.Tools
         {
             try
             {
-                formula.value = LJExprParser.Parse(formula.formula).Result;
+                formula.value = LJExprParser.Parse(formula.formula_transform).Result.DecimalValue;
             }
             catch (Exception ex)
             {

+ 9 - 9
JLHWEB/src/routers/modules/baseRouter.ts

@@ -494,12 +494,12 @@ export const baseRouter: Menu.MenuOptions[] = [
         ]
       },
       {
-        path: "/baseinfo/erpmtrldef",
-        name: "erpmtrldef",
-        component: "/baseinfo/erpmtrldef/index",
+        path: "/baseinfo/erpmtrlprice",
+        name: "erpmtrlprice",
+        component: "/baseinfo/erpmtrlprice/index",
         meta: {
           icon: "Common_List.png",
-          title: "ERP物料资料定义",
+          title: "ERP物料价格定义",
           isLink: "",
           isHide: false,
           isFull: false,
@@ -511,18 +511,18 @@ export const baseRouter: Menu.MenuOptions[] = [
         },
         children: [
           {
-            path: "/baseinfo/erpmtrldef/detail",
-            name: "erpmtrldefDetail",
-            component: "/baseinfo/erpmtrldef/detail",
+            path: "/baseinfo/erpmtrlprice/detail",
+            name: "erpmtrlpriceDetail",
+            component: "/baseinfo/erpmtrlprice/detail",
             meta: {
               icon: "Common_List.png",
-              title: "ERP物料资料定义详情",
+              title: "ERP物料价格定义详情",
               isLink: "",
               isHide: true,
               isFull: false,
               isAffix: false,
               isKeepAlive: true,
-              activeMenu: "/baseinfo/erpmtrldef"
+              activeMenu: "/baseinfo/erpmtrlprice"
             }
           }
         ]

+ 16 - 17
JLHWEB/src/views/quote/bednetQuote/hooks/index.tsx

@@ -1841,23 +1841,22 @@ export const useHooks = (t?: any, props?: any) => {
     });
 
     if (_mainData.bednettypeid !== 11) return;
-    let _params: any = {
-      bednet: bednet,
-      bednetMx: _bednetMx,
-      spring: state.vxeTableMxSpringRef?.element.getTableData().fullData ?? []
-    };
-    let res = await GetComputeSpring(_params);
-
-    console.log("setMxSpringQtyWidthAndLength res :>> ", res);
-    if (!res?.message) {
-      row.spring_qty_width = res.bednetMx[0].spring_qty_width;
-      row.spring_qty_length = res.bednetMx[0].spring_qty_length;
-
-      setMxSpringWidth(row);
-      setMxSpringLength();
-
-      ElMessage.success("已刷新弹簧排列");
-    }
+    // let _params: any = {
+    //   bednet: bednet,
+    //   bednetMx: _bednetMx,
+    //   spring: state.vxeTableMxSpringRef?.element.getTableData().fullData ?? []
+    // };
+    // let res = await GetComputeSpring(_params);
+
+    // console.log("setMxSpringQtyWidthAndLength res :>> ", res);
+    // if (!res?.message) {
+    //   row.spring_qty_width = res.bednetMx[0].spring_qty_width;
+    //   row.spring_qty_length = res.bednetMx[0].spring_qty_length;
+
+    //   setMxSpringWidth(row);
+    //   setMxSpringLength();
+
+    //   ElMessage.success("已刷新弹簧排列");
     // }
   };
   /**

+ 15 - 15
JLHWEB/src/views/quote/mattressQuote/hooks/index.tsx

@@ -5788,21 +5788,21 @@ export const useHooks = (t?: any) => {
           bednet.mattress_width = row.mattress_width;
           bednet.pricelistid = _pricelistid;
 
-          let _params: any = {
-            bednet: bednet
-            // bednetMx: state.vxeTableMxRef?.element.getTableData().fullData ?? [],
-            // spring: state.vxeTableMxSpringRef?.element.getTableData().fullData ?? []
-          };
-          console.log("setMxSpringQtyWidthAndLength _params :>> ", _params);
-          let res = await GetComputeSpring(_params);
-
-          console.log("setMxSpringQtyWidthAndLength res :>> ", res);
-          console.log("setMxSpringQtyWidthAndLength row :>> ", row);
-          if (!res?.message) {
-            scope.row["spring_qty_width_" + (i + 1)] = res.bednetMx[0].spring_qty_width;
-            scope.row["spring_qty_length_" + (i + 1)] = res.bednetMx[0].spring_qty_length;
-          }
-          console.log("setMxSpringQtyWidthAndLength scopes row :>> ", scope.row);
+          // let _params: any = {
+          //   bednet: bednet
+          //   // bednetMx: state.vxeTableMxRef?.element.getTableData().fullData ?? [],
+          //   // spring: state.vxeTableMxSpringRef?.element.getTableData().fullData ?? []
+          // };
+          // console.log("setMxSpringQtyWidthAndLength _params :>> ", _params);
+          // let res = await GetComputeSpring(_params);
+
+          // console.log("setMxSpringQtyWidthAndLength res :>> ", res);
+          // console.log("setMxSpringQtyWidthAndLength row :>> ", row);
+          // if (!res?.message) {
+          //   scope.row["spring_qty_width_" + (i + 1)] = res.bednetMx[0].spring_qty_width;
+          //   scope.row["spring_qty_length_" + (i + 1)] = res.bednetMx[0].spring_qty_length;
+          // }
+          // console.log("setMxSpringQtyWidthAndLength scopes row :>> ", scope.row);
         }
       }
     }

+ 63 - 23
JLHWEB/src/views/quote/softbedQuote/hooks/index.tsx

@@ -10,6 +10,7 @@ import SoftBedSelect from "@/views/system/selector/softbedTemplate/select.vue";
 import { cloneDeep } from "lodash-es";
 import { getCurrentRecords } from "@/utils/index";
 import ErpMtrlPriceSelect from "@/views/system/selector/erpMtrlPrice/select.vue";
+import { useUserStore } from "@/stores/modules/user";
 interface defaultState {
   /**
    * @description 单据当前状态
@@ -179,10 +180,7 @@ export const useHooks = (t?: any) => {
         order: 1,
         group: "单据信息",
         editable: (scope: any) => {
-          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.softbed_id) <= 0) {
-            return true;
-          }
-          return false;
+          return ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.softbed_id) <= 0;
         },
         rules: [{ required: true, message: "请先选择部门", trigger: "change" }],
         props: {
@@ -200,6 +198,9 @@ export const useHooks = (t?: any) => {
       datatype: "checkbox",
       basicinfo: {
         el: "checkbox",
+        editable: (scope: any) => {
+          return ALLOW_EDIT_STATE.includes(scope.status) && useUserStore().userInfo.usermode != 1;
+        },
         props: {
           trueValue: 1,
           falseValue: 0
@@ -279,10 +280,7 @@ export const useHooks = (t?: any) => {
         order: 6,
         group: "单据信息",
         editable: (scope: any) => {
-          if (ALLOW_EDIT_STATE.includes(scope.status) && !Number(scope.searchParam.is_template)) {
-            return true;
-          }
-          return false;
+          return ALLOW_EDIT_STATE.includes(scope.status) && !Number(scope.searchParam.is_template);
         }
       }
     },
@@ -301,7 +299,13 @@ export const useHooks = (t?: any) => {
     {
       field: "mtrlmode",
       title: "物料规格",
+      enum: async () => {
+        const data = (await GetSoftBedMtrlmodeMapper()).datatable;
+        return data;
+      },
       basicinfo: {
+        el: "select",
+        editable: ALLOW_EDIT_STATE,
         span: 1,
         row: 1,
         order: 8,
@@ -321,7 +325,13 @@ export const useHooks = (t?: any) => {
     {
       field: "mtrltype",
       title: "物料类别",
+      enum: async () => {
+        const data = (await GetSoftBedMtrltypeMapper()).datatable;
+        return data;
+      },
       basicinfo: {
+        el: "select",
+        editable: ALLOW_EDIT_STATE,
         span: 1,
         row: 1,
         order: 10,
@@ -339,8 +349,14 @@ export const useHooks = (t?: any) => {
         group: "单据信息",
         labelHidden: true,
         render: (scope: any) => {
-          let _disabled = !ALLOW_EDIT_STATE.includes(state.orderStatus);
-          let _type = _disabled ? "info" : "primary";
+          let enable = ALLOW_EDIT_STATE.includes(state.orderStatus) && Number(scope.searchParam.is_template);
+
+          let bt_enable =
+            ALLOW_EDIT_STATE.includes(state.orderStatus) &&
+            (scope.searchParam.has_headboard || scope.searchParam.has_nightstand || scope.searchParam.has_bedframe) &&
+            (scope.searchParam.softbed_id > 0 || scope.searchParam.template_id > 0);
+
+          let _type = !bt_enable ? "info" : "primary";
           return (
             <>
               <ElRow>
@@ -349,7 +365,7 @@ export const useHooks = (t?: any) => {
                     v-model={scope.searchParam.has_headboard}
                     true-value={1}
                     false-value={0}
-                    disabled={_disabled}
+                    disabled={!enable}
                     label="床头"
                     class="mr-8"
                     // onChange={val => autoLoadExtraData_chai(val, "if_m_chai")}
@@ -358,7 +374,7 @@ export const useHooks = (t?: any) => {
                     v-model={scope.searchParam.has_nightstand}
                     true-value={1}
                     false-value={0}
-                    disabled={_disabled}
+                    disabled={!enable}
                     label="床头柜"
                     class="mr-8"
                     // onChange={val => autoLoadExtraData_chai(val, "if_z_chai")}
@@ -367,13 +383,13 @@ export const useHooks = (t?: any) => {
                     v-model={scope.searchParam.has_bedframe}
                     true-value={1}
                     false-value={0}
-                    disabled={_disabled}
+                    disabled={!enable}
                     label="床架"
                     // onChange={val => autoLoadExtraData_chai(val, "if_d_chai")}
                   />
                 </ElCol>
                 <ElCol span={8}>
-                  <ElButton type={_type} size="small" disabled={_disabled} onClick={onOpenConfigureDialog}>
+                  <ElButton type={_type} size="small" disabled={!bt_enable} onClick={onOpenConfigureDialog}>
                     选择部件配置
                   </ElButton>
                 </ElCol>
@@ -459,9 +475,10 @@ export const useHooks = (t?: any) => {
         render: (scope: any) => {
           let optionRender = [];
           let _disabled = !ALLOW_EDIT_STATE.includes(scope.status);
-          scope.enum.map(item => {
-            optionRender.push(<el-option label={item.label} value={item.value} />);
-          });
+          scope.enum &&
+            scope.enum.map(item => {
+              optionRender.push(<el-option label={item.label} value={item.value} />);
+            });
           let slotprefix = {
             prefix: () => {
               return <>{scope.searchParam.taxrate}</>;
@@ -501,7 +518,7 @@ export const useHooks = (t?: any) => {
       title: "币种",
       enum: async () => {
         const data = (await GetMoneyRateMapper()).datatable;
-        return { data };
+        return data;
       },
       render: (scope: any) => {
         return (
@@ -529,9 +546,10 @@ export const useHooks = (t?: any) => {
         render: (scope: any) => {
           let optionRender = [];
           let _disabled = !ALLOW_EDIT_STATE.includes(scope.status);
-          scope.enum.map(item => {
-            optionRender.push(<el-option label={item.label} value={item.value} />);
-          });
+          scope.enum &&
+            scope.enum.map(item => {
+              optionRender.push(<el-option label={item.label} value={item.value} />);
+            });
           let slotprefix = {
             prefix: () => {
               return <>{scope.searchParam.moneyrate}</>;
@@ -990,11 +1008,13 @@ export const useHooks = (t?: any) => {
    * 详细页获取数据
    */
   const detail_getData = async (params: any) => {
-    const result = await GetSoftBedMxList(params);
     if (state.orderStatus === "new") {
-      result.softbed.taxrate = 1;
+      const { _mainData } = state.LjDetailRef;
+      _mainData.taxrate = 1;
+      return;
     }
 
+    const result = await GetSoftBedMxList(params);
     state.softBed = [result.softbed];
     state.softBedMx = result.mxList;
     state.headBoardMx = result.mxList.filter(item => item.has_type === 1);
@@ -1188,6 +1208,20 @@ export const useHooks = (t?: any) => {
    * 显示公式
    */
   const onShowFormula = () => {};
+  /**
+   * 获取规格
+   * @returns
+   */
+  const GetSoftBedMtrlmodeMapper = async () => {
+    return CommonDynamicSelect({ dsname: "_Mapper_softbed_mtrlmode", queryparams: {} });
+  };
+  /**
+   * 获取币种
+   * @returns
+   */
+  const GetSoftBedMtrltypeMapper = async () => {
+    return CommonDynamicSelect({ dsname: "_Mapper_softbed_mtrltype", queryparams: {} });
+  };
   /**
    * 获取币种
    * @returns
@@ -1269,6 +1303,9 @@ export const useHooks = (t?: any) => {
     data.template_id = Number(item.softbed_id);
     data.template_code = item.softbed_code;
     data.template_name = item.softbed_name;
+    data.has_headboard = Number(item.has_headboard);
+    data.has_nightstand = Number(item.has_nightstand);
+    data.has_bedframe = Number(item.has_bedframe);
   };
   /**
    * 清空选择参数
@@ -1278,6 +1315,9 @@ export const useHooks = (t?: any) => {
     data.template_id = 0;
     data.template_code = "";
     data.template_name = "";
+    data.has_headboard = 0;
+    data.has_nightstand = 0;
+    data.has_bedframe = 0;
   };
 
   const toAddMx = async (tableRef: any) => {