SoftBedHelper.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. using DirectService.Tools;
  2. using JLHHJSvr.BLL;
  3. using JLHHJSvr.Com.Model;
  4. using JLHHJSvr.Excutor;
  5. using JLHHJSvr.LJException;
  6. using JLHHJSvr.Tools;
  7. using LJLib.DAL.SQL;
  8. using NPOI.SS.Formula.Functions;
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Web;
  16. using static JLHHJSvr.Helper.CacheHelper;
  17. namespace JLHHJSvr.Helper
  18. {
  19. internal class SoftBedHelper : HelperBase
  20. {
  21. /// <summary>
  22. /// 获取软床报价单据
  23. /// </summary>
  24. /// <param name="billid"></param>
  25. /// <param name="fields"></param>
  26. /// <param name="bill"></param>
  27. public u_softbed GetSoftBed(int billid,string fields = null)
  28. {
  29. 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,
  30. template_id,template_code,template_name,commission,taxes,taxrate,other_rate,extras_cost,money_type,moneyrate,dscrp,costamt,nottax_factory_cost,nottax_dept_cost,
  31. dept_cost,foreign_cost";
  32. var bill = new u_softbed() { softbed_id = billid };
  33. if (DbSqlHelper.SelectOne(cmd, bill, fields) == 0) return null;
  34. return bill;
  35. }
  36. /// <summary>
  37. /// 获取软床报价单据明细
  38. /// </summary>
  39. /// <param name="billid"></param>
  40. /// <param name="fields"></param>
  41. /// <param name="mxlist"></param>
  42. public List<u_softbed_mx> GetSoftBedMxList(int billid,string fields = null)
  43. {
  44. fields = fields ?? @"softbed_id,printid,formulaid,pzid,mtrlid,mtrlname,mtrlcode,mtrlmode,unit,has_type,allow_edit,cutting_length,cutting_width,cutting_qty,
  45. useqty,use_formula,use_formula_str,actual_useqty,loss_rate,price,price_formula,price_formula_str,cost_price,cost_amt,pzname,pzmxname";
  46. var mxlist = new List<u_softbed_mx>();
  47. var selectStr = @"SELECT u_softbed_mx.softbed_id
  48. ,u_softbed_mx.printid
  49. ,u_softbed_mx.formulaid
  50. ,u_softbed_mx.pzid
  51. ,u_softbed_mx.mtrlid
  52. ,u_softbed_mx.mtrlname
  53. ,u_softbed_mx.mtrlcode
  54. ,u_softbed_mx.mtrlmode
  55. ,u_softbed_mx.unit
  56. ,u_softbed_mx.has_type
  57. ,u_softbed_mx.allow_edit
  58. ,u_softbed_mx.cutting_length
  59. ,u_softbed_mx.cutting_width
  60. ,u_softbed_mx.cutting_qty
  61. ,u_softbed_mx.useqty
  62. ,u_softbed_mx.use_formula
  63. ,u_softbed_mx.use_formula_str
  64. ,u_softbed_mx.actual_useqty
  65. ,u_softbed_mx.loss_rate
  66. ,u_softbed_mx.price
  67. ,u_softbed_mx.price_formula
  68. ,u_softbed_mx.price_formula_str
  69. ,u_softbed_mx.cost_price
  70. ,u_softbed_mx.cost_amt
  71. ,u_configure_code.name AS pzname
  72. FROM u_softbed_mx
  73. LEFT JOIN u_configure_code ON u_softbed_mx.pzid = u_configure_code.pzid
  74. ";
  75. DbSqlHelper.SelectJoin(cmd, selectStr, "softbed_id = @billid", new Dictionary<string, object>() { { "@billid", billid } }, "printid", fields, 0, 0, mxlist);
  76. return mxlist;
  77. }
  78. /// <summary>
  79. /// 根据部件配置项值获取对应BOM明细
  80. /// </summary>
  81. /// <param name="mxlist"></param>
  82. /// <param name="codeList"></param>
  83. public List<u_softbed_mx> GetSoftBedMxBomList(List<u_configure_codemx> codeList)
  84. {
  85. var mxlist = new List<u_softbed_mx>();
  86. foreach(var code in codeList)
  87. {
  88. var resultList = new List<u_configure_codemxbom>();
  89. var outputFields = @"pzid,printid,pid,mtrlid,sonscale,sonscale_formula,mng_cost_rate,profit_rate,realqty,cost,cost_emp,cost_date,sonloss,sonloss_formula,
  90. sondecloss,sondecloss_formula,deptid_scll,default_length,default_width,default_qty,mtrlcode,mtrlname,mtrlmode,unit,
  91. mtrlsectype,zxmtrlmode,usermtrlmode";
  92. var selectStr = @"SELECT u_configure_codemxbom.pzid
  93. ,u_configure_codemxbom.printid
  94. ,u_configure_codemxbom.pid
  95. ,u_configure_codemxbom.mtrlid
  96. ,u_configure_codemxbom.sonscale
  97. ,u_configure_codemxbom.sonscale_formula
  98. ,u_configure_codemxbom.mng_cost_rate
  99. ,u_configure_codemxbom.profit_rate
  100. ,u_configure_codemxbom.realqty
  101. ,u_configure_codemxbom.cost
  102. ,u_configure_codemxbom.cost_emp
  103. ,u_configure_codemxbom.cost_date
  104. ,u_configure_codemxbom.sonloss
  105. ,u_configure_codemxbom.sonloss_formula
  106. ,u_configure_codemxbom.sondecloss
  107. ,u_configure_codemxbom.sondecloss_formula
  108. ,u_configure_codemxbom.deptid_scll
  109. ,u_configure_codemxbom.default_length
  110. ,u_configure_codemxbom.default_width
  111. ,u_configure_codemxbom.default_qty
  112. ,u_mtrldef.mtrlcode
  113. ,u_mtrldef.mtrlname
  114. ,u_mtrldef.mtrlmode
  115. ,u_mtrldef.unit
  116. ,u_mtrldef.mtrlsectype
  117. ,u_mtrldef.zxmtrlmode
  118. ,u_mtrldef.usermtrlmode
  119. FROM u_configure_codemxbom
  120. INNER JOIN u_mtrldef ON u_configure_codemxbom.mtrlid = u_mtrldef.mtrlid";
  121. DbSqlHelper.SelectJoin(cmd,selectStr,
  122. "u_configure_codemxbom.pzid = @pzid AND u_configure_codemxbom.printid = @printid",
  123. new Dictionary<string, object>() { { "@pzid", code.pzid }, { "@printid",code.printid} },
  124. "u_configure_codemxbom.pid", outputFields, 0,0,resultList);
  125. foreach(var item in resultList)
  126. {
  127. mxlist.Add(InitSoftBedMxFromBom(item));
  128. }
  129. }
  130. return mxlist;
  131. }
  132. /// <summary>
  133. /// 初始化配置项值带出的BOM清单列表
  134. /// </summary>
  135. /// <param name="bomItem"></param>
  136. /// <returns></returns>
  137. public u_softbed_mx InitSoftBedMxFromBom(u_configure_codemxbom bomItem)
  138. {
  139. var mx = new u_softbed_mx()
  140. {
  141. pzid = bomItem.pzid,
  142. mtrlid = bomItem.mtrlid,
  143. mtrlname = bomItem.mtrlname,
  144. mtrlcode = bomItem.mtrlcode,
  145. mtrlmode = bomItem.mtrlmode,
  146. unit = bomItem.unit,
  147. allow_edit = 0,
  148. has_type = bomItem.has_type, // 1-床头、2-床头柜、4-床架
  149. cutting_length = bomItem.default_length,
  150. cutting_width = bomItem.default_width,
  151. cutting_qty = bomItem.default_qty,
  152. useqty = bomItem.sonscale,
  153. use_formula = "",
  154. use_formula_str = bomItem.sonscale_formula,
  155. actual_useqty = 0,
  156. loss_rate = bomItem.sonloss,
  157. cost_price = bomItem.cost,
  158. cost_amt = 0
  159. };
  160. // 用量
  161. // 实际用量: 用量 * 损耗
  162. mx.actual_useqty = mx.useqty * mx.loss_rate;
  163. // 成本金额: 实际用量 * 成本单价
  164. mx.cost_amt = mx.actual_useqty * mx.cost_price;
  165. return mx;
  166. }
  167. /// <summary>
  168. /// 新建/修改 软床报价
  169. /// </summary>
  170. /// <param name="softbed"></param>
  171. /// <exception cref="LJCommonException"></exception>
  172. public void SaveSoftBed(u_softbed softbed)
  173. {
  174. if (softbed == null) throw new LJCommonException("软床报价保存失败,数据异常!");
  175. if (softbed.is_template == 0 && (softbed.mxList == null || softbed.mxList.Count <= 0)) throw new LJCommonException("软床报价保存失败,明细内容为空!");
  176. // 初始化属性
  177. AutoInit.AutoInitS(softbed);
  178. foreach(var mx in softbed.mxList)
  179. {
  180. AutoInit.AutoInitS(mx);
  181. }
  182. // TODO:计算价格
  183. CalCulateFormula(softbed);
  184. //
  185. var dtNow = context.opdate;
  186. var fields = @"softbed_relcode,softbed_name,deptid,mtrlmode,mtrltype,has_headboard,has_nightstand,has_bedframe,is_template,
  187. template_id,template_code,template_name,commission,taxes,taxrate,other_rate,extras_cost,money_type,moneyrate,dscrp,costamt,nottax_factory_cost,nottax_dept_cost,
  188. dept_cost,foreign_cost";
  189. var mx_fields = @"softbed_id,printid,pzid,mtrlid,mtrlname,mtrlcode,mtrlmode,unit,has_type,allow_edit,cutting_length,cutting_width,cutting_qty,
  190. useqty,use_formula,use_formula_str,actual_useqty,loss_rate,price,price_formula,price_formula_str,cost_price,cost_amt,pzname,pzmxname";
  191. if(softbed.softbed_id == 0)
  192. {
  193. // 新建
  194. fields += ",softbed_id,softbed_code,create_date,create_emp";
  195. softbed.softbed_id = BllHelper.GetID(cmd, "u_softbed");
  196. softbed.create_date = dtNow;
  197. softbed.create_emp = context.tokendata.username;
  198. if (string.IsNullOrEmpty(softbed.softbed_code))
  199. {
  200. // 编号-年月日+流水
  201. softbed.softbed_code = $"RC-{dtNow.ToString("yyyyMMdd")}{(softbed.softbed_id % 10000).ToString("D4")}";
  202. }
  203. DbSqlHelper.Insert(cmd, "u_softbed", null, softbed, fields);
  204. } else
  205. {
  206. // 修改
  207. softbed.update_date = dtNow;
  208. softbed.update_emp = context.tokendata.username;
  209. fields += ",update_date,update_emp";
  210. cmd.CommandText = @"DELETE FROM u_softbed_mx WHERE softbed_id = @softbed_id";
  211. cmd.Parameters.Clear();
  212. cmd.Parameters.AddWithValue("@softbed_id", softbed.softbed_id);
  213. cmd.ExecuteNonQuery();
  214. DbSqlHelper.Update(cmd, "u_softbed", null, softbed, "softbed_id", fields);
  215. }
  216. for (int i = 0; i < softbed.mxList.Count; i++)
  217. {
  218. var mx = softbed.mxList[i];
  219. mx.softbed_id = softbed.softbed_id;
  220. mx.printid = i + 1;
  221. DbSqlHelper.Insert(cmd, "u_softbed_mx", null, mx, mx_fields);
  222. }
  223. SaveSoftBedTemplate(softbed);
  224. }
  225. /// <summary>
  226. /// 新建软床报价模板
  227. /// </summary>
  228. /// <param name="softbed"></param>
  229. private void SaveSoftBedTemplate(u_softbed softbed)
  230. {
  231. if (softbed.is_template == 0) return;
  232. if(string.IsNullOrEmpty(softbed.softbed_code))
  233. {
  234. throw new LJCommonException("报价未生成唯一码,无法生成模板配置");
  235. }
  236. string prefix = $"{softbed.softbed_code}|";
  237. var configureList = new List<u_configure_type>();
  238. if(softbed.has_headboard == 1)
  239. {
  240. configureList.Add(new u_configure_type()
  241. {
  242. contfigtypeid = 0,
  243. contfigtypename = $"{prefix}床头",
  244. contfigtype = 0,
  245. usechflag = 1,
  246. flag = 0
  247. });
  248. }
  249. if(softbed.has_bedframe == 1)
  250. {
  251. configureList.Add(new u_configure_type()
  252. {
  253. contfigtypeid = 0,
  254. contfigtypename = $"{prefix}床架",
  255. contfigtype = 0,
  256. usechflag = 1,
  257. flag = 0
  258. });
  259. }
  260. if (softbed.has_nightstand == 1)
  261. {
  262. configureList.Add(new u_configure_type()
  263. {
  264. contfigtypeid = 0,
  265. contfigtypename = $"{prefix}床头柜",
  266. contfigtype = 0,
  267. usechflag = 1,
  268. flag = 0
  269. });
  270. }
  271. var baseInfoHelper = GetHelper<BasicInfoHelper>(cmd, context);
  272. foreach(var configure in configureList)
  273. {
  274. // 判断是否已存在
  275. cmd.CommandText = @"SELECT COUNT(*) FROM u_configure_type WHERE LTRIM(RTRIM(contfigtypename)) = @contfigtypename";
  276. cmd.Parameters.Clear();
  277. cmd.Parameters.AddWithValue("@contfigtypename", configure.contfigtypename);
  278. var cnt = Convert.ToInt32(cmd.ExecuteScalar());
  279. if (cnt > 0) continue;
  280. baseInfoHelper.SaveConfigureType(configure);
  281. }
  282. // 生成标准选配项值ifdft
  283. if(softbed.codeMxList != null && softbed.codeMxList.Count > 0)
  284. {
  285. foreach (var codeMx in softbed.codeMxList)
  286. {
  287. if (codeMx.pzid == 0) continue;
  288. // 判断是否有标准
  289. cmd.CommandText = @"SELECT COUNT(*) FROM u_configure_codemx WHERE pzid = @pzid AND ifdft = 1";
  290. cmd.Parameters.Clear();
  291. cmd.Parameters.AddWithValue("@pzid", codeMx.pzid);
  292. if(Convert.ToInt32(cmd.ExecuteScalar()) > 0)
  293. {
  294. cmd.CommandText = @"UPDATE u_configure_codemx SET ifdft = 0 WHERE pzid = @pzid AND ifdft = 1";
  295. cmd.Parameters.Clear();
  296. cmd.Parameters.AddWithValue("@pzid", codeMx.pzid);
  297. cmd.ExecuteNonQuery();
  298. }
  299. codeMx.ifdft = 1;
  300. DbSqlHelper.Update(cmd, "u_configure_codemx", null, codeMx, "pzid,printid", "ifdft");
  301. }
  302. }
  303. }
  304. public List<u_configure_type> GetSoftBedConfigureList(u_softbed softbed)
  305. {
  306. var codeMxList = new List<u_configure_codemx>();
  307. var selectStr = @"SELECT u_configure_codemx.pzid
  308. ,u_configure_codemx.printid
  309. ,u_configure_codemx.pzcodemx
  310. ,u_configure_codemx.namemx
  311. ,u_configure_code.name AS pzname
  312. ,u_configure_code.pzcode
  313. ,u_configure_code.inputtype
  314. ,LTRIM(RTRIM(u_configure_type.contfigtypename)) AS contfigtypename
  315. ,u_configure_code.typeid
  316. FROM u_configure_codemx
  317. INNER JOIN u_configure_code ON u_configure_codemx.pzid = u_configure_code.pzid
  318. INNER JOIN u_configure_type ON u_configure_code.typeid = u_configure_type.contfigtypeid";
  319. var whereList = new List<string>();
  320. var nameList = new List<string>();
  321. if (softbed.softbed_id > 0)
  322. {
  323. // 模版配置获取
  324. var _softbed = GetSoftBed(softbed.softbed_id, "softbed_id,softbed_code,has_headboard,has_nightstand,has_bedframe");
  325. string prefix = $"{_softbed.softbed_code}|";
  326. if(_softbed.has_headboard == 1)
  327. {
  328. nameList.Add($"{prefix}床头");
  329. }
  330. if (_softbed.has_nightstand == 1)
  331. {
  332. nameList.Add($"{prefix}床头柜");
  333. }
  334. if (_softbed.has_bedframe == 1)
  335. {
  336. nameList.Add($"{prefix}床架");
  337. }
  338. }
  339. if(nameList.Count > 0)
  340. {
  341. whereList.Add($"LTRIM(RTRIM(u_configure_type.contfigtypename)) IN {ListEx.getString(nameList)}");
  342. }
  343. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), null, "typeid,pzid,printid", "typeid,pzid,printid,pzcodemx,namemx,pzname,pzcode,contfigtypename", 0, 0, codeMxList);
  344. // 部件选配项
  345. var codeMap = new Dictionary<int, u_configure_code>();
  346. foreach(var codeMx in codeMxList)
  347. {
  348. int pzid = codeMx.pzid.Value;
  349. if (!codeMap.TryGetValue(pzid, out var config))
  350. {
  351. config = new u_configure_code
  352. {
  353. pzid = pzid,
  354. name = codeMx.pzname,
  355. contfigtypename = codeMx.contfigtypename,
  356. pzcode = codeMx.pzcode,
  357. typeid = codeMx.pzid,
  358. codeMxList = new List<u_configure_codemx>()
  359. };
  360. codeMap.Add(pzid, config);
  361. }
  362. config.codeMxList.Add(codeMx);
  363. }
  364. // 部件选配类型
  365. var typeMap = new Dictionary<int, u_configure_type>();
  366. foreach(var code in codeMap.Values.ToList())
  367. {
  368. int typeid = code.typeid.Value;
  369. if (!typeMap.TryGetValue(typeid, out var config))
  370. {
  371. config = new u_configure_type
  372. {
  373. contfigtypeid = typeid,
  374. contfigtypename = code.contfigtypename,
  375. codeList = new List<u_configure_code>()
  376. };
  377. typeMap.Add(typeid, config);
  378. }
  379. config.codeList.Add(code);
  380. }
  381. return typeMap.Values.ToList();
  382. }
  383. /// <summary>
  384. /// 复制软床报价
  385. /// </summary>
  386. /// <param name="softbed"></param>
  387. /// <param name="newId"></param>
  388. public void CopySoftBed(u_softbed softbed, out int newId)
  389. {
  390. var fields = @"mtrlmode,mtrltype,has_headboard,has_nightstand,has_bedframe,is_template,
  391. template_id,template_code,template_name,commission,taxes,taxrate,other_rate,extras_cost,moneyrate";
  392. var softbed_copy = GetSoftBed(softbed.softbed_id, fields);
  393. // 判断copy_bedNet.bednetcode是否存在@@字符串,如果存在,则删除@@后面的字符串,包括@@
  394. if (softbed_copy.softbed_code.IndexOf("@@") > -1)
  395. {
  396. softbed_copy.softbed_code = softbed_copy.softbed_code.Substring(softbed_copy.softbed_code.IndexOf("@@"));
  397. }
  398. softbed_copy.softbed_code += " @@";
  399. softbed_copy.softbed_code += DateTime.Now.ToString("yyyMMdd_mmhhss");
  400. softbed_copy.softbed_id = 0;
  401. SaveSoftBed(softbed_copy);
  402. newId = softbed_copy.softbed_id;
  403. }
  404. /// <summary>
  405. /// 删除软床报价
  406. /// </summary>
  407. /// <param name="billid"></param>
  408. /// <exception cref="LJCommonException"></exception>
  409. public void DeleteSoftBed(int billid)
  410. {
  411. var softbed = GetSoftBed(billid, "softbed_code,flag");
  412. if (softbed == null) throw new LJCommonException($"单据不存在,请检查! billid:{billid}");
  413. if (softbed.flag == 1) throw new LJCommonException($"单据:{softbed.softbed_code}已审核,无法删除!");
  414. DbSqlHelper.Delete(cmd, softbed);
  415. }
  416. /// <summary>
  417. /// 审核软床报价
  418. /// </summary>
  419. /// <param name="billid"></param>
  420. /// <exception cref="LJCommonException"></exception>
  421. public void AuditSoftBed(int billid)
  422. {
  423. var softbed = GetSoftBed(billid, "softbed_code,flag");
  424. if (softbed == null) throw new LJCommonException($"单据不存在,请检查! billid:{billid}");
  425. if (softbed.flag == 1) throw new LJCommonException($"单据:{softbed.softbed_code}未撤审,无法审核!");
  426. softbed.flag = 1;
  427. softbed.audit_date = context.opdate;
  428. softbed.audit_emp = context.tokendata.username;
  429. DbSqlHelper.Update(cmd, "u_softbed",null,softbed, "softbed_id", "flag,audit_date,audit_emp");
  430. }
  431. /// <summary>
  432. /// 撤审软床报价
  433. /// </summary>
  434. /// <param name="billid"></param>
  435. /// <exception cref="LJCommonException"></exception>
  436. public void CAuditSoftBed(int billid)
  437. {
  438. var softbed = GetSoftBed(billid, "softbed_code,flag");
  439. if (softbed == null) throw new LJCommonException($"单据不存在,请检查! billid:{billid}");
  440. if (softbed.flag == 0) throw new LJCommonException($"单据:{softbed.softbed_code}未审核,无法撤审!");
  441. softbed.flag = 0;
  442. softbed.audit_date = null;
  443. softbed.audit_emp = string.Empty;
  444. DbSqlHelper.Update(cmd, "u_softbed", null, softbed, "softbed_id", "flag,audit_date,audit_emp");
  445. }
  446. public void CalCulateFormula(u_softbed softbed)
  447. {
  448. InitSoftBed(softbed);
  449. InitReplaceMents(softbed);
  450. foreach (var mx in softbed.mxList)
  451. {
  452. InitMxReplaceMents(softbed, mx);
  453. }
  454. }
  455. private void InitSoftBed(u_softbed softbed)
  456. {
  457. var dept = Cache.GetData<int, u_dept, DeptMapping>(softbed.deptid);
  458. softbed.moneyrate = softbed.moneyrate <= 0 ? 1 : softbed.moneyrate;
  459. softbed.commission = softbed.commission <= 0 ? 1 : softbed.commission;
  460. softbed.taxrate = softbed.taxrate <= 0 ? 1 : softbed.taxrate;
  461. softbed.other_rate = softbed.other_rate <= 0 ? 1 : softbed.other_rate;
  462. softbed.dept_profitrate = softbed.dept_profitrate <= 0 ? 1 : softbed.dept_profitrate;
  463. // 检查佣金是否小于1
  464. if (softbed.commission < 1)
  465. {
  466. throw new LJCommonException("佣金点数不能小于1!");
  467. }
  468. // 检查税率是否小于1
  469. if (softbed.taxrate < 1)
  470. {
  471. throw new LJCommonException("税率不能小于1!");
  472. }
  473. // 检查额外点数是否小于1
  474. if (softbed.other_rate < 1)
  475. {
  476. throw new LJCommonException("税率不能小于1!");
  477. }
  478. // 检查部门利润率是否为0
  479. if (softbed.dept_profitrate == 0)
  480. {
  481. throw new LJCommonException("部门利润率不能为0!");
  482. }
  483. if(softbed.is_template == 1)
  484. {
  485. // 使用模板报价
  486. softbed.template_id = 0;
  487. softbed.template_code = string.Empty;
  488. softbed.template_name = string.Empty;
  489. }
  490. }
  491. private void InitReplaceMents(u_softbed softbed)
  492. {
  493. // 公式变量
  494. formula.AddFormulaItem("【不含税出厂价】", "【车间成本】*(【工厂利润率】+【外销加点】)");
  495. formula.AddFormulaItem("【部门不含税价】", "【不含税出厂价】/【部门利润率】/( 1 - (【佣金点数】- 1))*【额外点数】+【FOB】");
  496. formula.AddFormulaItem("【部门含税价】", "【部门不含税价】*【税率】");
  497. formula.AddFormulaItem("【税金】", "【部门不含税价】* (【税率】-1)");
  498. formula.AddFormulaItem("【外币价】", "【部门含税价】/【汇率】");
  499. // 常量变量
  500. formula.AddFormulaItem("【部门利润率】", softbed.dept_profitrate);
  501. formula.AddFormulaItem("【佣金点数】", softbed.commission);
  502. formula.AddFormulaItem("【额外点数】", softbed.other_rate);
  503. formula.AddFormulaItem("【额外费用】", softbed.extras_cost);
  504. formula.AddFormulaItem("【FOB】", 0);
  505. formula.AddFormulaItem("【汇率】", softbed.moneyrate);
  506. formula.AddFormulaItem("【税率】", softbed.taxrate);
  507. }
  508. private void InitMxReplaceMents(u_softbed softbed,u_softbed_mx mx)
  509. {
  510. // 默认公式变量
  511. formula.AddFormulaItem("【实际用量】", "【用料量】*【1 + 损耗率】");
  512. formula.AddFormulaItem("【成本金额】", "【实际用量】 * 【成本单价】");
  513. // 常量变量
  514. formula.AddFormulaItem("【下料长】", mx.cutting_length);
  515. formula.AddFormulaItem("【下料宽】", mx.cutting_width);
  516. formula.AddFormulaItem("【下料数量】", mx.cutting_qty);
  517. formula.AddFormulaItem("【用料量】", mx.useqty);
  518. formula.AddFormulaItem("【损耗率】", mx.loss_rate);
  519. formula.AddFormulaItem("【材料单价】", mx.price);
  520. if(mx.formulaid > 0)
  521. {
  522. cmd.CommandText = @"SELECT u_softbed_formula.formulaid
  523. ,u_softbed_formula.formulaname
  524. ,u_softbed_formula.use_formula
  525. ,u_softbed_formula.price_formula
  526. FROM u_softbed_formula
  527. WHERE formulaid = @formulaid";
  528. cmd.Parameters.Clear();
  529. cmd.Parameters.AddWithValue("@formulaid", mx.formulaid);
  530. using(var reader = cmd.ExecuteReader())
  531. {
  532. if(reader.Read())
  533. {
  534. formula.AddFormulaItem("【实际用量】", Convert.ToString(reader["use_formula"]));
  535. formula.AddFormulaItem("【成本单价】", Convert.ToString(reader["price_formula"]));
  536. }
  537. }
  538. }
  539. }
  540. #region 通用公式
  541. private CalculateFormula formula = new CalculateFormula();
  542. #endregion
  543. }
  544. }