CartViewController.m 247 KB

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