MattressHelper.cs 159 KB

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