|
@@ -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("【成本金额】", "【实际用量】 * 【成本单价】");
|
|
|
|
|
|
// 常量变量
|