MattressHelper.cs 160 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564
  1. using CSUST.Data.Expr;
  2. using DirectService.Tools;
  3. using JLHHJSvr.BLL;
  4. using JLHHJSvr.Com.Model;
  5. using JLHHJSvr.LJException;
  6. using JLHHJSvr.LJFramework.Tools;
  7. using JLHHJSvr.Tools;
  8. using LJLib.DAL.SQL;
  9. using NPOI.POIFS.Properties;
  10. using NPOI.SS.Formula.Functions;
  11. using System;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using System.Data.SqlClient;
  15. using System.Linq;
  16. using System.Runtime.InteropServices;
  17. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  18. using System.Text;
  19. using System.Text.RegularExpressions;
  20. using System.Threading.Tasks;
  21. using static JLHHJSvr.Helper.CacheHelper;
  22. namespace JLHHJSvr.Helper
  23. {
  24. class MattressHelper : HelperBase
  25. {
  26. private Dictionary<string, object> replacements = new Dictionary<string, object>();
  27. /// <summary>
  28. /// 默认展示公式
  29. /// </summary>
  30. private Dictionary<string, string> formula_replacements = new Dictionary<string, string>();
  31. /// <summary>
  32. /// 隐藏公式
  33. /// </summary>
  34. private Dictionary<string, string> formula_replacements_hide = new Dictionary<string, string>();
  35. /// <summary>
  36. /// 床网参数替换
  37. /// </summary>
  38. public List<replacement_bednet> BendetReplace = new List<replacement_bednet>();
  39. public List<replacement> BendetFormulasReplace = new List<replacement>();
  40. public List<replacement> Replacements
  41. {
  42. get
  43. {
  44. var res = new List<replacement>();
  45. foreach (var item in replacements)
  46. {
  47. res.Add(new replacement { label = item.Key, value = item.Value, type = 0 });
  48. }
  49. return res;
  50. }
  51. }
  52. public List<replacement> FormulaReplacements
  53. {
  54. get
  55. {
  56. var res = new List<replacement>();
  57. foreach (var item in formula_replacements)
  58. {
  59. res.Add(new replacement { label = item.Key, value = item.Value, type = 0 });
  60. }
  61. string[] keys = { "车间成本", "总床垫车间成本", "不含税出厂价", "部门不含税价", "税金", "部门含税价", "外币价", "底价", "佣金" };
  62. res = res.OrderBy(r => Array.IndexOf(keys, r.label.Replace("【", "").Replace("】", ""))).ToList();
  63. foreach (var item in formula_replacements_hide)
  64. {
  65. res.Add(new replacement { label = item.Key, value = item.Value, type = 1 });
  66. }
  67. return res;
  68. }
  69. }
  70. /// <summary>
  71. /// 公式计算
  72. /// </summary>
  73. /// <param name="mattress"></param>
  74. /// <param name="mxlist"></param>
  75. /// <param name="isCalBed">是否实时计算</param>
  76. /// <param name="isNewFormula">是否获取新的公式计算</param>
  77. /// <param name="extraProcesses">特殊工艺</param>
  78. /// <param name="extraCosts">额外费用</param>
  79. public void CalCulateFormula(u_mattress mattress, List<u_mattress_mx_mtrl> mxlist, Boolean isCalBed = true, Boolean isNewFormula = true, List<u_mattress_mx_extra> extraProcesses = null, List<u_mattress_mx_extra> extraCosts = null)
  80. {
  81. BendetReplace = new List<replacement_bednet>();
  82. BendetFormulasReplace = new List<replacement>();
  83. InitMattress(mattress);
  84. InitReplaceMents(mattress, isCalBed, isNewFormula, extraProcesses, extraCosts);
  85. if (isCalBed || isNewFormula) CalCulateBedNet(mxlist, isCalBed, isNewFormula, mattress.deptid.Value);
  86. // 实时计算价格
  87. if (isCalBed)
  88. {
  89. InitMattressMx(mattress, mxlist);
  90. //CalCulateBedNet(mxlist);
  91. var diancengList = mxlist.Where(t => t.formulatype == 1).ToList();
  92. var mattersstype = new u_mattress_type() { mattresstypeid = mattress.mattresstypeid };
  93. DbSqlHelper.SelectOne(cmd, mattersstype, "formula_big_side,formula_small_side,formula_v_side");
  94. var thicknessDict = InitMxThicknessReplaceMents(mxlist);
  95. foreach (var mx in mxlist)
  96. {
  97. if (mx.mtrlid == 0 && mx.formulakind != 31) continue;
  98. if (string.IsNullOrEmpty(mx.formula) && string.IsNullOrEmpty(mx.useformula)) continue;
  99. InitMxReplaceMents(mx);
  100. // 顶替分组关键值:內布套、顶布裥棉
  101. if (thicknessDict.ContainsKey(mx.chastr))
  102. {
  103. foreach(var rp in thicknessDict[mx.chastr])
  104. {
  105. AddKeyValue(rp.Key, rp.Value);
  106. }
  107. }
  108. string expression = ConvertToEnglishSymbols(mx.formula), use_expression = ConvertToEnglishSymbols(mx.useformula);
  109. #region 替换大侧,小侧,V侧高度
  110. expression = InitMxSideReplaceMents(mattress, mx, diancengList, mattersstype, expression);
  111. use_expression = InitMxSideReplaceMents(mattress, mx, diancengList, mattersstype,use_expression);
  112. #endregion
  113. #region 替换布料幅宽
  114. //大侧
  115. if (new List<int>() { 2,42,52,62,72,82 }.Contains(mx.formulakind.Value))
  116. {
  117. InitMxClothWidthReplaceMents(mx, mxlist,2);
  118. }
  119. //小侧
  120. if (new List<int>() { 3, 43, 53, 63, 73, 83 }.Contains(mx.formulakind.Value))
  121. {
  122. InitMxClothWidthReplaceMents(mx, mxlist,3);
  123. }
  124. //大侧
  125. if (new List<int>() { 4, 44, 54, 64, 74, 84 }.Contains(mx.formulakind.Value))
  126. {
  127. InitMxClothWidthReplaceMents(mx, mxlist,4);
  128. }
  129. //面裥绵
  130. if (new List<int>() { 0, 40, 50, 60, 70, 80, 203 }.Contains(mx.formulakind.Value))
  131. {
  132. InitMxClothWidthReplaceMents(mx, mxlist,0);
  133. }
  134. //底裥绵
  135. if (new List<int>() { 1, 41, 51, 61, 71, 81 }.Contains(mx.formulakind.Value))
  136. {
  137. InitMxClothWidthReplaceMents(mx, mxlist,1);
  138. }
  139. #endregion
  140. #region 替换布套高
  141. //if(new List<int>() { 101 }.Contains(mx.formulakind.Value))
  142. //{
  143. // if (mx.mattress_width != null && mx.mattress_width > 0) expression = expression.Replace("【规格宽】", $"{mx.mattress_width}");
  144. // if (mx.mattress_length != null && mx.mattress_length > 0) expression = expression.Replace("【规格长】", $"{mx.mattress_length}");
  145. //}
  146. //内布套
  147. if (new List<int>() { 101,102,103,104,105,106 }.Contains(mx.formulakind.Value))
  148. {
  149. expression = InitMxClothHeightReplaceMents(mattress, mx, expression, mxlist, 101);
  150. use_expression = InitMxClothHeightReplaceMents(mattress, mx, use_expression, mxlist, 101);
  151. }
  152. //外布套
  153. if (new List<int>() { 111, 112, 113, 114, 115, 116 }.Contains(mx.formulakind.Value))
  154. {
  155. expression = InitMxClothHeightReplaceMents(mattress, mx, expression, mxlist, 111);
  156. use_expression = InitMxClothHeightReplaceMents(mattress, mx, use_expression, mxlist, 111);
  157. }
  158. #endregion
  159. #region 裥绵收缩率
  160. InitMxShrinkageReplaceMents(mx,mxlist);
  161. #endregion
  162. foreach (var replacement in replacements)
  163. {
  164. expression = expression.Replace(replacement.Key, Convert.ToString(replacement.Value));
  165. use_expression = use_expression.Replace(replacement.Key, Convert.ToString(replacement.Value));
  166. }
  167. #region 计算成本金额
  168. // 判断expression前两个字符是否为@@
  169. bool sqlCal = !string.IsNullOrEmpty(expression) && expression.Length > 2 && expression.Substring(0, 2) == "@@";
  170. expression = expression.Replace("@@", "");
  171. mx.replace_formula = expression;
  172. try
  173. {
  174. if (sqlCal)
  175. {
  176. mx.costamt = Convert.ToDecimal(SqlCalculate(expression, "成本金额"));
  177. }
  178. else
  179. {
  180. mx.costamt = Calculate(expression, "成本金额").DecimalValue;
  181. }
  182. }
  183. catch (Exception e)
  184. {
  185. mx.if_success = 1;
  186. mx.message = e.Message;
  187. }
  188. #endregion
  189. #region 计算清单用量
  190. sqlCal = !string.IsNullOrEmpty(use_expression) && use_expression.Length > 2 &&use_expression.Substring(0, 2) == "@@";
  191. use_expression = use_expression.Replace("@@", "");
  192. mx.replace_useformula = use_expression;
  193. try
  194. {
  195. if (sqlCal)
  196. {
  197. mx.useqty = Convert.ToDecimal(SqlCalculate(use_expression, "清单用量"));
  198. }
  199. else
  200. {
  201. mx.useqty = Calculate(use_expression, "清单用量").DecimalValue;
  202. }
  203. }
  204. catch (Exception e)
  205. {
  206. mx.if_success = 1;
  207. mx.message = e.Message;
  208. }
  209. #endregion
  210. }
  211. }
  212. InitMattressMxListReplaceMents(mattress, mxlist, isNewFormula);
  213. string[] keys = { "车间成本", "不含税出厂价", "部门不含税价", "税金", "部门含税价", "外币价", "底价", "佣金" };
  214. if (formula_replacements_hide.Count > 0)
  215. {
  216. foreach (var replacement in formula_replacements_hide)
  217. {
  218. var _key = replacement.Key.Replace("【", "").Replace("】", "");
  219. var value = CalculateVarFormula(_key).DecimalValue;
  220. AddKeyValue(_key, value);
  221. }
  222. foreach (var replacement in formula_replacements)
  223. {
  224. var _key = replacement.Key.Replace("【", "").Replace("】", "");
  225. if (!keys.Contains(_key) )
  226. {
  227. var value = CalculateVarFormula(_key).DecimalValue;
  228. AddKeyValue(_key, value);
  229. }
  230. }
  231. }
  232. if(mattress.dannum_type == 2)
  233. {
  234. foreach (var re in BendetReplace)
  235. {
  236. foreach (var mx in re.replace.Where(t => new List<string>() { "【总人力费用】", "【总材料成本】" }.Contains(t.label)))
  237. {
  238. mattress.total_mtrl_hr_cost += Convert.ToDecimal(mx.value);
  239. }
  240. }
  241. replacements.TryGetValue("【总人工费用】", out object hrCost);
  242. replacements.TryGetValue("【总材料成本】", out object mtrlCost);
  243. mattress.total_mtrl_hr_cost += Convert.ToDecimal(hrCost);
  244. mattress.total_mtrl_hr_cost += Convert.ToDecimal(mtrlCost);
  245. }
  246. }
  247. /// <summary>
  248. /// 记录明细按分组读取厚度变量
  249. /// </summary>
  250. /// <param name="mxlist"></param>
  251. private Dictionary<string, Dictionary<string, object>> InitMxThicknessReplaceMents(List<u_mattress_mx_mtrl> mxlist)
  252. {
  253. // 明细按分组读取厚度变量
  254. var thicknessDict = new Dictionary<string, Dictionary<string, object>> () { };
  255. foreach (var mx in mxlist)
  256. {
  257. // 只处理 内布套(101,102)、顶布裥棉(103)
  258. if (!new List<int>() { 101, 102, 103 }.Contains(mx.formulatype.Value)) continue;
  259. if (mx.chastr.Contains("顶布裥棉") || mx.chastr.Contains("内布套"))
  260. {
  261. if(!thicknessDict.ContainsKey(mx.chastr))
  262. {
  263. thicknessDict.Add(mx.chastr, new Dictionary<string, object>() {});
  264. }
  265. var mxDict = thicknessDict[mx.chastr];
  266. setMxThicknessValue(mx, ref mxDict);
  267. thicknessDict[mx.chastr] = mxDict;
  268. }
  269. }
  270. return thicknessDict;
  271. }
  272. private void setMxThicknessValue(u_mattress_mx_mtrl mx, ref Dictionary<string, object> mxDict)
  273. {
  274. var keyStr = "";
  275. if (new List<int>() { 101, 102 }.Contains(mx.formulatype.Value))
  276. {
  277. switch (mx.formulakind.Value)
  278. {
  279. case 0: // 面裥绵-布料
  280. keyStr = "内布套上覆";
  281. break;
  282. case 1: // 底裥绵-布料
  283. keyStr = "内布套下覆";
  284. break;
  285. case 2: // 大侧裥绵-布料
  286. keyStr = "内布套侧覆";
  287. break;
  288. }
  289. if (!string.IsNullOrEmpty(keyStr))
  290. {
  291. mxDict.Add(keyStr, mx.sidecover);
  292. }
  293. }
  294. else if (new List<int>() { 103 }.Contains(mx.formulatype.Value))
  295. {
  296. switch (mx.formulakind.Value)
  297. {
  298. case 50: // 面裥绵-裥绵海绵
  299. keyStr = "物料厚度";
  300. break;
  301. }
  302. if (!string.IsNullOrEmpty(keyStr))
  303. {
  304. mxDict.Add(keyStr, mx.thickness.Value);
  305. }
  306. }
  307. }
  308. private void CalCulateBedNet(List<u_mattress_mx_mtrl> mxlist, Boolean isCalBed = true, Boolean isNewFormula = true, int deptid = 0)
  309. {
  310. var bedNetHelper = HelperBase.GetHelper<BedNetHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  311. var bednetList = mxlist.Where(t => t.formulatype == 99);
  312. decimal dannumRate = 0;
  313. int dannumType = 0;
  314. //if (replacements.TryGetValue("【大小单系数】", out object value2))
  315. //{
  316. // dannumRate = Convert.ToDecimal(value2);
  317. //}
  318. if (replacements.TryGetValue("【大小单类型】", out object value1))
  319. {
  320. dannumType = Convert.ToInt32(value1);
  321. }
  322. List<replacement_bednet> rpBednet = new List<replacement_bednet>();
  323. var bednetSumList = new List<decimal?>();
  324. var index = 0;
  325. foreach (var mx in bednetList)
  326. {
  327. if (mx.mtrlid <= 0) continue;
  328. var bednet = bedNetHelper.GetBedNet(mx.mtrlid.Value);
  329. if (bednet.flag == 1) continue;
  330. if (deptid > 0)
  331. {
  332. bednet.deptid = deptid;
  333. }
  334. var bednetMxlist = bedNetHelper.GetBedNetMxList(bednet.bednetid.Value);
  335. var bednetSpringList = bedNetHelper.GetBedNetSpringList(bednet.bednetid.Value);
  336. //bednet.dannum_rate = dannumRate;
  337. bednet.dannum_type = dannumType;
  338. bedNetHelper.CalCulateFormula(bednet, bednetMxlist, bednetSpringList, true, true);
  339. var rpBednetItem = new replacement_bednet()
  340. {
  341. label = mx.mtrlname,
  342. replace = bedNetHelper.Replacements
  343. };
  344. BendetFormulasReplace = bedNetHelper.FormulaReplacements.Where(itm => new List<int>{ 0, 1 }.Contains(itm.type.Value)).ToList();
  345. rpBednet.Add(rpBednetItem);
  346. //if (isCalBed)
  347. //{
  348. // bedNetHelper.SaveBedNet(bednet, bednetMxlist, bednetSpringList);
  349. //}
  350. if (isNewFormula)
  351. {
  352. mx.price = bednet.total_cost;
  353. AddKeyValue("床网车间成本" + (index + 1), bednet.total_cost);
  354. bednetSumList.Add(bednet.total_cost);
  355. }
  356. else
  357. {
  358. mx.price = bednet.nottax_factory_cost;
  359. }
  360. }
  361. BendetReplace = rpBednet;
  362. #region 总床网车间成本
  363. AddKeyValue("总床网车间成本", bednetSumList.Sum());
  364. #endregion
  365. }
  366. private void InitMattress(u_mattress mattress)
  367. {
  368. var dept = Cache.GetData<u_dept, DeptMapping>(mattress.deptid.Value);
  369. //var profirate = new u_factory_profitrate() { deptid = mattress.deptid, bednettypeid_mattresstypeid = mattress.mattresstypeid, bednet_or_mattress = 1 };
  370. //DbSqlHelper.SelectOne(cmd, profirate, "profitrate");
  371. decimal profitrate = 0;
  372. cmd.CommandText = @"SELECT profitrate FROM u_factory_profitrate
  373. WHERE deptid = @deptid
  374. AND bednettypeid_mattresstypeid = @bednettypeid_mattresstypeid
  375. AND bednet_or_mattress = 1";
  376. cmd.Parameters.Clear();
  377. cmd.Parameters.AddWithValue("@deptid", mattress.deptid);
  378. cmd.Parameters.AddWithValue("@bednettypeid_mattresstypeid", mattress.mattresstypeid);
  379. using (var reader = cmd.ExecuteReader())
  380. {
  381. if (reader.Read())
  382. {
  383. profitrate = Convert.ToDecimal(reader["profitrate"]);
  384. }
  385. }
  386. mattress.pricelistid = dept.pricelistid;
  387. mattress.dept_profitrate = dept.profitrate;
  388. mattress.profitrate = profitrate;
  389. mattress.moneyrate = mattress.if_moneyrate == 1 ? dept.moneyrate ?? 1 : 1;
  390. mattress.discount = dept.discount ?? 1 ;
  391. mattress.commission = mattress.commission ?? 1;
  392. mattress.taxrate = mattress.taxrate ?? 1;
  393. mattress.other_rate = mattress.other_rate ?? 1;
  394. mattress.dept_profitrate = mattress.dept_profitrate ?? 0;
  395. // 检查佣金是否小于1
  396. if (mattress.commission < 1)
  397. {
  398. throw new LJCommonException("佣金点数不能小于1!");
  399. }
  400. // 检查税率是否小于1
  401. if (mattress.taxrate < 1)
  402. {
  403. throw new LJCommonException("税率不能小于1!");
  404. }
  405. // 检查额外点数是否小于1
  406. if (mattress.other_rate < 1)
  407. {
  408. throw new LJCommonException("税率不能小于1!");
  409. }
  410. // 检查部门利润率是否为0
  411. if (mattress.dept_profitrate == 0)
  412. {
  413. throw new LJCommonException("部门利润率不能为0!");
  414. }
  415. }
  416. private void InitMattressMx(u_mattress mattress,List<u_mattress_mx_mtrl> mxlist)
  417. {
  418. foreach (var mx in mxlist)
  419. {
  420. if (!new List<int>() { 0, 1, 2, 3, 104 }.Contains(mx.formulatype.Value)) continue;
  421. // 垫层 wf_check_dianceng_ifright
  422. if (mx.formulatype.Value == 1)
  423. {
  424. cmd.CommandText = @"SELECT TOP 1 formulaid From u_mattress_formula where formulakind = @ll_formulakind";
  425. cmd.Parameters.Clear();
  426. cmd.Parameters.AddWithValue("@ll_formulakind", mx.formulakind);
  427. using (var reader = cmd.ExecuteReader())
  428. {
  429. if (reader.Read())
  430. {
  431. mx.formulaid = Convert.ToInt32(reader["formulaid"]);
  432. }
  433. else
  434. {
  435. mx.formulaid = 0;
  436. }
  437. }
  438. }
  439. var formula = new u_mattress_formula() { formulaid = mx.formulaid, };
  440. DbSqlHelper.SelectOne(cmd, formula, "formulakind,formulatype,sortcode");
  441. var mtrldef = new u_mtrl_price() { mtrlid = mx.mtrlid };
  442. DbSqlHelper.SelectOne(cmd, mtrldef, "name,gram_weight,cloth_width,if_inputqty,priceunit,shrinkage,if_areaprice");
  443. mx.costamt = 0;
  444. mx.useqty = 0;
  445. mx.if_success = 0;
  446. mx.replace_formula = "";
  447. mx.replace_useformula = "";
  448. mx.formulakind = formula.formulakind;
  449. mx.formulatype = formula.formulatype;
  450. //mx.sortcode = formula.sortcode.Trim();
  451. mx.mtrlname = mtrldef.name ?? "";
  452. var formula2 = new u_mattress_formula();
  453. DbSqlHelper.SelectOne(cmd, "u_mattress_formula","formulakind = @formulakind",
  454. new Dictionary<string, object>() { { "@formulakind",mx.formulakind } },formula2, "formula,useformula,gydscrp");
  455. mx.formula = formula2.formula;
  456. mx.useformula = formula2.useformula;
  457. mx.gydscrp = formula2.gydscrp;
  458. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS pricelistprice
  459. ,u_mtrl_price.gram_weight
  460. ,u_mtrl_price.cloth_width
  461. ,u_mtrl_price.if_inputqty
  462. ,u_mtrl_price.priceunit
  463. ,u_mtrl_price.shrinkage
  464. ,isnull(u_mtrl_price_pricelist.price_formula, 0) AS price_formula
  465. ,isnull(u_mtrl_price_pricelist.qty_formula, 0) AS qty_formula
  466. ,u_mtrl_price.if_areaprice
  467. ,u_mtrl_price.thickness
  468. FROM u_mtrl_price
  469. INNER JOIN u_mtrl_price_pricelist ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  470. WHERE (u_mtrl_price.mtrlid = @mtrlid)
  471. AND (u_mtrl_price_pricelist.pricelistid = @pricelistid)";
  472. cmd.Parameters.Clear();
  473. cmd.Parameters.AddWithValue("@mtrlid", mx.mtrlid);
  474. cmd.Parameters.AddWithValue("@pricelistid", mattress.pricelistid);
  475. using(var reader = cmd.ExecuteReader())
  476. {
  477. if (reader.Read())
  478. {
  479. mx.price = Convert.ToDecimal(reader["pricelistprice"]);
  480. mx.gram_weight = Convert.ToDecimal(reader["gram_weight"]);
  481. mx.cloth_width = Convert.ToDecimal(reader["cloth_width"]);
  482. mx.if_inputqty = Convert.ToInt32(reader["if_inputqty"]);
  483. mx.priceunit = reader["priceunit"].ToString();
  484. mx.shrinkage = Convert.ToDecimal(reader["shrinkage"]);
  485. mx.if_areaprice = Convert.ToByte(reader["if_areaprice"]);
  486. if(mx.if_inputqty == 1) mx.thickness = Convert.ToDecimal(reader["thickness"]);
  487. string price_formula = Convert.ToString(reader["price_formula"]);
  488. string qty_formula = Convert.ToString(reader["qty_formula"]);
  489. mx.formula = string.IsNullOrEmpty(price_formula) ? mx.formula : price_formula;
  490. mx.useformula = string.IsNullOrEmpty(qty_formula) ? mx.useformula : qty_formula;
  491. }
  492. }
  493. }
  494. }
  495. /// <summary>
  496. /// 其他额外费用tab / 特殊工艺计算
  497. /// </summary>
  498. /// <param name="mattress"></param>
  499. /// <param name="typeid"></param> 1: 特殊工艺。2:其他额外费用
  500. /// <returns></returns>
  501. private decimal GetExtraAmt(u_mattress mattress, int typeid)
  502. {
  503. decimal amt = 0;
  504. cmd.CommandText = @"
  505. SELECT ISNULL(SUM(u_mattress_mx_extra.price * u_mattress_mx_extra.qty), 0) AS amt
  506. From u_mattress_mx_extra
  507. INNER JOIN u_mattress_extra_type On u_mattress_extra_type.extraid = u_mattress_mx_extra.extraid
  508. WHERE u_mattress_extra_type.typeid = @typeid
  509. AND u_mattress_mx_extra.mattressid = @mattressid";
  510. cmd.Parameters.Clear();
  511. cmd.Parameters.AddWithValue("@typeid", typeid);
  512. cmd.Parameters.AddWithValue("@mattressid", mattress.mattressid);
  513. using (var reader = cmd.ExecuteReader())
  514. {
  515. if (reader.Read())
  516. {
  517. amt = Convert.ToDecimal(reader["amt"]);
  518. }
  519. }
  520. return amt;
  521. }
  522. private void InitReplaceMents(u_mattress mattress, Boolean isCalBed = true, Boolean isNewFormula = true, List<u_mattress_mx_extra> extraProcesses = null, List<u_mattress_mx_extra> extraCosts = null)
  523. {
  524. replacements.Clear();
  525. decimal cost = 0;
  526. if (isCalBed)
  527. {
  528. if (extraCosts != null)
  529. {
  530. foreach (var itemCost in extraCosts)
  531. {
  532. cost += itemCost.price.Value * itemCost.qty.Value;
  533. }
  534. }
  535. }
  536. else
  537. {
  538. cost = GetExtraAmt(mattress, 2);
  539. }
  540. AddKeyValue("材料额外费用", cost);
  541. decimal cost1 = 0;
  542. if (isCalBed)
  543. {
  544. if (extraProcesses != null)
  545. {
  546. foreach (var itemPro in extraProcesses)
  547. {
  548. cost1 += itemPro.price.Value * itemPro.qty.Value;
  549. }
  550. }
  551. }
  552. else
  553. {
  554. cost1 = GetExtraAmt(mattress, 1);
  555. }
  556. AddKeyValue("特殊工艺费用", cost1);
  557. AddKeyValue("规格宽", mattress.mattress_width);
  558. AddKeyValue("规格长", mattress.mattress_length);
  559. AddKeyValue("规格高", mattress.mattress_height);
  560. AddKeyValue("压包数量", mattress.packqty);
  561. AddKeyValue("卷包直径", mattress.diameter);
  562. AddKeyValue("顶布裥棉外布套做法", mattress.if_db_wbutao_way);
  563. AddKeyValue("面料外布套做法", mattress.if_m_wbutao_way);
  564. AddKeyValue("内布套上覆", mattress.s_cover_qty);
  565. AddKeyValue("内布套侧覆", mattress.z_cover_qty);
  566. AddKeyValue("内布套下覆", mattress.x_cover_qty);
  567. AddKeyValue("面料上覆", mattress.s_m_cover_qty);
  568. AddKeyValue("面料侧覆", mattress.z_m_cover_qty);
  569. AddKeyValue("面料下覆", mattress.x_m_cover_qty);
  570. AddKeyValue("面拆", mattress.if_m_chai);
  571. AddKeyValue("中拆", mattress.if_z_chai);
  572. AddKeyValue("底拆", mattress.if_d_chai);
  573. AddKeyValue("工厂利润率", mattress.profitrate);
  574. AddKeyValue("部门利润率", mattress.dept_profitrate);
  575. AddKeyValue("部门让利点数", mattress.dept_profitrate_rangli);
  576. AddKeyValue("佣金点数", mattress.commission);
  577. AddKeyValue("额外点数", mattress.other_rate);
  578. AddKeyValue("额外费用", mattress.extras_cost);
  579. AddKeyValue("汇率", mattress.moneyrate);
  580. AddKeyValue("税率", mattress.taxrate);
  581. AddKeyValue("折扣率", mattress.discount);
  582. AddKeyValue("边带数", mattress.biandai_qty);
  583. // 地区FOB费用,如果存在变量表,会替代
  584. AddKeyValue("大柜-普通地区-地区FOB费用", 6500);
  585. AddKeyValue("大柜-特定地区-地区FOB费用", 8500);
  586. AddKeyValue("小柜-普通地区-地区FOB费用", 6000);
  587. AddKeyValue("小柜-特定地区-地区FOB费用", 7000);
  588. // 柜型立方数
  589. AddKeyValue("大柜-柜型立方数", 64);
  590. AddKeyValue("小柜-柜型立方数", 28);
  591. // 柜型米数
  592. AddKeyValue("大柜-柜型米数", 12);
  593. AddKeyValue("小柜-柜型米数", 5.9);
  594. AddKeyValue("柜型", mattress.cabinet_type);
  595. //AddFormulaHideKeyValue("【总材料成本】", "【弹簧材料总成本】+【蛇线材料成本】+【四周口袋弹簧成本】+【四周口袋无纺布成本】+【四周加硬材料成本】+【胶水材料成本】+【入袋无纺布材料成本】+【底面无纺布材料成本】+【边铁材料成本】+【C钉/夹码材料成本】+【海绵包边材料成本】+【填充海绵成本】+【封边材料成本】+【弹叉材料成本】+【胶条/包角材料成本】+【上垫层物料成本】+【下垫层物料成本】+【包装总成本】");
  596. if (mattress.woodpallettype == 0)
  597. {
  598. AddKeyValue("木托方式", "'普通木托'");
  599. }else if (mattress.woodpallettype == 1)
  600. {
  601. AddKeyValue("木托方式", " '夹板木托'");
  602. }else if (mattress.woodpallettype == 2)
  603. {
  604. AddKeyValue("木托方式", "'铁管木托' ");
  605. }
  606. // 公式
  607. AddFormulaKeyValue("车间成本", "【材料成本】*【大小单】+【人工费用】+【边带费用】+【额外费用】+【制造费用】");
  608. AddFormulaKeyValue("不含税出厂价", "【车间成本】*(【工厂利润率】+【工艺点数】+【内布套点数】+【拆装点数】+【海绵扣点】)*【管理费点】");
  609. AddFormulaKeyValue("部门不含税价", "【不含税出厂价】/(【部门利润率】+【部门让利点数】/100)/(1-(【佣金点数】-1))*【额外点数】+【FOB】");
  610. AddFormulaKeyValue("税金", "【部门不含税价】*(【税率】-1)+【佣金】 * 0.05");
  611. AddFormulaKeyValue("部门含税价", "(【部门不含税价】+【佣金】 * 0.06)*【税率】*【折扣率】");
  612. AddFormulaKeyValue("外币价", "【部门含税价】/【汇率】");
  613. AddFormulaKeyValue("底价", "if((【部门利润率】+【部门让利点数】/100)<> 0,【不含税出厂价】/(【部门利润率】+【部门让利点数】/ 100),0)");
  614. AddFormulaKeyValue("佣金", "【底价】/(1-(【佣金点数】-1))-【底价】");
  615. var dept = Cache.GetData<u_dept, DeptMapping>(mattress.deptid.Value);
  616. AddKeyValue("税金补偿", dept.taxes_rate);
  617. var bednetVarList = new List<u_bednet_var>();
  618. var selectStr = @"SELECT u_bednet_varmx.varid AS varid
  619. ,varkind
  620. ,varcode
  621. ,varname
  622. ,varclass
  623. ,vartype
  624. ,varunit
  625. ,u_bednet_varmx.varvalue AS varvalue
  626. ,formula
  627. FROM u_bednet_var
  628. INNER JOIN u_bednet_varmx ON u_bednet_varmx.varid = u_bednet_var.varid
  629. INNER JOIN u_dept ON u_dept.pricelistid = u_bednet_varmx.pricelistid";
  630. var whereList = new List<string>();
  631. whereList.Add("u_bednet_var.varclass < 2");
  632. whereList.Add("u_bednet_var.varkind = @varkind");
  633. whereList.Add("u_dept.deptid = @deptid");
  634. var param = new Dictionary<string, object>();
  635. param.Add("@varkind", 1);
  636. param.Add("@deptid", mattress.deptid);
  637. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "varid", "varid,varkind,varcode,varname,varclass,vartype,varunit,varvalue", 0, 0, bednetVarList);
  638. foreach (var netvar in bednetVarList)
  639. {
  640. AddKeyValue(netvar.varname, netvar.varvalue);
  641. }
  642. if (isNewFormula)
  643. {
  644. selectStr = @"SELECT varid
  645. ,varkind
  646. ,varcode
  647. ,varname
  648. ,varclass
  649. ,vartype
  650. ,varunit
  651. ,formula
  652. FROM u_bednet_var";
  653. bednetVarList = new List<u_bednet_var>();
  654. whereList = new List<string>();
  655. whereList.Add("u_bednet_var.varkind = @varkind");
  656. whereList.Add("u_bednet_var.varclass = @varclass");
  657. param = new Dictionary<string, object>();
  658. param.Add("@varkind", 1);
  659. param.Add("@varclass", 2);
  660. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "varid", "varid,varkind,varcode,varname,varclass,vartype,varunit,formula", 0, 0, bednetVarList);
  661. string[] keys = { "车间成本", "不含税出厂价", "部门不含税价", "税金", "部门含税价", "外币价", "底价", "佣金", "总床垫车间成本" };
  662. // 添加替换公式变量
  663. foreach (var netvar in bednetVarList)
  664. {
  665. if (keys.Contains(netvar.varname))
  666. {
  667. AddFormulaKeyValue(netvar.varname, netvar.formula);
  668. }
  669. else
  670. {
  671. AddFormulaHideKeyValue(netvar.varname, netvar.formula);
  672. }
  673. }
  674. }
  675. if (isNewFormula) GetDannumRate(mattress);
  676. }
  677. private void InitMxReplaceMents(u_mattress_mx_mtrl mx)
  678. {
  679. mx.mtrlname = !string.IsNullOrEmpty(mx.mtrlname) ? mx.mtrlname.Trim() : "null";
  680. decimal _shrinkage = mx.shrinkage.Value == 0 ? (decimal)1 : mx.shrinkage.Value;
  681. //取mtrldef.name的前两位
  682. AddKeyValue("名称前2位", mx.mtrlname.Length > 2 ? mx.mtrlname.Substring(0, 2) : mx.mtrlname);
  683. AddKeyValue("物料单价", mx.price);
  684. AddKeyValue("物料克重", mx.gram_weight);
  685. AddKeyValue("幅宽", mx.cloth_width);
  686. AddKeyValue("数量", mx.qty);
  687. AddKeyValue("物料厚度", mx.if_inputqty);
  688. AddKeyValue("固定厚度", mx.if_inputqty);
  689. AddKeyValue("厚度", mx.thickness);
  690. AddKeyValue("按面积单价", mx.if_areaprice);
  691. AddKeyValue("物料名称", mx.mtrlname);
  692. if (_shrinkage > 0) AddKeyValue("物料收缩率", _shrinkage);
  693. }
  694. /// <summary>
  695. /// 添加大侧,小侧,V侧高度公式替换
  696. /// </summary>
  697. /// <param name="mx"></param>
  698. /// <param name="diancengList"></param>
  699. /// <param name="mattersstype"></param>
  700. /// <param name="expression"></param>
  701. /// <returns></returns>
  702. private string InitMxSideReplaceMents(u_mattress mattress, u_mattress_mx_mtrl mx,List<u_mattress_mx_mtrl> diancengList, u_mattress_type mattersstype, string expression)
  703. {
  704. // 获取垫层的数据
  705. decimal bigSum = 0, smallSum = 0, vSum = 0;
  706. string bigChaStr = "大侧";
  707. string smallChaStr = mx.chastr ?? "小侧1";
  708. string vChaStr = mx.chastr ?? "V侧1";
  709. foreach (var dianceng in diancengList)
  710. {
  711. if (dianceng.chastr.IndexOf(bigChaStr) > -1) bigSum += dianceng.qty.Value * dianceng.thickness.Value;
  712. if (dianceng.chastr.IndexOf(smallChaStr) > -1) smallSum += dianceng.qty.Value * dianceng.thickness.Value;
  713. if (dianceng.chastr.IndexOf(vChaStr) > -1) vSum += dianceng.qty.Value * dianceng.thickness.Value;
  714. }
  715. if (bigSum > 0)
  716. {
  717. AddKeyValue("垫层", bigSum);
  718. }
  719. if (smallSum > 0)
  720. {
  721. AddKeyValue("垫层", smallSum);
  722. }
  723. if (vSum > 0)
  724. {
  725. AddKeyValue("垫层", vSum);
  726. }
  727. #region 替换大侧高度
  728. if (expression.IndexOf("【大侧高度】") > -1)
  729. {
  730. if (!string.IsNullOrEmpty(mattersstype.formula_big_side)) expression = expression.Replace("【大侧高度】", $"({mattersstype.formula_big_side})");
  731. expression = expression.Replace("【位置】", $"'{bigChaStr}'");
  732. if (bigSum > 0) expression = expression.Replace("【大侧高度】", $"{bigSum}");
  733. }
  734. #endregion
  735. #region 替换小侧高度
  736. if (expression.IndexOf("【小侧高度】") > -1)
  737. {
  738. if (!string.IsNullOrEmpty(mattersstype.formula_small_side)) expression = expression.Replace("【小侧高度】", $"({mattersstype.formula_small_side})");
  739. expression = expression.Replace("【位置】", $"'{smallChaStr}'");
  740. expression = expression.Replace("【小侧高度】", $"{smallSum}");
  741. }
  742. #endregion
  743. #region 替换V侧高度
  744. if (expression.IndexOf("【V侧高度】") > -1)
  745. {
  746. if(!string.IsNullOrEmpty(mattersstype.formula_v_side)) expression = expression.Replace("【V侧高度】", $"({mattersstype.formula_v_side})");
  747. expression = expression.Replace("【位置】", $"'{vChaStr}'");
  748. expression = expression.Replace("【V侧高度】", $"18");
  749. }
  750. #endregion
  751. #region 若填写则顶替床垫尺寸
  752. if (mx.mattress_width != null && mx.mattress_width > 0) expression = expression.Replace("【规格宽】", $"{mx.mattress_width}");
  753. if (mx.mattress_length != null && mx.mattress_length > 0) expression = expression.Replace("【规格长】", $"{mx.mattress_length}");
  754. #endregion
  755. return expression;
  756. }
  757. /// <summary>
  758. /// 添加布料幅宽公式替换
  759. /// </summary>
  760. /// <param name="mx"></param>
  761. /// <param name="mxlist"></param>
  762. /// <param name="formulakind"></param>
  763. private void InitMxClothWidthReplaceMents(u_mattress_mx_mtrl mx, List<u_mattress_mx_mtrl> mxlist,int formulakind)
  764. {
  765. decimal cloth_width = 0;
  766. if (string.IsNullOrEmpty(mx.chastr))
  767. {
  768. cloth_width = mxlist.First(t => t.formulakind.Value == formulakind).cloth_width.Value;
  769. }
  770. else
  771. {
  772. cloth_width = mxlist.First(t => t.formulakind.Value == formulakind && t.chastr.Equals(mx.chastr)).cloth_width.Value;
  773. }
  774. AddKeyValue("布料幅宽", cloth_width);
  775. }
  776. /// <summary>
  777. /// 添加布套高公式替换
  778. /// </summary>
  779. /// <param name="mxlist"></param>
  780. /// <param name="formulakind"></param>
  781. private string InitMxClothHeightReplaceMents(u_mattress mattress, u_mattress_mx_mtrl mx, string expression, List<u_mattress_mx_mtrl> mxlist, int formulakind)
  782. {
  783. decimal cloth_height = 0;
  784. cloth_height = mxlist.First(t => t.formulakind.Value == formulakind).thickness.Value;
  785. AddKeyValue("布套高", cloth_height);
  786. //if (mx.mattress_width != null && mx.mattress_width > 0) expression = expression.Replace("【规格宽】", $"{mx.mattress_width}");
  787. //if (mx.mattress_length != null && mx.mattress_length > 0) expression = expression.Replace("【规格长】", $"{mx.mattress_length}");
  788. return expression;
  789. }
  790. /// <summary>
  791. /// 添加裥绵收缩率公式替换
  792. /// </summary>
  793. /// <param name="mx"></param>
  794. /// <param name="mxlist"></param>
  795. private void InitMxShrinkageReplaceMents(u_mattress_mx_mtrl mx, List<u_mattress_mx_mtrl> mxlist)
  796. {
  797. decimal thickness = 0, shrinkage = 0;
  798. int[][] formulaKinds = new int[][]
  799. {
  800. new int [] {50, 0, 40, 60, 70, 80},
  801. new int [] {51, 1, 41, 61, 71, 81},
  802. new int [] {52, 2, 42, 62, 72, 82},
  803. new int [] {53, 3, 43, 63, 73, 83},
  804. new int [] {54, 4, 44, 64, 74, 84},
  805. };
  806. foreach (int[] kindGroup in formulaKinds)
  807. {
  808. if (kindGroup.Contains(mx.formulakind.Value))
  809. {
  810. var _mxList = mxlist.Where(o => o.formulatype == mx.formulatype).ToList(); //在同一个tab中计算
  811. foreach (var row in _mxList) // mxList.Rows等价于arg_dw.RowCount()
  812. {
  813. if (row.formulakind.Value == kindGroup[0])
  814. {
  815. thickness += row.thickness.Value * row.qty.Value; // 简化计算
  816. }
  817. }
  818. }
  819. }
  820. if(thickness >= 0)
  821. {
  822. cmd.CommandText = @"SELECT TOP 1 shrinkage
  823. FROM u_shrinkage
  824. WHERE u_shrinkage.minvalue <= @thickness
  825. AND u_shrinkage.maxvalue >= @thickness";
  826. cmd.Parameters.Clear();
  827. cmd.Parameters.AddWithValue("@thickness", thickness);
  828. using(var reader = cmd.ExecuteReader())
  829. {
  830. if (reader.Read())
  831. {
  832. shrinkage = Convert.ToDecimal(reader["shrinkage"]);
  833. }
  834. }
  835. }
  836. if(shrinkage > 0)
  837. {
  838. AddKeyValue("收缩率", shrinkage);
  839. }
  840. }
  841. /// <summary>
  842. /// 添加主表与明细表相关公式替换
  843. /// </summary>
  844. /// <param name="mattress"></param>
  845. /// <param name="mxlist"></param>
  846. /// <param name="isNewFormula">是否获取新的公式计算</param>
  847. private void InitMattressMxListReplaceMents(u_mattress mattress,List<u_mattress_mx_mtrl> mxlist, Boolean isNewFormula = true)
  848. {
  849. string fob_expression = string.Empty,cubage_expression = string.Empty;
  850. cubage_expression = "(【规格长】*【规格宽】* 【规格高】)/100000";
  851. #region 判断装柜方式 是否进箱
  852. if (mattress.packtype == 0)
  853. {
  854. mattress.loading_type = "平压";
  855. fob_expression = "【地区FOB费用】/(【柜型米数】 /(【规格宽】/ 100 +0.1)*(【压包数量】*2))";
  856. //if (mattress.packqty == 0) throw new LJCommonException("请填写压包数量!");
  857. }
  858. else if (mattress.packtype == 1)
  859. {
  860. mattress.loading_type = "卷包(非进箱)";
  861. fob_expression = "【地区FOB费用】 /(【柜型立方数】 /( 3.14*( 【卷包直径】 /100/2+0.03)*( 【卷包直径】 /100/2+0.03)*(【规格宽】/ 100 +0.05)))";
  862. cubage_expression = "( 3.14*( 【卷包直径】 /100/2+0.03)*( 【卷包直径】 /100/2+0.03)*(【规格宽】/ 100 +0.05))";
  863. //if (mattress.diameter == 0) throw new LJCommonException("请填写卷包直径!");
  864. var _bzList = mxlist.Where(t => t.formulatype == 3 && t.formulakind == 19).ToList();
  865. foreach(var bz in _bzList)
  866. {
  867. if (bz.mtrlname.IndexOf("箱") > -1) {
  868. mattress.loading_type = "卷包(进箱)";
  869. fob_expression = "【地区FOB费用】/(【柜型立方数】 / (( 【纸箱宽】 /100+0.03)*(【纸箱宽】/100+0.03)*(【规格宽】/ 100 +0.1)))";
  870. cubage_expression = "( 【纸箱宽】 /100+0.03)*(【纸箱宽】/100+0.03)*(【规格宽】/ 100 +0.1)";
  871. AddKeyValue("纸箱宽", bz.mtrlname.Length > 2 ? bz.mtrlname.Substring(0, 2) : bz.mtrlname);
  872. break;
  873. }
  874. }
  875. }
  876. else if (mattress.packtype == 2)
  877. {
  878. mattress.loading_type = "国内";
  879. fob_expression = "【地区FOB费用】/(【柜型立方数】/((【规格宽】/100+0.03)*(【规格长】/100+0.03)*(【规格高】/100+0.03)))";
  880. }
  881. #endregion
  882. #region 计算FOB
  883. if (!string.IsNullOrEmpty(mattress.area) && !string.IsNullOrEmpty(mattress.cabinet_type) && !string.IsNullOrEmpty(mattress.loading_type))
  884. {
  885. //地区FOB费用
  886. if (new List<string>() { "大柜", "小柜" }.Contains(mattress.cabinet_type) && new List<string>() { "普通地区", "特定地区" }.Contains(mattress.area))
  887. {
  888. fob_expression = fob_expression.Replace("【地区FOB费用】", $"【{mattress.cabinet_type.Trim()}-{mattress.area.Trim()}-地区FOB费用】");
  889. }
  890. //柜型立方数
  891. if (new List<string>() { "大柜", "小柜" }.Contains(mattress.cabinet_type))
  892. {
  893. fob_expression = fob_expression.Replace("【柜型立方数】", $"【{mattress.cabinet_type.Trim()}-柜型立方数】");
  894. }
  895. //纸箱宽 见上面
  896. //柜型米数
  897. if (new List<string>() { "大柜", "小柜" }.Contains(mattress.cabinet_type))
  898. {
  899. fob_expression = fob_expression.Replace("【柜型米数】", $"【{mattress.cabinet_type.Trim()}-柜型米数】");
  900. }
  901. mattress.fob_replace_formula = fob_expression;
  902. mattress.fob = Calculate(fob_expression, "FOB").DecimalValue;
  903. //半成品:如果PE袋物料是含 半成品专用 的编码,FOB需要除以数量
  904. var bzList2 = mxlist.Where(t => t.formulatype == 3).ToList();
  905. foreach (var bz in bzList2)
  906. {
  907. if (bz.qty.Value > 0 && bz.mtrlname.IndexOf("半成品专用") > -1)
  908. {
  909. mattress.fob /= bz.qty.Value;
  910. mattress.fob_replace_formula = $"{mattress.fob_replace_formula} / {bz.qty.Value}";
  911. }
  912. }
  913. }
  914. else {
  915. mattress.fob = 0;
  916. }
  917. AddKeyValue("FOB", mattress.fob);
  918. #endregion
  919. #region 计算体积
  920. if (mattress.fob > 0)
  921. {
  922. mattress.cubage = Calculate(cubage_expression, "体积").DecimalValue;
  923. }
  924. #endregion
  925. #region 计算人工费用
  926. var mattersstype = new u_mattress_type() { mattresstypeid = mattress.mattresstypeid };
  927. DbSqlHelper.SelectOne(cmd, mattersstype, "hrcost_formula,biandaiqty,zhizao_amt,guanli_rate,typerate,dannum1_rate,dannum2_rate,dannum3_rate,dannum4_rate");
  928. if(mattress.biandai_qty == 0 && mattress.if_m_chai == 0 && mattress.if_z_chai == 0 && mattress.if_d_chai == 0)
  929. {
  930. mattress.biandai_qty = mattersstype.biandaiqty;
  931. }
  932. mattress.hrcost_replace_formula = mattersstype.hrcost_formula;
  933. mattress.zhizao_amt = mattersstype.zhizao_amt;
  934. mattress.guanli_rate = mattersstype.guanli_rate;
  935. var diancengList = mxlist.Where(t => t.formulatype == 1).ToList();
  936. int diancengCount = 0;
  937. foreach(var dianceng in diancengList)
  938. {
  939. if (dianceng.formulakind == 32) diancengCount++;
  940. }
  941. AddKeyValue("垫层数量", diancengCount);
  942. AddKeyValue("制造费用", mattress.zhizao_amt);
  943. AddKeyValue("管理费点", mattress.guanli_rate);
  944. mattress.hrcost = Calculate(mattress.hrcost_replace_formula, "人工费用").DecimalValue;
  945. AddKeyValue("人工费用", mattress.hrcost);
  946. #endregion
  947. #region 计算边带费用
  948. if (!isNewFormula || !formula_replacements.ContainsKey("【边带费用】"))
  949. {
  950. mattress.biandaicost_replace_formula = "【边带条数】*【边带单价】*((【规格宽】+【规格长】)*2+30)/100";
  951. }
  952. else
  953. {
  954. mattress.biandaicost_replace_formula = formula_replacements["【边带费用】"];
  955. }
  956. AddKeyValue("边带条数", mattress.biandai_qty);
  957. mattress.biandaicost = Calculate(mattress.biandaicost_replace_formula, "边带费用").DecimalValue;
  958. AddKeyValue("边带费用", mattress.biandaicost);
  959. #endregion
  960. #region 辅料 有打钮纽扣 加0.13 工厂利润率
  961. var fuliaoList = mxlist.Where(t => t.formulatype == 2 && t.mtrlname.IndexOf("打钮") > -1).ToList();
  962. if (fuliaoList.Any()) mattress.profitrate += 0.13M;
  963. #endregion
  964. #region 拼侧 最大金额的侧 和 工厂利润率加点
  965. CalCulatePince(mattress, mxlist, isNewFormula);
  966. #endregion
  967. #region 内布套特殊加点
  968. CalCulateNetBuTao(mattress, mxlist);
  969. #endregion
  970. #region 拆装特殊加点
  971. CalCulateChaiZhuang(mattress);
  972. #endregion
  973. #region 海绵款特殊扣点
  974. CalCulateHaiMian(mattress);
  975. #endregion
  976. #region 计算主表 材料成本
  977. var aa = new List<decimal>();
  978. mxlist.ForEach(t => {
  979. var _costamt = t.costamt.Value;
  980. if (isNewFormula)
  981. {
  982. decimal _dannum_rate = 0;
  983. #region 计算损耗率
  984. switch (mattress.dannum_type.Value)
  985. {
  986. case 1:
  987. if (t.dannum1_rate != null) _dannum_rate = t.dannum1_rate.Value;
  988. break;
  989. case 2:
  990. if (t.dannum2_rate != null) _dannum_rate = t.dannum2_rate.Value;
  991. break;
  992. case 3:
  993. if (t.dannum3_rate != null) _dannum_rate = t.dannum3_rate.Value;
  994. break;
  995. case 4:
  996. if (t.dannum4_rate != null) _dannum_rate = t.dannum4_rate.Value;
  997. break;
  998. }
  999. _costamt = _costamt * (1 + _dannum_rate);
  1000. #endregion
  1001. // 新公式排除床网计算
  1002. if (t.formulatype != 99)
  1003. {
  1004. if (new List<int> { 101, 102 }.Contains(t.formulatype.Value))
  1005. {
  1006. /// 內布套 需要勾选了标记才纳入计算
  1007. if (mattress.if_n_butao != null && mattress.if_n_butao.Value > 0)
  1008. {
  1009. aa.Add(_costamt);
  1010. }
  1011. }
  1012. else if (new List<int> { 103 }.Contains(t.formulatype.Value))
  1013. {
  1014. /// 顶布裥棉 需要勾选了标记才纳入计算
  1015. if (mattress.if_w_butao != null && mattress.if_w_butao.Value > 0)
  1016. {
  1017. aa.Add(_costamt);
  1018. }
  1019. }
  1020. else
  1021. {
  1022. aa.Add(_costamt);
  1023. }
  1024. }
  1025. }
  1026. else
  1027. {
  1028. aa.Add(_costamt);
  1029. }
  1030. });
  1031. mattress.total_material_cost = aa.Sum();
  1032. AddKeyValue("材料成本", mattress.total_material_cost);
  1033. #endregion
  1034. //#region 标准金额
  1035. //if (!isNewFormula)
  1036. //{
  1037. // // 旧公式
  1038. // CalCulateCostNew(mattress, "标准");
  1039. // // 查找点数
  1040. // decimal _rate = GetWorkmanshipRate(mattress, "num_10", "标准");
  1041. // _rate = _rate == 0 ? 1 : _rate;
  1042. // mattress.foreign_cost_bz = mattress.dept_cost / _rate;
  1043. //}
  1044. //else
  1045. //{
  1046. // CalCulateCostNew(mattress, "标准", mattersstype);
  1047. // mattress.foreign_cost_bz = mattress.dept_cost;
  1048. //}
  1049. //AddKeyValue("标准金额", mattress.foreign_cost_bz);
  1050. //#endregion
  1051. //#region 大单金额
  1052. //if (!isNewFormula)
  1053. //{
  1054. // // 旧公式
  1055. // CalCulateCostNew(mattress, "大单");
  1056. // // 查找点数
  1057. // decimal _rate2 = GetWorkmanshipRate(mattress, "num_11", "大单");
  1058. // _rate2 = _rate2 == 0 ? 1 : _rate2;
  1059. // mattress.foreign_cost_dd = mattress.dept_cost / _rate2;
  1060. //}
  1061. //else
  1062. //{
  1063. // CalCulateCostNew(mattress, "大单", mattersstype);
  1064. // mattress.foreign_cost_dd = mattress.dept_cost;
  1065. //}
  1066. //AddKeyValue("大单金额", mattress.foreign_cost_dd);
  1067. //#endregion
  1068. if (!isNewFormula)
  1069. {
  1070. // 旧公式
  1071. CalCulateCostNew(mattress, "散单");
  1072. }
  1073. else
  1074. {
  1075. CalCulateCostNew(mattress, "散单", isNewFormula);
  1076. }
  1077. AddKeyValue("散单金额", mattress.foreign_cost);
  1078. }
  1079. /// <summary>
  1080. /// 计算拼侧最大金额的侧和工厂利润率加点
  1081. /// </summary>
  1082. /// <param name="mattress"></param>
  1083. /// <param name="mxlist"></param>
  1084. private void CalCulatePince(u_mattress mattress, List<u_mattress_mx_mtrl> mxlist, Boolean isNewFormula = true)
  1085. {
  1086. var mianliaoList = mxlist.Where(t => t.formulatype == 0).ToList();
  1087. var costAmounts = new Dictionary<string, decimal>
  1088. {
  1089. { "普通大侧", 0m },
  1090. { "上下拼侧1", 0m },
  1091. { "上下拼侧2", 0m },
  1092. { "上下拼侧3", 0m },
  1093. { "左右拼侧1", 0m },
  1094. { "左右拼侧2", 0m },
  1095. { "左右拼侧3", 0m },
  1096. { "左右拼侧4", 0m }
  1097. };
  1098. var costAmounts2 = new Dictionary<string, decimal>
  1099. {
  1100. { "小侧1-上下拼侧1", 0m },
  1101. { "小侧1-上下拼侧2", 0m },
  1102. { "小侧1-上下拼侧3", 0m }
  1103. };
  1104. foreach (var mianliao in mianliaoList)
  1105. {
  1106. if (costAmounts.ContainsKey(mianliao.sortcode))
  1107. {
  1108. costAmounts[mianliao.sortcode] += mianliao.costamt.Value;
  1109. }else if (costAmounts2.ContainsKey(mianliao.sortcode))
  1110. {
  1111. costAmounts2[mianliao.sortcode] += mianliao.costamt.Value;
  1112. }
  1113. }
  1114. // 找出最大拼侧金额及对应的拼侧名称
  1115. string lsTempMaxStr = null;
  1116. decimal ldeTempMax = decimal.MinValue;
  1117. foreach (var item in costAmounts)
  1118. {
  1119. if (item.Value >= ldeTempMax)
  1120. {
  1121. ldeTempMax = item.Value;
  1122. lsTempMaxStr = item.Key;
  1123. }
  1124. }
  1125. // 清空不是最大金额的拼侧
  1126. foreach (var mianliao in mianliaoList)
  1127. {
  1128. if (mianliao.sortcode != lsTempMaxStr && new List<int>() { 2, 82, 42, 52, 62, 72 }.Contains(mianliao.formulakind.Value))
  1129. {
  1130. mianliao.costamt = 0;
  1131. }
  1132. }
  1133. // 找出最大小侧拼侧金额及对应的拼侧名称
  1134. string lsTempMaxStr2 = null;
  1135. decimal ldeTempMax2 = decimal.MinValue;
  1136. foreach (var item in costAmounts)
  1137. {
  1138. if (item.Value >= ldeTempMax)
  1139. {
  1140. ldeTempMax = item.Value;
  1141. lsTempMaxStr = item.Key;
  1142. }
  1143. }
  1144. if (ldeTempMax2 > 0)
  1145. {
  1146. // 清空不是最大金额的拼侧
  1147. foreach (var mianliao in mianliaoList)
  1148. {
  1149. if (mianliao.sortcode != lsTempMaxStr2 && new List<int>() { 3, 83, 43, 53, 63, 73 }.Contains(mianliao.formulakind.Value))
  1150. {
  1151. mianliao.costamt = 0;
  1152. }
  1153. }
  1154. }
  1155. // 计算拼侧数量
  1156. int pinceCnt = costAmounts.Values.Count(value => value > 0);
  1157. AddKeyValue("拼侧数量", pinceCnt);
  1158. // 判断是否有大侧
  1159. bool hasBigSide = mianliaoList.Any(row => new[] { 7, 8, 9, 10 }.Contains(row.formulakind.Value) && row.mtrlid.Value > 0);
  1160. AddKeyValue("大侧数量", Convert.ToInt32(hasBigSide));
  1161. string field = pinceCnt > 3 || (hasBigSide && (pinceCnt == 2 || pinceCnt == 3)) ? "num_3" : hasBigSide ? "num_1" : pinceCnt == 2 || pinceCnt == 3 ? "num_2" : string.Empty;
  1162. // 查找点数
  1163. mattress.profitrate_point = GetWorkmanshipRate(mattress, field, "工艺点数", isNewFormula);
  1164. AddKeyValue("工艺点数", mattress.profitrate_point);
  1165. //decimal extraProcesses = GetExtraAmt(mattress, 1);
  1166. //AddKeyValue("特殊工艺费用", extraProcesses);
  1167. }
  1168. /// <summary>
  1169. /// 计算内布套特殊加点
  1170. /// </summary>
  1171. /// <param name="mattress"></param>
  1172. /// <param name="mxlist"></param>
  1173. private void CalCulateNetBuTao(u_mattress mattress, List<u_mattress_mx_mtrl> mxlist)
  1174. {
  1175. if(mattress.if_n_butao == 1)
  1176. {
  1177. var butaoList = mxlist.Where(t => t.formulatype == 101 || t.formulatype == 102);
  1178. bool butaoFz = false, butaoJd = false;
  1179. // 检查内布套是否为复杂款
  1180. foreach (var butao in butaoList) {
  1181. if (butao.formulakind == 70 && butao.mtrlid > 0) { butaoFz = true; break; }
  1182. }
  1183. if (butaoFz)
  1184. {
  1185. foreach (var butao in butaoList)
  1186. {
  1187. if (butao.formulakind == 203 && butao.mtrlid > 0) { butaoFz = true; break; }
  1188. }
  1189. }
  1190. else
  1191. {
  1192. butaoJd = true; // 没有找到复杂款即为简单款
  1193. }
  1194. // 根据款式类型判断查询的字段
  1195. string field = butaoJd ? "num_4" : (butaoFz ? "num_5" : "");
  1196. AddKeyValue("内布套简单款", Convert.ToInt32(butaoJd));
  1197. AddKeyValue("内布套复杂款", Convert.ToInt32(butaoFz));
  1198. // 查找点数
  1199. //var workmanship = new u_workmanship_add() { deptid = mattress.deptid, mattresstypeid = mattress.mattresstypeid, workmanshipname = field };
  1200. mattress.butao_point = GetWorkmanshipRate(mattress, field, "内布套点数");
  1201. }
  1202. AddKeyValue("内布套点数", mattress.butao_point);
  1203. }
  1204. /// <summary>
  1205. /// 拆装特殊加点
  1206. /// </summary>
  1207. /// <param name="mattress"></param>
  1208. private void CalCulateChaiZhuang(u_mattress mattress)
  1209. {
  1210. int cnt = 0;
  1211. // 判断 if_m_chai, if_z_chai, if_d_chai 是否为 1
  1212. if (Convert.ToInt32(mattress.if_m_chai) == 1) cnt++;
  1213. if (Convert.ToInt32(mattress.if_z_chai) == 1) cnt++;
  1214. if (Convert.ToInt32(mattress.if_d_chai) == 1) cnt++;
  1215. // 根据款式类型判断查询的字段
  1216. string field = cnt == 1 ? "num_6" : (cnt > 1 ? "num_7" : "");
  1217. AddKeyValue("拆装数量", cnt);
  1218. // 查找点数
  1219. mattress.chaizhuang_point = GetWorkmanshipRate(mattress, field, "拆装点数");
  1220. AddKeyValue("拆装点数", mattress.chaizhuang_point);
  1221. }
  1222. /// <summary>
  1223. /// 计算海绵款特殊扣点
  1224. /// </summary>
  1225. /// <param name="mattress"></param>
  1226. private void CalCulateHaiMian(u_mattress mattress)
  1227. {
  1228. if (mattress.if_haimian_type == 1)
  1229. {
  1230. // 根据款式类型判断查询的字段
  1231. string field = "num_8";
  1232. // 查找点数
  1233. mattress.haimian_point = GetWorkmanshipRate(mattress, field, "海绵扣点");
  1234. }
  1235. AddKeyValue("海绵扣点", mattress.haimian_point);
  1236. }
  1237. /// <summary>
  1238. /// 查询工艺加点设置
  1239. /// </summary>
  1240. /// <param name="label"></param>
  1241. /// <returns></returns>
  1242. public List<u_workmanship_add> GetWorkmanshipAdd(string label)
  1243. {
  1244. var list = new List<u_workmanship_add>();
  1245. var outputFields = @"deptid, mattresstypeid, formula, rate";
  1246. var selectStr = @"SELECT deptid, mattresstypeid, formula, rate FROM u_workmanship_add ";
  1247. var whereList = new List<string>();
  1248. whereList.Add("u_workmanship_add.inuse = 1");
  1249. whereList.Add("workmanshipname = @workmanshipname");
  1250. var param = new Dictionary<string, object>();
  1251. param.Add("@workmanshipname", label);
  1252. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "mattressid", outputFields, 0, 0, list);
  1253. return list;
  1254. }
  1255. /// <summary>
  1256. /// 获取工厂利润率
  1257. /// </summary>
  1258. /// <param name="mattress"></param>
  1259. /// <param name="field">旧表字段名</paramD>
  1260. /// <param name="label">新表变量名</paramD>
  1261. /// <returns></returns>
  1262. public decimal GetWorkmanshipRate(u_mattress mattress, string field, string label, Boolean isNewFormula = true)
  1263. {
  1264. decimal rate = 0;
  1265. if (field == "") return 0;
  1266. if (isNewFormula)
  1267. {
  1268. var addList = GetWorkmanshipAdd(label);
  1269. var tgList = addList.Where(o => o.deptid == mattress.deptid && o.mattresstypeid == mattress.mattresstypeid).ToList();
  1270. if (tgList.Count <= 0) tgList = addList.Where(o => o.deptid == mattress.deptid).ToList();
  1271. if (tgList.Count <= 0) tgList = addList.Where(o => o.mattresstypeid == mattress.mattresstypeid).ToList();
  1272. if (tgList.Count <= 0) tgList = addList;
  1273. if (tgList.Count > 0)
  1274. {
  1275. var item = tgList[0];
  1276. rate = item.rate == null ? 0 : Convert.ToDecimal(item.rate);
  1277. var _formula = Convert.ToString(item.formula);
  1278. if (!string.IsNullOrEmpty(_formula))
  1279. {
  1280. AddKeyValue(label, rate);
  1281. rate = Calculate(_formula, label).DecimalValue;
  1282. }
  1283. }
  1284. }
  1285. else
  1286. {
  1287. cmd.CommandText = @"SELECT " + field + " FROM u_workmanship_dianshu WHERE deptid = @deptid AND mattresstypeid = @mattresstypeid";
  1288. cmd.Parameters.Clear();
  1289. cmd.Parameters.AddWithValue("@deptid", mattress.deptid);
  1290. cmd.Parameters.AddWithValue("@mattresstypeid", mattress.mattresstypeid);
  1291. using (var reader = cmd.ExecuteReader())
  1292. {
  1293. if (reader.Read())
  1294. {
  1295. rate = reader[field] == null ? 0 : Convert.ToDecimal(reader[field]);
  1296. }
  1297. }
  1298. }
  1299. return rate;
  1300. }
  1301. /// <summary>
  1302. /// 计算大小单加点
  1303. /// </summary>
  1304. /// <param name="mattress"></param>
  1305. /// <param name="typename"></param>
  1306. private void CalCulateDanNum(u_mattress mattress,string typename)
  1307. {
  1308. var _typename = typename;
  1309. if (mattress.dannum_type.Value != 1)
  1310. {
  1311. switch(mattress.dannum_type.Value)
  1312. {
  1313. case 1:
  1314. _typename = "散单";
  1315. break;
  1316. case 2:
  1317. _typename = "标准";
  1318. break;
  1319. case 3:
  1320. _typename = "大单";
  1321. break;
  1322. case 4: // "小单":
  1323. _typename = "";
  1324. break;
  1325. }
  1326. }
  1327. // 根据款式类型判断查询的字段
  1328. string field = "散单".Equals(_typename) ? "num_9" : "标准".Equals(_typename) ? "num_10" : "大单".Equals(_typename) ? "num_11" : "";
  1329. // 查找点数
  1330. decimal _rate = GetWorkmanshipRate(mattress, field, typename);
  1331. mattress.dannum_rate = _rate == 0 ? 1 : _rate;
  1332. AddKeyValue("大小单", mattress.dannum_rate);
  1333. }
  1334. private decimal CalCulateDanNumRate(u_mattress mattress, string typename)
  1335. {
  1336. // 根据款式类型判断查询的字段
  1337. string field = "散单".Equals(typename) ? "num_9" : "标准".Equals(typename) ? "num_10" : "大单".Equals(typename) ? "num_11" : "";
  1338. // 查找点数
  1339. decimal _rate = GetWorkmanshipRate(mattress, field, typename);
  1340. return _rate;
  1341. }
  1342. /// <summary>
  1343. ///
  1344. /// </summary>
  1345. private void GetDannumRate(u_mattress mattress)
  1346. {
  1347. var mattressType = new u_mattress_type() { mattresstypeid = mattress.mattresstypeid };
  1348. DbSqlHelper.SelectOne(cmd, mattressType, "hrcost_formula,biandaiqty,zhizao_amt,guanli_rate,typerate,dannum1_rate,dannum2_rate,dannum3_rate,dannum4_rate");
  1349. var dept = Cache.GetData<u_dept, DeptMapping>(mattress.deptid.Value);
  1350. decimal? com_profitrate_dannum = 0;
  1351. decimal _rate = 1;
  1352. if (mattress.dannum_type == null)
  1353. {
  1354. mattress.dannum_type = 2;
  1355. }
  1356. switch (mattress.dannum_type.Value)
  1357. {
  1358. case 1: // "散单":
  1359. _rate = mattressType.dannum1_rate.Value;
  1360. com_profitrate_dannum = dept.dannum1_rate;
  1361. break;
  1362. case 3: // "大单":
  1363. _rate = mattressType.dannum3_rate.Value;
  1364. com_profitrate_dannum = dept.dannum3_rate;
  1365. break;
  1366. case 4: // "小单":
  1367. _rate = mattressType.dannum4_rate.Value;
  1368. com_profitrate_dannum = dept.dannum4_rate;
  1369. break;
  1370. default: // "标准":
  1371. _rate = mattressType.dannum2_rate.Value;
  1372. com_profitrate_dannum = dept.dannum2_rate;
  1373. break;
  1374. }
  1375. AddKeyValue("大小单类型", mattress.dannum_type.Value);
  1376. mattress.dannum_rate = _rate;
  1377. AddKeyValue("大小单系数", _rate);
  1378. AddKeyValue("款式系数", mattressType.typerate.Value);
  1379. #region 公式利润点
  1380. AddKeyValue("管理费用点", dept.managerate);
  1381. AddKeyValue("公司利润点(部门)", dept.com_profitrate);
  1382. AddKeyValue("公司利润点", dept.com_profitrate + com_profitrate_dannum);
  1383. #endregion
  1384. }
  1385. /// <summary>
  1386. /// 计算成本
  1387. /// </summary>
  1388. /// <param name="mattress"></param>
  1389. /// <param name="typename"></param>
  1390. private void CalCulateCostNew(u_mattress mattress, string typename, Boolean isNewFormula = false)
  1391. {
  1392. #region 判断大小单
  1393. if (isNewFormula)
  1394. {
  1395. GetDannumRate(mattress);
  1396. }
  1397. #endregion
  1398. #region 总成本-车间成本
  1399. CalCulateDanNum(mattress, typename);
  1400. if (mattress.if_zhedie_type == 1)
  1401. {
  1402. var _formula = formula_replacements["【车间成本】"];
  1403. AddFormulaKeyValue("车间成本", "( " + _formula + " ) * 2");
  1404. mattress.total_cost = CalculateVarFormula("车间成本").DecimalValue;
  1405. }
  1406. else
  1407. {
  1408. mattress.total_cost = CalculateVarFormula("车间成本").DecimalValue;
  1409. }
  1410. AddKeyValue("车间成本", mattress.total_cost);
  1411. #endregion
  1412. #region 不含税出厂价
  1413. mattress.nottax_factory_cost = CalculateVarFormula("不含税出厂价").DecimalValue;
  1414. AddKeyValue("不含税出厂价", mattress.nottax_factory_cost);
  1415. #endregion
  1416. #region 部门不含税价
  1417. mattress.nottax_dept_cost = CalculateVarFormula("部门不含税价").DecimalValue;
  1418. AddKeyValue("部门不含税价", mattress.nottax_dept_cost);
  1419. #endregion
  1420. #region 底价
  1421. decimal _dijia = CalculateVarFormula("底价").DecimalValue;
  1422. AddKeyValue("底价", _dijia);
  1423. #endregion
  1424. #region 佣金
  1425. decimal _yongjin = CalculateVarFormula("佣金").DecimalValue;
  1426. AddKeyValue("佣金", _yongjin);
  1427. #endregion
  1428. #region 税金
  1429. mattress.taxes = CalculateVarFormula("税金").DecimalValue;
  1430. AddKeyValue("税金", mattress.taxes);
  1431. #endregion
  1432. #region 部门含税价=(部门不含税价+佣金*0.06)*税率*折扣率(fob>0)
  1433. if (mattress.fob == 0) {
  1434. mattress.discount = 1;
  1435. AddKeyValue("折扣率", mattress.discount);
  1436. }
  1437. mattress.dept_cost = CalculateVarFormula("部门含税价").DecimalValue;
  1438. AddKeyValue("部门含税价", mattress.dept_cost);
  1439. #endregion
  1440. #region 外币价= 部门含税价/汇率
  1441. //if (mattress.moneyrate > 0)
  1442. //{
  1443. // if ("标准".Equals(typename)) mattress.foreign_cost_bz = mattress.dept_cost / mattress.moneyrate;
  1444. // else if ("大单".Equals(typename)) mattress.foreign_cost_dd = mattress.dept_cost / mattress.moneyrate;
  1445. // else if ("散单".Equals(typename)) mattress.foreign_cost = mattress.dept_cost / mattress.moneyrate;
  1446. //}
  1447. decimal _waibi = 0;
  1448. if (mattress.moneyrate > 0)
  1449. {
  1450. _waibi = CalculateVarFormula("外币价").DecimalValue;
  1451. } else
  1452. {
  1453. _waibi = mattress.dept_cost.Value;
  1454. }
  1455. mattress.foreign_cost = _waibi;
  1456. AddKeyValue("外币价", _waibi);
  1457. #endregion
  1458. }
  1459. public u_mattress GetMattress(int mattressid,string fields = null)
  1460. {
  1461. if(mattressid <= 0)
  1462. {
  1463. throw new LJCommonException("查找床垫报价失败,ID错误!");
  1464. }
  1465. var mattress = new u_mattress() { mattressid = mattressid };
  1466. fields = fields ?? @"mattressid,mattressname,deptid,mattresstypeid,mattresscode,mattress_width,mattress_length,mattress_height,packtype,packqty,woodpallettype,old_mtrlname,
  1467. total_hr_cost,total_material_cost,fees_dscrp,total_fees_cost,taxrate,commissionrate,commission,fob,profitrate,profitrate_point,butao_point,chaizhuang_point,
  1468. haimian_point,dannum_rate,hrcost,biandaicost,zhizao_amt,guanli_rate,discount,extras_cost,dept_profitrate,dept_profitrate_rangli,moneyrate,mattressrelcode,
  1469. flag,auditingrep,auditingdate,createtime,createby,total_cost,nottax_factory_cost,nottax_dept_cost,taxes,dept_cost,foreign_cost,foreign_cost_bz,
  1470. nottax_factory_cost/(dept_profitratedept_profitrate_rangli/100) as dijia_cost,xd_flag,xd_auditingrep,xd_auditingdate,qr_flag,qr_auditingrep,
  1471. qr_auditingdate,js1_flag,erp_mtrlcode,erp_cb_updatetime,if_bcp_type,if_zhedie_type,if_w_butao,biandai_qty,other_rate,if_moneyrate,parentid,
  1472. if_m_chai,if_z_chai,if_d_chai,if_n_butao,if_m_wbutao_way,s_cover_qty,z_cover_qty,x_cover_qty,s_m_cover_qty,z_m_cover_qty,x_m_cover_qty,cabinet_type,area,diameter,cubage,erp_mtrlcode,erp_mtrlid,dannum_type";
  1473. DbSqlHelper.SelectOne(cmd, mattress, fields);
  1474. return mattress;
  1475. }
  1476. public List<u_mattress> GetMattressList (int mattressid, string fields)
  1477. {
  1478. if (mattressid <= 0)
  1479. {
  1480. throw new LJCommonException("查找床垫报价失败,ID错误!");
  1481. }
  1482. var mattressList = new List<u_mattress>();
  1483. fields = fields ?? @"mattressid,mattressname,deptid,mattresstypeid,mattresscode,mattress_width,mattress_length,mattress_height,packtype,packqty,woodpallettype,old_mtrlname,
  1484. total_hr_cost,total_material_cost,fees_dscrp,total_fees_cost,taxrate,commissionrate,commission,fob,profitrate,profitrate_point,butao_point,chaizhuang_point,
  1485. haimian_point,dannum_rate,hrcost,biandaicost,zhizao_amt,guanli_rate,discount,extras_cost,dept_profitrate,dept_profitrate_rangli,moneyrate,mattressrelcode,
  1486. flag,auditingrep,auditingdate,createtime,createby,total_cost,nottax_factory_cost,nottax_dept_cost,taxes,dept_cost,foreign_cost,foreign_cost_bz,
  1487. nottax_factory_cost/(dept_profitratedept_profitrate_rangli/100) as dijia_cost,xd_flag,xd_auditingrep,xd_auditingdate,qr_flag,qr_auditingrep,
  1488. qr_auditingdate,js1_flag,erp_mtrlcode,erp_cb_updatetime,if_bcp_type,if_zhedie_type,if_w_butao,biandai_qty,other_rate,if_moneyrate,parentid,
  1489. if_m_chai,if_z_chai,if_d_chai,if_n_butao,if_m_wbutao_way,s_cover_qty,z_cover_qty,x_cover_qty,s_m_cover_qty,z_m_cover_qty,x_m_cover_qty,cabinet_type,area,diameter,cubage,erp_mtrlcode,erp_mtrlid,dannum_type";
  1490. DbSqlHelper.Select(cmd, "u_mattress", "mattressid = @mattressid", new Dictionary<string, object>() { { "@mattressid", mattressid } }, "createtime", 0, 0, mattressList, null, fields);
  1491. return mattressList;
  1492. }
  1493. public List<u_mattress_mx_mtrl> GetMattressMxMtrl(int mattressid,List<string> extraWhere = null)
  1494. {
  1495. var mxList = new List<u_mattress_mx_mtrl>();
  1496. var outputFields = @"mattressmxid, mattressid, formulakind, formula, formulaid, mtrlid, mtrlname, price, gram_weight, cloth_width, if_inputqty, qty , costamt, if_areaprice, formulatype, sortcode, if_mtrl, if_success, replace_formula, priceunit, shrinkage, name, dannum1_rate, dannum2_rate, dannum3_rate, dannum4_rate, thickness, chastr, xu, useqty, useformula, replace_useformula , gydscrp, mattress_width, mattress_length, spring_qty_width, spring_qty_length,sidecover";
  1497. var selectStr = @"
  1498. SELECT
  1499. u_mattress_mx_mtrl.mattressmxid,
  1500. u_mattress_mx_mtrl.mattressid,
  1501. u_mattress_formula.formulakind as formulakind ,
  1502. u_mattress_mx_mtrl.formula as formula,
  1503. u_mattress_mx_mtrl.formulaid,
  1504. u_mattress_mx_mtrl.mtrlid,
  1505. CASE WHEN u_mattress_formula.formulatype = 99 THEN vv_bednet.bednetname ELSE vv_mtrl_price.mtrlname END AS mtrlname,
  1506. u_mattress_mx_mtrl.price,
  1507. u_mattress_mx_mtrl.gram_weight,
  1508. u_mattress_mx_mtrl.cloth_width,
  1509. u_mattress_mx_mtrl.if_inputqty,
  1510. u_mattress_mx_mtrl.qty ,
  1511. u_mattress_mx_mtrl.costamt,
  1512. u_mattress_mx_mtrl.if_areaprice,
  1513. u_mattress_formula.formulatype,
  1514. case when u_mattress_mx_mtrl.chastr <> '' then u_mattress_mx_mtrl.chastr else u_mattress_formula.sortcode end as sortcode,
  1515. u_mattress_formula.if_mtrl,
  1516. u_mattress_mx_mtrl.if_success,
  1517. u_mattress_mx_mtrl.replace_formula,
  1518. u_mattress_mx_mtrl.priceunit,
  1519. u_mattress_mx_mtrl.shrinkage,
  1520. CASE when u_mattress_formula.if_mtrl > 1 THEN '+' ELSE '' END as addmx,
  1521. CASE when u_mattress_formula.if_mtrl > 1 THEN '-' ELSE '' END as delmx,
  1522. u_mtrl_price.name,
  1523. ISNULL(u_mtrltype.dannum1_rate, 0) AS dannum1_rate,
  1524. ISNULL(u_mtrltype.dannum2_rate, 0) AS dannum2_rate,
  1525. ISNULL(u_mtrltype.dannum3_rate, 0) AS dannum3_rate,
  1526. ISNULL(u_mtrltype.dannum4_rate, 0) AS dannum4_rate,
  1527. u_mattress_mx_mtrl.thickness,
  1528. u_mattress_mx_mtrl.chastr,
  1529. u_mattress_mx_mtrl.xu,
  1530. u_mattress_mx_mtrl.useqty as useqty,
  1531. u_mattress_mx_mtrl.useformula,
  1532. u_mattress_mx_mtrl.replace_useformula ,
  1533. u_mattress_mx_mtrl.gydscrp,
  1534. u_mattress_mx_mtrl.mattress_width,
  1535. u_mattress_mx_mtrl.mattress_length,
  1536. u_mattress_mx_mtrl.sidecover,
  1537. CASE WHEN u_mattress_formula.formulatype = 99 THEN vv_bednetmx.spring_qty_width ELSE 0 END AS spring_qty_width,
  1538. CASE WHEN u_mattress_formula.formulatype = 99 THEN vv_bednetmx.spring_qty_length ELSE 0 END AS spring_qty_length
  1539. From u_mattress_mx_mtrl
  1540. Left join u_mattress_formula On u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  1541. left outer join u_mtrl_price on u_mattress_mx_mtrl.mtrlid = u_mtrl_price.mtrlid
  1542. left outer join u_mtrltype on u_mtrltype.mtrltypeid = u_mtrl_price.mtrltype
  1543. Left OUTER JOIN (
  1544. select
  1545. mtrlid,
  1546. name as mtrlname
  1547. from u_mtrl_price
  1548. union all
  1549. select top 1
  1550. 0 as mtrlid,
  1551. ' ' as mtrlname
  1552. from u_user_jlhprice
  1553. ) AS vv_mtrl_price on vv_mtrl_price.mtrlid = u_mattress_mx_mtrl.mtrlid
  1554. Left OUTER JOIN (
  1555. SELECT u_bednet.bednetid,
  1556. rtrim(u_bednet_type.typename)+ ' ' + rtrim(u_bednet.bednetcode)+ ' '+cast(u_bednet.mattress_width as char(3))+ '*'
  1557. +cast(u_bednet.mattress_length as char(3))+ '*'+cast(u_bednet.mattress_height as char(3)) as bednetname
  1558. FROM u_bednet
  1559. inner join u_bednet_type ON u_bednet_type.bednettypeid = u_bednet.bednettypeid
  1560. ) as vv_bednet ON vv_bednet.bednetid = u_mattress_mx_mtrl.mtrlid
  1561. Left OUTER JOIN (
  1562. SELECT u_bednetmx.bednetid,
  1563. u_bednetmx.spring_qty_width,
  1564. u_bednetmx.spring_qty_length
  1565. FROM u_bednetmx
  1566. ) AS vv_bednetmx ON vv_bednetmx.bednetid = u_mattress_mx_mtrl.mtrlid ";
  1567. var whereList = new List<string>();
  1568. if(mattressid > 0) whereList.Add("u_mattress_mx_mtrl.mattressid = @mattressid");
  1569. if(extraWhere != null && extraWhere.Any())
  1570. {
  1571. whereList = whereList.Concat(extraWhere).ToList();
  1572. }
  1573. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), new Dictionary<string, object>() { { "@mattressid", mattressid } }, "mattressmxid", outputFields, 0, 0, mxList);
  1574. return mxList;
  1575. }
  1576. /// <summary>
  1577. /// 其他额外费用tab / 特殊工艺列表
  1578. /// </summary>
  1579. /// <param name="mattress"></param>
  1580. /// <param name="typeid"></param> 1: 特殊工艺。2:其他额外费用
  1581. /// <returns></returns>
  1582. public List<u_mattress_mx_extra> GetMattressMxExtra(int mattressid, int typeid)
  1583. {
  1584. var mxList = new List<u_mattress_mx_extra>();
  1585. var outputFields = @"mattressmxid,mattressid,extraid,extramxid,extratypename,extraname,price,dscrp,qty";
  1586. var selectStr = @"
  1587. SELECT
  1588. u_mattress_mx_extra.mattressid,
  1589. u_mattress_mx_extra.mattressmxid,
  1590. u_mattress_mx_extra.extraid,
  1591. u_mattress_mx_extra.extramxid,
  1592. u_mattress_mx_extra.extraname,
  1593. u_mattress_mx_extra.price,
  1594. u_mattress_mx_extra.qty,
  1595. u_mattress_mx_extra.dscrp
  1596. From u_mattress_mx_extra
  1597. Left OUTER JOIN u_mattress_extra_type On u_mattress_extra_type.extraid = u_mattress_mx_extra.extraid
  1598. Left OUTER JOIN u_mattress_extra On u_mattress_extra.extramxid = u_mattress_mx_extra.extramxid
  1599. ";
  1600. var whereList = new List<string>();
  1601. whereList.Add("u_mattress_mx_extra.mattressid = @mattressid");
  1602. whereList.Add("u_mattress_extra_type.typeid = @typeid");
  1603. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), new Dictionary<string, object>() { { "@mattressid", mattressid }, { "@typeid", typeid } }, "mattressmxid", outputFields, 0, 0, mxList);
  1604. return mxList;
  1605. }
  1606. /// <summary>
  1607. /// 获取副规格列表
  1608. /// </summary>
  1609. /// <param name="mattressid"></param>
  1610. /// <returns></returns>
  1611. public List<u_mattress> GetMattressSubspecs(int mattressid,string fields = null)
  1612. {
  1613. var list = new List<u_mattress>();
  1614. fields = fields ?? "mattressid,mattresscode,mattress_width,mattress_length,mattress_height,mattressname,mattressrelcode,parentid,erp_mtrlid,erp_mtrlcode,erp_configcodetype, erp_mtrlengname, erp_mtrlmode, erp_mtrlname, erp_mtrltype, erp_mtrltypeid, erp_mtrlunit, erp_piccode,xd_flag, flag, js1_flag";
  1615. var whereList = new List<string>();
  1616. whereList.Add(@"u_mattress.parentid = @mattressid OR parentid = (
  1617. SELECT parentid FROM u_mattress WHERE mattressid = @mattressid and parentid > 0
  1618. )");
  1619. DbSqlHelper.Select(cmd, "u_mattress", ListEx.GetWhereStr(whereList), new Dictionary<string, object>() { { "@mattressid", mattressid } }, "mattressid", 0, 0, list, null, fields);
  1620. return list;
  1621. }
  1622. /// <summary>
  1623. /// 获取副规格的床网弹簧排列数
  1624. /// </summary>
  1625. /// <param name="mattressid"></param>
  1626. /// <returns></returns>
  1627. public List<u_mattress_mx_mtrl> GetMattressSubspecsBednet(int mattressid)
  1628. {
  1629. var list = new List<u_mattress_mx_mtrl>();
  1630. var outputFields = @"mattressid,mtrlid,spring_qty_width,spring_qty_length,bednet_iffork,bednet_fork_qty";
  1631. var selectStr = @"SELECT
  1632. u_mattress_mx_mtrl.mattressid,
  1633. u_mattress_mx_mtrl.mattressmxid,
  1634. u_mattress_mx_mtrl.mtrlid,
  1635. ISNULL(u_bednetmx.spring_qty_width, 0) AS spring_qty_width,
  1636. ISNULL(u_bednetmx.spring_qty_length, 0) AS spring_qty_length,
  1637. ISNULL(u_bednet.iffork, 0) AS bednet_iffork,
  1638. ISNULL(u_bednet.fork_qty, 0) AS bednet_fork_qty
  1639. FROM u_mattress_mx_mtrl
  1640. LEFT JOIN u_mattress_formula On u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  1641. LEFT OUTER JOIN u_bednetmx on u_bednetmx.bednetid = u_mattress_mx_mtrl.mtrlid
  1642. LEFT OUTER JOIN u_bednet on u_bednetmx.bednetid = u_bednet.bednetid
  1643. ";
  1644. var whereList = new List<string>();
  1645. whereList.Add("u_mattress_formula.formulatype = 99");
  1646. whereList.Add("u_mattress_mx_mtrl.mattressid = @mattressid");
  1647. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), new Dictionary<string, object>() { { "@mattressid", mattressid } }, "mattressmxid", outputFields, 0, 0, list);
  1648. return list;
  1649. }
  1650. /// <summary>
  1651. /// 获取床垫明细中,垫层出现的主副规格调整物料
  1652. /// </summary>
  1653. /// <param name="mattressid"></param>
  1654. /// <returns></returns>
  1655. public List<u_mattress_mx_mtrl> GetMattressMxSubspecsMtrl(int mattressid)
  1656. {
  1657. var list = new List<u_mattress_mx_mtrl>();
  1658. var outputFields = @"mattressid,mtrlid,chastr,formulakind,formulatype,qty,mtrlname";
  1659. var selectStr = @"SELECT
  1660. u_mattress_mx_mtrl.mattressid,
  1661. u_mattress_mx_mtrl.mattressmxid,
  1662. u_mattress_mx_mtrl.mtrlid,
  1663. u_mattress_mx_mtrl.chastr,
  1664. u_mattress_formula.formulakind,
  1665. u_mattress_formula.formulatype,
  1666. u_mattress_mx_mtrl.qty,
  1667. vv_mtrl_price.mtrlname
  1668. FROM u_mattress_mx_mtrl
  1669. LEFT JOIN u_mattress_formula On u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  1670. LEFT OUTER JOIN u_mtrl_price on u_mtrl_price.mtrlid = u_mattress_mx_mtrl.mtrlid
  1671. Left OUTER JOIN (
  1672. select
  1673. mtrlid,
  1674. name as mtrlname
  1675. from u_mtrl_price
  1676. union all
  1677. select top 1
  1678. 0 as mtrlid,
  1679. ' ' as mtrlname
  1680. from u_user_jlhprice
  1681. ) AS vv_mtrl_price on vv_mtrl_price.mtrlid = u_mattress_mx_mtrl.mtrlid
  1682. ";
  1683. var whereList = new List<string>();
  1684. whereList.Add("u_mattress_formula.formulatype IN (1,2)");
  1685. whereList.Add("u_mtrl_price.if_subspecs = 1");
  1686. whereList.Add("u_mattress_mx_mtrl.mattressid = @mattressid");
  1687. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), new Dictionary<string, object>() { { "@mattressid", mattressid } }, "mattressmxid", outputFields, 0, 0, list);
  1688. return list;
  1689. }
  1690. /// <summary>
  1691. /// 床垫报价复制清单
  1692. /// </summary>
  1693. /// <param name="mattressid"></param>
  1694. public void CopyMattressInterface(int cpoyid,int mattressid)
  1695. {
  1696. cmd.CommandText = @"INSERT INTO u_mattress_interface (
  1697. mattressid
  1698. ,printid
  1699. ,itemname
  1700. ,bj_pzname
  1701. ,bj_namemx
  1702. ,bj_inputtype
  1703. ,actual_size
  1704. ,sb_craft
  1705. ,actual_size_sb
  1706. ,erp_pzid
  1707. ,ss_rate
  1708. ,ls_rate
  1709. )
  1710. SELECT @mattressid
  1711. ,printid
  1712. ,itemname
  1713. ,bj_pzname
  1714. ,bj_namemx
  1715. ,bj_inputtype
  1716. ,actual_size
  1717. ,sb_craft
  1718. ,actual_size_sb
  1719. ,erp_pzid
  1720. ,ss_rate
  1721. ,ls_rate
  1722. FROM u_mattress_interface
  1723. WHERE mattressid = @copy_id";
  1724. cmd.Parameters.Clear();
  1725. cmd.Parameters.AddWithValue("@mattressid", mattressid);
  1726. cmd.Parameters.AddWithValue("@copy_id", cpoyid);
  1727. cmd.ExecuteNonQuery();
  1728. cmd.CommandText = @"INSERT INTO u_mattress_interface_qd (
  1729. mattressid
  1730. ,printid
  1731. ,itemname
  1732. ,bj_pzname
  1733. ,bj_pzname_mx
  1734. ,mtrlid
  1735. ,erp_mtrlid
  1736. ,wrkgrpid
  1737. ,useqty
  1738. ,dscrp
  1739. ,actual_useqty
  1740. ,qd_actual_size
  1741. ,qd_pfgroupqty
  1742. ,formulaid
  1743. )
  1744. SELECT @mattressid
  1745. ,printid
  1746. ,itemname
  1747. ,bj_pzname
  1748. ,bj_pzname_mx
  1749. ,mtrlid
  1750. ,erp_mtrlid
  1751. ,wrkgrpid
  1752. ,useqty
  1753. ,dscrp
  1754. ,actual_useqty
  1755. ,qd_actual_size
  1756. ,qd_pfgroupqty
  1757. ,formulaid
  1758. FROM u_mattress_interface_qd
  1759. WHERE mattressid = @copy_id";
  1760. cmd.Parameters.Clear();
  1761. cmd.Parameters.AddWithValue("@mattressid", mattressid);
  1762. cmd.Parameters.AddWithValue("@copy_id", cpoyid);
  1763. cmd.ExecuteNonQuery();
  1764. }
  1765. public void CopyMattress(List<u_mattress> mattressList,int gwidth,int glength)
  1766. {
  1767. var bedNetHelpe = HelperBase.GetHelper<BedNetHelper>(cmd);
  1768. foreach(var mattress in mattressList)
  1769. {
  1770. var mattress_copy = GetMattress(mattress.mattressid);
  1771. var mxlist = new List<u_mattress_mx_mtrl>();
  1772. mattress_copy.deptid = mattress.deptid;
  1773. if (mattress.mattress_length > 0 && mattress.mattress_width > 0)
  1774. {
  1775. cmd.CommandText = @"SELECT u_mattress_mx_mtrl.mtrlid
  1776. FROM u_mattress_mx_mtrl
  1777. INNER JOIN u_mattress_formula ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  1778. WHERE u_mattress_formula.formulakind = 99
  1779. AND u_mattress_mx_mtrl.mattressid = @mattressid
  1780. AND u_mattress_mx_mtrl.mtrlid > 0";
  1781. cmd.Parameters.Clear();
  1782. cmd.Parameters.AddWithValue("@mattressid", mattress.mattressid);
  1783. using(var reader = cmd.ExecuteReader())
  1784. {
  1785. while (reader.Read())
  1786. {
  1787. mxlist.Add(new u_mattress_mx_mtrl() { copty_mtrlid = Convert.ToInt32(reader["mtrlid"]) });
  1788. }
  1789. }
  1790. foreach(var mx in mxlist)
  1791. {
  1792. var bednet = new u_bednet() { bednetid = mx.copty_mtrlid, mattress_width = mattress.mattress_width ,mattress_length = mattress.mattress_length };
  1793. var bednetMx = new u_bednetmx() { spring_qty_width = gwidth, spring_qty_length = glength };
  1794. bedNetHelpe.CopyBedNet(bednet, bednetMx, out int newMtrlid);
  1795. mx.mtrlid = newMtrlid;
  1796. }
  1797. }
  1798. // 判断copy_bedNet.bednetcode是否存在@@字符串,如果存在,则删除@@后面的字符串,包括@@
  1799. if (mattress_copy.mattresscode.IndexOf("@@") > -1)
  1800. {
  1801. mattress_copy.mattresscode = mattress_copy.mattresscode.Substring(mattress_copy.mattresscode.IndexOf("@@"));
  1802. }
  1803. mattress_copy.mattresscode += " @@";
  1804. mattress_copy.mattresscode += DateTime.Now.ToString("yyyMMdd_mmhhss");
  1805. if (mattress_copy.mattressrelcode.IndexOf("@@") > -1)
  1806. {
  1807. mattress_copy.mattressrelcode = mattress_copy.mattressrelcode.Substring(mattress_copy.mattressrelcode.IndexOf("@@"));
  1808. }
  1809. mattress_copy.mattressrelcode += " @@";
  1810. mattress_copy.mattressrelcode += DateTime.Now.ToString("yyyMMdd_mmhhss");
  1811. mattress_copy.mattressid = 0;
  1812. mattress_copy.mattress_width = mattress.mattress_width > 0 ? mattress.mattress_width : mattress_copy.mattress_width;
  1813. mattress_copy.mattress_length = mattress.mattress_length > 0 ? mattress.mattress_length : mattress_copy.mattress_length;
  1814. if (!"维持原状".Equals(mattress.area)) mattress_copy.area = mattress.area;
  1815. if (!"维持原状".Equals(mattress.cabinet_type)) mattress_copy.cabinet_type = mattress.cabinet_type;
  1816. if (mattress.packtype == 0) mattress_copy.packqty = mattress.packqty;
  1817. mattress_copy.js1_flag = 0;
  1818. mattress_copy.js1_auditingrep = string.Empty;
  1819. mattress_copy.js1_auditingdate = null;
  1820. mattress_copy.xd_flag = 0;
  1821. mattress_copy.commission = mattress.commission;
  1822. mattress_copy.taxes = mattress.taxes;
  1823. mattress_copy.other_rate = mattress.other_rate;
  1824. mattress_copy.extras_cost = mattress.extras_cost;
  1825. mattress_copy.moneyrate = mattress.moneyrate;
  1826. mattress_copy.discount = mattress.discount;
  1827. mattress_copy.createby = mattress.createby;
  1828. var mattressMxMtrlList = GetMattressMxMtrl(mattress.mattressid);
  1829. foreach(var mx in mattressMxMtrlList)
  1830. {
  1831. mx.mattressid = 0;
  1832. mx.mattressmxid = 0;
  1833. }
  1834. var mattressMxExtra1List = GetMattressMxExtra(mattress.mattressid, 1);
  1835. foreach (var mx in mattressMxExtra1List)
  1836. {
  1837. mx.mattressid = 0;
  1838. mx.mattressmxid = 0;
  1839. }
  1840. var mattressMxExtra2List = GetMattressMxExtra(mattress.mattressid, 2);
  1841. foreach (var mx in mattressMxExtra2List)
  1842. {
  1843. mx.mattressid = 0;
  1844. mx.mattressmxid = 0;
  1845. }
  1846. try
  1847. {
  1848. //CalCulateFormula(mattress_copy, mattressMxMtrlList, true, true, mattressMxExtra1List, mattressMxExtra2List);
  1849. MattressCalculateCost(mattress_copy, mattressMxMtrlList, mattressMxExtra1List, mattressMxExtra2List);
  1850. }
  1851. catch (Exception e)
  1852. {
  1853. throw new LJCommonException(e.Message);
  1854. }
  1855. var mattressSubspecs = GetMattressSubspecs(mattress.mattressid);
  1856. foreach(var sub in mattressSubspecs)
  1857. {
  1858. sub.copy_id = sub.mattressid;
  1859. sub.createby = mattress.createby;
  1860. sub.mattressid = 0;
  1861. if (sub.mattresscode.IndexOf("@@") > -1)
  1862. {
  1863. sub.mattresscode = sub.mattresscode.Substring(sub.mattresscode.IndexOf("@@"));
  1864. }
  1865. sub.mattresscode += " @@";
  1866. sub.mattresscode += DateTime.Now.ToString("yyyMMdd_mmhhss");
  1867. if (sub.mattressrelcode.IndexOf("@@") > -1)
  1868. {
  1869. sub.mattressrelcode = sub.mattressrelcode.Substring(sub.mattressrelcode.IndexOf("@@"));
  1870. }
  1871. sub.mattressrelcode += " @@";
  1872. sub.mattressrelcode += DateTime.Now.ToString("yyyMMdd_mmhhss");
  1873. sub.mattress_width = mattress.mattress_width > 0 ? mattress.mattress_width : sub.mattress_width;
  1874. sub.mattress_length = mattress.mattress_length > 0 ? mattress.mattress_length : sub.mattress_length;
  1875. if (!"维持原状".Equals(mattress.area)) sub.area = mattress.area;
  1876. if (!"维持原状".Equals(mattress.cabinet_type)) sub.cabinet_type = mattress.cabinet_type;
  1877. if (mattress.packtype == 0) sub.packqty = mattress.packqty;
  1878. }
  1879. var _mattress = ObjectHelper.DeepCopy(mattress_copy);
  1880. _mattress.mxList = mattressMxMtrlList;
  1881. _mattress.extraList = mattressMxExtra1List;
  1882. _mattress.extraCostList = mattressMxExtra2List;
  1883. _mattress.subspecsList = mattressSubspecs;
  1884. SaveMattressPro(_mattress,true,true);
  1885. CopyMattressInterface(mattress.mattressid, _mattress.mattressid);
  1886. foreach (var sub in _mattress.subspecsList)
  1887. {
  1888. CopyMattressInterface(sub.copy_id.Value,sub.mattressid);
  1889. }
  1890. foreach (var mx in mxlist)
  1891. {
  1892. cmd.CommandText = @"UPDATE u_mattress_mx_mtrl
  1893. SET mtrlid = @new_mtrlid
  1894. FROM u_mattress_mx_mtrl
  1895. INNER JOIN u_mattress_formula ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  1896. WHERE u_mattress_formula.formulakind = 99
  1897. AND u_mattress_mx_mtrl.mattressid = @new_mattressid
  1898. AND u_mattress_mx_mtrl.mtrlid = @old_mtrld";
  1899. cmd.Parameters.Clear();
  1900. cmd.Parameters.AddWithValue("@new_mtrlid", mx.mtrlid);
  1901. cmd.Parameters.AddWithValue("@new_mattressid", mattress_copy.mattressid);
  1902. cmd.Parameters.AddWithValue("@old_mtrld", mx.copty_mtrlid);
  1903. cmd.ExecuteNonQuery();
  1904. }
  1905. }
  1906. }
  1907. public void MattressCalculateCost(u_mattress mattress, List<u_mattress_mx_mtrl> mattressMx, List<u_mattress_mx_extra> extraProcesses, List<u_mattress_mx_extra> extraCosts)
  1908. {
  1909. // 没有输入默认按标准计算
  1910. //if (mattress.dannum_type == null || mattress.dannum_type == 0)
  1911. // 20250703:默认只保存标准的单据
  1912. mattress.dannum_type = 2;
  1913. // 作为记录不含税出厂价、部门含税价的各个大小单价格的载体
  1914. var _mattressMain = ObjectHelper.DeepCopy(mattress);
  1915. try
  1916. {
  1917. List<u_mattress> sumMattress = new List<u_mattress>();
  1918. for (var i = 1; i < 5; i++)
  1919. {
  1920. var _mattress = ObjectHelper.DeepCopy(mattress);
  1921. if (mattress.dannum_type.Value != i)
  1922. {
  1923. _mattress.dannum_type = i;
  1924. CalCulateFormula(_mattress, mattressMx, true, true, extraProcesses, extraCosts);
  1925. var nottax_factory_cost = Replacements.Where(o => o.label == "【不含税出厂价】").ToList();
  1926. var dept_cost = Replacements.Where(o => o.label == "【部门含税价】").ToList();
  1927. if (nottax_factory_cost.Count > 0)
  1928. {
  1929. decimal nottax_value = Convert.ToDecimal(nottax_factory_cost[0].value);
  1930. if (i == 1)
  1931. {
  1932. _mattress.dijia_cost1 = nottax_value;
  1933. }
  1934. else if (i == 2)
  1935. {
  1936. _mattress.dijia_cost2 = nottax_value;
  1937. }
  1938. else if (i == 3)
  1939. {
  1940. _mattress.dijia_cost3 = nottax_value;
  1941. }
  1942. else if (i == 4)
  1943. {
  1944. _mattress.dijia_cost4 = nottax_value;
  1945. }
  1946. }
  1947. if (dept_cost.Count > 0)
  1948. {
  1949. decimal dept_costValue = Convert.ToDecimal(dept_cost[0].value);
  1950. if (i == 1)
  1951. {
  1952. _mattress.dannum_cost1 = dept_costValue;
  1953. }
  1954. else if (i == 2)
  1955. {
  1956. _mattress.dannum_cost2 = dept_costValue;
  1957. }
  1958. else if (i == 3)
  1959. {
  1960. _mattress.dannum_cost3 = dept_costValue;
  1961. }
  1962. else if (i == 4)
  1963. {
  1964. _mattress.dannum_cost4 = dept_costValue;
  1965. }
  1966. }
  1967. sumMattress.Add(_mattress);
  1968. }
  1969. }
  1970. CalCulateFormula(mattress, mattressMx, true, true, extraProcesses, extraCosts);
  1971. for (var i = 1; i < 5; i++)
  1972. {
  1973. if (mattress.dannum_type.Value == i)
  1974. {
  1975. var nottax_factory_cost = Replacements.Where(o => o.label == "【不含税出厂价】").ToList();
  1976. var dept_cost = Replacements.Where(o => o.label == "【部门含税价】").ToList();
  1977. if (nottax_factory_cost.Count > 0)
  1978. {
  1979. decimal nottax_value = Convert.ToDecimal(nottax_factory_cost[0].value);
  1980. decimal dept_costValue = Convert.ToDecimal(dept_cost[0].value);
  1981. if (i == 1)
  1982. {
  1983. mattress.dijia_cost1 = nottax_value;
  1984. }
  1985. else if (i == 2)
  1986. {
  1987. mattress.dijia_cost2 = nottax_value;
  1988. }
  1989. else if (i == 3)
  1990. {
  1991. mattress.dijia_cost3 = nottax_value;
  1992. }
  1993. else if (i == 4)
  1994. {
  1995. mattress.dijia_cost4 = nottax_value;
  1996. }
  1997. }
  1998. if (dept_cost.Count > 0)
  1999. {
  2000. decimal dept_costValue = Convert.ToDecimal(dept_cost[0].value);
  2001. if (i == 1)
  2002. {
  2003. mattress.dannum_cost1 = dept_costValue;
  2004. }
  2005. else if (i == 2)
  2006. {
  2007. mattress.dannum_cost2 = dept_costValue;
  2008. }
  2009. else if (i == 3)
  2010. {
  2011. mattress.dannum_cost3 = dept_costValue;
  2012. }
  2013. else if (i == 4)
  2014. {
  2015. mattress.dannum_cost4 = dept_costValue;
  2016. }
  2017. }
  2018. }
  2019. else
  2020. {
  2021. var matchMattress = sumMattress.Where(o => o.dannum_type == i).ToList();
  2022. if (matchMattress.Count > 0)
  2023. {
  2024. if (i == 1)
  2025. {
  2026. mattress.dannum_cost1 = matchMattress[0].dannum_cost1;
  2027. mattress.dijia_cost1 = matchMattress[0].dijia_cost1;
  2028. }
  2029. else if (i == 2)
  2030. {
  2031. mattress.dannum_cost2 = matchMattress[0].dannum_cost2;
  2032. mattress.dijia_cost2 = matchMattress[0].dijia_cost2;
  2033. }
  2034. else if (i == 3)
  2035. {
  2036. mattress.dannum_cost3 = matchMattress[0].dannum_cost3;
  2037. mattress.dijia_cost3 = matchMattress[0].dijia_cost3;
  2038. }
  2039. else if (i == 4)
  2040. {
  2041. mattress.dannum_cost4 = matchMattress[0].dannum_cost4;
  2042. mattress.dijia_cost4 = matchMattress[0].dijia_cost4;
  2043. }
  2044. }
  2045. }
  2046. }
  2047. }
  2048. catch (Exception e)
  2049. {
  2050. throw new LJCommonException(e.Message);
  2051. }
  2052. }
  2053. #region 床垫接口相关方法
  2054. /// <summary>
  2055. /// 床垫不保价审核
  2056. /// </summary>
  2057. /// <param name="mattressid"></param>
  2058. /// <exception cref="LJCommonException"></exception>
  2059. public void MattressAudit(int mattressid)
  2060. {
  2061. var power73 = UserHelper.CheckFuncPower(cmd, context.tokendata.empid, 73);
  2062. if (!power73)
  2063. {
  2064. throw new LJCommonException("你没有审核权限");
  2065. }
  2066. // 检查锁
  2067. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2068. var mattress = new u_mattress() { mattressid = mattressid };
  2069. DbSqlHelper.SelectOne(cmd, mattress, "flag,mattresscode,version");
  2070. if (mattress.flag == 1)
  2071. {
  2072. throw new LJCommonException($"床垫报价【{mattress.mattresscode}】已审核!");
  2073. }
  2074. mattress.flag = 1;
  2075. mattress.auditingrep = context.tokendata.username;
  2076. mattress.auditingdate = DateTime.Now;
  2077. mattress.version++;
  2078. if (DbSqlHelper.Update(cmd, "u_mattress", null, mattress, "mattressid", "flag,auditingrep,auditingdate,version") <= 0)
  2079. {
  2080. throw new LJCommonException("因网络或其它原因,【审核】操作失败!");
  2081. }
  2082. }
  2083. /// <summary>
  2084. /// 床垫报价撤销审核
  2085. /// </summary>
  2086. /// <param name="mattressid"></param>
  2087. /// <exception cref="LJCommonException"></exception>
  2088. public void MattressCAudit(int mattressid)
  2089. {
  2090. var power74 = UserHelper.CheckFuncPower(cmd, context.tokendata.empid, 74);
  2091. if (!power74)
  2092. {
  2093. throw new LJCommonException("你没有取消审核权限");
  2094. }
  2095. // 检查锁
  2096. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2097. var mattress = new u_mattress() { mattressid = mattressid };
  2098. DbSqlHelper.SelectOne(cmd, mattress, "flag,mattresscode,version");
  2099. if (mattress.flag == 0)
  2100. {
  2101. throw new LJCommonException($"床垫报价【{mattress.mattresscode}】未审核!");
  2102. }
  2103. mattress.flag = 0;
  2104. mattress.auditingrep = "";
  2105. mattress.auditingdate = null;
  2106. mattress.version++;
  2107. if (DbSqlHelper.Update(cmd, "u_mattress", null, mattress, "mattressid", "flag,auditingrep,auditingdate,version") <= 0)
  2108. {
  2109. throw new LJCommonException("因网络或其它原因,【撤销审核】操作失败!");
  2110. }
  2111. }
  2112. /// <summary>
  2113. /// 业务下单
  2114. /// </summary>
  2115. /// <param name="mattress"></param>
  2116. public void MattressXDAudit(int mattressid)
  2117. {
  2118. var power94 = UserHelper.CheckFuncPower(cmd, context.tokendata.empid, 94);
  2119. if (!power94)
  2120. {
  2121. throw new LJCommonException("你没有业务下单权限");
  2122. }
  2123. // 检查锁
  2124. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2125. var mattress = new u_mattress() { mattressid = mattressid };
  2126. DbSqlHelper.SelectOne(cmd, mattress, "flag,xd_flag,yw_flag,mattresscode,version");
  2127. if (mattress.flag == 1)
  2128. {
  2129. throw new LJCommonException($"床垫报价【{mattress.mattresscode}】已审核,不能业务下单!");
  2130. }
  2131. if (mattress.xd_flag == 1)
  2132. {
  2133. throw new LJCommonException($"床垫报价【{mattress.mattresscode}】已业务下单,不能业务下单!");
  2134. }
  2135. mattress.xd_flag = 1;
  2136. mattress.xd_auditingrep = context.tokendata.username;
  2137. mattress.xd_auditingdate = DateTime.Now;
  2138. mattress.version++;
  2139. if (DbSqlHelper.Update(cmd, "u_mattress", null, mattress, "mattressid", "xd_flag, xd_auditingrep, xd_auditingdate,version") <= 0)
  2140. {
  2141. throw new LJCommonException("因网络或其它原因,【业务下单/取消】操作失败!");
  2142. }
  2143. }
  2144. /// <summary>
  2145. /// 取消业务下单
  2146. /// </summary>
  2147. /// <param name="mattress"></param>
  2148. public void MattressXDCAudit(int mattressid)
  2149. {
  2150. var power95 = UserHelper.CheckFuncPower(cmd, context.tokendata.empid, 95);
  2151. if (!power95)
  2152. {
  2153. throw new LJCommonException("你没有取消业务下单权限");
  2154. }
  2155. // 检查锁
  2156. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2157. var mattress = new u_mattress() { mattressid = mattressid };
  2158. DbSqlHelper.SelectOne(cmd, mattress, "js1_flag,js2_flag,xd_flag,yw_flag,mattresscode,version");
  2159. if (mattress.js1_flag == 1)
  2160. {
  2161. throw new LJCommonException($"床垫报价【{mattress.mattresscode}】已产品补充审核,不能取消下单!");
  2162. }
  2163. if (mattress.js2_flag == 1)
  2164. {
  2165. throw new LJCommonException($"床垫报价【{mattress.mattresscode}】已清单补充审核,不能取消下单!");
  2166. }
  2167. if (mattress.xd_flag == 0)
  2168. {
  2169. throw new LJCommonException($"床垫报价【{mattress.mattresscode}】未业务下单,不能取消下单!");
  2170. }
  2171. mattress.xd_flag = 0;
  2172. mattress.xd_auditingrep = "";
  2173. mattress.xd_auditingdate = null;
  2174. mattress.version++;
  2175. if (DbSqlHelper.Update(cmd, "u_mattress", null, mattress, "mattressid", "xd_flag, xd_auditingrep, xd_auditingdate,version") <= 0)
  2176. {
  2177. throw new LJCommonException("因网络或其它原因,【业务下单/取消】操作失败!");
  2178. }
  2179. }
  2180. /// <summary>
  2181. /// 业务审核
  2182. /// </summary>
  2183. /// <param name="mattressid"></param>
  2184. /// <exception cref="LJCommonException"></exception>
  2185. public void MattressYWAudit(int mattressid)
  2186. {
  2187. // 检查锁
  2188. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2189. var mattress = new u_mattress() { mattressid = mattressid };
  2190. DbSqlHelper.SelectOne(cmd, mattress, "yw_flag,version");
  2191. if(mattress.yw_flag == 1)
  2192. {
  2193. throw new LJCommonException("床垫已业务审核,不能业务审核!");
  2194. }
  2195. mattress.yw_flag = 1;
  2196. mattress.yw_auditingdate = context.opdate;
  2197. mattress.yw_auditingrep = context.tokendata.username;
  2198. mattress.version++;
  2199. DbSqlHelper.Update(cmd, mattress, "yw_flag,yw_auditingdate,yw_auditingrep,version");
  2200. }
  2201. /// <summary>
  2202. /// 业务撤审
  2203. /// </summary>
  2204. /// <param name="mattressid"></param>
  2205. /// <exception cref="LJCommonException"></exception>
  2206. public void MattressYWCancelAudit(int mattressid)
  2207. {
  2208. // 检查锁
  2209. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2210. var mattress = new u_mattress() { mattressid = mattressid };
  2211. DbSqlHelper.SelectOne(cmd, mattress, "yw_flag,js1_flag");
  2212. if (mattress.js1_flag == 1)
  2213. {
  2214. throw new LJCommonException("床垫已技术1审核,不能业务撤审!");
  2215. }
  2216. if (mattress.yw_flag == 0)
  2217. {
  2218. throw new LJCommonException("床垫未业务审核,不能业务撤审!");
  2219. }
  2220. mattress.yw_flag = 0;
  2221. mattress.yw_auditingdate = null;
  2222. mattress.yw_auditingrep = string.Empty;
  2223. mattress.version++;
  2224. DbSqlHelper.Update(cmd, mattress, "yw_flag,yw_auditingdate,yw_auditingrep,version");
  2225. }
  2226. /// <summary>
  2227. /// 产品补充审核
  2228. /// </summary>
  2229. /// <param name="mattressid"></param>
  2230. /// <exception cref="LJCommonException"></exception>
  2231. public void MattressJSAudit(int mattressid)
  2232. {
  2233. // 检查锁
  2234. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2235. var mattress = new u_mattress() { mattressid = mattressid };
  2236. DbSqlHelper.SelectOne(cmd, mattress, "yw_flag,js1_flag,version");
  2237. if (mattress.js1_flag == 1)
  2238. {
  2239. throw new LJCommonException("床垫已技术1审核,不能技术1审核!");
  2240. }
  2241. //if (mattress.yw_flag == 0)
  2242. //{
  2243. // throw new LJCommonException("床垫未业务审核,不能技术1审核!");
  2244. //}
  2245. mattress.js1_flag = 1;
  2246. mattress.js1_auditingdate = context.opdate;
  2247. mattress.js1_auditingrep = context.tokendata.username;
  2248. mattress.version++;
  2249. DbSqlHelper.Update(cmd, mattress, "js1_flag,js1_auditingdate,js1_auditingrep,version");
  2250. }
  2251. /// <summary>
  2252. /// 产品补充撤审
  2253. /// </summary>
  2254. /// <param name="mattressid"></param>
  2255. /// <exception cref="LJCommonException"></exception>
  2256. public void MattressJSCancelAudit(int mattressid)
  2257. {
  2258. // 检查锁
  2259. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2260. var mattress = new u_mattress() { mattressid = mattressid };
  2261. DbSqlHelper.SelectOne(cmd, mattress, "yw_flag,js1_flag,creatmtrl_flag");
  2262. //if (mattress.creatmtrl_flag == 1)
  2263. //{
  2264. // throw new LJCommonException("床垫已生成产品,不能技术1撤审!");
  2265. //}
  2266. if (mattress.js1_flag == 0)
  2267. {
  2268. throw new LJCommonException("床垫未技术1撤审,不能技术1撤审!");
  2269. }
  2270. mattress.js1_flag = 0;
  2271. mattress.js1_auditingdate = null;
  2272. mattress.js1_auditingrep = string.Empty;
  2273. mattress.version++;
  2274. DbSqlHelper.Update(cmd, mattress, "js1_flag,js1_auditingdate,js1_auditingrep,version");
  2275. }
  2276. /// <summary>
  2277. /// 清单补充审核
  2278. /// </summary>
  2279. /// <param name="mattressid"></param>
  2280. /// <exception cref="LJCommonException"></exception>
  2281. public void MattressJS2Audit(int mattressid)
  2282. {
  2283. // 检查锁
  2284. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2285. var mattress = new u_mattress() { mattressid = mattressid };
  2286. DbSqlHelper.SelectOne(cmd, mattress, "js2_flag,version");
  2287. if (mattress.js2_flag == 1)
  2288. {
  2289. throw new LJCommonException("床垫已技术2审核,不能技术2审核!");
  2290. }
  2291. mattress.js2_flag = 1;
  2292. mattress.js2_auditingdate = context.opdate;
  2293. mattress.js2_auditingrep = context.tokendata.username;
  2294. mattress.version++;
  2295. DbSqlHelper.Update(cmd, mattress, "js2_flag,js2_auditingdate,js2_auditingrep,version");
  2296. }
  2297. /// <summary>
  2298. /// 清单补充撤审
  2299. /// </summary>
  2300. /// <param name="mattressid"></param>
  2301. /// <exception cref="LJCommonException"></exception>
  2302. public void MattressJS2CancelAudit(int mattressid)
  2303. {
  2304. // 检查锁
  2305. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2306. var mattress = new u_mattress() { mattressid = mattressid };
  2307. DbSqlHelper.SelectOne(cmd, mattress, "js2_flag,version");
  2308. if (mattress.js2_flag == 0)
  2309. {
  2310. throw new LJCommonException("床垫未技术2审核,不能技术2撤审!");
  2311. }
  2312. mattress.js2_flag = 0;
  2313. mattress.js2_auditingdate = null;
  2314. mattress.js2_auditingrep = string.Empty;
  2315. mattress.version++;
  2316. DbSqlHelper.Update(cmd, mattress, "js2_flag,js2_auditingdate,js2_auditingrep,version");
  2317. }
  2318. #endregion
  2319. #region 方法优化
  2320. /// <summary>
  2321. /// 床垫报价保存
  2322. /// </summary>
  2323. /// <param name="mattress"></param>
  2324. /// <param name="ifErp"></param>
  2325. public void SaveMattressPro(u_mattress mattress)
  2326. {
  2327. SaveMattressPro(mattress, false, false);
  2328. }
  2329. public void SaveMattressPro(u_mattress mattress, bool ifErp = false, bool ignoreLock = false)
  2330. {
  2331. SaveMattressCheck(mattress);
  2332. var fields = @"mattressname, deptid, mattresscode, mattresstypeid, mattress_width, mattress_length, mattress_height, packtype, packqty, woodpallettype, total_hr_cost,
  2333. total_material_cost, fees_dscrp, total_fees_cost, total_cost, taxrate, taxes, commissionrate, commission, fob, profitrate, dept_profitrate,
  2334. moneyrate, nottax_factory_cost, nottax_dept_cost, foreign_cost, diameter, area, cabinet_type, hrcost, biandaicost,
  2335. mattressrelcode, other_rate, flag, dept_profitrate_rangli, profitrate_point, if_moneyrate, discount, if_m_chai, if_z_chai, if_d_chai, if_n_butao,
  2336. if_w_butao, if_m_wbutao_way, s_cover_qty, z_cover_qty, x_cover_qty, biandai_qty, s_m_cover_qty, z_m_cover_qty, x_m_cover_qty, chaizhuang_point,
  2337. haimian_point, if_zhedie_type, qr_auditingrep, qr_auditingdate, if_bcp_type, zhizao_amt, foreign_cost_bz, cubage, extras_cost, extras_cost_dscrp,
  2338. parentid, flag, xd_flag, dannum_type,dannum_cost1,dannum_cost2, dannum_cost3, dannum_cost4, dijia_cost1,dijia_cost2,dijia_cost3,dijia_cost4,version,total_mtrl_hr_cost";
  2339. var fieldsMx = "mattressmxid,mattressid,formulaid,formula,replace_formula,if_success,priceunit,shrinkage,mtrlid,price,gram_weight,cloth_width,if_inputqty,qty ,costamt,if_areaprice,thickness,chastr,xu,useqty,useformula,replace_useformula,gydscrp,mattress_width,mattress_length,sidecover";
  2340. var fieldsExtra = "mattressmxid,mattressid, extraid, extramxid, extraname, price, qty, dscrp, mtrlid";
  2341. mattress.qr_auditingdate = context.opdate;
  2342. mattress.qr_auditingrep = context.tokendata.username;
  2343. if (ifErp)
  2344. {
  2345. fields += ",erp_mtrlcode,erp_mtrlid,erp_configcodetype, erp_mtrlengname, erp_mtrlmode, erp_mtrlname, erp_mtrltype, erp_mtrltypeid, erp_mtrlunit, erp_piccode";
  2346. }
  2347. if (mattress.mattressid <= 0)
  2348. {
  2349. // 新建
  2350. AutoInit.AutoInitS(mattress);
  2351. //
  2352. mattress.createtime = context.opdate;
  2353. if (string.IsNullOrEmpty(mattress.createby)) mattress.createby = context.tokendata.username;
  2354. mattress.mattressid = BllHelper.GetID(cmd, "u_mattress");
  2355. mattress.version = 1;
  2356. fields += ",mattressid, createtime, createby";
  2357. if (string.IsNullOrEmpty(mattress.mattresscode))
  2358. {
  2359. var mattresstype = new u_mattress_type() { mattresstypeid = mattress.mattresstypeid };
  2360. DbSqlHelper.SelectOne(cmd, mattresstype, "typecode");
  2361. mattress.mattresscode = $"{mattresstype.typecode}-{context.opdate.ToString("yyyyMMdd")}{(mattress.mattressid % 10000).ToString("D4")}";
  2362. }
  2363. DbSqlHelper.Insert(cmd, "u_mattress", null, mattress, fields);
  2364. }
  2365. else
  2366. {
  2367. // 修改
  2368. AutoInit.AutoInitS(mattress);
  2369. //
  2370. mattress.version++;
  2371. DbSqlHelper.Update(cmd, "u_mattress", null, mattress, "mattressid", fields);
  2372. // 删除所有明细
  2373. cmd.CommandText = @"DELETE u_mattress_mx_mtrl WHERE mattressid = @mattressid";
  2374. cmd.Parameters.Clear();
  2375. cmd.Parameters.AddWithValue("@mattressid", mattress.mattressid);
  2376. cmd.ExecuteNonQuery();
  2377. // 删除所有额外费用明细
  2378. cmd.CommandText = @"DELETE u_mattress_mx_extra WHERE mattressid = @mattressid";
  2379. cmd.Parameters.Clear();
  2380. cmd.Parameters.AddWithValue("@mattressid", mattress.mattressid);
  2381. cmd.ExecuteNonQuery();
  2382. }
  2383. // 插入明细内容
  2384. if (mattress.mxList != null && mattress.mxList.Count > 0)
  2385. {
  2386. foreach (var item in mattress.mxList)
  2387. {
  2388. AutoInit.AutoInitS(cmd, item);
  2389. item.mattressid = mattress.mattressid;
  2390. if (item.mattressmxid == null || item.mattressmxid <= 0)
  2391. {
  2392. item.mattressmxid = BllHelper.GetID(cmd, "u_mattress_mx_mtrl");
  2393. }
  2394. DbSqlHelper.Insert(cmd, "u_mattress_mx_mtrl", null, item, fieldsMx);
  2395. }
  2396. }
  2397. // 插入特殊工艺
  2398. if (mattress.extraList != null && mattress.extraList.Count > 0)
  2399. {
  2400. foreach (var item in mattress.extraList)
  2401. {
  2402. AutoInit.AutoInitS(cmd, item);
  2403. item.mattressid = mattress.mattressid;
  2404. item.mattressmxid = BllHelper.GetID(cmd, "u_mattress_mx_extra");
  2405. DbSqlHelper.Insert(cmd, "u_mattress_mx_extra", null, item, fieldsExtra);
  2406. }
  2407. }
  2408. // 特殊费用
  2409. if (mattress.extraCostList != null && mattress.extraCostList.Count > 0)
  2410. {
  2411. foreach (var item in mattress.extraCostList)
  2412. {
  2413. AutoInit.AutoInitS(cmd, item);
  2414. item.mattressid = mattress.mattressid;
  2415. item.mattressmxid = BllHelper.GetID(cmd, "u_mattress_mx_extra");
  2416. DbSqlHelper.Insert(cmd, "u_mattress_mx_extra", null, item, fieldsExtra);
  2417. }
  2418. }
  2419. // 更新计价历史
  2420. var hisprice = new u_his_price
  2421. {
  2422. bednetid_mattressid = mattress.mattressid,
  2423. typeid = 1,
  2424. cmpdate = context.opdate,
  2425. cmpemp = context.tokendata.username,
  2426. nottax_dept_cost = mattress.nottax_dept_cost,
  2427. dept_cost = mattress.dept_cost,
  2428. foreign_cost = mattress.foreign_cost,
  2429. dannum_cost1 = mattress.dannum_cost1,
  2430. dannum_cost2 = mattress.dannum_cost2,
  2431. dannum_cost3 = mattress.dannum_cost3,
  2432. dannum_cost4 = mattress.dannum_cost4,
  2433. dijia_cost1 = mattress.dijia_cost1,
  2434. dijia_cost2 = mattress.dijia_cost2,
  2435. dijia_cost3 = mattress.dijia_cost3,
  2436. dijia_cost4 = mattress.dijia_cost4,
  2437. fob = mattress.fob,
  2438. cabinet_type = mattress.cabinet_type,
  2439. taxrate = mattress.taxrate,
  2440. commission = mattress.commission
  2441. };
  2442. var fieldsHs = "bednetid_mattressid, typeid, cmpdate, cmpemp, nottax_dept_cost, dept_cost, foreign_cost, dannum_cost1, dannum_cost2, dannum_cost3, dannum_cost4,dijia_cost1,dijia_cost2,dijia_cost3,dijia_cost4,fob,cabinet_type,taxrate,commission";
  2443. DbSqlHelper.Insert(cmd, "u_his_price", null, hisprice, fieldsHs);
  2444. // 处理子规格
  2445. ProcessSubSpecs(mattress, ifErp);
  2446. // 解锁
  2447. if(!ignoreLock) LockHelper.UnLockBill(cmd, BillKeyWord, mattress.mattressid, context.tokendata.username, 0);
  2448. }
  2449. /// <summary>
  2450. /// 初始化子规格
  2451. /// </summary>
  2452. /// <param name="parent">主规格</param>
  2453. /// <param name="subspecsList">副规格</param>
  2454. public void InitMattressSubSpecs(u_mattress parent, u_mattress child)
  2455. {
  2456. var bedNetHelper = GetHelper<BedNetHelper>(cmd, context);
  2457. var bednetIndex = 0; // 床网索引
  2458. var cushionsIndex = 1; // 垫层主副规格物料索引
  2459. var accessoriesIndex = 1; // 辅料主副规格物料索引
  2460. // 处理副规格的明细内容
  2461. foreach (var childMx in child.mxList)
  2462. {
  2463. // 副规格床网自动匹配/新增逻辑
  2464. if (childMx.formulatype == 99 && childMx.mtrlid > 0)
  2465. {
  2466. bednetIndex++;
  2467. var oBednet = new u_bednet();
  2468. var _bednet = bedNetHelper.GetBedNet(childMx.mtrlid.Value);
  2469. var _bednetMx = bedNetHelper.GetBedNetMxList(childMx.mtrlid.Value);
  2470. var _bednetSpring = bedNetHelper.GetBedNetSpringList(childMx.mtrlid.Value);
  2471. // 20250714 副规格的床网,不匹配查找,直接新建
  2472. oBednet = _bednet;
  2473. oBednet.bednetid = 0;
  2474. oBednet.mattress_width = child.mattress_width;
  2475. oBednet.mattress_length = child.mattress_length;
  2476. if (child.DynamicFields != null && child.DynamicFields.Count > 0)
  2477. {
  2478. child.DynamicFields.TryGetValue($"spring_qty_width_{bednetIndex}", out var _spring_qty_width);
  2479. child.DynamicFields.TryGetValue($"spring_qty_length_{bednetIndex}", out var _spring_qty_length);
  2480. _bednetMx[0].spring_qty_width = Convert.ToInt32(_spring_qty_width);
  2481. _bednetMx[0].spring_qty_length = Convert.ToInt32(_spring_qty_length);
  2482. if (!child.DynamicFields.TryGetValue($"bednet_fork_qty_{bednetIndex}", out var _bednet_fork_qty))
  2483. {
  2484. _bednet_fork_qty = _bednet.fork_qty;
  2485. }
  2486. oBednet.fork_qty = Convert.ToDecimal(_bednet_fork_qty);
  2487. }
  2488. // 袋装网,多个分区时,重新分配弹簧
  2489. bedNetHelper.GetSpringListQty(oBednet, _bednetMx[0], ref _bednetSpring);
  2490. bedNetHelper.SaveBedNet(oBednet, _bednetMx, _bednetSpring);
  2491. childMx.mtrlid = oBednet.bednetid;
  2492. childMx.mtrlname = $"{oBednet.typename} {oBednet.bednetcode} {oBednet.mattress_width}*{oBednet.mattress_length}*{oBednet.mattress_height}";
  2493. childMx.price = oBednet.nottax_factory_cost;
  2494. childMx.qty = 1;
  2495. }
  2496. // 垫层改动逻辑
  2497. if (childMx.formulatype == 1 && childMx.mtrlid > 0)
  2498. {
  2499. // 规格长/宽,按比例缩放
  2500. if (childMx.mattress_width > 0)
  2501. {
  2502. childMx.mattress_width = (int)Math.Floor((decimal)childMx.mattress_width * (Convert.ToDecimal(child.mattress_width) / (decimal)parent.mattress_width));
  2503. }
  2504. if (childMx.mattress_length > 0)
  2505. {
  2506. childMx.mattress_length = (int)Math.Floor((decimal)childMx.mattress_length * (Convert.ToDecimal(child.mattress_length) / (decimal)parent.mattress_length));
  2507. }
  2508. // 副规格-垫层物料替换
  2509. if (childMx.if_subspecs == 1 && child.DynamicFields.TryGetValue($"cushions_subspecs_{cushionsIndex}", out var cushions_subspecs))
  2510. {
  2511. childMx.mtrlid = Convert.ToInt32(cushions_subspecs);
  2512. cushionsIndex++;
  2513. }
  2514. }
  2515. // 辅料改动逻辑
  2516. if (childMx.formulatype == 2 && childMx.mtrlid > 0)
  2517. {
  2518. // 副规格-辅料物料替换
  2519. if (childMx.if_subspecs == 1 && child.DynamicFields.TryGetValue($"accessories_subspecs_{accessoriesIndex}", out var accessories_subspecs))
  2520. {
  2521. child.DynamicFields.TryGetValue($"accessories_subspecs_qty_{accessoriesIndex}", out object accessories_subspecs_qty);
  2522. childMx.mtrlid = Convert.ToInt32(accessories_subspecs);
  2523. childMx.qty = accessories_subspecs_qty == null ? childMx.qty.Value : Convert.ToInt32(accessories_subspecs_qty);
  2524. accessoriesIndex++;
  2525. }
  2526. }
  2527. // 内布套 / 顶部裥棉逻辑
  2528. if ((childMx.formulatype == 101 || childMx.formulatype == 102 || childMx.formulatype == 103) && childMx.mtrlid > 0 && (childMx.mattress_width > 0 || childMx.mattress_length > 0))
  2529. {
  2530. childMx.mattress_width += child.mattress_width - parent.mattress_width;
  2531. childMx.mattress_length += child.mattress_length - parent.mattress_length;
  2532. }
  2533. }
  2534. }
  2535. /// <summary>
  2536. /// 子规格保存
  2537. /// </summary>
  2538. /// <param name="mattress"></param>
  2539. /// <param name="ifErp"></param>
  2540. public void ProcessSubSpecs(u_mattress mattress, bool ifErp)
  2541. {
  2542. if (mattress.subspecsList == null) return;
  2543. var existing = GetMattressSubspecs(mattress.mattressid, "mattressid,mattresscode,flag,js1_flag") ?? new List<u_mattress>();
  2544. // TODO
  2545. foreach (var child in existing)
  2546. {
  2547. if (child.flag == 1) throw new LJCommonException($"存在副规格[{child.mattresscode}]已财务审核,无法修改主规格!");
  2548. if (child.js1_flag == 1) throw new LJCommonException($"存在副规格[{child.mattresscode}]已产品审核,无法修改主规格!");
  2549. }
  2550. var oldIdSet = new HashSet<int>(existing.Select(x => x.mattressid));
  2551. var newIdSet = new HashSet<int>(mattress.subspecsList.Where(x => x.mattressid != 0).Select(x => x.mattressid));
  2552. var toUpdate = mattress.subspecsList.Where(x => oldIdSet.Contains(x.mattressid)).ToList();
  2553. var toInsert = mattress.subspecsList.Where(x => x.mattressid == 0).ToList();
  2554. var toDelete = existing.Where(x => !newIdSet.Contains(x.mattressid)).ToList();
  2555. toDelete.ForEach(x => DeleteMattress(x.mattressid));
  2556. var subspecsList = new List<u_mattress>();
  2557. foreach (var child in toInsert)
  2558. {
  2559. subspecsList.Add(child);
  2560. }
  2561. foreach (var child in toUpdate)
  2562. {
  2563. subspecsList.Add(child);
  2564. }
  2565. SaveSubSpecs(mattress, subspecsList, ifErp);
  2566. }
  2567. public void SaveSubSpecs(u_mattress parent,List<u_mattress> childs,bool ifErp)
  2568. {
  2569. var subspecsList = new List<u_mattress>();
  2570. foreach (var child in childs)
  2571. {
  2572. var copy = CreateSubSpecClone(parent, child);
  2573. subspecsList.Add(copy);
  2574. }
  2575. subspecsList.Sort((a, b) =>
  2576. {
  2577. int cmp = a.mattress_width.Value.CompareTo(b.mattress_width);
  2578. return cmp != 0 ? cmp : a.mattress_length.Value.CompareTo(b.mattress_length);
  2579. });
  2580. foreach (var child in subspecsList)
  2581. {
  2582. // 已经审核的不进行再次保存/修改
  2583. if (child.flag == 1 || child.yw_flag == 1 || child.xd_flag == 1) continue;
  2584. InitMattressSubSpecs(parent, child);
  2585. MattressCalculateCost(child, child.mxList, child.extraList, child.extraCostList);
  2586. SaveMattressPro(child, ifErp, true);
  2587. }
  2588. parent.subspecsList = subspecsList;
  2589. }
  2590. /// <summary>
  2591. /// 子规格复制逻辑
  2592. /// </summary>
  2593. /// <param name="parent"></param>
  2594. /// <param name="child"></param>
  2595. /// <returns></returns>
  2596. private u_mattress CreateSubSpecClone(u_mattress parent, u_mattress child)
  2597. {
  2598. AutoInit.AutoInitS(child);
  2599. var clone = ObjectHelper.DeepCopy(parent);
  2600. clone.parentid = parent.mattressid;
  2601. clone.createby = parent.createby;
  2602. clone.mattressid = child.mattressid;
  2603. clone.mattresscode = child.mattresscode;
  2604. clone.mattressrelcode = child.mattressrelcode;
  2605. clone.mattressname = child.mattressname;
  2606. clone.xd_flag = child.xd_flag;
  2607. clone.xd_auditingdate = child.xd_auditingdate;
  2608. clone.xd_auditingrep = child.xd_auditingrep;
  2609. clone.flag = child.flag;
  2610. clone.auditingdate = child.auditingdate;
  2611. clone.auditingrep = child.auditingrep;
  2612. clone.js1_flag = child.js1_flag;
  2613. clone.js1_auditingdate = child.js1_auditingdate;
  2614. clone.js1_auditingrep = child.js1_auditingrep;
  2615. clone.yw_flag = child.yw_flag;
  2616. clone.yw_auditingdate = child.yw_auditingdate;
  2617. clone.yw_auditingrep = child.yw_auditingrep;
  2618. clone.js2_flag = child.js2_flag;
  2619. clone.js2_auditingdate = child.js2_auditingdate;
  2620. clone.js2_auditingrep = child.js2_auditingrep;
  2621. clone.qr_flag = child.qr_flag;
  2622. clone.qr_auditingdate = child.qr_auditingdate;
  2623. clone.qr_auditingrep = child.qr_auditingrep;
  2624. clone.subspecsList = child.subspecsList;
  2625. clone.mattress_width = child.mattress_width;
  2626. clone.mattress_length = child.mattress_length;
  2627. clone.mattress_height = child.mattress_height;
  2628. clone.version = child.version;
  2629. clone.DynamicFields = child.DynamicFields;
  2630. clone.mxList = parent.mxList?.Select(mx =>
  2631. {
  2632. var mxClone = ObjectHelper.DeepCopy(mx);
  2633. mxClone.mattressid = 0;
  2634. mxClone.mattressmxid = 0;
  2635. return mxClone;
  2636. }).ToList();
  2637. clone.extraList = parent.extraList?.Select(mx =>
  2638. {
  2639. var mxClone = ObjectHelper.DeepCopy(mx);
  2640. mxClone.mattressid = 0;
  2641. mxClone.mattressmxid = 0;
  2642. return mxClone;
  2643. }).ToList();
  2644. clone.extraCostList = parent.extraCostList?.Select(mx =>
  2645. {
  2646. var mxClone = ObjectHelper.DeepCopy(mx);
  2647. mxClone.mattressid = 0;
  2648. mxClone.mattressmxid = 0;
  2649. return mxClone;
  2650. }).ToList();
  2651. // iferp
  2652. clone.erp_mtrlcode = child.erp_mtrlcode;
  2653. clone.erp_mtrlid = child.erp_mtrlid;
  2654. clone.erp_configcodetype = child.erp_configcodetype;
  2655. clone.erp_mtrlengname = child.erp_mtrlengname;
  2656. clone.erp_mtrlmode = child.erp_mtrlmode;
  2657. clone.erp_mtrlname = child.erp_mtrlname;
  2658. clone.erp_mtrltype = child.erp_mtrltype;
  2659. clone.erp_mtrltypeid = child.erp_mtrltypeid;
  2660. clone.erp_mtrlunit = child.erp_mtrlunit;
  2661. clone.erp_piccode = child.erp_piccode;
  2662. return clone;
  2663. }
  2664. /// <summary>
  2665. /// 删除床垫报价
  2666. /// </summary>
  2667. /// <param name="mattressid"></param>
  2668. /// <param name="isDelMain"></param>
  2669. public void DeleteMattress(int mattressid)
  2670. {
  2671. //
  2672. if (mattressid <= 0) throw new LJCommonException("ID错误,删除床垫报价失败!");
  2673. var mattress = GetMattress(mattressid, "mattresscode,flag,js1_flag,xd_flag,parentid");
  2674. if (mattress.parentid > 0 && (mattress.js1_flag == 1 || mattress.flag == 1)) return;
  2675. if (mattress.xd_flag == 1) throw new LJCommonException($"床垫报价[{mattress.mattresscode}]已下单,无法删除!");
  2676. if (mattress.js1_flag == 1) throw new LJCommonException($"床垫报价[{mattress.mattresscode}]已产品审核,无法删除!");
  2677. if (mattress.flag == 1) throw new LJCommonException($"床垫报价[{mattress.mattresscode}]已财务审核,无法删除!");
  2678. // 删除所有明细
  2679. cmd.CommandText = @"DELETE u_mattress_mx_mtrl WHERE mattressid = @mattressid";
  2680. cmd.Parameters.Clear();
  2681. cmd.Parameters.AddWithValue("@mattressid", mattressid);
  2682. cmd.ExecuteNonQuery();
  2683. // 删除所有额外费用明细
  2684. cmd.CommandText = @"DELETE u_mattress_mx_extra WHERE mattressid = @mattressid";
  2685. cmd.Parameters.Clear();
  2686. cmd.Parameters.AddWithValue("@mattressid", mattressid);
  2687. cmd.ExecuteNonQuery();
  2688. // 删除主表
  2689. cmd.CommandText = @"DELETE u_mattress WHERE mattressid = @mattressid";
  2690. cmd.Parameters.Clear();
  2691. cmd.Parameters.AddWithValue("@mattressid", mattressid);
  2692. cmd.ExecuteNonQuery();
  2693. }
  2694. /// <summary>
  2695. /// 保存床垫检测
  2696. /// </summary>
  2697. /// <param name="mattress"></param>
  2698. /// <exception cref="LJCommonException"></exception>
  2699. public void SaveMattressCheck(u_mattress mattress)
  2700. {
  2701. if (mattress == null) throw new LJCommonException("床垫报价保存失败,数据异常!");
  2702. if (mattress.mxList == null || mattress.mxList.Count <= 0) throw new LJCommonException("床垫报价保存失败,明细内容为空!");
  2703. // 1.卷包包装必须有卷包直径
  2704. if(mattress.packtype == 1 && mattress.diameter <= 0)
  2705. {
  2706. throw new LJCommonException("卷包直径有误,卷包包装必须有卷包直径!");
  2707. }
  2708. if (mattress.mattressid > 0 && mattress.parentid == 0)
  2709. {
  2710. // 检查锁
  2711. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattress.mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2712. // 检测版本控制
  2713. CheckBillVersion<u_mattress>(cmd, mattress.mattressid, mattress.version);
  2714. }
  2715. InitMattressExtra(mattress.mxList, mattress.extraList);
  2716. }
  2717. /// <summary>
  2718. /// 初始化床垫保存自动生成特殊工艺
  2719. /// </summary>
  2720. /// <param name="mxlist"></param>
  2721. /// <param name="extraList"></param>
  2722. public void InitMattressExtra(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_mx_extra> extraList)
  2723. {
  2724. var fuliaoList = mxlist.Where(t => t.formulatype.Value == 2).ToList();
  2725. if (fuliaoList.Count <= 0) return;
  2726. var mtrlList = new List<u_mtrldef>();
  2727. var mtrlids = fuliaoList.Select(t => t.mtrlid.Value).ToList();
  2728. if (mtrlids.Count <= 0) return;
  2729. var selectStr = @"SELECT u_mtrl_price.mtrlid
  2730. ,u_mtrl_price.if_subspecs
  2731. ,u_mtrl_price.extra_cost
  2732. ,u_mtrl_price.name
  2733. FROM u_mtrl_price";
  2734. var list = new List<u_mtrl_price>();
  2735. var whereList = new List<string>();
  2736. var parms = new Dictionary<string, object>();
  2737. whereList.Add($"u_mtrl_price.mtrlid IN {ListEx.getString(mtrlids)}");
  2738. whereList.Add($"u_mtrl_price.extra_cost <> 0");
  2739. var outputFields = "mtrlid,name,if_subspecs,extra_cost";
  2740. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), parms, "mtrlid", outputFields, 0,0, list);
  2741. if(extraList != null && extraList.Count > 0)
  2742. {
  2743. //
  2744. var namelist = list.Select(t => t.name).ToList();
  2745. extraList.RemoveAll(t => !string.IsNullOrEmpty(t.extraname) && namelist.Contains(t.extraname));
  2746. }
  2747. foreach(var mtrl in list)
  2748. {
  2749. var matchItems = fuliaoList
  2750. .Where(t => t != null &&
  2751. !string.IsNullOrEmpty(t.mtrlname) &&
  2752. !string.IsNullOrEmpty(mtrl.name) && t.mtrlname.Trim() == mtrl.name.Trim()).ToList();
  2753. var extra = new u_mattress_mx_extra()
  2754. {
  2755. extraid = 5,
  2756. extramxid = 0,
  2757. extraname = mtrl.name,
  2758. mattressid = 0,
  2759. mattressmxid = 0,
  2760. price = mtrl.extra_cost,
  2761. qty = 0,
  2762. dscrp = "",
  2763. mtrlid = mtrl.mtrlid,
  2764. typeid = 1,
  2765. inputtype = 1
  2766. };
  2767. foreach (var mx in matchItems)
  2768. {
  2769. extra.mattressid = mx.mattressid;
  2770. extra.mattressmxid = mx.mattressmxid;
  2771. extra.qty += mx.qty;
  2772. }
  2773. extraList.Add(extra);
  2774. }
  2775. }
  2776. #endregion
  2777. #region 公式计算通用方法
  2778. private void AddKeyValue(string key, object value, bool isReplace = true)
  2779. {
  2780. key = $"【{key}】";
  2781. if (!replacements.ContainsKey(key))
  2782. {
  2783. replacements.Add(key, value);
  2784. }
  2785. else if (isReplace)
  2786. {
  2787. replacements[key] = value;
  2788. }
  2789. }
  2790. private void AddFormulaKeyValue(string key, string value, bool isReplace = true)
  2791. {
  2792. key = $"【{key}】";
  2793. if (!formula_replacements.ContainsKey(key))
  2794. {
  2795. formula_replacements.Add(key, value);
  2796. }
  2797. else if (isReplace)
  2798. {
  2799. formula_replacements[key] = value;
  2800. }
  2801. }
  2802. /// <summary>
  2803. /// 记录隐藏公式
  2804. /// </summary>
  2805. /// <param name="key"></param>
  2806. /// <param name="value"></param>
  2807. /// <param name="isReplace"></param>
  2808. private void AddFormulaHideKeyValue(string key, string value, bool isReplace = true)
  2809. {
  2810. key = $"【{key}】";
  2811. if (!formula_replacements_hide.ContainsKey(key))
  2812. {
  2813. formula_replacements_hide.Add(key, value);
  2814. }
  2815. else if (isReplace)
  2816. {
  2817. formula_replacements_hide[key] = value;
  2818. }
  2819. }
  2820. private string ConvertToEnglishSymbols(string input)
  2821. {
  2822. input = input.Replace("(", "(")
  2823. .Replace(")", ")")
  2824. .Replace(",", ",")
  2825. .Replace("。", ".")
  2826. .Replace(":", ":")
  2827. .Replace(";", ";")
  2828. .Replace("“", "\"")
  2829. .Replace("”", "\"")
  2830. .Replace("‘", "'")
  2831. .Replace("’", "'");
  2832. return input;
  2833. }
  2834. /// <summary>
  2835. /// 变量公式计算
  2836. /// </summary>
  2837. /// <param name="varname"></param>
  2838. /// <returns></returns>
  2839. private TData CalculateVarFormula(string varname)
  2840. {
  2841. varname = $"【{varname}】";
  2842. if (formula_replacements.ContainsKey(varname)) return Calculate(formula_replacements[varname], varname);
  2843. if (formula_replacements_hide.ContainsKey(varname)) return Calculate(formula_replacements_hide[varname], varname);
  2844. return null;
  2845. }
  2846. private void replaceFormulas(ref string expression)
  2847. {
  2848. bool hasReplace = false;
  2849. foreach (var replacement in formula_replacements)
  2850. {
  2851. if (expression.IndexOf(replacement.Key) > -1)
  2852. {
  2853. expression = expression.Replace(replacement.Key, "(" + replacement.Value + ")");
  2854. hasReplace = true;
  2855. }
  2856. }
  2857. foreach (var replacement in formula_replacements_hide)
  2858. {
  2859. if (expression.IndexOf(replacement.Key) > -1)
  2860. {
  2861. expression = expression.Replace(replacement.Key, "(" + replacement.Value + ")");
  2862. hasReplace = true;
  2863. }
  2864. }
  2865. if (hasReplace)
  2866. {
  2867. replaceFormulas(ref expression);
  2868. }
  2869. }
  2870. private void FormatExpression(ref string expression)
  2871. {
  2872. // 替换相互嵌套的公式
  2873. replaceFormulas(ref expression);
  2874. expression = ConvertToEnglishSymbols(expression);
  2875. // 定义正则表达式模式,匹配包含【】的内容
  2876. string pattern = @"【(.*?)】";
  2877. // 创建正则表达式对象
  2878. Regex regex = new Regex(pattern);
  2879. // 使用正则表达式匹配输入字符串
  2880. MatchCollection matches = regex.Matches(expression);
  2881. var new_replacements = new Dictionary<string, object>();
  2882. foreach (System.Text.RegularExpressions.Match match in matches)
  2883. {
  2884. if (replacements.TryGetValue(match.Value, out object value2))
  2885. {
  2886. new_replacements[match.Value] = value2;
  2887. }
  2888. }
  2889. foreach (var replacement in new_replacements)
  2890. {
  2891. expression = expression.Replace(replacement.Key, Convert.ToString(replacement.Value));
  2892. }
  2893. }
  2894. /// <summary>
  2895. /// 公式计算
  2896. /// </summary>
  2897. /// <param name="expression"></param>
  2898. /// <param name="name"></param>
  2899. /// <returns></returns>
  2900. private TData Calculate(string expression, string name = "")
  2901. {
  2902. FormatExpression(ref expression);
  2903. try
  2904. {
  2905. return LJExprParser.Parse(expression).Result;
  2906. }
  2907. catch (Exception ex)
  2908. {
  2909. throw new LJCommonException($"计算{name}公式错误: {ex.Message}");
  2910. }
  2911. }
  2912. /// <summary>
  2913. /// Sql公式计算
  2914. /// </summary>
  2915. /// <param name="expression"></param>
  2916. /// <param name="name"></param>
  2917. /// <returns></returns>
  2918. private object SqlCalculate(string expression, string name = "")
  2919. {
  2920. FormatExpression(ref expression);
  2921. try
  2922. {
  2923. cmd.CommandText = $@"{expression}";
  2924. cmd.Parameters.Clear();
  2925. return cmd.ExecuteScalar();
  2926. }
  2927. catch (Exception ex)
  2928. {
  2929. throw new LJCommonException($"计算{name}公式错误: {ex.Message}");
  2930. }
  2931. }
  2932. #endregion
  2933. #region 导入包装明细
  2934. /// <summary>
  2935. /// 导入 2-按包装方式 的公式
  2936. /// </summary>
  2937. /// <param name="packtype">包装方式</param>
  2938. /// <param name="dw_2">结果导出</param>
  2939. public void wf_import_bz(int packtype, ref List<u_mattress_mx_mtrl> dw_2)
  2940. {
  2941. var selectStr = @"
  2942. SELECT formulaid
  2943. ,formulakind
  2944. ,formulatype
  2945. ,sortcode
  2946. ,if_mtrl
  2947. ,formula
  2948. ,usetype
  2949. ,if_packtype0
  2950. ,if_packtype1
  2951. ,if_packtype2
  2952. ,default_mtrlid
  2953. ,createtime
  2954. ,createby
  2955. ,useformula
  2956. ,gydscrp
  2957. ,mtrltype
  2958. ,default_mtrlid0
  2959. ,default_mtrlid1
  2960. ,default_mtrlid2
  2961. FROM u_mattress_formula";
  2962. var outFields = "formulaid, formulakind, formulatype, sortcode, if_mtrl, formula, usetype, if_packtype0, if_packtype1, if_packtype2, default_mtrlid, createtime, createby, useformula, gydscrp, mtrltype,default_mtrlid0,default_mtrlid1,default_mtrlid2";
  2963. var whereList = new List<string>();
  2964. whereList.Add("u_mattress_formula.formulatype IN (0, 1, 2, 3, 99, 104)");
  2965. whereList.Add("u_mattress_formula.usetype = @usetype");
  2966. var param = new Dictionary<string, object>();
  2967. // 导入 2-按包装方式 的公式
  2968. var mattressFormulaList = new List<u_mattress_formula>();
  2969. param.Clear();
  2970. param.Add("@usetype", 2);
  2971. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "formulatype, sortcode", outFields, 0, 0, mattressFormulaList);
  2972. foreach (var mx in mattressFormulaList)
  2973. {
  2974. if (packtype == 0 && mx.if_packtype0 != 1) continue;
  2975. if (packtype == 1 && mx.if_packtype1 != 1) continue;
  2976. if (packtype == 2 && mx.if_packtype2 != 1) continue;
  2977. var newDw2 = new u_mattress_mx_mtrl();
  2978. AutoInit.AutoInitS(newDw2);
  2979. if (mx.if_mtrl > 1)
  2980. {
  2981. newDw2.addmx = "+";
  2982. newDw2.delmx = "-";
  2983. }
  2984. newDw2.formulatype = mx.formulatype;
  2985. newDw2.if_mtrl = mx.if_mtrl;
  2986. newDw2.formulaid = mx.formulaid;
  2987. newDw2.sortcode = mx.sortcode;
  2988. newDw2.formulakind = mx.formulakind;
  2989. newDw2.formula = mx.formula;
  2990. newDw2.useformula = mx.useformula;
  2991. newDw2.gydscrp = mx.gydscrp;
  2992. newDw2.default_mtrlid = mx.default_mtrlid;
  2993. if(mx.formulatype == 3)
  2994. {
  2995. if(packtype == 0) newDw2.default_mtrlid = mx.default_mtrlid0;
  2996. else if(packtype == 1) newDw2.default_mtrlid = mx.default_mtrlid1;
  2997. else if(packtype == 2) newDw2.default_mtrlid = mx.default_mtrlid2;
  2998. }
  2999. dw_2.Add(newDw2);
  3000. }
  3001. }
  3002. #endregion
  3003. #region 床垫明细排序
  3004. /// <summary>
  3005. /// 明细排序
  3006. /// </summary>
  3007. /// <param name="dw_2"></param>
  3008. public void wf_sort_mx(ref List<u_mattress_mx_mtrl> dw_2)
  3009. {
  3010. // u_mattress_formula_formulatype A xu A u_mattress_formula_sortcode A u_mattress_mx_mtrl_formulaid A
  3011. dw_2.Sort((a, b) =>
  3012. {
  3013. if (a.formulatype != b.formulatype)
  3014. {
  3015. return a.formulatype.Value.CompareTo(b.formulatype.Value);
  3016. }
  3017. if (a.xu != b.xu)
  3018. {
  3019. return a.xu.Value.CompareTo(b.xu.Value);
  3020. }
  3021. if (a.sortcode != b.sortcode)
  3022. {
  3023. return a.sortcode.CompareTo(b.sortcode);
  3024. }
  3025. int result = GetFormulakindOrder(a.formulakind).CompareTo(GetFormulakindOrder(b.formulakind));
  3026. if (result != 0)
  3027. {
  3028. return result;
  3029. }
  3030. return a.formulaid.Value.CompareTo(b.formulaid.Value);
  3031. });
  3032. }
  3033. public List<u_mattress_mx_mtrl> SortMxList(List<u_mattress_mx_mtrl> mxlist)
  3034. {
  3035. return mxlist.OrderBy(x => x.formulatype)
  3036. .ThenBy(x => x.xu)
  3037. .ThenBy(x => x.sortcode)
  3038. .ThenBy(x => GetFormulakindOrder(x.formulakind))
  3039. .ThenBy(x => x.formulaid)
  3040. .ToList();
  3041. }
  3042. #endregion
  3043. #region 显示报价清单
  3044. public void ShowQuoteList(int mattressid)
  3045. {
  3046. }
  3047. #endregion
  3048. // 普通大侧特殊排序
  3049. private int GetFormulakindOrder(int? formulakind)
  3050. {
  3051. switch (formulakind)
  3052. {
  3053. case 2: return 1;
  3054. case 82: return 2;
  3055. case 42: return 3;
  3056. case 52: return 4;
  3057. case 62: return 5;
  3058. case 72: return 6;
  3059. default: return int.MaxValue;
  3060. }
  3061. }
  3062. #region 获取物料信息
  3063. public void wf_mtrl_fine(List<int> arg_mtrlid, int arg_pricelistid, ref List<u_mtrl_price> mtrlList)
  3064. {
  3065. var selectStr = @"
  3066. SELECT
  3067. u_mtrl_price.mtrlid,
  3068. u_mtrl_price.name,
  3069. isnull(u_mtrl_price_pricelist.price,0) as price,
  3070. u_mtrl_price.gram_weight,
  3071. u_mtrl_price.cloth_width,
  3072. u_mtrl_price.if_inputqty,
  3073. u_mtrl_price.priceunit,
  3074. u_mtrl_price.shrinkage,
  3075. isnull(u_mtrl_price_pricelist.price_formula,0) as price_formula,
  3076. isnull(u_mtrl_price_pricelist.qty_formula,0) as qty_formula,
  3077. u_mtrl_price.if_areaprice,
  3078. u_mtrl_price.thickness
  3079. FROM u_mtrl_price inner join u_mtrl_price_pricelist on
  3080. u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid";
  3081. var outFields = "mtrlid, name, price, gram_weight, cloth_width, if_inputqty, priceunit, shrinkage, price_formula, qty_formula, if_areaprice, thickness";
  3082. var whereList = new List<string>();
  3083. whereList.Add("u_mtrl_price.mtrlid IN (" + string.Join(",", arg_mtrlid) + ")");
  3084. whereList.Add("u_mtrl_price_pricelist.pricelistid = @arg_pricelistid");
  3085. var param = new Dictionary<string, object>();
  3086. param.Clear();
  3087. param.Add("@arg_pricelistid", arg_pricelistid);
  3088. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "", outFields, 0, 0, mtrlList);
  3089. }
  3090. #endregion
  3091. #region 获取包装默认物料
  3092. /// <summary>
  3093. /// 获取包装默认物料
  3094. /// </summary>
  3095. /// <param name="dw_2"></param>
  3096. public void wf_default_mtrlid(int pricelistid, ref List<u_mattress_mx_mtrl> dw_2)
  3097. {
  3098. // 导入 2-按包装方式 的公式
  3099. var mtrlPriceList = new List<u_mtrl_price>();
  3100. var mtrlids = new List<int>();
  3101. List<int> uniqueMtrlIds = new HashSet<int>(dw_2.Select(obj => obj.default_mtrlid.Value)).ToList();
  3102. wf_mtrl_fine(uniqueMtrlIds, pricelistid, ref mtrlPriceList);
  3103. foreach (var mx in dw_2)
  3104. {
  3105. var _mtrlid = mx.default_mtrlid;
  3106. if(_mtrlid == null || _mtrlid == 0)
  3107. {
  3108. if (mx.formulakind == 16)
  3109. {
  3110. //默认 pe kind = 16 默认 10C PE袋 mtrlid 46804
  3111. _mtrlid = 46804;
  3112. }
  3113. else if (mx.formulakind == 17)
  3114. {
  3115. //默认 外层pe kind = 17 默认 20C mtrlid 46809
  3116. _mtrlid = 46809;
  3117. }
  3118. else if (mx.formulakind == 18)
  3119. {
  3120. //默认 pvc kind = 18 默认 15C mtrlid 46811
  3121. _mtrlid = 46811;
  3122. }
  3123. else if (mx.formulakind == 19)
  3124. {
  3125. //默认 卷包外包装 kind = 19 默认 彩箱 32*32 46817
  3126. _mtrlid = 46817;
  3127. }
  3128. else if (mx.formulakind == 27)
  3129. {
  3130. //默认 拉手脚轮 kind = 27 默认 46872
  3131. _mtrlid = 46872;
  3132. }
  3133. }
  3134. var mtrlItm = mtrlPriceList.Where((itm) => itm.mtrlid == _mtrlid).ToList();
  3135. if (mtrlItm.Count > 0)
  3136. {
  3137. mx.mtrlid = mtrlItm[0].mtrlid;
  3138. mx.mtrlname = mtrlItm[0].name;
  3139. mx.price = mtrlItm[0].price;
  3140. mx.gram_weight = mtrlItm[0].gram_weight;
  3141. mx.cloth_width = mtrlItm[0].cloth_width;
  3142. mx.if_inputqty = mtrlItm[0].if_inputqty;
  3143. mx.priceunit = mtrlItm[0].priceunit;
  3144. mx.shrinkage = mtrlItm[0].shrinkage;
  3145. mx.qty = 1;
  3146. if (!string.IsNullOrEmpty(mtrlItm[0].price_formula)) mx.formula = mtrlItm[0].price_formula;
  3147. }
  3148. }
  3149. }
  3150. #endregion
  3151. #region 获取非包装默认物料
  3152. /// <summary>
  3153. /// 获取非包装默认物料
  3154. /// </summary>
  3155. /// <param name="dw_2"></param>
  3156. public void wf_default_mtrlid_notbz(int pricelistid, ref List<u_mattress_mx_mtrl> dw_2)
  3157. {
  3158. foreach (var mx in dw_2)
  3159. {
  3160. var matterssformula = new u_mattress_formula() { formulaid = mx.formulaid };
  3161. if (DbSqlHelper.SelectOne(cmd, matterssformula, "default_mtrlid") != 1 || matterssformula.default_mtrlid.Value == 0) continue;
  3162. // 导入 2-按包装方式 的公式
  3163. var mtrlItm = new List<u_mtrl_price>();
  3164. wf_mtrl_fine(new List<int> { matterssformula.default_mtrlid.Value }, pricelistid, ref mtrlItm);
  3165. if (mtrlItm.Count > 0)
  3166. {
  3167. mx.mtrlid = mtrlItm[0].mtrlid;
  3168. mx.mtrlname = mtrlItm[0].name;
  3169. mx.price = mtrlItm[0].price;
  3170. mx.gram_weight = mtrlItm[0].gram_weight;
  3171. mx.cloth_width = mtrlItm[0].cloth_width;
  3172. mx.if_inputqty = mtrlItm[0].if_inputqty;
  3173. mx.priceunit = mtrlItm[0].priceunit;
  3174. mx.shrinkage = mtrlItm[0].shrinkage;
  3175. mx.qty = 1;
  3176. if (!string.IsNullOrEmpty(mtrlItm[0].price_formula)) mx.formula = mtrlItm[0].price_formula;
  3177. }
  3178. }
  3179. }
  3180. #endregion
  3181. #region 大小单类型枚举
  3182. public enum DannumType
  3183. {
  3184. /// <summary>
  3185. /// 散单
  3186. /// </summary>
  3187. Scattered = 1,
  3188. /// <summary>
  3189. /// 标准
  3190. /// </summary>
  3191. Standard = 2,
  3192. /// <summary>
  3193. /// 大单
  3194. /// </summary>
  3195. Large = 3,
  3196. /// <summary>
  3197. /// 小单
  3198. /// </summary>
  3199. Small = 4
  3200. }
  3201. public static string BillKeyWord = BillNames.MattressQuote;
  3202. #endregion
  3203. }
  3204. }