CartViewController.m 247 KB

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