iSalesNetwork.m 164 KB

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