MattressHelper.cs 160 KB

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