CartViewController.m 190 KB

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