MattressHelper.cs 162 KB

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