MainViewController.m 157 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116
  1. //
  2. // ViewController.m
  3. // RedAnt ERP Suite
  4. //
  5. // Created by Ray on 14-5-19.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "MainViewController.h"
  9. //#import "SideMenuViewController.h"
  10. //#import "RootContainerViewController.h"
  11. #import <Accelerate/Accelerate.h>
  12. #import "PopupNavigationController.h"
  13. //#import "CommonGridViewController.h"
  14. #import "CacheViewController.h"
  15. #import "ScannerViewController.h"
  16. #import "ContactListViewController.h"
  17. #import "RAUtils.h"
  18. #import "AboutViewController.h"
  19. #import "ScannerSettingViewController.h"
  20. #import "ActiveViewController.h"
  21. #import "WebViewController.h"
  22. #import "FunctionTestViewController.h"
  23. #import "SimplifiedBuyingProgramViewController.h"
  24. #import "UserListViewController.h"
  25. #import "OfflineSettingViewController.h"
  26. #import "DefaultAppearance.h"
  27. #import "PriceSettingViewController.h"
  28. #import "JKLockController.h"
  29. #import "RASingleton.h"
  30. #import "NotificationNameCenter.h"
  31. //#import "OLOSettingViewController.h"
  32. //#import "ScanHistoryViewController.h"
  33. #import "CustomerEditViewController.h"
  34. #import "ScanOrderScanModelViewController.h"
  35. #import "ScanOrderModelListViewController.h"
  36. #import "SetupServerViewController.h"
  37. #import "ScanUserListViewController.h"
  38. @interface MainViewController ()
  39. // scan order main frame
  40. @end
  41. @implementation MainViewController
  42. -(void) logoutDocuments
  43. {
  44. // [self.pdfListViewController logout];
  45. }
  46. -(void) logoutCart
  47. {
  48. [self.cartViewController logout];
  49. RASingleton.sharedInstance.scan_cart = nil;
  50. RASingleton.sharedInstance.price_type = 1;
  51. }
  52. -(void) logoutWish
  53. {
  54. // [self.watchListViewController logout];
  55. }
  56. -(void) logoutPortfolio
  57. {
  58. // [self.portfolioViewController logout];
  59. }
  60. -(void) logoutOrder
  61. {
  62. [self.scanorderViewController logout];
  63. }
  64. -(void) logoutContact
  65. {
  66. [self.contactListViewController logout];
  67. }
  68. -(void) logoutCategory
  69. {
  70. // [self.categoryViewController logout];
  71. }
  72. - (IBAction)onScanOrderSetting:(id)sender {
  73. [self clearSelected];
  74. self.btnsetting.selected = true;
  75. if([self.current_VC isKindOfClass:[ServerSettingViewController class]])
  76. return;
  77. [self flipFromViewController:self.current_VC toViewController:self.settingViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  78. }
  79. - (IBAction)onSelectSales:(id)sender {
  80. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  81. ScanUserListViewController * userVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanUserListViewController"];
  82. userVC.returnValue=^(NSString* user)
  83. {
  84. // self.btnContact.hidden = false;
  85. appDelegate.user = user;
  86. [self.buttonUser setTitle:user forState:UIControlStateNormal];
  87. [self refreshContactDisplay];
  88. //
  89. };
  90. // loginvc.delegate = self;
  91. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  92. // appDelegate.active_controller = gunVC;
  93. // gunVC.onDismissVC = ^(){
  94. // appDelegate.active_controller = active_vc;
  95. // };
  96. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:userVC] ;
  97. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  98. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  99. [self presentViewController:navi animated:YES completion:^{
  100. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  101. DebugLog(@"about present.........");
  102. // self.btop = false;
  103. // <#code#>
  104. }];
  105. [appDelegate update_count_mark];
  106. // appDelegate.bLogin = true;
  107. }
  108. #ifndef RA_NOTIFICATION
  109. -(void) reloadCategory:(BOOL) update_data immediately:(bool)immediately
  110. {
  111. if(immediately)
  112. [ self.categoryViewController reload_container_getdata:update_data];
  113. else
  114. {
  115. if(update_data&&self.categoryViewController.refresh_type<=REFRESH_DATA)
  116. self.categoryViewController.refresh_type = REFRESH_DATA;
  117. else if(self.categoryViewController.refresh_type<=REFRESH_VIEW)
  118. self.categoryViewController.refresh_type = REFRESH_VIEW;
  119. }
  120. }
  121. -(void) reloadDocuments:(BOOL) update_data immediately:(bool)immediately
  122. {
  123. if(immediately)
  124. [ self.pdfListViewController reload_container_getdata:update_data];
  125. else
  126. {
  127. if(update_data&&self.pdfListViewController.refresh_type<=REFRESH_DATA)
  128. self.pdfListViewController.refresh_type = REFRESH_DATA;
  129. else if(self.pdfListViewController.refresh_type<=REFRESH_VIEW)
  130. self.pdfListViewController.refresh_type = REFRESH_VIEW;
  131. }
  132. //[self.pdfListViewController reload_container_getdata:update_data];
  133. }
  134. -(void) reloadCart:(BOOL) update_data immediately:(bool)immediately
  135. {
  136. if(immediately)
  137. [ self.cartViewController reload_container_getdata:update_data];
  138. else
  139. {
  140. if(update_data&&self.cartViewController.refresh_type<=REFRESH_DATA)
  141. self.cartViewController.refresh_type = REFRESH_DATA;
  142. else if(self.cartViewController.refresh_type<=REFRESH_VIEW)
  143. self.cartViewController.refresh_type = REFRESH_VIEW;
  144. }
  145. // [self.cartViewController reload_container_getdata:update_data];
  146. }
  147. -(void) reloadWish:(BOOL) update_data immediately:(bool)immediately
  148. {
  149. if(immediately)
  150. [ self.watchListViewController reload_container_getdata:update_data];
  151. else
  152. {
  153. if(update_data&&self.watchListViewController.refresh_type<=REFRESH_DATA)
  154. self.watchListViewController.refresh_type = REFRESH_DATA;
  155. else if(self.watchListViewController.refresh_type<=REFRESH_VIEW)
  156. self.watchListViewController.refresh_type = REFRESH_VIEW;
  157. }
  158. // [self.watchListViewController reload_container_getdata:update_data];
  159. }
  160. -(void) reloadPortfolio:(BOOL) update_data immediately:(bool)immediately
  161. {
  162. // NSMutableDictionary* dict = [NSMutableDictionary new];
  163. // dict[@"receiver"]=@[@"PortfolioViewController"];
  164. // NSString* notificationname = nil;
  165. // if(update_data)
  166. // notificationname = RA_NOTIFICATION_RELOAD_DATA;
  167. // else
  168. // notificationname = RA_NOTIFICATION_REFRESH_UI;
  169. // NSNotification *notification =[NSNotification notificationWithName:notificationname object:nil userInfo:dict];
  170. //
  171. // //通过通知中心发送通知
  172. //
  173. // [[NSNotificationCenter defaultCenter] postNotification:notification];
  174. // return;
  175. if(immediately)
  176. [ self.portfolioViewController reload_container_getdata:update_data];
  177. else
  178. {
  179. if(update_data&&self.portfolioViewController.refresh_type<=REFRESH_DATA)
  180. self.portfolioViewController.refresh_type = REFRESH_DATA;
  181. else if(self.portfolioViewController.refresh_type<=REFRESH_VIEW)
  182. self.portfolioViewController.refresh_type = REFRESH_VIEW;
  183. }
  184. // [self.portfolioViewController reload_container_getdata:update_data];
  185. }
  186. -(void) reloadOrder:(BOOL) update_data immediately:(bool)immediately
  187. {
  188. if(immediately)
  189. [ self.orderViewController reload_container_getdata:update_data];
  190. else
  191. {
  192. if(update_data&&self.orderViewController.refresh_type<=REFRESH_DATA)
  193. self.orderViewController.refresh_type = REFRESH_DATA;
  194. else if(self.orderViewController.refresh_type<=REFRESH_VIEW)
  195. self.orderViewController.refresh_type = REFRESH_VIEW;
  196. }
  197. // [self.orderViewController reload_container_getdata:update_data];
  198. }
  199. -(void) reloadContact:(BOOL) update_data immediately:(bool)immediately
  200. {
  201. //[self.con reload_container];
  202. if(immediately)
  203. [ self.contactListViewController reload_container_getdata:update_data];
  204. else
  205. {
  206. if(update_data&&self.contactListViewController.refresh_type<=REFRESH_DATA)
  207. self.contactListViewController.refresh_type = REFRESH_DATA;
  208. else if(self.contactListViewController.refresh_type<=REFRESH_VIEW)
  209. self.contactListViewController.refresh_type = REFRESH_VIEW;
  210. }
  211. }
  212. #endif
  213. -(void)viewWillLayoutSubviews
  214. {
  215. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  216. }
  217. -(void) viewWillAppear:(BOOL)animated
  218. {
  219. [super viewWillAppear:animated];
  220. // [self.label_ccount.layer setMasksToBounds:YES];
  221. [self refreshContactDisplay];
  222. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  223. }
  224. -(void) refreshContactDisplay
  225. {
  226. UIApplication * app = [UIApplication sharedApplication];
  227. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  228. // self.labelContact.text=appDelegate.contact_name;
  229. NSString * contact =[appDelegate.customerInfo valueForKey:@"customer_contact"];
  230. NSString * customer=[appDelegate.customerInfo valueForKey:@"customer_name"];
  231. NSDictionary * customerinfo=appDelegate.customerInfo;
  232. if(customerinfo==nil)
  233. {
  234. contact=@"Select Contact";
  235. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  236. }
  237. // if(contact==nil||contact.length==0)
  238. // {
  239. // contact=@"No Name";
  240. // [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  241. // }
  242. else
  243. {
  244. if(contact==nil||contact.length==0)
  245. {
  246. contact=@"No Name";
  247. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  248. }
  249. else
  250. {
  251. [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal];
  252. }
  253. }
  254. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  255. if(contact.length>0)
  256. [arr_contact addObject:contact];
  257. if(customer.length>0)
  258. [arr_contact addObject:customer];
  259. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  260. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  261. }
  262. - (void) checklogin:(bool) reloadCurrentVC
  263. {
  264. [self initMenuItems];
  265. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  266. self.sideMenu_UserName.text =appDelegate.user;
  267. [self.btn_sideMenu_UserName setTitle:appDelegate.user forState:UIControlStateNormal];
  268. if(appDelegate.bLogin)
  269. [self.btnLogin setTitle:@"Sign out" forState:UIControlStateNormal];
  270. else
  271. [self.btnLogin setTitle:@"Sign in" forState:UIControlStateNormal];
  272. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  273. [RANetwork LoadImage:appDelegate.user_icon into:self.user_head ];
  274. });
  275. // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  276. // self.btnContact.hidden = NO;
  277. // else
  278. // self.btnContact.hidden = YES;
  279. NSDictionary * customerinfo=appDelegate.customerInfo;
  280. NSString * contact=nil;
  281. NSString * customer=nil;
  282. if(customerinfo==nil)
  283. {
  284. contact=@"Select Contact";
  285. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  286. }
  287. else
  288. {
  289. contact=[customerinfo valueForKey:@"customer_contact"];
  290. customer=[customerinfo valueForKey:@"customer_name"];
  291. if(contact==nil||contact.length==0)
  292. {
  293. contact=@"No Name";
  294. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  295. }
  296. else
  297. {
  298. [self.btnContact setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
  299. }
  300. }
  301. // self.btnContact.hidden = !appDelegate.bLogin;// 修复登出后仍旧显示select contact
  302. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  303. if(contact.length>0)
  304. [arr_contact addObject:contact];
  305. if(customer.length>0)
  306. [arr_contact addObject:customer];
  307. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  308. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  309. // if(appDelegate.bLogin)
  310. // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal];
  311. // else
  312. // [self.buttonUser setTitle:@"Sign in" forState:UIControlStateNormal];
  313. #ifdef RA_NOTIFICATION
  314. [ActiveViewController Notify:@"DetailViewController,PDFListViewController,CartViewController,PortfolioViewController,WatchListViewController,OrderListViewController,OrderListViewController,ContactListViewController,CategoryViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  315. #else
  316. [self reloadDocuments:true immediately:false];
  317. [self reloadCart:true immediately:false];
  318. [self reloadPortfolio:true immediately:false];
  319. [self reloadWish:true immediately:false];
  320. [self reloadOrder:true immediately:false];
  321. [self reloadContact:true immediately:false];
  322. [self reloadCategory:true immediately:false];
  323. ActiveViewController* lrvc = (ActiveViewController*)appDelegate.active_controller;
  324. if(reloadCurrentVC)
  325. {
  326. if(lrvc!=nil)
  327. [ lrvc refresh_on_login];
  328. }
  329. else
  330. {
  331. if(lrvc.refresh_type<=REFRESH_DATA)
  332. lrvc.refresh_type = REFRESH_DATA;
  333. else if(lrvc.refresh_type<=REFRESH_VIEW)
  334. lrvc.refresh_type = REFRESH_VIEW;
  335. }
  336. #endif
  337. // [self reload];
  338. }
  339. - (IBAction)onContactClick:(id)sender {
  340. UIApplication * app = [UIApplication sharedApplication];
  341. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  342. NSString* contactid=appDelegate.contact_id ;
  343. if(contactid==nil)
  344. {
  345. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  346. CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  347. cuseditVC.bnewcustomer=true;
  348. cuseditVC.bolocustomer = true;
  349. cuseditVC.url_type = URL_FILE;
  350. cuseditVC.request_url=[OLDataProvider scanTemplatePath:@"scan_contact.json"];;
  351. cuseditVC.params = params;
  352. cuseditVC.returnValue=^(NSMutableDictionary* value)
  353. {
  354. if(value == nil)
  355. {
  356. return; //canceled
  357. }
  358. NSString* contact_id=[[NSUUID new] UUIDString];
  359. value[@"business_card"] = value[@"customer_cid"];
  360. NSArray*arr =[RAConvertor string2arr:value[@"business_card"] separator:@","];
  361. for(int l=0;l<arr.count;l++)
  362. {
  363. value[[NSString stringWithFormat:@"business_card_%d",l]]=arr[l];
  364. }
  365. //---------------- construct customer_contact----------------------
  366. NSString* customer_first_name = [value valueForKey:@"customer_first_name"];
  367. if(customer_first_name==nil)
  368. customer_first_name=@"";
  369. NSString* customer_last_name= [value valueForKey:@"customer_last_name"];
  370. if(customer_last_name==nil)
  371. customer_last_name=@"";
  372. NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  373. customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  374. [value setValue:customer_contact forKey:@"customer_contact"];
  375. value [@"customer_cid"] = contact_id;
  376. appDelegate.contact_id=contact_id;
  377. appDelegate.customerInfo = value;
  378. };
  379. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  380. [self.navigationController pushViewController:cuseditVC animated:false];
  381. }
  382. else
  383. {
  384. CustomerInfoViewController * vc = [[CustomerInfoViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  385. vc.url_type = URL_FILE;
  386. // if(appDelegate.order_code.length>0)
  387. {
  388. vc.edit_icon = false;
  389. vc.assig_icon = true;
  390. vc.reset_icon = true;
  391. vc.request_url=[OLDataProvider scanTemplatePath:@"scan_contact.json"];
  392. }
  393. // else
  394. // {
  395. // vc.edit_icon = false;
  396. // vc.assig_icon = false;
  397. // vc.reset_icon = true;
  398. // vc.request_url=LOCAL_URL_CUSTOMER_INFO_EDITOR;
  399. // }
  400. // NSDictionary* dd=appDelegate.customerInfo;;
  401. vc.data_init = appDelegate.customerInfo;
  402. vc.update_order = true;
  403. vc.contactId=contactid;
  404. // vc.delegate = self;
  405. vc.returnValue = ^(NSMutableDictionary* value){
  406. if(value==nil)
  407. {
  408. //reset
  409. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  410. {
  411. [OLDataProvider deleteScanOrder:appDelegate.order_code];
  412. [appDelegate closeOrder];
  413. //
  414. // [self prepareReturn:nil];
  415. [self.navigationController popViewControllerAnimated:true];
  416. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  417. return;
  418. }
  419. }
  420. else
  421. {
  422. value[@"business_card"] = value[@"business_card"];
  423. NSArray*arr =[RAConvertor string2arr:value[@"business_card"] separator:@","];
  424. for(int l=0;l<arr.count;l++)
  425. {
  426. value[[NSString stringWithFormat:@"business_card_%d",l]]=arr[l];
  427. }
  428. //---------------- construct customer_contact----------------------
  429. NSString* customer_first_name = [value valueForKey:@"customer_first_name"];
  430. if(customer_first_name==nil)
  431. customer_first_name=@"";
  432. NSString* customer_last_name= [value valueForKey:@"customer_last_name"];
  433. if(customer_last_name==nil)
  434. customer_last_name=@"";
  435. NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  436. customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  437. [value setValue:customer_contact forKey:@"customer_contact"];
  438. value [@"customer_cid"] = appDelegate.customerInfo[@"customer_cid"];
  439. // appDelegate.contact_id=contact_id;
  440. appDelegate.customerInfo = value;
  441. }
  442. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  443. // appDelegate.customerInfo = value;
  444. };
  445. [self.navigationController pushViewController:vc animated:true];
  446. }
  447. }
  448. -(void) clearSelected
  449. {
  450. self.btncart.selected = false;
  451. self.btnorder.selected = false;
  452. self.btnlist.selected = false;
  453. self.btnsearch.selected = false;
  454. self.btnsetting.selected = false;
  455. }
  456. - (void)of_test
  457. {
  458. NSString* str =@"[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"]";
  459. NSDictionary* item = [RAConvertor string2dict:str];
  460. NSMutableDictionary* of = [NSMutableDictionary new];
  461. for(int i=0;i<4000;i++)
  462. {
  463. of[[NSString stringWithFormat:@"model_%d",i]]=item;
  464. }
  465. NSString* strof=[RAConvertor dict2string:of];
  466. NSString* str2 = [AESCrypt encrypt:strof password:@"usai2010"];
  467. NSString * str3 = [AESCrypt decrypt:@"x6P5P+DUN+s4mYoSoipdmvaPtU1mGvGGHtoqQF3GlMg=" password:@"usai2010"];
  468. NSString * str123 = [AESCrypt decrypt:@"706dZ9zTqNPauH3j2S7MQg==" password:@"usai"];
  469. // NSString * str333 = [AESCrypt decrypt:@"RQtrNBCGKxNq6Bk5QGkPiw==" password:@"usai2010\0\0\0\0\0\0\0\0"];
  470. // NSString * str33 = [AESCrypt decrypt:@"0s0+JiC2ZzoDiBGQaCnT1g==" password:@"usai2010"];
  471. [self sortedDictionary:of];
  472. NSDictionary* test1 = of[@"model_1234"];
  473. NSDictionary* test2 = of[@"model_9876"];
  474. NSDictionary* test3 = of[@"model_4567"];
  475. NSDictionary* test4 = of[@"model_7654"];
  476. [self of_search:of keyword:@"12"];
  477. }
  478. /**
  479. 对字典(Key-Value)排序 区分大小写
  480. @param dict 要排序的字典
  481. */
  482. - (void)sortedDictionary:(NSDictionary *)dict{
  483. //将所有的key放进数组
  484. NSArray *allKeyArray = [dict allKeys];
  485. //序列化器对数组进行排序的block 返回值为排序后的数组
  486. NSArray *afterSortKeyArray = [allKeyArray sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id
  487. _Nonnull obj2) {
  488. /**
  489. In the compare: methods, the range argument specifies the
  490. subrange, rather than the whole, of the receiver to use in the
  491. comparison. The range is not applied to the search string. For
  492. example, [@"AB" compare:@"ABC" options:0 range:NSMakeRange(0,1)]
  493. compares "A" to "ABC", not "A" to "A", and will return
  494. NSOrderedAscending. It is an error to specify a range that is
  495. outside of the receiver's bounds, and an exception may be raised.
  496. - (NSComparisonResult)compare:(NSString *)string;
  497. compare方法的比较原理为,依次比较当前字符串的第一个字母:
  498. 如果不同,按照输出排序结果
  499. 如果相同,依次比较当前字符串的下一个字母(这里是第二个)
  500. 以此类推
  501. 排序结果
  502. NSComparisonResult resuest = [obj1 compare:obj2];为从小到大,即升序;
  503. NSComparisonResult resuest = [obj2 compare:obj1];为从大到小,即降序;
  504. 注意:compare方法是区分大小写的,即按照ASCII排序
  505. */
  506. //排序操作
  507. NSComparisonResult resuest = [obj1 compare:obj2];
  508. return resuest;
  509. }];
  510. NSLog(@"afterSortKeyArray:%@",afterSortKeyArray);
  511. //通过排列的key值获取value
  512. NSMutableArray *valueArray = [NSMutableArray array];
  513. for (NSString *sortsing in afterSortKeyArray) {
  514. NSString *valueString = [dict objectForKey:sortsing];
  515. [valueArray addObject:valueString];
  516. }
  517. NSLog(@"valueArray:%@",valueArray);
  518. }
  519. -(void)of_search:(NSMutableDictionary*) dict keyword:(NSString*)keyword
  520. {
  521. NSMutableArray* arr = [NSMutableArray new];
  522. NSArray* keys=[dict allKeys];
  523. for(int i=0;i<keys.count;i++)
  524. {
  525. NSString* key = keys[i];
  526. if([key containsString:keyword])
  527. {
  528. [arr addObject:dict[key]];
  529. }
  530. }
  531. int a=0;
  532. }
  533. - (void)viewDidLoad
  534. {
  535. [super viewDidLoad];
  536. // NSString * str3 = [AESCrypt AES128Decrypt:@"" key:@"usai2010"];
  537. // NSString * str4 = [AESCrypt AES128Decrypt:@"" key:@"usai2010"];
  538. // NSString * str5 = [AESCrypt AES128Decrypt:@"" key:@"usai2010"];
  539. // NSLog(@"decrypt:%@",[AESCrypt fastdecrypt:@"vafHUwfRPIUbPNVnKhLc5aAVK7sOFRztlfJVRHW7QVa/qGgm11E5UwfYWZEBTQpH"]);
  540. // [self of_test];
  541. [RADataProvider load_scan_models];
  542. [self.btncart setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  543. [self.btnorder setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  544. [self.btnlist setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  545. [self.btnsearch setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  546. [self.btnsetting setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateSelected];
  547. // [self.btncart setTintColor:UIColor.whiteColor];
  548. // self.btncart.configuration.baseForegroundColor = UIColor.redColor;
  549. // [self.btncart updateConfiguration];
  550. // [self.btncart setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateHighlighted];
  551. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  552. if (addressDic) {
  553. self.labelServer.text = [addressDic objectForKey:@"show_name"];
  554. // NSUInteger selectedIndex = [[addressDic objectForKey:@"selectedIndex"] integerValue];
  555. // switch (selectedIndex) {
  556. // case 0:
  557. // case 1: {
  558. // [self internalCheckBtnClick:self.internalCheckBtn];
  559. // }
  560. // break;
  561. // case 2: {
  562. // [self externalCheckBtnClick:self.externalCheckBtn];
  563. // }
  564. // break;
  565. //
  566. // default:
  567. // break;
  568. // }
  569. }
  570. // self.btnContact.hidden = NO;
  571. self.automaticallyAdjustsScrollViewInsets = NO;
  572. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultColor" valuename:@"labelcolor"];
  573. if(value==nil)
  574. value=@"";
  575. unsigned long frontcolor = strtoul([value UTF8String],0,16);
  576. [self.labelSo setTextColor:UIColorFromRGB(frontcolor)];
  577. float vx =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"x"] floatValue];
  578. float vy =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"y"] floatValue];
  579. float vwidth =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"width"] floatValue];
  580. float vheight =[[DefaultAppearance get_noneappearance_value:@"MainLogo" valuename:@"height"] floatValue];
  581. self.btn_LogoHome.frame = CGRectMake(vx, vy, vwidth, vheight);
  582. float mvx =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"x"] floatValue];
  583. float mvy =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"y"] floatValue];
  584. float mvwidth =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"width"] floatValue];
  585. float mvheight =[[DefaultAppearance get_noneappearance_value:@"ModePos" valuename:@"height"] floatValue];
  586. self.labelMode.frame = CGRectMake(mvx, mvy, mvwidth, mvheight);
  587. self.label_ccount.layer.cornerRadius=10.5;
  588. self.label_ccount.layer.masksToBounds=true;
  589. self.label_wcount.layer.cornerRadius=10.5;
  590. self.label_wcount.layer.masksToBounds=true;
  591. self.label_cccount.layer.cornerRadius=10.5;
  592. self.label_cccount.layer.masksToBounds=true;
  593. self.label_cwcount.layer.cornerRadius=10.5;
  594. self.label_cwcount.layer.masksToBounds=true;
  595. self.employee_bp.hidden = false;
  596. // self.customer_bp.hidden = true;
  597. UIApplication * app = [UIApplication sharedApplication];
  598. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  599. appDelegate.main_vc = self;
  600. [appDelegate update_count_mark];
  601. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  602. NSString* build =[infoDict objectForKey:@"CFBundleVersion"];
  603. NSString* version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  604. //#ifdef BUILD_HMLG
  605. // NSString* versionNum = [NSString stringWithFormat:@"HMLG %@ Build %@",version,build];
  606. //#endif
  607. //#if defined(BUILD_NPD) || defined(BUILD_USAI)
  608. // NSString* versionNum = [NSString stringWithFormat:@"npd %@ Build %@",version,build];
  609. //#endif
  610. //#ifdef BUILD_HOMER
  611. NSString* versionNum = [NSString stringWithFormat:@"%@ %@ Build %@",COMPANY_SHORT_NAME,version,build];
  612. //#endif
  613. [self initAppDelegate]; // 初始化scan order 参数
  614. [self initMenuItems];
  615. self.homeViewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanHomeViewController"];
  616. // self.categoryViewController =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Search" bundle:nil] instantiateViewControllerWithIdentifier:@"CategoryViewController"];
  617. self.settingViewController=[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"ServerSettingViewController"];
  618. self.cartViewController =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"CartViewController"];
  619. __block MainViewController *brself= self;
  620. self.scanorderViewController =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  621. self.contactListViewController = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  622. self.contactListViewController.contact_type = @"Sales_Order_Customer";
  623. self.contactListViewController.edit_icon = true;
  624. self.contactListViewController.assig_icon = true;
  625. self.contactListViewController.reset_icon = false;
  626. self.contactListViewController.ui_type = CONTACT_LIST;
  627. self.contactListViewController.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  628. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  629. appDelegate.customerInfo = value;
  630. [brself refreshContactDisplay];
  631. [brself switchToCart:nil];
  632. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  633. //
  634. // if(self.returnValue)
  635. // self.returnValue(value);
  636. };
  637. //Capturing strongly warring;
  638. self.scanHistoryViewController =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanHistoryViewController"];
  639. // self.portfolioViewController = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Portfolio" bundle:nil] instantiateViewControllerWithIdentifier:@"PortfolioViewController" ];
  640. // [self addChildViewController:self.scanHistoryViewController];
  641. // self.pdfListViewController = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Portfolio" bundle:nil] instantiateViewControllerWithIdentifier:@"PortfolioListViewController" ];
  642. // self.itemSearchViewController=[[UIStoryboard storyboardWithName:@"ERP_Mobile_Search" bundle:nil] instantiateViewControllerWithIdentifier:@"ItemSearchViewController"];
  643. self.scansearchViewController=[ [UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanSearchViewController"];
  644. [self addChildViewController:self.homeViewController]; //1
  645. self.homeViewController.view.frame = self.container.bounds;
  646. [self.container addSubview:self.homeViewController.view]; //2
  647. [self.homeViewController didMoveToParentViewController:self];
  648. self.current_VC = self.homeViewController;
  649. // [self addChildViewController:self.scanorderViewController]; //1
  650. //
  651. // self.scanorderViewController.view.frame = self.container.bounds;
  652. // [self.container addSubview:self.scanorderViewController.view]; //2
  653. // [self.scanorderViewController didMoveToParentViewController:self];
  654. // self.current_VC = self.scanorderViewController;
  655. // // self.is_home = true;
  656. // [UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  657. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  658. self.headerView.layer.masksToBounds = false;
  659. //添加四个边阴影
  660. self.headerView.layer.shadowColor = [UIColor blackColor].CGColor;
  661. self.headerView.layer.shadowOffset = CGSizeMake(0, 0);
  662. self.headerView.layer.shadowOpacity = 0.5;
  663. self.headerView.layer.shadowRadius = 2.0;
  664. self.labelVer.text=versionNum;
  665. // UIApplication * app = [UIApplication sharedApplication];
  666. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  667. // Do any additional setup after loading the view, typically from a nib.
  668. // SetupServerViewController * servervc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"SetupServerViewController"];
  669. // [self.navigationController pushViewController:servervc animated:true];
  670. }
  671. - (IBAction)onmenuButtonClicked:(id)sender {
  672. self.openMenuButton.hidden = true;
  673. self.sideMenu.hidden = false;
  674. [self showMenu];
  675. }
  676. - (IBAction)switchMenu:(UIButton *)sender {
  677. // if(self.menuShown==true)
  678. [self hideMenu];
  679. self.openMenuButton.hidden = false;
  680. self.sideMenu.hidden = true;
  681. // else
  682. // [self showMenu];
  683. }
  684. -(void) Loginout:(bool)showlogin
  685. {
  686. UIApplication * app = [UIApplication sharedApplication];
  687. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  688. if(appDelegate.bLogin)
  689. {
  690. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign out" completion:^{
  691. [RANetwork request_logout:^(NSMutableDictionary *result) {
  692. NSMutableDictionary* return_json =result;
  693. [waitalert dismissViewControllerAnimated:YES completion:^{
  694. if([[return_json valueForKey:@"result"] intValue]==2)
  695. {
  696. // [self hideMenu];
  697. // [self switchToHome:nil];
  698. [appDelegate Logout];
  699. [self checklogin :false];
  700. if(showlogin)
  701. {
  702. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  703. loginvc.returnValue = ^(bool blogin){
  704. [self checklogin :true];
  705. };
  706. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  707. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  708. [self presentViewController:navi animated:YES completion:^{
  709. DebugLog(@"login present.........");
  710. }];
  711. }
  712. }
  713. else
  714. {
  715. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
  716. }
  717. }];
  718. }];
  719. }];
  720. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  721. //
  722. // NSDictionary* return_json = [RANetwork logout];
  723. //
  724. // dispatch_async(dispatch_get_main_queue(), ^{
  725. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  726. //
  727. //
  728. // if([[return_json valueForKey:@"result"] intValue]==2)
  729. // {
  730. //// [self hideMenu];
  731. //// [self switchToHome:nil];
  732. // [appDelegate Logout];
  733. // [self checklogin :false];
  734. // if(showlogin)
  735. // {
  736. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  737. // loginvc.returnValue = ^(bool blogin){
  738. //
  739. // [self checklogin :true];
  740. //
  741. // };
  742. //
  743. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  744. //
  745. //
  746. //
  747. //
  748. //
  749. //
  750. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  751. // [self presentViewController:navi animated:YES completion:^{
  752. //
  753. // DebugLog(@"login present.........");
  754. //
  755. // }];
  756. // }
  757. // }
  758. // else
  759. // {
  760. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
  761. // }
  762. //
  763. //
  764. //
  765. //
  766. // });
  767. // });
  768. }
  769. else
  770. {
  771. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  772. loginvc.returnValue = ^(bool blogin){
  773. [self checklogin :true];
  774. };
  775. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  776. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  777. [self presentViewController:navi animated:YES completion:^{
  778. DebugLog(@"login present.........");
  779. }];
  780. }
  781. }
  782. - (IBAction)onUserListClick:(id)sender {
  783. UIApplication * app = [UIApplication sharedApplication];
  784. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  785. if(!appDelegate.bLogin)
  786. return;
  787. UserListViewController * vc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"UserListViewController"];
  788. vc.returnValue = ^(bool blogin){
  789. if(blogin==false)
  790. {
  791. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  792. loginvc.returnValue = ^(bool blogin){
  793. [self checklogin :true];
  794. };
  795. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  796. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  797. [self presentViewController:navi animated:YES completion:^{
  798. DebugLog(@"login present.........");
  799. }];
  800. }
  801. };
  802. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  803. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  804. [self presentViewController:navi animated:YES completion:^{
  805. DebugLog(@"login present.........");
  806. }];
  807. }
  808. - (IBAction)OnLoginClick:(UIButton *)sender {
  809. [self Loginout:true];
  810. }
  811. - (IBAction)onScanClick:(id)sender {
  812. ScannerViewController * scannerVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  813. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  814. // ScanOrderScanModelViewController *scanresult = [[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderScanModelViewController"];
  815. ScanOrderModelListViewController* scanresult = [[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderModelListViewController"];
  816. scannerVC.resultvc = scanresult;
  817. [self.navigationController pushViewController:scannerVC animated:true];
  818. }
  819. - (IBAction)switchToSearch:(UIButton *)sender {
  820. [self clearSelected];
  821. self.btnsearch.selected = true;
  822. if([self.current_VC isKindOfClass:[ScanSearchViewController class]])
  823. return;
  824. [self flipFromViewController:self.current_VC toViewController:self.scansearchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  825. }
  826. //- (IBAction)switchToList:(UIButton *)sender {
  827. // [self switchtowishlist];
  828. //}
  829. - (IBAction)switchToList:(UIButton *)sender {
  830. [self clearSelected];
  831. self.btnlist.selected = true;
  832. [self switchtowishlist];
  833. }
  834. -(void)switchtowishlist
  835. {
  836. if([self.current_VC isKindOfClass:[ScanHistoryViewController class]])
  837. return;
  838. // if([self.current_VC isKindOfClass:[OrderListViewController class]])
  839. // return;
  840. // UIApplication * app = [UIApplication sharedApplication];
  841. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  842. // if(appDelegate.bLogin==false)
  843. // {
  844. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  845. // // loginvc.delegate = self;
  846. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  847. //
  848. // loginvc.returnValue = ^(bool blogin){
  849. //
  850. //
  851. // if(blogin)
  852. // {
  853. // [self checklogin:true];
  854. //
  855. //
  856. // [self flipFromViewController:self.current_VC toViewController:self.watchListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  857. // }
  858. //
  859. //
  860. // };
  861. //
  862. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  863. //
  864. //
  865. //
  866. //
  867. //
  868. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  869. //
  870. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  871. // [self presentViewController:navi animated:YES completion:^{
  872. //
  873. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  874. //
  875. // DebugLog(@"LoginViewController present.........");
  876. //
  877. // // self.btop = false;
  878. // // <#code#>
  879. // }];
  880. // }
  881. // else
  882. [self flipFromViewController:self.current_VC toViewController:self.scanHistoryViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  883. }
  884. - (IBAction)switchToContact:(UIButton *)sender {
  885. [self switchtocontact];
  886. }
  887. -(void)switchtocontact
  888. {
  889. if([self.current_VC isKindOfClass:[ContactListViewController class]])
  890. return;
  891. UIApplication * app = [UIApplication sharedApplication];
  892. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  893. if(appDelegate.bLogin==false)
  894. {
  895. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  896. // loginvc.delegate = self;
  897. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  898. loginvc.returnValue = ^(bool blogin){
  899. if(blogin)
  900. {
  901. [self checklogin:true];
  902. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  903. {
  904. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  905. }
  906. else
  907. {
  908. [RAUtils message_alert:@"Customer Login does not support this feature." title:@"Contact List" controller:self] ;
  909. }
  910. }
  911. };
  912. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  913. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  914. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  915. [self presentViewController:navi animated:YES completion:^{
  916. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  917. DebugLog(@"LoginViewController present.........");
  918. // self.btop = false;
  919. // <#code#>
  920. }];
  921. }
  922. else
  923. [self flipFromViewController:self.current_VC toViewController:self.contactListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  924. }
  925. - (void) reload
  926. {
  927. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  928. return;
  929. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  930. //
  931. //
  932. // NSDictionary* category=[RANetwork request_Cagegory];
  933. //
  934. // dispatch_async(dispatch_get_main_queue(), ^{
  935. //
  936. // if([[category valueForKey:@"result"] intValue]==2)
  937. // {
  938. // appDelegate.categoryMenu = category;
  939. // }
  940. // else
  941. // {
  942. // // [RAUtils error_alert:[category valueForKey:@"err_msg"]] ;
  943. // }
  944. //
  945. // });
  946. // });
  947. }
  948. -(void) scanTempsave
  949. {
  950. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  951. // RASingleton.sharedInstance.scan_temp_code
  952. NSString *orderdir =[OLDataProvider getScanPath];
  953. appDelegate.order_code = RASingleton.sharedInstance.scan_temp_code;
  954. [OLDataProvider moveScanTemp2Order];
  955. // NSString *orderdir = [OLDataProvider getScanPath];
  956. NSString* userdir = [OLDataProvider getUserPath];
  957. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  958. // [RAUtils dicttofile:orderPath dict:self.content_data_download];
  959. NSString* order_code = RASingleton.sharedInstance.scan_temp_code;
  960. //
  961. // int section_count = [self.content_data_download[@"section_count"] intValue];
  962. //
  963. // for(int i=0;i<section_count;i++)
  964. // {
  965. // NSMutableDictionary* section = [self.content_data_download[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  966. // NSString* title = section[@"title"];
  967. //
  968. // if([title isEqualToString:@"Customer"])
  969. // {
  970. // // 订单信息会写customer info
  971. //
  972. // int scount = [section[@"count"] intValue];
  973. // for(int j=0;j<scount;j++)
  974. // {
  975. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  976. // NSString * name = item[@"name"];
  977. //
  978. //
  979. // if(item[@"value"]!=nil )
  980. // appDelegate.customerInfo[name]=item[@"value"];
  981. //
  982. //
  983. // }
  984. //
  985. //
  986. //
  987. // }
  988. //
  989. // NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  990. //
  991. //
  992. //
  993. // [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  994. orderdir = [OLDataProvider getScanOrderPath];
  995. NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
  996. RASingleton.sharedInstance.scan_cart[@"price_type"] = @(RASingleton.sharedInstance.price_type);
  997. [RAUtils dicttofile:cartpath dict:RASingleton.sharedInstance.scan_cart];
  998. NSMutableDictionary* orderlist = nil;
  999. NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
  1000. if (![[NSFileManager defaultManager] fileExistsAtPath:orderlistPath]) {
  1001. orderlist = [NSMutableDictionary new];
  1002. // [orderlist addObject:appDelegate.order_code];
  1003. // [RAUtils dicttofile:orderlistPath dict:orderlist];
  1004. }
  1005. else
  1006. {
  1007. orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
  1008. // [orderlist insertObject:appDelegate.order_code atIndex:0];
  1009. // [RAUtils dicttofile:orderlistPath dict:orderlist];
  1010. }
  1011. float p =0;
  1012. float s =0;
  1013. int order_qty=0;
  1014. for(int j=0;j<[RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] intValue];j++)
  1015. {
  1016. NSDictionary* cartitem =RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",j]];
  1017. p+=[cartitem[@"unit_price"] doubleValue]*[cartitem[@"count"]intValue] * (1-[cartitem[@"discount"]doubleValue]/100.0);
  1018. int mcount = [cartitem[@"count"] intValue];
  1019. order_qty+=mcount;
  1020. double msurcharge =0;
  1021. if(RASingleton.sharedInstance.price_type==1)
  1022. {
  1023. if([cartitem[@"special_price"] boolValue])
  1024. {
  1025. msurcharge=([cartitem[@"price3"] doubleValue]-[cartitem[@"price2"] doubleValue])*mcount*(1-[cartitem[@"discount"]doubleValue]/100.0);
  1026. }
  1027. else
  1028. {
  1029. msurcharge=([cartitem[@"price3"] doubleValue]-[cartitem[@"price1"] doubleValue])*mcount*(1-[cartitem[@"discount"]doubleValue]/100.0);
  1030. }
  1031. }
  1032. s+=msurcharge;
  1033. }
  1034. NSMutableDictionary* orderitem = [NSMutableDictionary new];
  1035. orderitem[@"create_by"] = appDelegate.user;
  1036. orderitem[@"price"] = [RAConvertor currencyNumber:p+s];//[NSString stringWithFormat:@"%.2f",p+s];
  1037. orderitem[@"model_count"] =[ NSString stringWithFormat:@"%d",order_qty];
  1038. // orderitem[@"price"] = upparams[@"totalPrice"];
  1039. // NSString*
  1040. orderitem[@"customer_name"] = appDelegate.customerInfo[@"customer_contact"];
  1041. orderitem[@"purchase_time"] = [RAUtils current_date_time];
  1042. orderitem[@"order_status"] = @"Saved Order";
  1043. orderitem[@"order_code"] = order_code;
  1044. NSMutableDictionary* section =RASingleton.sharedInstance.scan_cart[@"section_0"];
  1045. // orderitem[@"model_count"] =[ NSString stringWithFormat:@"%d",order_qty];//RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] ];
  1046. int count = [orderlist[@"count"] intValue];
  1047. NSMutableDictionary* newlist = [NSMutableDictionary new];
  1048. newlist[@"item_0"]=orderitem;
  1049. int newcount = 1;
  1050. for(int i=0;i<count;i++)
  1051. {
  1052. NSMutableDictionary* item = orderlist[[NSString stringWithFormat:@"item_%d",i]];
  1053. if([item[@"order_code"] isEqualToString: appDelegate.order_code ])
  1054. continue;
  1055. else
  1056. {
  1057. newlist[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  1058. newcount++;
  1059. }
  1060. }
  1061. newlist[@"count"] = @(newcount);
  1062. [RAUtils dicttofile:orderlistPath dict:newlist];
  1063. #ifdef RA_NOTIFICATION
  1064. [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1065. #else
  1066. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1067. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1068. #endif
  1069. }
  1070. - (IBAction)onUserButtonClick:(id)sender {
  1071. DebugLog(@"header view login");
  1072. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1073. if( appDelegate.user ==nil /*|| [appDelegate.user isEqualToString:@"GUEST"]*/)
  1074. {
  1075. // appDelegate.user = nil;
  1076. // appDelegate.password = nil;
  1077. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1078. // loginvc.delegate = self;
  1079. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1080. loginvc.returnValue = ^(bool blogin){
  1081. [self checklogin:true];
  1082. };
  1083. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1084. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1085. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1086. [self presentViewController:navi animated:YES completion:^{
  1087. // <#code#>
  1088. }];
  1089. }
  1090. else
  1091. {
  1092. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Sign Out" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1093. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Sign Out" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1094. //open exist
  1095. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1096. // int cc=[RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] intValue];
  1097. if(appDelegate.order_code == nil && [RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] intValue]>0)
  1098. {
  1099. UIAlertController *alertController1 = [UIAlertController alertControllerWithTitle:@"Save Cart?" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1100. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1101. [self scanTempsave];
  1102. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  1103. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  1104. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  1105. [appDelegate update_count_mark];
  1106. appDelegate.can_show_price =false;
  1107. appDelegate.can_see_price =false;
  1108. appDelegate.can_create_portfolio =false;
  1109. appDelegate.can_create_order =false;
  1110. appDelegate.can_cancel_order =false;
  1111. appDelegate.can_set_cart_price =false;
  1112. appDelegate.can_delete_order =false;
  1113. appDelegate.can_submit_order =false;
  1114. appDelegate.can_set_tearsheet_price =false;
  1115. appDelegate.can_update_contact_info = false;
  1116. appDelegate.save_order_logout = false;
  1117. appDelegate.submit_order_logout = false;
  1118. appDelegate.alert_sold_in_quantities = false;
  1119. appDelegate.ipad_perm =nil ;
  1120. appDelegate.user_type = USER_ROLE_UNKNOWN;
  1121. appDelegate.OrderFilter= nil;
  1122. [appDelegate SetSo:nil];
  1123. [appDelegate set_main_button_panel];
  1124. #ifdef RA_NOTIFICATION
  1125. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  1126. #endif
  1127. [appDelegate Logout];
  1128. }];
  1129. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1130. //create new;
  1131. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  1132. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  1133. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  1134. [appDelegate update_count_mark];
  1135. appDelegate.can_show_price =false;
  1136. appDelegate.can_see_price =false;
  1137. appDelegate.can_create_portfolio =false;
  1138. appDelegate.can_create_order =false;
  1139. appDelegate.can_cancel_order =false;
  1140. appDelegate.can_set_cart_price =false;
  1141. appDelegate.can_delete_order =false;
  1142. appDelegate.can_submit_order =false;
  1143. appDelegate.can_set_tearsheet_price =false;
  1144. appDelegate.can_update_contact_info = false;
  1145. appDelegate.save_order_logout = false;
  1146. appDelegate.submit_order_logout = false;
  1147. appDelegate.alert_sold_in_quantities = false;
  1148. appDelegate.ipad_perm =nil ;
  1149. appDelegate.user_type = USER_ROLE_UNKNOWN;
  1150. appDelegate.OrderFilter= nil;
  1151. [appDelegate SetSo:nil];
  1152. [appDelegate set_main_button_panel];
  1153. #ifdef RA_NOTIFICATION
  1154. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  1155. #endif
  1156. [appDelegate Logout];
  1157. }];
  1158. [alertController1 addAction:action_1];
  1159. [alertController1 addAction:action_2];
  1160. [self presentViewController:alertController1 animated:YES completion:nil];
  1161. return;
  1162. }
  1163. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  1164. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  1165. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  1166. [appDelegate update_count_mark];
  1167. appDelegate.can_show_price =false;
  1168. appDelegate.can_see_price =false;
  1169. appDelegate.can_create_portfolio =false;
  1170. appDelegate.can_create_order =false;
  1171. appDelegate.can_cancel_order =false;
  1172. appDelegate.can_set_cart_price =false;
  1173. appDelegate.can_delete_order =false;
  1174. appDelegate.can_submit_order =false;
  1175. appDelegate.can_set_tearsheet_price =false;
  1176. appDelegate.can_update_contact_info = false;
  1177. appDelegate.save_order_logout = false;
  1178. appDelegate.submit_order_logout = false;
  1179. appDelegate.alert_sold_in_quantities = false;
  1180. appDelegate.ipad_perm =nil ;
  1181. appDelegate.user_type = USER_ROLE_UNKNOWN;
  1182. appDelegate.OrderFilter= nil;
  1183. [appDelegate SetSo:nil];
  1184. [appDelegate set_main_button_panel];
  1185. #ifdef RA_NOTIFICATION
  1186. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  1187. #endif
  1188. [appDelegate Logout];
  1189. }];
  1190. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1191. //create new;
  1192. }];
  1193. [alertController addAction:action_1];
  1194. [alertController addAction:action_2];
  1195. [self presentViewController:alertController animated:YES completion:nil];
  1196. }
  1197. }
  1198. #pragma mark - LoginViewControllerDelegate
  1199. -(void)LoginViewControllerDidLogin:(LoginViewController *)viewController
  1200. {
  1201. [viewController dismissViewControllerAnimated:YES completion:^{
  1202. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1203. self.sideMenu_UserName.text =appDelegate.user;
  1204. [self.btn_sideMenu_UserName setTitle:appDelegate.user forState:UIControlStateNormal];
  1205. [self.btnLogin setTitle:@"Sign out" forState:UIControlStateNormal];
  1206. [RANetwork LoadImage:appDelegate.user_icon into:self.user_head ];
  1207. // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  1208. // self.btnContact.hidden = NO;
  1209. // else
  1210. // self.btnContact.hidden = YES;
  1211. NSDictionary * customerinfo=appDelegate.customerInfo;
  1212. NSString * contact=nil;
  1213. NSString * customer=nil;
  1214. if(customerinfo==nil)
  1215. {
  1216. contact=@"Select Contact";
  1217. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  1218. }
  1219. else
  1220. {
  1221. contact=[customerinfo valueForKey:@"customer_contact"];
  1222. customer=[customerinfo valueForKey:@"customer_name"];
  1223. if(contact==nil||contact.length==0)
  1224. {
  1225. contact=@"No Name";
  1226. [self.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  1227. }
  1228. else
  1229. {
  1230. [self.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal];
  1231. }
  1232. }
  1233. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  1234. if(contact.length>0)
  1235. [arr_contact addObject:contact];
  1236. if(customer.length>0)
  1237. [arr_contact addObject:customer];
  1238. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  1239. [self.btnContact setTitle:contact_string forState:UIControlStateNormal];
  1240. // [self.buttonUser setTitle:appDelegate.user forState:UIControlStateNormal];
  1241. [self reload];
  1242. }];
  1243. }
  1244. - (void) flipFromViewController:(UIViewController*) fromController
  1245. toViewController:(UIViewController*) toController
  1246. withDirection:(UIViewAnimationOptions) direction
  1247. {
  1248. toController.view.frame = self.container.bounds; // 1
  1249. // UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
  1250. // UIViewAutoresizingFlexibleWidth = 1 << 1,
  1251. // UIViewAutoresizingFlexibleRightMargin = 1 << 2,
  1252. // UIViewAutoresizingFlexibleTopMargin = 1 << 3,
  1253. // UIViewAutoresizingFlexibleHeight = 1 << 4,
  1254. // UIViewAutoresizingFlexibleBottomMargin = 1 << 5
  1255. toController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
  1256. NSLog(@"MAIN VIEWCONTROLLER CHILD COUNT %lu",(unsigned long)self.childViewControllers.count);
  1257. [self addChildViewController:toController]; //
  1258. [fromController willMoveToParentViewController:nil]; //
  1259. [self transitionFromViewController:fromController
  1260. toViewController:toController
  1261. duration:0.0
  1262. options:direction | UIViewAnimationOptionCurveEaseIn
  1263. animations:nil
  1264. completion:^(BOOL finished) {
  1265. [toController didMoveToParentViewController:self]; // 2
  1266. [fromController removeFromParentViewController]; // 3
  1267. self.current_VC = toController;
  1268. // if([fromController isKindOfClass:[HomeViewController class]])
  1269. // {
  1270. // // [[NSNotificationCenter defaultCenter] postNotificationName:CYCLESCROLL_STOPTIMMER object:nil];
  1271. // // self.homeViewController = nil;
  1272. //
  1273. // }
  1274. }];
  1275. }
  1276. -(void)topicViewSelected:(int) type _id: (int) _id
  1277. {
  1278. // [self switchToCagegory:nil];
  1279. // if(type==0)
  1280. // {
  1281. // // [self.categoryViewController showDetailat:_id];
  1282. // }
  1283. // else
  1284. // {
  1285. // [self.categoryViewController showCategory];
  1286. //
  1287. // }
  1288. }
  1289. -(void)categoryMenuSelected:(NSString*)_id
  1290. {
  1291. [self switchToCagegory:_id];
  1292. // [self.categoryViewController showCategory];
  1293. }
  1294. //- (void)switchToItemSearch:(NSString* )coverttype {
  1295. //
  1296. //
  1297. // self.itemSearchViewController.default_filter = nil;
  1298. // self.itemSearchViewController.covertype = coverttype;
  1299. // self.itemSearchViewController.saved_covertype = coverttype;
  1300. //
  1301. //
  1302. //
  1303. // self.itemSearchViewController.p_available = nil;
  1304. // self.itemSearchViewController.p_price = nil;
  1305. // self.itemSearchViewController.p_QTY = nil;
  1306. // self.itemSearchViewController.p_bestseller = nil;
  1307. //#ifdef RA_NOTIFICATION
  1308. // [ActiveViewController Notify:@"ItemSearchViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1309. //#else
  1310. // [self.itemSearchViewController reload_container_getdata:true];
  1311. //#endif
  1312. //
  1313. // if([self.current_VC isKindOfClass:[ItemSearchViewController class]])
  1314. //
  1315. // return;
  1316. // [self flipFromViewController:self.current_VC toViewController:self.itemSearchViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1317. //
  1318. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1319. //
  1320. //
  1321. // // self.is_home = false;
  1322. // // self.current_vc = VC_CATEGORY;
  1323. // // [self.homeViewController willMoveToParentViewController:nil]; //1
  1324. // // [self.homeViewController.view removeFromSuperview]; //2
  1325. // // [self.homeViewController removeFromParentViewController]; //3
  1326. // //
  1327. // // [self.container addSubview:self.cagegoryViewController.view]; //2
  1328. // // [self.cagegoryViewController didMoveToParentViewController:self];
  1329. //}
  1330. //- (void)switchToCagegory:(NSString* )categoryid {
  1331. // // NSString* ttt =[@"Category" stringByAppendingString:[self categoryString:categoryid node:self.categoryMenu level:0]];
  1332. //
  1333. //
  1334. // UIApplication * app = [UIApplication sharedApplication];
  1335. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1336. // #if defined(BUILD_UWAVER)
  1337. // self.categoryViewController.categoryString = [@"Collections" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  1338. //#else
  1339. // self.categoryViewController.categoryString = [@"Category" stringByAppendingString:[self categoryString:categoryid node:appDelegate.categoryMenu level:0]];
  1340. //#endif
  1341. //
  1342. // self.categoryViewController.cagegoryLabel.text =self.categoryViewController.categoryString;
  1343. // self.categoryViewController.categoryid = categoryid ;
  1344. // self.categoryViewController.loadall=false;
  1345. //// self.categoryViewController.collectionview
  1346. // self.categoryViewController.p_alert = nil;
  1347. // self.categoryViewController.p_available = nil;
  1348. // self.categoryViewController.p_price = nil;
  1349. // self.categoryViewController.p_QTY = nil;
  1350. // self.categoryViewController.p_bestseller = nil;
  1351. //
  1352. // self.categoryViewController.modelname = nil;
  1353. // self.categoryViewController.modeldescrip = nil;
  1354. //#ifdef RA_NOTIFICATION
  1355. // [ActiveViewController Notify:@"CategoryViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1356. //#else
  1357. // [self.categoryViewController reload_container_getdata:true];
  1358. //#endif
  1359. //
  1360. // [self.categoryViewController showCategory];
  1361. // if([self.current_VC isKindOfClass:[CategoryViewController class]])
  1362. //
  1363. // return;
  1364. // [self flipFromViewController:self.current_VC toViewController:self.categoryViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1365. //
  1366. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1367. //
  1368. //
  1369. // // self.is_home = false;
  1370. // // self.current_vc = VC_CATEGORY;
  1371. // // [self.homeViewController willMoveToParentViewController:nil]; //1
  1372. // // [self.homeViewController.view removeFromSuperview]; //2
  1373. // // [self.homeViewController removeFromParentViewController]; //3
  1374. // //
  1375. // // [self.container addSubview:self.cagegoryViewController.view]; //2
  1376. // // [self.cagegoryViewController didMoveToParentViewController:self];
  1377. //}
  1378. - (IBAction)switchToHome:(UIButton *)sender {
  1379. [self clearSelected];
  1380. [self switchToHome];
  1381. // self.current_vc = VC_HOME;
  1382. // self.is_home = true;
  1383. //
  1384. // [self.cagegoryViewController willMoveToParentViewController:nil]; //1
  1385. // [self.cagegoryViewController.view removeFromSuperview]; //2
  1386. // [self.cagegoryViewController removeFromParentViewController]; //3
  1387. //
  1388. // [self.container addSubview:self.homeViewController.view]; //2
  1389. // [self.homeViewController didMoveToParentViewController:self];
  1390. }
  1391. -(void)switchToHome
  1392. {
  1393. [self clearSelected];
  1394. if([self.current_VC isKindOfClass:[ScanHomeViewController class]])
  1395. return;
  1396. if(self.homeViewController == nil)
  1397. {
  1398. self.homeViewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanHomeViewController"];
  1399. self.homeViewController.view.frame = self.container.bounds;
  1400. }
  1401. [self flipFromViewController:self.current_VC toViewController:self.homeViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1402. }
  1403. -(void) switchToPreviousVC
  1404. {
  1405. if(self.previous_VC==nil)
  1406. return;
  1407. if([self.current_VC isKindOfClass:[self.previous_VC class]])
  1408. return;
  1409. [self flipFromViewController:self.current_VC toViewController:self.previous_VC withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1410. }
  1411. - (IBAction)switchToCart:(UIButton *)sender {
  1412. // [self.btncart setBackgroundColor:UIColor.whiteColor];
  1413. // [self.btncart setTintColor:UIColor.clearColor];
  1414. // UIColor *color0=[self.btncart titleColorForState:UIControlStateNormal];
  1415. // UIColor *color1=[self.btncart titleColorForState:UIControlStateSelected];
  1416. [self switchToCart];
  1417. // self.current_vc = VC_HOME;
  1418. }
  1419. -(void) switchToCart
  1420. {
  1421. if([self.current_VC isKindOfClass:[CartViewController class]])
  1422. return;
  1423. [self clearSelected];
  1424. self.btncart.selected = true;
  1425. //
  1426. //
  1427. // UIApplication * app = [UIApplication sharedApplication];
  1428. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1429. // // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1430. // if(appDelegate.bLogin==false&& !RASingleton.sharedInstance.enable_OfflineOrder)
  1431. // {
  1432. //
  1433. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1434. // // loginvc.delegate = self;
  1435. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1436. //
  1437. // loginvc.returnValue = ^(bool blogin){
  1438. //
  1439. //
  1440. // // UIApplication * app = [UIApplication sharedApplication];
  1441. // // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1442. //
  1443. //
  1444. //
  1445. //
  1446. // if(blogin)
  1447. // {
  1448. // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  1449. // {
  1450. //
  1451. // [self checklogin:false];
  1452. // if(appDelegate.can_create_order)
  1453. // {
  1454. //
  1455. // NSString* msg =@"";
  1456. // if(appDelegate.contact_id.length>0)
  1457. // {
  1458. // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  1459. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  1460. //
  1461. // }
  1462. //
  1463. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Switch To Cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1464. //
  1465. // UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1466. // //open exist
  1467. //
  1468. // ScanOrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  1469. // ovc.showNavibar = true;
  1470. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1471. // if(appDelegate.order_code==nil)
  1472. // {
  1473. // [self neworderforCart];
  1474. // }
  1475. // else
  1476. // {
  1477. // self.previous_VC = self.current_VC;
  1478. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1479. //
  1480. // [self checklogin:true];
  1481. //
  1482. // }
  1483. //
  1484. // };
  1485. //// ovc.init_style = OL_OPEN;
  1486. // ovc.onCancel = ^(){
  1487. //
  1488. // [self checklogin:true];
  1489. //
  1490. // };
  1491. // ovc.title = @"SAVED ORDER";
  1492. // [self.navigationController pushViewController:ovc animated:true];
  1493. // }];
  1494. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1495. // //create new;
  1496. //
  1497. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1498. // {
  1499. //
  1500. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1501. // cvc.showNavibar = true;
  1502. // cvc.contact_type = @"Sales_Order_Customer";
  1503. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1504. //
  1505. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1506. // appDelegate.customerInfo = value;
  1507. //
  1508. //
  1509. // if(appDelegate.order_code==nil)
  1510. // [self neworderforCart];
  1511. //
  1512. //
  1513. // };
  1514. //
  1515. // cvc.onCancel = ^(){
  1516. //
  1517. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  1518. //
  1519. //
  1520. //
  1521. // };
  1522. // cvc.onReset = ^(){
  1523. // [self checklogin:true];
  1524. // };
  1525. //
  1526. // [self.navigationController pushViewController:cvc animated:true];
  1527. // }
  1528. // else
  1529. // {
  1530. // [self neworderforCart];
  1531. // }
  1532. //
  1533. // }];
  1534. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1535. //
  1536. //
  1537. //
  1538. // }];
  1539. //
  1540. // [alertController addAction:action_1];
  1541. // [alertController addAction:action_2];
  1542. // [alertController addAction:action_3];
  1543. //
  1544. //
  1545. // [self presentViewController:alertController animated:YES completion:nil];
  1546. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Switch To Cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil),NSLocalizedString(@"Create new order", nil), nil];
  1547. ////
  1548. ////
  1549. ////
  1550. //// // alert.
  1551. //// [alert show];
  1552. // }
  1553. // else
  1554. // {
  1555. //
  1556. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Switch To Cart" message:@"Do you want to switch to a pending order?" preferredStyle:UIAlertControllerStyleAlert];
  1557. //
  1558. //
  1559. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1560. // //open exist
  1561. //
  1562. // ScanOrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  1563. // ovc.showNavibar = true;
  1564. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1565. // if(appDelegate.order_code==nil)
  1566. // {
  1567. // [self neworderforCart];
  1568. // }
  1569. // else
  1570. // {
  1571. // self.previous_VC = self.current_VC;
  1572. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1573. //
  1574. // [self checklogin:true];
  1575. //
  1576. // }
  1577. //
  1578. // };
  1579. //// ovc.init_style = OL_OPEN;
  1580. // ovc.onCancel = ^(){
  1581. //
  1582. // [self checklogin:true];
  1583. //
  1584. // };
  1585. // ovc.title = @"SAVED ORDER";
  1586. // [self.navigationController pushViewController:ovc animated:true];
  1587. // }];
  1588. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1589. //
  1590. //
  1591. //
  1592. // }];
  1593. //
  1594. //
  1595. // [alertController addAction:action_2];
  1596. // [alertController addAction:action_3];
  1597. //
  1598. //
  1599. // [self presentViewController:alertController animated:YES completion:nil];
  1600. //
  1601. //
  1602. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Switch To Cart", nil) message:NSLocalizedString(@"Do you want to switch to a pending order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil), nil];
  1603. ////
  1604. //// // alert.
  1605. //// [alert show];
  1606. // }
  1607. // }
  1608. //// else
  1609. //// {
  1610. //// [self checklogin:true];
  1611. //// self.previous_VC = self.current_VC;
  1612. //// [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1613. //// }
  1614. // }
  1615. //
  1616. // // self.offset = 0;
  1617. // // [self.content_data removeAllObjects];
  1618. // // [self loadpage];
  1619. // //
  1620. // // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1621. //
  1622. // };
  1623. //
  1624. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1625. //
  1626. //
  1627. //
  1628. //
  1629. //
  1630. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1631. //
  1632. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1633. // [self presentViewController:navi animated:YES completion:^{
  1634. //
  1635. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1636. //
  1637. // DebugLog(@"LoginViewController present.........");
  1638. //
  1639. // // self.btop = false;
  1640. // // <#code#>
  1641. // }];
  1642. // }
  1643. // else
  1644. // {
  1645. //// if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  1646. // if(appDelegate.order_code==nil)
  1647. // {
  1648. //// [self checklogin:false];
  1649. // if(appDelegate.can_create_order)
  1650. // {
  1651. // NSString* msg =@"";
  1652. // if(appDelegate.contact_id.length>0)
  1653. // {
  1654. // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  1655. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  1656. //
  1657. // }
  1658. //
  1659. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Switch To Cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1660. //
  1661. // UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1662. // //open exist
  1663. //
  1664. // ScanOrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  1665. // ovc.showNavibar = true;
  1666. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1667. // if(appDelegate.order_code==nil)
  1668. // {
  1669. // [self neworderforCart];
  1670. // }
  1671. // else
  1672. // {
  1673. // self.previous_VC = self.current_VC;
  1674. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1675. //
  1676. // [self checklogin:true];
  1677. //
  1678. // }
  1679. //
  1680. // };
  1681. //// ovc.init_style = OL_OPEN;
  1682. // ovc.onCancel = ^(){
  1683. //
  1684. // [self checklogin:true];
  1685. //
  1686. // };
  1687. // ovc.title = @"SAVED ORDER";
  1688. // [self.navigationController pushViewController:ovc animated:true];
  1689. // }];
  1690. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1691. // //create new;
  1692. //
  1693. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1694. // {
  1695. //
  1696. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1697. // cvc.showNavibar = true;
  1698. // cvc.contact_type = @"Sales_Order_Customer";
  1699. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1700. //
  1701. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1702. // appDelegate.customerInfo = value;
  1703. //
  1704. //
  1705. // if(appDelegate.order_code==nil)
  1706. // [self neworderforCart];
  1707. //
  1708. //
  1709. // };
  1710. //
  1711. // cvc.onCancel = ^(){
  1712. //
  1713. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  1714. //
  1715. //
  1716. //
  1717. // };
  1718. // cvc.onReset = ^(){
  1719. // [self checklogin:true];
  1720. // };
  1721. //
  1722. // [self.navigationController pushViewController:cvc animated:true];
  1723. // }
  1724. // else
  1725. // {
  1726. // [self neworderforCart];
  1727. // }
  1728. //
  1729. // }];
  1730. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1731. //
  1732. //
  1733. //
  1734. // }];
  1735. //
  1736. // [alertController addAction:action_1];
  1737. // [alertController addAction:action_2];
  1738. // [alertController addAction:action_3];
  1739. //
  1740. //
  1741. // [self presentViewController:alertController animated:YES completion:nil];
  1742. //
  1743. //
  1744. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Switch to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil),NSLocalizedString(@"Create new order", nil), nil];
  1745. ////
  1746. //// // alert.
  1747. //// [alert show];
  1748. // }
  1749. // else
  1750. // {
  1751. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Switch To Cart" message:@"Do you want to switch to a pending order?" preferredStyle:UIAlertControllerStyleAlert];
  1752. //
  1753. //
  1754. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Switch to pending order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1755. // //open exist
  1756. //
  1757. // ScanOrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanOrderListViewController"];
  1758. // ovc.showNavibar = true;
  1759. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1760. // if(appDelegate.order_code==nil)
  1761. // {
  1762. // [self neworderforCart];
  1763. // }
  1764. // else
  1765. // {
  1766. // self.previous_VC = self.current_VC;
  1767. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1768. //
  1769. // [self checklogin:true];
  1770. //
  1771. // }
  1772. //
  1773. // };
  1774. //// ovc.init_style = OL_OPEN;
  1775. // ovc.onCancel = ^(){
  1776. //
  1777. // [self checklogin:true];
  1778. //
  1779. // };
  1780. // ovc.title = @"SAVED ORDER";
  1781. // [self.navigationController pushViewController:ovc animated:true];
  1782. // }];
  1783. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1784. //
  1785. //
  1786. //
  1787. // }];
  1788. //
  1789. //
  1790. // [alertController addAction:action_2];
  1791. // [alertController addAction:action_3];
  1792. //
  1793. //
  1794. // [self presentViewController:alertController animated:YES completion:nil];
  1795. //
  1796. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Switch to cart", nil) message:NSLocalizedString(@"Do you want to Switch to a pending order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to pending order", nil), nil];
  1797. ////
  1798. //// // alert.
  1799. //// [alert show];
  1800. // }
  1801. // }
  1802. // else
  1803. // {
  1804. //
  1805. // self.previous_VC = self.current_VC;
  1806. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1807. //
  1808. //
  1809. //
  1810. // }
  1811. // }
  1812. //
  1813. self.previous_VC = self.current_VC;
  1814. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1815. }
  1816. -(void) switchToOrder
  1817. {
  1818. [self clearSelected];
  1819. self.btnorder.selected = true;
  1820. if([self.current_VC isKindOfClass:[ScanOrderListViewController class]])
  1821. return;
  1822. UIApplication * app = [UIApplication sharedApplication];
  1823. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1824. [self flipFromViewController:self.current_VC toViewController:self.scanorderViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  1825. }
  1826. - (IBAction)switchToOrder:(id)sender {
  1827. [self switchToOrder];
  1828. }
  1829. #pragma mark - CategoryMenuDelegate
  1830. -(void)SelectCategory:(NSString *)category
  1831. {
  1832. [self switchToCagegory:category];
  1833. }
  1834. -(NSString*) categoryString:(NSString*) categoryid node:(NSDictionary*) json level:(int) level;
  1835. {
  1836. if(categoryid.length==0)
  1837. return @">All Products>";
  1838. //NSString* idString = [NSString stringWithFormat:@"%d",categoryid];
  1839. NSString* categoryString =@">";
  1840. int count = [[json valueForKey:@"count"] intValue];
  1841. for(int i=0;i<count;i++)
  1842. {
  1843. NSDictionary * category_json = [json objectForKey:[NSString stringWithFormat:@"category_%d",i]];
  1844. NSString* cid = [category_json valueForKey:@"id"] ;
  1845. // NSString* ttt =[categoryid substringToIndex:2+level*2];
  1846. // NSString * qqq =[cid substringToIndex:2+level*2];
  1847. // NSString *ds1=[categoryid substringToIndex:3+level*3];
  1848. // NSString*ds2 = [cid substringToIndex:3+level*3];
  1849. if(cid.length<3+level*3)
  1850. continue;
  1851. if(categoryid.length<3+level*3)
  1852. continue;
  1853. if([[categoryid substringToIndex:3+level*3] isEqualToString: [cid substringToIndex:3+level*3]])
  1854. {
  1855. //categoryString = [categoryString stringByAppendingString:@">"];
  1856. categoryString =[categoryString stringByAppendingString: [category_json valueForKey:@"title" ] ];
  1857. categoryString = [categoryString stringByAppendingString:[ self categoryString:categoryid node:category_json level:level+1]];
  1858. break;
  1859. }
  1860. }
  1861. return categoryString;
  1862. }
  1863. - (void)didReceiveMemoryWarning
  1864. {
  1865. [super didReceiveMemoryWarning];
  1866. // Dispose of any resources that can be recreated.
  1867. }
  1868. - (IBAction)openMenu:(UIButton *)sender {
  1869. [self showMenu];
  1870. }
  1871. - (UIImage*)screen_shot
  1872. {
  1873. // CGRect r = self.view.frame;
  1874. // CGRect r1 = self.view.bounds;
  1875. // double width,height;
  1876. //
  1877. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  1878. // ;
  1879. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  1880. // {
  1881. // width = self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1882. // height =self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1883. // }
  1884. // else
  1885. // {
  1886. // width = self.view.frame.size.width<self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1887. // height =self.view.frame.size.width>self.view.frame.size.height? self.view.frame.size.width:self.view.frame.size.height;
  1888. // }
  1889. UIGraphicsBeginImageContext(CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height));
  1890. [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
  1891. UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
  1892. UIGraphicsEndImageContext();
  1893. return viewImage;
  1894. }
  1895. - (IBAction)onhideMenuClick:(id)sender {
  1896. [self hideMenu];
  1897. self.backgroundButton.hidden=true;
  1898. self.openMenuButton.hidden = false;
  1899. self.sideMenu.hidden = true;
  1900. }
  1901. - (void)hideMenu
  1902. {
  1903. CGRect frame ;
  1904. frame.origin.x = -300;
  1905. frame.origin.y = 0;
  1906. frame.size.height = self.view.bounds.size.height;
  1907. frame.size.width = 364;
  1908. self.sideMenu.frame=frame;
  1909. self.sideMenu.hidden = true;
  1910. self.blurView.alpha = 0;
  1911. [self.menuButton setImage:[UIImage imageNamed:@"menu_open"] forState:UIControlStateNormal];
  1912. self.menuShown = false;
  1913. self.backgroundButton.hidden=true;
  1914. self.openMenuButton.hidden = false;
  1915. }
  1916. - (void)showMenu
  1917. {
  1918. [self.sideMenuTable reloadData];
  1919. UIImage* imgsource = [self screen_shot];
  1920. self.blurView.alpha = 0;
  1921. UIImage* imgBlur =[self applyBlurWithRadius:5 sourceImage:imgsource tintColor:[UIColor colorWithWhite:0.2 alpha:0.73] saturationDeltaFactor:1.8 maskImage:nil];
  1922. self.blurView.image = imgBlur;
  1923. // self.blurView.hidden = imgBlur;
  1924. // [self.sideMenu becomeFirstResponder];
  1925. self.sideMenu.hidden = false;
  1926. self.backgroundButton.hidden=false;
  1927. CGRect frame ;
  1928. frame.origin.x = 0;
  1929. frame.origin.y = 0;
  1930. frame.size.height = self.view.bounds.size.height;
  1931. frame.size.width = 364;
  1932. // [UIView animateWithDuration:1.0 animations:^{ self.sideMenu.frame=frame;
  1933. // self.blurView.alpha = 1;
  1934. // [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1935. //
  1936. // }];
  1937. [UIView animateWithDuration:0.5 animations:^{ self.sideMenu.frame=frame;
  1938. self.blurView.alpha = 1;
  1939. }
  1940. completion:^(BOOL finished) {
  1941. [self.menuButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
  1942. }];
  1943. // UIImage* img= [UIImage imageNamed:@"menu"];
  1944. // self.menuButton.imageView.image = nil;
  1945. self.menuShown = true;
  1946. }
  1947. -(void)initMenuItems
  1948. {
  1949. UIApplication * app = [UIApplication sharedApplication];
  1950. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1951. self.sideMenuItems = [[NSMutableArray alloc] init];
  1952. NSMutableDictionary* map = [[NSMutableDictionary alloc] init];
  1953. if(appDelegate.user!=nil)
  1954. {
  1955. [map setValue:@"Wish List" forKey:@"title"];
  1956. [map setValue:@"rect_market_news" forKey:@"img"];
  1957. [self.sideMenuItems addObject:map.copy];
  1958. }
  1959. #if !defined(BUILD_HOMER) && !defined(BUILD_GATIT)
  1960. //#ifndef BUILD_HOMER //homer 要求去掉cam scan 2017/12/20
  1961. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1962. {
  1963. [map setValue:@"Cam Scan" forKey:@"title"];
  1964. [map setValue:@"rect_contact_list" forKey:@"img"];
  1965. [self.sideMenuItems addObject:map.copy];
  1966. }
  1967. #endif
  1968. if(appDelegate.user_type==USER_ROLE_EMPLOYEE || (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer))
  1969. {
  1970. // [map setValue:@"Contact" forKey:@"title"];
  1971. // [map setValue:@"rect_contact_list" forKey:@"img"];
  1972. // [self.sideMenuItems addObject:map.copy];
  1973. //#ifdef BUILD_UWAVER
  1974. // [map setValue:@"Hang Tag" forKey:@"title"];
  1975. //#else
  1976. [map setValue:@"Portfolio" forKey:@"title"];
  1977. //#endif
  1978. [map setValue:@"rect_market_news" forKey:@"img"];
  1979. [self.sideMenuItems addObject:map.copy];
  1980. //#ifdef BUILD_UWAVER
  1981. // [map setValue:@"View Hang Tags" forKey:@"title"];
  1982. //#else
  1983. [map setValue:@"View Portfolios" forKey:@"title"];
  1984. //#endif
  1985. [map setValue:@"rect_pdf_list" forKey:@"img"];
  1986. [self.sideMenuItems addObject:map.copy];
  1987. }
  1988. if(appDelegate.can_show_price)
  1989. {
  1990. if(appDelegate.price_hidden)
  1991. [map setValue:@"Show Price" forKey:@"title"];
  1992. else
  1993. [map setValue:@"Hide Price" forKey:@"title"];
  1994. [map setValue:@"rect_announcements" forKey:@"img"];
  1995. [self.sideMenuItems addObject:map.copy];
  1996. }
  1997. // [map setValue:@"Contact" forKey:@"title"];
  1998. // [map setValue:@"rect_market_news" forKey:@"img"];
  1999. // [self.sideMenuItems addObject:map.copy];
  2000. // [map setValue:@"Cache" forKey:@"title"];
  2001. // [map setValue:@"rect_announcements" forKey:@"img"];
  2002. //[self.sideMenuItems addObject:map.copy];
  2003. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  2004. // [map setValue:@"Message" forKey:@"title"];
  2005. // [map setValue:@"rect_search_history" forKey:@"img"];
  2006. // [self.sideMenuItems addObject:map.copy];
  2007. //
  2008. #if defined(BUILD_NPD)
  2009. [map setValue:@"Scanner Setting" forKey:@"title"];
  2010. [map setValue:@"rect_change_password" forKey:@"img"];
  2011. [self.sideMenuItems addObject:map.copy];
  2012. # endif
  2013. #if defined(SCANNER_ORDER)
  2014. [map setValue:@"Scanner Order" forKey:@"title"];
  2015. [map setValue:@"rect_change_password" forKey:@"img"];
  2016. [self.sideMenuItems addObject:map.copy];
  2017. # endif
  2018. #if defined(BUILD_NPD)|| defined (BUILD_CONTRAST)
  2019. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  2020. {
  2021. [map setValue:@"Offline Setting" forKey:@"title"];
  2022. [map setValue:@"rect_market_news" forKey:@"img"];
  2023. [self.sideMenuItems addObject:map.copy];
  2024. }
  2025. #endif
  2026. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore ) {
  2027. [map setValue:@"Price Setting" forKey:@"title"];
  2028. // [map setValue:@"rect_market_news" forKey:@"img"];
  2029. [self.sideMenuItems addObject:map.copy];
  2030. }
  2031. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore ) {
  2032. if ([RASingleton sharedInstance].global_lock) {
  2033. [map setValue:@"Unlock" forKey:@"title"];
  2034. } else {
  2035. [map setValue:@"Lock" forKey:@"title"];
  2036. }
  2037. [self.sideMenuItems addObject:map.copy];
  2038. }
  2039. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  2040. /*
  2041. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  2042. {
  2043. [map setValue:@"Offline Setting" forKey:@"title"];
  2044. [map setValue:@"rect_market_news" forKey:@"img"];
  2045. [self.sideMenuItems addObject:map.copy];
  2046. }
  2047. */
  2048. // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2049. // [map setValue:@"Price Setting" forKey:@"title"];
  2050. // // [map setValue:@"rect_market_news" forKey:@"img"];
  2051. // [self.sideMenuItems addObject:map.copy];
  2052. // }
  2053. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore ) {
  2054. if ([Singleton sharedInstance].global_lock) {
  2055. [map setValue:@"Unlock" forKey:@"title"];
  2056. } else {
  2057. [map setValue:@"Lock" forKey:@"title"];
  2058. }
  2059. [self.sideMenuItems addObject:map.copy];
  2060. }
  2061. # endif
  2062. #ifdef DEBUG
  2063. // if([[appDelegate.user lowercaseString] isEqualToString:@"larryl"]||[[appDelegate.user lowercaseString] isEqualToString:@"arpithat"])
  2064. {
  2065. // [map setValue:@"Contact" forKey:@"title"];
  2066. // [map setValue:@"rect_contact_list" forKey:@"img"];
  2067. // [self.sideMenuItems addObject:map.copy];
  2068. [map setValue:@"Function Test" forKey:@"title"];
  2069. [map setValue:@"rect_market_news" forKey:@"img"];
  2070. [self.sideMenuItems addObject:map.copy];
  2071. }
  2072. #endif
  2073. [map setValue:@"Privacy Policy" forKey:@"title"];
  2074. [map setValue:@"rect_change_password" forKey:@"img"];
  2075. [self.sideMenuItems addObject:map.copy];
  2076. [map setValue:@"About us" forKey:@"title"];
  2077. [map setValue:@"rect_change_password" forKey:@"img"];
  2078. [self.sideMenuItems addObject:map.copy];
  2079. #ifdef BUILD_HMLG
  2080. [map setValue:@"Homelegance Website" forKey:@"title"];
  2081. [map setValue:@"rect_change_password" forKey:@"img"];
  2082. [self.sideMenuItems addObject:map.copy];
  2083. #endif
  2084. #if defined(BUILD_NPD)
  2085. [map setValue:@"BLOG" forKey:@"title"];
  2086. [map setValue:@"rect_change_password" forKey:@"img"];
  2087. [self.sideMenuItems addObject:map.copy];
  2088. [map setValue:[NSString stringWithFormat:@"%@ Website",COMPANY_SHORT_NAME] forKey:@"title"];
  2089. [map setValue:@"rect_change_password" forKey:@"img"];
  2090. [self.sideMenuItems addObject:map.copy];
  2091. [map setValue:[NSString stringWithFormat:@"%@ Policy",COMPANY_SHORT_NAME] forKey:@"title"];
  2092. [map setValue:@"rect_change_password" forKey:@"img"];
  2093. [self.sideMenuItems addObject:map.copy];
  2094. [map setValue:@"Simplified Buying Program" forKey:@"title"];
  2095. [map setValue:@"rect_change_password" forKey:@"img"];
  2096. [self.sideMenuItems addObject:map.copy];
  2097. #endif
  2098. #ifdef BUILD_USAI
  2099. // [map setValue:@"BLOG" forKey:@"title"];
  2100. // [map setValue:@"rect_change_password" forKey:@"img"];
  2101. // [self.sideMenuItems addObject:map.copy];
  2102. [map setValue:@"USAI Website" forKey:@"title"];
  2103. [map setValue:@"rect_change_password" forKey:@"img"];
  2104. [self.sideMenuItems addObject:map.copy];
  2105. #endif
  2106. #ifdef BUILD_HOMER
  2107. /*
  2108. [map setValue:@"BLOG" forKey:@"title"];
  2109. [map setValue:@"rect_change_password" forKey:@"img"];
  2110. [self.sideMenuItems addObject:map.copy];
  2111. */
  2112. [map setValue:@"HOMER Website" forKey:@"title"];
  2113. [map setValue:@"rect_change_password" forKey:@"img"];
  2114. [self.sideMenuItems addObject:map.copy];
  2115. #endif
  2116. #ifdef BUILD_GATIT
  2117. [map setValue:@"TITAN Website" forKey:@"title"];
  2118. [map setValue:@"rect_change_password" forKey:@"img"];
  2119. [self.sideMenuItems addObject:map.copy];
  2120. # endif
  2121. [self.sideMenuTable reloadData];
  2122. //
  2123. }
  2124. - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius sourceImage:(UIImage*)sourceImage tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage
  2125. {
  2126. // Check pre-conditions.
  2127. if (sourceImage.size.width < 1 || sourceImage.size.height < 1) {
  2128. DebugLog (@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", sourceImage.size.width, sourceImage.size.height, self);
  2129. return nil;
  2130. }
  2131. if (!sourceImage.CGImage) {
  2132. DebugLog (@"*** error: image must be backed by a CGImage: %@", self);
  2133. return nil;
  2134. }
  2135. if (maskImage && !maskImage.CGImage) {
  2136. DebugLog (@"*** error: maskImage must be backed by a CGImage: %@", maskImage);
  2137. return nil;
  2138. }
  2139. CGRect imageRect = { CGPointZero, sourceImage.size };
  2140. UIImage *effectImage = sourceImage;
  2141. BOOL hasBlur = blurRadius > __FLT_EPSILON__;
  2142. BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__;
  2143. if (hasBlur || hasSaturationChange) {
  2144. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  2145. CGContextRef effectInContext = UIGraphicsGetCurrentContext();
  2146. CGContextScaleCTM(effectInContext, 1.0, -1.0);
  2147. CGContextTranslateCTM(effectInContext, 0, -sourceImage.size.height);
  2148. CGContextDrawImage(effectInContext, imageRect, sourceImage.CGImage);
  2149. vImage_Buffer effectInBuffer;
  2150. effectInBuffer.data = CGBitmapContextGetData(effectInContext);
  2151. effectInBuffer.width = CGBitmapContextGetWidth(effectInContext);
  2152. effectInBuffer.height = CGBitmapContextGetHeight(effectInContext);
  2153. effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext);
  2154. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  2155. CGContextRef effectOutContext = UIGraphicsGetCurrentContext();
  2156. vImage_Buffer effectOutBuffer;
  2157. effectOutBuffer.data = CGBitmapContextGetData(effectOutContext);
  2158. effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext);
  2159. effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext);
  2160. effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext);
  2161. if (hasBlur) {
  2162. // A description of how to compute the box kernel width from the Gaussian
  2163. // radius (aka standard deviation) appears in the SVG spec:
  2164. // http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
  2165. //
  2166. // For larger values of 's' (s >= 2.0), an approximation can be used: Three
  2167. // successive box-blurs build a piece-wise quadratic convolution kernel, which
  2168. // approximates the Gaussian kernel to within roughly 3%.
  2169. //
  2170. // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5)
  2171. //
  2172. // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel.
  2173. //
  2174. CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale];
  2175. NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5);
  2176. if (radius % 2 != 1) {
  2177. radius += 1; // force radius to be odd so that the three box-blur methodology works.
  2178. }
  2179. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  2180. vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  2181. vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (unsigned int)radius, (unsigned int)radius, 0, kvImageEdgeExtend);
  2182. }
  2183. BOOL effectImageBuffersAreSwapped = NO;
  2184. if (hasSaturationChange) {
  2185. CGFloat s = saturationDeltaFactor;
  2186. CGFloat floatingPointSaturationMatrix[] = {
  2187. 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0,
  2188. 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0,
  2189. 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0,
  2190. 0, 0, 0, 1,
  2191. };
  2192. const int32_t divisor = 256;
  2193. NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]);
  2194. int16_t saturationMatrix[matrixSize];
  2195. for (NSUInteger i = 0; i < matrixSize; ++i) {
  2196. saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor);
  2197. }
  2198. if (hasBlur) {
  2199. vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  2200. effectImageBuffersAreSwapped = YES;
  2201. }
  2202. else {
  2203. vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
  2204. }
  2205. }
  2206. if (!effectImageBuffersAreSwapped)
  2207. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  2208. UIGraphicsEndImageContext();
  2209. if (effectImageBuffersAreSwapped)
  2210. effectImage = UIGraphicsGetImageFromCurrentImageContext();
  2211. UIGraphicsEndImageContext();
  2212. }
  2213. // Set up output context.
  2214. UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, [[UIScreen mainScreen] scale]);
  2215. CGContextRef outputContext = UIGraphicsGetCurrentContext();
  2216. CGContextScaleCTM(outputContext, 1.0, -1.0);
  2217. CGContextTranslateCTM(outputContext, 0, -sourceImage.size.height);
  2218. // Draw base image.
  2219. CGContextDrawImage(outputContext, imageRect, sourceImage.CGImage);
  2220. // Draw effect image.
  2221. if (hasBlur) {
  2222. CGContextSaveGState(outputContext);
  2223. if (maskImage) {
  2224. CGContextClipToMask(outputContext, imageRect, maskImage.CGImage);
  2225. }
  2226. CGContextDrawImage(outputContext, imageRect, effectImage.CGImage);
  2227. CGContextRestoreGState(outputContext);
  2228. }
  2229. // Add in color tint.
  2230. if (tintColor) {
  2231. CGContextSaveGState(outputContext);
  2232. CGContextSetFillColorWithColor(outputContext, tintColor.CGColor);
  2233. CGContextFillRect(outputContext, imageRect);
  2234. CGContextRestoreGState(outputContext);
  2235. }
  2236. // Output image is ready.
  2237. UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
  2238. UIGraphicsEndImageContext();
  2239. return outputImage;
  2240. }
  2241. //- (IBAction)openMenu:(UIButton *)sender {
  2242. //}
  2243. #pragma mark - Table view data source
  2244. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  2245. {
  2246. return 1;
  2247. }
  2248. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  2249. {
  2250. return self.sideMenuItems.count;
  2251. }
  2252. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2253. {
  2254. UIApplication * app = [UIApplication sharedApplication];
  2255. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2256. NSString *CellIdentifier = @"SideMenuItem";
  2257. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2258. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  2259. cell.backgroundColor = [UIColor clearColor];
  2260. // [cell.backgroundColor:[UIColor clearColor]];
  2261. // UIImageView* iv= [[UIImageView alloc] initWithImage:];
  2262. cell.textLabel.text = title;
  2263. cell.detailTextLabel.textColor =[UIColor redColor];
  2264. if([title isEqualToString:@"Wish List"]&&appDelegate.wish_count>0)
  2265. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.wish_count];
  2266. else if(([title isEqualToString:@"Portfolio"] || [title isEqualToString:@"Hang Tag"])&&appDelegate.port_count>0)
  2267. cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",appDelegate.port_count];
  2268. else
  2269. {
  2270. cell.detailTextLabel.text =nil;
  2271. }
  2272. // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
  2273. return cell;
  2274. }
  2275. #ifdef SCANNER_ORDER
  2276. //#pragma mark - Offline Order
  2277. //-(void) CreateOfflineOrder
  2278. //{
  2279. //
  2280. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  2281. //
  2282. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2283. // __block MainViewController *brself= self;
  2284. // if(appDelegate.contact_id.length<=0)
  2285. // {
  2286. //
  2287. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"New Offline Order" message:nil preferredStyle:UIAlertControllerStyleAlert];
  2288. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"With Offline Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2289. //
  2290. //// if(appDelegate.order_code && appDelegate.order_code.length>0)
  2291. //// {
  2292. //// [RAUtils message_alert:@"Please close current order and try again." title:@"" controller:self];
  2293. //// }
  2294. //// NSLog(@"new click");
  2295. //
  2296. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2297. //
  2298. //// NSString *path = [[NSBundle mainBundle] pathForResource:@"editContact.json" ofType:nil];
  2299. //
  2300. // CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2301. // cuseditVC.bnewcustomer=true;
  2302. // cuseditVC.bolocustomer = true;
  2303. // cuseditVC.url_type = URL_LOCAL;
  2304. // cuseditVC.request_url=URL_SO_NEW_CONTACT;
  2305. //
  2306. // cuseditVC.params = params;
  2307. //
  2308. // cuseditVC.returnValue=^(NSMutableDictionary* value)
  2309. // {
  2310. // if(value==nil)
  2311. // {
  2312. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  2313. // }
  2314. // else
  2315. // {
  2316. // NSString* contact_id=[[NSUUID new] UUIDString];
  2317. //
  2318. //
  2319. //
  2320. //
  2321. //
  2322. //
  2323. // value [@"customer_cid"] = contact_id;
  2324. // appDelegate.contact_id=contact_id;
  2325. // appDelegate.customerInfo = value;
  2326. // [brself refreshContactDisplay];
  2327. // [self newoloorder];
  2328. //// [brself switchToCart:nil];
  2329. //
  2330. // }
  2331. // };
  2332. //
  2333. //
  2334. // // cuseditVC.delegate=self;
  2335. // //
  2336. // // if(checked.count==count)
  2337. // // {
  2338. // // orderinfoVC.have_tail = true
  2339. // // }
  2340. //
  2341. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  2342. // [self.navigationController pushViewController:cuseditVC animated:false];
  2343. //
  2344. //// [self dismissViewControllerAnimated:NO completion:^{
  2345. ////// [(UINavigationController*)[self parentViewController] pushViewController:cuseditVC animated:false];;
  2346. ////// [[self navigationController] setNavigationBarHidden:NO animated:NO];
  2347. ////
  2348. ////// [self pushViewController:cuseditVC animated:false];
  2349. //// }];
  2350. //
  2351. //// [[self navigationController] setNavigationBarHidden:NO animated:NO];
  2352. //// [self.navigationController pushViewController:cuseditVC animated:false];
  2353. //
  2354. //
  2355. // }];
  2356. //
  2357. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"With Online Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2358. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2359. //
  2360. // if(appDelegate.order_code && appDelegate.order_code.length>0)
  2361. // {
  2362. // // appDelegate.order_code= nil;
  2363. // // [appDelegate SetSo:nil];
  2364. //
  2365. //
  2366. // // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2367. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2368. // cvc.showNavibar = true;
  2369. // cvc.contact_type = @"Sales_Order_Customer";
  2370. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2371. //
  2372. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  2373. // appDelegate.customerInfo = value;
  2374. //
  2375. //// self.norefresh = true;
  2376. // [self newoloorder];
  2377. //
  2378. //
  2379. //
  2380. // // [main_vc checklogin:true];
  2381. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2382. //
  2383. // //
  2384. // // if(self.returnValue)
  2385. // // self.returnValue(value);
  2386. // };
  2387. //
  2388. // cvc.onCancel = ^(){
  2389. //// self.norefresh = true;
  2390. // if(appDelegate.customerInfo==nil)
  2391. // {
  2392. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  2393. // }
  2394. // else
  2395. // {
  2396. // [self newoloorder];
  2397. // }
  2398. // // [main_vc checklogin:true];
  2399. // };
  2400. // cvc.onReset = ^(){
  2401. // // [main_vc checklogin:true];
  2402. // };
  2403. //
  2404. // [self.navigationController pushViewController:cvc animated:true];
  2405. //
  2406. //
  2407. //
  2408. // }
  2409. // else
  2410. // {
  2411. // //create new;
  2412. //
  2413. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  2414. // {
  2415. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2416. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2417. // cvc.showNavibar = true;
  2418. // cvc.contact_type = @"Sales_Order_Customer";
  2419. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2420. //
  2421. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  2422. // appDelegate.customerInfo = value;
  2423. //
  2424. //
  2425. // if(appDelegate.order_code==nil)
  2426. // [self newoloorder];
  2427. //
  2428. // // [main_vc checklogin:true];
  2429. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2430. //
  2431. // //
  2432. // // if(self.returnValue)
  2433. // // self.returnValue(value);
  2434. // };
  2435. //
  2436. // cvc.onCancel = ^(){
  2437. //
  2438. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  2439. //
  2440. //
  2441. //
  2442. // };
  2443. // cvc.onReset = ^(){
  2444. // [main_vc checklogin:true];
  2445. // };
  2446. //
  2447. // [self.navigationController pushViewController:cvc animated:true];
  2448. // }
  2449. // else
  2450. // {
  2451. // [self newoloorder];
  2452. // }
  2453. // }
  2454. //
  2455. // }];
  2456. //
  2457. // UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2458. //
  2459. // }];
  2460. //
  2461. // [alertControl addAction:actionOne];
  2462. //
  2463. // [alertControl addAction:alertthree];
  2464. // [alertControl addAction:alertCancel];
  2465. //
  2466. // [self presentViewController:alertControl animated:YES completion:nil];
  2467. // }
  2468. // else
  2469. // {
  2470. // [self newoloorder];
  2471. // }
  2472. //}
  2473. -(void) scanLogin
  2474. {
  2475. [self onUserButtonClick:nil];
  2476. }
  2477. -(void) initAppDelegate
  2478. {
  2479. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2480. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  2481. // appDelegate.can_set_cart_price = true;
  2482. // appDelegate.can_see_price = true;
  2483. // appDelegate.can_set_cart_price = true;
  2484. // appDelegate.can_show_price = true;
  2485. // appDelegate.can_cancel_order = true;
  2486. // appDelegate.can_create_order=true;
  2487. // appDelegate.can_delete_order = true;
  2488. // appDelegate.can_submit_order = true;
  2489. // appDelegate.bLogin = true;
  2490. // RASingleton.sharedInstance.permissions_edit_order = true;
  2491. RASingleton.sharedInstance.price_type = 1;
  2492. [OLDataProvider createScanTempFolder];
  2493. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"] ;
  2494. if (addressDic) {
  2495. // NSUInteger selectedIndex = [[addressDic objectForKey:@"selectedIndex"] integerValue];
  2496. // if (selectedIndex == 1) {
  2497. // self.address = [addressDic objectForKey:@"serverAddress"];
  2498. // }
  2499. // if (selectedIndex == 2) {
  2500. // self.address = [addressDic objectForKey:@"serverAddress"];
  2501. // }
  2502. appDelegate.address = [addressDic objectForKey:@"serverAddress"];
  2503. // [OLDataProvider guestLogin];
  2504. NSMutableDictionary* guestjson=[OLDataProvider loadScanTemplate:@"guest.json"];
  2505. if(!guestjson)
  2506. {
  2507. [RADataProvider updateTemplate:self];
  2508. }
  2509. else
  2510. [self onUserButtonClick:nil];
  2511. }
  2512. else
  2513. {
  2514. // return;
  2515. SetupServerViewController * servervc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"SetupServerViewController"];
  2516. servervc.returnValue = ^{
  2517. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  2518. if (addressDic) {
  2519. self.labelServer.text = [addressDic objectForKey:@"show_name"];
  2520. }
  2521. [RADataProvider updateTemplate:self];
  2522. };
  2523. [self.navigationController pushViewController:servervc animated:true];
  2524. }
  2525. }
  2526. //-(void) newoloorder
  2527. //{
  2528. // NSString* order_code = [[NSUUID new] UUIDString];
  2529. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2530. // appDelegate.order_code = order_code;
  2531. //
  2532. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  2533. // RASingleton.sharedInstance.scan_cart=[[RAConvertor data2dict:json] mutableCopy];
  2534. //
  2535. //
  2536. //// __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
  2537. //// [RANetwork request_create_order:^(NSMutableDictionary *result) {
  2538. //// NSMutableDictionary* return_json =result;
  2539. ////
  2540. //// [waitalert dismissViewControllerAnimated:YES completion:^{
  2541. //// if([[return_json valueForKey:@"result"] intValue]==2)
  2542. //// {
  2543. //// int result=[[return_json valueForKey:@"result"] intValue];
  2544. //// if(result==2)
  2545. //// {
  2546. //// //successed.
  2547. ////
  2548. //// NSString* order_code = [return_json valueForKey:@"orderCode"];
  2549. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2550. //// appDelegate.order_code = order_code;
  2551. //// appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  2552. ////
  2553. ////
  2554. //// #ifdef RA_NOTIFICATION
  2555. //// [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2556. //// #else
  2557. //// MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2558. //// [main_vc reloadCart:true immediately:false];
  2559. //// #endif
  2560. ////
  2561. ////// [self ReloadData];
  2562. ////
  2563. ////
  2564. //// // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  2565. //// // [self loadpage];
  2566. ////
  2567. ////
  2568. //// // if(self.shopCartBlock!=nil)
  2569. //// // {
  2570. //// // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  2571. //// //
  2572. //// //
  2573. //// // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  2574. //// // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  2575. //// // iv.image = img;
  2576. //// // // [self.contentView addSubview:iv];
  2577. //// // self.shopCartBlock(iv);
  2578. //// //
  2579. //// // }
  2580. ////
  2581. //// }
  2582. //// }
  2583. //// else
  2584. //// {
  2585. //// [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  2586. //// }
  2587. //// }];
  2588. //// // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2589. ////
  2590. ////
  2591. ////
  2592. ////
  2593. ////
  2594. ////
  2595. ////
  2596. ////
  2597. //// }];
  2598. ////
  2599. //// }];
  2600. //
  2601. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2602. ////
  2603. //// NSDictionary* return_json = [RANetwork new_Order];
  2604. ////
  2605. //// dispatch_async(dispatch_get_main_queue(), ^{
  2606. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  2607. ////
  2608. ////
  2609. //// if([[return_json valueForKey:@"result"] intValue]==2)
  2610. //// {
  2611. //// int result=[[return_json valueForKey:@"result"] intValue];
  2612. //// if(result==2)
  2613. //// {
  2614. //// //successed.
  2615. ////
  2616. //// NSString* order_code = [return_json valueForKey:@"orderCode"];
  2617. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2618. //// appDelegate.order_code = order_code;
  2619. //// appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  2620. ////
  2621. ////
  2622. ////#ifdef RA_NOTIFICATION
  2623. //// [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2624. ////#else
  2625. //// MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2626. //// [main_vc reloadCart:true immediately:false];
  2627. ////#endif
  2628. ////
  2629. //// [self ReloadData];
  2630. ////
  2631. ////
  2632. //// // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  2633. //// // [self loadpage];
  2634. ////
  2635. ////
  2636. //// // if(self.shopCartBlock!=nil)
  2637. //// // {
  2638. //// // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  2639. //// //
  2640. //// //
  2641. //// // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  2642. //// // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  2643. //// // iv.image = img;
  2644. //// // // [self.contentView addSubview:iv];
  2645. //// // self.shopCartBlock(iv);
  2646. //// //
  2647. //// // }
  2648. ////
  2649. //// }
  2650. //// }
  2651. //// else
  2652. //// {
  2653. //// [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  2654. //// }
  2655. ////
  2656. ////
  2657. ////
  2658. ////
  2659. //// });
  2660. //// });
  2661. //}
  2662. #endif
  2663. #pragma mark - Table view delegate
  2664. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  2665. {
  2666. NSString* title = [self.sideMenuItems[indexPath.row] valueForKey:@"title"];
  2667. if([title isEqualToString:@"Cache"])
  2668. {
  2669. CacheViewController * settingvc=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CacheViewController"];
  2670. PopupNavigationController * navi=[[PopupNavigationController alloc] initWithRootViewController:settingvc];
  2671. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2672. [self presentViewController:navi animated:YES completion:^{
  2673. //DebugLog(@"login.........");
  2674. // <#code#>
  2675. }];
  2676. }
  2677. #ifdef SCANNER_ORDER
  2678. // else if([title isEqualToString:@"Scanner Order"])
  2679. // {
  2680. //
  2681. // OLOSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OLOSettingViewController"];
  2682. // offlineVC.returnValue=^(int type){
  2683. // if(type == OOC_CREATE_ORDER){
  2684. // [self CreateOfflineOrder];
  2685. // }
  2686. // };
  2687. // // loginvc.delegate = self;
  2688. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2689. // // appDelegate.active_controller = gunVC;
  2690. //// gunVC.onDismissVC = ^(){
  2691. //// appDelegate.active_controller = active_vc;
  2692. //// };
  2693. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
  2694. //
  2695. //
  2696. //
  2697. //
  2698. //
  2699. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2700. //
  2701. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2702. // [self presentViewController:navi animated:YES completion:^{
  2703. //
  2704. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2705. //
  2706. // DebugLog(@"about present.........");
  2707. //
  2708. // // self.btop = false;
  2709. // // <#code#>
  2710. // }];
  2711. //
  2712. // }
  2713. #endif
  2714. else if([title isEqualToString:@"Scanner Setting"])
  2715. {
  2716. //
  2717. #ifndef RA_NOTIFICATION
  2718. UIApplication * app = [UIApplication sharedApplication];
  2719. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2720. UIViewController* active_vc = appDelegate.active_controller;
  2721. ScannerSettingViewController * gunVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"];
  2722. appDelegate.active_controller = gunVC;
  2723. gunVC.onDismissVC = ^(){
  2724. appDelegate.active_controller = active_vc;
  2725. };
  2726. #else
  2727. ScannerSettingViewController * gunVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerSettingViewController"];
  2728. #endif
  2729. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:gunVC] ;
  2730. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2731. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2732. [self presentViewController:navi animated:YES completion:^{
  2733. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2734. DebugLog(@"about present.........");
  2735. // self.btop = false;
  2736. // <#code#>
  2737. }];
  2738. }
  2739. else if([title isEqualToString:@"Offline Setting"])
  2740. {
  2741. // UIApplication * app = [UIApplication sharedApplication];
  2742. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2743. //UIViewController* active_vc = appDelegate.active_controller;
  2744. OfflineSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineSettingViewController"];
  2745. // loginvc.delegate = self;
  2746. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2747. // appDelegate.active_controller = gunVC;
  2748. // gunVC.onDismissVC = ^(){
  2749. // appDelegate.active_controller = active_vc;
  2750. // };
  2751. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
  2752. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2753. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2754. [self presentViewController:navi animated:YES completion:^{
  2755. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2756. DebugLog(@"about present.........");
  2757. // self.btop = false;
  2758. // <#code#>
  2759. }];
  2760. // [iSalesDB testdata];
  2761. }
  2762. else if([title isEqualToString:@"Function Test"])
  2763. {
  2764. // NSString* url = @"https://shopla.homelegance.com/";
  2765. //
  2766. //
  2767. // NSString* title = @"NPD";
  2768. // UIApplication * app = [UIApplication sharedApplication];
  2769. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2770. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2771. //
  2772. //
  2773. FunctionTestViewController *ViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"FunctionTestViewController"];
  2774. // ViewController.url = url;
  2775. // ViewController.title = title;
  2776. [self.navigationController pushViewController:ViewController animated:YES];
  2777. }
  2778. else if ([title isEqualToString:@"BLOG"]) {
  2779. NSString* url = URL_BLOG;
  2780. #ifdef BUILD_HOMER
  2781. NSString* title = @"HOMER BLOG";
  2782. #endif
  2783. #ifdef BUILD_GATIT
  2784. NSString* title = @"TITAN BLOG";
  2785. #endif
  2786. #ifdef BUILD_NPD
  2787. NSString* title = @"NPD BLOG";
  2788. #endif
  2789. #ifdef BUILD_USAI
  2790. NSString* title = @"USAI BLOG";
  2791. #endif
  2792. #ifdef BUILD_CONTRAST
  2793. NSString* title = @"CONTRAST BLOG";
  2794. #endif
  2795. title = [NSString stringWithFormat:@"%@ BLOG",COMPANY_SHORT_NAME];
  2796. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2797. ViewController.url = url;
  2798. ViewController.title = title;
  2799. [self.navigationController pushViewController:ViewController animated:YES];
  2800. }
  2801. else if([title isEqualToString:@"NPD Website"])
  2802. {
  2803. NSString* url = @"https://www.newpacificdirect.com";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2804. NSString* title = @"NPD";
  2805. // UIApplication * app = [UIApplication sharedApplication];
  2806. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2807. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2808. //
  2809. //
  2810. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2811. ViewController.url = url;
  2812. ViewController.title = title;
  2813. [self.navigationController pushViewController:ViewController animated:YES];
  2814. }
  2815. else if([title isEqualToString:@"USAI Website"])
  2816. {
  2817. NSString* url = @"http://www.united-us.net/";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2818. NSString* title = @"USAI";
  2819. // UIApplication * app = [UIApplication sharedApplication];
  2820. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2821. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2822. //
  2823. //
  2824. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2825. ViewController.url = url;
  2826. ViewController.title = title;
  2827. [self.navigationController pushViewController:ViewController animated:YES];
  2828. }
  2829. else if([title isEqualToString:@"Homelegance Website"])
  2830. {
  2831. NSString* url = @"http://207.140.24.83";//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2832. NSString* title = @"Homelegance";
  2833. // UIApplication * app = [UIApplication sharedApplication];
  2834. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2835. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2836. //
  2837. //
  2838. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2839. ViewController.url = url;
  2840. ViewController.title = title;
  2841. [self.navigationController pushViewController:ViewController animated:YES];
  2842. }
  2843. else if([title isEqualToString:@"HOMER Website"])
  2844. {
  2845. NSString* url = COMPANY_WEB;
  2846. NSString* title = @"HOMER";
  2847. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2848. ViewController.url = url;
  2849. ViewController.title = title;
  2850. [self.navigationController pushViewController:ViewController animated:YES];
  2851. }
  2852. else if([title isEqualToString:@"TITAN Website"])
  2853. {
  2854. NSString* url = COMPANY_WEB;
  2855. NSString* title = @"TITAN";
  2856. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2857. ViewController.url = url;
  2858. ViewController.title = title;
  2859. [self.navigationController pushViewController:ViewController animated:YES];
  2860. }
  2861. else if([title isEqualToString:@"NPD Policy"])
  2862. {
  2863. NSString* url = URL_NPD_POLICY;//@"https://shopla.homelegance.com/general.htm?websiteId=1";//
  2864. NSString* title = @"NPD Policy";
  2865. // UIApplication * app = [UIApplication sharedApplication];
  2866. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2867. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2868. //
  2869. //
  2870. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2871. ViewController.url = url;
  2872. ViewController.title = title;
  2873. [self.navigationController pushViewController:ViewController animated:YES];
  2874. }
  2875. else if([title isEqualToString:@"USAI Policy"])
  2876. {
  2877. NSString* url = URL_NPD_POLICY;
  2878. NSString* title = @"USAI Policy";
  2879. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2880. ViewController.url = url;
  2881. ViewController.title = title;
  2882. [self.navigationController pushViewController:ViewController animated:YES];
  2883. }
  2884. else if([title isEqualToString:@"HOMER Policy"])
  2885. {
  2886. NSString* url = URL_NPD_POLICY;
  2887. NSString* title = @"HOMER Policy";
  2888. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2889. ViewController.url = url;
  2890. ViewController.title = title;
  2891. [self.navigationController pushViewController:ViewController animated:YES];
  2892. }
  2893. else if([title isEqualToString:@"Simplified Buying Program"])
  2894. {
  2895. SimplifiedBuyingProgramViewController *ViewController = [[UIStoryboard storyboardWithName:@"NPD_Mobile" bundle:nil] instantiateViewControllerWithIdentifier:@"SimplifiedBuyingProgramViewController"];
  2896. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:ViewController] ;
  2897. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2898. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2899. [self presentViewController:navi animated:YES completion:^{
  2900. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2901. DebugLog(@"about present.........");
  2902. // self.btop = false;
  2903. // <#code#>
  2904. }];
  2905. }
  2906. else if ([title isEqualToString:@"Privacy Policy"]) {
  2907. NSString* url = URL_PRIVACY;
  2908. NSString* title = @"Privacy Policy";
  2909. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  2910. ViewController.url = url;
  2911. ViewController.title = title;
  2912. [self.navigationController pushViewController:ViewController animated:YES];
  2913. }
  2914. else if([title isEqualToString:@"About us"])
  2915. {
  2916. AboutViewController * aboutVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AboutViewController"];
  2917. // loginvc.delegate = self;
  2918. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2919. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:aboutVC] ;
  2920. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2921. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2922. [self presentViewController:navi animated:YES completion:^{
  2923. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2924. DebugLog(@"about present.........");
  2925. // self.btop = false;
  2926. // <#code#>
  2927. }];
  2928. }
  2929. // else if([title isEqualToString:@"Wish List"])
  2930. // {
  2931. // [self hideMenu];
  2932. // [self switchtowishlist];
  2933. // }
  2934. else if([title isEqualToString:@"Show Price"])
  2935. {
  2936. UIApplication * app = [UIApplication sharedApplication];
  2937. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2938. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && [RASingleton sharedInstance].global_lock) {
  2939. JKLockController *lockVC = [[JKLockController alloc] init];
  2940. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  2941. __weak typeof(self) weakself = self;
  2942. lockVC.authoReturn = ^(BOOL failure) {
  2943. if (weakself) {
  2944. __strong typeof(weakself) strongself = weakself;
  2945. [appDelegate set_priceHidden:false];
  2946. [strongself initMenuItems];
  2947. [strongself hideMenu];
  2948. }
  2949. };
  2950. [self.navigationController pushViewController:lockVC animated:YES];
  2951. } else {
  2952. [appDelegate set_priceHidden:false];
  2953. [self initMenuItems];
  2954. [self hideMenu];
  2955. }
  2956. }
  2957. else if([title isEqualToString:@"Hide Price"])
  2958. {
  2959. UIApplication * app = [UIApplication sharedApplication];
  2960. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2961. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && [RASingleton sharedInstance].global_lock) {
  2962. JKLockController *lockVC = [[JKLockController alloc] init];
  2963. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  2964. __weak typeof(self) weakself = self;
  2965. lockVC.authoReturn = ^(BOOL failure) {
  2966. if (weakself) {
  2967. __strong typeof(weakself) strongself = weakself;
  2968. [appDelegate set_priceHidden:true];
  2969. [strongself initMenuItems];
  2970. [strongself hideMenu];
  2971. }
  2972. };
  2973. [self.navigationController pushViewController:lockVC animated:YES];
  2974. } else {
  2975. [appDelegate set_priceHidden:true];
  2976. [self initMenuItems];
  2977. [self hideMenu];
  2978. }
  2979. }
  2980. // else if([title isEqualToString:@"Portfolio"] || [title isEqualToString:@"Hang Tag"])
  2981. // {
  2982. // [self hideMenu];
  2983. // if([self.current_VC isKindOfClass:[PortfolioViewController class]])
  2984. // return;
  2985. // [self flipFromViewController:self.current_VC toViewController:self.portfolioViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  2986. // }
  2987. // else if([title isEqualToString:@"View Portfolios"] || [title isEqualToString:@"View Hang Tags"])
  2988. // {
  2989. // [self hideMenu];
  2990. // if([self.current_VC isKindOfClass:[PortfolioListViewController class]])
  2991. // return;
  2992. // [self flipFromViewController:self.current_VC toViewController:self.pdfListViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  2993. // }
  2994. else if([title isEqualToString:@"Contact"])
  2995. {
  2996. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  2997. //
  2998. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  2999. //
  3000. // if(indexPath.section!=1)
  3001. // return ;
  3002. // // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  3003. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3004. //
  3005. // NSString* product_id = [item_json valueForKey:@"product_id"];
  3006. [self hideMenu];
  3007. [self switchtocontact];
  3008. }
  3009. else if([title isEqualToString:@"Cam Scan"])
  3010. {
  3011. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  3012. //
  3013. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  3014. //
  3015. // if(indexPath.section!=1)
  3016. // return ;
  3017. // // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  3018. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3019. //
  3020. // NSString* product_id = [item_json valueForKey:@"product_id"];
  3021. [self hideMenu];
  3022. //
  3023. // [self switchtocontact];
  3024. ScannerViewController * scannerVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerViewController"];
  3025. [self.navigationController pushViewController:scannerVC animated:true];
  3026. } else if ([title isEqualToString:@"Price Setting"]) {
  3027. UIApplication * app = [UIApplication sharedApplication];
  3028. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  3029. if ([RASingleton sharedInstance].global_lock) {
  3030. JKLockController *lockVC = [[JKLockController alloc] init];
  3031. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  3032. __weak typeof(self) weakself = self;
  3033. lockVC.authoReturn = ^(BOOL failure) {
  3034. if (weakself) {
  3035. __strong typeof(weakself) strongself = weakself;
  3036. PriceSettingViewController *priceSettingVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"PriceSettingViewController"];
  3037. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:priceSettingVC] ;
  3038. navi.navigationBar.translucent = NO;
  3039. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  3040. [strongself presentViewController:navi animated:YES completion:^{
  3041. }];
  3042. }
  3043. };
  3044. [self.navigationController pushViewController:lockVC animated:YES];
  3045. } else {
  3046. PriceSettingViewController *priceSettingVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"PriceSettingViewController"];
  3047. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:priceSettingVC] ;
  3048. navi.navigationBar.translucent = NO;
  3049. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  3050. [self presentViewController:navi animated:YES completion:^{
  3051. }];
  3052. }
  3053. } else if ([title isEqualToString:@"Lock"] || [title isEqualToString:@"Unlock"]) {
  3054. UIApplication * app = [UIApplication sharedApplication];
  3055. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  3056. JKLockController *lockVC = [[JKLockController alloc] init];
  3057. [lockVC setPasswordKey:[NSString stringWithFormat:@"%@_password",appDelegate.user]];
  3058. __weak typeof(self) weakself = self;
  3059. lockVC.authoReturn = ^(BOOL failure) {
  3060. if (weakself) {
  3061. __strong typeof(weakself) strongself = weakself;
  3062. [RASingleton sharedInstance].global_lock = ![RASingleton sharedInstance].global_lock;
  3063. [strongself initMenuItems];
  3064. [strongself hideMenu];
  3065. }
  3066. };
  3067. [self.navigationController pushViewController:lockVC animated:YES];
  3068. }
  3069. }
  3070. //#pragma mark - UIAlertViewDelegate
  3071. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  3072. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  3073. //{
  3074. // UIApplication * app = [UIApplication sharedApplication];
  3075. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  3076. //
  3077. //
  3078. //
  3079. // // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  3080. // if(buttonIndex==alertView.cancelButtonIndex)
  3081. // {
  3082. //
  3083. //
  3084. //
  3085. // }
  3086. // else if(buttonIndex==1)
  3087. // {
  3088. // //open exist
  3089. //
  3090. // OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  3091. // ovc.showNavibar = true;
  3092. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  3093. // if(appDelegate.order_code==nil)
  3094. // {
  3095. // [self neworderforCart];
  3096. // }
  3097. // else
  3098. // {
  3099. // self.previous_VC = self.current_VC;
  3100. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  3101. //
  3102. // [self checklogin:true];
  3103. //
  3104. // }
  3105. //
  3106. // };
  3107. // ovc.init_style = OL_OPEN;
  3108. // ovc.onCancel = ^(){
  3109. //
  3110. // [self checklogin:true];
  3111. //
  3112. // };
  3113. // ovc.title = @"SAVED ORDER";
  3114. // [self.navigationController pushViewController:ovc animated:true];
  3115. // }
  3116. // else
  3117. // {
  3118. // //create new;
  3119. //
  3120. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  3121. // {
  3122. //
  3123. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  3124. // cvc.showNavibar = true;
  3125. // cvc.contact_type = @"Sales_Order_Customer";
  3126. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  3127. //
  3128. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  3129. // appDelegate.customerInfo = value;
  3130. //
  3131. //
  3132. // if(appDelegate.order_code==nil)
  3133. // [self neworderforCart];
  3134. //
  3135. //
  3136. // };
  3137. //
  3138. // cvc.onCancel = ^(){
  3139. //
  3140. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  3141. //
  3142. //
  3143. //
  3144. // };
  3145. // cvc.onReset = ^(){
  3146. // [self checklogin:true];
  3147. // };
  3148. //
  3149. // [self.navigationController pushViewController:cvc animated:true];
  3150. // }
  3151. // else
  3152. // {
  3153. // [self neworderforCart];
  3154. // }
  3155. //
  3156. // }
  3157. //}
  3158. -(void) neworderforCart
  3159. {
  3160. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
  3161. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  3162. NSMutableDictionary* return_json = result;
  3163. [waitalert dismissViewControllerAnimated:YES completion:^{
  3164. if([[return_json valueForKey:@"result"] intValue]==2)
  3165. {
  3166. int result=[[return_json valueForKey:@"result"] intValue];
  3167. if(result==2)
  3168. {
  3169. //successed.
  3170. NSString* order_code = [return_json valueForKey:@"orderCode"];
  3171. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3172. appDelegate.order_code = order_code;
  3173. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  3174. self.previous_VC = self.current_VC;
  3175. [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  3176. #ifdef RA_NOTIFICATION
  3177. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3178. #else
  3179. [self reloadCart:true immediately:false];
  3180. [self reloadOrder:true immediately:false];
  3181. #endif
  3182. }
  3183. }
  3184. else
  3185. {
  3186. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  3187. }
  3188. }];
  3189. }];
  3190. }];
  3191. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3192. //
  3193. // NSDictionary* return_json = [RANetwork new_Order];
  3194. //
  3195. // dispatch_async(dispatch_get_main_queue(), ^{
  3196. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  3197. //
  3198. //
  3199. // if([[return_json valueForKey:@"result"] intValue]==2)
  3200. // {
  3201. // int result=[[return_json valueForKey:@"result"] intValue];
  3202. // if(result==2)
  3203. // {
  3204. // //successed.
  3205. //
  3206. // NSString* order_code = [return_json valueForKey:@"orderCode"];
  3207. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3208. // appDelegate.order_code = order_code;
  3209. // appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  3210. //
  3211. // self.previous_VC = self.current_VC;
  3212. // [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
  3213. //
  3214. //
  3215. //#ifdef RA_NOTIFICATION
  3216. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3217. //#else
  3218. // [self reloadCart:true immediately:false];
  3219. // [self reloadOrder:true immediately:false];
  3220. //#endif
  3221. //
  3222. //
  3223. // }
  3224. // }
  3225. // else
  3226. // {
  3227. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  3228. // }
  3229. //
  3230. //
  3231. //
  3232. //
  3233. // });
  3234. // });
  3235. }
  3236. - (void)showPriceAuth:(NSInteger)from {
  3237. }
  3238. @end