123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- using JLHHJSvr.BLL;
- using JLHHJSvr.Com.Model;
- using JLHHJSvr.LJException;
- using JLHHJSvr.Tools;
- using LJLib.DAL.SQL;
- using NPOI.SS.Formula.Functions;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Web;
- namespace JLHHJSvr.Helper
- {
- internal class SoftBedHelper : HelperBase
- {
- /// <summary>
- /// 获取软床报价单据
- /// </summary>
- /// <param name="billid"></param>
- /// <param name="fields"></param>
- /// <param name="bill"></param>
- public u_softbed GetSoftBed(int billid,string fields = null)
- {
- fields = fields ?? @"softbed_id,softbed_code,softbed_name,deptid,create_time,create_by,mtrlmode,mtrltype,has_headboard,has_nightstand,has_bedframe,is_template,
- template_id,template_code,template_name,commission,taxes,other_rate,extras_cost,moneyrate,dscrp,costamt,nottax_factory_cost,nottax_dept_cost,
- dept_cost,foreign_cost";
- var bill = new u_softbed() { softbed_id = billid };
- if (DbSqlHelper.SelectOne(cmd, bill, fields) == 0) return null;
- return bill;
- }
- /// <summary>
- /// 获取软床报价单据明细
- /// </summary>
- /// <param name="billid"></param>
- /// <param name="fields"></param>
- /// <param name="mxlist"></param>
- public void GetSoftBedMxList(int billid,string fields,out List<u_softbed_mx> mxlist,out List<u_configure_codemx> codeList)
- {
- fields = fields ?? @"softbed_id,printid,pzid,pz_printid,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";
- mxlist = new List<u_softbed_mx>();
- var selectStr = @"SELECT u_softbed_mx.softbed_id
- ,u_softbed_mx.printid
- ,u_softbed_mx.pzid
- ,u_softbed_mx.pz_printid
- ,u_softbed_mx.mtrlid
- ,u_softbed_mx.mtrlname
- ,u_softbed_mx.mtrlcode
- ,u_softbed_mx.mtrlmode
- ,u_softbed_mx.unit
- ,u_softbed_mx.has_type
- ,u_softbed_mx.allow_edit
- ,u_softbed_mx.cutting_length
- ,u_softbed_mx.cutting_width
- ,u_softbed_mx.cutting_qty
- ,u_softbed_mx.useqty
- ,u_softbed_mx.use_formula
- ,u_softbed_mx.use_formula_str
- ,u_softbed_mx.actual_useqty
- ,u_softbed_mx.loss_rate
- ,u_softbed_mx.price
- ,u_softbed_mx.price_formula
- ,u_softbed_mx.price_formula_str
- ,u_softbed_mx.cost_price
- ,u_softbed_mx.cost_amt
- ,u_configure_code.name AS pzname
- ,u_configure_codemx.namemx AS pzmxname
- FROM u_softbed_mx
- INNER JOIN u_configure_codemx ON u_configure_codemx.pzid = u_softbed_mx.pzid
- AND u_configure_codemx.printid = u_softbed_mx.pz_printid
- INNER JOIN u_configure_code ON u_configure_code.pzid = u_configure_codemx.pzid";
- DbSqlHelper.SelectJoin(cmd, selectStr, "softbed_id = @billid", new Dictionary<string, object>() { { "@billid", billid } }, "printid,pz_printid", fields, 0, 0, mxlist);
- codeList = mxlist.GroupBy(item => new { item.pzid, item.pz_pringid })
- .Select(group => new u_configure_codemx
- {
- pzid = group.Key.pzid,
- printid = group.Key.pz_pringid,
- pzname = group.First().pzname,
- namemx = group.First().pzmxname,
- })
- .ToList();
- }
- /// <summary>
- /// 获取软床报价单据明细
- /// </summary>
- /// <param name="billid"></param>
- /// <param name="fields"></param>
- /// <param name="mxlist"></param>
- public List<u_softbed_mx> GetSoftBedMxList(int billid, string fields = null)
- {
- GetSoftBedMxList(billid, fields, out var mxlist, out _);
- return mxlist;
- }
- /// <summary>
- /// 根据部件配置项值获取对应BOM明细
- /// </summary>
- /// <param name="mxlist"></param>
- /// <param name="codeList"></param>
- public List<u_softbed_mx> GetSoftBedMxBomList(int deptid, List<u_configure_codemx> codeList)
- {
- var mxlist = new List<u_softbed_mx>();
- foreach(var code in codeList)
- {
- 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,price,price_formula,mtrlcode,mtrlname,mtrlmode,unit,mtrlsectype,zxmtrlmode,usermtrlmode";
- var selectStr = @"SELECT u_configure_codemxbom.pzid
- ,u_configure_codemxbom.printid
- ,u_configure_codemxbom.pid
- ,u_configure_codemxbom.mtrlid
- ,u_configure_codemxbom.sonscale
- ,u_configure_codemxbom.sonscale_formula
- ,u_configure_codemxbom.mng_cost_rate
- ,u_configure_codemxbom.profit_rate
- ,u_configure_codemxbom.realqty
- ,u_configure_codemxbom.cost
- ,u_configure_codemxbom.cost_emp
- ,u_configure_codemxbom.cost_date
- ,u_configure_codemxbom.sonloss
- ,u_configure_codemxbom.sonloss_formula
- ,u_configure_codemxbom.sondecloss
- ,u_configure_codemxbom.sondecloss_formula
- ,u_configure_codemxbom.deptid_scll
- ,u_configure_codemxbom.price
- ,u_configure_codemxbom.price_formula
- ,u_mtrldef.mtrlcode
- ,u_mtrldef.mtrlname
- ,u_mtrldef.mtrlmode
- ,u_mtrldef.unit
- ,u_mtrldef.mtrlsectype
- ,u_mtrldef.zxmtrlmode
- ,u_mtrldef.usermtrlmode
- FROM u_configure_codemxbom
- INNER JOIN u_mtrldef ON u_configure_codemxbom.mtrlid = u_mtrldef.mtrlid";
- DbSqlHelper.SelectJoin(cmd,selectStr,
- "u_configure_codemxbom.pzid = @pzid AND u_configure_codemxbom.printid = @printid AND u_configure_codemxbom.deptid_scll = @deptid",
- new Dictionary<string, object>() { { "@pzid", code.pzid }, { "@printid",code.printid},{ "@deptid",deptid } },
- "u_configure_codemxbom.pid", outputFields, 0,0,resultList);
- foreach(var item in resultList)
- {
- mxlist.Add(InitSoftBedMxFromBom(item));
- }
- }
- return mxlist;
- }
- public u_softbed_mx InitSoftBedMxFromBom(u_configure_codemxbom bomItem)
- {
- var mx = new u_softbed_mx()
- {
- pzid = bomItem.pzid,
- pz_pringid = bomItem.printid,
- mtrlid = bomItem.mtrlid,
- mtrlname = bomItem.mtrlname,
- mtrlcode = bomItem.mtrlcode,
- mtrlmode = bomItem.mtrlmode,
- unit = bomItem.unit,
- allow_edit = 0,
- has_type = 1, // 1-床头、2-床头柜、4-床架
- cutting_length = 0,
- cutting_qty = 0,
- cutting_width = 0,
- useqty = bomItem.sonscale,
- use_formula = "",
- use_formula_str = bomItem.sonscale_formula,
- actual_useqty = 0,
- loss_rate = bomItem.sonloss,
- price = bomItem.price,
- price_formula = "",
- price_formula_str = bomItem.price_formula,
- cost_price = bomItem.cost,
- cost_amt = 0
- };
- // 用量
- // 实际用量: 用量 * 损耗
- mx.actual_useqty = mx.useqty * mx.loss_rate;
- // 成本金额: 实际用量 * 成本单价
- mx.cost_amt = mx.actual_useqty * mx.cost_price;
- return mx;
- }
- /// <summary>
- /// 新建/修改 软床报价
- /// </summary>
- /// <param name="softbed"></param>
- /// <exception cref="LJCommonException"></exception>
- public void SaveSoftBed(u_softbed softbed)
- {
- if (softbed == null) throw new LJCommonException("软床报价保存失败,数据异常!");
- if (softbed.mxList == null || softbed.mxList.Count <= 0) throw new LJCommonException("软床报价保存失败,明细内容为空!");
- // 初始化属性
- AutoInit.AutoInitS(softbed);
- foreach(var mx in softbed.mxList)
- {
- AutoInit.AutoInitS(mx);
- }
- // TODO:计算价格
- //
- var dtNow = DateTime.Now;
- var fields = @"softbed_name,deptid,mtrlmode,mtrltype,has_headboard,has_nightstand,has_bedframe,is_template,
- template_id,template_code,template_name,commission,taxes,other_rate,extras_cost,moneyrate,dscrp,costamt,nottax_factory_cost,nottax_dept_cost,
- dept_cost,foreign_cost";
- var mx_fields = @"softbed_id,printid,pzid,pz_printid,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";
- if(softbed.softbed_id == 0)
- {
- // 新建
- fields += ",softbed_id,softbed_code,create_time,create_by";
- softbed.softbed_id = BllHelper.GetID(cmd, "u_softbed");
- softbed.create_time = dtNow;
- softbed.create_by = context.tokendata.username;
- if (string.IsNullOrEmpty(softbed.softbed_code))
- {
- // 编号-年月日+流水
- softbed.softbed_code = $"RC-{dtNow.ToString("yyyyMMdd")}{(softbed.softbed_id % 10000).ToString("D4")}";
- }
- DbSqlHelper.Insert(cmd, "u_softbed", null, softbed, fields);
- } else
- {
- // 修改
- cmd.CommandText = @"DELETE FROM u_softbed_mx WHERE softbed_id = @softbed_id";
- cmd.Parameters.Clear();
- cmd.Parameters.AddWithValue("@softbed_id", softbed.softbed_id);
- cmd.ExecuteNonQuery();
- DbSqlHelper.Update(cmd, "u_softbed", null, softbed, "softbed_id", fields);
- }
- for (int i = 0; i < softbed.mxList.Count; i++)
- {
- var mx = softbed.mxList[i];
- mx.softbed_id = softbed.softbed_id;
- mx.printid = i + 1;
- DbSqlHelper.Insert(cmd, "u_softbed_mx", null, mx, mx_fields);
- }
- }
- /// <summary>
- /// 复制软床报价
- /// </summary>
- /// <param name="softbed"></param>
- /// <param name="newId"></param>
- public void CopySoftBed(u_softbed softbed, out int newId)
- {
- var fields = @"softbed_code,mtrlmode,mtrltype,has_headboard,has_nightstand,has_bedframe,is_template,
- template_id,template_code,template_name,commission,taxes,other_rate,extras_cost,moneyrate,dscrp";
- var softbed_copy = GetSoftBed(softbed.softbed_id, fields);
- // 判断copy_bedNet.bednetcode是否存在@@字符串,如果存在,则删除@@后面的字符串,包括@@
- if (softbed_copy.softbed_code.IndexOf("@@") > -1)
- {
- softbed_copy.softbed_code = softbed_copy.softbed_code.Substring(softbed_copy.softbed_code.IndexOf("@@"));
- }
- softbed_copy.softbed_code += " @@";
- softbed_copy.softbed_code += DateTime.Now.ToString("yyyMMdd_mmhhss");
- softbed_copy.softbed_id = 0;
- SaveSoftBed(softbed_copy);
- newId = softbed_copy.softbed_id;
- }
- /// <summary>
- /// 删除软床报价
- /// </summary>
- /// <param name="billid"></param>
- /// <exception cref="LJCommonException"></exception>
- public void DeleteSoftBed(int billid)
- {
- var softbed = GetSoftBed(billid, "softbed_code,flag");
- if (softbed == null) throw new LJCommonException($"单据不存在,请检查! billid:{billid}");
- if (softbed.flag == 1) throw new LJCommonException($"单据:{softbed.softbed_code}已审核,无法删除!");
- DbSqlHelper.Delete(cmd, softbed);
- }
- /// <summary>
- /// 审核软床报价
- /// </summary>
- /// <param name="billid"></param>
- /// <exception cref="LJCommonException"></exception>
- public void AuditSoftBed(int billid)
- {
- var softbed = GetSoftBed(billid, "softbed_code,flag");
- if (softbed == null) throw new LJCommonException($"单据不存在,请检查! billid:{billid}");
- if (softbed.flag == 1) throw new LJCommonException($"单据:{softbed.softbed_code}未撤审,无法审核!");
- softbed.flag = 1;
- DbSqlHelper.Update(cmd, "u_softbed",null,softbed, "softbed_id", "flag");
- }
- /// <summary>
- /// 撤审软床报价
- /// </summary>
- /// <param name="billid"></param>
- /// <exception cref="LJCommonException"></exception>
- public void CAuditSoftBed(int billid)
- {
- var softbed = GetSoftBed(billid, "softbed_code,flag");
- if (softbed == null) throw new LJCommonException($"单据不存在,请检查! billid:{billid}");
- if (softbed.flag == 0) throw new LJCommonException($"单据:{softbed.softbed_code}未审核,无法撤审!");
- softbed.flag = 0;
- DbSqlHelper.Update(cmd, "u_softbed", null, softbed, "softbed_id", "flag");
- }
- #region 通用公式方法
- private HashSet<CalCulationFormula> const_formula = new HashSet<CalCulationFormula>();
- private string ConvertToEnglishSymbols(string input)
- {
- input = input.Replace("(", "(")
- .Replace(")", ")")
- .Replace(",", ",")
- .Replace("。", ".")
- .Replace(":", ":")
- .Replace(";", ";")
- .Replace("“", "\"")
- .Replace("”", "\"")
- .Replace("‘", "'")
- .Replace("’", "'");
- return input;
- }
- private void FormatExpression(string expression)
- {
- expression = ConvertToEnglishSymbols(expression);
- }
- #endregion
- }
- }
|