MattressHelper.cs 159 KB

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