CartViewController.m 180 KB

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