CartViewController.m 182 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830
  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. UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"%25" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1086. // self.btnPrice.titleLabel.text = @"%25";
  1087. [self.btnPrice setTitle: @"%25" forState:UIControlStateNormal];
  1088. RASingleton.sharedInstance.price_type=2;
  1089. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1090. int count = [section[@"count"] intValue];
  1091. for(int i=0;i<count;i++)
  1092. {
  1093. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1094. item[@"price"]= item[price_group[@"price_2"][@"name"]];
  1095. item[@"unit_price"]= item[price_group[@"price_2"][@"name"]];
  1096. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1097. }
  1098. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1099. RASingleton.sharedInstance.scan_cart[@"price_type"] = @2;
  1100. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1101. [self.cartIndicatorBar removeFromSuperview];
  1102. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1103. [self.view addSubview:self.cartIndicatorBar];
  1104. [self reload_data];
  1105. }];
  1106. UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1107. }];
  1108. [alertControl addAction:action1];
  1109. [alertControl addAction:action2];
  1110. // [alertControl addAction:action3];
  1111. // [alertControl addAction:alertthree];
  1112. [alertControl addAction:alertCancel];
  1113. [self presentViewController:alertControl animated:YES completion:nil];
  1114. #endif
  1115. }
  1116. -(void) newoloorder
  1117. {
  1118. NSString *orderdir =[OLDataProvider getScanPath];
  1119. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1120. appDelegate.can_set_cart_price = true;
  1121. appDelegate.can_see_price = true;
  1122. {
  1123. if(appDelegate.user_type== USER_ROLE_EMPLOYEE)
  1124. {
  1125. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1126. //block代码块取代了delegate
  1127. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1128. NSMutableDictionary* dict = nil;
  1129. // NSMutableDictionary* dict = nil;
  1130. NSString* ordertemplate = nil;
  1131. if([RADataProvider getSiteHasERP])
  1132. ordertemplate =@"e_order.json";
  1133. else
  1134. ordertemplate =@"e_order_noerp.json";
  1135. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1136. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1137. [RAUtils dicttofile:orderPath dict:dict];
  1138. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1139. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1140. [self scanPlaceOrder];
  1141. }];
  1142. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1143. NSMutableDictionary* dict = nil;
  1144. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1145. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1146. [RAUtils dicttofile:orderPath dict:dict];
  1147. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1148. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1149. [self scanPlaceOrder];
  1150. }];
  1151. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1152. appDelegate.order_code = nil;
  1153. DebugLog(@"No");
  1154. }];
  1155. [alertControl addAction:actionOne];
  1156. [alertControl addAction:alert2];
  1157. [alertControl addAction:alertthree];
  1158. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1159. [self presentViewController:alertControl animated:YES completion:nil];
  1160. DebugLog(@"%@",self.edit_select_arr);
  1161. }
  1162. else
  1163. {
  1164. NSMutableDictionary* dict = nil;
  1165. if([appDelegate.customerInfo[@"customer_cid"] stringValue].length ==0 )
  1166. {
  1167. dict=[OLDataProvider loadScanTemplate:@"nc_order.json"];
  1168. }
  1169. else
  1170. dict=[OLDataProvider loadScanTemplate:@"c_order.json"];
  1171. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1172. [RAUtils dicttofile:orderPath dict:dict];
  1173. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1174. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1175. [self scanPlaceOrder];
  1176. }
  1177. // NSMutableDictionary* dict=[OLDataProvider loadScanTemplate:@"scan_order.json"];
  1178. }
  1179. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  1180. // mainvc.btnScan.enabled = true;
  1181. // [appDelegate updateScanButton:true];
  1182. }
  1183. -(void) newoloorder1
  1184. {
  1185. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1186. appDelegate.can_set_cart_price = true;
  1187. appDelegate.can_see_price = true;
  1188. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1189. // NSString *documents = [paths objectAtIndex:0];
  1190. {
  1191. NSString *orderdir =[OLDataProvider getScanPath];
  1192. if(appDelegate.user_type== USER_ROLE_EMPLOYEE)
  1193. {
  1194. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1195. //block代码块取代了delegate
  1196. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1197. NSMutableDictionary* dict = nil;
  1198. NSString* ordertemplate = nil;
  1199. if([RADataProvider getSiteHasERP])
  1200. ordertemplate =@"e_order.json";
  1201. else
  1202. ordertemplate =@"e_order_noerp.json";
  1203. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1204. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1205. [RAUtils dicttofile:orderPath dict:dict];
  1206. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1207. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1208. [self scanPlaceOrder];
  1209. }];
  1210. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1211. NSMutableDictionary* dict = nil;
  1212. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1213. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1214. [RAUtils dicttofile:orderPath dict:dict];
  1215. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1216. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1217. [self scanPlaceOrder];
  1218. }];
  1219. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1220. appDelegate.order_code = nil;
  1221. DebugLog(@"No");
  1222. }];
  1223. [alertControl addAction:actionOne];
  1224. [alertControl addAction:alert2];
  1225. [alertControl addAction:alertthree];
  1226. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1227. [self presentViewController:alertControl animated:YES completion:nil];
  1228. DebugLog(@"%@",self.edit_select_arr);
  1229. }
  1230. else
  1231. {
  1232. NSMutableDictionary* dict = nil;
  1233. if([appDelegate.customerInfo[@"customer_cid"] stringValue].length ==0 )
  1234. {
  1235. dict=[OLDataProvider loadScanTemplate:@"nc_order.json"];
  1236. }
  1237. else
  1238. dict=[OLDataProvider loadScanTemplate:@"c_order.json"];
  1239. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1240. [RAUtils dicttofile:orderPath dict:dict];
  1241. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1242. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1243. [self scanPlaceOrder];
  1244. }
  1245. // NSMutableDictionary* dict=[OLDataProvider loadScanTemplate:@"scan_order.json"];
  1246. }
  1247. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  1248. // mainvc.btnScan.enabled = true;
  1249. // [appDelegate updateScanButton:true];
  1250. }
  1251. -(void)newScanOrder1
  1252. {
  1253. //
  1254. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1255. //
  1256. //
  1257. // if(appDelegate.order_code.length>0)
  1258. // {
  1259. //// 当前订单先关闭
  1260. //// [OLDataProvider deleteScanOrder:appDelegate.order_code];
  1261. // appDelegate.order_code = nil;
  1262. // appDelegate.customerInfo = nil;
  1263. // RASingleton.sharedInstance.scan_cart = nil;
  1264. // appDelegate.contact_id = nil;
  1265. //// [appDelegate updateScanButton:false];
  1266. //
  1267. // [appDelegate update_count_mark];
  1268. // [appDelegate closeOrder];
  1269. //
  1270. // }
  1271. //
  1272. //
  1273. {
  1274. [self newoloorder1];
  1275. }
  1276. }
  1277. -(void)newScanOrder
  1278. {
  1279. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1280. {
  1281. [self newoloorder];
  1282. }
  1283. }
  1284. -(void)placeOrder
  1285. {
  1286. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1287. #ifndef SCANNER_ORDER
  1288. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1289. if (![RASingleton sharedInstance].permissions_edit_order) {
  1290. return;
  1291. }
  1292. }
  1293. #endif
  1294. // NSMutableArray* checked = [[NSMutableArray alloc] init];
  1295. bool have_free = false;
  1296. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  1297. if(count==0)
  1298. {
  1299. [RAUtils message_box:@"Cart Is Empty." message:@"Add some model first." completion:nil] ;
  1300. return;
  1301. }
  1302. for(int i=0;i<count;i++)
  1303. {
  1304. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1305. // bool check = [[item_json valueForKey:@"check"] boolValue];
  1306. NSString* product_id = [item_json valueForKey:@"product_id"];
  1307. // if(check)
  1308. // {
  1309. // [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  1310. //
  1311. // }
  1312. if(product_id.length==0)
  1313. {
  1314. [RAUtils message_box:@"No Such Model" message:@"Some models in cart does not exist, you must remove them before place order." completion:nil] ;
  1315. return;
  1316. }
  1317. bool is_free = [[item_json valueForKey:@"is_free"]boolValue];
  1318. if(is_free)
  1319. have_free=true;
  1320. }
  1321. #ifdef SCANNER_ORDER
  1322. if(appDelegate.bLogin==false)
  1323. {
  1324. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1325. // loginvc.delegate = self;
  1326. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1327. loginvc.returnValue = ^(bool blogin){
  1328. if(blogin)
  1329. {
  1330. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1331. if(appDelegate.order_code.length==0)
  1332. {
  1333. [self newScanOrder];
  1334. }
  1335. }
  1336. };
  1337. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1338. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1339. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1340. [self presentViewController:navi animated:YES completion:^{
  1341. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1342. DebugLog(@"LoginViewController present.........");
  1343. // self.btop = false;
  1344. // <#code#>
  1345. }];
  1346. return;
  1347. }
  1348. else
  1349. {
  1350. NSString *orderdir =[OLDataProvider getScanPath];
  1351. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1352. if(appDelegate.order_code.length==0 )
  1353. {
  1354. [self newScanOrder];
  1355. }
  1356. else if( ![[NSFileManager defaultManager] fileExistsAtPath:orderPath])
  1357. {
  1358. [self newScanOrder1];
  1359. }
  1360. else
  1361. {
  1362. [self scanPlaceOrder];
  1363. //place order
  1364. }
  1365. return;
  1366. }
  1367. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  1368. // {
  1369. //
  1370. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1371. // // NSString * string = [checked componentsJoinedByString:@","];
  1372. // // [params setValue:string forKey:@"cart2Checkbox"];
  1373. //
  1374. //// NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1375. //// NSError *error=nil;
  1376. //// NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1377. ////
  1378. //
  1379. //
  1380. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1381. // NSString *documents = [paths objectAtIndex:0];
  1382. //
  1383. //
  1384. //
  1385. // NSString *orderdir = [documents stringByAppendingPathComponent:appDelegate.order_code];
  1386. //
  1387. // NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  1388. //
  1389. // int section_count = [dict[@"section_count"] intValue];
  1390. //
  1391. // for(int i=0;i<section_count;i++)
  1392. // {
  1393. // NSMutableDictionary* section = [dict[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  1394. // NSString* title = section[@"title"];
  1395. // if([title isEqualToString:@"Model Information"])
  1396. // {
  1397. //
  1398. // NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  1399. // int cart_count = [cart_section[@"count"] intValue];
  1400. // for(int j=0;j<cart_count;j++)
  1401. // {
  1402. // NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1403. // cart_item[@"control"]=@"model";
  1404. // section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  1405. //
  1406. // }
  1407. // section[@"count"] = @(cart_count);
  1408. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1409. // }
  1410. // else
  1411. // if([title isEqualToString:@"Customer"])
  1412. // {
  1413. //
  1414. // int scount = [section[@"count"] intValue];
  1415. // for(int j=0;j<scount;j++)
  1416. // {
  1417. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1418. // NSString * name = item[@"name"];
  1419. //
  1420. // if([name isEqualToString:@"business_card"])
  1421. // {
  1422. // NSArray*arr =[RAConvertor string2arr:appDelegate.customerInfo[name] separator:@","];
  1423. // for(int l=0;l<arr.count;l++)
  1424. // {
  1425. // item[[NSString stringWithFormat:@"img_url_%d",l] ]=arr[l];
  1426. // }
  1427. // }
  1428. // else
  1429. // item[@"value"]=appDelegate.customerInfo[name];
  1430. //
  1431. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1432. // }
  1433. //
  1434. //// NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1435. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1436. //
  1437. //
  1438. // }
  1439. // else
  1440. // if([title isEqualToString:@"Remarks Content"])
  1441. // {
  1442. //
  1443. // int scount = [section[@"count"] intValue];
  1444. // for(int j=0;j<scount;j++)
  1445. // {
  1446. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1447. // NSString * name = item[@"name"];
  1448. //
  1449. //
  1450. // if([name isEqualToString:@"comments"])
  1451. // {
  1452. // item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  1453. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1454. // }
  1455. //
  1456. //
  1457. // }
  1458. //
  1459. // // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1460. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1461. //
  1462. //
  1463. // }
  1464. // else if([title isEqualToString:@"Order Total"])
  1465. // {
  1466. //
  1467. // int scount = [section[@"count"] intValue];
  1468. // for(int j=0;j<scount;j++)
  1469. // {
  1470. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1471. // NSString * name = item[@"name"];
  1472. //
  1473. //
  1474. // if([name isEqualToString:@"totalPrice"])
  1475. // {
  1476. // item[@"value"] = [NSString stringWithFormat:@"%.2f",self.total];
  1477. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1478. // }
  1479. //
  1480. //
  1481. // }
  1482. //
  1483. //// NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1484. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1485. //
  1486. //
  1487. //
  1488. // }
  1489. //
  1490. //
  1491. //
  1492. //
  1493. // }
  1494. //
  1495. //// NSString *path = NSTemporaryDirectory();
  1496. ////
  1497. //// NSString* file=[NSString stringWithFormat:@"SO_%@.json",appDelegate.order_code];
  1498. //// NSString *filePath = [path stringByAppendingPathComponent:file];
  1499. ////
  1500. ////
  1501. ////
  1502. // [RAUtils dicttofile:[orderdir stringByAppendingPathComponent:@"order.json"] dict:dict];
  1503. //
  1504. // CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1505. //
  1506. //
  1507. //
  1508. // orderinfoVC.disable_dropdown_refresh=true;
  1509. // orderinfoVC.url_type = URL_FILE;
  1510. // orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  1511. //
  1512. // orderinfoVC.params = params;
  1513. // orderinfoVC.title=@"";
  1514. // orderinfoVC.delegate=self;
  1515. // //
  1516. // // if(checked.count==count)
  1517. // // {
  1518. // // orderinfoVC.have_tail = true
  1519. // // }
  1520. //
  1521. // [self.navigationController pushViewController:orderinfoVC animated:true];
  1522. //
  1523. // return;
  1524. // }
  1525. #endif
  1526. //#ifdef BACKORDER_PROCESS
  1527. // if (self.back_order_flag) {
  1528. //
  1529. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1530. // [params setObject:@(0) forKey:@"step"];
  1531. //
  1532. //
  1533. // RAOrderEditorViewController *orderEditorVC =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"RAOrderEditorViewController"];
  1534. //
  1535. //
  1536. // //[[RAOrderEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1537. //
  1538. // orderEditorVC.disable_dropdown_refresh=true;
  1539. // orderEditorVC.url_type = URL_REMOTE;
  1540. // orderEditorVC.request_url=URL_CARTDELIVERY;
  1541. // orderEditorVC.params = params;
  1542. // orderEditorVC.delegate=self;
  1543. // orderEditorVC.title=@"";
  1544. // [self.navigationController pushViewController:orderEditorVC animated:true];
  1545. //
  1546. // }
  1547. // else
  1548. //#endif
  1549. // {
  1550. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1551. // // NSString * string = [checked componentsJoinedByString:@","];
  1552. // // [params setValue:string forKey:@"cart2Checkbox"];
  1553. //
  1554. //
  1555. //
  1556. //
  1557. //
  1558. // CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1559. //
  1560. // orderinfoVC.disable_dropdown_refresh=true;
  1561. // orderinfoVC.url_type = URL_REMOTE;
  1562. // orderinfoVC.request_url=URL_CARTDELIVERY;
  1563. //
  1564. // orderinfoVC.params = params;
  1565. // orderinfoVC.title=@"";
  1566. // orderinfoVC.delegate=self;
  1567. // //
  1568. // // if(checked.count==count)
  1569. // // {
  1570. // // orderinfoVC.have_tail = true
  1571. // // }
  1572. //
  1573. // [self.navigationController pushViewController:orderinfoVC animated:true];
  1574. // }
  1575. }
  1576. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  1577. {
  1578. return NO;
  1579. }
  1580. - (IBAction)onScanDiscount:(UIButton*)sender {
  1581. #ifdef SCANNER_ORDER
  1582. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1583. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  1584. UIViewController* parentvc=self;
  1585. // EditModelPriceViewController
  1586. ScanDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanDiscountViewController"];
  1587. NSMutableDictionary * item_json = nil;
  1588. if (self.back_order_flag) {
  1589. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  1590. } else {
  1591. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1592. }
  1593. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  1594. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  1595. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1596. __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  1597. // vc.delegate = parentvc.self;
  1598. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1599. vc.onSetValue = ^(double price,double discount){
  1600. bool bmodify=false;
  1601. if(discount>0)
  1602. bmodify=true;
  1603. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  1604. PopWaitAlert* pop = [RAUtils waiting_pop:@"Update Price" completion:nil];
  1605. [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  1606. NSDictionary* cart_json = result;
  1607. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1608. [pop hide];
  1609. if([[cart_json valueForKey:@"result"] intValue]==2)
  1610. {
  1611. [self reload_data];
  1612. #ifdef RA_NOTIFICATION
  1613. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1614. #else
  1615. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1616. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1617. #endif
  1618. }
  1619. else
  1620. {
  1621. [RAUtils message_box:@"Update Price" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  1622. }
  1623. // }];
  1624. }];
  1625. // }];
  1626. };
  1627. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1628. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1629. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1630. [parentvc presentViewController:navi animated:YES completion:^{
  1631. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1632. DebugLog(@"EditModelPriceViewController present.........");
  1633. // self.btop = false;
  1634. // <#code#>
  1635. }];
  1636. #endif
  1637. }
  1638. -(void)refresh_total
  1639. {
  1640. self.total=0;
  1641. self.total_carton=0;
  1642. self.total_cuft=0;
  1643. self.total_weight=0;
  1644. self.total_QTY=0;
  1645. self.total_item=0;
  1646. self.surcharge=0;
  1647. #ifdef SCANNER_ORDER
  1648. NSString* pricename;
  1649. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  1650. NSString* servername = [addressDic objectForKey:@"show_name"];
  1651. NSArray* arrsn = [RAConvertor string2arr:servername separator:@","];
  1652. NSString * shortname = arrsn[0];
  1653. if(shortname.length==0)
  1654. shortname = servername;
  1655. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1656. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  1657. switch(RASingleton.sharedInstance.price_type )
  1658. {
  1659. case 0: pricename =price_group[@"price_0"][@"display"];//@"DDP";//[NSString stringWithFormat:@"%@_DDP",shortname];
  1660. break;;
  1661. case 1: pricename =price_group[@"price_1"][@"display"];//@"WHSE";//[NSString stringWithFormat:@"%@_WHSE",shortname];;
  1662. break;;
  1663. // case 2: pricename = @"25%";
  1664. // break;
  1665. }
  1666. [self.btnPrice setTitle:pricename forState:UIControlStateNormal];
  1667. // self.cartIndicatorBar = [self setupCartIndicatorBar];
  1668. [self.cartIndicatorBar removeFromSuperview];
  1669. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1670. [self.view addSubview:self.cartIndicatorBar];
  1671. #endif
  1672. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  1673. for(int i=0;i<count;i++)
  1674. {
  1675. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1676. bool bcheck = [[item_json valueForKey:@"check"]boolValue];
  1677. if(bcheck)
  1678. {
  1679. double unitprice = [[item_json valueForKey:@"unit_price"] doubleValue];
  1680. double discount = [[item_json valueForKey:@"discount"] doubleValue];
  1681. int count=[[item_json valueForKey:@"count"] intValue];
  1682. double totalprice =count*unitprice*(1-discount/100.0);
  1683. double cuft=[[item_json valueForKey:@"cuft"] doubleValue];
  1684. double weight=[[item_json valueForKey:@"weight"] doubleValue];
  1685. int carton=/*count**/[[item_json valueForKey:@"carton"] intValue];
  1686. int item_count=1;
  1687. int item_qty=1;
  1688. // NSDictionary * bundle_item =[item_json objectForKey:@"combine"];
  1689. double msurcharge =0;
  1690. // remove net price
  1691. // if(RASingleton.sharedInstance.price_type==1)
  1692. // {
  1693. // if([item_json[@"special_price"] boolValue])
  1694. // {
  1695. // msurcharge=([item_json[price_group[@"price_3"][@"name"]] doubleValue]-[item_json[price_group[@"price_2"][@"name"]] doubleValue])*count*(1-discount/100.0);
  1696. // if(msurcharge<0)
  1697. // msurcharge = 0;
  1698. // }
  1699. // else
  1700. // {
  1701. // msurcharge=([item_json[price_group[@"price_3"][@"name"]] doubleValue]-[item_json[price_group[@"price_1"][@"name"]] doubleValue])*count*(1-discount/100.0);
  1702. // if(msurcharge<0)
  1703. // msurcharge = 0;
  1704. //
  1705. //
  1706. // }
  1707. // }
  1708. // double dprice=0;
  1709. // if(bundle_item!=nil)
  1710. // {
  1711. // // int citem=0;
  1712. //
  1713. // int bcount=[[bundle_item valueForKey:@"count"] intValue];
  1714. // for(int bc=0;bc<bcount;bc++)
  1715. // {
  1716. // NSDictionary * bitem = [bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  1717. // int modulus= [[bitem valueForKey:@"modulus"] intValue];
  1718. // // citem+= modulus;
  1719. // item_count+=1;
  1720. // item_qty+=modulus;
  1721. // double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  1722. // dprice+= uprice*modulus*count;
  1723. //
  1724. // }
  1725. // }
  1726. // totalprice+= dprice;
  1727. self.surcharge+=msurcharge;
  1728. self.total+=totalprice;
  1729. self.total_cuft+=cuft;
  1730. self.total_carton+=carton;
  1731. self.total_weight+=weight;
  1732. self.total_item+=item_count;
  1733. self.total_QTY+=(item_qty)*count;
  1734. }
  1735. }
  1736. NSString* subtotal = [RAConvertor currencyNumber:self.total];//[NSString stringWithFormat:@"$%@",];
  1737. NSString* subcuft = [NSString stringWithFormat:@"%.2f",self.total_cuft];
  1738. NSString* subcarton = [NSString stringWithFormat:@"%d",self.total_carton];
  1739. NSString* subweight = [NSString stringWithFormat:@"%.2f lbs",self.total_weight];
  1740. NSString* surcharge = [RAConvertor currencyNumber:self.surcharge];//[NSString stringWithFormat:@"$%@",];
  1741. NSString* totalprice = [RAConvertor currencyNumber:(self.total+self.surcharge)];//[NSString stringWithFormat:@"$%@",];
  1742. NSString* subitems = [NSString stringWithFormat:@"%d",self.total_item];
  1743. NSString* subqty = [NSString stringWithFormat:@"%d",self.total_QTY];
  1744. #ifndef SCANNER_ORDER
  1745. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1746. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1747. {
  1748. }
  1749. else
  1750. {
  1751. subtotal=nil;
  1752. }
  1753. #else
  1754. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1755. [OLDataProvider updateScanOrder:appDelegate.order_code];
  1756. #endif
  1757. self.labelTotalSurcharge.text = surcharge;
  1758. self.labelTotalPrice.text = totalprice;
  1759. self.labelTotal.text=subtotal;
  1760. self.label_cuft.text=subcuft;
  1761. self.label_carton.text=subcarton;
  1762. self.label_weight.text=subweight;
  1763. self.label_items.text = subitems;
  1764. self.label_qty.text = subqty;
  1765. self.label_notes.text = [self.notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
  1766. }
  1767. - (IBAction)onEditGeneralNotes:(id)sender {
  1768. #ifndef SCANNER_ORDER
  1769. if (![self isOrderAvailable]) {
  1770. return;
  1771. }
  1772. #endif
  1773. UIViewController* parentvc=self;
  1774. CartGeneralNotesViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"CartGeneralNotesViewController"];
  1775. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row ] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1776. vc.notes=self.notes;
  1777. // vc.delegate = parentvc.self;
  1778. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1779. vc.onSetValue = ^(NSString* notes){
  1780. self.notes = notes;
  1781. [self refresh_total];
  1782. };
  1783. //
  1784. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1785. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1786. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1787. [parentvc presentViewController:navi animated:YES completion:^{
  1788. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1789. DebugLog(@"general notes editor present.........");
  1790. // self.btop = false;
  1791. // <#code#>
  1792. }];
  1793. }
  1794. - (IBAction)OnCancelOrderClicked:(id)sender {
  1795. }
  1796. #pragma mark - Private
  1797. - (BOOL)isOrderAvailable {
  1798. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1799. if (appDelegate.order_code.length == 0) {
  1800. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"please create a new order first" preferredStyle:UIAlertControllerStyleAlert];
  1801. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1802. }];
  1803. [alertVC addAction:okAction];
  1804. [self presentViewController:alertVC animated:YES completion:nil];
  1805. return NO;
  1806. }
  1807. return YES;
  1808. }
  1809. #pragma mark - commoneditor controller delegate
  1810. -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  1811. {
  1812. // [self reload_data];
  1813. if([value[@"commitorder_logout"] boolValue])
  1814. [self logout];
  1815. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1816. }
  1817. #pragma mark - Table view data source
  1818. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  1819. {
  1820. NSDictionary * item_json = nil;
  1821. if (self.back_order_flag) {
  1822. item_json = [self itemJsonAtIndexPath:indexPath];
  1823. } else {
  1824. item_json = self.content_arr[indexPath.row ];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1825. }
  1826. NSString* notes =[item_json valueForKey:@"note"];
  1827. if(notes.length>0)
  1828. {
  1829. return 146;
  1830. }
  1831. else
  1832. return 120;
  1833. }
  1834. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1835. //{
  1836. // return 0;
  1837. //}
  1838. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  1839. //{
  1840. // return 0;
  1841. //}
  1842. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  1843. //{
  1844. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1845. // return myView;
  1846. //
  1847. //}
  1848. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1849. //{
  1850. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1851. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  1852. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  1853. //// titleLabel.textColor=[UIColor whiteColor];
  1854. //// titleLabel.backgroundColor = [UIColor clearColor];
  1855. //// if(section==0)
  1856. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  1857. //// else
  1858. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  1859. //// [titleLabel sizeToFit];
  1860. //// [myView addSubview:titleLabel];
  1861. ////
  1862. // return myView;
  1863. //}
  1864. //
  1865. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  1866. // if(section==0)
  1867. // return nil;
  1868. // else
  1869. // return @"detail section";
  1870. //}
  1871. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1872. {
  1873. if (self.back_order_flag) {
  1874. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  1875. } else {
  1876. return 1;
  1877. }
  1878. }
  1879. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1880. {
  1881. #ifdef SCANNER_ORDER
  1882. return 0;
  1883. #else
  1884. if (self.back_order_flag) {
  1885. return 50;
  1886. } else {
  1887. return 0;
  1888. }
  1889. #endif
  1890. }
  1891. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1892. {
  1893. #ifdef SCANNER_ORDER
  1894. return nil;
  1895. #else
  1896. if (self.back_order_flag) {
  1897. // UIView *header = [tableView dequeueReusableCellWithIdentifier:@"section_header_cell"];
  1898. // UILabel *title_lb = [header viewWithTag:8520];
  1899. UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 50.0f)];
  1900. header.backgroundColor = [UIColor colorWithRed:128 / 255.0 green:95 / 255.0 blue:54 / 255.0 alpha:1];
  1901. header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1902. UILabel *title_lb = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, CGRectGetWidth(header.bounds) - 10, 50.0f)];
  1903. title_lb.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1904. title_lb.font = [UIFont systemFontOfSize:25.0f];
  1905. title_lb.textColor = [UIColor whiteColor];
  1906. [header addSubview:title_lb];
  1907. title_lb.text = [self titleForSection:section];
  1908. return header;
  1909. } else {
  1910. return nil;
  1911. }
  1912. #endif
  1913. }
  1914. #ifdef SCANNER_ORDER
  1915. - (IBAction)onScanChangeCustomerType:(id)sender {
  1916. return;
  1917. // NSString *orderdir =[OLDataProvider getScanPath];
  1918. //
  1919. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1920. // //block代码块取代了delegate
  1921. //
  1922. //
  1923. //
  1924. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1925. //
  1926. // NSMutableDictionary* dict = nil;
  1927. // NSString* ordertemplate = nil;
  1928. // if([RADataProvider getSiteHasERP])
  1929. // ordertemplate =@"e_order.json";
  1930. // else
  1931. // ordertemplate =@"e_order_noerp.json";
  1932. //
  1933. // dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1934. //
  1935. // NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1936. //
  1937. //
  1938. //
  1939. // [RAUtils dicttofile:orderPath dict:dict];
  1940. //
  1941. //
  1942. //
  1943. //
  1944. ////
  1945. //// NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1946. ////
  1947. ////
  1948. ////
  1949. //// [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1950. ////
  1951. //// [self scanPlaceOrder];
  1952. ////
  1953. // }];
  1954. //
  1955. // UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1956. // NSMutableDictionary* dict = nil;
  1957. // dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1958. //
  1959. // NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1960. //
  1961. //
  1962. //
  1963. // [RAUtils dicttofile:orderPath dict:dict];
  1964. //
  1965. //
  1966. //
  1967. ////
  1968. ////
  1969. //// NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1970. ////
  1971. ////
  1972. ////
  1973. //// [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1974. //// [self scanPlaceOrder];
  1975. // }];
  1976. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1977. // DebugLog(@"No");
  1978. // }];
  1979. // [alertControl addAction:actionOne];
  1980. // [alertControl addAction:alert2];
  1981. // [alertControl addAction:alertthree];
  1982. //
  1983. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1984. //
  1985. //
  1986. // [self presentViewController:alertControl animated:YES completion:nil];
  1987. //
  1988. // DebugLog(@"%@",self.edit_select_arr);
  1989. }
  1990. #endif
  1991. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1992. {
  1993. if (self.back_order_flag) {
  1994. return [self itemCountInSection:section];
  1995. } else {
  1996. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  1997. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  1998. return count;
  1999. }
  2000. }
  2001. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2002. {
  2003. // if(tableView==self.itemListTable)
  2004. // {
  2005. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2006. NSString *CellIdentifier;
  2007. #ifdef SCANNER_ORDER
  2008. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2009. CellIdentifier = @"ScanCartItemCell";
  2010. ScanCartItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2011. NSDictionary * item_json = nil;//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2012. item_json = [self itemJsonAtIndexPath:indexPath];
  2013. NSString* notes = [item_json valueForKey:@"note"];
  2014. if(notes.length>0)
  2015. {
  2016. cell.labelNotes.text = notes;
  2017. }
  2018. else
  2019. {
  2020. cell.labelNotes.text = nil;
  2021. }
  2022. NSString* description =[item_json valueForKey:@"description"];
  2023. NSString* model =[item_json valueForKey:@"model"];
  2024. NSString* dimension =[item_json valueForKey:@"dimension"] ;
  2025. int count =[[item_json valueForKey:@"count"] intValue];
  2026. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  2027. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  2028. double discount=[[item_json valueForKey:@"discount"] doubleValue];
  2029. cell.discount = discount;
  2030. if(appDelegate.user_type == USER_ROLE_CUSTOMER)
  2031. {
  2032. cell.btnScanDiscount.hidden = true;
  2033. }
  2034. else
  2035. {
  2036. switch(RASingleton.sharedInstance.price_type)
  2037. {
  2038. case 0: cell.btnScanDiscount.hidden = true;
  2039. break;;
  2040. case 1:
  2041. {
  2042. if(![item_json[@"special_price"] boolValue]&&![item_json[@"net_price"] boolValue])
  2043. cell.btnScanDiscount.hidden = false;
  2044. else
  2045. cell.btnScanDiscount.hidden = true;
  2046. }
  2047. break;;
  2048. // case 2: pricename = @"25%";
  2049. // break;
  2050. }
  2051. }
  2052. NSString* product_id = [item_json valueForKey:@"product_id"];
  2053. CGRect frame = cell.frame;
  2054. cell.labelMpack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
  2055. __weak typeof(self) weakSelf = self;
  2056. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  2057. {
  2058. int result = [[ext objectForKey:@"result"] intValue];
  2059. BOOL refresh = [[ext objectForKey:@"refresh"] boolValue];
  2060. if (result == 2 && refresh) {
  2061. [self ReloadData];
  2062. return;
  2063. }
  2064. NSMutableDictionary * item_json = nil;
  2065. if (weakSelf.back_order_flag) {
  2066. item_json = [[weakSelf itemJsonAtIndexPath:indexPath] mutableCopy];
  2067. } else {
  2068. item_json = [weakSelf.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2069. }
  2070. // int count=[[item_json valueForKey:@"count"] intValue];
  2071. // if(count==qty)
  2072. // return;
  2073. if ([[ext valueForKey:@"result"] integerValue] == 8) {
  2074. return ;
  2075. }
  2076. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  2077. double unit_cuft = [[item_json valueForKey:@"unit_cuft"] doubleValue];
  2078. [item_json setValue:[NSString stringWithFormat:@"%f",unit_cuft*qty] forKey:@"cuft"];
  2079. // [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  2080. // [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  2081. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  2082. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2083. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty*(1-discount/100.0)] forKey:@"subtotal_price"];
  2084. if (weakSelf.back_order_flag) {
  2085. [weakSelf updateItemJson:item_json atIndexPath:indexPath];
  2086. } else {
  2087. weakSelf.content_arr[indexPath.row]= item_json;
  2088. }
  2089. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2090. [weakSelf refresh_total];
  2091. #ifdef RA_NOTIFICATION
  2092. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2093. #else
  2094. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2095. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2096. #endif
  2097. };
  2098. // cell.delegate=self;
  2099. // cell.from=indexPath;
  2100. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  2101. if(RASingleton.sharedInstance.price_type==1&&([item_json[@"net_price"] boolValue]||[item_json[@"special_price"] boolValue]||discount>0))
  2102. {
  2103. cell.labelUnitPrice.textColor= [UIColor redColor];
  2104. if([item_json[@"special_price"] boolValue]||discount>0)
  2105. {
  2106. cell.labelOldPrice.hidden = false;
  2107. // if([item_json[@"special_price"] boolValue])
  2108. // {
  2109. cell.labelOldPrice.text=[RAConvertor currencyNumber:[item_json[price_group[@"price_1"][@"name"]] doubleValue]];//[NSString stringWithFormat:@"%.2f",[item_json[@"price1"] doubleValue]];
  2110. // }
  2111. // else
  2112. // {
  2113. // }
  2114. }
  2115. else
  2116. cell.labelOldPrice.hidden = true;
  2117. }
  2118. else
  2119. {
  2120. cell.labelUnitPrice.textColor= [UIColor blackColor];
  2121. cell.labelOldPrice.hidden = true;
  2122. }
  2123. // if(discount>0)
  2124. // {
  2125. // cell.labelNotes.text = [NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  2126. // cell.labelOldPrice.hidden = false;
  2127. //// cell.labelOldPrice.textColor = [UIColor redColor];
  2128. // cell.labelUnitPrice.textColor= [UIColor redColor];
  2129. // cell.labelOldPrice.text=[item_json[@"unit_price"] stringValue];
  2130. // frame.size.height = 120;
  2131. // }
  2132. // else
  2133. // {
  2134. //
  2135. //
  2136. // cell.labelOldPrice.hidden = true;
  2137. // cell.labelNotes.text = nil;
  2138. // frame.size.height = 94;
  2139. // }
  2140. cell.unit_price = unitprice;
  2141. // cell.labelAttribute.text = attribute;
  2142. // cell.labelCurrency.text = currency;
  2143. NSString* subtotal = [RAConvertor currencyNumber:unitprice*count*(1-discount/100)];//[NSString stringWithFormat:@"%.2f",unitprice*count*(1-discount/100)];
  2144. NSString* newunitprice = [RAConvertor currencyNumber:unitprice*(1-discount/100)];//[NSString stringWithFormat:@"%.2f",unitprice*(1-discount/100)];
  2145. cell.labelModel.text = model;
  2146. cell.labelDescription.text = [NSString stringWithFormat:@"%@\n%@",description,dimension];
  2147. // if(noprice&&unitprice==0.0)
  2148. // {
  2149. // cell.labelPrice.text = @"No Price";
  2150. //
  2151. // cell.labelUnitPrice.text = @"No Price";
  2152. // }
  2153. // else
  2154. {
  2155. cell.labelSubtotal.text = subtotal;
  2156. cell.labelUnitPrice.text = newunitprice;
  2157. }
  2158. bool check = [[item_json valueForKey:@"check"] boolValue];
  2159. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  2160. cell.cart_id = cart_item_id;
  2161. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  2162. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  2163. // else
  2164. // [cell init_Stepper:1 max:9999 min:1 value:count];
  2165. [cell set_Count:count];
  2166. // Button 设置了大小约束,Size就不会随内容变化
  2167. cell.backgroundColor = [UIColor whiteColor];
  2168. return cell;
  2169. #else
  2170. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2171. CellIdentifier = @"CartItemCell";
  2172. ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2173. NSDictionary * item_json = nil;//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2174. if (self.back_order_flag) {
  2175. item_json = [self itemJsonAtIndexPath:indexPath];
  2176. } else {
  2177. item_json = self.content_arr[indexPath.row];
  2178. }
  2179. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2180. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  2181. if (cell.masterBtn != nil) {
  2182. if (master_json == nil) {
  2183. cell.masterBtn.hidden = YES;
  2184. } else{
  2185. cell.masterBtn.hidden = NO;
  2186. cell.master_items = master_json;
  2187. }
  2188. }
  2189. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2190. NSString* notes = [item_json valueForKey:@"note"];
  2191. BOOL is_out_of_stock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  2192. bool noprice =[[item_json valueForKey:@"is_no_price"]boolValue];
  2193. cell.noprice = noprice;
  2194. cell.enable_longpress = true;
  2195. cell.bundle_item=combine_json;
  2196. NSString* img_url = [item_json valueForKey:@"img_url"];
  2197. NSString* description = [item_json valueForKey:@"description"];
  2198. // NSString* identifier = [item_json valueForKey:@"identifier"];
  2199. // NSString* attribute = [item_json valueForKey:@"attribute"];
  2200. // NSString* currency = [item_json valueForKey:@"currency"];
  2201. int count =[[item_json valueForKey:@"count"] intValue];
  2202. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  2203. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2204. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  2205. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  2206. NSString* product_id = [item_json valueForKey:@"product_id"];
  2207. // handle no such model
  2208. if(product_id.length==0)
  2209. cell.labelNoSuchModel.hidden=false;
  2210. else
  2211. cell.labelNoSuchModel.hidden=true;
  2212. //if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2213. if (!is_out_of_stock) {
  2214. cell.labelOutOfStock.hidden = YES;
  2215. } else {
  2216. cell.labelOutOfStock.hidden = NO;
  2217. }
  2218. // } else {
  2219. // cell.labelOutOfStock.hidden = YES;
  2220. // }
  2221. // discount = 5.0;
  2222. cell.discount = discount;
  2223. CGRect frame = cell.frame;
  2224. if(notes.length>0)
  2225. {
  2226. cell.labelNotes.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  2227. frame.size.height = 146;
  2228. }
  2229. else
  2230. {
  2231. cell.labelNotes.text = nil;
  2232. frame.size.height = 120;
  2233. }
  2234. // cell.frame = frame;
  2235. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  2236. if(isfree)
  2237. {
  2238. cell.labelOldPrice.hidden = false;
  2239. cell.labelOldPrice.textColor = [UIColor redColor];
  2240. cell.labelOldPrice.text=@"Free";
  2241. cell.labelOldPrice.hideline = true;
  2242. cell.labelDiscount.hidden = true;
  2243. }
  2244. else
  2245. {
  2246. cell.labelOldPrice.textColor = [UIColor blackColor];
  2247. cell.labelOldPrice.hideline = false;
  2248. if(discount==0)
  2249. {
  2250. cell.labelOldPrice.hidden = true;
  2251. cell.labelDiscount.hidden = true;
  2252. }
  2253. else
  2254. {
  2255. cell.labelOldPrice.hidden = false;
  2256. cell.labelDiscount.hidden = false;
  2257. }
  2258. }
  2259. __weak typeof(self) weakSelf = self;
  2260. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  2261. {
  2262. int result = [[ext objectForKey:@"result"] intValue];
  2263. BOOL refresh = [[ext objectForKey:@"refresh"] boolValue];
  2264. if (result == 2 && refresh) {
  2265. [self ReloadData];
  2266. return;
  2267. }
  2268. NSMutableDictionary * item_json = nil;
  2269. if (weakSelf.back_order_flag) {
  2270. item_json = [[weakSelf itemJsonAtIndexPath:indexPath] mutableCopy];
  2271. } else {
  2272. item_json = [weakSelf.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2273. }
  2274. // int count=[[item_json valueForKey:@"count"] intValue];
  2275. // if(count==qty)
  2276. // return;
  2277. if ([[ext valueForKey:@"result"] integerValue] == 8) {
  2278. return ;
  2279. }
  2280. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  2281. [item_json setValue:[ext valueForKey:@"cuft"] forKey:@"cuft"];
  2282. [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  2283. [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  2284. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  2285. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2286. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty] forKey:@"subtotal_price"];
  2287. if (weakSelf.back_order_flag) {
  2288. [weakSelf updateItemJson:item_json atIndexPath:indexPath];
  2289. } else {
  2290. weakSelf.content_arr[indexPath.row]= item_json;
  2291. }
  2292. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2293. [weakSelf refresh_total];
  2294. #ifdef RA_NOTIFICATION
  2295. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2296. #else
  2297. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2298. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2299. #endif
  2300. };
  2301. // cell.delegate=self;
  2302. // cell.from=indexPath;
  2303. cell.unit_price = unitprice;
  2304. // cell.labelAttribute.text = attribute;
  2305. // cell.labelCurrency.text = currency;
  2306. NSString* oldprice =[NSString stringWithFormat:@"%.2f",unitprice];
  2307. NSString* newprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)*count];
  2308. NSString* newunitprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
  2309. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2310. {
  2311. }
  2312. else
  2313. {
  2314. oldprice=nil;
  2315. newprice=nil;
  2316. newunitprice=nil;
  2317. }
  2318. cell.labelDiscount.text = discountstr;
  2319. cell.labelOldPrice.text = oldprice;
  2320. cell.labelMasterpack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
  2321. cell.labelDescription.text = description;
  2322. // cell.labelIdentifier.text = identifier;
  2323. if(noprice&&unitprice==0.0)
  2324. {
  2325. cell.labelPrice.text = @"No Price";
  2326. cell.labelUnitPrice.text = @"No Price";
  2327. }
  2328. else
  2329. {
  2330. cell.labelPrice.text = newprice;
  2331. cell.labelUnitPrice.text = newunitprice;
  2332. }
  2333. bool check = [[item_json valueForKey:@"check"] boolValue];
  2334. if(check)
  2335. {
  2336. cell.img_checkmark.hidden=false;
  2337. // [item_json setValue:@"0" forKey:@"check"];
  2338. }
  2339. else
  2340. {
  2341. // [item_json setValue:@"1" forKey:@"check"];
  2342. cell.img_checkmark.hidden=true;
  2343. }
  2344. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  2345. cell.cart_id = cart_item_id;
  2346. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  2347. {
  2348. #ifdef IGNORE_SOLD_IN_QTY
  2349. [cell init_Stepper:1 max:9999 min:1 value:count];
  2350. #else
  2351. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  2352. #endif
  2353. }
  2354. // else
  2355. // [cell init_Stepper:1 max:9999 min:1 value:count];
  2356. [cell set_Count:count];
  2357. // Button 设置了大小约束,Size就不会随内容变化
  2358. [cell.btnImage setContentMode:UIViewContentModeScaleAspectFit];
  2359. [cell.btnImage setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  2360. [cell.btnImage setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  2361. [cell.btnImage setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  2362. cell.btnImage.imageView.contentMode = UIViewContentModeScaleAspectFit;
  2363. if (![cell.imageName isEqualToString:img_url]) {
  2364. cell.imageName = img_url;
  2365. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2366. [cell.btnImage setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2367. NSString* file_name=[img_url lastPathComponent];
  2368. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2369. if(img_data!=nil)
  2370. {
  2371. UIImage * img =[UIImage imageWithData:img_data];
  2372. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  2373. [cell.btnImage setImage:img forState:UIControlStateNormal];
  2374. }
  2375. else
  2376. {
  2377. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2378. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2379. dispatch_async(dispatch_get_main_queue(), ^{
  2380. if(downloadimg_data!=nil)
  2381. {
  2382. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2383. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2384. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  2385. [cell.btnImage setImage:img forState:UIControlStateNormal];
  2386. }
  2387. else
  2388. {
  2389. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2390. [cell.btnImage setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2391. }
  2392. });
  2393. });
  2394. }
  2395. }
  2396. cell.backgroundColor = [UIColor whiteColor];
  2397. if(self.itemListTable.editing)
  2398. {
  2399. cell.editCount.enabled = false;
  2400. cell.stepper.hidden=true;
  2401. }
  2402. else
  2403. {
  2404. cell.editCount.enabled=true;
  2405. cell.stepper.hidden=false;
  2406. }
  2407. return cell;
  2408. // }
  2409. // else
  2410. // {
  2411. // NSString *CellIdentifier = @"OrderInfoListItem";
  2412. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2413. // return cell;
  2414. // }
  2415. #endif
  2416. }
  2417. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
  2418. {
  2419. if(!self.itemListTable.editing)
  2420. return;
  2421. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2422. NSMutableDictionary * item_json = nil;
  2423. if (self.back_order_flag) {
  2424. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2425. } else {
  2426. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2427. }
  2428. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2429. if ([self.edit_select_arr containsObject:cart_item_id])
  2430. {
  2431. [self.edit_select_arr removeObject:cart_item_id];
  2432. }
  2433. }
  2434. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  2435. {
  2436. #ifdef SCANNER_ORDER
  2437. return;
  2438. #endif
  2439. NSMutableDictionary * item_json = nil;
  2440. if (self.back_order_flag) {
  2441. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2442. } else {
  2443. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2444. }
  2445. // NSMutableDictionary * item_json =[self.content_arr[indexPath.row] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2446. if(self.itemListTable.editing)
  2447. {
  2448. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2449. if (![self.edit_select_arr containsObject:cart_item_id]) {
  2450. [self.edit_select_arr addObject:cart_item_id];
  2451. }
  2452. return;
  2453. }
  2454. // no checkmark support anymore for cart
  2455. return;
  2456. }
  2457. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  2458. if(self.itemListTable.editing)
  2459. return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
  2460. else
  2461. return UITableViewCellEditingStyleDelete;
  2462. }
  2463. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  2464. //- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  2465. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath
  2466. {
  2467. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2468. // 添加一个删除按钮
  2469. self.indexPath=indexPath;
  2470. NSMutableDictionary * item_json = nil;
  2471. if (self.back_order_flag) {
  2472. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2473. } else {
  2474. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2475. }
  2476. NSString* productID = [item_json valueForKey:@"product_id"];
  2477. BOOL outOfStock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  2478. __weak typeof(self) weakself = self;
  2479. // UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@" Delete " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2480. UIContextualAction* deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@" Delete " handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2481. DebugLog(@"delete click");
  2482. //[self.itemListTable setEditing:false animated:YES];
  2483. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Confirm Deletion" message:@"Are you sure to delete this model?" preferredStyle:UIAlertControllerStyleAlert];
  2484. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2485. // [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2486. NSMutableDictionary * item_json = nil;
  2487. if (self.back_order_flag) {
  2488. item_json = [[self itemJsonAtIndexPath:self.indexPath] mutableCopy];
  2489. } else {
  2490. item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2491. }
  2492. NSString *ids=[NSString stringWithFormat:@"%@",[item_json valueForKey:@"cart_item_id"] ];
  2493. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Model" completion:^{
  2494. PopWaitAlert* pop = [RAUtils waiting_pop:@"Remove Model" completion:nil];
  2495. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  2496. NSMutableDictionary* cart_json = result;
  2497. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2498. [pop hide];
  2499. if([[cart_json valueForKey:@"result"] intValue]==2)
  2500. {
  2501. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2502. if (self.back_order_flag) {
  2503. NSInteger section_count = [self sectionCount];
  2504. for (int i = 0; i < section_count; i++) {
  2505. NSInteger item_count = [self itemCountInSection:i];
  2506. BOOL ready_break = NO;
  2507. for (int j = 0; j < item_count; j++) {
  2508. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  2509. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  2510. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  2511. if([_id isEqualToString:ids])
  2512. {
  2513. [self updateItemJson:nil atIndexPath:indexPath];
  2514. ready_break = YES;
  2515. break;
  2516. }
  2517. }
  2518. if (ready_break) {
  2519. break;
  2520. }
  2521. }
  2522. } else {
  2523. for(int i=0;i<self.content_arr.count;i++)
  2524. {
  2525. NSDictionary* obj_json = self.content_arr[i];
  2526. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  2527. if([_id isEqualToString:ids])
  2528. {
  2529. [self.content_arr removeObjectAtIndex:i];
  2530. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  2531. break;
  2532. // appDelegate.cart_count--;
  2533. // [appDelegate update_count_mark];
  2534. }
  2535. }
  2536. }
  2537. #ifdef SCANNER_ORDER
  2538. self.cart_json = cart_json;
  2539. #endif
  2540. [self.itemListTable reloadData];
  2541. [self refresh_total];
  2542. #ifdef RA_NOTIFICATION
  2543. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2544. #else
  2545. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2546. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2547. #endif
  2548. // [self reload_data];
  2549. }
  2550. else
  2551. {
  2552. [RAUtils message_box:@"Delete Model" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  2553. }
  2554. // }];
  2555. }];
  2556. // }];
  2557. }];
  2558. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  2559. }];
  2560. [alertController addAction:action_2];
  2561. [alertController addAction:action_3];
  2562. [self presentViewController:alertController animated:YES completion:nil];
  2563. // 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];
  2564. // alert.tag = ALERT_DEL;
  2565. // // alert.
  2566. // [alert show];
  2567. }];
  2568. deleteRowAction.backgroundColor = [UIColor redColor];
  2569. UIContextualAction* notifyMeAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Notify Me" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2570. {
  2571. // __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  2572. PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  2573. [RANetwork request_notifymodel:productID emailAddr:nil withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  2574. NSMutableDictionary *dic = result;
  2575. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  2576. // [waitting_alert dismissViewControllerAnimated:YES completion:^{
  2577. [pop hide];
  2578. int result_code = [[dic valueForKey:@"result"] intValue];
  2579. if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS)
  2580. {
  2581. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  2582. if ([dic valueForKey:@"err_msg"]) {
  2583. msg = [dic valueForKey:@"err_msg"];
  2584. }
  2585. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  2586. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2587. }];
  2588. [errorAlertVC addAction:action];
  2589. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  2590. } else if (result_code == RESULT_TRUE){
  2591. [RAUtils message_box:@"Message" message:@"Notification is sent to default email address." completion:nil];
  2592. } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
  2593. [weakself showAddressBoxToEmailProduct:productID];
  2594. }
  2595. // }];
  2596. }];
  2597. // }];
  2598. };
  2599. }];
  2600. // UITableViewRowAction *notifyMeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Notify Me" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  2601. //
  2602. // {
  2603. //
  2604. //// __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  2605. // PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  2606. // [RANetwork request_notifymodel:productID emailAddr:nil withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  2607. // NSMutableDictionary *dic = result;
  2608. //
  2609. //
  2610. // // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  2611. //// [waitting_alert dismissViewControllerAnimated:YES completion:^{
  2612. // [pop hide];
  2613. // int result_code = [[dic valueForKey:@"result"] intValue];
  2614. //
  2615. // if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS)
  2616. // {
  2617. //
  2618. // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  2619. //
  2620. // if ([dic valueForKey:@"err_msg"]) {
  2621. // msg = [dic valueForKey:@"err_msg"];
  2622. // }
  2623. //
  2624. //
  2625. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  2626. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2627. //
  2628. // }];
  2629. //
  2630. // [errorAlertVC addAction:action];
  2631. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  2632. //
  2633. // } else if (result_code == RESULT_TRUE){
  2634. //
  2635. // [RAUtils message_box:@"Message" message:@"Notification is sent to default email address." completion:nil];
  2636. //
  2637. // } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
  2638. //
  2639. // [weakself showAddressBoxToEmailProduct:productID];
  2640. //
  2641. // }
  2642. //// }];
  2643. //
  2644. //
  2645. //
  2646. // }];
  2647. //
  2648. //// }];
  2649. //
  2650. // };
  2651. //
  2652. //
  2653. // }];
  2654. notifyMeAction.backgroundColor = UIColorFromRGB(0x9BBF5A);
  2655. // UITableViewRowAction *addWatchAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Move To Wish List" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
  2656. UIContextualAction* addWatchAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Move To Wish List" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2657. DebugLog(@"Wishlist click");
  2658. NSMutableDictionary * item_json = nil;
  2659. if (self.back_order_flag) {
  2660. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2661. } else {
  2662. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2663. }
  2664. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  2665. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2666. [RANetwork request_move_cart2wish:cart_item_id completionHandler:^(NSMutableDictionary *result) {
  2667. NSDictionary* return_json = result;
  2668. if([[return_json valueForKey:@"result"] intValue]==2)
  2669. {
  2670. #ifdef RA_NOTIFICATION
  2671. [ActiveViewController Notify:@"WatchListViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2672. #else
  2673. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2674. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  2675. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2676. #endif
  2677. for(int i=0;i<self.content_arr.count;i++)
  2678. {
  2679. NSDictionary* obj_json = self.content_arr[i];
  2680. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  2681. if([_id isEqualToString:cart_item_id])
  2682. {
  2683. if (self.back_order_flag) {
  2684. [self updateItemJson:nil atIndexPath:indexPath];
  2685. } else {
  2686. [self.content_arr removeObjectAtIndex:i];
  2687. }
  2688. [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  2689. appDelegate.cart_count--;
  2690. [appDelegate update_count_mark];
  2691. [self refresh_total];
  2692. }
  2693. }
  2694. [self.itemListTable reloadData];
  2695. }
  2696. else
  2697. {
  2698. [RAUtils message_box:@"Move To Wish List" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  2699. }
  2700. }];
  2701. }];
  2702. addWatchAction.backgroundColor = UIColorFromRGB(0x339966);
  2703. // 添加一个编辑按钮
  2704. // UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Edit Price"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
  2705. UIContextualAction* editRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Edit Price" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2706. DebugLog(@"edit click");
  2707. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  2708. if (self.currentOrderIsMerged) { // 合并过的订单不能编辑价格
  2709. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Purchase Order Can't Edit Price" preferredStyle:UIAlertControllerStyleAlert];
  2710. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  2711. [alert dismissViewControllerAnimated:YES completion:nil];
  2712. }];
  2713. [alert addAction:action];
  2714. if (weakself) {
  2715. __strong typeof(weakself) strongself = weakself;
  2716. [strongself presentViewController:alert animated:YES completion:nil];
  2717. }
  2718. return ;
  2719. }
  2720. if ([RASingleton sharedInstance].npd_shop_price_type == 0) { // 提货价不能编辑价格
  2721. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current Price Type is %@,You Can't Change it",[RASingleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  2722. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  2723. [alert dismissViewControllerAnimated:YES completion:nil];
  2724. }];
  2725. [alert addAction:action];
  2726. if (weakself) {
  2727. __strong typeof(weakself) strongself = weakself;
  2728. [strongself presentViewController:alert animated:YES completion:nil];
  2729. }
  2730. return ;
  2731. }
  2732. }
  2733. UIViewController* parentvc=self;
  2734. EditModelPriceViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"EditModelPriceViewController"];
  2735. NSMutableDictionary * item_json = nil;
  2736. if (self.back_order_flag) {
  2737. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2738. } else {
  2739. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2740. }
  2741. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  2742. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  2743. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2744. __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  2745. // vc.delegate = parentvc.self;
  2746. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2747. vc.onSetValue = ^(double price,double discount){
  2748. bool bmodify=false;
  2749. if(price!= [[item_json valueForKey:@"unit_price"] floatValue])
  2750. bmodify=true;
  2751. NSString* notes = [item_json valueForKey:@"note"];
  2752. if(notes.length==0)
  2753. notes=@"";
  2754. if(bmodify)
  2755. {
  2756. if([notes isEqualToString:@""])
  2757. notes=@"PRICE MODIFIED";
  2758. NSRange range;
  2759. range = [notes rangeOfString:@"PRICE MODIFIED"];
  2760. if (range.location != NSNotFound) {
  2761. }else{
  2762. notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  2763. }
  2764. }
  2765. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  2766. PopWaitAlert* pop = [RAUtils waiting_pop:@"Update Price" completion:nil];
  2767. [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:notes completionHandler:^(NSMutableDictionary *result) {
  2768. NSDictionary* cart_json = result;
  2769. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2770. [pop hide];
  2771. if([[cart_json valueForKey:@"result"] intValue]==2)
  2772. {
  2773. [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  2774. [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  2775. [item_json setValue:notes forKey:@"note"];
  2776. if (self.back_order_flag) {
  2777. [self updateItemJson:item_json atIndexPath:indexPath];
  2778. } else {
  2779. self.content_arr[indexPath.row ] = item_json;
  2780. }
  2781. tableView.editing = false;
  2782. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2783. // [self refresh_total];
  2784. [weakself reload_data];
  2785. #ifdef RA_NOTIFICATION
  2786. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2787. #else
  2788. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2789. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2790. #endif
  2791. }
  2792. else
  2793. {
  2794. [RAUtils message_box:@"Update Price" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  2795. }
  2796. // }];
  2797. }];
  2798. // }];
  2799. // [self reload_data];//[main_vc checklogin:true];
  2800. };
  2801. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2802. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2803. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2804. [parentvc presentViewController:navi animated:YES completion:^{
  2805. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2806. DebugLog(@"EditModelPriceViewController present.........");
  2807. // self.btop = false;
  2808. // <#code#>
  2809. }];
  2810. // [self.itemListTable setEditing:false animated:YES];
  2811. //[tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2812. }];
  2813. editRowAction.backgroundColor = UIColorFromRGB(0xff9933);
  2814. // // 添加一个更多按钮
  2815. //
  2816. // UITableViewRowAction *moreRowAction = [UITableView RowActionrowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2817. //
  2818. // DebugLog(@点击了更多);
  2819. //
  2820. //
  2821. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2822. //
  2823. // }];
  2824. //
  2825. // moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
  2826. //
  2827. // 将设置好的按钮放到数组中返回
  2828. // UITableViewRowAction *freeRowAction = nil;
  2829. //
  2830. //
  2831. // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2832. //
  2833. // bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2834. //
  2835. // if(!isfree)
  2836. // {
  2837. //
  2838. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Set Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2839. //
  2840. // DebugLog(@"free click");
  2841. //
  2842. //
  2843. //
  2844. // 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];
  2845. // alert.tag = ALERT_SET_FREE;
  2846. // // alert.
  2847. // [alert show];
  2848. // }];
  2849. // }
  2850. // else
  2851. // {
  2852. //
  2853. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Not Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2854. //
  2855. // 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];
  2856. // alert.tag = ALERT_RESTORE_FREE;
  2857. // // alert.
  2858. // [alert show];
  2859. // }];
  2860. // }
  2861. //
  2862. //
  2863. //
  2864. // freeRowAction.backgroundColor = [UIColor lightGrayColor];
  2865. // UITableViewRowAction *noteRowAction = nil;
  2866. //
  2867. //
  2868. // // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2869. //
  2870. //
  2871. //
  2872. //
  2873. // noteRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Edit note" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2874. UIContextualAction* noteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Edit note" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2875. DebugLog(@"item note click");
  2876. UIViewController* parentvc=self;
  2877. ItemNotesViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"ItemNotesViewController"];
  2878. NSMutableDictionary * item_json = nil;
  2879. if (self.back_order_flag) {
  2880. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2881. } else {
  2882. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2883. }
  2884. vc.onSaveNote=^(NSString* notes){
  2885. [item_json setValue:notes forKey:@"note"];
  2886. if (self.back_order_flag) {
  2887. [self updateItemJson:item_json atIndexPath:indexPath];
  2888. } else {
  2889. self.content_arr[indexPath.row ] = item_json;
  2890. }
  2891. tableView.editing = false;
  2892. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2893. };
  2894. vc.notes=[item_json valueForKey:@"note"];
  2895. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2896. // vc.delegate = parentvc.self;
  2897. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2898. // vc.onSetValue = ^(){
  2899. // [self reload_data];//[main_vc checklogin:true];
  2900. // };
  2901. //
  2902. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2903. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2904. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2905. [parentvc presentViewController:navi animated:YES completion:^{
  2906. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2907. DebugLog(@"EditModelPriceViewController present.........");
  2908. // self.btop = false;
  2909. // <#code#>
  2910. }];
  2911. // [self.itemListTable setEditing:false animated:YES];
  2912. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2913. }];
  2914. noteRowAction.backgroundColor = [UIColor lightGrayColor];
  2915. // UITableViewRowAction *move2BackAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Move to Back Order" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  2916. UIContextualAction* move2BackAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Move to Back Order" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2917. NSDictionary *item_json = [self itemJsonAtIndexPath:indexPath];
  2918. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  2919. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move To Back Order" completion:^{
  2920. PopWaitAlert* pop = [RAUtils waiting_pop:@"Move To Back Order" completion:nil];
  2921. [RANetwork request_movetobackorder:cart_item_id completionHandler:^(NSMutableDictionary *result) {
  2922. NSMutableDictionary* return_json =result ;
  2923. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2924. [pop hide];
  2925. if([[return_json valueForKey:@"result"] intValue]==2) {
  2926. [self reload_data];
  2927. } // if 2
  2928. else {
  2929. [RAUtils message_box:@"Move To Back Order" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  2930. }
  2931. // }];
  2932. }];
  2933. // }];
  2934. }];
  2935. move2BackAction.backgroundColor = UIColorFromRGB(0x336699);
  2936. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  2937. {
  2938. NSMutableDictionary * item_json = nil;
  2939. if (self.back_order_flag) {
  2940. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2941. } else {
  2942. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2943. }
  2944. NSString* product_id = [item_json valueForKey:@"product_id"];
  2945. int is_rate = [item_json[@"is_rate"] intValue];
  2946. NSMutableArray* arr=[@[] mutableCopy];
  2947. BOOL condition = outOfStock;
  2948. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  2949. #ifdef OFFLINE_MODE
  2950. condition = !appDelegate.offline_mode && outOfStock;
  2951. #endif
  2952. if (condition) {
  2953. [arr addObject:notifyMeAction];
  2954. }
  2955. NSDictionary *section_json = [self jsonAtSection:indexPath.section];
  2956. BOOL available = [[section_json objectForKey:@"available"] boolValue]; // available list
  2957. if (self.back_order_flag && available) {
  2958. [arr addObject:move2BackAction];
  2959. }
  2960. #endif
  2961. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  2962. #ifdef OFFLINE_MODE
  2963. condition = !appDelegate.offline_mode && outOfStock;
  2964. #endif
  2965. if (condition) {
  2966. [arr addObject:notifyMeAction];
  2967. }
  2968. #endif
  2969. if(product_id.length>0)
  2970. [arr addObject:noteRowAction];
  2971. [arr addObject:deleteRowAction];
  2972. #ifndef SCANNER_ORDER
  2973. if(product_id.length>0&& is_rate==0)
  2974. [arr addObject:addWatchAction];
  2975. if(appDelegate.can_set_cart_price && product_id.length>0&& is_rate==0)
  2976. {
  2977. [arr addObject:editRowAction];
  2978. // [arr addObject:freeRowAction];
  2979. }
  2980. #endif
  2981. // return arr;
  2982. return [UISwipeActionsConfiguration configurationWithActions:arr];
  2983. // return @[deleteRowAction,addWatchAction, editRowAction,freeRowAction];
  2984. } else if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2985. if (appDelegate.customer_type == CustomerTypeStore) {
  2986. #ifndef SCANNER_ORDER
  2987. // return @[notifyMeAction,deleteRowAction,addWatchAction,editRowAction];
  2988. return [UISwipeActionsConfiguration configurationWithActions:@[notifyMeAction,deleteRowAction,addWatchAction,editRowAction]];
  2989. #else
  2990. // return @[deleteRowAction];
  2991. return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
  2992. #endif
  2993. } else {
  2994. // normal
  2995. // NSArray *actionArray = @[notifyMeAction,deleteRowAction,addWatchAction];
  2996. NSMutableArray *actionArray = [NSMutableArray array];
  2997. // move to backorder
  2998. NSDictionary *section_json = [self jsonAtSection:indexPath.section];
  2999. BOOL available = [[section_json objectForKey:@"available"] boolValue]; // available list
  3000. if (self.back_order_flag && available) {
  3001. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction];
  3002. [actionArray addObject:move2BackAction];
  3003. }
  3004. [actionArray addObjectsFromArray:@[notifyMeAction,deleteRowAction,addWatchAction]];
  3005. // edit price
  3006. NSMutableDictionary * item_json = nil;
  3007. if (self.back_order_flag) {
  3008. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3009. } else {
  3010. item_json = [self.content_arr[indexPath.row] mutableCopy];
  3011. }
  3012. NSString* product_id = [item_json valueForKey:@"product_id"];
  3013. int is_rate = [item_json[@"is_rate"] intValue];
  3014. if(appDelegate.can_set_cart_price && product_id.length>0&& is_rate==0) {
  3015. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction,editRowAction];
  3016. [actionArray addObject:editRowAction];
  3017. }
  3018. // return actionArray;
  3019. return [UISwipeActionsConfiguration configurationWithActions:actionArray];
  3020. }
  3021. }
  3022. else
  3023. #ifndef SCANNER_ORDER
  3024. // return @[deleteRowAction,addWatchAction];
  3025. return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction,addWatchAction]];
  3026. #else
  3027. // return @[deleteRowAction];
  3028. return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
  3029. #endif
  3030. }
  3031. - (void)tableView:(UITableView *)tableView
  3032. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  3033. }
  3034. #pragma mark - Support scanner
  3035. -(void) onDecodedData:(NSString*) value
  3036. {
  3037. int cqty=0;
  3038. if (self.back_order_flag) {
  3039. NSInteger section_count = [self sectionCount];
  3040. for (int i = 0; i < section_count; i++) {
  3041. NSInteger item_count = [self itemCountInSection:i];
  3042. for (int j = 0; j < item_count; j++) {
  3043. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  3044. NSDictionary* item = [self itemJsonAtIndexPath:indexPath];
  3045. if([item[@"model"] isEqualToString:value]) {
  3046. cqty=[item[@"count"] intValue];
  3047. }
  3048. }
  3049. }
  3050. } else {
  3051. for(int i=0;i<self.content_arr.count;i++)
  3052. {
  3053. NSDictionary* item= self.content_arr[i];
  3054. if([item[@"model"] isEqualToString:value])
  3055. cqty=[item[@"count"]intValue];
  3056. }
  3057. }
  3058. if(cqty>0)
  3059. {
  3060. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  3061. //block代码块取代了delegate
  3062. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  3063. [self addtocart:value];
  3064. }];
  3065. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  3066. DebugLog(@"No");
  3067. }];
  3068. [alertControl addAction:actionOne];
  3069. [alertControl addAction:alertthree];
  3070. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  3071. [self presentViewController:alertControl animated:YES completion:nil];
  3072. }
  3073. else
  3074. [self addtocart:value];
  3075. }
  3076. -(void) addtocart:(NSString*) modelname
  3077. {
  3078. [RANetwork request_addto_cart_byname:modelname withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  3079. NSDictionary* return_json =result;
  3080. if([[return_json valueForKey:@"result"] intValue]==2)
  3081. {
  3082. NSDictionary* newitem = [return_json objectForKey:@"item_0"];
  3083. NSString* item_id = [newitem valueForKey:@"cart_item_id"];
  3084. // bool isnew=false;
  3085. //
  3086. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  3087. if (self.back_order_flag) {
  3088. NSInteger section_count = [self sectionCount];
  3089. for (int i = 0; i < section_count; i++) {
  3090. NSInteger item_count = [self itemCountInSection:i];
  3091. BOOL ready_break = NO;
  3092. for (int j = 0; j < item_count; j++) {
  3093. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  3094. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  3095. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3096. if([_id isEqualToString:item_id])
  3097. {
  3098. [self updateItemJson:nil atIndexPath:indexPath];
  3099. ready_break = YES;
  3100. break;
  3101. }
  3102. }
  3103. if (ready_break) {
  3104. break;
  3105. }
  3106. }
  3107. } else {
  3108. for(int i=0;i<self.content_arr.count;i++)
  3109. {
  3110. NSDictionary* obj_json = self.content_arr[i];
  3111. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3112. if([_id isEqualToString:item_id])
  3113. {
  3114. // self.content_arr[i] = newitem;
  3115. [self.content_arr removeObjectAtIndex:i];
  3116. break;
  3117. // [self.content_arr removeObjectAtIndex:i];
  3118. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3119. // appDelegate.cart_count--;
  3120. // [appDelegate update_count_mark];
  3121. }
  3122. }
  3123. }
  3124. AppDelegate *appDelegate =nil;
  3125. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3126. #ifdef OFFLINE_MODE
  3127. if(appDelegate.offline_mode)
  3128. {
  3129. [self ReloadData];
  3130. }
  3131. else
  3132. #endif
  3133. {
  3134. if (self.back_order_flag) {
  3135. [self ReloadData];
  3136. } else {
  3137. [self.content_arr insertObject:newitem atIndex:0];
  3138. [self.itemListTable reloadData];
  3139. [self refresh_total];
  3140. }
  3141. }
  3142. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3143. #ifdef RA_NOTIFICATION
  3144. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3145. #else
  3146. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  3147. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3148. #endif
  3149. }
  3150. else
  3151. {
  3152. [RAUtils message_box:@"Add To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  3153. }
  3154. }];
  3155. }
  3156. #pragma mark - sort button
  3157. - (void)cartSortButtonClicked:(UIButton *)sender {
  3158. DebugLog(@"cart sort button clicked");
  3159. [self.view addSubview:self.sortItemController.view];
  3160. }
  3161. - (SortItemViewController *)sortItemController {
  3162. if (!_sortItemController) {
  3163. _sortItemController = [[SortItemViewController alloc] initWithTableOrigin:CGPointMake(20, 50)];
  3164. _sortItemController.sortIndex = self.sortIndex;
  3165. _sortItemController.sortData = @[
  3166. @{@"title":@"Last",@"icon":@"TX_18"},
  3167. @{@"title":@"First",@"icon":@"TS_18"},
  3168. @{@"title":@"Item number a-z",@"icon":@"IX_18"},
  3169. @{@"title":@"Item number z-a",@"icon":@"IS_18"},
  3170. @{@"title":@"Description",@"icon":@"DX_18"},
  3171. ];
  3172. __weak typeof(self) weakSelf = self;
  3173. _sortItemController.sortBlock = ^(int sort){
  3174. weakSelf.sortIndex = sort;
  3175. [weakSelf reload_data];
  3176. };
  3177. }
  3178. // _sortItemController.sortIndex = self.sortIndex;
  3179. return _sortItemController;
  3180. }
  3181. - (SortButton *)sortButton {
  3182. if (!_sortButton) {
  3183. _sortButton = [SortButton sortButtonWithHeight:40];
  3184. _sortButton.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  3185. [_sortButton addTarget:self action:@selector(cartSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  3186. }
  3187. return _sortButton;
  3188. }
  3189. - (void)setSortIndex:(int)sortIndex {
  3190. _sortIndex = sortIndex;
  3191. NSString *selectedImageName = @"";
  3192. switch (sortIndex) {
  3193. case 0:{
  3194. selectedImageName = @"TX_22";
  3195. }
  3196. break;
  3197. case 1:{
  3198. selectedImageName = @"TS_22";
  3199. }
  3200. break;
  3201. case 2:{
  3202. selectedImageName = @"IX_22";
  3203. }
  3204. break;
  3205. case 3:{
  3206. selectedImageName = @"IS_22";
  3207. }
  3208. break;
  3209. case 4:{
  3210. selectedImageName = @"DX_22";
  3211. }
  3212. break;
  3213. default:
  3214. break;
  3215. }
  3216. self.sortButton.imageView.image = [UIImage imageNamed:selectedImageName];
  3217. }
  3218. #pragma mark - rotation
  3219. //- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  3220. //
  3221. // self.sortItemController.view.frame = self.view.bounds;
  3222. //}
  3223. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  3224. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  3225. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  3226. // what ever you want to prepare
  3227. } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  3228. // self.sortItemController.view.frame = self.view.bounds;
  3229. self.sortItemController.view.frame = self.view.bounds;
  3230. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  3231. // [self.itemListTable reloadData];
  3232. self.cartIndicatorBar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.cartIndicatorBar.bounds].CGPath;
  3233. [self layoutCartIndicatorBar];
  3234. }];
  3235. }
  3236. -(BOOL) shouldAutorotate
  3237. {
  3238. return YES;
  3239. }
  3240. //- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  3241. // return YES;
  3242. //}
  3243. //- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  3244. // self.sortItemController.view.frame = self.view.bounds;
  3245. // self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  3246. //
  3247. //// [self.itemListTable reloadData];
  3248. //
  3249. // self.cartIndicatorBar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.cartIndicatorBar.bounds].CGPath;
  3250. // [self layoutCartIndicatorBar];
  3251. //}
  3252. #pragma mark - notification action
  3253. - (void)priceTypeChanged:(id)notification {
  3254. [self reload_data];
  3255. #ifdef RA_NOTIFICATION
  3256. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3257. #else
  3258. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  3259. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3260. #endif
  3261. }
  3262. #pragma mark - button action
  3263. - (IBAction)emailButtonClick:(UIButton *)sender {
  3264. if (![self isOrderAvailable]) {
  3265. return;
  3266. }
  3267. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  3268. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"Please enter email address"];
  3269. emailAddrVC.textFiled.secureTextEntry = NO;
  3270. emailAddrVC.yesButtonTitle = @"send";
  3271. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  3272. __weak typeof(self) weakself = self;
  3273. emailAddrVC.textHandler = ^(NSString *text){
  3274. // 验证邮箱格式是否正确
  3275. // NSString *match = EMAIL_MATCHES;
  3276. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  3277. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  3278. BOOL isEmailAddr = YES;
  3279. if (isEmailAddr) {
  3280. // 验证是邮件地址,发送邮件
  3281. [weakVC dismissViewControllerAnimated:YES completion:^{
  3282. // __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  3283. PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  3284. [RANetwork request_qouteorder:appDelegate.order_code emailAddr:text completionHandler:^(NSMutableDictionary *result) {
  3285. DebugLog(@"email cart result: %@",result);
  3286. // [waitting_alert dismissViewControllerAnimated:YES completion:^{
  3287. [pop hide];
  3288. // [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  3289. if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  3290. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  3291. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3292. }];
  3293. [errorAlertVC addAction:action];
  3294. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  3295. }else {
  3296. [RAUtils message_box:@"Message" message:@"Send Email Success" completion:nil];
  3297. }
  3298. // }];
  3299. }];
  3300. // }];
  3301. }];
  3302. } else {
  3303. // 非邮件地址,警告
  3304. [weakVC warning:@"Please enter right email address"];
  3305. }
  3306. };
  3307. [self presentViewController:emailAddrVC animated:YES completion:nil];
  3308. }
  3309. - (IBAction)printCartButtonClick:(UIButton *)sender {
  3310. if (![self isOrderAvailable]) {
  3311. return;
  3312. }
  3313. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  3314. ViewController.url = self.print_url;
  3315. ViewController.canSave = false;
  3316. ViewController.isLocalfile=NO;
  3317. NSString* subject;
  3318. subject =@"Cart Print";
  3319. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3320. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  3321. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  3322. if(customer_email.length>0)
  3323. {
  3324. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  3325. }
  3326. ViewController.mail_to = send_to;
  3327. ViewController.filename = [NSString stringWithFormat:@"%@_Product_List.pdf",COMPANY_SHORT_NAME];
  3328. ViewController.mail_subject = subject;
  3329. ViewController.hidenavi = false;
  3330. [self.navigationController pushViewController:ViewController animated:YES];
  3331. }
  3332. - (void)showAddressBoxToEmailProduct:(NSString *)productID {
  3333. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  3334. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"E-mail not setup, please enter your default e-mail address" ContentSize:CGSizeMake(400, 150)];
  3335. emailAddrVC.textFiled.secureTextEntry = NO;
  3336. emailAddrVC.yesButtonTitle = @"send";
  3337. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  3338. __weak typeof(self) weakself = self;
  3339. emailAddrVC.textHandler = ^(NSString *text){
  3340. // 验证邮箱格式是否正确
  3341. // NSString *match = EMAIL_MATCHES;
  3342. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  3343. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  3344. BOOL isEmailAddr = YES;
  3345. if (isEmailAddr) {
  3346. // 验证是邮件地址,发送邮件
  3347. [weakVC dismissViewControllerAnimated:YES completion:^{
  3348. // __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  3349. PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  3350. [RANetwork request_notifymodel:productID emailAddr:text withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  3351. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  3352. // [waitting_alert dismissViewControllerAnimated:YES completion:^{
  3353. [pop hide];
  3354. int resultStatus = [[result objectForKey:@"result"] intValue];
  3355. if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  3356. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  3357. if ([result valueForKey:@"err_msg"]) {
  3358. msg = [result valueForKey:@"err_msg"];
  3359. }
  3360. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  3361. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3362. }];
  3363. [errorAlertVC addAction:action];
  3364. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  3365. }else if(resultStatus == RESULT_TRUE){
  3366. [RAUtils message_box:@"Message" message:@"Notification is sent to default email address." completion:nil];
  3367. } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  3368. [weakself showAddressBoxToEmailProduct:productID];
  3369. }
  3370. // }];
  3371. }];
  3372. // }];
  3373. }];
  3374. } else {
  3375. // 非邮件地址,警告
  3376. [weakVC warning:@"Please enter right email address"];
  3377. }
  3378. };
  3379. [self presentViewController:emailAddrVC animated:YES completion:nil];
  3380. }
  3381. #pragma mark - Back Order
  3382. - (void) setCart_json:(NSDictionary *)cart_json {
  3383. _cart_json = cart_json;
  3384. [self fillContentArray];
  3385. }
  3386. - (void)fillContentArray {
  3387. NSMutableArray *arr = [NSMutableArray array];
  3388. for (int i = 0; i < [self sectionCount]; i++) {
  3389. NSInteger item_count = [self itemCountInSection:i];
  3390. for (int j = 0; j < item_count; j++) {
  3391. NSDictionary *item = [self itemJsonAtIndexPath:[NSIndexPath indexPathForRow:j inSection:i]];
  3392. [arr addObject:item];
  3393. }
  3394. }
  3395. self.content_arr = arr;
  3396. [self refresh_total];
  3397. }
  3398. - (NSInteger)sectionCount {
  3399. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  3400. }
  3401. - (NSDictionary *)jsonAtSection:(NSInteger)section {
  3402. return [self.cart_json objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  3403. }
  3404. - (NSInteger)itemCountInSection:(NSInteger)section {
  3405. NSDictionary *section_json = [self jsonAtSection:section];
  3406. return [[section_json objectForKey:@"count"] integerValue];
  3407. }
  3408. - (NSString *)titleForSection:(NSInteger)section {
  3409. NSDictionary *section_json = [self jsonAtSection:section];
  3410. return [section_json objectForKey:@"title"];
  3411. }
  3412. - (NSDictionary *)itemJsonAtIndexPath:(NSIndexPath *)indexPath {
  3413. NSDictionary *section = [self jsonAtSection:indexPath.section];
  3414. return [section objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  3415. }
  3416. - (void)updateItemJson:(NSDictionary *)new_item_json atIndexPath:(NSIndexPath *)indexPath {
  3417. NSMutableDictionary *new_cart_json = [self.cart_json mutableCopy];
  3418. NSMutableDictionary *new_section_json = [[self jsonAtSection:indexPath.section] mutableCopy];
  3419. NSString *section_key = [NSString stringWithFormat:@"section_%ld",indexPath.section];
  3420. NSString *item_key = [NSString stringWithFormat:@"item_%ld",indexPath.row];
  3421. if (new_item_json) {
  3422. // 更新Item
  3423. [new_section_json setObject:new_item_json forKey:item_key];
  3424. } else {
  3425. // 删除Item
  3426. NSInteger item_count = [self itemCountInSection:indexPath.section];
  3427. for (NSInteger i = 0; i < item_count; i++) {
  3428. if (i >= indexPath.row) {
  3429. if (i < item_count - 1) {
  3430. item_key = [NSString stringWithFormat:@"item_%ld",i + 1];
  3431. NSDictionary *followed_item_json = [new_section_json objectForKey:item_key];
  3432. item_key = [NSString stringWithFormat:@"item_%ld",i];
  3433. [new_section_json setObject:followed_item_json forKey:item_key];
  3434. } else {
  3435. item_key = [NSString stringWithFormat:@"item_%ld",i];
  3436. [new_section_json removeObjectForKey:item_key];
  3437. }
  3438. }
  3439. }
  3440. [new_section_json setObject:@(item_count - 1) forKey:@"count"];
  3441. }
  3442. [new_cart_json setObject:new_section_json forKey:section_key];
  3443. self.cart_json = [new_cart_json copy];
  3444. }
  3445. - (void)reRefreshView {
  3446. [self.itemListTable reloadData];
  3447. }
  3448. #pragma mark - RA_NOTIFICAITON
  3449. -(void) refresh_ui
  3450. {
  3451. [self.itemListTable reloadData];
  3452. [self refresh_total];
  3453. }
  3454. -(void) refresh_price
  3455. {
  3456. [self refresh_ui];
  3457. }
  3458. - (void) reload_data {
  3459. __weak typeof(self) weakself = self;
  3460. self.currentOrderIsMerged = NO;
  3461. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  3462. if (weakself) {
  3463. __strong typeof(weakself) strongself = weakself;
  3464. [strongself operation_reload_data];
  3465. }
  3466. }];
  3467. [self.dataOperationQueue addOperation:operation];
  3468. }
  3469. @end