CartViewController.m 231 KB

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