iSalesNetwork.m 150 KB

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