SoftBedHelper.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using JLHHJSvr.BLL;
  2. using JLHHJSvr.Com.Model;
  3. using LJLib.DAL.SQL;
  4. using NPOI.SS.Formula.Functions;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Web;
  11. namespace JLHHJSvr.Helper
  12. {
  13. internal class SoftBedHelper : HelperBase
  14. {
  15. /// <summary>
  16. /// 获取软床报价单据
  17. /// </summary>
  18. /// <param name="billid"></param>
  19. /// <param name="fields"></param>
  20. /// <param name="bill"></param>
  21. public u_softbed GetSoftBed(int billid,string fields)
  22. {
  23. fields = fields ?? @"softbed_id,softbed_code,softbed_name,deptid,create_time,create_by,mtrlmode,mtrltype,has_headboard,has_nightstand,has_bedframe,is_template,
  24. template_id,template_code,template_name,commission,taxes,other_rate,extras_cost,moneyrate,dscrp,costamt,nottax_factory_cost,nottax_dept_cost,
  25. dept_cost,foreign_cost";
  26. var bill = new u_softbed() { softbed_id = billid };
  27. DbSqlHelper.SelectOne(cmd, bill, fields);
  28. return bill;
  29. }
  30. /// <summary>
  31. /// 获取软床报价单据明细
  32. /// </summary>
  33. /// <param name="billid"></param>
  34. /// <param name="fields"></param>
  35. /// <param name="mxlist"></param>
  36. public void GetSoftBedMxList(int billid,string fields,out List<u_softbed_mx> mxlist,out List<u_configure_codemx> codeList)
  37. {
  38. fields = fields ?? @"softbed_id,printid,pzid,pz_printid,mtrlid,mtrlname,mtrlcode,mtrlmode,unit,has_type,allow_edit,cutting_length,cutting_width,cutting_qty,
  39. useqty,use_formula,use_formula_str,actual_useqty,loss_rate,price,price_formula,price_formula_str,cost_price,cost_amt,pzname,pzmxname";
  40. mxlist = new List<u_softbed_mx>();
  41. var selectStr = @"SELECT u_softbed_mx.softbed_id
  42. ,u_softbed_mx.printid
  43. ,u_softbed_mx.pzid
  44. ,u_softbed_mx.pz_printid
  45. ,u_softbed_mx.mtrlid
  46. ,u_softbed_mx.mtrlname
  47. ,u_softbed_mx.mtrlcode
  48. ,u_softbed_mx.mtrlmode
  49. ,u_softbed_mx.unit
  50. ,u_softbed_mx.has_type
  51. ,u_softbed_mx.allow_edit
  52. ,u_softbed_mx.cutting_length
  53. ,u_softbed_mx.cutting_width
  54. ,u_softbed_mx.cutting_qty
  55. ,u_softbed_mx.useqty
  56. ,u_softbed_mx.use_formula
  57. ,u_softbed_mx.use_formula_str
  58. ,u_softbed_mx.actual_useqty
  59. ,u_softbed_mx.loss_rate
  60. ,u_softbed_mx.price
  61. ,u_softbed_mx.price_formula
  62. ,u_softbed_mx.price_formula_str
  63. ,u_softbed_mx.cost_price
  64. ,u_softbed_mx.cost_amt
  65. ,u_configure_code.name AS pzname
  66. ,u_configure_codemx.namemx AS pzmxname
  67. FROM u_softbed_mx
  68. INNER JOIN u_configure_codemx ON u_configure_codemx.pzid = u_softbed_mx.pzid
  69. AND u_configure_codemx.printid = u_softbed_mx.pz_printid
  70. INNER JOIN u_configure_code ON u_configure_code.pzid = u_configure_codemx.pzid";
  71. DbSqlHelper.SelectJoin(cmd, selectStr, "softbed_id = @billid", new Dictionary<string, object>() { { "@billid", billid } }, "printid,pz_printid", fields, 0, 0, mxlist);
  72. codeList = mxlist.GroupBy(item => new { item.pzid, item.pz_pringid })
  73. .Select(group => new u_configure_codemx
  74. {
  75. pzid = group.Key.pzid,
  76. printid = group.Key.pz_pringid,
  77. pzname = group.First().pzname,
  78. namemx = group.First().pzmxname,
  79. })
  80. .ToList();
  81. }
  82. /// <summary>
  83. /// 获取软床报价单据明细
  84. /// </summary>
  85. /// <param name="billid"></param>
  86. /// <param name="fields"></param>
  87. /// <param name="mxlist"></param>
  88. public void GetSoftBedMxList(int billid, string fields, out List<u_softbed_mx> mxlist)
  89. {
  90. GetSoftBedMxList(billid, fields, out mxlist, out _);
  91. }
  92. /// <summary>
  93. /// 根据部件配置项值获取对应BOM明细
  94. /// </summary>
  95. /// <param name="mxlist"></param>
  96. /// <param name="codeList"></param>
  97. public List<u_softbed_mx> GetSoftBedMxBomList(int deptid, List<u_configure_codemx> codeList)
  98. {
  99. var mxlist = new List<u_softbed_mx>();
  100. foreach(var code in codeList)
  101. {
  102. var resultList = new List<u_configure_codemxbom>();
  103. var outputFields = @"pzid,printid,pid,mtrlid,sonscale,sonscale_formula,mng_cost_rate,profit_rate,realqty,cost,cost_emp,cost_date,sonloss,sonloss_formula,
  104. sondecloss,sondecloss_formula,deptid_scll,price,price_formula,mtrlcode,mtrlname,mtrlmode,unit,mtrlsectype,zxmtrlmode,usermtrlmode";
  105. var selectStr = @"SELECT u_configure_codemxbom.pzid
  106. ,u_configure_codemxbom.printid
  107. ,u_configure_codemxbom.pid
  108. ,u_configure_codemxbom.mtrlid
  109. ,u_configure_codemxbom.sonscale
  110. ,u_configure_codemxbom.sonscale_formula
  111. ,u_configure_codemxbom.mng_cost_rate
  112. ,u_configure_codemxbom.profit_rate
  113. ,u_configure_codemxbom.realqty
  114. ,u_configure_codemxbom.cost
  115. ,u_configure_codemxbom.cost_emp
  116. ,u_configure_codemxbom.cost_date
  117. ,u_configure_codemxbom.sonloss
  118. ,u_configure_codemxbom.sonloss_formula
  119. ,u_configure_codemxbom.sondecloss
  120. ,u_configure_codemxbom.sondecloss_formula
  121. ,u_configure_codemxbom.deptid_scll
  122. ,u_configure_codemxbom.price
  123. ,u_configure_codemxbom.price_formula
  124. ,u_mtrldef.mtrlcode
  125. ,u_mtrldef.mtrlname
  126. ,u_mtrldef.mtrlmode
  127. ,u_mtrldef.unit
  128. ,u_mtrldef.mtrlsectype
  129. ,u_mtrldef.zxmtrlmode
  130. ,u_mtrldef.usermtrlmode
  131. FROM u_configure_codemxbom
  132. INNER JOIN u_mtrldef ON u_configure_codemxbom.mtrlid = u_mtrldef.mtrlid";
  133. DbSqlHelper.SelectJoin(cmd,selectStr,
  134. "u_configure_codemxbom.pzid = @pzid AND u_configure_codemxbom.printid = @printid AND u_configure_codemxbom.deptid_scll = @deptid",
  135. new Dictionary<string, object>() { { "@pzid", code.pzid }, { "@printid",code.printid},{ "@deptid",deptid } },
  136. "u_configure_codemxbom.pid", outputFields, 0,0,resultList);
  137. foreach(var item in resultList)
  138. {
  139. mxlist.Add(InitSoftBedMxFromBom(item));
  140. //
  141. }
  142. }
  143. return null;
  144. }
  145. public u_softbed_mx InitSoftBedMxFromBom(u_configure_codemxbom bomItem)
  146. {
  147. var mx = new u_softbed_mx()
  148. {
  149. pzid = bomItem.pzid,
  150. pz_pringid = bomItem.printid,
  151. mtrlid = bomItem.mtrlid,
  152. mtrlname = bomItem.mtrlname,
  153. mtrlcode = bomItem.mtrlcode,
  154. mtrlmode = bomItem.mtrlmode,
  155. unit = bomItem.unit,
  156. allow_edit = 0,
  157. has_type = 1, // 1-床头、2-床头柜、4-床架
  158. cutting_length = 0,
  159. cutting_qty = 0,
  160. cutting_width = 0,
  161. useqty = bomItem.sonscale,
  162. use_formula = "",
  163. use_formula_str = bomItem.sonscale_formula,
  164. actual_useqty = 0,
  165. loss_rate = bomItem.sonloss,
  166. price = bomItem.price,
  167. price_formula = "",
  168. price_formula_str = bomItem.price_formula,
  169. cost_price = bomItem.cost,
  170. cost_amt = 0
  171. };
  172. // 用量
  173. // 实际用量: 用量 * 损耗
  174. mx.actual_useqty = mx.useqty * mx.loss_rate;
  175. // 成本金额: 实际用量 * 成本单价
  176. mx.cost_amt = mx.actual_useqty * mx.cost_price;
  177. return mx;
  178. }
  179. #region 通用公式方法
  180. private string ConvertToEnglishSymbols(string input)
  181. {
  182. input = input.Replace("(", "(")
  183. .Replace(")", ")")
  184. .Replace(",", ",")
  185. .Replace("。", ".")
  186. .Replace(":", ":")
  187. .Replace(";", ";")
  188. .Replace("“", "\"")
  189. .Replace("”", "\"")
  190. .Replace("‘", "'")
  191. .Replace("’", "'");
  192. return input;
  193. }
  194. private void FormatExpression(string expression)
  195. {
  196. expression = ConvertToEnglishSymbols(expression);
  197. }
  198. #endregion
  199. }
  200. }