MattressHelper.cs 159 KB

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