CartViewController.m 245 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345
  1. //
  2. // CartViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-6.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RAUtils.h"
  9. #import "CartViewController.h"
  10. #ifdef BUILD_CONTRAST
  11. #import "ContrastModelItemCell.h"
  12. #else
  13. #import "ModelItemCell.h"
  14. #endif
  15. #import "RANetwork.h"
  16. //#import "CommonGridViewController.h"
  17. #import "CreateOrderViewController.h"
  18. #import "DetailViewController.h"
  19. #import "EditModelPriceViewController.h"
  20. #import "MainViewController.h"
  21. #import "LoginViewController.h"
  22. #import "ItemNotesViewController.h"
  23. #import "CartGeneralNotesViewController.h"
  24. #import "DefaultAppearance.h"
  25. #import "DefaultTableHeaderView.h"
  26. #import "SortItemViewController.h"
  27. #import "SortButton.h"
  28. #import "NotificationNameCenter.h"
  29. #import "RASingleton.h"
  30. #import "JKMessageBoxController.h"
  31. #import "RAPDFViewController.h"
  32. #ifdef SCANNER_ORDER
  33. #import "ScanCartItemCell.h"
  34. #import "ScanDiscountViewController.h"
  35. #else
  36. #endif
  37. #ifdef BUILD_CONTRAST
  38. #import "OrderDiscountViewController.h"
  39. #endif
  40. #ifdef BACKORDER_PROCESS
  41. #import "RAOrderEditorViewController.h"
  42. #endif
  43. #import "CustomerEditViewController.h"
  44. //#define ALERT_FREE 1024
  45. //#define ALERT_DEL 1025
  46. //#define ALERT_SET_FREE 1026
  47. //#define ALERT_RESTORE_FREE 1027
  48. @interface CartViewController ()
  49. {
  50. CGRect cancelButtonFrame;
  51. }
  52. @property (nonatomic,strong) SortItemViewController *sortItemController;
  53. @property (nonatomic,assign) int sortIndex;
  54. @property (nonatomic,strong) SortButton *sortButton;
  55. @property (strong, nonatomic) IBOutlet UIButton *placeOrderButton;
  56. @property (strong, nonatomic) IBOutlet UIButton *cancelOrderButton;
  57. @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
  58. @property (strong, nonatomic) IBOutlet UIButton *emailButton;
  59. @property (strong, nonatomic) IBOutlet UIButton *printButton;
  60. @property (weak, nonatomic) IBOutlet UIButton *editButton;
  61. @property (weak, nonatomic) IBOutlet UIButton *continueButton;
  62. @property (weak, nonatomic) IBOutlet UILabel *labelTotalcuft;
  63. @property (weak, nonatomic) IBOutlet UILabel *labelTotalWeight;
  64. @property (weak, nonatomic) IBOutlet UILabel *labelTotalCarton;
  65. @property (weak, nonatomic) IBOutlet UILabel *valuecuft;
  66. @property (weak, nonatomic) IBOutlet UILabel *valueweight;
  67. @property (weak, nonatomic) IBOutlet UILabel *valuecarton;
  68. @property (nonatomic,assign) BOOL currentOrderIsMerged;
  69. @property (nonatomic,strong) DefaultTableHeaderView *cartIndicatorBar;
  70. @property (nonatomic,assign) BOOL back_order_flag;
  71. @property (nonatomic,strong) NSDictionary *cart_json;
  72. @property (nonatomic,copy) NSString *print_url;
  73. @property (nonatomic,assign) BOOL available;///<所有Model均有库存,才能Place Order。
  74. @end
  75. @implementation CartViewController
  76. - (NSOperationQueue *)dataOperationQueue {
  77. if (!_dataOperationQueue) {
  78. _dataOperationQueue = [[NSOperationQueue alloc] init];
  79. _dataOperationQueue.maxConcurrentOperationCount = 1;
  80. }
  81. return _dataOperationQueue;
  82. }
  83. - (void)dealloc {
  84. #ifndef RA_NOTIFICATION
  85. [[NSNotificationCenter defaultCenter] removeObserver:self];
  86. #endif
  87. }
  88. -(void) logout
  89. {
  90. [super logout];
  91. [self.content_arr removeAllObjects];
  92. [self refresh_ui];
  93. self.cart_json = nil;
  94. }
  95. - (IBAction)OnEditSelectClick:(id)sender {
  96. NSMutableArray* arr_ids = [[NSMutableArray alloc] init];
  97. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  98. if(count==0)
  99. {
  100. [RAUtils message_alert:@"No item in the cart" title:@"Cart" controller:self] ;
  101. return;
  102. }
  103. for(int i=0;i<count;i++)
  104. {
  105. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  106. [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  107. }
  108. NSString * ids = [arr_ids componentsJoinedByString:@","];
  109. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select all model and" message:nil preferredStyle:UIAlertControllerStyleAlert];
  110. //block代码块取代了delegate
  111. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  112. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove all models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  113. //block代码块取代了delegate
  114. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  115. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Models From Cart" completion:^{
  116. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  117. NSMutableDictionary* cart_json =result;
  118. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  119. [waitalert dismissViewControllerAnimated:YES completion:^{
  120. if([[cart_json valueForKey:@"result"] intValue]==2)
  121. {
  122. [self end_edit];
  123. #ifdef RA_NOTIFICATION
  124. [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  125. #else
  126. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  127. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  128. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  129. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  130. #endif
  131. }
  132. else
  133. {
  134. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  135. }
  136. }];
  137. }];
  138. }];
  139. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  140. //
  141. // NSDictionary* cart_json = [RANetwork cart_remove:ids];
  142. //
  143. // dispatch_async(dispatch_get_main_queue(), ^{
  144. //
  145. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  146. //
  147. // if([[cart_json valueForKey:@"result"] intValue]==2)
  148. // {
  149. //
  150. // [self end_edit];
  151. //
  152. //
  153. //
  154. //#ifdef RA_NOTIFICATION
  155. // [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  156. //#else
  157. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  158. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  159. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  160. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  161. //#endif
  162. // }
  163. // else
  164. // {
  165. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  166. // }
  167. //
  168. //
  169. //
  170. // });
  171. // });
  172. }];
  173. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  174. DebugLog(@"No");
  175. }];
  176. [alertControl addAction:actionOne];
  177. [alertControl addAction:alertthree];
  178. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  179. [self presentViewController:alertControl animated:YES completion:nil];
  180. DebugLog(@"%@",self.edit_select_arr);
  181. }];
  182. UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Move To Wish List" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  183. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move Models To Wish List" completion:^{
  184. [RANetwork request_move_cart2wish:ids completionHandler:^(NSMutableDictionary *result) {
  185. NSDictionary* cart_json =result;
  186. [waitalert dismissViewControllerAnimated:YES completion:^{
  187. if([[cart_json valueForKey:@"result"] intValue]==2)
  188. {
  189. #ifdef RA_NOTIFICATION
  190. [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  191. #else
  192. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  193. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  194. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  195. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  196. #endif
  197. [self end_edit];
  198. }
  199. else
  200. {
  201. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move Models To Wish List" controller:self] ;
  202. }
  203. }];
  204. }];
  205. }];
  206. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  207. //
  208. // NSDictionary* cart_json = [RANetwork move_cart2wish:ids];
  209. //
  210. // dispatch_async(dispatch_get_main_queue(), ^{
  211. //
  212. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  213. //
  214. // if([[cart_json valueForKey:@"result"] intValue]==2)
  215. // {
  216. //
  217. //
  218. //
  219. //
  220. //#ifdef RA_NOTIFICATION
  221. // [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  222. //#else
  223. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  224. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  225. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  226. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  227. //#endif
  228. //
  229. //
  230. // [self end_edit];
  231. // }
  232. // else
  233. // {
  234. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move Models To Wish List" controller:self] ;
  235. // }
  236. //
  237. //
  238. //
  239. // });
  240. // });
  241. }];
  242. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  243. DebugLog(@"No");
  244. }];
  245. [alertControl addAction:actionOne];
  246. [alertControl addAction:actionTwo];
  247. [alertControl addAction:alertthree];
  248. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  249. [self presentViewController:alertControl animated:YES completion:nil];
  250. DebugLog(@"%@",self.edit_select_arr);
  251. }
  252. - (IBAction)onEditAddWishClick:(id)sender {
  253. if(self.edit_select_arr.count==0)
  254. {
  255. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Move To Wish List" controller:self] ;
  256. return;
  257. }
  258. NSString * ids = [self.edit_select_arr componentsJoinedByString:@","];
  259. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove selected models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  260. // //block代码块取代了delegate
  261. //
  262. //
  263. //
  264. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  265. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move Models To Wish List" completion:^{
  266. [RANetwork request_move_cart2wish:ids completionHandler:^(NSMutableDictionary *result) {
  267. NSDictionary* cart_json = result;
  268. [waitalert dismissViewControllerAnimated:YES completion:^{
  269. if([[cart_json valueForKey:@"result"] intValue]==2)
  270. {
  271. [self end_edit];
  272. #ifdef RA_NOTIFICATION
  273. [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  274. #else
  275. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  276. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  277. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  278. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  279. #endif
  280. }
  281. else
  282. {
  283. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  284. }
  285. }];
  286. }];
  287. }];
  288. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  289. //
  290. // NSDictionary* cart_json = [RANetwork move_cart2wish:ids];
  291. //
  292. // dispatch_async(dispatch_get_main_queue(), ^{
  293. //
  294. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  295. //
  296. // if([[cart_json valueForKey:@"result"] intValue]==2)
  297. // {
  298. //
  299. // [self end_edit];
  300. //
  301. //#ifdef RA_NOTIFICATION
  302. // [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  303. //#else
  304. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  305. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  306. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  307. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  308. //#endif
  309. //
  310. // }
  311. // else
  312. // {
  313. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  314. // }
  315. //
  316. //
  317. //
  318. // });
  319. // });
  320. // }];
  321. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  322. // DebugLog(@"No");
  323. // }];
  324. // [alertControl addAction:actionOne];
  325. //
  326. // [alertControl addAction:alertthree];
  327. //
  328. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  329. //
  330. //
  331. // [self presentViewController:alertControl animated:YES completion:nil];
  332. //
  333. // DebugLog(@"%@",self.edit_select_arr);
  334. }
  335. - (IBAction)onEditDelClick:(id)sender {
  336. if(self.edit_select_arr.count==0)
  337. {
  338. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Delete From Cart" controller:self] ;
  339. return;
  340. }
  341. NSString * ids = [self.edit_select_arr componentsJoinedByString:@","];
  342. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove selected models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  343. //block代码块取代了delegate
  344. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  345. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Models From Cart" completion:^{
  346. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  347. NSMutableDictionary* cart_json =result;
  348. [waitalert dismissViewControllerAnimated:YES completion:^{
  349. if([[cart_json valueForKey:@"result"] intValue]==2)
  350. {
  351. [self end_edit];
  352. #ifdef RA_NOTIFICATION
  353. [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  354. #else
  355. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  356. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  357. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  358. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  359. #endif
  360. }
  361. else
  362. {
  363. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  364. }
  365. }];
  366. }];
  367. }];
  368. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  369. //
  370. // NSDictionary* cart_json = [RANetwork cart_remove:ids];
  371. //
  372. // dispatch_async(dispatch_get_main_queue(), ^{
  373. //
  374. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  375. //
  376. // if([[cart_json valueForKey:@"result"] intValue]==2)
  377. // {
  378. //
  379. // [self end_edit];
  380. //
  381. //
  382. //#ifdef RA_NOTIFICATION
  383. // [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  384. //#else
  385. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  386. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  387. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  388. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  389. //#endif
  390. // }
  391. // else
  392. // {
  393. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  394. // }
  395. //
  396. //
  397. //
  398. // });
  399. // });
  400. }];
  401. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  402. DebugLog(@"No");
  403. }];
  404. [alertControl addAction:actionOne];
  405. [alertControl addAction:alertthree];
  406. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  407. [self presentViewController:alertControl animated:YES completion:nil];
  408. DebugLog(@"%@",self.edit_select_arr);
  409. }
  410. - (IBAction)onEndEditClick:(id)sender {
  411. [self end_edit];
  412. }
  413. -(void)begin_edit
  414. {
  415. self.toolpanel.hidden = true;
  416. self.toolbar.hidden = false;
  417. // DebugLog(@"begin edit %@",NSStringFromCGRect(self.cartItemView.frame));
  418. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  419. if ( UIInterfaceOrientationIsPortrait(orientation))
  420. self.cartItemView.frame = CGRectMake(0,40,768,840);
  421. else
  422. self.cartItemView.frame = CGRectMake(0,40,1024,584);
  423. [self.itemListTable setEditing:true animated:YES];
  424. [self.itemListTable reloadData];
  425. }
  426. -(void) end_edit
  427. {
  428. self.toolpanel.hidden=false;
  429. self.toolbar.hidden=true;
  430. // DebugLog(@"end edit %@",NSStringFromCGRect(self.cartItemView.frame));
  431. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  432. if ( UIInterfaceOrientationIsPortrait(orientation))
  433. self.cartItemView.frame = CGRectMake(0,40,768,760);
  434. else
  435. self.cartItemView.frame = CGRectMake(0,40,1024,508);
  436. [self.itemListTable setEditing:false animated:YES];
  437. [self.edit_select_arr removeAllObjects];
  438. [self.itemListTable reloadData];
  439. // [self reload_data];
  440. }
  441. - (IBAction)onEditClick:(id)sender {
  442. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  443. //
  444. // [appDelegate test_onDecodedDataResult:@"4400022"];
  445. //
  446. //
  447. // return;
  448. [self begin_edit];
  449. }
  450. #ifndef RA_NOTIFICATION
  451. -(void) reload_container_getdata:(bool) update_data
  452. {
  453. [super reload_container_getdata:update_data];
  454. if(update_data)
  455. [self reload_data];
  456. else
  457. {
  458. [self.itemListTable reloadData];
  459. [self refresh_total];
  460. }
  461. }
  462. #endif
  463. -(void) showHidePrice
  464. {
  465. #ifndef RA_NOTIFICATION
  466. [self reload_container_getdata:false];
  467. #endif
  468. // [self refresh_total];
  469. }
  470. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  471. {
  472. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  473. if (self) {
  474. // Custom initialization
  475. }
  476. return self;
  477. }
  478. - (IBAction)imgbtnClick:(UIButton *)sender {
  479. #ifdef SCANNER_ORDER
  480. return;
  481. #endif
  482. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  483. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  484. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  485. NSDictionary * item_json = nil;
  486. if (self.back_order_flag) {
  487. item_json = [self itemJsonAtIndexPath:indexPath];
  488. } else {
  489. item_json = self.content_arr[indexPath.row];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  490. }
  491. NSString* product_id = [item_json valueForKey:@"product_id"];
  492. NSString *name = [item_json valueForKey:@"model"];
  493. int is_rate = [item_json[@"is_rate"] intValue];
  494. if(is_rate==1)
  495. return;
  496. DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  497. // dvc
  498. dvc.product_id=product_id;
  499. dvc.category_id=nil;
  500. dvc.ispush=true;
  501. dvc.model_name = name;
  502. [dvc reload];
  503. [self.navigationController pushViewController:dvc animated:true];
  504. }
  505. -(void)viewWillLayoutSubviews
  506. {
  507. // if(self.showDetail==true)
  508. // {
  509. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  510. // int width=175;
  511. // // int height;
  512. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  513. // {
  514. // width = 370;
  515. // // height = 400;
  516. // }
  517. // else
  518. // {
  519. // // height = 300;
  520. // width = 175;
  521. // }
  522. //
  523. //
  524. // CGRect frame = CGRectMake(0, 64, width, self.view.bounds.size.height-64);
  525. //
  526. // self.collectionview.frame=frame;
  527. //
  528. //
  529. //
  530. // CGRect framedetail = CGRectMake(width,64 ,self.view.bounds.size.width-width,self.view.bounds.size.height-64);
  531. // self.detailView.frame = framedetail;
  532. // }
  533. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  534. // self.collectionview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.collectionview.bounds].CGPath;
  535. }
  536. - (void)viewWillAppear:(BOOL)animated
  537. {
  538. [super viewWillAppear:animated];
  539. // print 13 email 19 cancel 24 place order
  540. // Shop 权限检查
  541. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  542. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  543. if (![RASingleton sharedInstance].permissions_edit_order) {
  544. CGRect frame0 = self.cancelOrderButton.frame;
  545. CGRect frame1 = self.placeOrderButton.frame;
  546. CGRect frame2 = self.emailButton.frame;
  547. CGRect frame3 = self.printButton.frame;
  548. CGFloat x = CGRectGetMaxX(frame1) - frame0.size.width;
  549. frame0.origin.x = x;
  550. self.cancelOrderButton.frame = frame0;
  551. x -= 20 + CGRectGetWidth(frame2);
  552. frame2.origin.x = x;
  553. self.emailButton.frame = frame2;
  554. x -= 20 + CGRectGetWidth(frame3);
  555. frame3.origin.x = x;
  556. self.printButton.frame = frame3;
  557. self.placeOrderButton.hidden = YES;
  558. } else {
  559. self.placeOrderButton.hidden = NO;
  560. CGSize size = cancelButtonFrame.size;
  561. CGFloat x = CGRectGetMinX(self.placeOrderButton.frame) - 24 - size.width;
  562. CGFloat y = CGRectGetMinY(self.placeOrderButton.frame);
  563. self.cancelOrderButton.frame = CGRectMake(x, y, size.width, size.height);
  564. CGRect frame2 = self.emailButton.frame;
  565. x -= 20 + CGRectGetWidth(frame2);
  566. frame2.origin.x = x;
  567. self.emailButton.frame = frame2;
  568. CGRect frame3 = self.printButton.frame;
  569. x -= 20 + CGRectGetWidth(frame3);
  570. frame3.origin.x = x;
  571. self.printButton.frame = frame3;
  572. }
  573. } else {
  574. // self.cancelOrderButton.frame = cancelButtonFrame;
  575. self.placeOrderButton.hidden = NO;
  576. CGSize size = cancelButtonFrame.size;
  577. CGFloat x = CGRectGetMinX(self.placeOrderButton.frame) - 24 - size.width;
  578. CGFloat y = CGRectGetMinY(self.placeOrderButton.frame);
  579. self.cancelOrderButton.frame = CGRectMake(x, y, size.width, size.height);
  580. CGRect frame2 = self.emailButton.frame;
  581. x -= 20 + CGRectGetWidth(frame2);
  582. frame2.origin.x = x;
  583. self.emailButton.frame = frame2;
  584. CGRect frame3 = self.printButton.frame;
  585. x -= 20 + CGRectGetWidth(frame3);
  586. frame3.origin.x = x;
  587. self.printButton.frame = frame3;
  588. }
  589. #ifdef OFFLINE_MODE
  590. // 离线隐藏Email
  591. self.emailButton.hidden = appDelegate.offline_mode;
  592. // 离线隐藏Print
  593. self.printButton.hidden = appDelegate.offline_mode;
  594. #endif
  595. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  596. #ifdef SCANNER_ORDER
  597. if(appDelegate.user_type == USER_ROLE_EMPLOYEE)
  598. {
  599. self.btnBulkDiscount.hidden = false;
  600. }
  601. else
  602. self.btnBulkDiscount.hidden = true;
  603. #endif
  604. }
  605. - (void)checkProductAvailable:(NSArray *)contents {
  606. if (contents == nil) {
  607. self.available = NO;
  608. return;
  609. }
  610. [contents enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  611. if ([obj isKindOfClass:[NSDictionary class]]) {
  612. NSDictionary *item_json = (NSDictionary *)obj;
  613. BOOL isAvailable = ![[item_json valueForKey:@"is_out_of_stock"] boolValue];
  614. self.available = self.available && isAvailable;
  615. }
  616. }];
  617. }
  618. - (void)clearContent {
  619. dispatch_async(dispatch_get_main_queue(), ^{
  620. self.freejson = nil;
  621. self.notes = nil;
  622. self.content_arr = nil;
  623. self.currentOrderIsMerged = nil;
  624. self.cart_json = nil;
  625. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  626. self.print_url = nil;
  627. [self checkProductAvailable:self.content_arr];
  628. [self refresh_total];
  629. [self.itemListTable reloadData];
  630. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  631. appDelegate.cart_count = 0;
  632. [appDelegate update_count_mark];
  633. });
  634. }
  635. -(void) operation_reload_data
  636. {
  637. if (self.dataOperationQueue.operationCount > 1) {
  638. NSLog(@"operationCount >1 cancel");
  639. return;
  640. }
  641. NSLog(@"operating...");
  642. __block AppDelegate *appDelegate = nil;
  643. dispatch_sync(dispatch_get_main_queue(), ^{
  644. //some UI methods ej
  645. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  646. });
  647. // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  648. #ifndef SCANNER_ORDER
  649. //扫码订单允许后建订单
  650. if (appDelegate.order_code == nil || appDelegate.order_code.length == 0) {
  651. [self clearContent];
  652. return;
  653. }
  654. #endif
  655. __weak typeof(self) weakself = self;
  656. dispatch_async(dispatch_get_main_queue(), ^{
  657. if(weakself.isrefreshing)
  658. return;
  659. weakself.available = YES;
  660. weakself.itemListTable.hidden = true;
  661. weakself.label_net_err.hidden=true;
  662. weakself.isrefreshing=true;
  663. // [self.content_data removeAllObjects];
  664. // [self.itemListTable reloadData];
  665. // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  666. //
  667. // [reF endRefreshing];
  668. //
  669. // reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  670. weakself.mum.center = weakself.view.center;
  671. weakself.mum.hidden = YES;
  672. // [self.mum startAnimating];
  673. DebugLog(@"reloading...");
  674. __block UIAlertController *loadingView = [RAUtils waiting_alert:self title:@"Loading" completion:^{
  675. [RANetwork request_cart:weakself.sortIndex completionHandler:^(NSMutableDictionary *result) {
  676. DebugLog(@"BEGIN LOAD CART");
  677. NSDictionary* cart_json = result;
  678. //
  679. // [self.mum stopAnimating];
  680. [loadingView dismissViewControllerAnimated:YES completion:^{
  681. // [loadingView dismissWithClickedButtonIndex:0 animated:YES];
  682. // self.content_data = [cart_json mutableCopy];
  683. #ifdef BACKORDER_PROCESS
  684. weakself.back_order_flag = [[cart_json objectForKey:@"back_order_version"] boolValue];
  685. #else
  686. weakself.back_order_flag = NO;
  687. #endif
  688. if (!weakself.back_order_flag) {
  689. weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  690. weakself.notes = [cart_json valueForKey:@"general_note"];
  691. weakself.content_arr = [RAUtils dictionary2array:cart_json count_fields:@"count" item_mark:@"item_" items_mark:nil];
  692. weakself.currentOrderIsMerged = [[cart_json valueForKey:@"is_merged_order"] boolValue];
  693. [RASingleton sharedInstance].currentOrderIsMerged = weakself.currentOrderIsMerged;
  694. [weakself.itemListTable reloadData];
  695. weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  696. [weakself checkProductAvailable:weakself.content_arr];
  697. [weakself refresh_total];
  698. } else {
  699. // v1.94
  700. weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  701. weakself.notes = [cart_json valueForKey:@"general_note"];
  702. weakself.cart_json = cart_json;
  703. [weakself.itemListTable reloadData];
  704. weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  705. [weakself checkProductAvailable:weakself.content_arr];
  706. }
  707. int result_code=[[cart_json valueForKey:@"result"] intValue];
  708. if (weakself.dataOperationQueue.operationCount > 1) {
  709. weakself.isrefreshing=false;
  710. return;
  711. }
  712. if(result_code==2||result_code==1||result_code==0)
  713. {
  714. [weakself.edit_select_arr removeAllObjects];
  715. weakself.itemListTable.hidden = false;
  716. // UIApplication * app = [UIApplication sharedApplication];
  717. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  718. // appDelegate.cart_count =weakself.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  719. weakself.itemListTable.hidden=false;
  720. if(weakself.onFinishLoad)
  721. weakself.onFinishLoad();
  722. }
  723. else
  724. if(result_code==RESULT_NET_ERROR)
  725. {
  726. weakself.label_net_err.hidden=false;
  727. weakself.itemListTable.hidden=true;
  728. }
  729. else
  730. {
  731. if(result_code!=1)
  732. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Cart" controller:weakself] ;
  733. }
  734. weakself.isrefreshing=false;
  735. DebugLog(@"FINISH LOAD CART");
  736. }];
  737. }];
  738. }];
  739. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  740. // DebugLog(@"BEGIN LOAD CART");
  741. // NSDictionary* cart_json = [RANetwork request_Cart:weakself.sortIndex];
  742. //
  743. // dispatch_async(dispatch_get_main_queue(), ^{
  744. // //
  745. //// [self.mum stopAnimating];
  746. // [loadingView dismissWithClickedButtonIndex:0 animated:YES];
  747. //
  748. // // self.content_data = [cart_json mutableCopy];
  749. //#ifdef BACKORDER_PROCESS
  750. // weakself.back_order_flag = [[cart_json objectForKey:@"back_order_version"] boolValue];
  751. //#else
  752. // weakself.back_order_flag = NO;
  753. //#endif
  754. //
  755. // if (!weakself.back_order_flag) {
  756. // weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  757. // weakself.notes = [cart_json valueForKey:@"general_note"];
  758. // weakself.content_arr = [RAUtils dictionary2array:cart_json count_fields:@"count" item_mark:@"item_" items_mark:nil];
  759. // weakself.currentOrderIsMerged = [[cart_json valueForKey:@"is_merged_order"] boolValue];
  760. // [Singleton sharedInstance].currentOrderIsMerged = weakself.currentOrderIsMerged;
  761. // [weakself.itemListTable reloadData];
  762. // weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  763. //
  764. //
  765. // [weakself checkProductAvailable:weakself.content_arr];
  766. //
  767. //
  768. // [weakself refresh_total];
  769. // } else {
  770. // // v1.94
  771. // weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  772. // weakself.notes = [cart_json valueForKey:@"general_note"];
  773. // weakself.cart_json = cart_json;
  774. // [weakself.itemListTable reloadData];
  775. // weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  776. // [weakself checkProductAvailable:weakself.content_arr];
  777. // }
  778. //
  779. // int result=[[cart_json valueForKey:@"result"] intValue];
  780. //
  781. // if (weakself.dataOperationQueue.operationCount > 1) {
  782. // weakself.isrefreshing=false;
  783. // return;
  784. // }
  785. //
  786. // if(result==2||result==1||result==0)
  787. // {
  788. //
  789. // [weakself.edit_select_arr removeAllObjects];
  790. //
  791. // weakself.itemListTable.hidden = false;
  792. //// UIApplication * app = [UIApplication sharedApplication];
  793. //// AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  794. //// appDelegate.cart_count =weakself.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  795. // weakself.itemListTable.hidden=false;
  796. // if(weakself.onFinishLoad)
  797. // weakself.onFinishLoad();
  798. // }
  799. // else
  800. // if(result==RESULT_NET_ERROR)
  801. // {
  802. // weakself.label_net_err.hidden=false;
  803. // weakself.itemListTable.hidden=true;
  804. // }
  805. // else
  806. // {
  807. // if(result!=1)
  808. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Cart" controller:weakself] ;
  809. // }
  810. //
  811. // weakself.isrefreshing=false;
  812. // DebugLog(@"FINISH LOAD CART");
  813. //
  814. // });
  815. // });
  816. });
  817. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  818. }
  819. -(void)manually_refresh
  820. {
  821. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  822. if(self.isrefreshing)
  823. {
  824. [reF endRefreshing];
  825. return;
  826. }
  827. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  828. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  829. // DebugLog(@"refresh!!!!!!!!");
  830. }
  831. -(void) ReloadData
  832. {
  833. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  834. [reF endRefreshing];
  835. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  836. [self reload_data];
  837. }
  838. - (void)viewDidLayoutSubviews {
  839. [super viewDidLayoutSubviews];
  840. [self layoutCartIndicatorBar];
  841. }
  842. - (DefaultTableHeaderView *)setupCartIndicatorBar {
  843. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  844. if(value==nil)
  845. value=@"";
  846. unsigned long color = strtoul([value UTF8String],0,16);
  847. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 40)];
  848. // myView.backgroundColor = UIColorFromRGB(0x996633);
  849. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  850. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  851. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  852. myView.layer.shadowOffset = CGSizeMake(0, 0);
  853. myView.layer.shadowOpacity = 0.5;
  854. myView.layer.shadowRadius = 2.0;
  855. #ifndef SCANNER_ORDER
  856. self.sortButton.tag = 5678 + 0;
  857. [myView addSubview:self.sortButton];
  858. #endif
  859. UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 9, 90, 22)];
  860. solabel.tag = 5678 + 1;
  861. solabel.textColor=UIColorFromRGB(color);
  862. solabel.backgroundColor = [UIColor clearColor];
  863. solabel.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  864. solabel.text=NSLocalizedString(@"Description", nil);
  865. [solabel sizeToFit];
  866. [myView addSubview:solabel];
  867. CGFloat x = self.itemListTable.bounds.size.width - (768 - 320);
  868. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  869. contactlabel.tag = 5678 + 2;
  870. contactlabel.textColor=UIColorFromRGB(color);
  871. contactlabel.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  872. contactlabel.backgroundColor = [UIColor clearColor];
  873. #ifdef SCANNER_ORDER
  874. NSString* pricename;
  875. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  876. NSString* servername = [addressDic objectForKey:@"show_name"];
  877. NSArray* arrsn = [RAConvertor string2arr:servername separator:@","];
  878. NSString * shortname = arrsn[0];
  879. if(shortname.length==0)
  880. shortname = servername;
  881. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  882. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  883. // self.labelPrice0.text = price_group[@"price_0"][@"display"];//appDelegate.price0_name;
  884. // self.labelPrice1.text = price_group[@"price_1"][@"display"];//appDelegate.price1_name;
  885. switch(RASingleton.sharedInstance.price_type)
  886. {
  887. case 0:
  888. // pricename =[NSString stringWithFormat:@"%@_DDP",shortname];
  889. pricename = price_group[@"price_0"][@"display"];
  890. break;;
  891. case 1:
  892. // pricename = [NSString stringWithFormat:@"%@_WHSE",shortname];;
  893. pricename=price_group[@"price_1"][@"display"];//@"WHSE";
  894. break;;
  895. // case 2: pricename = @"25%";
  896. // break;
  897. }
  898. contactlabel.text=pricename;
  899. // contactlabel.frame= CGRectMake(x-100, 9, 90, 22);
  900. // contactlabel.tran
  901. #else
  902. contactlabel.text=NSLocalizedString(@"Unit price", nil);
  903. #endif
  904. [contactlabel sizeToFit];
  905. [myView addSubview:contactlabel];
  906. x = self.itemListTable.bounds.size.width - (768 - 470);
  907. UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  908. modellabel.tag = 5678 + 3;
  909. modellabel.textColor=UIColorFromRGB(color);
  910. modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  911. modellabel.backgroundColor = [UIColor clearColor];
  912. modellabel.text=NSLocalizedString(@"Discount/QTY", nil);
  913. [modellabel sizeToFit];
  914. [myView addSubview:modellabel];
  915. x = self.itemListTable.bounds.size.width - (768 - 640);
  916. UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  917. pricelabel.tag = 5678 + 4;
  918. pricelabel.textColor=UIColorFromRGB(color);
  919. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  920. pricelabel.backgroundColor = [UIColor clearColor];
  921. pricelabel.text=NSLocalizedString(@"Set/Subtotal", nil);
  922. [pricelabel sizeToFit];
  923. [myView addSubview:pricelabel];
  924. return myView;
  925. }
  926. - (void)layoutCartIndicatorBar {
  927. CGFloat x = self.itemListTable.bounds.size.width - (768 - 320);
  928. UILabel *solabel = [self.cartIndicatorBar viewWithTag:5678 + 1];
  929. [solabel sizeToFit];
  930. UILabel *contactlabel = [self.cartIndicatorBar viewWithTag:5678 + 2];
  931. contactlabel.frame = CGRectMake(x, 9, 90, 22);
  932. [contactlabel sizeToFit];
  933. x = self.itemListTable.bounds.size.width - (768 - 470);
  934. UILabel *modellabel = [self.cartIndicatorBar viewWithTag:5678 + 3];
  935. modellabel.frame = CGRectMake(x, 9, 90, 22);
  936. [modellabel sizeToFit];
  937. x = self.itemListTable.bounds.size.width - (768 - 640);
  938. UILabel *pricelabel = [self.cartIndicatorBar viewWithTag:5678 + 4];
  939. pricelabel.frame = CGRectMake(x, 9, 90, 22);
  940. [pricelabel sizeToFit];
  941. }
  942. - (void)viewDidLoad
  943. {
  944. [super viewDidLoad];
  945. #if defined(USE_BLE_SCANNER) || defined(USE_MFI_SCANNER)
  946. self.batch_scan=false;
  947. self.stop_response=false;
  948. #endif
  949. #ifdef BUILD_CONTRAST
  950. self.btnOrderDiscount.hidden=false;
  951. #endif
  952. #ifdef SCANNER_ORDER
  953. self.printButton.hidden = true;
  954. self.emailButton.hidden = true;
  955. self.editButton.hidden = true;
  956. self.continueButton.hidden = true;
  957. self.labelTotalcuft.hidden = false;
  958. self.labelTotalWeight.hidden = true;
  959. self.labelTotalCarton.hidden = true;
  960. self.valuecuft.hidden = false;
  961. self.valueweight.hidden = true;
  962. self.valuecarton.hidden = true;
  963. #endif
  964. #ifdef RA_NOTIFICATION
  965. self.support_scanner = true;
  966. #endif
  967. self.edit_select_arr= [[NSMutableArray alloc] init];
  968. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  969. self.label_net_err.layer.borderWidth = 2.0;
  970. self.label_net_err.layer.cornerRadius=15;
  971. self.label_net_err.layer.masksToBounds=true;
  972. #ifdef SCANNER_ORDER
  973. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cartrefresh:) name:@"RA_NOTIFICATION_CART_REFRESH" object:nil];
  974. #endif
  975. #ifndef RA_NOTIFICATION
  976. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(priceTypeChanged:) name:Change_Price_Type_Notification object:nil];
  977. #endif
  978. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  979. // tap.minimumPressDuration = 0.8; //定义按的时间
  980. [self.label_net_err addGestureRecognizer:tap];
  981. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  982. ref.tag = 200 ;
  983. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  984. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  985. // ref.hidden = true;
  986. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  987. [self.itemListTable addSubview:ref];
  988. self.sortIndex = 0;
  989. self.currentOrderIsMerged = NO;
  990. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  991. self.toolpanel.layer.masksToBounds = false;
  992. //添加四个边阴影
  993. self.toolpanel.layer.shadowColor = [UIColor blackColor].CGColor;
  994. self.toolpanel.layer.shadowOffset = CGSizeMake(0, 0);
  995. self.toolpanel.layer.shadowOpacity = 0.5;
  996. self.toolpanel.layer.shadowRadius = 2.0;
  997. cancelButtonFrame = self.cancelOrderButton.frame;
  998. // CGRect frame =self.orderInfoTableView.tableHeaderView.frame;
  999. // self.orderInfoTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.orderInfoTableView.bounds.size.width, 0.0001)];
  1000. // self.orderInfoTableView.tableHeaderView.backgroundColor = [UIColor redColor];
  1001. // // self.detailTable.sectionHeaderHeight = 0.0001;
  1002. // self.orderInfoTableView.sectionFooterHeight = 0.0001;
  1003. // Do any additional setup after loading the view.
  1004. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1005. [self.view addSubview:self.cartIndicatorBar];
  1006. }
  1007. -(void) cartrefresh: (NSNotification *)notification
  1008. {
  1009. [OLDataProvider scanRefreshCart];
  1010. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1011. // [self refresh_total];
  1012. // [self refresh_ui];
  1013. }
  1014. //-(void)SelectOrder:(NSString *)orderid
  1015. //{
  1016. //// self.editOrderID.text=orderid;
  1017. //// self.btnAddToOrder.enabled = true;
  1018. //}
  1019. - (void)didReceiveMemoryWarning
  1020. {
  1021. [super didReceiveMemoryWarning];
  1022. // Dispose of any resources that can be recreated.
  1023. }
  1024. //- (IBAction)stepperAction:(UIStepper *)sender {
  1025. //
  1026. //
  1027. //}
  1028. - (IBAction)onContinueShoppingClick:(id)sender {
  1029. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1030. [appDelegate switchToPreviousVC];
  1031. }
  1032. - (IBAction)onOrderDiscount:(id)sender {
  1033. #ifdef BUILD_CONTRAST
  1034. OrderDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderDiscountViewController"];
  1035. // vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  1036. // vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  1037. // vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1038. // __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  1039. // vc.delegate = parentvc.self;
  1040. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1041. vc.onSetValue = ^(double discount){
  1042. // bool bmodify=false;
  1043. // if(discount>0)
  1044. // bmodify=true;
  1045. // NSString* notes = [item_json valueForKey:@"note"];
  1046. // if(notes.length==0)
  1047. // notes=@"";
  1048. // if(bmodify)
  1049. // {
  1050. //
  1051. //
  1052. // // if([notes isEqualToString:@""])
  1053. //// notes=[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  1054. ////
  1055. //// NSRange range;
  1056. //// range = [notes rangeOfString:@"PRICE MODIFIED"];
  1057. //// if (range.location != NSNotFound) {
  1058. ////
  1059. //// }else{
  1060. //// notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  1061. //// }
  1062. // }
  1063. // else
  1064. //
  1065. // {
  1066. //// notes =@"";
  1067. // }
  1068. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Discount" completion:^{
  1069. [RANetwork request_order_discount:discount completionHandler:^(NSMutableDictionary *result) {
  1070. [waitalert dismissViewControllerAnimated:YES completion:^{
  1071. int iresult = [result[@"result"] intValue];
  1072. if(iresult==RESULT_TRUE)
  1073. {
  1074. [self reload_data];
  1075. }
  1076. else
  1077. {
  1078. [RAUtils message_alert:@"Can't set order discount, please contact administrator" title:@"Set Order Discount" controller:self];
  1079. }
  1080. // if([[cart_json valueForKey:@"result"] intValue]==2)
  1081. // {
  1082. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  1083. //
  1084. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  1085. // // [item_json setValue:notes forKey:@"note"];
  1086. //
  1087. // // RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",indexPath.row]]=item_json;
  1088. // // if (self.back_order_flag) {
  1089. // // [self updateItemJson:item_json atIndexPath:indexPath];
  1090. // // } else {
  1091. // // self.content_arr[indexPath.row ] = item_json;
  1092. // // }
  1093. // // tableView.editing = false;
  1094. // // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1095. // // [self refresh_total];
  1096. //
  1097. //
  1098. // [self reload_data];
  1099. //
  1100. // #ifdef RA_NOTIFICATION
  1101. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1102. // #else
  1103. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1104. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1105. // #endif
  1106. // }
  1107. // else
  1108. // {
  1109. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  1110. // }
  1111. }];
  1112. }];
  1113. // [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  1114. // NSDictionary* cart_json = result;
  1115. //
  1116. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1117. // if([[cart_json valueForKey:@"result"] intValue]==2)
  1118. // {
  1119. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  1120. //
  1121. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  1122. //// [item_json setValue:notes forKey:@"note"];
  1123. //
  1124. //// RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",indexPath.row]]=item_json;
  1125. //// if (self.back_order_flag) {
  1126. //// [self updateItemJson:item_json atIndexPath:indexPath];
  1127. //// } else {
  1128. //// self.content_arr[indexPath.row ] = item_json;
  1129. //// }
  1130. //// tableView.editing = false;
  1131. // // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1132. // // [self refresh_total];
  1133. //
  1134. //
  1135. // [self reload_data];
  1136. //
  1137. // #ifdef RA_NOTIFICATION
  1138. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1139. // #else
  1140. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1141. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1142. // #endif
  1143. // }
  1144. // else
  1145. // {
  1146. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  1147. // }
  1148. // }];
  1149. //
  1150. //
  1151. //
  1152. //
  1153. //
  1154. //
  1155. // }];
  1156. }];
  1157. };
  1158. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1159. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1160. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1161. [self presentViewController:navi animated:YES completion:^{
  1162. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1163. DebugLog(@"EditModelPriceViewController present.........");
  1164. // self.btop = false;
  1165. // <#code#>
  1166. }];
  1167. #endif
  1168. }
  1169. - (IBAction)onPlaceOrder:(UIButton *)sender {
  1170. #ifndef SCANNER_ORDER
  1171. if (![self isOrderAvailable]) {
  1172. return;
  1173. }
  1174. #endif
  1175. [self placeOrder];
  1176. }
  1177. -(void) scanPlaceOrder
  1178. {
  1179. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1180. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1181. // NSString * string = [checked componentsJoinedByString:@","];
  1182. // [params setValue:string forKey:@"cart2Checkbox"];
  1183. // NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1184. // NSError *error=nil;
  1185. // NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1186. //
  1187. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1188. // NSString *documents = [paths objectAtIndex:0];
  1189. NSString *orderdir = [OLDataProvider getScanPath];
  1190. NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  1191. int section_count = [dict[@"section_count"] intValue];
  1192. for(int i=0;i<section_count;i++)
  1193. {
  1194. NSMutableDictionary* section = [dict[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  1195. NSString* title = section[@"title"];
  1196. if([title isEqualToString:@"Model Information"])
  1197. {
  1198. NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  1199. int cart_count = [cart_section[@"count"] intValue];
  1200. for(int j=0;j<cart_count;j++)
  1201. {
  1202. NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1203. cart_item[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  1204. cart_item[@"control"]=@"model";
  1205. section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  1206. }
  1207. section[@"count"] = @(cart_count);
  1208. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1209. }
  1210. else
  1211. if([title isEqualToString:@"Customer"])
  1212. {
  1213. int scount = [section[@"count"] intValue];
  1214. for(int j=0;j<scount;j++)
  1215. {
  1216. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1217. NSString * name = item[@"name"];
  1218. if([name isEqualToString:@"business_card"])
  1219. {
  1220. NSArray*arr =[RAConvertor string2arr:appDelegate.customerInfo[name] separator:@","];
  1221. for(int l=0;l<arr.count;l++)
  1222. {
  1223. item[[NSString stringWithFormat:@"img_url_%d",l] ]=arr[l];
  1224. }
  1225. }
  1226. else
  1227. {
  1228. if(item[@"value"]==nil ||[item[@"value"] stringValue].length==0) //order 内没有值才从customer 复制
  1229. item[@"value"]=appDelegate.customerInfo[name];
  1230. }
  1231. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1232. }
  1233. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1234. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1235. }
  1236. else
  1237. if([title isEqualToString:@"Remarks Content"])
  1238. {
  1239. int scount = [section[@"count"] intValue];
  1240. for(int j=0;j<scount;j++)
  1241. {
  1242. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1243. NSString * name = item[@"name"];
  1244. if([name isEqualToString:@"comments"])
  1245. {
  1246. item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  1247. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1248. }
  1249. }
  1250. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1251. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1252. }
  1253. else if([title isEqualToString:@"Order Total"])
  1254. {
  1255. int scount = [section[@"count"] intValue];
  1256. for(int j=0;j<scount;j++)
  1257. {
  1258. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1259. NSString * name = item[@"name"];
  1260. if([name isEqualToString:@"totalPrice"])
  1261. {
  1262. item[@"value"] = [RAConvertor currencyNumber:self.total+self.surcharge];//[NSString stringWithFormat:@"%.2f",self.total+self.surcharge];
  1263. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1264. }
  1265. else if([name isEqualToString:@"subtotalPrice"])
  1266. {
  1267. item[@"value"] = [RAConvertor currencyNumber:self.total];//[NSString stringWithFormat:@"%.2f",self.total];
  1268. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1269. }
  1270. else if([name isEqualToString:@"surcharge"])
  1271. {
  1272. item[@"value"] = [RAConvertor currencyNumber:self.surcharge];//[NSString stringWithFormat:@"%.2f",self.surcharge];
  1273. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1274. }
  1275. }
  1276. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1277. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1278. }
  1279. }
  1280. // NSString *path = NSTemporaryDirectory();
  1281. //
  1282. // NSString* file=[NSString stringWithFormat:@"SO_%@.json",appDelegate.order_code];
  1283. // NSString *filePath = [path stringByAppendingPathComponent:file];
  1284. //
  1285. //
  1286. //
  1287. [RAUtils dicttofile:[orderdir stringByAppendingPathComponent:@"order.json"] dict:dict];
  1288. CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1289. orderinfoVC.disable_dropdown_refresh=true;
  1290. orderinfoVC.url_type = URL_FILE;
  1291. orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  1292. orderinfoVC.params = params;
  1293. orderinfoVC.title=@"";
  1294. orderinfoVC.delegate=self;
  1295. //
  1296. // if(checked.count==count)
  1297. // {
  1298. // orderinfoVC.have_tail = true
  1299. // }
  1300. [self.navigationController pushViewController:orderinfoVC animated:true];
  1301. return;
  1302. }
  1303. - (IBAction)onBulkDiscount:(id)sender {
  1304. #ifdef SCANNER_ORDER
  1305. ScanDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanDiscountViewController"];
  1306. vc.bulk = true;
  1307. vc.discount=0;
  1308. // vc.price = 0;
  1309. // vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1310. // __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  1311. // vc.delegate = parentvc.self;
  1312. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1313. vc.onSetValue = ^(double price,double discount){
  1314. bool bmodify=false;
  1315. if(discount>0)
  1316. bmodify=true;
  1317. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  1318. [RANetwork request_scan_bulkdiscount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  1319. NSDictionary* cart_json = result;
  1320. [waitalert dismissViewControllerAnimated:YES completion:^{
  1321. if([[cart_json valueForKey:@"result"] intValue]==2)
  1322. {
  1323. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  1324. //
  1325. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  1326. // [item_json setValue:notes forKey:@"note"];
  1327. // RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",indexPath.row]]=item_json;
  1328. // if (self.back_order_flag) {
  1329. // [self updateItemJson:item_json atIndexPath:indexPath];
  1330. // } else {
  1331. // self.content_arr[indexPath.row ] = item_json;
  1332. // }
  1333. // tableView.editing = false;
  1334. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1335. // [self refresh_total];
  1336. [self reload_data];
  1337. #ifdef RA_NOTIFICATION
  1338. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1339. #else
  1340. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1341. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1342. #endif
  1343. }
  1344. else
  1345. {
  1346. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  1347. }
  1348. }];
  1349. }];
  1350. }];
  1351. };
  1352. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1353. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1354. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1355. [self presentViewController:navi animated:YES completion:^{
  1356. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1357. DebugLog(@"EditModelPriceViewController present.........");
  1358. // self.btop = false;
  1359. // <#code#>
  1360. }];
  1361. #endif
  1362. }
  1363. - (IBAction)onChangePrice:(id)sender {
  1364. #ifdef SCANNER_ORDER
  1365. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1366. if(RASingleton.sharedInstance.scan_cart ==nil)
  1367. {
  1368. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  1369. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  1370. RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  1371. }
  1372. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  1373. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Change Price Type" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1374. UIAlertAction *action1 = [UIAlertAction actionWithTitle:price_group[@"price_0"][@"display"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1375. self.btnBulkDiscount.hidden = true;
  1376. // self.btnPrice.titleLabel.text = @"FOB CTNR";
  1377. [self.btnPrice setTitle: price_group[@"price_0"][@"display"] forState:UIControlStateNormal];
  1378. RASingleton.sharedInstance.price_type=0;
  1379. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1380. int count = [section[@"count"] intValue];
  1381. for(int i=0;i<count;i++)
  1382. {
  1383. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1384. item[@"price"]=item[ price_group[@"price_0"][@"name"]];
  1385. item[@"unit_price"]= item[price_group[@"price_0"][@"name"]];
  1386. item[@"erp_unit_price"]= item[price_group[@"price_0"][@"name"]];
  1387. item[@"discount"]=@(0);
  1388. item[@"note"]=@"";
  1389. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1390. }
  1391. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1392. RASingleton.sharedInstance.scan_cart[@"price_type"] = @0;
  1393. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1394. [self.cartIndicatorBar removeFromSuperview];
  1395. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1396. [self.view addSubview:self.cartIndicatorBar];
  1397. [self reload_data];
  1398. }];
  1399. UIAlertAction *action2 = [UIAlertAction actionWithTitle:price_group[@"price_1"][@"display"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1400. self.btnBulkDiscount.hidden = false;
  1401. [self.btnPrice setTitle: price_group[@"price_1"][@"display"] forState:UIControlStateNormal];
  1402. RASingleton.sharedInstance.price_type=1;
  1403. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1404. int count = [section[@"count"] intValue];
  1405. for(int i=0;i<count;i++)
  1406. {
  1407. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1408. NSString * unit_price;
  1409. if(item [@"net_price"])
  1410. unit_price=item[price_group[@"price_3"][@"name"]];
  1411. else if(item [@"special_price"])
  1412. {
  1413. unit_price= item[price_group[@"price_2"][@"name"]];
  1414. }
  1415. else
  1416. {
  1417. unit_price= item[price_group[@"price_1"][@"name"]];
  1418. }
  1419. if([unit_price isEqualToString:@"N/A"])
  1420. unit_price = @"0";
  1421. else
  1422. {
  1423. unit_price = [NSString stringWithFormat:@"%.2f", [unit_price doubleValue]];
  1424. }
  1425. item[@"unit_price"] = unit_price;
  1426. item[@"erp_unit_price"] = unit_price;
  1427. item[@"price"]= unit_price;//item[@"price1"];
  1428. // item[@"unit_price"]= item[@"price1"];
  1429. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1430. }
  1431. RASingleton.sharedInstance.scan_cart[@"price_type"] = @1;
  1432. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1433. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1434. [self.cartIndicatorBar removeFromSuperview];
  1435. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1436. [self.view addSubview:self.cartIndicatorBar];
  1437. [self reload_data];
  1438. }];
  1439. UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"%25" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1440. // self.btnPrice.titleLabel.text = @"%25";
  1441. [self.btnPrice setTitle: @"%25" forState:UIControlStateNormal];
  1442. RASingleton.sharedInstance.price_type=2;
  1443. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1444. int count = [section[@"count"] intValue];
  1445. for(int i=0;i<count;i++)
  1446. {
  1447. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1448. item[@"price"]= item[price_group[@"price_2"][@"name"]];
  1449. item[@"unit_price"]= item[price_group[@"price_2"][@"name"]];
  1450. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1451. }
  1452. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1453. RASingleton.sharedInstance.scan_cart[@"price_type"] = @2;
  1454. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1455. [self.cartIndicatorBar removeFromSuperview];
  1456. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1457. [self.view addSubview:self.cartIndicatorBar];
  1458. [self reload_data];
  1459. }];
  1460. UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1461. }];
  1462. [alertControl addAction:action1];
  1463. [alertControl addAction:action2];
  1464. // [alertControl addAction:action3];
  1465. // [alertControl addAction:alertthree];
  1466. [alertControl addAction:alertCancel];
  1467. [self presentViewController:alertControl animated:YES completion:nil];
  1468. #endif
  1469. }
  1470. -(void) newoloorder
  1471. {
  1472. NSString *orderdir =[OLDataProvider getScanPath];
  1473. // NSString* order_code = RASingleton.sharedInstance.scan_temp_code;
  1474. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1475. // appDelegate.order_code = order_code;
  1476. // if(appDelegate.user.length==0)
  1477. // {
  1478. // [RAUtils message_alert:@"Please login first." title:@"Warring" controller:self];
  1479. // return;
  1480. // }
  1481. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  1482. // NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  1483. // RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  1484. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  1485. appDelegate.can_set_cart_price = true;
  1486. appDelegate.can_see_price = true;
  1487. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1488. // NSString *documents = [paths objectAtIndex:0];
  1489. {
  1490. // [OLDataProvider moveScanTemp2Order];
  1491. // NSError *error = nil;
  1492. // bool bsuccess=[[NSFileManager defaultManager] createDirectoryAtPath:orderdir withIntermediateDirectories:YES attributes:nil error:&error];
  1493. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1494. // NSString * string = [checked componentsJoinedByString:@","];
  1495. // [params setValue:string forKey:@"cart2Checkbox"];
  1496. // NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1497. // NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1498. // __block NSMutableDictionary* block_dict = dict;
  1499. if(appDelegate.user_type== USER_ROLE_EMPLOYEE)
  1500. {
  1501. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1502. //block代码块取代了delegate
  1503. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1504. NSMutableDictionary* dict = nil;
  1505. // NSMutableDictionary* dict = nil;
  1506. NSString* ordertemplate = nil;
  1507. if([RADataProvider getSiteHasERP])
  1508. ordertemplate =@"e_order.json";
  1509. else
  1510. ordertemplate =@"e_order_noerp.json";
  1511. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1512. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1513. [RAUtils dicttofile:orderPath dict:dict];
  1514. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1515. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1516. [self scanPlaceOrder];
  1517. }];
  1518. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1519. NSMutableDictionary* dict = nil;
  1520. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1521. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1522. [RAUtils dicttofile:orderPath dict:dict];
  1523. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1524. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1525. [self scanPlaceOrder];
  1526. }];
  1527. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1528. appDelegate.order_code = nil;
  1529. DebugLog(@"No");
  1530. }];
  1531. [alertControl addAction:actionOne];
  1532. [alertControl addAction:alert2];
  1533. [alertControl addAction:alertthree];
  1534. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1535. [self presentViewController:alertControl animated:YES completion:nil];
  1536. DebugLog(@"%@",self.edit_select_arr);
  1537. }
  1538. else
  1539. {
  1540. NSMutableDictionary* dict = nil;
  1541. if([appDelegate.customerInfo[@"customer_cid"] stringValue].length ==0 )
  1542. {
  1543. dict=[OLDataProvider loadScanTemplate:@"nc_order.json"];
  1544. }
  1545. else
  1546. dict=[OLDataProvider loadScanTemplate:@"c_order.json"];
  1547. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1548. [RAUtils dicttofile:orderPath dict:dict];
  1549. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1550. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1551. [self scanPlaceOrder];
  1552. }
  1553. // NSMutableDictionary* dict=[OLDataProvider loadScanTemplate:@"scan_order.json"];
  1554. }
  1555. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  1556. // mainvc.btnScan.enabled = true;
  1557. // [appDelegate updateScanButton:true];
  1558. }
  1559. -(void) newoloorder1
  1560. {
  1561. // NSString* order_code = RASingleton.sharedInstance.scan_temp_code;
  1562. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1563. // appDelegate.order_code = order_code;
  1564. // if(appDelegate.user.length==0)
  1565. // {
  1566. // [RAUtils message_alert:@"Please login first." title:@"Warring" controller:self];
  1567. // return;
  1568. // }
  1569. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  1570. // NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  1571. // RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  1572. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  1573. appDelegate.can_set_cart_price = true;
  1574. appDelegate.can_see_price = true;
  1575. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1576. // NSString *documents = [paths objectAtIndex:0];
  1577. {
  1578. NSString *orderdir =[OLDataProvider getScanPath];
  1579. // [OLDataProvider moveScanTemp2Order];
  1580. // NSError *error = nil;
  1581. // bool bsuccess=[[NSFileManager defaultManager] createDirectoryAtPath:orderdir withIntermediateDirectories:YES attributes:nil error:&error];
  1582. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1583. // NSString * string = [checked componentsJoinedByString:@","];
  1584. // [params setValue:string forKey:@"cart2Checkbox"];
  1585. // NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1586. // NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1587. // __block NSMutableDictionary* block_dict = dict;
  1588. if(appDelegate.user_type== USER_ROLE_EMPLOYEE)
  1589. {
  1590. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1591. //block代码块取代了delegate
  1592. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1593. NSMutableDictionary* dict = nil;
  1594. NSString* ordertemplate = nil;
  1595. if([RADataProvider getSiteHasERP])
  1596. ordertemplate =@"e_order.json";
  1597. else
  1598. ordertemplate =@"e_order_noerp.json";
  1599. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1600. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1601. [RAUtils dicttofile:orderPath dict:dict];
  1602. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1603. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1604. [self scanPlaceOrder];
  1605. }];
  1606. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1607. NSMutableDictionary* dict = nil;
  1608. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1609. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1610. [RAUtils dicttofile:orderPath dict:dict];
  1611. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1612. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1613. [self scanPlaceOrder];
  1614. }];
  1615. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1616. appDelegate.order_code = nil;
  1617. DebugLog(@"No");
  1618. }];
  1619. [alertControl addAction:actionOne];
  1620. [alertControl addAction:alert2];
  1621. [alertControl addAction:alertthree];
  1622. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1623. [self presentViewController:alertControl animated:YES completion:nil];
  1624. DebugLog(@"%@",self.edit_select_arr);
  1625. }
  1626. else
  1627. {
  1628. NSMutableDictionary* dict = nil;
  1629. if([appDelegate.customerInfo[@"customer_cid"] stringValue].length ==0 )
  1630. {
  1631. dict=[OLDataProvider loadScanTemplate:@"nc_order.json"];
  1632. }
  1633. else
  1634. dict=[OLDataProvider loadScanTemplate:@"c_order.json"];
  1635. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1636. [RAUtils dicttofile:orderPath dict:dict];
  1637. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1638. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1639. [self scanPlaceOrder];
  1640. }
  1641. // NSMutableDictionary* dict=[OLDataProvider loadScanTemplate:@"scan_order.json"];
  1642. }
  1643. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  1644. // mainvc.btnScan.enabled = true;
  1645. // [appDelegate updateScanButton:true];
  1646. }
  1647. -(void)newScanOrder1
  1648. {
  1649. //
  1650. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1651. //
  1652. //
  1653. // if(appDelegate.order_code.length>0)
  1654. // {
  1655. //// 当前订单先关闭
  1656. //// [OLDataProvider deleteScanOrder:appDelegate.order_code];
  1657. // appDelegate.order_code = nil;
  1658. // appDelegate.customerInfo = nil;
  1659. // RASingleton.sharedInstance.scan_cart = nil;
  1660. // appDelegate.contact_id = nil;
  1661. //// [appDelegate updateScanButton:false];
  1662. //
  1663. // [appDelegate update_count_mark];
  1664. // [appDelegate closeOrder];
  1665. //
  1666. // }
  1667. //
  1668. //
  1669. {
  1670. [self newoloorder1];
  1671. }
  1672. }
  1673. -(void)newScanOrder
  1674. {
  1675. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1676. //if(appDelegate.user.length<=0)
  1677. //{
  1678. // [RAUtils message_alert:@"Please select a sales first." title:@"Warring" controller:self];
  1679. // return;
  1680. //}
  1681. // if(appDelegate.order_code.length>0)
  1682. // {
  1683. //// 当前订单先关闭
  1684. //// [OLDataProvider deleteScanOrder:appDelegate.order_code];
  1685. // appDelegate.order_code = nil;
  1686. // appDelegate.customerInfo = nil;
  1687. // RASingleton.sharedInstance.scan_cart = nil;
  1688. // appDelegate.contact_id = nil;
  1689. //// [appDelegate updateScanButton:false];
  1690. //
  1691. // [appDelegate update_count_mark];
  1692. // [appDelegate closeOrder];
  1693. //
  1694. // }
  1695. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  1696. // __block MainViewController *brself= self;
  1697. // if(appDelegate.contact_id.length<=0)
  1698. // {
  1699. //
  1700. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"New Offline Order" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1701. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"With Offline Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1702. //
  1703. //// if(appDelegate.order_code && appDelegate.order_code.length>0)
  1704. //// {
  1705. //// [RAUtils message_alert:@"Please close current order and try again." title:@"" controller:self];
  1706. //// }
  1707. //// NSLog(@"new click");
  1708. //
  1709. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1710. //
  1711. //// NSString *path = [[NSBundle mainBundle] pathForResource:@"editContact.json" ofType:nil];
  1712. //
  1713. // CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1714. // cuseditVC.bnewcustomer=true;
  1715. // cuseditVC.bolocustomer = true;
  1716. // cuseditVC.url_type = URL_FILE;
  1717. // cuseditVC.request_url=[OLDataProvider scanTemplatePath:@"scan_contact.json"];
  1718. //
  1719. // cuseditVC.params = params;
  1720. //
  1721. // cuseditVC.returnValue=^(NSMutableDictionary* value)
  1722. // {
  1723. // if(value==nil)
  1724. // {
  1725. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  1726. // }
  1727. // else
  1728. // {
  1729. // NSString* contact_id=[[NSUUID new] UUIDString];
  1730. //
  1731. //
  1732. // //---------------- construct customer_contact----------------------
  1733. // NSString* customer_first_name = [value valueForKey:@"customer_first_name"];
  1734. // if(customer_first_name==nil)
  1735. // customer_first_name=@"";
  1736. //
  1737. // NSString* customer_last_name= [value valueForKey:@"customer_last_name"];
  1738. // if(customer_last_name==nil)
  1739. // customer_last_name=@"";
  1740. // NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  1741. // customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  1742. // [value setValue:customer_contact forKey:@"customer_contact"];
  1743. //
  1744. //
  1745. //
  1746. // value [@"customer_cid"] = contact_id;
  1747. // appDelegate.contact_id=contact_id;
  1748. // appDelegate.customerInfo = value;
  1749. //
  1750. //
  1751. //
  1752. //
  1753. //
  1754. //
  1755. //// [brself refreshContactDisplay];
  1756. // [self newoloorder];
  1757. //
  1758. // [self scanPlaceOrder];
  1759. //
  1760. //// [brself switchToCart:nil];
  1761. //
  1762. // }
  1763. // };
  1764. //
  1765. //
  1766. // // cuseditVC.delegate=self;
  1767. // //
  1768. // // if(checked.count==count)
  1769. // // {
  1770. // // orderinfoVC.have_tail = true
  1771. // // }
  1772. //
  1773. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  1774. // [self.navigationController pushViewController:cuseditVC animated:false];
  1775. //
  1776. //// [self dismissViewControllerAnimated:NO completion:^{
  1777. ////// [(UINavigationController*)[self parentViewController] pushViewController:cuseditVC animated:false];;
  1778. ////// [[self navigationController] setNavigationBarHidden:NO animated:NO];
  1779. ////
  1780. ////// [self pushViewController:cuseditVC animated:false];
  1781. //// }];
  1782. //
  1783. //// [[self navigationController] setNavigationBarHidden:NO animated:NO];
  1784. //// [self.navigationController pushViewController:cuseditVC animated:false];
  1785. //
  1786. //
  1787. // }];
  1788. //
  1789. //
  1790. //
  1791. // UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1792. //
  1793. // }];
  1794. //
  1795. // [alertControl addAction:actionOne];
  1796. //
  1797. //// [alertControl addAction:alertthree];
  1798. // [alertControl addAction:alertCancel];
  1799. //
  1800. // [self presentViewController:alertControl animated:YES completion:nil];
  1801. // }
  1802. // else
  1803. {
  1804. [self newoloorder];
  1805. }
  1806. }
  1807. -(void)placeOrder
  1808. {
  1809. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1810. #ifndef SCANNER_ORDER
  1811. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1812. if (![RASingleton sharedInstance].permissions_edit_order) {
  1813. return;
  1814. }
  1815. // if (!self.available) {
  1816. //
  1817. // [RAUtils message_alert:@"There are some products is not available" title:@"Warning" controller:self];
  1818. // return;
  1819. // }
  1820. }
  1821. #endif
  1822. // NSMutableArray* checked = [[NSMutableArray alloc] init];
  1823. bool have_free = false;
  1824. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  1825. if(count==0)
  1826. {
  1827. [RAUtils message_alert:@"Add some model first." title:@"Cart Is Empty." controller:self] ;
  1828. return;
  1829. }
  1830. for(int i=0;i<count;i++)
  1831. {
  1832. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1833. // bool check = [[item_json valueForKey:@"check"] boolValue];
  1834. NSString* product_id = [item_json valueForKey:@"product_id"];
  1835. // if(check)
  1836. // {
  1837. // [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  1838. //
  1839. // }
  1840. if(product_id.length==0)
  1841. {
  1842. [RAUtils message_alert:@"Some models in cart does not exist, you must remove them before place order." title:@"No Such Model" controller:self] ;
  1843. return;
  1844. }
  1845. bool is_free = [[item_json valueForKey:@"is_free"]boolValue];
  1846. if(is_free)
  1847. have_free=true;
  1848. }
  1849. // disable for debug
  1850. // if(checked.count==0)
  1851. // {
  1852. // [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Place Order" controller:self] ;
  1853. // return;
  1854. // }
  1855. // NSDictionary * freejson = [self.content_data objectForKey:@"freeGiveaway"];
  1856. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1857. /* FREE GIVE AWAY
  1858. int free_count = [[self.freejson valueForKey:@"count"]intValue];
  1859. for(int ic=free_count-1;ic>=0;ic--)
  1860. {
  1861. float compare_price = [[self.freejson valueForKey:[NSString stringWithFormat:@"item_%d",ic]] floatValue];
  1862. if(self.total>=compare_price && !have_free&&appDelegate.can_set_cart_price)
  1863. {
  1864. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Free give away available.", nil) message:[NSString stringWithFormat:@"Order total price more than %.2f, do you want to add free give away item before place order?", compare_price] delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  1865. alert.tag = ALERT_FREE;
  1866. [alert show];
  1867. return;
  1868. }
  1869. }
  1870. */
  1871. #ifdef SCANNER_ORDER
  1872. if(appDelegate.bLogin==false)
  1873. {
  1874. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1875. // loginvc.delegate = self;
  1876. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1877. loginvc.returnValue = ^(bool blogin){
  1878. if(blogin)
  1879. {
  1880. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1881. if(appDelegate.order_code.length==0)
  1882. {
  1883. [self newScanOrder];
  1884. }
  1885. }
  1886. };
  1887. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1888. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1889. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1890. [self presentViewController:navi animated:YES completion:^{
  1891. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1892. DebugLog(@"LoginViewController present.........");
  1893. // self.btop = false;
  1894. // <#code#>
  1895. }];
  1896. return;
  1897. }
  1898. else
  1899. {
  1900. NSString *orderdir =[OLDataProvider getScanPath];
  1901. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1902. if(appDelegate.order_code.length==0 )
  1903. {
  1904. [self newScanOrder];
  1905. }
  1906. else if( ![[NSFileManager defaultManager] fileExistsAtPath:orderPath])
  1907. {
  1908. [self newScanOrder1];
  1909. }
  1910. else
  1911. {
  1912. [self scanPlaceOrder];
  1913. //place order
  1914. }
  1915. return;
  1916. }
  1917. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  1918. // {
  1919. //
  1920. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1921. // // NSString * string = [checked componentsJoinedByString:@","];
  1922. // // [params setValue:string forKey:@"cart2Checkbox"];
  1923. //
  1924. //// NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1925. //// NSError *error=nil;
  1926. //// NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1927. ////
  1928. //
  1929. //
  1930. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1931. // NSString *documents = [paths objectAtIndex:0];
  1932. //
  1933. //
  1934. //
  1935. // NSString *orderdir = [documents stringByAppendingPathComponent:appDelegate.order_code];
  1936. //
  1937. // NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  1938. //
  1939. // int section_count = [dict[@"section_count"] intValue];
  1940. //
  1941. // for(int i=0;i<section_count;i++)
  1942. // {
  1943. // NSMutableDictionary* section = [dict[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  1944. // NSString* title = section[@"title"];
  1945. // if([title isEqualToString:@"Model Information"])
  1946. // {
  1947. //
  1948. // NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  1949. // int cart_count = [cart_section[@"count"] intValue];
  1950. // for(int j=0;j<cart_count;j++)
  1951. // {
  1952. // NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1953. // cart_item[@"control"]=@"model";
  1954. // section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  1955. //
  1956. // }
  1957. // section[@"count"] = @(cart_count);
  1958. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1959. // }
  1960. // else
  1961. // if([title isEqualToString:@"Customer"])
  1962. // {
  1963. //
  1964. // int scount = [section[@"count"] intValue];
  1965. // for(int j=0;j<scount;j++)
  1966. // {
  1967. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1968. // NSString * name = item[@"name"];
  1969. //
  1970. // if([name isEqualToString:@"business_card"])
  1971. // {
  1972. // NSArray*arr =[RAConvertor string2arr:appDelegate.customerInfo[name] separator:@","];
  1973. // for(int l=0;l<arr.count;l++)
  1974. // {
  1975. // item[[NSString stringWithFormat:@"img_url_%d",l] ]=arr[l];
  1976. // }
  1977. // }
  1978. // else
  1979. // item[@"value"]=appDelegate.customerInfo[name];
  1980. //
  1981. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1982. // }
  1983. //
  1984. //// NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1985. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1986. //
  1987. //
  1988. // }
  1989. // else
  1990. // if([title isEqualToString:@"Remarks Content"])
  1991. // {
  1992. //
  1993. // int scount = [section[@"count"] intValue];
  1994. // for(int j=0;j<scount;j++)
  1995. // {
  1996. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1997. // NSString * name = item[@"name"];
  1998. //
  1999. //
  2000. // if([name isEqualToString:@"comments"])
  2001. // {
  2002. // item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  2003. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  2004. // }
  2005. //
  2006. //
  2007. // }
  2008. //
  2009. // // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  2010. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  2011. //
  2012. //
  2013. // }
  2014. // else if([title isEqualToString:@"Order Total"])
  2015. // {
  2016. //
  2017. // int scount = [section[@"count"] intValue];
  2018. // for(int j=0;j<scount;j++)
  2019. // {
  2020. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  2021. // NSString * name = item[@"name"];
  2022. //
  2023. //
  2024. // if([name isEqualToString:@"totalPrice"])
  2025. // {
  2026. // item[@"value"] = [NSString stringWithFormat:@"%.2f",self.total];
  2027. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  2028. // }
  2029. //
  2030. //
  2031. // }
  2032. //
  2033. //// NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  2034. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  2035. //
  2036. //
  2037. //
  2038. // }
  2039. //
  2040. //
  2041. //
  2042. //
  2043. // }
  2044. //
  2045. //// NSString *path = NSTemporaryDirectory();
  2046. ////
  2047. //// NSString* file=[NSString stringWithFormat:@"SO_%@.json",appDelegate.order_code];
  2048. //// NSString *filePath = [path stringByAppendingPathComponent:file];
  2049. ////
  2050. ////
  2051. ////
  2052. // [RAUtils dicttofile:[orderdir stringByAppendingPathComponent:@"order.json"] dict:dict];
  2053. //
  2054. // CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2055. //
  2056. //
  2057. //
  2058. // orderinfoVC.disable_dropdown_refresh=true;
  2059. // orderinfoVC.url_type = URL_FILE;
  2060. // orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  2061. //
  2062. // orderinfoVC.params = params;
  2063. // orderinfoVC.title=@"";
  2064. // orderinfoVC.delegate=self;
  2065. // //
  2066. // // if(checked.count==count)
  2067. // // {
  2068. // // orderinfoVC.have_tail = true
  2069. // // }
  2070. //
  2071. // [self.navigationController pushViewController:orderinfoVC animated:true];
  2072. //
  2073. // return;
  2074. // }
  2075. #endif
  2076. #ifdef BACKORDER_PROCESS
  2077. if (self.back_order_flag) {
  2078. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2079. [params setObject:@(0) forKey:@"step"];
  2080. RAOrderEditorViewController *orderEditorVC =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"RAOrderEditorViewController"];
  2081. //[[RAOrderEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2082. orderEditorVC.disable_dropdown_refresh=true;
  2083. orderEditorVC.url_type = URL_REMOTE;
  2084. orderEditorVC.request_url=URL_CARTDELIVERY;
  2085. orderEditorVC.params = params;
  2086. orderEditorVC.delegate=self;
  2087. orderEditorVC.title=@"";
  2088. [self.navigationController pushViewController:orderEditorVC animated:true];
  2089. }
  2090. else
  2091. #endif
  2092. {
  2093. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2094. // NSString * string = [checked componentsJoinedByString:@","];
  2095. // [params setValue:string forKey:@"cart2Checkbox"];
  2096. CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2097. orderinfoVC.disable_dropdown_refresh=true;
  2098. orderinfoVC.url_type = URL_REMOTE;
  2099. orderinfoVC.request_url=URL_CARTDELIVERY;
  2100. orderinfoVC.params = params;
  2101. orderinfoVC.title=@"";
  2102. orderinfoVC.delegate=self;
  2103. //
  2104. // if(checked.count==count)
  2105. // {
  2106. // orderinfoVC.have_tail = true
  2107. // }
  2108. [self.navigationController pushViewController:orderinfoVC animated:true];
  2109. }
  2110. }
  2111. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  2112. {
  2113. return NO;
  2114. }
  2115. //- (IBAction)onDelete:(UIButton *)sender {
  2116. // return ;
  2117. // NSMutableArray* checked = [[NSMutableArray alloc] init];
  2118. //
  2119. //
  2120. //
  2121. // long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  2122. // for(int i=0;i<count;i++)
  2123. // {
  2124. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  2125. // bool check = [[item_json valueForKey:@"check"] boolValue];
  2126. // if(check)
  2127. // {
  2128. // [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  2129. //
  2130. // }
  2131. // }
  2132. // // disable for debug
  2133. // if(checked.count==0)
  2134. // return;
  2135. //
  2136. // // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2137. // NSString * string = [checked componentsJoinedByString:@","];
  2138. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2139. //
  2140. // NSDictionary* cart_json = [RANetwork cart_remove:string];
  2141. //
  2142. // dispatch_async(dispatch_get_main_queue(), ^{
  2143. //
  2144. //
  2145. //
  2146. // if([[cart_json valueForKey:@"result"] intValue]==2)
  2147. // {
  2148. //
  2149. // [self reload_data];
  2150. // }
  2151. // else
  2152. // {
  2153. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  2154. // }
  2155. //
  2156. //
  2157. //
  2158. // });
  2159. // });
  2160. //}
  2161. - (IBAction)onScanDiscount:(UIButton*)sender {
  2162. #ifdef SCANNER_ORDER
  2163. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  2164. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  2165. UIViewController* parentvc=self;
  2166. // EditModelPriceViewController
  2167. ScanDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanDiscountViewController"];
  2168. NSMutableDictionary * item_json = nil;
  2169. if (self.back_order_flag) {
  2170. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2171. } else {
  2172. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2173. }
  2174. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  2175. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  2176. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2177. __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  2178. // vc.delegate = parentvc.self;
  2179. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2180. vc.onSetValue = ^(double price,double discount){
  2181. bool bmodify=false;
  2182. if(discount>0)
  2183. bmodify=true;
  2184. // NSString* notes = [item_json valueForKey:@"note"];
  2185. // if(notes.length==0)
  2186. // notes=@"";
  2187. // if(bmodify)
  2188. // {
  2189. //
  2190. //
  2191. // // if([notes isEqualToString:@""])
  2192. //// notes=[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  2193. ////
  2194. //// NSRange range;
  2195. //// range = [notes rangeOfString:@"PRICE MODIFIED"];
  2196. //// if (range.location != NSNotFound) {
  2197. ////
  2198. //// }else{
  2199. //// notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  2200. //// }
  2201. // }
  2202. // else
  2203. //
  2204. // {
  2205. //// notes =@"";
  2206. // }
  2207. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  2208. [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  2209. NSDictionary* cart_json = result;
  2210. [waitalert dismissViewControllerAnimated:YES completion:^{
  2211. if([[cart_json valueForKey:@"result"] intValue]==2)
  2212. {
  2213. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  2214. //
  2215. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  2216. // [item_json setValue:notes forKey:@"note"];
  2217. // RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",indexPath.row]]=item_json;
  2218. // if (self.back_order_flag) {
  2219. // [self updateItemJson:item_json atIndexPath:indexPath];
  2220. // } else {
  2221. // self.content_arr[indexPath.row ] = item_json;
  2222. // }
  2223. // tableView.editing = false;
  2224. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2225. // [self refresh_total];
  2226. [self reload_data];
  2227. #ifdef RA_NOTIFICATION
  2228. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2229. #else
  2230. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2231. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2232. #endif
  2233. }
  2234. else
  2235. {
  2236. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  2237. }
  2238. }];
  2239. }];
  2240. }];
  2241. };
  2242. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2243. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2244. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2245. [parentvc presentViewController:navi animated:YES completion:^{
  2246. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2247. DebugLog(@"EditModelPriceViewController present.........");
  2248. // self.btop = false;
  2249. // <#code#>
  2250. }];
  2251. #endif
  2252. }
  2253. -(void)refresh_total
  2254. {
  2255. self.total=0;
  2256. self.total_carton=0;
  2257. self.total_cuft=0;
  2258. self.total_weight=0;
  2259. self.total_QTY=0;
  2260. self.total_item=0;
  2261. self.surcharge=0;
  2262. #ifdef SCANNER_ORDER
  2263. NSString* pricename;
  2264. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  2265. NSString* servername = [addressDic objectForKey:@"show_name"];
  2266. NSArray* arrsn = [RAConvertor string2arr:servername separator:@","];
  2267. NSString * shortname = arrsn[0];
  2268. if(shortname.length==0)
  2269. shortname = servername;
  2270. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2271. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  2272. switch(RASingleton.sharedInstance.price_type )
  2273. {
  2274. case 0: pricename =price_group[@"price_0"][@"display"];//@"DDP";//[NSString stringWithFormat:@"%@_DDP",shortname];
  2275. break;;
  2276. case 1: pricename =price_group[@"price_1"][@"display"];//@"WHSE";//[NSString stringWithFormat:@"%@_WHSE",shortname];;
  2277. break;;
  2278. // case 2: pricename = @"25%";
  2279. // break;
  2280. }
  2281. [self.btnPrice setTitle:pricename forState:UIControlStateNormal];
  2282. // self.cartIndicatorBar = [self setupCartIndicatorBar];
  2283. [self.cartIndicatorBar removeFromSuperview];
  2284. self.cartIndicatorBar = [self setupCartIndicatorBar];
  2285. [self.view addSubview:self.cartIndicatorBar];
  2286. #endif
  2287. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  2288. for(int i=0;i<count;i++)
  2289. {
  2290. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  2291. bool bcheck = [[item_json valueForKey:@"check"]boolValue];
  2292. if(bcheck)
  2293. {
  2294. double unitprice = [[item_json valueForKey:@"unit_price"] doubleValue];
  2295. double discount = [[item_json valueForKey:@"discount"] doubleValue];
  2296. int count=[[item_json valueForKey:@"count"] intValue];
  2297. double totalprice =count*unitprice*(1-discount/100.0);
  2298. double cuft=[[item_json valueForKey:@"cuft"] doubleValue];
  2299. double weight=[[item_json valueForKey:@"weight"] doubleValue];
  2300. int carton=/*count**/[[item_json valueForKey:@"carton"] intValue];
  2301. int item_count=1;
  2302. int item_qty=1;
  2303. // NSDictionary * bundle_item =[item_json objectForKey:@"combine"];
  2304. #ifdef SCANNER_ORDER
  2305. double msurcharge =0;
  2306. if(RASingleton.sharedInstance.price_type==1)
  2307. {
  2308. if([item_json[@"special_price"] boolValue])
  2309. {
  2310. msurcharge=([item_json[price_group[@"price_3"][@"name"]] doubleValue]-[item_json[price_group[@"price_2"][@"name"]] doubleValue])*count*(1-discount/100.0);
  2311. if(msurcharge<0)
  2312. msurcharge = 0;
  2313. }
  2314. else
  2315. {
  2316. msurcharge=([item_json[price_group[@"price_3"][@"name"]] doubleValue]-[item_json[price_group[@"price_1"][@"name"]] doubleValue])*count*(1-discount/100.0);
  2317. if(msurcharge<0)
  2318. msurcharge = 0;
  2319. }
  2320. }
  2321. // double dprice=0;
  2322. // if(bundle_item!=nil)
  2323. // {
  2324. // // int citem=0;
  2325. //
  2326. // int bcount=[[bundle_item valueForKey:@"count"] intValue];
  2327. // for(int bc=0;bc<bcount;bc++)
  2328. // {
  2329. // NSDictionary * bitem = [bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  2330. // int modulus= [[bitem valueForKey:@"modulus"] intValue];
  2331. // // citem+= modulus;
  2332. // item_count+=1;
  2333. // item_qty+=modulus;
  2334. // double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  2335. // dprice+= uprice*modulus*count;
  2336. //
  2337. // }
  2338. // }
  2339. // totalprice+= dprice;
  2340. self.surcharge+=msurcharge;
  2341. #endif
  2342. self.total+=totalprice;
  2343. self.total_cuft+=cuft;
  2344. self.total_carton+=carton;
  2345. self.total_weight+=weight;
  2346. self.total_item+=item_count;
  2347. self.total_QTY+=(item_qty)*count;
  2348. }
  2349. }
  2350. NSString* subtotal = [RAConvertor currencyNumber:self.total];//[NSString stringWithFormat:@"$%@",];
  2351. NSString* subcuft = [NSString stringWithFormat:@"%.2f",self.total_cuft];
  2352. NSString* subcarton = [NSString stringWithFormat:@"%d",self.total_carton];
  2353. NSString* subweight = [NSString stringWithFormat:@"%.2f lbs",self.total_weight];
  2354. NSString* surcharge = [RAConvertor currencyNumber:self.surcharge];//[NSString stringWithFormat:@"$%@",];
  2355. NSString* totalprice = [RAConvertor currencyNumber:(self.total+self.surcharge)];//[NSString stringWithFormat:@"$%@",];
  2356. NSString* subitems = [NSString stringWithFormat:@"%d",self.total_item];
  2357. NSString* subqty = [NSString stringWithFormat:@"%d",self.total_QTY];
  2358. #ifndef SCANNER_ORDER
  2359. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2360. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2361. {
  2362. }
  2363. else
  2364. {
  2365. subtotal=nil;
  2366. }
  2367. #else
  2368. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2369. [OLDataProvider updateScanOrder:appDelegate.order_code];
  2370. #endif
  2371. self.labelTotalSurcharge.text = surcharge;
  2372. self.labelTotalPrice.text = totalprice;
  2373. self.labelTotal.text=subtotal;
  2374. self.label_cuft.text=subcuft;
  2375. self.label_carton.text=subcarton;
  2376. self.label_weight.text=subweight;
  2377. self.label_items.text = subitems;
  2378. self.label_qty.text = subqty;
  2379. self.label_notes.text = [self.notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
  2380. }
  2381. - (IBAction)onEditGeneralNotes:(id)sender {
  2382. #ifndef SCANNER_ORDER
  2383. if (![self isOrderAvailable]) {
  2384. return;
  2385. }
  2386. #endif
  2387. UIViewController* parentvc=self;
  2388. CartGeneralNotesViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"CartGeneralNotesViewController"];
  2389. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row ] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2390. vc.notes=self.notes;
  2391. // vc.delegate = parentvc.self;
  2392. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2393. vc.onSetValue = ^(NSString* notes){
  2394. self.notes = notes;
  2395. [self refresh_total];
  2396. };
  2397. //
  2398. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2399. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2400. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2401. [parentvc presentViewController:navi animated:YES completion:^{
  2402. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2403. DebugLog(@"general notes editor present.........");
  2404. // self.btop = false;
  2405. // <#code#>
  2406. }];
  2407. }
  2408. //- (IBAction)onSelectAll:(UIButton *)sender {
  2409. //
  2410. //
  2411. // NSMutableArray* arr_ids = [[NSMutableArray alloc] init];
  2412. //
  2413. //
  2414. //
  2415. //
  2416. //
  2417. //
  2418. // if([self.btnselect.titleLabel.text isEqualToString:@"Select all"])
  2419. // {
  2420. //
  2421. // long count = self.content_arr.count;// [[self.content_data valueForKey:@"count"] intValue];
  2422. // for(int i=0;i<count;i++)
  2423. // {
  2424. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy]; //[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  2425. // if(![[item_json valueForKey:@"check"] boolValue])
  2426. // [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  2427. //
  2428. // }
  2429. // [self.btnselect setTitle: @"Deselect all" forState: UIControlStateNormal];
  2430. // }
  2431. // else
  2432. // {
  2433. // long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  2434. // for(int i=0;i<count;i++)
  2435. // {
  2436. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy]; //[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  2437. // if([[item_json valueForKey:@"check"] boolValue])
  2438. // [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  2439. //
  2440. // }
  2441. // [self.btnselect setTitle: @"Select all" forState: UIControlStateNormal];
  2442. // }
  2443. //
  2444. // NSString * ids = [arr_ids componentsJoinedByString:@","];
  2445. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2446. //
  2447. //
  2448. // NSDictionary* check_json = [iSalesNetwork cart_check:ids];
  2449. //
  2450. // dispatch_async(dispatch_get_main_queue(), ^{
  2451. //
  2452. //
  2453. //
  2454. // if([[check_json valueForKey:@"result"] intValue]==2)
  2455. // {
  2456. //
  2457. // long count = self.content_arr.count;
  2458. // for(int i=0;i<count;i++)
  2459. // {
  2460. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];
  2461. // if([item_json[@"check"] boolValue])
  2462. // item_json[@"check"]= @"false";
  2463. // else
  2464. // item_json[@"check"]= @"true";
  2465. //
  2466. // self.content_arr[i] = item_json;
  2467. // //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
  2468. // }
  2469. //
  2470. // [self reload_container_getdata:false];
  2471. //
  2472. // // [self reload_data];
  2473. // }
  2474. // else
  2475. // {
  2476. // [RAUtils message_alert:[check_json valueForKey:@"err_msg"] title:nil controller:self] ;
  2477. // }
  2478. //
  2479. //
  2480. //
  2481. // });
  2482. // });
  2483. //
  2484. //
  2485. //
  2486. //
  2487. //
  2488. //
  2489. // // [self refresh_total];
  2490. // // self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  2491. // // DebugLog(self.btnselect.titleLabel.text);
  2492. // // if(self.btnselect.titleLabel.text)
  2493. //}
  2494. //#pragma mark - MODEL cell delegate
  2495. //-(void) returnQTY:(int)qty
  2496. //{
  2497. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2498. //
  2499. // int count=[[item_json valueForKey:@"count"] intValue];
  2500. //
  2501. // if(count==qty)
  2502. // return;
  2503. // [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  2504. // double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  2505. // // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2506. // [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty] forKey:@"subtotal_price"];
  2507. // self.content_arr[indexPath.row]= item_json;
  2508. // // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2509. // [self refresh_total];
  2510. // // self.total+=(unit_price*qty-sub_total);
  2511. // // self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  2512. //
  2513. //
  2514. //}
  2515. - (IBAction)OnCancelOrderClicked:(id)sender {
  2516. // if (![self isOrderAvailable]) {
  2517. // return;
  2518. // }
  2519. //
  2520. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Cancel Order" message:@"Are you sure to cancel the order in cart ?" preferredStyle:UIAlertControllerStyleAlert];
  2521. // //block代码块取代了delegate
  2522. //
  2523. //
  2524. //
  2525. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2526. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2527. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Cancel Order" completion:^{
  2528. //
  2529. //#ifdef SCANNER_ORDER
  2530. //// if(RASingleton.sharedInstance.enable_OfflineOrder)
  2531. // {
  2532. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2533. // [OLDataProvider deleteScanOrder:appDelegate.order_code];
  2534. // [appDelegate closeOrder];
  2535. // return;
  2536. // }
  2537. //#endif
  2538. // [RANetwork request_cancel_order:nil order_code:appDelegate.order_code completionHandler:^(NSMutableDictionary *result) {
  2539. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2540. // NSDictionary* return_json = result;
  2541. //
  2542. // if([[return_json valueForKey:@"result"] intValue]==2)
  2543. // {
  2544. // //if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  2545. // {
  2546. // appDelegate.order_code = nil;
  2547. // //appDelegate.user_type = 0;
  2548. // appDelegate.customerInfo = nil;
  2549. // appDelegate.contact_id = nil;
  2550. // appDelegate.order_customer_id = nil;
  2551. // [appDelegate SetSo:nil];
  2552. // appDelegate.cart_count=0;
  2553. // [appDelegate update_count_mark];
  2554. //
  2555. //
  2556. // }
  2557. // #ifdef RA_NOTIFICATION
  2558. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2559. // #else
  2560. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2561. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2562. // #endif
  2563. // //[RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  2564. // //[self ReloadData];
  2565. //
  2566. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2567. // // // appDelegate.order_code = nil;
  2568. // //
  2569. // // [appDelegate closeOrder];
  2570. // // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  2571. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  2572. //
  2573. // // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2574. // // {
  2575. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2576. // // }
  2577. // }
  2578. // else
  2579. // {
  2580. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  2581. // }
  2582. // }];
  2583. //
  2584. //
  2585. //
  2586. //
  2587. //
  2588. //
  2589. // }];
  2590. //
  2591. // }];
  2592. //
  2593. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2594. ////
  2595. //// NSDictionary* return_json = [RANetwork cancel_Order:nil order_code:appDelegate.order_code];
  2596. ////
  2597. //// dispatch_async(dispatch_get_main_queue(), ^{
  2598. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  2599. ////
  2600. ////
  2601. //// if([[return_json valueForKey:@"result"] intValue]==2)
  2602. //// {
  2603. //// //if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  2604. //// {
  2605. //// appDelegate.order_code= nil;
  2606. //// //appDelegate.user_type = 0;
  2607. //// appDelegate.customerInfo = nil;
  2608. //// appDelegate.contact_id = nil;
  2609. //// appDelegate.order_customer_id = nil;
  2610. //// [appDelegate SetSo:nil];
  2611. //// appDelegate.cart_count=0;
  2612. //// [appDelegate update_count_mark];
  2613. ////
  2614. ////
  2615. //// }
  2616. ////#ifdef RA_NOTIFICATION
  2617. //// [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2618. ////#else
  2619. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2620. //// [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2621. ////#endif
  2622. //// //[RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  2623. //// //[self ReloadData];
  2624. ////
  2625. ////// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2626. ////// // appDelegate.order_code = nil;
  2627. //////
  2628. ////// [appDelegate closeOrder];
  2629. ////// [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  2630. //// [((MainViewController*)appDelegate.main_vc) switchToHome];
  2631. ////
  2632. ////// if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2633. ////// {
  2634. ////// [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2635. ////// }
  2636. //// }
  2637. //// else
  2638. //// {
  2639. //// [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  2640. //// }
  2641. ////
  2642. ////
  2643. ////
  2644. ////
  2645. //// });
  2646. //// });
  2647. //
  2648. //
  2649. // }];
  2650. //
  2651. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2652. // DebugLog(@"No");
  2653. // }];
  2654. // [alertControl addAction:actionOne];
  2655. //
  2656. // [alertControl addAction:alertthree];
  2657. //
  2658. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  2659. //
  2660. //
  2661. // [self presentViewController:alertControl animated:YES completion:nil];
  2662. //
  2663. // DebugLog(@"%@",self.edit_select_arr);
  2664. //
  2665. //
  2666. }
  2667. #pragma mark - Private
  2668. - (BOOL)isOrderAvailable {
  2669. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2670. if (appDelegate.order_code.length == 0) {
  2671. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"please create a new order first" preferredStyle:UIAlertControllerStyleAlert];
  2672. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2673. }];
  2674. [alertVC addAction:okAction];
  2675. [self presentViewController:alertVC animated:YES completion:nil];
  2676. return NO;
  2677. }
  2678. return YES;
  2679. }
  2680. #pragma mark - commoneditor controller delegate
  2681. -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  2682. {
  2683. // [self reload_data];
  2684. if([value[@"commitorder_logout"] boolValue])
  2685. [self logout];
  2686. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  2687. }
  2688. #pragma mark - Table view data source
  2689. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  2690. {
  2691. NSDictionary * item_json = nil;
  2692. if (self.back_order_flag) {
  2693. item_json = [self itemJsonAtIndexPath:indexPath];
  2694. } else {
  2695. item_json = self.content_arr[indexPath.row ];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2696. }
  2697. NSString* notes =[item_json valueForKey:@"note"];
  2698. if(notes.length>0)
  2699. {
  2700. return 146;
  2701. }
  2702. else
  2703. return 120;
  2704. }
  2705. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  2706. //{
  2707. // return 0;
  2708. //}
  2709. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  2710. //{
  2711. // return 0;
  2712. //}
  2713. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  2714. //{
  2715. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  2716. // return myView;
  2717. //
  2718. //}
  2719. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  2720. //{
  2721. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  2722. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  2723. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  2724. //// titleLabel.textColor=[UIColor whiteColor];
  2725. //// titleLabel.backgroundColor = [UIColor clearColor];
  2726. //// if(section==0)
  2727. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  2728. //// else
  2729. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  2730. //// [titleLabel sizeToFit];
  2731. //// [myView addSubview:titleLabel];
  2732. ////
  2733. // return myView;
  2734. //}
  2735. //
  2736. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  2737. // if(section==0)
  2738. // return nil;
  2739. // else
  2740. // return @"detail section";
  2741. //}
  2742. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  2743. {
  2744. if (self.back_order_flag) {
  2745. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  2746. } else {
  2747. return 1;
  2748. }
  2749. }
  2750. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  2751. {
  2752. #ifdef SCANNER_ORDER
  2753. return 0;
  2754. #endif
  2755. if (self.back_order_flag) {
  2756. return 50;
  2757. } else {
  2758. return 0;
  2759. }
  2760. }
  2761. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  2762. {
  2763. #ifdef SCANNER_ORDER
  2764. return nil;
  2765. #endif
  2766. if (self.back_order_flag) {
  2767. // UIView *header = [tableView dequeueReusableCellWithIdentifier:@"section_header_cell"];
  2768. // UILabel *title_lb = [header viewWithTag:8520];
  2769. UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 50.0f)];
  2770. header.backgroundColor = [UIColor colorWithRed:128 / 255.0 green:95 / 255.0 blue:54 / 255.0 alpha:1];
  2771. header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  2772. UILabel *title_lb = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, CGRectGetWidth(header.bounds) - 10, 50.0f)];
  2773. title_lb.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  2774. title_lb.font = [UIFont systemFontOfSize:25.0f];
  2775. title_lb.textColor = [UIColor whiteColor];
  2776. [header addSubview:title_lb];
  2777. title_lb.text = [self titleForSection:section];
  2778. return header;
  2779. } else {
  2780. return nil;
  2781. }
  2782. }
  2783. #ifdef SCANNER_ORDER
  2784. - (IBAction)onScanChangeCustomerType:(id)sender {
  2785. return;
  2786. NSString *orderdir =[OLDataProvider getScanPath];
  2787. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  2788. //block代码块取代了delegate
  2789. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2790. NSMutableDictionary* dict = nil;
  2791. NSString* ordertemplate = nil;
  2792. if([RADataProvider getSiteHasERP])
  2793. ordertemplate =@"e_order.json";
  2794. else
  2795. ordertemplate =@"e_order_noerp.json";
  2796. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  2797. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  2798. [RAUtils dicttofile:orderPath dict:dict];
  2799. //
  2800. // NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  2801. //
  2802. //
  2803. //
  2804. // [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  2805. //
  2806. // [self scanPlaceOrder];
  2807. //
  2808. }];
  2809. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2810. NSMutableDictionary* dict = nil;
  2811. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  2812. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  2813. [RAUtils dicttofile:orderPath dict:dict];
  2814. //
  2815. //
  2816. // NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  2817. //
  2818. //
  2819. //
  2820. // [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  2821. // [self scanPlaceOrder];
  2822. }];
  2823. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2824. DebugLog(@"No");
  2825. }];
  2826. [alertControl addAction:actionOne];
  2827. [alertControl addAction:alert2];
  2828. [alertControl addAction:alertthree];
  2829. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  2830. [self presentViewController:alertControl animated:YES completion:nil];
  2831. DebugLog(@"%@",self.edit_select_arr);
  2832. }
  2833. #endif
  2834. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  2835. {
  2836. if (self.back_order_flag) {
  2837. return [self itemCountInSection:section];
  2838. } else {
  2839. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  2840. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  2841. return count;
  2842. }
  2843. }
  2844. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2845. {
  2846. // if(tableView==self.itemListTable)
  2847. // {
  2848. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2849. NSString *CellIdentifier;
  2850. #ifdef SCANNER_ORDER
  2851. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2852. CellIdentifier = @"ScanCartItemCell";
  2853. ScanCartItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2854. NSDictionary * item_json = nil;//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2855. item_json = [self itemJsonAtIndexPath:indexPath];
  2856. NSString* notes = [item_json valueForKey:@"note"];
  2857. if(notes.length>0)
  2858. {
  2859. cell.labelNotes.text = notes;
  2860. }
  2861. else
  2862. {
  2863. cell.labelNotes.text = nil;
  2864. }
  2865. NSString* description =[item_json valueForKey:@"description"];
  2866. NSString* model =[item_json valueForKey:@"model"];
  2867. NSString* dimension =[item_json valueForKey:@"dimension"] ;
  2868. int count =[[item_json valueForKey:@"count"] intValue];
  2869. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  2870. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  2871. double discount=[[item_json valueForKey:@"discount"] doubleValue];
  2872. cell.discount = discount;
  2873. if(appDelegate.user_type == USER_ROLE_CUSTOMER)
  2874. {
  2875. cell.btnScanDiscount.hidden = true;
  2876. }
  2877. else
  2878. {
  2879. switch(RASingleton.sharedInstance.price_type)
  2880. {
  2881. case 0: cell.btnScanDiscount.hidden = true;
  2882. break;;
  2883. case 1:
  2884. {
  2885. if(![item_json[@"special_price"] boolValue]&&![item_json[@"net_price"] boolValue])
  2886. cell.btnScanDiscount.hidden = false;
  2887. else
  2888. cell.btnScanDiscount.hidden = true;
  2889. }
  2890. break;;
  2891. // case 2: pricename = @"25%";
  2892. // break;
  2893. }
  2894. }
  2895. NSString* product_id = [item_json valueForKey:@"product_id"];
  2896. CGRect frame = cell.frame;
  2897. cell.labelMpack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
  2898. __weak typeof(self) weakSelf = self;
  2899. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  2900. {
  2901. int result = [[ext objectForKey:@"result"] intValue];
  2902. BOOL refresh = [[ext objectForKey:@"refresh"] boolValue];
  2903. if (result == 2 && refresh) {
  2904. [self ReloadData];
  2905. return;
  2906. }
  2907. NSMutableDictionary * item_json = nil;
  2908. if (weakSelf.back_order_flag) {
  2909. item_json = [[weakSelf itemJsonAtIndexPath:indexPath] mutableCopy];
  2910. } else {
  2911. item_json = [weakSelf.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2912. }
  2913. // int count=[[item_json valueForKey:@"count"] intValue];
  2914. // if(count==qty)
  2915. // return;
  2916. if ([[ext valueForKey:@"result"] integerValue] == 8) {
  2917. return ;
  2918. }
  2919. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  2920. double unit_cuft = [[item_json valueForKey:@"unit_cuft"] doubleValue];
  2921. [item_json setValue:[NSString stringWithFormat:@"%f",unit_cuft*qty] forKey:@"cuft"];
  2922. // [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  2923. // [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  2924. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  2925. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2926. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty*(1-discount/100.0)] forKey:@"subtotal_price"];
  2927. if (weakSelf.back_order_flag) {
  2928. [weakSelf updateItemJson:item_json atIndexPath:indexPath];
  2929. } else {
  2930. weakSelf.content_arr[indexPath.row]= item_json;
  2931. }
  2932. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2933. [weakSelf refresh_total];
  2934. #ifdef RA_NOTIFICATION
  2935. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2936. #else
  2937. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2938. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2939. #endif
  2940. };
  2941. // cell.delegate=self;
  2942. // cell.from=indexPath;
  2943. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  2944. if(RASingleton.sharedInstance.price_type==1&&([item_json[@"net_price"] boolValue]||[item_json[@"special_price"] boolValue]||discount>0))
  2945. {
  2946. cell.labelUnitPrice.textColor= [UIColor redColor];
  2947. if([item_json[@"special_price"] boolValue]||discount>0)
  2948. {
  2949. cell.labelOldPrice.hidden = false;
  2950. // if([item_json[@"special_price"] boolValue])
  2951. // {
  2952. cell.labelOldPrice.text=[RAConvertor currencyNumber:[item_json[price_group[@"price_1"][@"name"]] doubleValue]];//[NSString stringWithFormat:@"%.2f",[item_json[@"price1"] doubleValue]];
  2953. // }
  2954. // else
  2955. // {
  2956. // }
  2957. }
  2958. else
  2959. cell.labelOldPrice.hidden = true;
  2960. }
  2961. else
  2962. {
  2963. cell.labelUnitPrice.textColor= [UIColor blackColor];
  2964. cell.labelOldPrice.hidden = true;
  2965. }
  2966. // if(discount>0)
  2967. // {
  2968. // cell.labelNotes.text = [NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  2969. // cell.labelOldPrice.hidden = false;
  2970. //// cell.labelOldPrice.textColor = [UIColor redColor];
  2971. // cell.labelUnitPrice.textColor= [UIColor redColor];
  2972. // cell.labelOldPrice.text=[item_json[@"unit_price"] stringValue];
  2973. // frame.size.height = 120;
  2974. // }
  2975. // else
  2976. // {
  2977. //
  2978. //
  2979. // cell.labelOldPrice.hidden = true;
  2980. // cell.labelNotes.text = nil;
  2981. // frame.size.height = 94;
  2982. // }
  2983. cell.unit_price = unitprice;
  2984. // cell.labelAttribute.text = attribute;
  2985. // cell.labelCurrency.text = currency;
  2986. NSString* subtotal = [RAConvertor currencyNumber:unitprice*count*(1-discount/100)];//[NSString stringWithFormat:@"%.2f",unitprice*count*(1-discount/100)];
  2987. NSString* newunitprice = [RAConvertor currencyNumber:unitprice*(1-discount/100)];//[NSString stringWithFormat:@"%.2f",unitprice*(1-discount/100)];
  2988. cell.labelModel.text = model;
  2989. cell.labelDescription.text = [NSString stringWithFormat:@"%@\n%@",description,dimension];
  2990. // if(noprice&&unitprice==0.0)
  2991. // {
  2992. // cell.labelPrice.text = @"No Price";
  2993. //
  2994. // cell.labelUnitPrice.text = @"No Price";
  2995. // }
  2996. // else
  2997. {
  2998. cell.labelSubtotal.text = subtotal;
  2999. cell.labelUnitPrice.text = newunitprice;
  3000. }
  3001. bool check = [[item_json valueForKey:@"check"] boolValue];
  3002. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  3003. cell.cart_id = cart_item_id;
  3004. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  3005. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  3006. // else
  3007. // [cell init_Stepper:1 max:9999 min:1 value:count];
  3008. [cell set_Count:count];
  3009. // Button 设置了大小约束,Size就不会随内容变化
  3010. cell.backgroundColor = [UIColor whiteColor];
  3011. return cell;
  3012. #else
  3013. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3014. #ifdef BUILD_CONTRAST
  3015. CellIdentifier = @"ContrastCartItemCell";
  3016. ContrastModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3017. #else
  3018. CellIdentifier = @"CartItemCell";
  3019. ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3020. #endif
  3021. NSDictionary * item_json = nil;//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3022. if (self.back_order_flag) {
  3023. item_json = [self itemJsonAtIndexPath:indexPath];
  3024. } else {
  3025. item_json = self.content_arr[indexPath.row];
  3026. }
  3027. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  3028. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  3029. if (cell.masterBtn != nil) {
  3030. if (master_json == nil) {
  3031. cell.masterBtn.hidden = YES;
  3032. } else{
  3033. cell.masterBtn.hidden = NO;
  3034. cell.master_items = master_json;
  3035. }
  3036. }
  3037. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  3038. NSString* notes = [item_json valueForKey:@"note"];
  3039. BOOL is_out_of_stock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  3040. bool noprice =[[item_json valueForKey:@"is_no_price"]boolValue];
  3041. cell.noprice = noprice;
  3042. cell.enable_longpress = true;
  3043. cell.bundle_item=combine_json;
  3044. NSString* img_url = [item_json valueForKey:@"img_url"];
  3045. NSString* description = [item_json valueForKey:@"description"];
  3046. // NSString* identifier = [item_json valueForKey:@"identifier"];
  3047. // NSString* attribute = [item_json valueForKey:@"attribute"];
  3048. // NSString* currency = [item_json valueForKey:@"currency"];
  3049. int count =[[item_json valueForKey:@"count"] intValue];
  3050. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  3051. int mpack =[[item_json valueForKey:@"mpack"] intValue];
  3052. #ifdef BUILD_CONTRAST
  3053. cell.labelMpack.text =[NSString stringWithFormat:@"Master Pack:%d", mpack];
  3054. #endif
  3055. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3056. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  3057. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  3058. NSString* product_id = [item_json valueForKey:@"product_id"];
  3059. // handle no such model
  3060. if(product_id.length==0)
  3061. cell.labelNoSuchModel.hidden=false;
  3062. else
  3063. cell.labelNoSuchModel.hidden=true;
  3064. //if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  3065. if (!is_out_of_stock) {
  3066. cell.labelOutOfStock.hidden = YES;
  3067. } else {
  3068. cell.labelOutOfStock.hidden = NO;
  3069. }
  3070. // } else {
  3071. // cell.labelOutOfStock.hidden = YES;
  3072. // }
  3073. // discount = 5.0;
  3074. cell.discount = discount;
  3075. CGRect frame = cell.frame;
  3076. if(notes.length>0)
  3077. {
  3078. cell.labelNotes.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  3079. frame.size.height = 146;
  3080. }
  3081. else
  3082. {
  3083. cell.labelNotes.text = nil;
  3084. frame.size.height = 120;
  3085. }
  3086. // cell.frame = frame;
  3087. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  3088. if(isfree)
  3089. {
  3090. cell.labelOldPrice.hidden = false;
  3091. cell.labelOldPrice.textColor = [UIColor redColor];
  3092. cell.labelOldPrice.text=@"Free";
  3093. cell.labelOldPrice.hideline = true;
  3094. cell.labelDiscount.hidden = true;
  3095. }
  3096. else
  3097. {
  3098. cell.labelOldPrice.textColor = [UIColor blackColor];
  3099. cell.labelOldPrice.hideline = false;
  3100. if(discount==0)
  3101. {
  3102. cell.labelOldPrice.hidden = true;
  3103. cell.labelDiscount.hidden = true;
  3104. }
  3105. else
  3106. {
  3107. cell.labelOldPrice.hidden = false;
  3108. cell.labelDiscount.hidden = false;
  3109. }
  3110. }
  3111. __weak typeof(self) weakSelf = self;
  3112. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  3113. {
  3114. int result = [[ext objectForKey:@"result"] intValue];
  3115. BOOL refresh = [[ext objectForKey:@"refresh"] boolValue];
  3116. if (result == 2 && refresh) {
  3117. [self ReloadData];
  3118. return;
  3119. }
  3120. NSMutableDictionary * item_json = nil;
  3121. if (weakSelf.back_order_flag) {
  3122. item_json = [[weakSelf itemJsonAtIndexPath:indexPath] mutableCopy];
  3123. } else {
  3124. item_json = [weakSelf.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3125. }
  3126. // int count=[[item_json valueForKey:@"count"] intValue];
  3127. // if(count==qty)
  3128. // return;
  3129. if ([[ext valueForKey:@"result"] integerValue] == 8) {
  3130. return ;
  3131. }
  3132. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  3133. [item_json setValue:[ext valueForKey:@"cuft"] forKey:@"cuft"];
  3134. [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  3135. [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  3136. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  3137. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3138. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty] forKey:@"subtotal_price"];
  3139. if (weakSelf.back_order_flag) {
  3140. [weakSelf updateItemJson:item_json atIndexPath:indexPath];
  3141. } else {
  3142. weakSelf.content_arr[indexPath.row]= item_json;
  3143. }
  3144. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3145. [weakSelf refresh_total];
  3146. #ifdef RA_NOTIFICATION
  3147. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3148. #else
  3149. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3150. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3151. #endif
  3152. };
  3153. // cell.delegate=self;
  3154. // cell.from=indexPath;
  3155. cell.unit_price = unitprice;
  3156. // cell.labelAttribute.text = attribute;
  3157. // cell.labelCurrency.text = currency;
  3158. NSString* oldprice =[NSString stringWithFormat:@"%.2f",unitprice];
  3159. NSString* newprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)*count];
  3160. NSString* newunitprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
  3161. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  3162. {
  3163. }
  3164. else
  3165. {
  3166. oldprice=nil;
  3167. newprice=nil;
  3168. newunitprice=nil;
  3169. }
  3170. cell.labelDiscount.text = discountstr;
  3171. cell.labelOldPrice.text = oldprice;
  3172. cell.labelMasterpack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
  3173. cell.labelDescription.text = description;
  3174. // cell.labelIdentifier.text = identifier;
  3175. if(noprice&&unitprice==0.0)
  3176. {
  3177. cell.labelPrice.text = @"No Price";
  3178. cell.labelUnitPrice.text = @"No Price";
  3179. }
  3180. else
  3181. {
  3182. cell.labelPrice.text = newprice;
  3183. cell.labelUnitPrice.text = newunitprice;
  3184. }
  3185. bool check = [[item_json valueForKey:@"check"] boolValue];
  3186. if(check)
  3187. {
  3188. cell.img_checkmark.hidden=false;
  3189. // [item_json setValue:@"0" forKey:@"check"];
  3190. }
  3191. else
  3192. {
  3193. // [item_json setValue:@"1" forKey:@"check"];
  3194. cell.img_checkmark.hidden=true;
  3195. }
  3196. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  3197. cell.cart_id = cart_item_id;
  3198. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  3199. {
  3200. #ifdef BUILD_CONTRAST
  3201. [cell init_Stepper:stockUom max:9999 min:1 value:count];
  3202. #else
  3203. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  3204. #endif
  3205. }
  3206. // else
  3207. // [cell init_Stepper:1 max:9999 min:1 value:count];
  3208. [cell set_Count:count];
  3209. // Button 设置了大小约束,Size就不会随内容变化
  3210. [cell.btnImage setContentMode:UIViewContentModeScaleAspectFit];
  3211. [cell.btnImage setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  3212. [cell.btnImage setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  3213. [cell.btnImage setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  3214. cell.btnImage.imageView.contentMode = UIViewContentModeScaleAspectFit;
  3215. if (![cell.imageName isEqualToString:img_url]) {
  3216. cell.imageName = img_url;
  3217. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  3218. [cell.btnImage setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  3219. NSString* file_name=[img_url lastPathComponent];
  3220. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  3221. if(img_data!=nil)
  3222. {
  3223. UIImage * img =[UIImage imageWithData:img_data];
  3224. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  3225. [cell.btnImage setImage:img forState:UIControlStateNormal];
  3226. }
  3227. else
  3228. {
  3229. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3230. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  3231. dispatch_async(dispatch_get_main_queue(), ^{
  3232. if(downloadimg_data!=nil)
  3233. {
  3234. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  3235. UIImage * img =[UIImage imageWithData:downloadimg_data];
  3236. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  3237. [cell.btnImage setImage:img forState:UIControlStateNormal];
  3238. }
  3239. else
  3240. {
  3241. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  3242. [cell.btnImage setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  3243. }
  3244. });
  3245. });
  3246. }
  3247. }
  3248. cell.backgroundColor = [UIColor whiteColor];
  3249. if(self.itemListTable.editing)
  3250. {
  3251. cell.editCount.enabled = false;
  3252. cell.stepper.hidden=true;
  3253. }
  3254. else
  3255. {
  3256. cell.editCount.enabled=true;
  3257. cell.stepper.hidden=false;
  3258. }
  3259. return cell;
  3260. // }
  3261. // else
  3262. // {
  3263. // NSString *CellIdentifier = @"OrderInfoListItem";
  3264. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3265. // return cell;
  3266. // }
  3267. #endif
  3268. }
  3269. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
  3270. {
  3271. if(!self.itemListTable.editing)
  3272. return;
  3273. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3274. NSMutableDictionary * item_json = nil;
  3275. if (self.back_order_flag) {
  3276. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3277. } else {
  3278. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3279. }
  3280. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3281. if ([self.edit_select_arr containsObject:cart_item_id])
  3282. {
  3283. [self.edit_select_arr removeObject:cart_item_id];
  3284. }
  3285. }
  3286. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  3287. {
  3288. #ifdef SCANNER_ORDER
  3289. return;
  3290. #endif
  3291. NSMutableDictionary * item_json = nil;
  3292. if (self.back_order_flag) {
  3293. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3294. } else {
  3295. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3296. }
  3297. // NSMutableDictionary * item_json =[self.content_arr[indexPath.row] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3298. if(self.itemListTable.editing)
  3299. {
  3300. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3301. if (![self.edit_select_arr containsObject:cart_item_id]) {
  3302. [self.edit_select_arr addObject:cart_item_id];
  3303. }
  3304. return;
  3305. }
  3306. // no checkmark support anymore for cart
  3307. return;
  3308. // ModelItemCell* cell = (ModelItemCell*)[tableView cellForRowAtIndexPath:indexPath];
  3309. //
  3310. //
  3311. // cell.selected = false;
  3312. // // self.dirty = true;
  3313. //
  3314. //
  3315. // bool check = [[item_json valueForKey:@"check"] boolValue];
  3316. // if(check)
  3317. // {
  3318. // [item_json setValue:@"false" forKey:@"check"];
  3319. // cell.img_checkmark.hidden=true;
  3320. // [self.btnselect setTitle: @"Select all" forState: UIControlStateNormal];
  3321. // // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3322. // // self.total-=totalprice;
  3323. // }
  3324. // else
  3325. // {
  3326. // [item_json setValue:@"true" forKey:@"check"];
  3327. // cell.img_checkmark.hidden=false;
  3328. // // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3329. // // self.total+=totalprice;
  3330. // }
  3331. //
  3332. //
  3333. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3334. //
  3335. //
  3336. // NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3337. //
  3338. // NSDictionary* check_json = [iSalesNetwork cart_check:ids];
  3339. //
  3340. // dispatch_async(dispatch_get_main_queue(), ^{
  3341. //
  3342. //
  3343. //
  3344. // if([[check_json valueForKey:@"result"] intValue]==2)
  3345. // {
  3346. //
  3347. //
  3348. // if([item_json[@"check"] boolValue]==false)
  3349. // item_json[@"check"]= @"false";
  3350. // else
  3351. // item_json[@"check"]= @"true";
  3352. //
  3353. // self.content_arr[indexPath.row] = item_json;
  3354. // //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3355. //
  3356. //
  3357. // [self reload_container_getdata:false];
  3358. //
  3359. //
  3360. // }
  3361. // else
  3362. // {
  3363. // [RAUtils message_alert:[check_json valueForKey:@"err_msg"] title:nil controller:self] ;
  3364. // }
  3365. //
  3366. //
  3367. //
  3368. // });
  3369. // });
  3370. //
  3371. // //debug
  3372. // //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3373. //
  3374. // [self refresh_total];
  3375. //self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  3376. }
  3377. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  3378. if(self.itemListTable.editing)
  3379. return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
  3380. else
  3381. return UITableViewCellEditingStyleDelete;
  3382. }
  3383. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  3384. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  3385. {
  3386. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3387. // 添加一个删除按钮
  3388. self.indexPath=indexPath;
  3389. NSMutableDictionary * item_json = nil;
  3390. if (self.back_order_flag) {
  3391. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3392. } else {
  3393. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3394. }
  3395. NSString* productID = [item_json valueForKey:@"product_id"];
  3396. BOOL outOfStock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  3397. __weak typeof(self) weakself = self;
  3398. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@" Delete " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3399. DebugLog(@"delete click");
  3400. //[self.itemListTable setEditing:false animated:YES];
  3401. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Confirm Deletion" message:@"Are you sure to delete this model?" preferredStyle:UIAlertControllerStyleAlert];
  3402. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3403. // [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3404. NSMutableDictionary * item_json = nil;
  3405. if (self.back_order_flag) {
  3406. item_json = [[self itemJsonAtIndexPath:self.indexPath] mutableCopy];
  3407. } else {
  3408. item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3409. }
  3410. NSString *ids=[NSString stringWithFormat:@"%@",[item_json valueForKey:@"cart_item_id"] ];
  3411. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Model" completion:^{
  3412. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  3413. NSMutableDictionary* cart_json = result;
  3414. [waitalert dismissViewControllerAnimated:YES completion:^{
  3415. if([[cart_json valueForKey:@"result"] intValue]==2)
  3416. {
  3417. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3418. if (self.back_order_flag) {
  3419. NSInteger section_count = [self sectionCount];
  3420. for (int i = 0; i < section_count; i++) {
  3421. NSInteger item_count = [self itemCountInSection:i];
  3422. BOOL ready_break = NO;
  3423. for (int j = 0; j < item_count; j++) {
  3424. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  3425. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  3426. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3427. if([_id isEqualToString:ids])
  3428. {
  3429. [self updateItemJson:nil atIndexPath:indexPath];
  3430. ready_break = YES;
  3431. break;
  3432. }
  3433. }
  3434. if (ready_break) {
  3435. break;
  3436. }
  3437. }
  3438. } else {
  3439. for(int i=0;i<self.content_arr.count;i++)
  3440. {
  3441. NSDictionary* obj_json = self.content_arr[i];
  3442. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3443. if([_id isEqualToString:ids])
  3444. {
  3445. [self.content_arr removeObjectAtIndex:i];
  3446. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3447. break;
  3448. // appDelegate.cart_count--;
  3449. // [appDelegate update_count_mark];
  3450. }
  3451. }
  3452. }
  3453. #ifdef SCANNER_ORDER
  3454. self.cart_json = cart_json;
  3455. #endif
  3456. [self.itemListTable reloadData];
  3457. [self refresh_total];
  3458. #ifdef RA_NOTIFICATION
  3459. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3460. #else
  3461. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3462. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3463. #endif
  3464. // [self reload_data];
  3465. }
  3466. else
  3467. {
  3468. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  3469. }
  3470. }];
  3471. }];
  3472. }];
  3473. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3474. //
  3475. // NSDictionary* cart_json = [RANetwork cart_remove:ids];
  3476. //
  3477. // dispatch_async(dispatch_get_main_queue(), ^{
  3478. //
  3479. //
  3480. //
  3481. // if([[cart_json valueForKey:@"result"] intValue]==2)
  3482. // {
  3483. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3484. // if (self.back_order_flag) {
  3485. //
  3486. // NSInteger section_count = [self sectionCount];
  3487. // for (int i = 0; i < section_count; i++) {
  3488. // NSInteger item_count = [self itemCountInSection:i];
  3489. // BOOL ready_break = NO;
  3490. //
  3491. // for (int j = 0; j < item_count; j++) {
  3492. // NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  3493. // NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  3494. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3495. // if([_id isEqualToString:ids])
  3496. // {
  3497. // [self updateItemJson:nil atIndexPath:indexPath];
  3498. // ready_break = YES;
  3499. // break;
  3500. // }
  3501. // }
  3502. //
  3503. // if (ready_break) {
  3504. // break;
  3505. // }
  3506. // }
  3507. //
  3508. // } else {
  3509. // for(int i=0;i<self.content_arr.count;i++)
  3510. // {
  3511. // NSDictionary* obj_json = self.content_arr[i];
  3512. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3513. // if([_id isEqualToString:ids])
  3514. // {
  3515. // [self.content_arr removeObjectAtIndex:i];
  3516. // // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3517. // break;
  3518. // // appDelegate.cart_count--;
  3519. // // [appDelegate update_count_mark];
  3520. // }
  3521. //
  3522. // }
  3523. // }
  3524. // [self.itemListTable reloadData];
  3525. // [self refresh_total];
  3526. // #ifdef RA_NOTIFICATION
  3527. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3528. // #else
  3529. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3530. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3531. // #endif
  3532. // // [self reload_data];
  3533. // }
  3534. // else
  3535. // {
  3536. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  3537. // }
  3538. //
  3539. // });
  3540. // });
  3541. }];
  3542. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  3543. }];
  3544. [alertController addAction:action_2];
  3545. [alertController addAction:action_3];
  3546. [self presentViewController:alertController animated:YES completion:nil];
  3547. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Delete confirm", nil) message:NSLocalizedString(@"Are you sure remove model from cart?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  3548. // alert.tag = ALERT_DEL;
  3549. // // alert.
  3550. // [alert show];
  3551. }];
  3552. deleteRowAction.backgroundColor = [UIColor redColor];
  3553. UITableViewRowAction *notifyMeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Notify Me" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  3554. {
  3555. __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  3556. [RANetwork request_notifymodel:productID emailAddr:nil withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  3557. NSMutableDictionary *dic = result;
  3558. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  3559. [waitting_alert dismissViewControllerAnimated:YES completion:^{
  3560. int result_code = [[dic valueForKey:@"result"] intValue];
  3561. if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS)
  3562. {
  3563. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  3564. if ([dic valueForKey:@"err_msg"]) {
  3565. msg = [dic valueForKey:@"err_msg"];
  3566. }
  3567. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  3568. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3569. }];
  3570. [errorAlertVC addAction:action];
  3571. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  3572. } else if (result_code == RESULT_TRUE){
  3573. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  3574. } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
  3575. [weakself showAddressBoxToEmailProduct:productID];
  3576. }
  3577. }];
  3578. }];
  3579. }];
  3580. // dispatch_async(dispatch_get_global_queue(0,0), ^{
  3581. //
  3582. // NSDictionary *dic = [RANetwork notifyModel:productID emailAddr:nil withScreen:ScreenCodeCart];
  3583. //
  3584. // dispatch_async(dispatch_get_main_queue(), ^{
  3585. //
  3586. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  3587. //
  3588. // NSInteger result = [[dic valueForKey:@"result"] integerValue];
  3589. //
  3590. // if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
  3591. //
  3592. // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  3593. //
  3594. // if ([dic valueForKey:@"err_msg"]) {
  3595. // msg = [dic valueForKey:@"err_msg"];
  3596. // }
  3597. //
  3598. //
  3599. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  3600. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3601. //
  3602. // }];
  3603. //
  3604. // [errorAlertVC addAction:action];
  3605. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  3606. //
  3607. // } else if (result == RESULT_TRUE){
  3608. //
  3609. // [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  3610. //
  3611. // } else if (result == RESULT_NO_EMAIL_ADDRESS) {
  3612. //
  3613. // [weakself showAddressBoxToEmailProduct:productID];
  3614. //
  3615. // }
  3616. // });
  3617. //
  3618. //
  3619. // });
  3620. };
  3621. }];
  3622. notifyMeAction.backgroundColor = UIColorFromRGB(0x9BBF5A);
  3623. UITableViewRowAction *addWatchAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Move To Wish List" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3624. DebugLog(@"Wishlist click");
  3625. NSMutableDictionary * item_json = nil;
  3626. if (self.back_order_flag) {
  3627. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3628. } else {
  3629. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3630. }
  3631. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  3632. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3633. [RANetwork request_move_cart2wish:cart_item_id completionHandler:^(NSMutableDictionary *result) {
  3634. NSDictionary* return_json = result;
  3635. if([[return_json valueForKey:@"result"] intValue]==2)
  3636. {
  3637. #ifdef RA_NOTIFICATION
  3638. [ActiveViewController Notify:@"WatchListViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3639. #else
  3640. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3641. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  3642. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3643. #endif
  3644. for(int i=0;i<self.content_arr.count;i++)
  3645. {
  3646. NSDictionary* obj_json = self.content_arr[i];
  3647. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3648. if([_id isEqualToString:cart_item_id])
  3649. {
  3650. if (self.back_order_flag) {
  3651. [self updateItemJson:nil atIndexPath:indexPath];
  3652. } else {
  3653. [self.content_arr removeObjectAtIndex:i];
  3654. }
  3655. [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3656. appDelegate.cart_count--;
  3657. [appDelegate update_count_mark];
  3658. [self refresh_total];
  3659. }
  3660. }
  3661. [self.itemListTable reloadData];
  3662. }
  3663. else
  3664. {
  3665. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  3666. }
  3667. }];
  3668. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3669. //// ModelItemCell* cell=[self.itemListTable cellForRowAtIndexPath:indexPath];
  3670. //// [cell cancel_setQTY];
  3671. //
  3672. // NSDictionary* return_json = [RANetwork move_cart2wish:cart_item_id ];
  3673. //
  3674. // dispatch_async(dispatch_get_main_queue(), ^{
  3675. //
  3676. // if([[return_json valueForKey:@"result"] intValue]==2)
  3677. // {
  3678. //
  3679. //
  3680. //
  3681. //
  3682. //
  3683. //
  3684. //#ifdef RA_NOTIFICATION
  3685. // [ActiveViewController Notify:@"WatchListViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3686. //#else
  3687. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3688. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  3689. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3690. //
  3691. //#endif
  3692. //
  3693. //
  3694. // for(int i=0;i<self.content_arr.count;i++)
  3695. // {
  3696. // NSDictionary* obj_json = self.content_arr[i];
  3697. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3698. // if([_id isEqualToString:cart_item_id])
  3699. // {
  3700. // if (self.back_order_flag) {
  3701. // [self updateItemJson:nil atIndexPath:indexPath];
  3702. // } else {
  3703. // [self.content_arr removeObjectAtIndex:i];
  3704. // }
  3705. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3706. // appDelegate.cart_count--;
  3707. // [appDelegate update_count_mark];
  3708. //
  3709. //
  3710. // [self refresh_total];
  3711. // }
  3712. //
  3713. // }
  3714. //
  3715. // [self.itemListTable reloadData];
  3716. //
  3717. // }
  3718. // else
  3719. // {
  3720. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  3721. // }
  3722. //
  3723. //
  3724. //
  3725. // });
  3726. // });
  3727. }];
  3728. addWatchAction.backgroundColor = UIColorFromRGB(0x339966);
  3729. // 添加一个编辑按钮
  3730. UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Edit Price"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3731. DebugLog(@"edit click");
  3732. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  3733. if (self.currentOrderIsMerged) { // 合并过的订单不能编辑价格
  3734. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Purchase Order Can't Edit Price" preferredStyle:UIAlertControllerStyleAlert];
  3735. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  3736. [alert dismissViewControllerAnimated:YES completion:nil];
  3737. }];
  3738. [alert addAction:action];
  3739. if (weakself) {
  3740. __strong typeof(weakself) strongself = weakself;
  3741. [strongself presentViewController:alert animated:YES completion:nil];
  3742. }
  3743. return ;
  3744. }
  3745. if ([RASingleton sharedInstance].npd_shop_price_type == 0) { // 提货价不能编辑价格
  3746. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current Price Type is %@,You Can't Change it",[RASingleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  3747. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  3748. [alert dismissViewControllerAnimated:YES completion:nil];
  3749. }];
  3750. [alert addAction:action];
  3751. if (weakself) {
  3752. __strong typeof(weakself) strongself = weakself;
  3753. [strongself presentViewController:alert animated:YES completion:nil];
  3754. }
  3755. return ;
  3756. }
  3757. }
  3758. UIViewController* parentvc=self;
  3759. EditModelPriceViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"EditModelPriceViewController"];
  3760. NSMutableDictionary * item_json = nil;
  3761. if (self.back_order_flag) {
  3762. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3763. } else {
  3764. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3765. }
  3766. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  3767. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  3768. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3769. __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  3770. // vc.delegate = parentvc.self;
  3771. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  3772. vc.onSetValue = ^(double price,double discount){
  3773. bool bmodify=false;
  3774. if(price!= [[item_json valueForKey:@"unit_price"] floatValue])
  3775. bmodify=true;
  3776. NSString* notes = [item_json valueForKey:@"note"];
  3777. if(notes.length==0)
  3778. notes=@"";
  3779. if(bmodify)
  3780. {
  3781. if([notes isEqualToString:@""])
  3782. notes=@"PRICE MODIFIED";
  3783. NSRange range;
  3784. range = [notes rangeOfString:@"PRICE MODIFIED"];
  3785. if (range.location != NSNotFound) {
  3786. }else{
  3787. notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  3788. }
  3789. }
  3790. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  3791. [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:notes completionHandler:^(NSMutableDictionary *result) {
  3792. NSDictionary* cart_json = result;
  3793. [waitalert dismissViewControllerAnimated:YES completion:^{
  3794. if([[cart_json valueForKey:@"result"] intValue]==2)
  3795. {
  3796. [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  3797. [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  3798. [item_json setValue:notes forKey:@"note"];
  3799. if (self.back_order_flag) {
  3800. [self updateItemJson:item_json atIndexPath:indexPath];
  3801. } else {
  3802. self.content_arr[indexPath.row ] = item_json;
  3803. }
  3804. tableView.editing = false;
  3805. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3806. // [self refresh_total];
  3807. [weakself reload_data];
  3808. #ifdef RA_NOTIFICATION
  3809. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3810. #else
  3811. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3812. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3813. #endif
  3814. }
  3815. else
  3816. {
  3817. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  3818. }
  3819. }];
  3820. }];
  3821. }];
  3822. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3823. //
  3824. //
  3825. //
  3826. // NSDictionary* cart_json = nil;
  3827. //
  3828. // cart_json = [RANetwork cart_setPrice:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]] price:price discount:discount notes:notes];
  3829. //
  3830. // dispatch_async(dispatch_get_main_queue(), ^{
  3831. //
  3832. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  3833. //
  3834. // if([[cart_json valueForKey:@"result"] intValue]==2)
  3835. // {
  3836. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  3837. //
  3838. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  3839. // [item_json setValue:notes forKey:@"note"];
  3840. // if (self.back_order_flag) {
  3841. // [self updateItemJson:item_json atIndexPath:indexPath];
  3842. // } else {
  3843. // self.content_arr[indexPath.row ] = item_json;
  3844. // }
  3845. // tableView.editing = false;
  3846. //// [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3847. //// [self refresh_total];
  3848. //
  3849. //
  3850. // [weakself reload_data];
  3851. //
  3852. //#ifdef RA_NOTIFICATION
  3853. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3854. //#else
  3855. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3856. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3857. //#endif
  3858. // }
  3859. // else
  3860. // {
  3861. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  3862. // }
  3863. //
  3864. //
  3865. //
  3866. //
  3867. // });
  3868. // });
  3869. // [self reload_data];//[main_vc checklogin:true];
  3870. };
  3871. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  3872. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  3873. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  3874. [parentvc presentViewController:navi animated:YES completion:^{
  3875. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  3876. DebugLog(@"EditModelPriceViewController present.........");
  3877. // self.btop = false;
  3878. // <#code#>
  3879. }];
  3880. // [self.itemListTable setEditing:false animated:YES];
  3881. //[tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3882. }];
  3883. editRowAction.backgroundColor = UIColorFromRGB(0xff9933);
  3884. // // 添加一个更多按钮
  3885. //
  3886. // UITableViewRowAction *moreRowAction = [UITableView RowActionrowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3887. //
  3888. // DebugLog(@点击了更多);
  3889. //
  3890. //
  3891. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3892. //
  3893. // }];
  3894. //
  3895. // moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
  3896. //
  3897. // 将设置好的按钮放到数组中返回
  3898. // UITableViewRowAction *freeRowAction = nil;
  3899. //
  3900. //
  3901. // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3902. //
  3903. // bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  3904. //
  3905. // if(!isfree)
  3906. // {
  3907. //
  3908. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Set Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3909. //
  3910. // DebugLog(@"free click");
  3911. //
  3912. //
  3913. //
  3914. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Free give away confirm", nil) message:NSLocalizedString(@"Are you sure make this model free?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  3915. // alert.tag = ALERT_SET_FREE;
  3916. // // alert.
  3917. // [alert show];
  3918. // }];
  3919. // }
  3920. // else
  3921. // {
  3922. //
  3923. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Not Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3924. //
  3925. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Restore free model confirm", nil) message:NSLocalizedString(@"Are you sure restore free model?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  3926. // alert.tag = ALERT_RESTORE_FREE;
  3927. // // alert.
  3928. // [alert show];
  3929. // }];
  3930. // }
  3931. //
  3932. //
  3933. //
  3934. // freeRowAction.backgroundColor = [UIColor lightGrayColor];
  3935. UITableViewRowAction *noteRowAction = nil;
  3936. // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3937. noteRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Edit note" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3938. DebugLog(@"item note click");
  3939. UIViewController* parentvc=self;
  3940. ItemNotesViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"ItemNotesViewController"];
  3941. NSMutableDictionary * item_json = nil;
  3942. if (self.back_order_flag) {
  3943. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3944. } else {
  3945. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3946. }
  3947. vc.onSaveNote=^(NSString* notes){
  3948. [item_json setValue:notes forKey:@"note"];
  3949. if (self.back_order_flag) {
  3950. [self updateItemJson:item_json atIndexPath:indexPath];
  3951. } else {
  3952. self.content_arr[indexPath.row ] = item_json;
  3953. }
  3954. tableView.editing = false;
  3955. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3956. };
  3957. vc.notes=[item_json valueForKey:@"note"];
  3958. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3959. // vc.delegate = parentvc.self;
  3960. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  3961. // vc.onSetValue = ^(){
  3962. // [self reload_data];//[main_vc checklogin:true];
  3963. // };
  3964. //
  3965. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  3966. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  3967. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  3968. [parentvc presentViewController:navi animated:YES completion:^{
  3969. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  3970. DebugLog(@"EditModelPriceViewController present.........");
  3971. // self.btop = false;
  3972. // <#code#>
  3973. }];
  3974. // [self.itemListTable setEditing:false animated:YES];
  3975. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3976. }];
  3977. noteRowAction.backgroundColor = [UIColor lightGrayColor];
  3978. UITableViewRowAction *move2BackAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Move to Back Order" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  3979. NSDictionary *item_json = [self itemJsonAtIndexPath:indexPath];
  3980. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  3981. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move To Back Order" completion:^{
  3982. [RANetwork request_movetobackorder:cart_item_id completionHandler:^(NSMutableDictionary *result) {
  3983. NSMutableDictionary* return_json =result ;
  3984. [waitalert dismissViewControllerAnimated:YES completion:^{
  3985. if([[return_json valueForKey:@"result"] intValue]==2) {
  3986. [self reload_data];
  3987. } // if 2
  3988. else {
  3989. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Back Order" controller:self] ;
  3990. }
  3991. }];
  3992. }];
  3993. }];
  3994. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3995. //
  3996. // NSDictionary* return_json = [RANetwork movetobackorder:cart_item_id];
  3997. //
  3998. // dispatch_async(dispatch_get_main_queue(), ^{
  3999. //
  4000. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  4001. //
  4002. // if([[return_json valueForKey:@"result"] intValue]==2) {
  4003. //
  4004. // [self reload_data];
  4005. //
  4006. // } // if 2
  4007. // else {
  4008. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Back Order" controller:self] ;
  4009. // }
  4010. //
  4011. // }); // main
  4012. //
  4013. // }); // global
  4014. }];
  4015. move2BackAction.backgroundColor = UIColorFromRGB(0x336699);
  4016. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  4017. {
  4018. NSMutableDictionary * item_json = nil;
  4019. if (self.back_order_flag) {
  4020. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  4021. } else {
  4022. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  4023. }
  4024. NSString* product_id = [item_json valueForKey:@"product_id"];
  4025. int is_rate = [item_json[@"is_rate"] intValue];
  4026. NSMutableArray* arr=[@[] mutableCopy];
  4027. BOOL condition = outOfStock;
  4028. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  4029. #ifdef OFFLINE_MODE
  4030. condition = !appDelegate.offline_mode && outOfStock;
  4031. #endif
  4032. if (condition) {
  4033. [arr addObject:notifyMeAction];
  4034. }
  4035. NSDictionary *section_json = [self jsonAtSection:indexPath.section];
  4036. BOOL available = [[section_json objectForKey:@"available"] boolValue]; // available list
  4037. if (self.back_order_flag && available) {
  4038. [arr addObject:move2BackAction];
  4039. }
  4040. #endif
  4041. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  4042. #ifdef OFFLINE_MODE
  4043. condition = !appDelegate.offline_mode && outOfStock;
  4044. #endif
  4045. if (condition) {
  4046. [arr addObject:notifyMeAction];
  4047. }
  4048. #endif
  4049. if(product_id.length>0)
  4050. [arr addObject:noteRowAction];
  4051. [arr addObject:deleteRowAction];
  4052. #ifndef SCANNER_ORDER
  4053. if(product_id.length>0&& is_rate==0)
  4054. [arr addObject:addWatchAction];
  4055. if(appDelegate.can_set_cart_price && product_id.length>0&& is_rate==0)
  4056. {
  4057. [arr addObject:editRowAction];
  4058. // [arr addObject:freeRowAction];
  4059. }
  4060. #endif
  4061. return arr;
  4062. // return @[deleteRowAction,addWatchAction, editRowAction,freeRowAction];
  4063. } else if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  4064. if (appDelegate.customer_type == CustomerTypeStore) {
  4065. #ifndef SCANNER_ORDER
  4066. return @[notifyMeAction,deleteRowAction,addWatchAction,editRowAction];
  4067. #else
  4068. return @[deleteRowAction];
  4069. #endif
  4070. } else {
  4071. // normal
  4072. // NSArray *actionArray = @[notifyMeAction,deleteRowAction,addWatchAction];
  4073. NSMutableArray *actionArray = [NSMutableArray array];
  4074. // move to backorder
  4075. NSDictionary *section_json = [self jsonAtSection:indexPath.section];
  4076. BOOL available = [[section_json objectForKey:@"available"] boolValue]; // available list
  4077. if (self.back_order_flag && available) {
  4078. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction];
  4079. [actionArray addObject:move2BackAction];
  4080. }
  4081. [actionArray addObjectsFromArray:@[notifyMeAction,deleteRowAction,addWatchAction]];
  4082. // edit price
  4083. NSMutableDictionary * item_json = nil;
  4084. if (self.back_order_flag) {
  4085. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  4086. } else {
  4087. item_json = [self.content_arr[indexPath.row] mutableCopy];
  4088. }
  4089. NSString* product_id = [item_json valueForKey:@"product_id"];
  4090. int is_rate = [item_json[@"is_rate"] intValue];
  4091. if(appDelegate.can_set_cart_price && product_id.length>0&& is_rate==0) {
  4092. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction,editRowAction];
  4093. [actionArray addObject:editRowAction];
  4094. }
  4095. return actionArray;
  4096. }
  4097. }
  4098. else
  4099. #ifndef SCANNER_ORDER
  4100. return @[deleteRowAction,addWatchAction];
  4101. #else
  4102. return @[deleteRowAction];
  4103. #endif
  4104. }
  4105. - (void)tableView:(UITableView *)tableView
  4106. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  4107. // NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  4108. //
  4109. // NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  4110. //
  4111. //
  4112. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4113. //
  4114. // NSDictionary* cart_json = [iSalesNetwork cart_remove:ids];
  4115. //
  4116. // dispatch_async(dispatch_get_main_queue(), ^{
  4117. //
  4118. //
  4119. //
  4120. // if(cart_json!=nil)
  4121. // {
  4122. //
  4123. // [self reload_data];
  4124. // }
  4125. //
  4126. // });
  4127. // });
  4128. // sqlite3* db = [ApexMobileDB get_db];
  4129. // NSString* sql = [NSString stringWithFormat:@"delete from history where _id=%@",[self.data.pagedata[indexPath.row] valueForKey:@"_id"]];
  4130. // [ApexMobileDB execSql:sql db:db];
  4131. // [iSalesDB close_db:db];
  4132. //
  4133. // [self.data.pagedata removeObjectAtIndex:indexPath.row];
  4134. //
  4135. // [tableView reloadData];
  4136. }
  4137. //#pragma mark - UIAlertViewDelegate
  4138. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  4139. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  4140. //{
  4141. //
  4142. // if(alertView.tag==ALERT_DEL)
  4143. // {
  4144. // if(buttonIndex!=alertView.cancelButtonIndex)
  4145. // {
  4146. // // [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  4147. // NSMutableDictionary * item_json = nil;
  4148. // if (self.back_order_flag) {
  4149. // item_json = [[self itemJsonAtIndexPath:self.indexPath] mutableCopy];
  4150. // } else {
  4151. // item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  4152. //
  4153. // }
  4154. //
  4155. // NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  4156. // [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  4157. // NSMutableDictionary* cart_json = result;
  4158. //
  4159. //
  4160. //
  4161. //
  4162. // if([[cart_json valueForKey:@"result"] intValue]==2)
  4163. // {
  4164. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4165. // if (self.back_order_flag) {
  4166. //
  4167. // NSInteger section_count = [self sectionCount];
  4168. // for (int i = 0; i < section_count; i++) {
  4169. // NSInteger item_count = [self itemCountInSection:i];
  4170. // BOOL ready_break = NO;
  4171. //
  4172. // for (int j = 0; j < item_count; j++) {
  4173. // NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4174. // NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  4175. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4176. // if([_id isEqualToString:ids])
  4177. // {
  4178. // [self updateItemJson:nil atIndexPath:indexPath];
  4179. // ready_break = YES;
  4180. // break;
  4181. // }
  4182. // }
  4183. //
  4184. // if (ready_break) {
  4185. // break;
  4186. // }
  4187. // }
  4188. //
  4189. // } else {
  4190. // for(int i=0;i<self.content_arr.count;i++)
  4191. // {
  4192. // NSDictionary* obj_json = self.content_arr[i];
  4193. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4194. // if([_id isEqualToString:ids])
  4195. // {
  4196. // [self.content_arr removeObjectAtIndex:i];
  4197. // // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  4198. // break;
  4199. // // appDelegate.cart_count--;
  4200. // // [appDelegate update_count_mark];
  4201. // }
  4202. //
  4203. // }
  4204. // }
  4205. // [self.itemListTable reloadData];
  4206. // [self refresh_total];
  4207. //#ifdef RA_NOTIFICATION
  4208. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4209. //#else
  4210. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4211. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4212. //#endif
  4213. // // [self reload_data];
  4214. // }
  4215. // else
  4216. // {
  4217. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  4218. // }
  4219. //
  4220. //
  4221. // }];
  4222. //
  4223. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4224. ////
  4225. //// NSDictionary* cart_json = [RANetwork cart_remove:ids];
  4226. ////
  4227. //// dispatch_async(dispatch_get_main_queue(), ^{
  4228. ////
  4229. ////
  4230. ////
  4231. //// if([[cart_json valueForKey:@"result"] intValue]==2)
  4232. //// {
  4233. //// // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4234. //// if (self.back_order_flag) {
  4235. ////
  4236. //// NSInteger section_count = [self sectionCount];
  4237. //// for (int i = 0; i < section_count; i++) {
  4238. //// NSInteger item_count = [self itemCountInSection:i];
  4239. //// BOOL ready_break = NO;
  4240. ////
  4241. //// for (int j = 0; j < item_count; j++) {
  4242. //// NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4243. //// NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  4244. //// NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4245. //// if([_id isEqualToString:ids])
  4246. //// {
  4247. //// [self updateItemJson:nil atIndexPath:indexPath];
  4248. //// ready_break = YES;
  4249. //// break;
  4250. //// }
  4251. //// }
  4252. ////
  4253. //// if (ready_break) {
  4254. //// break;
  4255. //// }
  4256. //// }
  4257. ////
  4258. //// } else {
  4259. //// for(int i=0;i<self.content_arr.count;i++)
  4260. //// {
  4261. //// NSDictionary* obj_json = self.content_arr[i];
  4262. //// NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4263. //// if([_id isEqualToString:ids])
  4264. //// {
  4265. //// [self.content_arr removeObjectAtIndex:i];
  4266. //// // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  4267. //// break;
  4268. //// // appDelegate.cart_count--;
  4269. //// // [appDelegate update_count_mark];
  4270. //// }
  4271. ////
  4272. //// }
  4273. //// }
  4274. //// [self.itemListTable reloadData];
  4275. //// [self refresh_total];
  4276. ////#ifdef RA_NOTIFICATION
  4277. //// [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4278. ////#else
  4279. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4280. //// [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4281. ////#endif
  4282. //// // [self reload_data];
  4283. //// }
  4284. //// else
  4285. //// {
  4286. //// [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  4287. //// }
  4288. ////
  4289. //// });
  4290. //// });
  4291. //
  4292. // }
  4293. // }
  4294. //
  4295. //}
  4296. #pragma mark - Support scanner
  4297. -(void) onDecodedData:(NSString*) value
  4298. {
  4299. #if defined(USE_BLE_SCANNER) || defined(USE_MFI_SCANNER)
  4300. if(self.stop_response)
  4301. return;
  4302. #endif
  4303. int cqty=0;
  4304. if (self.back_order_flag) {
  4305. NSInteger section_count = [self sectionCount];
  4306. for (int i = 0; i < section_count; i++) {
  4307. NSInteger item_count = [self itemCountInSection:i];
  4308. for (int j = 0; j < item_count; j++) {
  4309. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4310. NSDictionary* item = [self itemJsonAtIndexPath:indexPath];
  4311. if([item[@"model"] isEqualToString:value]) {
  4312. cqty=[item[@"count"] intValue];
  4313. }
  4314. }
  4315. }
  4316. } else {
  4317. for(int i=0;i<self.content_arr.count;i++)
  4318. {
  4319. NSDictionary* item= self.content_arr[i];
  4320. if([item[@"model"] isEqualToString:value])
  4321. cqty=[item[@"count"]intValue];
  4322. }
  4323. }
  4324. if(cqty>0)
  4325. {
  4326. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  4327. //block代码块取代了delegate
  4328. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  4329. [self addtocart:value];
  4330. }];
  4331. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  4332. DebugLog(@"No");
  4333. }];
  4334. [alertControl addAction:actionOne];
  4335. [alertControl addAction:alertthree];
  4336. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  4337. [self presentViewController:alertControl animated:YES completion:nil];
  4338. }
  4339. else
  4340. [self addtocart:value];
  4341. }
  4342. -(void) addtocart:(NSString*) modelname
  4343. {
  4344. #ifdef QUERY_BY_UPC
  4345. {
  4346. #if defined(USE_BLE_SCANNER) || defined(USE_MFI_SCANNER)
  4347. self.stop_response=true;
  4348. #endif
  4349. [RANetwork request_addto_cart_byupc:modelname withScreen:ScreenCodeCamScan completionHandler:^(NSMutableDictionary *result) {
  4350. NSDictionary* return_json = result;
  4351. if([[return_json valueForKey:@"result"] intValue]==2)
  4352. {
  4353. #ifdef RA_NOTIFICATION
  4354. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4355. #else
  4356. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4357. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4358. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  4359. #endif
  4360. #if defined(USE_BLE_SCANNER) || defined(USE_MFI_SCANNER)
  4361. self.stop_response=false;
  4362. #endif
  4363. }
  4364. else
  4365. {
  4366. [RAUtils message_alert:return_json[@"err_msg"] title:@"Add To Cart" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
  4367. #if defined(USE_BLE_SCANNER) || defined(USE_MFI_SCANNER)
  4368. self.stop_response=false;
  4369. #endif
  4370. } completion:^{
  4371. }];
  4372. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  4373. }
  4374. }];
  4375. }
  4376. #else
  4377. [RANetwork request_addto_cart_byname:modelname withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  4378. NSDictionary* return_json =result;
  4379. if([[return_json valueForKey:@"result"] intValue]==2)
  4380. {
  4381. NSDictionary* newitem = [return_json objectForKey:@"item_0"];
  4382. NSString* item_id = [newitem valueForKey:@"cart_item_id"];
  4383. // bool isnew=false;
  4384. //
  4385. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  4386. if (self.back_order_flag) {
  4387. NSInteger section_count = [self sectionCount];
  4388. for (int i = 0; i < section_count; i++) {
  4389. NSInteger item_count = [self itemCountInSection:i];
  4390. BOOL ready_break = NO;
  4391. for (int j = 0; j < item_count; j++) {
  4392. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4393. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  4394. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4395. if([_id isEqualToString:item_id])
  4396. {
  4397. [self updateItemJson:nil atIndexPath:indexPath];
  4398. ready_break = YES;
  4399. break;
  4400. }
  4401. }
  4402. if (ready_break) {
  4403. break;
  4404. }
  4405. }
  4406. } else {
  4407. for(int i=0;i<self.content_arr.count;i++)
  4408. {
  4409. NSDictionary* obj_json = self.content_arr[i];
  4410. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4411. if([_id isEqualToString:item_id])
  4412. {
  4413. // self.content_arr[i] = newitem;
  4414. [self.content_arr removeObjectAtIndex:i];
  4415. break;
  4416. // [self.content_arr removeObjectAtIndex:i];
  4417. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  4418. // appDelegate.cart_count--;
  4419. // [appDelegate update_count_mark];
  4420. }
  4421. }
  4422. }
  4423. AppDelegate *appDelegate =nil;
  4424. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4425. #ifdef OFFLINE_MODE
  4426. if(appDelegate.offline_mode)
  4427. {
  4428. [self ReloadData];
  4429. }
  4430. else
  4431. #endif
  4432. {
  4433. if (self.back_order_flag) {
  4434. [self ReloadData];
  4435. } else {
  4436. [self.content_arr insertObject:newitem atIndex:0];
  4437. [self.itemListTable reloadData];
  4438. [self refresh_total];
  4439. }
  4440. }
  4441. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4442. #ifdef RA_NOTIFICATION
  4443. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4444. #else
  4445. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  4446. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4447. #endif
  4448. }
  4449. else
  4450. {
  4451. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  4452. }
  4453. }];
  4454. #endif
  4455. }
  4456. #pragma mark - sort button
  4457. - (void)cartSortButtonClicked:(UIButton *)sender {
  4458. DebugLog(@"cart sort button clicked");
  4459. [self.view addSubview:self.sortItemController.view];
  4460. }
  4461. - (SortItemViewController *)sortItemController {
  4462. if (!_sortItemController) {
  4463. _sortItemController = [[SortItemViewController alloc] initWithTableOrigin:CGPointMake(20, 50)];
  4464. _sortItemController.sortIndex = self.sortIndex;
  4465. _sortItemController.sortData = @[
  4466. @{@"title":@"Last",@"icon":@"TX_18"},
  4467. @{@"title":@"First",@"icon":@"TS_18"},
  4468. @{@"title":@"Item number a-z",@"icon":@"IX_18"},
  4469. @{@"title":@"Item number z-a",@"icon":@"IS_18"},
  4470. @{@"title":@"Description",@"icon":@"DX_18"},
  4471. ];
  4472. __weak typeof(self) weakSelf = self;
  4473. _sortItemController.sortBlock = ^(int sort){
  4474. weakSelf.sortIndex = sort;
  4475. [weakSelf reload_data];
  4476. };
  4477. }
  4478. // _sortItemController.sortIndex = self.sortIndex;
  4479. return _sortItemController;
  4480. }
  4481. - (SortButton *)sortButton {
  4482. if (!_sortButton) {
  4483. _sortButton = [SortButton sortButtonWithHeight:40];
  4484. _sortButton.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  4485. [_sortButton addTarget:self action:@selector(cartSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  4486. }
  4487. return _sortButton;
  4488. }
  4489. - (void)setSortIndex:(int)sortIndex {
  4490. _sortIndex = sortIndex;
  4491. NSString *selectedImageName = @"";
  4492. switch (sortIndex) {
  4493. case 0:{
  4494. selectedImageName = @"TX_22";
  4495. }
  4496. break;
  4497. case 1:{
  4498. selectedImageName = @"TS_22";
  4499. }
  4500. break;
  4501. case 2:{
  4502. selectedImageName = @"IX_22";
  4503. }
  4504. break;
  4505. case 3:{
  4506. selectedImageName = @"IS_22";
  4507. }
  4508. break;
  4509. case 4:{
  4510. selectedImageName = @"DX_22";
  4511. }
  4512. break;
  4513. default:
  4514. break;
  4515. }
  4516. self.sortButton.imageView.image = [UIImage imageNamed:selectedImageName];
  4517. }
  4518. #pragma mark - rotation
  4519. //- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  4520. //
  4521. // self.sortItemController.view.frame = self.view.bounds;
  4522. //}
  4523. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  4524. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  4525. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  4526. // what ever you want to prepare
  4527. } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  4528. // self.sortItemController.view.frame = self.view.bounds;
  4529. self.sortItemController.view.frame = self.view.bounds;
  4530. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  4531. // [self.itemListTable reloadData];
  4532. self.cartIndicatorBar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.cartIndicatorBar.bounds].CGPath;
  4533. [self layoutCartIndicatorBar];
  4534. }];
  4535. }
  4536. -(BOOL) shouldAutorotate
  4537. {
  4538. return YES;
  4539. }
  4540. //- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  4541. // return YES;
  4542. //}
  4543. //- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  4544. // self.sortItemController.view.frame = self.view.bounds;
  4545. // self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  4546. //
  4547. //// [self.itemListTable reloadData];
  4548. //
  4549. // self.cartIndicatorBar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.cartIndicatorBar.bounds].CGPath;
  4550. // [self layoutCartIndicatorBar];
  4551. //}
  4552. #pragma mark - notification action
  4553. - (void)priceTypeChanged:(id)notification {
  4554. [self reload_data];
  4555. #ifdef RA_NOTIFICATION
  4556. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4557. #else
  4558. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  4559. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4560. #endif
  4561. }
  4562. #pragma mark - button action
  4563. - (IBAction)emailButtonClick:(UIButton *)sender {
  4564. if (![self isOrderAvailable]) {
  4565. return;
  4566. }
  4567. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  4568. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"Please enter email address"];
  4569. emailAddrVC.textFiled.secureTextEntry = NO;
  4570. emailAddrVC.yesButtonTitle = @"send";
  4571. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  4572. __weak typeof(self) weakself = self;
  4573. emailAddrVC.textHandler = ^(NSString *text){
  4574. // 验证邮箱格式是否正确
  4575. // NSString *match = EMAIL_MATCHES;
  4576. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  4577. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  4578. BOOL isEmailAddr = YES;
  4579. if (isEmailAddr) {
  4580. // 验证是邮件地址,发送邮件
  4581. [weakVC dismissViewControllerAnimated:YES completion:^{
  4582. __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  4583. [RANetwork request_qouteorder:appDelegate.order_code emailAddr:text completionHandler:^(NSMutableDictionary *result) {
  4584. DebugLog(@"email cart result: %@",result);
  4585. [waitting_alert dismissViewControllerAnimated:YES completion:^{
  4586. // [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  4587. if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  4588. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  4589. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  4590. }];
  4591. [errorAlertVC addAction:action];
  4592. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  4593. }else {
  4594. [RAUtils message_alert:@"Send Email Success" title:@"Message" controller:weakself];
  4595. }
  4596. }];
  4597. }];
  4598. }];
  4599. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  4600. //
  4601. // NSDictionary *result = [RANetwork quoteOrder:appDelegate.order_code emailAddr:text];
  4602. // DebugLog(@"email cart result: %@",result);
  4603. // dispatch_async(dispatch_get_main_queue(), ^{
  4604. //
  4605. // [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  4606. //
  4607. // if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  4608. //
  4609. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  4610. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  4611. //
  4612. // }];
  4613. //
  4614. // [errorAlertVC addAction:action];
  4615. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  4616. //
  4617. // }else {
  4618. //
  4619. // [RAUtils message_alert:@"Send Email Success" title:@"Message" controller:weakself];
  4620. //
  4621. // }
  4622. //
  4623. // });
  4624. //
  4625. // });
  4626. }];
  4627. } else {
  4628. // 非邮件地址,警告
  4629. [weakVC warning:@"Please enter right email address"];
  4630. }
  4631. };
  4632. [self presentViewController:emailAddrVC animated:YES completion:nil];
  4633. }
  4634. - (IBAction)printCartButtonClick:(UIButton *)sender {
  4635. if (![self isOrderAvailable]) {
  4636. return;
  4637. }
  4638. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  4639. ViewController.url = self.print_url;
  4640. ViewController.canSave = false;
  4641. ViewController.isLocalfile=NO;
  4642. NSString* subject;
  4643. subject =@"Cart Print";
  4644. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4645. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  4646. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  4647. if(customer_email.length>0)
  4648. {
  4649. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  4650. }
  4651. ViewController.mail_to = send_to;
  4652. ViewController.filename = [NSString stringWithFormat:@"%@_Product_List.pdf",COMPANY_SHORT_NAME];
  4653. ViewController.mail_subject = subject;
  4654. ViewController.hidenavi = false;
  4655. [self.navigationController pushViewController:ViewController animated:YES];
  4656. }
  4657. - (void)showAddressBoxToEmailProduct:(NSString *)productID {
  4658. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  4659. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"E-mail not setup, please enter your default e-mail address" ContentSize:CGSizeMake(400, 150)];
  4660. emailAddrVC.textFiled.secureTextEntry = NO;
  4661. emailAddrVC.yesButtonTitle = @"send";
  4662. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  4663. __weak typeof(self) weakself = self;
  4664. emailAddrVC.textHandler = ^(NSString *text){
  4665. // 验证邮箱格式是否正确
  4666. // NSString *match = EMAIL_MATCHES;
  4667. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  4668. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  4669. BOOL isEmailAddr = YES;
  4670. if (isEmailAddr) {
  4671. // 验证是邮件地址,发送邮件
  4672. [weakVC dismissViewControllerAnimated:YES completion:^{
  4673. __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  4674. [RANetwork request_notifymodel:productID emailAddr:text withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  4675. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  4676. [waitting_alert dismissViewControllerAnimated:YES completion:^{
  4677. int resultStatus = [[result objectForKey:@"result"] intValue];
  4678. if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  4679. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  4680. if ([result valueForKey:@"err_msg"]) {
  4681. msg = [result valueForKey:@"err_msg"];
  4682. }
  4683. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  4684. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  4685. }];
  4686. [errorAlertVC addAction:action];
  4687. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  4688. }else if(resultStatus == RESULT_TRUE){
  4689. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  4690. } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  4691. [weakself showAddressBoxToEmailProduct:productID];
  4692. }
  4693. }];
  4694. }];
  4695. }];
  4696. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  4697. //
  4698. // NSDictionary *result = [RANetwork notifyModel:productID emailAddr:text withScreen:ScreenCodeCart];
  4699. //
  4700. // dispatch_async(dispatch_get_main_queue(), ^{
  4701. //
  4702. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  4703. //
  4704. // int resultStatus = [[result objectForKey:@"result"] intValue];
  4705. // if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  4706. //
  4707. // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  4708. // if ([result valueForKey:@"err_msg"]) {
  4709. // msg = [result valueForKey:@"err_msg"];
  4710. // }
  4711. //
  4712. //
  4713. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  4714. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  4715. //
  4716. // }];
  4717. //
  4718. // [errorAlertVC addAction:action];
  4719. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  4720. //
  4721. // }else if(resultStatus == RESULT_TRUE){
  4722. //
  4723. // [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  4724. //
  4725. // } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  4726. //
  4727. // [weakself showAddressBoxToEmailProduct:productID];
  4728. //
  4729. // }
  4730. //
  4731. // });
  4732. //
  4733. // });
  4734. }];
  4735. } else {
  4736. // 非邮件地址,警告
  4737. [weakVC warning:@"Please enter right email address"];
  4738. }
  4739. };
  4740. [self presentViewController:emailAddrVC animated:YES completion:nil];
  4741. }
  4742. #pragma mark - Back Order
  4743. - (void) setCart_json:(NSDictionary *)cart_json {
  4744. _cart_json = cart_json;
  4745. [self fillContentArray];
  4746. }
  4747. - (void)fillContentArray {
  4748. NSMutableArray *arr = [NSMutableArray array];
  4749. for (int i = 0; i < [self sectionCount]; i++) {
  4750. NSInteger item_count = [self itemCountInSection:i];
  4751. for (int j = 0; j < item_count; j++) {
  4752. NSDictionary *item = [self itemJsonAtIndexPath:[NSIndexPath indexPathForRow:j inSection:i]];
  4753. [arr addObject:item];
  4754. }
  4755. }
  4756. self.content_arr = arr;
  4757. [self refresh_total];
  4758. }
  4759. - (NSInteger)sectionCount {
  4760. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  4761. }
  4762. - (NSDictionary *)jsonAtSection:(NSInteger)section {
  4763. return [self.cart_json objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  4764. }
  4765. - (NSInteger)itemCountInSection:(NSInteger)section {
  4766. NSDictionary *section_json = [self jsonAtSection:section];
  4767. return [[section_json objectForKey:@"count"] integerValue];
  4768. }
  4769. - (NSString *)titleForSection:(NSInteger)section {
  4770. NSDictionary *section_json = [self jsonAtSection:section];
  4771. return [section_json objectForKey:@"title"];
  4772. }
  4773. - (NSDictionary *)itemJsonAtIndexPath:(NSIndexPath *)indexPath {
  4774. NSDictionary *section = [self jsonAtSection:indexPath.section];
  4775. return [section objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  4776. }
  4777. - (void)updateItemJson:(NSDictionary *)new_item_json atIndexPath:(NSIndexPath *)indexPath {
  4778. NSMutableDictionary *new_cart_json = [self.cart_json mutableCopy];
  4779. NSMutableDictionary *new_section_json = [[self jsonAtSection:indexPath.section] mutableCopy];
  4780. NSString *section_key = [NSString stringWithFormat:@"section_%ld",indexPath.section];
  4781. NSString *item_key = [NSString stringWithFormat:@"item_%ld",indexPath.row];
  4782. if (new_item_json) {
  4783. // 更新Item
  4784. [new_section_json setObject:new_item_json forKey:item_key];
  4785. } else {
  4786. // 删除Item
  4787. NSInteger item_count = [self itemCountInSection:indexPath.section];
  4788. for (NSInteger i = 0; i < item_count; i++) {
  4789. if (i >= indexPath.row) {
  4790. if (i < item_count - 1) {
  4791. item_key = [NSString stringWithFormat:@"item_%ld",i + 1];
  4792. NSDictionary *followed_item_json = [new_section_json objectForKey:item_key];
  4793. item_key = [NSString stringWithFormat:@"item_%ld",i];
  4794. [new_section_json setObject:followed_item_json forKey:item_key];
  4795. } else {
  4796. item_key = [NSString stringWithFormat:@"item_%ld",i];
  4797. [new_section_json removeObjectForKey:item_key];
  4798. }
  4799. }
  4800. }
  4801. [new_section_json setObject:@(item_count - 1) forKey:@"count"];
  4802. }
  4803. [new_cart_json setObject:new_section_json forKey:section_key];
  4804. self.cart_json = [new_cart_json copy];
  4805. }
  4806. - (void)reRefreshView {
  4807. [self.itemListTable reloadData];
  4808. }
  4809. #pragma mark - RA_NOTIFICAITON
  4810. -(void) refresh_ui
  4811. {
  4812. [self.itemListTable reloadData];
  4813. [self refresh_total];
  4814. }
  4815. -(void) refresh_price
  4816. {
  4817. [self refresh_ui];
  4818. }
  4819. - (void) reload_data {
  4820. __weak typeof(self) weakself = self;
  4821. self.currentOrderIsMerged = NO;
  4822. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  4823. if (weakself) {
  4824. __strong typeof(weakself) strongself = weakself;
  4825. [strongself operation_reload_data];
  4826. }
  4827. }];
  4828. [self.dataOperationQueue addOperation:operation];
  4829. }
  4830. @end