iSalesNetwork.m 163 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320
  1. //
  2. // iSalesNetwork.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-20.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "iSalesNetwork.h"
  9. #import "RAUtils.h"
  10. #import "OLDataProvider.h"
  11. #import "Singleton.h"
  12. #import "GoogleAnalyst.h"
  13. #import "ERPUtils.h"
  14. NSString *const kScreenName = @"kScreenName";
  15. NSString *const kAction = @"kAction";
  16. NSString *const kExtra = @"kExtra";
  17. NSString *const ScreenCodeLoginView = @"Login Screen";
  18. NSString *const ScreenCodeHomeView = @"Home Screen";
  19. NSString *const ScreenCodeCategory = @"Category Screen";
  20. NSString *const ScreenCodeCart = @"Cart Sceen";
  21. NSString *const ScreenCodeOrderList = @"Order History Screen";
  22. NSString *const ScreenCodeSearch = @"Search Screen";
  23. NSString *const ScreenCodeAccount = @"Account Screen";
  24. NSString *const ScreenCodeWishList = @"Wish List Screen";
  25. NSString *const ScreenCodePortfolio = @"Portfolio Screen";
  26. NSString *const ScreenCodeViewPortfolios = @"View Portfolios Screen";
  27. NSString *const ScreenCodeCamScan = @"Cam Scan Screen";
  28. NSString *const ScreenCodeScannerSetting = @"Scanner Setting Screen";
  29. NSString *const ScreenCodeOfflineSetting = @"Offline Setting Screen";
  30. NSString *const ScreenCodePlaceOrder = @"Place Order Screen";
  31. NSString *const ScreenCodeCustomerInfo = @"Customer Information Screen";
  32. NSString *const ScreenCodeNewCustomer = @"New Customer Screen";
  33. NSString *const ScreenCodeEditCustomer = @"Edit Customer Information Screen";
  34. NSString *const ScreenCodeModelInfo = @"Model Information Screen";
  35. NSString *const ScreenCodeOrderInfo = @"Order Information Screeen";
  36. NSString *const ScreenCodeUserSign = @"User Sign Screen";
  37. NSString *const ScreenCodeNewAddress = @"New Address Screen";
  38. NSString *const ScreenCodeAdvanceSearch = @"Account Advance Search Screen";
  39. NSString *const ScreenCodeCreatePortfolio = @"Create Portfolio Screen";
  40. NSString *const ScreenCodeParticularCategory = @"Particular Category Screen";
  41. NSString *const ScreenCodeEditPortfolio = @"Edit Portfolio Screen";
  42. NSString *const ScreenCodePriceSetting = @"Price Setting Screen";
  43. NSString *const ScreenCodeCategoryPrice = @"Category Price Screen";
  44. NSString *const ScreenCodeSetCatetoryPrice = @"Set Category Price Screen";
  45. NSString *const ScreenCodeUploadImage = @"Upload Image Screen";
  46. NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
  47. @implementation iSalesNetwork
  48. +(void) LoadImage:(NSString*) url into:(UIImageView*) container
  49. {
  50. DebugLog(@"LoadImage:(NSString*) url in:(UIImageView*) container");
  51. NSString* file_name=[url lastPathComponent];
  52. NSData* img_data = [iSalesDB load_cached_img:file_name loadFrom:url];
  53. if(img_data==nil)
  54. {
  55. DebugLog(@"IMG NOT CACHED %@",file_name);
  56. img_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
  57. [iSalesDB cache_img:img_data filename:file_name saveTo:nil];
  58. //load from internet;
  59. }
  60. if(img_data!=nil)
  61. {
  62. UIImage * img =[UIImage imageWithData:img_data];
  63. if(img==nil)
  64. DebugLog(@"UIIMAGE IS NIL! %@",file_name);
  65. else
  66. container.image =img;
  67. }
  68. else
  69. {
  70. DebugLog(@"IMG DOWNLOAD FAILED! %@",file_name);
  71. }
  72. }
  73. //+(NSData*)fake_json:(NSString*) url
  74. //{
  75. // NSString* jsonfile = nil;
  76. // if([url isEqualToString:URL_UPDATE_AUTH])
  77. // {
  78. // jsonfile=@"login";
  79. //
  80. // }
  81. // else if([url isEqualToString:URL_REQUEST_CATMENU])
  82. // {
  83. // jsonfile=@"categorymenu";
  84. // }
  85. // else if([url isEqualToString:URL_LOAD_HOME])
  86. // {
  87. // jsonfile=@"homepage";
  88. // }
  89. // else if([url isEqualToString:URL_SEARCH])
  90. // {
  91. // jsonfile=@"search";
  92. // }
  93. // else if([url isEqualToString:URL_CATEGORY_LOADMORE])
  94. // {
  95. // jsonfile=@"category_more";
  96. // }else if([url isEqualToString:URL_ITEM_DETAIL])
  97. // {
  98. // jsonfile=@"detail";
  99. // }else if([url isEqualToString:URL_CART])
  100. // {
  101. // jsonfile=@"cart";
  102. // }else if([url isEqualToString:URL_ORDER_LIST])
  103. // {
  104. // jsonfile=@"orderlist";
  105. // }
  106. //// else if([url isEqualToString:URL_ORDER_INFO])
  107. //// {
  108. //// jsonfile=@"orderinfo";
  109. //// }
  110. //// else if([url isEqualToString:URL_ORDER_INFO])
  111. //// {
  112. //// jsonfile=@"orderinfo2label";
  113. //// }
  114. //
  115. //
  116. //
  117. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jsonfile ofType:@"json" ]];
  118. // NSMutableString *result = [[NSMutableString alloc] initWithData:json encoding:NSUTF8StringEncoding];
  119. //
  120. // DebugLog(@"result: \n%@",result);
  121. // return json;
  122. //}
  123. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
  124. {
  125. int retry = 0;
  126. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  127. if(appDelegate.user!=nil)
  128. [params setValue:appDelegate.user forKey:@"user"];
  129. if(appDelegate.password!=nil)
  130. [params setValue:appDelegate.password forKey:@"password"];
  131. if(appDelegate.ipad_perm!=nil)
  132. [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  133. [params setValue:appDelegate.build forKey:@"app_ver"];
  134. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  135. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  136. [params setValue:short_version forKey:@"app_short_ver"];
  137. UIDevice * dev = [UIDevice currentDevice];
  138. NSUUID* uuid =dev.identifierForVendor;
  139. #if TARGET_IPHONE_SIMULATOR//模拟器
  140. [params setValue:@"simulator_uuid" forKey:@"idfv"];
  141. #elif TARGET_OS_IPHONE//真机
  142. [params setValue:uuid.UUIDString forKey:@"idfv"];
  143. #endif
  144. NSString *screenName = [params valueForKey:kScreenName];
  145. NSString *userAction = [params valueForKey:kAction];
  146. NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  147. if ([userAction isEqualToString:@"Login"]) {
  148. if (!extra) {
  149. extra = [NSMutableDictionary dictionary];
  150. }
  151. [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  152. }
  153. repeat:
  154. {
  155. // return [self fake_json:url];
  156. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  157. //分界线的标识符
  158. NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
  159. //根据url初始化request
  160. NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
  161. cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
  162. timeoutInterval:JSON_TIMEOUT];
  163. //分界线 --AaB03x
  164. NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
  165. //结束符 AaB03x--
  166. NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
  167. //要上传的图片
  168. // UIImage *image=[params objectForKey:@"pic"];
  169. //得到图片的data
  170. // NSData* data = UIImagePNGRepresentation(image);
  171. //http body的字符串
  172. NSMutableString *body=[[NSMutableString alloc]init];
  173. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  174. // [params setValue:@"handset_login" forKey:@"action"];
  175. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  176. // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  177. // [params setValue:password forKey:@"password"];
  178. // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
  179. // [headers setValue:headQuerlString forKey:@"param"];
  180. //参数的集合的所有key的集合
  181. NSArray *keys= [params allKeys];
  182. DebugLog(@"================parms==================");
  183. //遍历keys
  184. for(int i=0;i<[keys count];i++)
  185. {
  186. //得到当前key
  187. NSString *key=[keys objectAtIndex:i];
  188. //如果key不是pic,说明value是字符类型,比如name:Boris
  189. if(![key isEqualToString:@"pic"])
  190. {
  191. //添加分界线,换行
  192. [body appendFormat:@"%@\r\n",MPboundary];
  193. //添加字段名称,换2行
  194. [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  195. //添加字段的值
  196. [body appendFormat:@"%@\r\n",[params objectForKey:key]];
  197. DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  198. }
  199. }
  200. DebugLog(@"================parms==================");
  201. ////添加分界线,换行
  202. [body appendFormat:@"%@\r\n",MPboundary];
  203. //声明pic字段,文件名为boris.png
  204. [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
  205. //声明上传文件的格式
  206. [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
  207. //声明结束符:--AaB03x--
  208. NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
  209. //声明myRequestData,用来放入http body
  210. NSMutableData *myRequestData=[NSMutableData data];
  211. //将body字符串转化为UTF8格式的二进制
  212. [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
  213. //将image的data加入
  214. // [myRequestData appendData:data];
  215. //加入结束符--AaB03x--
  216. [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  217. //设置HTTPHeader中Content-Type的值
  218. NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
  219. //设置HTTPHeader
  220. [request setValue:content forHTTPHeaderField:@"Content-Type"];
  221. // 关闭keep alive
  222. [request setValue:@"close" forHTTPHeaderField:@"Connection"];
  223. //设置Content-Length
  224. [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
  225. //设置http body
  226. [request setHTTPBody:myRequestData];
  227. //http method
  228. [request setHTTPMethod:@"POST"];
  229. NSHTTPURLResponse* urlResponse = nil;
  230. NSError *error = nil;
  231. NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  232. DebugLog(@"url: %@",url);
  233. DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
  234. if (responseData==nil) {
  235. // DebugLog(@"response error:%@", [error localizedDescription]);
  236. NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  237. //#define RESULT_FALSE 0
  238. //#define RESULT_TRUE 2
  239. //#define RESULT_NET_ERROR -3
  240. //#define RESULT_NET_NOTAVAILABLE -4
  241. //#define RESULT_ERROR -5
  242. //#define RESULT_LOCALFILE_ERROR -7
  243. //#define RESULT_USERAUTH_ERROR -9
  244. //#define RESULT_UPDATE_USERAUTH_ERROR -11
  245. //#define RESULT_SESSION_EXPIRED -13
  246. //#define RESULT_VER_LOW
  247. // NSString * moreinfo = error.description ;
  248. NSString* err_msg = [error localizedDescription];
  249. //-----------------retry 3 times for error code -1005------------------------
  250. if(error.code==-1005&&retry<3)
  251. {
  252. retry++;
  253. goto repeat;
  254. }
  255. //-----------------end retry 3 times for error code -1005------------------------
  256. NSDictionary* error_json = [RAUtils error_dict:error];
  257. [ret setObject:error_json forKey:@"err_obj"];
  258. NSString* resp_msg= nil;
  259. if(err_msg.length==0)
  260. {
  261. err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  262. resp_msg = err_msg;
  263. }
  264. [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  265. [ret setValue:err_msg forKey:@"err_msg"];
  266. [ret setValue:resp_msg forKey:@"resp_msg"];
  267. [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  268. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  269. options:0
  270. error:nil];
  271. if(![url isEqualToString:URL_ERR_LOG])
  272. {
  273. [iSalesNetwork err_log:[RAUtils base64en:[RAUtils dict2string:params]] result:[RAUtils base64en:[RAUtils dict2string:ret]] module:url code:RESULT_NET_ERROR];
  274. }
  275. #ifdef BUILD_NPD
  276. [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  277. #endif
  278. return jsonData;
  279. }
  280. else
  281. {
  282. NSString* err_msg = [error localizedDescription];
  283. NSMutableString *str = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  284. DebugLog(@"data string: %@",str);
  285. NSError *error1 = nil;
  286. NSMutableDictionary* jsobj = [[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error1] mutableCopy];
  287. if(jsobj==nil)// 服务器返回不是json
  288. {
  289. jsobj=[[NSMutableDictionary alloc] init];
  290. [jsobj setValue:@"1" forKey:@"result"];
  291. }
  292. int result=[[jsobj valueForKey:@"result"] intValue];
  293. UIApplication * app = [UIApplication sharedApplication];
  294. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  295. NSString* mode =[jsobj valueForKey:@"mode"];
  296. [appDelegate SetMode:mode];
  297. switch (result) {
  298. case 0:
  299. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  300. break;
  301. case 1:
  302. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  303. break;
  304. case 2:
  305. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  306. break;
  307. case 8:
  308. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  309. break;
  310. case 9:
  311. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  312. break;
  313. case 99:
  314. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  315. break;
  316. default:
  317. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  318. break;
  319. }
  320. if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  321. {
  322. [jsobj setValue:@"9" forKey:@"result"];
  323. [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  324. }
  325. if(![url isEqualToString:URL_ERR_LOG]&&![url isEqualToString:URL_DOWNLOAD_OFFLINE]/*&&result!=-3*/&&result!=2&&result!=99)
  326. {
  327. [iSalesNetwork err_log:[RAUtils base64en:[RAUtils dict2string:params]] result:[RAUtils base64en:str] module:url code:result];
  328. }
  329. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsobj
  330. options:0
  331. error:nil];
  332. #ifdef BUILD_NPD
  333. [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  334. #endif
  335. return jsonData;
  336. }
  337. return responseData;
  338. }
  339. }
  340. +(NSString*)DataTOjsonString:(id)object
  341. {
  342. NSString *jsonString = nil;
  343. NSError *error;
  344. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
  345. options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
  346. error:&error];
  347. if (! jsonData) {
  348. DebugLog(@"Got an error: %@", error);
  349. } else {
  350. jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  351. }
  352. return jsonString;
  353. }
  354. //+(NSDictionary*)request_Editor:(NSString*) sourceid editor:(NSString*)editor
  355. //{
  356. //
  357. //}
  358. +(NSDictionary*) delete_portfoliolist:(NSString* ) listid
  359. {
  360. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  361. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  362. if(appDelegate.user!=nil)
  363. [params setValue:appDelegate.user forKey:@"user"];
  364. if(appDelegate.contact_id!=nil)
  365. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  366. if(appDelegate.password!=nil)
  367. [params setValue:appDelegate.password forKey:@"password"];
  368. [params setValue:listid forKey:@"tearsheetsId"];
  369. // [params setValue:editor forKey:@"editor"];
  370. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  371. // [params setValue:@"Delete Portfolio" forKey:kAction];
  372. NSData* json = nil;
  373. if(appDelegate.offline_mode)
  374. {
  375. json = [OLDataProvider offline_removePDF:params];
  376. } else {
  377. if(![self IsNetworkAvailable])
  378. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  379. json=[self get_json:URL_PORTFOLIOLIST_REMOVE parameters:params];
  380. }
  381. if(json!=nil)
  382. {
  383. NSError *error=nil;
  384. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  385. return jsobj;
  386. }
  387. else
  388. return nil;
  389. }
  390. +(NSDictionary*) portfolio_remove:(NSString* ) item_ids
  391. {
  392. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  393. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  394. if(appDelegate.user!=nil)
  395. [params setValue:appDelegate.user forKey:@"user"];
  396. if(appDelegate.contact_id!=nil)
  397. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  398. if(appDelegate.password!=nil)
  399. [params setValue:appDelegate.password forKey:@"password"];
  400. [params setValue:item_ids forKey:@"portfolioId"];
  401. // [params setValue:editor forKey:@"editor"];
  402. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  403. NSData* json = nil;
  404. if(appDelegate.offline_mode)
  405. {
  406. json = [OLDataProvider offline_removePortfolio:params];
  407. } else {
  408. if(![self IsNetworkAvailable])
  409. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  410. json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  411. }
  412. if(json!=nil)
  413. {
  414. NSError *error=nil;
  415. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  416. int result = [[jsobj valueForKey:@"result"] intValue];
  417. if (result==2)
  418. {
  419. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  420. [appDelegate update_count_mark];
  421. }
  422. return jsobj;
  423. }
  424. else
  425. return nil;
  426. }
  427. +(NSDictionary*) watchlist_remove:(NSString* ) item_ids
  428. {
  429. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  430. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  431. if(appDelegate.user!=nil)
  432. [params setValue:appDelegate.user forKey:@"user"];
  433. if(appDelegate.contact_id!=nil)
  434. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  435. if(appDelegate.password!=nil)
  436. [params setValue:appDelegate.password forKey:@"password"];
  437. [params setValue:item_ids forKey:@"collectId"];
  438. // [params setValue:editor forKey:@"editor"];
  439. [params setValue:ScreenCodeWishList forKey:kScreenName];
  440. if(appDelegate.offline_mode)
  441. {
  442. return [OLDataProvider offline_deletewishlist:params];
  443. }
  444. if(![self IsNetworkAvailable])
  445. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  446. NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  447. if(json!=nil)
  448. {
  449. NSError *error=nil;
  450. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  451. int result = [[jsobj valueForKey:@"result"] intValue];
  452. if (result==2)
  453. {
  454. //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  455. appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  456. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  457. [appDelegate update_count_mark];
  458. }
  459. return jsobj;
  460. }
  461. else
  462. return nil;
  463. }
  464. +(NSDictionary*) move_cart2wish:(NSString* ) item_ids
  465. {
  466. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  467. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  468. if(appDelegate.user!=nil)
  469. [params setValue:appDelegate.user forKey:@"user"];
  470. if(appDelegate.contact_id!=nil)
  471. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  472. if(appDelegate.password!=nil)
  473. [params setValue:appDelegate.password forKey:@"password"];
  474. if(appDelegate.order_code!=nil)
  475. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  476. [params setValue:item_ids forKey:@"cartItemId"];
  477. // [params setValue:editor forKey:@"editor"];
  478. [params setValue:ScreenCodeCart forKey:kScreenName];
  479. // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  480. NSData* json = nil;
  481. if(appDelegate.offline_mode)
  482. {
  483. json= [OLDataProvider offline_movecart2wish:params];
  484. }
  485. else
  486. {
  487. if(![self IsNetworkAvailable])
  488. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  489. json=[self get_json:URL_CART2WISH parameters:params];
  490. }
  491. if(json!=nil)
  492. {
  493. NSError *error=nil;
  494. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  495. int result = [[jsobj valueForKey:@"result"] intValue];
  496. if (result==2)
  497. {
  498. //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  499. appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  500. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  501. [appDelegate update_count_mark];
  502. }
  503. return jsobj;
  504. }
  505. else
  506. return nil;
  507. }
  508. +(NSDictionary*) move_wish2cart:(NSString* ) item_ids
  509. {
  510. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  511. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  512. if(appDelegate.user!=nil)
  513. [params setValue:appDelegate.user forKey:@"user"];
  514. if(appDelegate.contact_id!=nil)
  515. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  516. if(appDelegate.password!=nil)
  517. [params setValue:appDelegate.password forKey:@"password"];
  518. if(appDelegate.order_code!=nil)
  519. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  520. [params setValue:item_ids forKey:@"collectId"];
  521. // [params setValue:editor forKey:@"editor"];
  522. [params setValue:ScreenCodeWishList forKey:kScreenName];
  523. [params setValue:@"Move To Cart" forKey:kAction];
  524. NSData *json = nil;
  525. if(appDelegate.offline_mode)
  526. {
  527. json = [OLDataProvider offline_movewish2cart:params];
  528. } else {
  529. if(![self IsNetworkAvailable])
  530. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  531. json=[self get_json:URL_WISH2CART parameters:params];
  532. }
  533. if(json!=nil)
  534. {
  535. NSError *error=nil;
  536. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  537. int result = [[jsobj valueForKey:@"result"] intValue];
  538. if (result==2)
  539. {
  540. //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  541. appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  542. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  543. [appDelegate update_count_mark];
  544. }
  545. return jsobj;
  546. }
  547. else
  548. return nil;
  549. }
  550. +(NSDictionary*) cart_remove:(NSString* ) item_ids
  551. {
  552. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  553. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  554. if(appDelegate.user!=nil)
  555. [params setValue:appDelegate.user forKey:@"user"];
  556. if(appDelegate.contact_id!=nil)
  557. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  558. if(appDelegate.password!=nil)
  559. [params setValue:appDelegate.password forKey:@"password"];
  560. if(appDelegate.order_code!=nil)
  561. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  562. [params setValue:item_ids forKey:@"cartItemId"];
  563. // [params setValue:editor forKey:@"editor"];
  564. [params setValue:ScreenCodeCart forKey:kScreenName];
  565. // [params setValue:@"" forKey:kAction];
  566. NSData* json=nil;
  567. if(appDelegate.offline_mode)
  568. {
  569. json= [OLDataProvider offline_cartremove:params];
  570. }
  571. else
  572. {
  573. if(![self IsNetworkAvailable])
  574. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  575. json=[self get_json:URL_CART_REMOVE parameters:params];
  576. }
  577. if(json!=nil)
  578. {
  579. NSError *error=nil;
  580. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  581. int result = [[jsobj valueForKey:@"result"] intValue];
  582. if (result==2)
  583. {
  584. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  585. [appDelegate update_count_mark];
  586. }
  587. return jsobj;
  588. }
  589. else
  590. return nil;
  591. }
  592. //+(NSDictionary*) cart_check:(NSString* ) item_ids
  593. //{
  594. // return nil;
  595. // if(![self IsNetworkAvailable])
  596. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  597. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  598. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  599. // if(appDelegate.user!=nil)
  600. // [params setValue:appDelegate.user forKey:@"user"];
  601. // if(appDelegate.contact_id!=nil)
  602. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  603. // if(appDelegate.password!=nil)
  604. // [params setValue:appDelegate.password forKey:@"password"];
  605. // [params setValue:item_ids forKey:@"cartItemId"];
  606. // // [params setValue:editor forKey:@"editor"];
  607. // if(appDelegate.offline_mode)
  608. // {
  609. // return [OLDataProvider offline_notimpl];
  610. // }
  611. // NSData* json=[self get_json:URL_CART_CHECK parameters:params];
  612. // if(json!=nil)
  613. // {
  614. // NSError *error=nil;
  615. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  616. // return jsobj;
  617. // }
  618. // else
  619. // return nil;
  620. //}
  621. +(NSDictionary*)create_Address:(NSMutableDictionary*)params
  622. {
  623. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  624. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  625. if(appDelegate.user!=nil)
  626. [params setValue:appDelegate.user forKey:@"user"];
  627. if(appDelegate.contact_id!=nil)
  628. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  629. if(appDelegate.password!=nil)
  630. [params setValue:appDelegate.password forKey:@"password"];
  631. // [params setValue:sourceid forKey:@"sourceid"];
  632. // [params setValue:editor forKey:@"editor"];
  633. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  634. NSData* json=nil;
  635. if(appDelegate.offline_mode)
  636. {
  637. json= [OLDataProvider offline_saveaddr:params];
  638. }
  639. else
  640. {
  641. if(![self IsNetworkAvailable])
  642. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  643. json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  644. }
  645. if(json!=nil)
  646. {
  647. NSError *error=nil;
  648. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  649. return jsobj;
  650. }
  651. else
  652. return nil;
  653. }
  654. +(NSDictionary*)copy_Order:(NSString*) order_code
  655. {
  656. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  657. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  658. if(appDelegate.user!=nil)
  659. [params setValue:appDelegate.user forKey:@"user"];
  660. if(appDelegate.contact_id!=nil)
  661. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  662. if(appDelegate.password!=nil)
  663. [params setValue:appDelegate.password forKey:@"password"];
  664. // NSString* ssaved = @"false";
  665. // if(saved)
  666. // ssaved=@"true";
  667. // [params setValue:@"true" forKey:@"saved"];
  668. [params setValue:order_code forKey:@"code"];
  669. // [params setValue:sourceid forKey:@"sourceid"];
  670. // [params setValue:editor forKey:@"editor"];
  671. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  672. NSData* json=nil;
  673. if(appDelegate.offline_mode)
  674. {
  675. json= [OLDataProvider offline_copyorder:params];
  676. }
  677. else
  678. {
  679. if(![self IsNetworkAvailable])
  680. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  681. json=[self get_json:URL_COPY_ORDER parameters:params];
  682. }
  683. if(json!=nil)
  684. {
  685. NSError *error=nil;
  686. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  687. return jsobj;
  688. }
  689. else
  690. return nil;
  691. }
  692. +(NSDictionary*)sign_Order:(NSString*) order_code path:(NSString*)path
  693. {
  694. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  695. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  696. if(appDelegate.user!=nil)
  697. [params setValue:appDelegate.user forKey:@"user"];
  698. if(appDelegate.contact_id!=nil)
  699. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  700. if(appDelegate.password!=nil)
  701. [params setValue:appDelegate.password forKey:@"password"];
  702. // NSString* ssaved = @"false";
  703. // if(saved)
  704. // ssaved=@"true";
  705. // [params setValue:@"true" forKey:@"saved"];
  706. [params setValue:order_code forKey:@"orderCode"];
  707. [params setValue:path forKey:@"picpath"];
  708. // [params setValue:sourceid forKey:@"sourceid"];
  709. // [params setValue:editor forKey:@"editor"];
  710. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  711. NSData* json=nil;
  712. if(appDelegate.offline_mode)
  713. {
  714. json= [OLDataProvider offline_signorder:params];
  715. }
  716. else
  717. {
  718. if(![self IsNetworkAvailable])
  719. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  720. json=[self get_json:URL_SIGN_ORDER parameters:params];
  721. }
  722. if(json!=nil)
  723. {
  724. NSError *error=nil;
  725. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  726. return jsobj;
  727. }
  728. else
  729. return nil;
  730. }
  731. +(NSDictionary*)commit_Order:(NSString*) order_code //saved:(bool) saved
  732. {
  733. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  734. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  735. if(appDelegate.user!=nil)
  736. [params setValue:appDelegate.user forKey:@"user"];
  737. if(appDelegate.contact_id!=nil)
  738. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  739. if(appDelegate.password!=nil)
  740. [params setValue:appDelegate.password forKey:@"password"];
  741. // NSString* ssaved = @"false";
  742. // if(saved)
  743. // ssaved=@"true";
  744. [params setValue:@"true" forKey:@"saved"];
  745. [params setValue:order_code forKey:@"orderCode"];
  746. // [params setValue:sourceid forKey:@"sourceid"];
  747. // [params setValue:editor forKey:@"editor"];
  748. [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  749. NSData* json = nil;
  750. if(appDelegate.offline_mode)
  751. {
  752. json= [OLDataProvider offline_submitorder:params];
  753. }
  754. else
  755. {
  756. if(![self IsNetworkAvailable])
  757. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  758. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  759. }
  760. if(json!=nil)
  761. {
  762. NSError *error=nil;
  763. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  764. return jsobj;
  765. }
  766. else
  767. return nil;
  768. }
  769. +(NSDictionary*)open_Order:(NSString*) order_code
  770. {
  771. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  772. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  773. if(appDelegate.user!=nil)
  774. [params setValue:appDelegate.user forKey:@"user"];
  775. // if(appDelegate.contact_id!=nil)
  776. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  777. if(appDelegate.password!=nil)
  778. [params setValue:appDelegate.password forKey:@"password"];
  779. [params setValue:order_code forKey:@"orderCode"];
  780. // [params setValue:sourceid forKey:@"sourceid"];
  781. // [params setValue:editor forKey:@"editor"];
  782. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  783. NSData* json=nil;
  784. if(appDelegate.offline_mode)
  785. {
  786. json=[OLDataProvider offline_editorder:params];
  787. }
  788. else
  789. {
  790. if(![self IsNetworkAvailable])
  791. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  792. json=[self get_json:URL_OPEN_ORDER parameters:params];
  793. }
  794. if(json!=nil)
  795. {
  796. NSError *error=nil;
  797. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  798. int result = [[jsobj valueForKey:@"result"] intValue];
  799. if (result==2)
  800. {
  801. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  802. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  803. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  804. [appDelegate update_count_mark];
  805. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  806. [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  807. }
  808. }
  809. return jsobj;
  810. }
  811. else
  812. return nil;
  813. }
  814. +(NSDictionary*)delete_Order:(NSString*) order_id
  815. {
  816. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  817. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  818. if(appDelegate.user!=nil)
  819. [params setValue:appDelegate.user forKey:@"user"];
  820. // if(appDelegate.contact_id!=nil)
  821. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  822. if(appDelegate.password!=nil)
  823. [params setValue:appDelegate.password forKey:@"password"];
  824. [params setValue:order_id forKey:@"orderId"];
  825. // [params setValue:sourceid forKey:@"sourceid"];
  826. // [params setValue:editor forKey:@"editor"];
  827. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  828. if(appDelegate.offline_mode)
  829. {
  830. return [OLDataProvider offline_notimpl];
  831. }
  832. if(![self IsNetworkAvailable])
  833. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  834. NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  835. if(json!=nil)
  836. {
  837. NSError *error=nil;
  838. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  839. return jsobj;
  840. }
  841. else
  842. return nil;
  843. }
  844. +(NSDictionary*)cancel_Order:(NSString*) order_id order_code:(NSString*) order_code
  845. {
  846. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  847. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  848. if(appDelegate.user!=nil)
  849. [params setValue:appDelegate.user forKey:@"user"];
  850. // if(appDelegate.contact_id!=nil)
  851. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  852. if(appDelegate.password!=nil)
  853. [params setValue:appDelegate.password forKey:@"password"];
  854. [params setValue:order_id forKey:@"orderId"];
  855. [params setValue:order_code forKey:@"orderCode"];
  856. // [params setValue:sourceid forKey:@"sourceid"];
  857. // [params setValue:editor forKey:@"editor"];
  858. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  859. NSData* json=nil;
  860. if(appDelegate.offline_mode)
  861. {
  862. json=[OLDataProvider offline_cancelorder:params];
  863. }
  864. else
  865. {
  866. if(![self IsNetworkAvailable])
  867. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  868. json=[self get_json:URL_CANCEL_ORDER parameters:params];
  869. }
  870. if(json!=nil)
  871. {
  872. NSError *error=nil;
  873. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  874. return jsobj;
  875. }
  876. else
  877. return nil;
  878. }
  879. +(NSDictionary*)release_Order:(NSString*) order_code withScreen:(NSString *)screenName
  880. {
  881. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  882. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  883. if(appDelegate.user!=nil)
  884. [params setValue:appDelegate.user forKey:@"user"];
  885. // if(appDelegate.contact_id!=nil)
  886. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  887. if(appDelegate.password!=nil)
  888. [params setValue:appDelegate.password forKey:@"password"];
  889. [params setValue:order_code forKey:@"orderCode"];
  890. // [params setValue:sourceid forKey:@"sourceid"];
  891. // [params setValue:editor forKey:@"editor"];
  892. if (screenName) {
  893. [params setValue:screenName forKey:kScreenName];
  894. }
  895. NSData* json=nil;
  896. if(appDelegate.offline_mode)
  897. {
  898. json= [OLDataProvider offline_resetorder:params];
  899. }
  900. else
  901. {
  902. if(![self IsNetworkAvailable])
  903. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  904. json=[self get_json:URL_RELEASE_ORDER parameters:params];
  905. }
  906. if(json!=nil)
  907. {
  908. NSError *error=nil;
  909. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  910. if([[jsobj valueForKey:@"result"]intValue]==2)
  911. { [appDelegate SetSo:nil];
  912. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  913. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  914. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  915. [appDelegate update_count_mark];
  916. }
  917. return jsobj;
  918. }
  919. else
  920. return nil;
  921. }
  922. +(NSDictionary*)update_OrderCustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info
  923. {
  924. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  925. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  926. if(appDelegate.user!=nil)
  927. [info setValue:appDelegate.user forKey:@"user"];
  928. // if(appDelegate.contact_id!=nil)
  929. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  930. if(appDelegate.password!=nil)
  931. [info setValue:appDelegate.password forKey:@"password"];
  932. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  933. [info setValue:order_code forKey:@"orderCode"];
  934. // [params setValue:sourceid forKey:@"sourceid"];
  935. // [params setValue:editor forKey:@"editor"];
  936. if(appDelegate.offline_mode)
  937. {
  938. return [OLDataProvider offline_notimpl];
  939. }
  940. if(![self IsNetworkAvailable])
  941. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  942. NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  943. if(json!=nil)
  944. {
  945. NSError *error=nil;
  946. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  947. return jsobj;
  948. }
  949. else
  950. return nil;
  951. }
  952. +(NSDictionary*)commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url
  953. {
  954. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  955. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  956. if(appDelegate.user!=nil)
  957. [params setValue:appDelegate.user forKey:@"user"];
  958. if(appDelegate.contact_id!=nil)
  959. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  960. if(appDelegate.password!=nil)
  961. [params setValue:appDelegate.password forKey:@"password"];
  962. // if(appDelegate.order_code!=nil)
  963. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  964. // NSDictionary* customerinfo= appDelegate.customerInfo;
  965. //
  966. // NSArray* keys=[customerinfo allKeys];
  967. // for(int i=0;i<keys.count;i++)
  968. // {
  969. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  970. // }
  971. //
  972. // [params setValue:sourceid forKey:@"sourceid"];
  973. // [params setValue:editor forKey:@"editor"];
  974. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  975. if(appDelegate.offline_mode)
  976. {
  977. params[@"offline_Command"]=url;
  978. return [OLDataProvider offline_commoneditor_partialrefresh:params];
  979. }
  980. if(![self IsNetworkAvailable])
  981. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  982. NSData* json=[self get_json:url parameters:params];
  983. if(json!=nil)
  984. {
  985. NSError *error=nil;
  986. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  987. if([[jsobj valueForKey:@"result"]intValue]==2)
  988. [appDelegate SetSo:nil];
  989. return jsobj;
  990. }
  991. else
  992. return nil;
  993. }
  994. +(NSDictionary*)saveandcommit_Order:(NSMutableDictionary*)params
  995. {
  996. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  997. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  998. if(appDelegate.user!=nil)
  999. [params setValue:appDelegate.user forKey:@"user"];
  1000. if(appDelegate.contact_id!=nil)
  1001. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1002. if(appDelegate.password!=nil)
  1003. [params setValue:appDelegate.password forKey:@"password"];
  1004. if(appDelegate.order_code!=nil)
  1005. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1006. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1007. //
  1008. // NSArray* keys=[customerinfo allKeys];
  1009. // for(int i=0;i<keys.count;i++)
  1010. // {
  1011. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1012. // }
  1013. //
  1014. // [params setValue:sourceid forKey:@"sourceid"];
  1015. // [params setValue:editor forKey:@"editor"];
  1016. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1017. NSData* json=nil;
  1018. if(appDelegate.offline_mode)
  1019. {
  1020. json=[OLDataProvider offline_submitorder:params];
  1021. }
  1022. else
  1023. {
  1024. if(![self IsNetworkAvailable])
  1025. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1026. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1027. }
  1028. if(json!=nil)
  1029. {
  1030. NSError *error=nil;
  1031. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1032. if([[jsobj valueForKey:@"result"]intValue]==2)
  1033. [appDelegate SetSo:nil];
  1034. return jsobj;
  1035. }
  1036. else
  1037. return nil;
  1038. }
  1039. +(NSDictionary*)update_Customer:(NSMutableDictionary*)params
  1040. {
  1041. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1042. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1043. if(appDelegate.user!=nil)
  1044. [params setValue:appDelegate.user forKey:@"user"];
  1045. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1046. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1047. // else
  1048. if(appDelegate.contact_id!=nil)
  1049. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1050. if(appDelegate.password!=nil)
  1051. [params setValue:appDelegate.password forKey:@"password"];
  1052. // NSDictionary* customerinfo=nil;
  1053. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1054. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1055. // else
  1056. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1057. //
  1058. // appDelegate.customerInfo;
  1059. // NSArray* keys=[customerinfo allKeys];
  1060. // for(int i=0;i<keys.count;i++)
  1061. // {
  1062. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1063. // }
  1064. // [params setValue:sourceid forKey:@"sourceid"];
  1065. // [params setValue:editor forKey:@"editor"];
  1066. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1067. NSData* json=nil;
  1068. if(appDelegate.offline_mode)
  1069. {
  1070. json= [OLDataProvider offline_saveContact:params];
  1071. }
  1072. else
  1073. {
  1074. if(![self IsNetworkAvailable])
  1075. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1076. json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  1077. }
  1078. if(json!=nil)
  1079. {
  1080. NSError *error=nil;
  1081. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1082. return jsobj;
  1083. }
  1084. else
  1085. return nil;
  1086. }
  1087. +(NSDictionary*)save_newCustomer:(NSMutableDictionary*)params
  1088. {
  1089. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1090. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1091. if(appDelegate.user!=nil)
  1092. [params setValue:appDelegate.user forKey:@"user"];
  1093. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1094. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1095. // else
  1096. if(appDelegate.contact_id!=nil)
  1097. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1098. if(appDelegate.password!=nil)
  1099. [params setValue:appDelegate.password forKey:@"password"];
  1100. // NSDictionary* customerinfo=nil;
  1101. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1102. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1103. // else
  1104. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1105. //
  1106. // appDelegate.customerInfo;
  1107. // NSArray* keys=[customerinfo allKeys];
  1108. // for(int i=0;i<keys.count;i++)
  1109. // {
  1110. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1111. // }
  1112. // [params setValue:sourceid forKey:@"sourceid"];
  1113. // [params setValue:editor forKey:@"editor"];
  1114. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1115. NSData* json=nil;
  1116. if(appDelegate.offline_mode)
  1117. {
  1118. json= [OLDataProvider offline_saveNewContact:params];
  1119. }
  1120. else
  1121. {
  1122. if(![self IsNetworkAvailable])
  1123. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1124. json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  1125. }
  1126. if(json!=nil)
  1127. {
  1128. NSError *error=nil;
  1129. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1130. return jsobj;
  1131. }
  1132. else
  1133. return nil;
  1134. }
  1135. +(NSDictionary*)save_Order:(NSMutableDictionary*)params
  1136. {
  1137. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1138. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1139. if(appDelegate.user!=nil)
  1140. [params setValue:appDelegate.user forKey:@"user"];
  1141. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1142. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1143. // else
  1144. if(appDelegate.contact_id!=nil)
  1145. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1146. if(appDelegate.password!=nil)
  1147. [params setValue:appDelegate.password forKey:@"password"];
  1148. if(appDelegate.order_code!=nil)
  1149. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1150. // NSDictionary* customerinfo=nil;
  1151. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1152. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1153. // else
  1154. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1155. //
  1156. // appDelegate.customerInfo;
  1157. // NSArray* keys=[customerinfo allKeys];
  1158. // for(int i=0;i<keys.count;i++)
  1159. // {
  1160. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1161. // }
  1162. // [params setValue:sourceid forKey:@"sourceid"];
  1163. // [params setValue:editor forKey:@"editor"];
  1164. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1165. NSData* json=nil;
  1166. if(appDelegate.offline_mode)
  1167. {
  1168. json= [OLDataProvider offline_saveorder:params];
  1169. }
  1170. else
  1171. {
  1172. if(![self IsNetworkAvailable])
  1173. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1174. json=[self get_json:URL_SAVE_ORDER parameters:params];
  1175. }
  1176. if(json!=nil)
  1177. {
  1178. NSError *error=nil;
  1179. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1180. NSString *so = [jsobj valueForKey:@"so#"];
  1181. if (so) {
  1182. [appDelegate SetSo:so];
  1183. }
  1184. return jsobj;
  1185. }
  1186. else
  1187. return nil;
  1188. }
  1189. +(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  1190. {
  1191. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1192. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1193. if(appDelegate.user!=nil)
  1194. [params setValue:appDelegate.user forKey:@"user"];
  1195. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1196. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1197. // else
  1198. if(appDelegate.contact_id!=nil)
  1199. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1200. if(appDelegate.password!=nil)
  1201. [params setValue:appDelegate.password forKey:@"password"];
  1202. if(appDelegate.order_code!=nil)
  1203. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1204. // [params setValue:sourceid forKey:@"sourceid"];
  1205. // [params setValue:editor forKey:@"editor"];
  1206. DebugLog(@"request editor url:%@",request_url);
  1207. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1208. {
  1209. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1210. }
  1211. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1212. {
  1213. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1214. }
  1215. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1216. {
  1217. [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  1218. }
  1219. else if([request_url isEqualToString:URL_CARTDELIVERY])
  1220. {
  1221. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1222. }
  1223. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1224. {
  1225. [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  1226. }
  1227. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1228. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1229. }
  1230. NSData* json = nil;
  1231. if(appDelegate.offline_mode)
  1232. {
  1233. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1234. {
  1235. json= [OLDataProvider offline_createContact:params];
  1236. }
  1237. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1238. {
  1239. json= [OLDataProvider offline_editContact:params];
  1240. }
  1241. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1242. {
  1243. json= [OLDataProvider offline_contactAdvancedSearch:params];
  1244. }
  1245. else if([request_url isEqualToString:URL_CARTDELIVERY])
  1246. {
  1247. json= [OLDataProvider offline_placeorder:params];
  1248. }
  1249. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1250. {
  1251. json= [OLDataProvider offline_addreditor:params];
  1252. }
  1253. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1254. json = [OLDataProvider offline_createTearSheet:params];
  1255. }
  1256. else
  1257. return [OLDataProvider offline_notimpl];
  1258. }
  1259. else
  1260. {
  1261. if(![self IsNetworkAvailable])
  1262. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1263. if([request_url isEqualToString:URL_CARTDELIVERY])
  1264. {
  1265. NSError *error=nil;
  1266. NSString * uuid= [[NSUUID UUID] UUIDString];
  1267. params[@"resultSerial"]=uuid;
  1268. for(int i=0;i<150;i++)
  1269. {
  1270. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1271. // result_params[@"resultSerial"]=uuid;
  1272. json=[self get_json:request_url parameters:params];
  1273. if(json!=nil)
  1274. {
  1275. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1276. if([jsobj[@"result"] intValue]==2 || [jsobj[@"result"] intValue] == 8)
  1277. {
  1278. break;
  1279. }
  1280. }
  1281. sleep(2);
  1282. }
  1283. }
  1284. else
  1285. json =[self get_json:request_url parameters:params];
  1286. }
  1287. if(json!=nil)
  1288. {
  1289. NSError *error=nil;
  1290. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1291. return jsobj;
  1292. }
  1293. else
  1294. return nil;
  1295. }
  1296. //+(NSDictionary*)request_OrderInfo:(NSString*) orderid
  1297. //{
  1298. // if(![self IsNetworkAvailable])
  1299. // return nil;
  1300. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1301. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1302. // if(appDelegate.user!=nil)
  1303. // [params setValue:appDelegate.user forKey:@"user"];
  1304. // if(appDelegate.password!=nil)
  1305. // [params setValue:appDelegate.password forKey:@"password"];
  1306. // [params setValue:orderid forKey:@"orderid"];
  1307. // NSData* json=[self get_json:URL_ORDER_INFO parameters:params];
  1308. // NSError *error=nil;
  1309. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1310. // return jsobj;
  1311. //}
  1312. +(NSDictionary*)request_OrderList:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged
  1313. {
  1314. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1315. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1316. if(appDelegate.user!=nil)
  1317. [params setValue:appDelegate.user forKey:@"user"];
  1318. if(appDelegate.contact_id!=nil)
  1319. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1320. if(appDelegate.password!=nil)
  1321. [params setValue:appDelegate.password forKey:@"password"];
  1322. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1323. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1324. [params setValue:keywords forKey:@"keyWord"];
  1325. [params setValue:customer forKey:@"customer_filter"];
  1326. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  1327. [params setValue:status_code forKey:@"orderStatus"];
  1328. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1329. if (keywords) {
  1330. [params setObject:@"Search" forKey:kAction];
  1331. }
  1332. NSData* json=nil;
  1333. if(appDelegate.offline_mode)
  1334. {
  1335. json= [OLDataProvider offline_orderlist:params];
  1336. }
  1337. else
  1338. {
  1339. if(![self IsNetworkAvailable])
  1340. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1341. json=[self get_json:URL_ORDER_LIST parameters:params];
  1342. }
  1343. if(json==nil)
  1344. return nil;
  1345. NSError *error=nil;
  1346. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1347. return jsobj;
  1348. }
  1349. +(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords
  1350. {
  1351. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1352. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1353. if(appDelegate.user!=nil)
  1354. [params setValue:appDelegate.user forKey:@"user"];
  1355. if(appDelegate.contact_id!=nil)
  1356. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1357. if(appDelegate.password!=nil)
  1358. [params setValue:appDelegate.password forKey:@"password"];
  1359. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  1360. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  1361. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  1362. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  1363. // [params setValue:filter forKey:@"filter"];
  1364. [params setValue:keywords forKey:@"keyWord"];
  1365. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  1366. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  1367. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  1368. if (keywords) {
  1369. [params setObject:@"Search" forKey:kAction];
  1370. }
  1371. NSData* json = nil;
  1372. if(appDelegate.offline_mode)
  1373. {
  1374. json = [OLDataProvider offline_pdfList:params];
  1375. } else {
  1376. if(![self IsNetworkAvailable])
  1377. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1378. json=[self get_json:URL_DM_LIST parameters:params];
  1379. }
  1380. if(json==nil)
  1381. return nil;
  1382. NSError *error=nil;
  1383. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1384. return jsobj;
  1385. }
  1386. +(NSString*) create_portfolio:(NSMutableDictionary*)params
  1387. { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1388. if(appDelegate.offline_mode)
  1389. {
  1390. NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  1391. if(json==nil)
  1392. return nil;
  1393. NSError *error=nil;
  1394. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1395. return jsobj[@"pdf_path"];
  1396. }
  1397. else
  1398. {
  1399. return nil;
  1400. }
  1401. }
  1402. +(NSDictionary*)direct_save_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url name:(NSString*)name delete:(NSString* )ids note:(NSString* )saveNote modelIds:(NSDictionary *)modelIds
  1403. {
  1404. NSMutableDictionary* off_params = [params mutableCopy];;
  1405. params[@"off_params"]=[RAUtils dict2string:off_params];;
  1406. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1407. if(appDelegate.user!=nil)
  1408. [params setValue:appDelegate.user forKey:@"user"];
  1409. if(appDelegate.contact_id!=nil)
  1410. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1411. if(appDelegate.password!=nil)
  1412. [params setValue:appDelegate.password forKey:@"password"];
  1413. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1414. /*
  1415. [params setValue:request_url forKey:@"pdfUrl"];
  1416. [params setValue:name forKey:@"pdfName"];
  1417. [params setValue:ids forKey:@"itemIds"];
  1418. [params setValue:saveNote forKey:@"pdfNote"];
  1419. [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1420. [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1421. [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1422. */
  1423. NSData* json= nil;
  1424. if(appDelegate.offline_mode)
  1425. {
  1426. json = [OLDataProvider offline_direct_save_TearSheet:params];
  1427. }
  1428. else
  1429. {
  1430. if(![self IsNetworkAvailable])
  1431. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1432. json=[self get_json:URL_REQUEST_DM parameters:params];
  1433. NSError *error=nil;
  1434. NSString * uuid= [[NSUUID UUID] UUIDString];
  1435. params[@"resultSerial"]=uuid;
  1436. for(int i=0;i<150;i++)
  1437. {
  1438. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1439. // result_params[@"resultSerial"]=uuid;
  1440. json=[self get_json:URL_REQUEST_DM parameters:params];
  1441. if(json!=nil)
  1442. {
  1443. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1444. if([jsobj[@"result"] intValue]==2)
  1445. {
  1446. break;
  1447. }
  1448. }
  1449. sleep(5);
  1450. }
  1451. }
  1452. if(json==nil)
  1453. return nil;
  1454. NSError *error=nil;
  1455. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1456. return jsobj;
  1457. }
  1458. +(NSDictionary*)request_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url
  1459. {
  1460. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1461. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1462. if(appDelegate.user!=nil)
  1463. [params setValue:appDelegate.user forKey:@"user"];
  1464. if(appDelegate.contact_id!=nil)
  1465. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1466. if(appDelegate.password!=nil)
  1467. [params setValue:appDelegate.password forKey:@"password"];
  1468. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1469. // [params setValue:request_url forKey:@"pdfUrl"];
  1470. NSData* json= nil;
  1471. if(appDelegate.offline_mode)
  1472. {
  1473. json= [OLDataProvider offline_request_tearsheet:params];
  1474. }
  1475. else
  1476. {
  1477. if(![self IsNetworkAvailable])
  1478. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1479. NSError *error=nil;
  1480. NSString * uuid= [[NSUUID UUID] UUIDString];
  1481. params[@"resultSerial"]=uuid;
  1482. for(int i=0;i<150;i++)
  1483. {
  1484. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1485. // result_params[@"resultSerial"]=uuid;
  1486. json=[self get_json:URL_REQUEST_DM parameters:params];
  1487. if(json!=nil)
  1488. {
  1489. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1490. if([jsobj[@"result"] intValue]==2)
  1491. {
  1492. break;
  1493. }
  1494. }
  1495. sleep(5);
  1496. }
  1497. }
  1498. if(json==nil)
  1499. return nil;
  1500. NSError *error=nil;
  1501. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1502. return jsobj;
  1503. }
  1504. +(NSDictionary*)save_TearSheet:(NSMutableDictionary *)params//(NSString*) path name:(NSString*)name delete:(NSString* )ids note:(NSString*)note configureParams:(NSString *)configureParams modelIds:(NSDictionary *)modelIds
  1505. {
  1506. NSMutableDictionary* off_params = [params mutableCopy];;
  1507. params[@"off_params"]=[RAUtils dict2string:off_params];
  1508. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1509. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1510. if(appDelegate.user!=nil)
  1511. [params setValue:appDelegate.user forKey:@"user"];
  1512. if(appDelegate.contact_id!=nil)
  1513. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1514. if(appDelegate.password!=nil)
  1515. [params setValue:appDelegate.password forKey:@"password"];
  1516. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1517. /*
  1518. [params setValue:path forKey:@"pdfPath"];
  1519. [params setValue:name forKey:@"pdfName"];
  1520. [params setValue:note forKey:@"pdfNote"];
  1521. [params setValue:ids forKey:@"itemIds"];
  1522. [params setValue:configureParams forKey:@"configureParams"];
  1523. [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1524. [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1525. [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1526. */
  1527. NSData* json = nil;
  1528. if(appDelegate.offline_mode)
  1529. {
  1530. json = [OLDataProvider offline_save_TearSheet:params];
  1531. } else {
  1532. if(![self IsNetworkAvailable])
  1533. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1534. json=[self get_json:URL_SAVE_DM parameters:params];
  1535. }
  1536. if(json==nil)
  1537. return nil;
  1538. NSError *error=nil;
  1539. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1540. return jsobj;
  1541. }
  1542. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  1543. {
  1544. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1545. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1546. if(appDelegate.user!=nil)
  1547. [params setValue:appDelegate.user forKey:@"user"];
  1548. [params setValue:up_params forKey:@"upparam"];
  1549. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  1550. [params setValue:result forKey:@"result"];
  1551. [params setValue:module forKey:@"interfac"];
  1552. [params setValue:[RAUtils base64en:[RAUtils dict2string: [RAUtils device_info]]] forKey:@"device"];
  1553. // [params setValue:module forKey:@"module"];
  1554. // [[UIDevice currentDevice] name];
  1555. // if(appDelegate.offline_mode)
  1556. // {
  1557. // return [OLDataProvider offline_notimpl];
  1558. // }
  1559. if(![self IsNetworkAvailable])
  1560. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1561. NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  1562. if(json==nil)
  1563. return nil;
  1564. NSError *error=nil;
  1565. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1566. return jsobj;
  1567. }
  1568. +(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams
  1569. {
  1570. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1571. if(upparams!=nil)
  1572. params = [upparams mutableCopy];
  1573. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1574. if(appDelegate.user!=nil)
  1575. [params setValue:appDelegate.user forKey:@"user"];
  1576. if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1577. [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1578. else
  1579. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1580. if(appDelegate.password!=nil)
  1581. [params setValue:appDelegate.password forKey:@"password"];
  1582. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1583. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1584. [params setValue:contact_type forKey:@"contactType"];
  1585. [params setValue:keywords forKey:@"keyword"];
  1586. [params setObject:ScreenCodeAccount forKey:kScreenName];
  1587. if (keywords) {
  1588. [params setObject:@"Search" forKey:kAction];
  1589. }
  1590. if (upparams) {
  1591. [params setObject:@"Advance Search" forKey:kAction];
  1592. }
  1593. NSString* url=nil;
  1594. if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  1595. url=URL_SHIPTO_LIST;
  1596. else
  1597. url=URL_CONTACT_LIST;
  1598. if(appDelegate.offline_mode)
  1599. return [OLDataProvider offline_contactlist:params];
  1600. if(![self IsNetworkAvailable])
  1601. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1602. NSData* json=[self get_json:url parameters:params];
  1603. if(json==nil)
  1604. return nil;
  1605. NSError *error=nil;
  1606. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1607. return jsobj;
  1608. }
  1609. +(NSDictionary*)request_OrderDetail:(NSString* ) orderid
  1610. {
  1611. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1612. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1613. if(appDelegate.user!=nil)
  1614. [params setValue:appDelegate.user forKey:@"user"];
  1615. if(appDelegate.contact_id!=nil)
  1616. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1617. if(appDelegate.password!=nil)
  1618. [params setValue:appDelegate.password forKey:@"password"];
  1619. [params setValue:orderid forKey:@"orderId"];
  1620. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1621. [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  1622. NSData* json=nil;
  1623. if(appDelegate.offline_mode)
  1624. {
  1625. json= [OLDataProvider offline_orderdetail:params];
  1626. }
  1627. else
  1628. {
  1629. if(![self IsNetworkAvailable])
  1630. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1631. NSError *error=nil;
  1632. NSString * uuid= [[NSUUID UUID] UUIDString];
  1633. params[@"resultSerial"]=uuid;
  1634. for(int i=0;i<150;i++)
  1635. {
  1636. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1637. // result_params[@"resultSerial"]=uuid;
  1638. json=[self get_json:URL_ORDER_DETAIL parameters:params];
  1639. if(json!=nil)
  1640. {
  1641. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1642. int resultCode = [jsobj[@"result"] intValue];
  1643. if(resultCode==2 || resultCode == 8)
  1644. {
  1645. break;
  1646. }
  1647. }
  1648. sleep(2);
  1649. }
  1650. }
  1651. if(json==nil)
  1652. return nil;
  1653. NSError *error=nil;
  1654. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1655. return jsobj;
  1656. }
  1657. +(NSDictionary*) add_toCart:(NSString* ) item_id count:(int) count name:(NSString *)name
  1658. {
  1659. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1660. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1661. if(appDelegate.user!=nil)
  1662. [params setValue:appDelegate.user forKey:@"user"];
  1663. if(appDelegate.contact_id!=nil)
  1664. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1665. if(appDelegate.password!=nil)
  1666. [params setValue:appDelegate.password forKey:@"password"];
  1667. if(appDelegate.order_code!=nil)
  1668. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1669. [params setValue:item_id forKey:@"product_id"];
  1670. [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  1671. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1672. [params setObject:@"Add To Cart" forKey:kAction];
  1673. if (name) {
  1674. NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  1675. [params setObject:extra forKey:kExtra];
  1676. }
  1677. NSDictionary* customerinfo= appDelegate.customerInfo;
  1678. NSArray* keys=[customerinfo allKeys];
  1679. for(int i=0;i<keys.count;i++)
  1680. {
  1681. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1682. }
  1683. NSData* json=nil;
  1684. if(appDelegate.offline_mode)
  1685. {
  1686. json=[OLDataProvider offline_add2cart:params];
  1687. }
  1688. else
  1689. {
  1690. if(![self IsNetworkAvailable])
  1691. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1692. json=[self get_json:URL_ADD_TO_CART parameters:params];
  1693. }
  1694. if(json==nil)
  1695. return nil;
  1696. NSError *error=nil;
  1697. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1698. int result = [[jsobj valueForKey:@"result"] intValue];
  1699. if (result==2)
  1700. {
  1701. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1702. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1703. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1704. [appDelegate update_count_mark];
  1705. }
  1706. return jsobj;
  1707. }
  1708. +(NSDictionary*) add_toCart_byName:(NSString* ) model_name withScreen:(NSString *)screenName
  1709. {
  1710. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1711. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1712. if(appDelegate.user!=nil)
  1713. [params setValue:appDelegate.user forKey:@"user"];
  1714. if(appDelegate.contact_id!=nil)
  1715. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1716. if(appDelegate.password!=nil)
  1717. [params setValue:appDelegate.password forKey:@"password"];
  1718. if(appDelegate.order_code!=nil)
  1719. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1720. [params setValue:model_name forKey:@"product_name"];
  1721. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  1722. [params setObject:screenName forKey:kScreenName];
  1723. [params setObject:@"Add To Cart" forKey:kAction];
  1724. [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  1725. NSDictionary* customerinfo= appDelegate.customerInfo;
  1726. NSArray* keys=[customerinfo allKeys];
  1727. for(int i=0;i<keys.count;i++)
  1728. {
  1729. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1730. }
  1731. NSData* json=nil;
  1732. if(appDelegate.offline_mode)
  1733. {
  1734. json= [OLDataProvider offline_add2cartbyname:params];
  1735. }
  1736. else
  1737. {
  1738. if(![self IsNetworkAvailable])
  1739. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1740. json=[self get_json:URL_ADD_TO_CART parameters:params];
  1741. }
  1742. if(json==nil)
  1743. return nil;
  1744. NSError *error=nil;
  1745. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1746. int result = [[jsobj valueForKey:@"result"] intValue];
  1747. if (result==2||result==8)
  1748. {
  1749. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1750. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1751. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1752. [appDelegate update_count_mark];
  1753. }
  1754. return jsobj;
  1755. }
  1756. //+(NSDictionary*) new_Customer
  1757. //{
  1758. // if(![self IsNetworkAvailable])
  1759. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1760. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1761. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1762. // if(appDelegate.user!=nil)
  1763. // [params setValue:appDelegate.user forKey:@"user"];
  1764. //// if(appDelegate.contact_id!=nil)
  1765. //// [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1766. // if(appDelegate.password!=nil)
  1767. // [params setValue:appDelegate.password forKey:@"password"];
  1768. //
  1769. //// if(appDelegate.order_code!=nil)
  1770. //// [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1771. //
  1772. //
  1773. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1774. //
  1775. // NSArray* keys=[customerinfo allKeys];
  1776. // for(int i=0;i<keys.count;i++)
  1777. // {
  1778. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1779. // }
  1780. //
  1781. // NSData* json=[self get_json:URL_CUSTOMER_EDIT parameters:params];
  1782. // if(json==nil)
  1783. // return nil;
  1784. // NSError *error=nil;
  1785. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1786. // return jsobj;
  1787. //}
  1788. +(NSDictionary*) new_Order
  1789. {
  1790. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1791. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1792. if(appDelegate.user!=nil)
  1793. [params setValue:appDelegate.user forKey:@"user"];
  1794. if(appDelegate.contact_id!=nil)
  1795. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1796. if(appDelegate.password!=nil)
  1797. [params setValue:appDelegate.password forKey:@"password"];
  1798. if(appDelegate.order_code!=nil)
  1799. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1800. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1801. NSDictionary* customerinfo= appDelegate.customerInfo;
  1802. NSArray* keys=[customerinfo allKeys];
  1803. for(int i=0;i<keys.count;i++)
  1804. {
  1805. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1806. }
  1807. NSData* json = nil;
  1808. if(appDelegate.offline_mode)
  1809. {
  1810. json= [OLDataProvider offline_createorder:params];
  1811. }
  1812. else
  1813. {
  1814. if(![self IsNetworkAvailable])
  1815. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1816. json=[self get_json:URL_NEW_ORDER parameters:params];
  1817. }
  1818. if(json==nil)
  1819. return nil;
  1820. NSError *error=nil;
  1821. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1822. int result = [[jsobj valueForKey:@"result"] intValue];
  1823. if (result==2)
  1824. {
  1825. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1826. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1827. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1828. [appDelegate update_count_mark];
  1829. }
  1830. [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  1831. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1832. [Singleton sharedInstance].currentOrderIsMerged = NO;
  1833. }
  1834. return jsobj;
  1835. }
  1836. +(NSDictionary*) add_toPortfolio:(NSString* ) item_id withScreen:(NSString *)screenName
  1837. {
  1838. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1839. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1840. if(appDelegate.user!=nil)
  1841. [params setValue:appDelegate.user forKey:@"user"];
  1842. if(appDelegate.contact_id!=nil)
  1843. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1844. if(appDelegate.password!=nil)
  1845. [params setValue:appDelegate.password forKey:@"password"];
  1846. [params setValue:item_id forKey:@"product_id"];
  1847. [params setObject:screenName forKey:kScreenName];
  1848. NSData* json = nil;
  1849. if(appDelegate.offline_mode)
  1850. {
  1851. json = [OLDataProvider offline_add2Portfolio:params];
  1852. } else {
  1853. if(![self IsNetworkAvailable])
  1854. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1855. json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  1856. }
  1857. if(json==nil)
  1858. return nil;
  1859. NSError *error=nil;
  1860. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1861. int result = [[jsobj valueForKey:@"result"] intValue];
  1862. if (result==2)
  1863. {
  1864. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1865. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1866. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1867. [appDelegate update_count_mark];
  1868. }
  1869. return jsobj;
  1870. }
  1871. +(NSDictionary*) add_toWatchList:(NSString* ) item_id withScreen:(NSString *)screenName
  1872. {
  1873. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1874. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1875. if(appDelegate.user!=nil)
  1876. [params setValue:appDelegate.user forKey:@"user"];
  1877. if(appDelegate.contact_id!=nil)
  1878. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1879. if(appDelegate.password!=nil)
  1880. [params setValue:appDelegate.password forKey:@"password"];
  1881. [params setValue:item_id forKey:@"product_id"];
  1882. [params setObject:screenName forKey:kScreenName];
  1883. if(appDelegate.offline_mode)
  1884. {
  1885. return [OLDataProvider offline_add2wishlist:params];
  1886. }
  1887. if(![self IsNetworkAvailable])
  1888. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1889. NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  1890. if(json==nil)
  1891. return nil;
  1892. NSError *error=nil;
  1893. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1894. int result = [[jsobj valueForKey:@"result"] intValue];
  1895. if (result==2)
  1896. {
  1897. //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1898. appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1899. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1900. [appDelegate update_count_mark];
  1901. }
  1902. return jsobj;
  1903. }
  1904. +(NSDictionary*) cart_setPrice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes
  1905. {
  1906. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1907. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1908. if(appDelegate.user!=nil)
  1909. [params setValue:appDelegate.user forKey:@"user"];
  1910. if(appDelegate.contact_id!=nil)
  1911. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1912. if(appDelegate.password!=nil)
  1913. [params setValue:appDelegate.password forKey:@"password"];
  1914. [params setValue:cart_id forKey:@"cartitem_id"];
  1915. [params setValue:notes forKey:@"item_note"];
  1916. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  1917. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  1918. [params setObject:ScreenCodeCart forKey:kScreenName];
  1919. NSData* json= nil;
  1920. if(appDelegate.offline_mode)
  1921. {
  1922. json=[OLDataProvider offline_cartsetprice:params];
  1923. }
  1924. else
  1925. {
  1926. if(![self IsNetworkAvailable])
  1927. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1928. json=[self get_json:URL_CART_SET_PRICE parameters:params];
  1929. }
  1930. if(json==nil)
  1931. return nil;
  1932. NSError *error=nil;
  1933. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1934. return jsobj;
  1935. }
  1936. //+(NSDictionary*) portfolio_setQTY:(NSString*) watchlist_id QTY:(int)qty
  1937. //{
  1938. // if(![self IsNetworkAvailable])
  1939. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1940. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1941. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1942. // if(appDelegate.user!=nil)
  1943. // [params setValue:appDelegate.user forKey:@"user"];
  1944. // if(appDelegate.contact_id!=nil)
  1945. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1946. // if(appDelegate.password!=nil)
  1947. // [params setValue:appDelegate.password forKey:@"password"];
  1948. //
  1949. // [params setValue:watchlist_id forKey:@"item_id"];
  1950. //
  1951. // [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  1952. //
  1953. //
  1954. //
  1955. // NSData* json=[self get_json:URL_DM_SET_QTY parameters:params];
  1956. // if(json==nil)
  1957. // return nil;
  1958. // NSError *error=nil;
  1959. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1960. // return jsobj;
  1961. //}
  1962. +(NSDictionary*) portfolio_setPrice:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes
  1963. {
  1964. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1965. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1966. if(appDelegate.user!=nil)
  1967. [params setValue:appDelegate.user forKey:@"user"];
  1968. if(appDelegate.contact_id!=nil)
  1969. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1970. if(appDelegate.password!=nil)
  1971. [params setValue:appDelegate.password forKey:@"password"];
  1972. [params setValue:watchlist_id forKey:@"item_id"];
  1973. // if(notes.length>0)
  1974. // [params setValue:notes forKey:@"notes"];
  1975. if(notes)
  1976. [params setValue:notes forKey:@"notes"];
  1977. if(price != -MAXFLOAT)
  1978. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  1979. if (discount != -MAXFLOAT)
  1980. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  1981. if(qty_p != -MAXFLOAT)
  1982. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  1983. if(qty != -INT32_MAX)
  1984. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  1985. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  1986. NSData* json = nil;
  1987. if(appDelegate.offline_mode)
  1988. {
  1989. json = [OLDataProvider offline_editPortfolio:params];
  1990. } else {
  1991. if(![self IsNetworkAvailable])
  1992. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1993. json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  1994. }
  1995. if(json==nil)
  1996. return nil;
  1997. NSError *error=nil;
  1998. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1999. return jsobj;
  2000. }
  2001. +(NSDictionary*) cart_setGeneralNote:(NSString*) order_code notes:(NSString*) notes
  2002. {
  2003. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2004. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2005. if(appDelegate.user!=nil)
  2006. [params setValue:appDelegate.user forKey:@"user"];
  2007. if(appDelegate.contact_id!=nil)
  2008. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2009. if(appDelegate.password!=nil)
  2010. [params setValue:appDelegate.password forKey:@"password"];
  2011. [params setValue:order_code forKey:@"orderCode"];
  2012. [params setObject:ScreenCodeCart forKey:kScreenName];
  2013. if(notes.length==0)
  2014. notes=@"";
  2015. [params setValue:notes forKey:@"comments"];
  2016. NSData* json=nil;
  2017. if(appDelegate.offline_mode)
  2018. {
  2019. json= [OLDataProvider offline_updategnotes:params];
  2020. }
  2021. else
  2022. {
  2023. if(![self IsNetworkAvailable])
  2024. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2025. json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  2026. }
  2027. if(json==nil)
  2028. return nil;
  2029. NSError *error=nil;
  2030. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2031. return jsobj;
  2032. }
  2033. +(NSDictionary*) cart_setItemNote:(NSString*) cart_id notes:(NSString*) notes
  2034. {
  2035. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2036. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2037. if(appDelegate.user!=nil)
  2038. [params setValue:appDelegate.user forKey:@"user"];
  2039. if(appDelegate.contact_id!=nil)
  2040. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2041. if(appDelegate.password!=nil)
  2042. [params setValue:appDelegate.password forKey:@"password"];
  2043. [params setValue:cart_id forKey:@"cartitem_id"];
  2044. [params setObject:ScreenCodeCart forKey:kScreenName];
  2045. if(notes.length==0)
  2046. notes=@"";
  2047. [params setValue:notes forKey:@"notes"];
  2048. NSData* json=nil;
  2049. if(appDelegate.offline_mode)
  2050. {
  2051. json= [OLDataProvider offline_cartsetlnotes:params];
  2052. }
  2053. else
  2054. {
  2055. if(![self IsNetworkAvailable])
  2056. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2057. json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  2058. }
  2059. if(json==nil)
  2060. return nil;
  2061. NSError *error=nil;
  2062. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2063. return jsobj;
  2064. }
  2065. +(NSDictionary*) cart_setFree:(NSString*) cart_id isfree:(bool) isfree
  2066. {
  2067. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2068. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2069. if(appDelegate.user!=nil)
  2070. [params setValue:appDelegate.user forKey:@"user"];
  2071. if(appDelegate.contact_id!=nil)
  2072. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2073. if(appDelegate.password!=nil)
  2074. [params setValue:appDelegate.password forKey:@"password"];
  2075. [params setValue:cart_id forKey:@"cartitem_id"];
  2076. [params setObject:ScreenCodeCart forKey:kScreenName];
  2077. NSString* free=nil;
  2078. if(isfree)
  2079. free=@"true";
  2080. else
  2081. free=@"false";
  2082. [params setValue:free forKey:@"free_giveaway"];
  2083. if(appDelegate.offline_mode)
  2084. {
  2085. return [OLDataProvider offline_notimpl];
  2086. }
  2087. if(![self IsNetworkAvailable])
  2088. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2089. NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2090. if(json==nil)
  2091. return nil;
  2092. NSError *error=nil;
  2093. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2094. return jsobj;
  2095. }
  2096. +(NSDictionary*) cart_setQTY:(NSString*) cart_id value:(int) value
  2097. {
  2098. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2099. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2100. if(appDelegate.user!=nil)
  2101. [params setValue:appDelegate.user forKey:@"user"];
  2102. if(appDelegate.contact_id!=nil)
  2103. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2104. if(appDelegate.password!=nil)
  2105. [params setValue:appDelegate.password forKey:@"password"];
  2106. [params setValue:cart_id forKey:@"cartitem_id"];
  2107. [params setObject:ScreenCodeCart forKey:kScreenName];
  2108. [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  2109. NSData* json=nil;
  2110. if(appDelegate.offline_mode)
  2111. {
  2112. json= [OLDataProvider offline_cartsetqty:params];
  2113. }
  2114. else
  2115. {
  2116. if(![self IsNetworkAvailable])
  2117. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2118. json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2119. }
  2120. if(json==nil)
  2121. return nil;
  2122. NSError *error=nil;
  2123. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2124. return jsobj;
  2125. }
  2126. +(NSDictionary*) cart_incresement:(NSString*) cart_id increse:(bool) increse
  2127. {
  2128. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2129. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2130. if(appDelegate.user!=nil)
  2131. [params setValue:appDelegate.user forKey:@"user"];
  2132. if(appDelegate.contact_id!=nil)
  2133. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2134. if(appDelegate.password!=nil)
  2135. [params setValue:appDelegate.password forKey:@"password"];
  2136. [params setValue:cart_id forKey:@"cartitem_id"];
  2137. if(increse)
  2138. [params setValue:@"1" forKey:@"incrementType"];
  2139. else
  2140. [params setValue:@"0" forKey:@"incrementType"];
  2141. if(appDelegate.offline_mode)
  2142. {
  2143. return [OLDataProvider offline_notimpl];
  2144. }
  2145. if(![self IsNetworkAvailable])
  2146. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2147. NSData* json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2148. if(json==nil)
  2149. return nil;
  2150. NSError *error=nil;
  2151. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2152. return jsobj;
  2153. }
  2154. +(NSDictionary*) finish_download_Offline:(NSString* )vid
  2155. {
  2156. if(![self IsNetworkAvailable])
  2157. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2158. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2159. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  2160. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2161. // if(appDelegate.user!=nil)
  2162. // [params setValue:appDelegate.user forKey:@"user"];
  2163. // // if(appDelegate.contact_id!=nil)
  2164. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2165. // if(appDelegate.password!=nil)
  2166. // [params setValue:appDelegate.password forKey:@"password"];
  2167. [params setValue:vid forKey:@"downSerial"];
  2168. NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  2169. if(json==nil)
  2170. return nil;
  2171. NSError *error=nil;
  2172. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2173. // int result = [[jsobj valueForKey:@"result"] intValue];
  2174. //
  2175. // if (result==2)
  2176. // {
  2177. //
  2178. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2179. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2180. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2181. ////
  2182. //// [appDelegate update_count_mark];
  2183. // }
  2184. return jsobj;
  2185. }
  2186. +(NSDictionary*) download_Offline:(NSString* )vid
  2187. {
  2188. if(![self IsNetworkAvailable])
  2189. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2190. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2191. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2192. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2193. // if(appDelegate.user!=nil)
  2194. // [params setValue:appDelegate.user forKey:@"user"];
  2195. // // if(appDelegate.contact_id!=nil)
  2196. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2197. // if(appDelegate.password!=nil)
  2198. // [params setValue:appDelegate.password forKey:@"password"];
  2199. [params setValue:vid forKey:@"downSerial"];
  2200. NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  2201. if(json==nil)
  2202. return nil;
  2203. NSError *error=nil;
  2204. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2205. // int result = [[jsobj valueForKey:@"result"] intValue];
  2206. //
  2207. // if (result==2)
  2208. // {
  2209. //
  2210. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2211. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2212. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2213. ////
  2214. //// [appDelegate update_count_mark];
  2215. // }
  2216. return jsobj;
  2217. }
  2218. +(NSDictionary*) check_Offline:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid
  2219. {
  2220. if(![self IsNetworkAvailable])
  2221. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2222. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2223. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2224. if(appDelegate.user!=nil)
  2225. [params setValue:appDelegate.user forKey:@"user"];
  2226. // if(appDelegate.contact_id!=nil)
  2227. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2228. if(appDelegate.password!=nil)
  2229. [params setValue:appDelegate.password forKey:@"password"];
  2230. [params setValue:ver forKey:@"ver"];
  2231. [params setValue:vid forKey:@"vid"];
  2232. if(buseinternaladdress)
  2233. [params setValue:@"true" forKey:@"internal_address"];
  2234. else
  2235. [params setValue:@"false" forKey:@"internal_address"];
  2236. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2237. NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  2238. if(json==nil)
  2239. return nil;
  2240. NSError *error=nil;
  2241. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2242. // int result = [[jsobj valueForKey:@"result"] intValue];
  2243. //
  2244. // if (result==2)
  2245. // {
  2246. //
  2247. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2248. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2249. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2250. ////
  2251. //// [appDelegate update_count_mark];
  2252. // }
  2253. return jsobj;
  2254. }
  2255. +(NSDictionary*)request_Cart:(int)sort
  2256. {
  2257. DebugLog(@"iSalesNetwork::request_Cart");
  2258. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2259. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2260. if(appDelegate.user!=nil)
  2261. [params setValue:appDelegate.user forKey:@"user"];
  2262. // if(appDelegate.contact_id!=nil)
  2263. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2264. if(appDelegate.password!=nil)
  2265. [params setValue:appDelegate.password forKey:@"password"];
  2266. if(appDelegate.order_code!=nil)
  2267. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2268. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2269. [params setObject:ScreenCodeCart forKey:kScreenName];
  2270. NSData* json=nil;
  2271. if(appDelegate.offline_mode)
  2272. {
  2273. json= [OLDataProvider offline_requestcart:params];
  2274. }
  2275. else
  2276. {
  2277. if(![self IsNetworkAvailable])
  2278. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2279. NSError *error=nil;
  2280. NSString * uuid= [[NSUUID UUID] UUIDString];
  2281. params[@"resultSerial"]=uuid;
  2282. for(int i=0;i<150;i++)
  2283. {
  2284. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2285. // result_params[@"resultSerial"]=uuid;
  2286. json=[self get_json:URL_CART parameters:params];
  2287. if(json!=nil)
  2288. {
  2289. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2290. if([jsobj[@"result"] intValue]==2)
  2291. {
  2292. break;
  2293. }
  2294. }
  2295. sleep(2);
  2296. }
  2297. }
  2298. if(json==nil)
  2299. return nil;
  2300. NSError *error=nil;
  2301. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2302. int result = [[jsobj valueForKey:@"result"] intValue];
  2303. if (result==2)
  2304. {
  2305. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2306. //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2307. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2308. [appDelegate update_count_mark];
  2309. }
  2310. return jsobj;
  2311. }
  2312. +(NSDictionary*)request_Portfolio:(int)sort
  2313. {
  2314. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2315. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2316. if(appDelegate.user!=nil)
  2317. [params setValue:appDelegate.user forKey:@"user"];
  2318. if(appDelegate.contact_id!=nil)
  2319. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2320. if(appDelegate.password!=nil)
  2321. [params setValue:appDelegate.password forKey:@"password"];
  2322. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2323. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2324. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2325. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2326. NSData* json = nil;
  2327. if(appDelegate.offline_mode)
  2328. {
  2329. json = [OLDataProvider offline_portfolioList:params];
  2330. } else {
  2331. if(![self IsNetworkAvailable])
  2332. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2333. json = [self get_json:URL_PORTFOLIO parameters:params];
  2334. }
  2335. if(json==nil)
  2336. return nil;
  2337. NSError *error=nil;
  2338. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2339. int result = [[jsobj valueForKey:@"result"] intValue];
  2340. if (result==2)
  2341. {
  2342. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2343. //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2344. appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  2345. [appDelegate update_count_mark];
  2346. }
  2347. return jsobj;
  2348. }
  2349. +(NSDictionary*)request_WatchList:(int)sort
  2350. {
  2351. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2352. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2353. if(appDelegate.user!=nil)
  2354. [params setValue:appDelegate.user forKey:@"user"];
  2355. if(appDelegate.contact_id!=nil)
  2356. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2357. if(appDelegate.password!=nil)
  2358. [params setValue:appDelegate.password forKey:@"password"];
  2359. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2360. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2361. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2362. [params setObject:ScreenCodeWishList forKey:kScreenName];
  2363. if(appDelegate.offline_mode)
  2364. {
  2365. return [OLDataProvider offline_wishlist:params];
  2366. }
  2367. if(![self IsNetworkAvailable])
  2368. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2369. NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  2370. if(json==nil)
  2371. return nil;
  2372. NSError *error=nil;
  2373. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2374. int result = [[jsobj valueForKey:@"result"] intValue];
  2375. if (result==2)
  2376. {
  2377. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2378. appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2379. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2380. [appDelegate update_count_mark];
  2381. }
  2382. return jsobj;
  2383. }
  2384. +(NSDictionary*)request_ItemDetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name
  2385. {
  2386. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2387. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2388. if(appDelegate.user!=nil)
  2389. [params setValue:appDelegate.user forKey:@"user"];
  2390. if(appDelegate.contact_id!=nil)
  2391. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2392. if(appDelegate.password!=nil)
  2393. [params setValue:appDelegate.password forKey:@"password"];
  2394. if(appDelegate.order_code!=nil)
  2395. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2396. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2397. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2398. if(use_name)
  2399. [params setValue:model_name forKey:@"product_name"];
  2400. else
  2401. [params setValue:item_id forKey:@"product_id"];
  2402. [params setValue:category_id forKey:@"category"];
  2403. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  2404. [params setObject:@"Open A Model" forKey:kAction];
  2405. if (model_name) {
  2406. NSDictionary *extra = @{@"ModelName" : model_name};
  2407. [params setObject:extra forKey:kExtra];
  2408. }
  2409. if(appDelegate.offline_mode)
  2410. return [OLDataProvider offline_model:params];
  2411. if(![self IsNetworkAvailable])
  2412. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2413. NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  2414. if(json==nil)
  2415. return nil;
  2416. NSError *error=nil;
  2417. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2418. return jsobj;
  2419. }
  2420. //+(NSDictionary*)category_LoadMore: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(int)offset
  2421. //{
  2422. // if(![self IsNetworkAvailable])
  2423. // return nil;
  2424. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2425. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2426. // if(appDelegate.user!=nil)
  2427. // [params setValue:appDelegate.user forKey:@"user"];
  2428. // if(appDelegate.contact_id!=nil)
  2429. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2430. // if(appDelegate.password!=nil)
  2431. // [params setValue:appDelegate.password forKey:@"password"];
  2432. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2433. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2434. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2435. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2436. // [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  2437. // [params setValue:filter forKey:@"filter"];
  2438. // [params setValue:keyword forKey:@"keyword"];
  2439. //
  2440. //
  2441. // NSData* json=[self get_json:URL_CATEGORY_LOADMORE parameters:params];
  2442. // if(json==nil)
  2443. // return nil;
  2444. // NSError *error=nil;
  2445. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2446. // return jsobj;
  2447. //
  2448. //}
  2449. +(NSDictionary*)Category_addall: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  2450. {
  2451. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2452. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2453. if(appDelegate.user!=nil)
  2454. [params setValue:appDelegate.user forKey:@"user"];
  2455. if(appDelegate.contact_id!=nil)
  2456. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2457. if(appDelegate.password!=nil)
  2458. [params setValue:appDelegate.password forKey:@"password"];
  2459. if(appDelegate.order_code!=nil)
  2460. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2461. [params setValue:addTo forKey:@"addTo"];
  2462. [params setValue:orderCode forKey:@"orderCode"];
  2463. [params setValue:alert forKey:@"alert"];
  2464. [params setValue:qty forKey:@"sold_by_qty"];
  2465. [params setValue:available forKey:@"available"];
  2466. [params setValue:price forKey:@"price"];
  2467. [params setValue:bestseller forKey:@"bestseller"];
  2468. [params setValue:modelname forKey:@"modelName"];
  2469. [params setValue:modeldescrip forKey:@"modelDescription"];
  2470. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2471. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2472. [params setValue:category forKey:@"category"];
  2473. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2474. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2475. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2476. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2477. [params setValue:filter forKey:@"filter"];
  2478. [params setValue:keyword forKey:@"keyword"];
  2479. [params setObject:ScreenCodeCategory forKey:kScreenName];
  2480. if ([addTo isEqualToString:@"cart"]) {
  2481. [params setObject:@"Add To Cart" forKey:kAction];
  2482. }
  2483. NSData* json= nil;
  2484. if(appDelegate.offline_mode)
  2485. {
  2486. json= [OLDataProvider offline_categoryaddall:params];
  2487. }
  2488. else
  2489. {
  2490. if(![self IsNetworkAvailable])
  2491. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2492. NSError *error=nil;
  2493. NSString * uuid= [[NSUUID UUID] UUIDString];
  2494. params[@"resultSerial"]=uuid;
  2495. for(int i=0;i<150;i++)
  2496. {
  2497. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2498. // result_params[@"resultSerial"]=uuid;
  2499. json=[self get_json:URL_CATEGORYADDALL parameters:params];
  2500. if(json!=nil)
  2501. {
  2502. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2503. int resultInt = [jsobj[@"result"] intValue];
  2504. if(resultInt == 2 || resultInt == 8)
  2505. {
  2506. break;
  2507. }
  2508. }
  2509. sleep(2);
  2510. }
  2511. }
  2512. if(json==nil)
  2513. return nil;
  2514. NSError *error=nil;
  2515. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2516. return jsobj;
  2517. }
  2518. //+(NSDictionary*)category_addall2portfolio: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
  2519. //{
  2520. //
  2521. //
  2522. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2523. //
  2524. //
  2525. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2526. //
  2527. // if(appDelegate.user!=nil)
  2528. // [params setValue:appDelegate.user forKey:@"user"];
  2529. // if(appDelegate.contact_id!=nil)
  2530. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2531. // if(appDelegate.password!=nil)
  2532. // [params setValue:appDelegate.password forKey:@"password"];
  2533. // if(appDelegate.order_code!=nil)
  2534. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2535. //
  2536. // [params setValue:alert forKey:@"alert"];
  2537. // [params setValue:qty forKey:@"sold_by_qty"];
  2538. // [params setValue:available forKey:@"available"];
  2539. // [params setValue:price forKey:@"price"];
  2540. // [params setValue:bestseller forKey:@"bestseller"];
  2541. // [params setValue:modelname forKey:@"modelName"];
  2542. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2543. //
  2544. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2545. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2546. // [params setValue:category forKey:@"category"];
  2547. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2548. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2549. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2550. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2551. // [params setValue:filter forKey:@"filter"];
  2552. // [params setValue:keyword forKey:@"keyword"];
  2553. //
  2554. //
  2555. //
  2556. // if(appDelegate.offline_mode)
  2557. // return [OLDataProvider offline_category:params];
  2558. // if(![self IsNetworkAvailable])
  2559. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2560. //
  2561. // NSData* json=[self get_json:URL_ADDALL2PORTFOLIO parameters:params];
  2562. // if(json==nil)
  2563. // return nil;
  2564. // NSError *error=nil;
  2565. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2566. // return jsobj;
  2567. //
  2568. //}
  2569. //+(NSDictionary*)category_addall2wish: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
  2570. //{
  2571. //
  2572. //
  2573. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2574. //
  2575. //
  2576. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2577. //
  2578. // if(appDelegate.user!=nil)
  2579. // [params setValue:appDelegate.user forKey:@"user"];
  2580. // if(appDelegate.contact_id!=nil)
  2581. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2582. // if(appDelegate.password!=nil)
  2583. // [params setValue:appDelegate.password forKey:@"password"];
  2584. // if(appDelegate.order_code!=nil)
  2585. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2586. //
  2587. // [params setValue:alert forKey:@"alert"];
  2588. // [params setValue:qty forKey:@"sold_by_qty"];
  2589. // [params setValue:available forKey:@"available"];
  2590. // [params setValue:price forKey:@"price"];
  2591. // [params setValue:bestseller forKey:@"bestseller"];
  2592. // [params setValue:modelname forKey:@"modelName"];
  2593. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2594. //
  2595. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2596. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2597. // [params setValue:category forKey:@"category"];
  2598. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2599. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2600. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2601. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2602. // [params setValue:filter forKey:@"filter"];
  2603. // [params setValue:keyword forKey:@"keyword"];
  2604. //
  2605. //
  2606. //
  2607. // if(appDelegate.offline_mode)
  2608. // return [OLDataProvider offline_category:params];
  2609. // if(![self IsNetworkAvailable])
  2610. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2611. //
  2612. // NSData* json=[self get_json:URL_ADDALL2WISH parameters:params];
  2613. // if(json==nil)
  2614. // return nil;
  2615. // NSError *error=nil;
  2616. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2617. // return jsobj;
  2618. //
  2619. //}
  2620. +(NSDictionary*)Category: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
  2621. {
  2622. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2623. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2624. if(appDelegate.user!=nil)
  2625. [params setValue:appDelegate.user forKey:@"user"];
  2626. if(appDelegate.contact_id!=nil)
  2627. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2628. if(appDelegate.password!=nil)
  2629. [params setValue:appDelegate.password forKey:@"password"];
  2630. if(appDelegate.order_code!=nil)
  2631. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2632. [params setValue:alert forKey:@"alert"];
  2633. [params setValue:qty forKey:@"sold_by_qty"];
  2634. [params setValue:available forKey:@"available"];
  2635. [params setValue:price forKey:@"price"];
  2636. [params setValue:bestseller forKey:@"bestseller"];
  2637. [params setValue:modelname forKey:@"modelName"];
  2638. [params setValue:modeldescrip forKey:@"modelDescription"];
  2639. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2640. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2641. [params setValue:category forKey:@"category"];
  2642. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2643. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2644. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2645. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2646. [params setValue:filter forKey:@"filter"];
  2647. [params setValue:keyword forKey:@"keyword"];
  2648. [params setObject:ScreenCodeCategory forKey:kScreenName];
  2649. if (alert) {
  2650. [params setObject:@"Filter" forKey:kAction];
  2651. }
  2652. if ([Singleton sharedInstance].homeItemClick) {
  2653. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  2654. [Singleton sharedInstance].homeItemClick = NO;
  2655. NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  2656. [Singleton sharedInstance].homeClickedItemName = nil;
  2657. [params setObject:extra forKey:kExtra];
  2658. }
  2659. if(appDelegate.offline_mode)
  2660. return [OLDataProvider offline_category:params];
  2661. if(![self IsNetworkAvailable])
  2662. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2663. NSData* json=[self get_json:URL_CATEGORY parameters:params];
  2664. if(json==nil)
  2665. return nil;
  2666. NSError *error=nil;
  2667. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2668. return jsobj;
  2669. }
  2670. +(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  2671. {
  2672. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2673. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2674. if(appDelegate.user!=nil)
  2675. [params setValue:appDelegate.user forKey:@"user"];
  2676. if(appDelegate.contact_id!=nil)
  2677. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2678. if(appDelegate.password!=nil)
  2679. [params setValue:appDelegate.password forKey:@"password"];
  2680. if(appDelegate.order_code!=nil)
  2681. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2682. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2683. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2684. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2685. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2686. // [params setValue:filter forKey:@"filter"];
  2687. [params setValue:keywords forKey:@"keyword"];
  2688. [params setValue:addTo forKey:@"addTo"];
  2689. [params setValue:orderCode forKey:@"orderCode"];
  2690. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2691. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2692. if(matchfull)
  2693. [params setValue:@"true" forKey:@"exactMatch"];
  2694. else
  2695. [params setValue:@"false" forKey:@"exactMatch"];
  2696. [params setObject:ScreenCodeSearch forKey:kScreenName];
  2697. if ([addTo isEqualToString:@"cart"]) {
  2698. [params setObject:@"Add To Cart" forKey:kAction];
  2699. }
  2700. NSData* json=nil;
  2701. if(appDelegate.offline_mode)
  2702. {
  2703. json=[OLDataProvider offline_searchaddall:params];
  2704. }
  2705. else
  2706. {
  2707. if(![self IsNetworkAvailable])
  2708. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2709. NSError *error=nil;
  2710. NSString * uuid= [[NSUUID UUID] UUIDString];
  2711. params[@"resultSerial"]=uuid;
  2712. for(int i=0;i<150;i++)
  2713. {
  2714. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2715. // result_params[@"resultSerial"]=uuid;
  2716. json=[self get_json:URL_SEARCHADDALL parameters:params];
  2717. if(json!=nil)
  2718. {
  2719. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2720. if([jsobj[@"result"] intValue]==2)
  2721. {
  2722. break;
  2723. }
  2724. }
  2725. sleep(2);
  2726. }
  2727. }
  2728. if(json==nil)
  2729. return nil;
  2730. NSError *error=nil;
  2731. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2732. return jsobj;
  2733. }
  2734. +(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
  2735. {
  2736. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2737. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2738. if(appDelegate.user!=nil)
  2739. [params setValue:appDelegate.user forKey:@"user"];
  2740. if(appDelegate.contact_id!=nil)
  2741. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2742. if(appDelegate.password!=nil)
  2743. [params setValue:appDelegate.password forKey:@"password"];
  2744. if(appDelegate.order_code!=nil)
  2745. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2746. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2747. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2748. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2749. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2750. // [params setValue:filter forKey:@"filter"];
  2751. [params setValue:keywords forKey:@"keyword"];
  2752. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2753. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2754. if(matchfull)
  2755. [params setValue:@"true" forKey:@"exactMatch"];
  2756. else
  2757. [params setValue:@"false" forKey:@"exactMatch"];
  2758. [params setObject:ScreenCodeSearch forKey:kScreenName];
  2759. if (keywords) {
  2760. [params setObject:@"Search" forKey:kAction];
  2761. }
  2762. if(appDelegate.offline_mode)
  2763. {
  2764. return [OLDataProvider offline_search:params];
  2765. }
  2766. if(![self IsNetworkAvailable])
  2767. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2768. NSData* json=[self get_json:URL_SEARCH parameters:params];
  2769. if(json==nil)
  2770. return nil;
  2771. NSError *error=nil;
  2772. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2773. return jsobj;
  2774. }
  2775. +(NSDictionary*)ItemSearch_addall:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  2776. {
  2777. // for debug
  2778. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  2779. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2780. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2781. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2782. if(appDelegate.user!=nil)
  2783. [params setValue:appDelegate.user forKey:@"user"];
  2784. if(appDelegate.contact_id!=nil)
  2785. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2786. if(appDelegate.password!=nil)
  2787. [params setValue:appDelegate.password forKey:@"password"];
  2788. if(appDelegate.order_code!=nil)
  2789. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2790. [params setValue:addTo forKey:@"addTo"];
  2791. [params setValue:orderCode forKey:@"orderCode"];
  2792. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2793. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2794. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2795. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2796. // [params setValue:filter forKey:@"filter"];
  2797. [params setValue:covertype forKey:@"covertype"];
  2798. [params setValue:ctgid forKey:@"ctgId"];
  2799. [params setValue:modelname forKey:@"modelName"];
  2800. [params setValue:modeldescrip forKey:@"modelDescription"];
  2801. [params setValue:alert forKey:@"alert"];
  2802. [params setValue:qty forKey:@"sold_by_qty"];
  2803. [params setValue:available forKey:@"available"];
  2804. [params setValue:price forKey:@"price"];
  2805. [params setValue:bestseller forKey:@"bestseller"];
  2806. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2807. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2808. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  2809. if ([addTo isEqualToString:@"cart"]) {
  2810. [params setObject:@"Add To Cart" forKey:kAction];
  2811. }
  2812. NSData* json = nil;
  2813. if(appDelegate.offline_mode)
  2814. {
  2815. json= [OLDataProvider offline_itemsearchaddall:params];
  2816. }
  2817. else
  2818. {
  2819. if(![self IsNetworkAvailable])
  2820. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2821. NSError *error=nil;
  2822. NSString * uuid= [[NSUUID UUID] UUIDString];
  2823. params[@"resultSerial"]=uuid;
  2824. for(int i=0;i<150;i++)
  2825. {
  2826. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2827. // result_params[@"resultSerial"]=uuid;
  2828. json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  2829. if(json!=nil)
  2830. {
  2831. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2832. if([jsobj[@"result"] intValue]==2)
  2833. {
  2834. break;
  2835. }
  2836. }
  2837. sleep(2);
  2838. }
  2839. }
  2840. if(json==nil)
  2841. return nil;
  2842. NSError *error=nil;
  2843. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2844. return jsobj;
  2845. }
  2846. +(NSDictionary*)ItemSearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller
  2847. {
  2848. // for debug
  2849. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  2850. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2851. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2852. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2853. if(appDelegate.user!=nil)
  2854. [params setValue:appDelegate.user forKey:@"user"];
  2855. if(appDelegate.contact_id!=nil)
  2856. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2857. if(appDelegate.password!=nil)
  2858. [params setValue:appDelegate.password forKey:@"password"];
  2859. if(appDelegate.order_code!=nil)
  2860. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2861. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  2862. if (alert && qty && available && price && bestseller) {
  2863. [params setObject:@"Filter" forKey:kAction];
  2864. }
  2865. if ([Singleton sharedInstance].homeItemClick) {
  2866. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  2867. [Singleton sharedInstance].homeItemClick = NO;
  2868. NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  2869. [Singleton sharedInstance].homeClickedItemName = nil;
  2870. [params setObject:extra forKey:kExtra];
  2871. }
  2872. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2873. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2874. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2875. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2876. // [params setValue:filter forKey:@"filter"];
  2877. [params setValue:covertype forKey:@"covertype"];
  2878. [params setValue:ctgid forKey:@"ctgId"];
  2879. [params setValue:modelname forKey:@"modelName"];
  2880. [params setValue:modeldescrip forKey:@"modelDescription"];
  2881. [params setValue:alert forKey:@"alert"];
  2882. [params setValue:qty forKey:@"sold_by_qty"];
  2883. [params setValue:available forKey:@"available"];
  2884. [params setValue:price forKey:@"price"];
  2885. [params setValue:bestseller forKey:@"bestseller"];
  2886. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2887. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2888. if(appDelegate.offline_mode)
  2889. {
  2890. return [OLDataProvider offline_itemsearch:params];
  2891. }
  2892. if(![self IsNetworkAvailable])
  2893. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2894. NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  2895. if(json==nil)
  2896. return nil;
  2897. NSError *error=nil;
  2898. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2899. return jsobj;
  2900. }
  2901. //+(NSDictionary*)Search: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword
  2902. //{
  2903. // if(![self IsNetworkAvailable])
  2904. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2905. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2906. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2907. // if(appDelegate.user!=nil)
  2908. // [params setValue:appDelegate.user forKey:@"user"];
  2909. // if(appDelegate.contact_id!=nil)
  2910. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2911. // if(appDelegate.password!=nil)
  2912. // [params setValue:appDelegate.password forKey:@"password"];
  2913. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2914. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2915. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2916. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2917. // [params setValue:filter forKey:@"filter"];
  2918. // [params setValue:keyword forKey:@"keyword"];
  2919. //
  2920. //
  2921. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  2922. // if(json==nil)
  2923. // return nil;
  2924. // NSError *error=nil;
  2925. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2926. // return jsobj;
  2927. //}
  2928. +(NSDictionary*)request_model_qty: (NSString*) fashionId
  2929. {
  2930. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2931. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2932. if(appDelegate.user!=nil)
  2933. [params setValue:appDelegate.user forKey:@"user"];
  2934. if(appDelegate.contact_id!=nil)
  2935. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2936. if(appDelegate.password!=nil)
  2937. [params setValue:appDelegate.password forKey:@"password"];
  2938. [params setValue:fashionId forKey:@"fashionId"];
  2939. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  2940. NSData* json = nil;
  2941. if(appDelegate.offline_mode)
  2942. {
  2943. json = [OLDataProvider offline_model_qty:params];
  2944. } else {
  2945. if(![self IsNetworkAvailable])
  2946. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2947. json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  2948. }
  2949. if(json==nil)
  2950. return nil;
  2951. NSError *error=nil;
  2952. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2953. return jsobj;
  2954. }
  2955. +(NSDictionary*)retrieve_password: (NSString*) user email:(NSString*) email
  2956. {
  2957. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2958. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2959. // if(appDelegate.user!=nil)
  2960. // [params setValue:appDelegate.user forKey:@"user"];
  2961. // if(appDelegate.contact_id!=nil)
  2962. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2963. // if(appDelegate.password!=nil)
  2964. // [params setValue:appDelegate.password forKey:@"password"];
  2965. [params setValue:user forKey:@"username"];
  2966. [params setValue:email forKey:@"email"];
  2967. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  2968. if(![self IsNetworkAvailable])
  2969. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2970. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  2971. if(json==nil)
  2972. return nil;
  2973. NSError *error=nil;
  2974. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2975. return jsobj;
  2976. }
  2977. +(NSDictionary*)load_HomePage:(int) price_template customid:(int) customid
  2978. {
  2979. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2980. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2981. if(appDelegate.user!=nil)
  2982. [params setValue:appDelegate.user forKey:@"user"];
  2983. if(appDelegate.contact_id!=nil)
  2984. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2985. if(appDelegate.password!=nil)
  2986. [params setValue:appDelegate.password forKey:@"password"];
  2987. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2988. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2989. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  2990. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2991. if(appDelegate.offline_mode)
  2992. {
  2993. //params[@"offline_Command"]=url;
  2994. return [OLDataProvider offline_home];
  2995. }
  2996. if(![self IsNetworkAvailable])
  2997. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2998. NSData* json=[self get_json:URL_LOAD_HOME parameters:params];
  2999. if(json==nil)
  3000. return nil;
  3001. NSError *error=nil;
  3002. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3003. return jsobj;
  3004. }
  3005. +(NSDictionary*)logout
  3006. {
  3007. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3008. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3009. if(appDelegate.user!=nil)
  3010. [params setValue:appDelegate.user forKey:@"user"];
  3011. if(appDelegate.password!=nil)
  3012. [params setValue:appDelegate.password forKey:@"password"];
  3013. if(appDelegate.offline_mode)
  3014. {
  3015. return [OLDataProvider offline_logout:params];
  3016. }
  3017. if(![self IsNetworkAvailable])
  3018. {
  3019. DebugLog(@"NET ERR");
  3020. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3021. // return nil;
  3022. }
  3023. NSData* json=[self get_json:URL_LOGOUT parameters:params];
  3024. //if(json==nil)
  3025. if(json==nil)
  3026. return nil;
  3027. NSError *error=nil;
  3028. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3029. int result = [[jsobj valueForKey:@"result"] intValue];
  3030. if (result==2)
  3031. {
  3032. appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  3033. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  3034. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  3035. [appDelegate update_count_mark];
  3036. appDelegate.can_show_price =false;
  3037. appDelegate.can_see_price =false;
  3038. appDelegate.can_create_portfolio =false;
  3039. appDelegate.can_create_order =false;
  3040. appDelegate.can_cancel_order =false;
  3041. appDelegate.can_set_cart_price =false;
  3042. appDelegate.can_delete_order =false;
  3043. appDelegate.can_submit_order =false;
  3044. appDelegate.can_set_tearsheet_price =false;
  3045. appDelegate.can_update_contact_info = false;
  3046. appDelegate.save_order_logout = false;
  3047. appDelegate.submit_order_logout = false;
  3048. appDelegate.alert_sold_in_quantities = false;
  3049. appDelegate.ipad_perm =nil ;
  3050. appDelegate.user_type = USER_ROLE_UNKNOWN;
  3051. appDelegate.OrderFilter= nil;
  3052. [appDelegate SetSo:nil];
  3053. [appDelegate set_main_button_panel];
  3054. }
  3055. return jsobj;
  3056. }
  3057. +(NSDictionary*)request_Cagegory
  3058. {
  3059. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  3060. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3061. if(appDelegate.offline_mode)
  3062. {
  3063. //params[@"offline_Command"]=url;
  3064. return [OLDataProvider offline_category_menu];
  3065. }
  3066. if(![self IsNetworkAvailable])
  3067. {
  3068. DebugLog(@"NET ERR");
  3069. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3070. // return nil;
  3071. }
  3072. NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  3073. //if(json==nil)
  3074. if(json==nil)
  3075. return nil;
  3076. NSError *error=nil;
  3077. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3078. return jsobj;
  3079. }
  3080. +(int)Authorize : (NSString*) user password:(NSString*) password{
  3081. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  3082. // return RESULT_NET_ERROR;
  3083. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3084. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3085. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3086. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3087. if(appDelegate.duid !=nil)
  3088. [params setValue:appDelegate.duid forKey:@"udid"];
  3089. [params setValue:@"handset_login" forKey:@"action"];
  3090. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  3091. [params setValue:user forKey:@"user"];
  3092. [params setValue:password forKey:@"password"];
  3093. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  3094. #ifdef TEST
  3095. [params setValue:@"true" forKey:@"is_debug"];
  3096. #else
  3097. [params setValue:@"false" forKey:@"is_debug"];
  3098. #endif
  3099. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3100. [params setObject:@"Login" forKey:kAction];
  3101. NSData* json= nil;
  3102. if(appDelegate.offline_mode)
  3103. {
  3104. json= [OLDataProvider offline_login:params] ;
  3105. }
  3106. else
  3107. {
  3108. if(![self IsNetworkAvailable])
  3109. return RESULT_NET_NOTAVAILABLE;
  3110. json =[self get_json:URL_UPDATE_AUTH parameters:params];
  3111. }
  3112. if(json==nil)
  3113. return RESULT_NET_ERROR;
  3114. int ret = [self parse_authinfo:json user:user password:password];
  3115. DebugLog(@"parse_authinfo return %d ",ret);
  3116. return ret;
  3117. }
  3118. +(NSDictionary*)update_customer_img: (NSString*) contactid img_url:(NSString*) url
  3119. {
  3120. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3121. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3122. if(appDelegate.user!=nil)
  3123. [params setValue:appDelegate.user forKey:@"user"];
  3124. // if(appDelegate.contact_id!=nil)
  3125. if(appDelegate.password!=nil)
  3126. [params setValue:appDelegate.password forKey:@"password"];
  3127. [params setValue:contactid forKey:@"contactId"];
  3128. [params setValue:url forKey:@"business_card"];
  3129. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  3130. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  3131. if(appDelegate.offline_mode)
  3132. {
  3133. return [OLDataProvider offline_notimpl];
  3134. }
  3135. if(![self IsNetworkAvailable])
  3136. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3137. NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  3138. if(json==nil)
  3139. return nil;
  3140. NSError *error=nil;
  3141. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3142. return jsobj;
  3143. }
  3144. +(NSDictionary*)request_PendingOrder:(NSString *)contactid
  3145. {
  3146. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3147. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3148. if(appDelegate.user!=nil)
  3149. [params setValue:appDelegate.user forKey:@"user"];
  3150. // if(appDelegate.contact_id!=nil)
  3151. if(appDelegate.password!=nil)
  3152. [params setValue:appDelegate.password forKey:@"password"];
  3153. [params setValue:contactid forKey:@"contactId"];
  3154. if(appDelegate.offline_mode)
  3155. {
  3156. return [OLDataProvider offline_notimpl];
  3157. }
  3158. if(![self IsNetworkAvailable])
  3159. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3160. NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  3161. if(json==nil)
  3162. return nil;
  3163. NSError *error=nil;
  3164. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3165. return jsobj;
  3166. }
  3167. +(NSDictionary*)request_CustomerInfo:(NSString* ) contactid
  3168. {
  3169. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3170. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3171. if(appDelegate.user!=nil)
  3172. [params setValue:appDelegate.user forKey:@"user"];
  3173. // if(appDelegate.contact_id!=nil)
  3174. if(appDelegate.password!=nil)
  3175. [params setValue:appDelegate.password forKey:@"password"];
  3176. [params setValue:contactid forKey:@"contactId"];
  3177. [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  3178. if(appDelegate.offline_mode)
  3179. return [OLDataProvider offline_contactinfo:params];
  3180. if(![self IsNetworkAvailable])
  3181. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3182. NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  3183. if(json==nil)
  3184. return nil;
  3185. NSError *error=nil;
  3186. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3187. return jsobj;
  3188. }
  3189. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  3190. {
  3191. DebugLog(@"parse_authinfo");
  3192. NSError *error=nil;
  3193. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3194. if(jsobj)
  3195. {
  3196. UIApplication * app = [UIApplication sharedApplication];
  3197. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  3198. int result = [[jsobj valueForKey:@"result"] intValue];
  3199. if (result<0)
  3200. return result;
  3201. if(result!=AP_USER_AUTH&& result!=9)
  3202. {
  3203. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  3204. [appDelegate Logout];
  3205. if(result==8)
  3206. {
  3207. return RESULT_LOGIN_DEVICE;
  3208. }
  3209. return RESULT_FALSE;
  3210. }
  3211. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  3212. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  3213. user=[objheader objectForKey:@"username"] ;
  3214. DebugLog(@"required_ver=%@ ",required_ver);
  3215. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  3216. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  3217. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  3218. int ibadge = [[objheader valueForKey:@"badge"] intValue];
  3219. // if([ibadge isEqual:[NSNull null]])
  3220. // strbadge=@"0";
  3221. // if(ibadge==nil)
  3222. // ibadge=@"0";
  3223. // if([strbadge isEqualToString:@"null"])
  3224. // strbadge=@"0";
  3225. app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  3226. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  3227. if([appDelegate.build intValue]<[required_ver intValue])
  3228. return RESULT_VER_LOW;
  3229. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  3230. appDelegate.user = user;
  3231. appDelegate.password = password;
  3232. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  3233. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  3234. appDelegate.bLogin = true;
  3235. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  3236. {
  3237. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  3238. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  3239. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  3240. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  3241. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  3242. }
  3243. NSString* mode =[jsobj valueForKey:@"mode"] ;
  3244. [appDelegate SetMode:mode];
  3245. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  3246. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  3247. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  3248. [appDelegate update_count_mark];
  3249. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  3250. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  3251. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  3252. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  3253. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  3254. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  3255. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  3256. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  3257. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  3258. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  3259. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  3260. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  3261. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  3262. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  3263. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  3264. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  3265. appDelegate.OrderFilter= [[RAUtils string2dict:strfilter] mutableCopy];
  3266. [appDelegate set_main_button_panel];
  3267. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  3268. // shop order status filter
  3269. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  3270. [Singleton sharedInstance].shop_order_status_filter = [[RAUtils string2dict:shopOrderStatusFilterStr] mutableCopy];
  3271. // Sales order status filter
  3272. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  3273. [Singleton sharedInstance].sales_order_status_filter = [[RAUtils string2dict:salesOrderStatusFilterStr] mutableCopy];
  3274. // specialInstruction
  3275. [Singleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  3276. //-价格类型
  3277. [Singleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  3278. // 权限
  3279. [Singleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  3280. [Singleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  3281. [Singleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  3282. [Singleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  3283. [Singleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  3284. [[Singleton sharedInstance] resetGlobalLock];
  3285. [Singleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  3286. [Singleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  3287. }
  3288. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  3289. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  3290. // {
  3291. // // no update on the server;
  3292. // return RESULT_TRUE;
  3293. // }
  3294. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  3295. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3296. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3297. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3298. // [defaults synchronize];
  3299. //
  3300. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  3301. // NSArray* keys= [objfuncs allKeys];
  3302. /*
  3303. db.setTransactionSuccessful();
  3304. db.endTransaction();
  3305. */
  3306. return RESULT_TRUE;
  3307. }
  3308. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  3309. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  3310. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  3311. return RESULT_USERAUTH_ERROR;
  3312. }
  3313. +(bool) IsNetworkAvailable
  3314. {
  3315. if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  3316. ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  3317. return false;
  3318. return true;
  3319. }
  3320. //+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim
  3321. //{
  3322. // NSScanner *theScanner = [NSScanner scannerWithString:html];
  3323. // NSString *text = nil;
  3324. //
  3325. // while ([theScanner isAtEnd] == NO) {
  3326. // // find start of tag
  3327. // [theScanner scanUpToString:@"<" intoString:NULL] ;
  3328. // // find end of tag
  3329. // [theScanner scanUpToString:@">" intoString:&text] ;
  3330. // // replace the found tag with a space
  3331. // //(you can filter multi-spaces out later if you wish)
  3332. // html = [html stringByReplacingOccurrencesOfString:
  3333. // [ NSString stringWithFormat:@"%@>", text]
  3334. // withString:@""];
  3335. // }
  3336. //
  3337. // return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
  3338. //}
  3339. //
  3340. //+(NSString *)flattenURL:(NSString *)url trimWhiteSpace:(BOOL)trim
  3341. //{
  3342. // NSScanner *theScanner = [NSScanner scannerWithString:url];
  3343. // NSString *text = nil;
  3344. //
  3345. // while ([theScanner isAtEnd] == NO) {
  3346. // // find start of tag
  3347. // [theScanner scanUpToString:@"/" intoString:NULL] ;
  3348. // // find end of tag
  3349. // [theScanner scanUpToString:@"/" intoString:&text] ;
  3350. // // replace the found tag with a space
  3351. // //(you can filter multi-spaces out later if you wish)
  3352. // url = [url stringByReplacingOccurrencesOfString:
  3353. // [ NSString stringWithFormat:@"%@", text]
  3354. // withString:@""];
  3355. // }
  3356. //
  3357. // return trim ? [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : url;
  3358. //}
  3359. + (NSDictionary *)set_npd_shop_price_type:(NSInteger)priceType {
  3360. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3361. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3362. if(appDelegate.user!=nil)
  3363. [dic setValue:appDelegate.user forKey:@"user"];
  3364. if(appDelegate.password!=nil)
  3365. [dic setValue:appDelegate.password forKey:@"password"];
  3366. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  3367. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  3368. NSData* json=nil;
  3369. if(appDelegate.offline_mode)
  3370. {
  3371. return [OLDataProvider offline_notimpl];
  3372. }
  3373. else
  3374. {
  3375. if(![self IsNetworkAvailable])
  3376. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3377. json = [iSalesNetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  3378. }
  3379. if(json!=nil)
  3380. {
  3381. NSError *error=nil;
  3382. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3383. return jsobj;
  3384. }
  3385. return nil;
  3386. }
  3387. + (NSDictionary *)get_npd_shop_givenPrice {
  3388. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3389. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3390. if(appDelegate.user!=nil)
  3391. [dic setValue:appDelegate.user forKey:@"user"];
  3392. if(appDelegate.password!=nil)
  3393. [dic setValue:appDelegate.password forKey:@"password"];
  3394. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  3395. NSData* json=nil;
  3396. if(appDelegate.offline_mode)
  3397. {
  3398. return [OLDataProvider offline_notimpl];
  3399. }
  3400. else
  3401. {
  3402. if(![self IsNetworkAvailable])
  3403. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3404. json = [iSalesNetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  3405. }
  3406. if(json!=nil)
  3407. {
  3408. NSError *error=nil;
  3409. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3410. return jsobj;
  3411. }
  3412. return nil;
  3413. }
  3414. + (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params {
  3415. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3416. if(appDelegate.user!=nil)
  3417. [params setValue:appDelegate.user forKey:@"user"];
  3418. if(appDelegate.password!=nil)
  3419. [params setValue:appDelegate.password forKey:@"password"];
  3420. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  3421. NSData* json=nil;
  3422. if(appDelegate.offline_mode)
  3423. {
  3424. return [OLDataProvider offline_notimpl];
  3425. }
  3426. else
  3427. {
  3428. if(![self IsNetworkAvailable])
  3429. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3430. json = [iSalesNetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  3431. }
  3432. if(json!=nil)
  3433. {
  3434. NSError *error=nil;
  3435. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3436. return jsobj;
  3437. }
  3438. return nil;
  3439. }
  3440. + (NSDictionary *)merge_order:(NSMutableDictionary *)params {
  3441. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3442. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3443. if(appDelegate.user!=nil)
  3444. [dic setValue:appDelegate.user forKey:@"user"];
  3445. if(appDelegate.password!=nil)
  3446. [dic setValue:appDelegate.password forKey:@"password"];
  3447. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  3448. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  3449. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  3450. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  3451. NSData* json=nil;
  3452. if(appDelegate.offline_mode)
  3453. {
  3454. return [OLDataProvider offline_notimpl];
  3455. }
  3456. else
  3457. {
  3458. if(![self IsNetworkAvailable])
  3459. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3460. json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  3461. }
  3462. if(json!=nil)
  3463. {
  3464. NSError *error=nil;
  3465. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3466. return jsobj;
  3467. }
  3468. else
  3469. return nil;
  3470. }
  3471. + (NSDictionary *)lock_order:(NSString *)oderCode {
  3472. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3473. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3474. if(appDelegate.user!=nil)
  3475. [params setValue:appDelegate.user forKey:@"user"];
  3476. if(appDelegate.password!=nil)
  3477. [params setValue:appDelegate.password forKey:@"password"];
  3478. [params setValue:oderCode forKey:@"orderCode"];
  3479. NSData* json=nil;
  3480. if(appDelegate.offline_mode)
  3481. {
  3482. json=[OLDataProvider offline_editorder:params];
  3483. }
  3484. else
  3485. {
  3486. if(![self IsNetworkAvailable])
  3487. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3488. json=[self get_json:URL_OPEN_ORDER parameters:params];
  3489. }
  3490. if(json!=nil)
  3491. {
  3492. NSError *error=nil;
  3493. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3494. return jsobj;
  3495. }
  3496. else
  3497. return nil;
  3498. }
  3499. + (NSDictionary *)quoteOrder:(NSString *)so_id emailAddr:(NSString *)addr {
  3500. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3501. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3502. if(appDelegate.user!=nil)
  3503. [dic setValue:appDelegate.user forKey:@"user"];
  3504. if(appDelegate.password!=nil)
  3505. [dic setValue:appDelegate.password forKey:@"password"];
  3506. [dic setValue:so_id forKey:@"orderCode"];
  3507. [dic setValue:addr forKey:@"email"];
  3508. [dic setObject:ScreenCodeCart forKey:kScreenName];
  3509. if (appDelegate.customerInfo) {
  3510. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3511. if (customer_cid) {
  3512. [dic setValue:customer_cid forKey:@"contactId"];
  3513. }
  3514. }
  3515. NSData* json=nil;
  3516. if(appDelegate.offline_mode)
  3517. {
  3518. return [OLDataProvider offline_notimpl];
  3519. }
  3520. else
  3521. {
  3522. if(![self IsNetworkAvailable])
  3523. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3524. json = [iSalesNetwork get_json:URL_EMAIL_CART parameters:dic];
  3525. }
  3526. if(json!=nil)
  3527. {
  3528. NSError *error=nil;
  3529. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3530. return jsobj;
  3531. }
  3532. return @{@"result" : @(RESULT_FALSE)};
  3533. }
  3534. + (NSDictionary *)notifyModel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName{
  3535. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3536. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3537. if(appDelegate.user!=nil)
  3538. [dic setValue:appDelegate.user forKey:@"user"];
  3539. if(appDelegate.password!=nil)
  3540. [dic setValue:appDelegate.password forKey:@"password"];
  3541. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  3542. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3543. if (customer_cid) {
  3544. [dic setValue:customer_cid forKey:@"contactId"];
  3545. }
  3546. }
  3547. [dic setObject:screenName forKey:kScreenName];
  3548. [dic setValue:modelID forKey:@"productId"];
  3549. if (addr) { // 弹框输入
  3550. [dic setValue:addr forKey:@"email"];
  3551. } else {
  3552. // employee选择了Contact,并且Contact有Email
  3553. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  3554. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  3555. // if (email) {
  3556. // [dic setValue:email forKey:@"email"];
  3557. // }
  3558. // }
  3559. }
  3560. NSData* json=nil;
  3561. if(appDelegate.offline_mode)
  3562. {
  3563. return [OLDataProvider offline_notimpl];
  3564. }
  3565. else
  3566. {
  3567. if(![self IsNetworkAvailable])
  3568. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3569. json = [iSalesNetwork get_json:URL_NOTIFY_ME parameters:dic];
  3570. }
  3571. if(json!=nil)
  3572. {
  3573. NSError *error=nil;
  3574. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3575. return jsobj;
  3576. }
  3577. return @{@"result" : @(RESULT_FALSE)};
  3578. }
  3579. @end