iSalesNetwork.m 170 KB

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